mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
parent
4dba394fbc
commit
e964b2a4a4
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -58,8 +58,6 @@ jobs:
|
|||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
||||||
env:
|
|
||||||
CONTRACTS_VERSION: v1.0.0-alpha.28
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Wait for contracts deployment
|
- name: Wait for contracts deployment
|
||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
@ -117,8 +115,6 @@ jobs:
|
|||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
||||||
env:
|
|
||||||
CONTRACTS_VERSION: v1.0.0-alpha.28
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build:metadata
|
- run: npm run build:metadata
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import {
|
|||||||
ProviderInitialize
|
ProviderInitialize
|
||||||
} from '../@types/'
|
} from '../@types/'
|
||||||
import { noZeroX } from '../utils/ConversionTypeHelper'
|
import { noZeroX } from '../utils/ConversionTypeHelper'
|
||||||
import { signText, signWithHash } from '../utils/SignatureUtils'
|
|
||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
import { DownloadResponse } from '../@types/DownloadResponse'
|
import { DownloadResponse } from '../@types/DownloadResponse'
|
||||||
export interface HttpCallback {
|
export interface HttpCallback {
|
||||||
@ -107,22 +106,17 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createSignature(
|
public async signProviderRequest(
|
||||||
web3: Web3,
|
|
||||||
accountId: string,
|
|
||||||
agreementId: string
|
|
||||||
): Promise<string> {
|
|
||||||
const signature = await signText(web3, noZeroX(agreementId), accountId)
|
|
||||||
return signature
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createHashSignature(
|
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
message: string
|
message: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const signature = await signWithHash(web3, message, accountId)
|
const consumerMessage = web3.utils.soliditySha3({
|
||||||
return signature
|
t: 'bytes',
|
||||||
|
v: web3.utils.utf8ToHex(message)
|
||||||
|
})
|
||||||
|
const consumerSignature = await web3.eth.sign(consumerMessage, accountId)
|
||||||
|
return consumerSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Encrypt data using the Provider's own symmetric key
|
/** Encrypt data using the Provider's own symmetric key
|
||||||
@ -361,8 +355,7 @@ export class Provider {
|
|||||||
: null
|
: null
|
||||||
if (!downloadUrl) return null
|
if (!downloadUrl) return null
|
||||||
const nonce = Date.now()
|
const nonce = Date.now()
|
||||||
const signature = await this.createSignature(web3, accountId, did + nonce)
|
const signature = await this.signProviderRequest(web3, accountId, did + nonce)
|
||||||
|
|
||||||
let consumeUrl = downloadUrl
|
let consumeUrl = downloadUrl
|
||||||
consumeUrl += `?fileIndex=${fileIndex}`
|
consumeUrl += `?fileIndex=${fileIndex}`
|
||||||
consumeUrl += `&documentId=${did}`
|
consumeUrl += `&documentId=${did}`
|
||||||
@ -411,12 +404,11 @@ export class Provider {
|
|||||||
let signatureMessage = consumerAddress
|
let signatureMessage = consumerAddress
|
||||||
signatureMessage += dataset.documentId
|
signatureMessage += dataset.documentId
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.createHashSignature(
|
const signature = await this.signProviderRequest(
|
||||||
web3,
|
web3,
|
||||||
consumerAddress,
|
consumerAddress,
|
||||||
signatureMessage
|
signatureMessage
|
||||||
)
|
)
|
||||||
|
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.consumerAddress = consumerAddress
|
payload.consumerAddress = consumerAddress
|
||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
@ -490,12 +482,11 @@ export class Provider {
|
|||||||
signatureMessage += jobId || ''
|
signatureMessage += jobId || ''
|
||||||
signatureMessage += (did && `${noZeroX(did)}`) || ''
|
signatureMessage += (did && `${noZeroX(did)}`) || ''
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.createHashSignature(
|
const signature = await this.signProviderRequest(
|
||||||
web3,
|
web3,
|
||||||
consumerAddress,
|
consumerAddress,
|
||||||
signatureMessage
|
signatureMessage
|
||||||
)
|
)
|
||||||
|
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.documentId = noZeroX(did)
|
payload.documentId = noZeroX(did)
|
||||||
@ -620,7 +611,7 @@ export class Provider {
|
|||||||
signatureMessage += jobId
|
signatureMessage += jobId
|
||||||
signatureMessage += index.toString()
|
signatureMessage += index.toString()
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.createHashSignature(web3, accountId, signatureMessage)
|
const signature = await this.signProviderRequest(web3, accountId, signatureMessage)
|
||||||
|
|
||||||
let consumeUrl = computeResultUrl
|
let consumeUrl = computeResultUrl
|
||||||
consumeUrl += `?consumerAddress=${accountId}`
|
consumeUrl += `?consumerAddress=${accountId}`
|
||||||
@ -680,12 +671,11 @@ export class Provider {
|
|||||||
signatureMessage += jobId || ''
|
signatureMessage += jobId || ''
|
||||||
signatureMessage += (did && `${noZeroX(did)}`) || ''
|
signatureMessage += (did && `${noZeroX(did)}`) || ''
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.createHashSignature(
|
const signature = await this.signProviderRequest(
|
||||||
web3,
|
web3,
|
||||||
consumerAddress,
|
consumerAddress,
|
||||||
signatureMessage
|
signatureMessage
|
||||||
)
|
)
|
||||||
|
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.documentId = noZeroX(did)
|
payload.documentId = noZeroX(did)
|
||||||
payload.consumerAddress = consumerAddress
|
payload.consumerAddress = consumerAddress
|
||||||
|
@ -32,7 +32,8 @@ export const configHelperNetworks: Config[] = [
|
|||||||
...configHelperNetworksBase,
|
...configHelperNetworksBase,
|
||||||
chainId: 8996,
|
chainId: 8996,
|
||||||
network: 'development',
|
network: 'development',
|
||||||
metadataCacheUri: 'http://127.0.0.1:5000'
|
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||||
|
providerUri: 'http://172.15.0.4:8030'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...configHelperNetworksBase,
|
...configHelperNetworksBase,
|
||||||
|
@ -1,32 +1,6 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { LoggerInstance } from './Logger'
|
import { LoggerInstance } from './Logger'
|
||||||
|
|
||||||
export async function signText(
|
|
||||||
web3: Web3,
|
|
||||||
text: string,
|
|
||||||
publicKey: string,
|
|
||||||
password?: string
|
|
||||||
): Promise<string> {
|
|
||||||
const isMetaMask =
|
|
||||||
web3 && web3.currentProvider && (web3.currentProvider as any).isMetaMask
|
|
||||||
try {
|
|
||||||
return await web3.eth.personal.sign(text, publicKey, password)
|
|
||||||
} catch (e) {
|
|
||||||
if (isMetaMask) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
LoggerInstance.warn('Error on personal sign.')
|
|
||||||
LoggerInstance.warn(e)
|
|
||||||
try {
|
|
||||||
return await web3.eth.sign(text, publicKey)
|
|
||||||
} catch (e2) {
|
|
||||||
LoggerInstance.error('Error on sign.')
|
|
||||||
LoggerInstance.error(e2)
|
|
||||||
throw new Error('Error executing personal sign')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function signHash(web3: Web3, message: string, address: string) {
|
export async function signHash(web3: Web3, message: string, address: string) {
|
||||||
let signedMessage = await web3.eth.sign(message, address)
|
let signedMessage = await web3.eth.sign(message, address)
|
||||||
signedMessage = signedMessage.substr(2) // remove 0x
|
signedMessage = signedMessage.substr(2) // remove 0x
|
||||||
@ -38,30 +12,3 @@ export async function signHash(web3: Web3, message: string, address: string) {
|
|||||||
if (v === '0x01') v = '0x1c'
|
if (v === '0x01') v = '0x1c'
|
||||||
return { v, r, s }
|
return { v, r, s }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signWithHash(
|
|
||||||
web3: Web3,
|
|
||||||
text: string,
|
|
||||||
publicKey: string,
|
|
||||||
password?: string
|
|
||||||
): Promise<string> {
|
|
||||||
const hash = web3.utils.utf8ToHex(text)
|
|
||||||
const isMetaMask =
|
|
||||||
web3 && web3.currentProvider && (web3.currentProvider as any).isMetaMask
|
|
||||||
try {
|
|
||||||
return await web3.eth.personal.sign(hash, publicKey, password)
|
|
||||||
} catch (e) {
|
|
||||||
if (isMetaMask) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
LoggerInstance.warn('Error on personal sign.')
|
|
||||||
LoggerInstance.warn(e)
|
|
||||||
try {
|
|
||||||
return await web3.eth.sign(hash, publicKey)
|
|
||||||
} catch (e2) {
|
|
||||||
LoggerInstance.error('Error on sign.')
|
|
||||||
LoggerInstance.error(e2)
|
|
||||||
throw new Error('Error executing personal sign')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user