From 7de1b110b0c1c3cd46de153b87db911e677be599 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 8 Apr 2020 10:44:36 +0300 Subject: [PATCH 01/12] fix auth & tests --- src/brizo/Brizo.ts | 11 +++++++---- test/integration/ocean/Compute.test.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index bbb3e29..e5c20cb 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -121,10 +121,13 @@ export class Brizo extends Instantiable { ): Promise { const signature = await this.createSignature(consumerAccount, serviceAgreementId) const address = consumerAccount.getId() - const serviceEndpoint = await this.getEndpointFromAgreement( - 'compute', - serviceAgreementId - ) + let serviceEndpoint + if (serviceAgreementId) + serviceEndpoint = await this.getEndpointFromAgreement( + 'compute', + serviceAgreementId + ) + else serviceEndpoint = await this.getComputeEndpoint() if (!serviceEndpoint) { throw new Error( diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 965221a..d0c8847 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -33,6 +33,7 @@ describe('Compute', () => { let dataset: DDO let algorithm: DDO let computeService: ServiceCompute + let jobId: string before(async () => { ocean = await Ocean.getInstance(customConfig) @@ -117,5 +118,18 @@ describe('Compute', () => { ) assert.equal(response.status, ComputeJobStatus.Started) + jobId = response.jobId + }) + + it('should get status of a compute job', async () => { + const response = await ocean.compute.status(account, agreementId, jobId) + + assert.equal(response[0].jobId, jobId) + }) + + it('should get status of all compute jobs for an address', async () => { + const response = await ocean.compute.status(account, undefined, undefined) + + assert.isAbove(response.length, 0) }) }) From 0b7eb1c0678762dc484be012a68b357b6c2f9b19 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 8 Apr 2020 11:05:32 +0300 Subject: [PATCH 02/12] add new signature support --- src/brizo/Brizo.ts | 14 ++++++++------ src/ocean/utils/SignatureUtils.ts | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index e5c20cb..a3429e1 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -119,8 +119,13 @@ export class Brizo extends Instantiable { jobId?: string, output?: Output ): Promise { - const signature = await this.createSignature(consumerAccount, serviceAgreementId) const address = consumerAccount.getId() + + let signatureMessage = address + signatureMessage += (jobId && `${jobId}`) || '' + signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || '' + const signature = await this.createSignature(consumerAccount, signatureMessage) + let serviceEndpoint if (serviceAgreementId) serviceEndpoint = await this.getEndpointFromAgreement( @@ -189,13 +194,10 @@ export class Brizo extends Instantiable { return result } - public async createSignature(account: Account, agreementId: string): Promise { + public async createSignature(account: Account, message: string): Promise { const signature = (await account.getToken()) || - (await this.ocean.utils.signature.signText( - noZeroX(agreementId), - account.getId() - )) + (await this.ocean.utils.signature.signText(message, account.getId())) return signature } diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 2f269ae..81a29d9 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -21,7 +21,8 @@ export class SignatureUtils { this.web3.currentProvider && (this.web3.currentProvider as any).isMetaMask try { - return await this.web3.eth.personal.sign(text, publicKey, password) + const hash = await this.getHash(text) + return await this.web3.eth.personal.sign(hash, publicKey, password) } catch (e) { if (isMetaMask) { throw e From b6454bb71860f4ff7d82799a8546df1697b50c8e Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Wed, 8 Apr 2020 12:20:08 +0300 Subject: [PATCH 03/12] Use experimental brizo Before merge, wait for new Brizo and change .travis.yaml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4da682b..7c981e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_script: - git clone https://github.com/oceanprotocol/barge - cd barge - export AQUARIUS_VERSION=unstable - - export BRIZO_VERSION=v0.9.3 + - export BRIZO_VERSION=experimental - export KEEPER_VERSION=v0.13.2 - export EVENTS_HANDLER_VERSION=v0.4.5 - export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260" From 920feb0fba8494ad213ea8bc93f5a5bb9b33e690 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 8 Apr 2020 12:26:48 +0300 Subject: [PATCH 04/12] lint --- test/integration/ocean/Compute.test.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index d0c8847..46701a9 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -40,10 +40,10 @@ describe('Compute', () => { ;[account] = await ocean.accounts.list() }) - it('should authenticate the consumer account', async () => { + /* it('should authenticate the consumer account', async () => { await account.authenticate() }) - + */ it('should publish a dataset with a compute service object', async () => { const stepsAsset = [] computeService = await ocean.compute.createComputeServiceAttributes( @@ -119,17 +119,17 @@ describe('Compute', () => { assert.equal(response.status, ComputeJobStatus.Started) jobId = response.jobId - }) - - it('should get status of a compute job', async () => { - const response = await ocean.compute.status(account, agreementId, jobId) - - assert.equal(response[0].jobId, jobId) }) - + + it('should get status of a compute job', async () => { + const response = await ocean.compute.status(account, agreementId, jobId) + + assert.equal(response[0].jobId, jobId) + }) + it('should get status of all compute jobs for an address', async () => { - const response = await ocean.compute.status(account, undefined, undefined) - - assert.isAbove(response.length, 0) + const response = await ocean.compute.status(account, undefined, undefined) + + assert.isAbove(response.length, 0) }) }) From 795f8494f99c4e771e70a8a33458f85ef89f36e4 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 8 Apr 2020 12:46:28 +0300 Subject: [PATCH 05/12] fix signing --- src/brizo/Brizo.ts | 2 +- src/ocean/utils/SignatureUtils.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index a3429e1..76f43fd 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -197,7 +197,7 @@ export class Brizo extends Instantiable { public async createSignature(account: Account, message: string): Promise { const signature = (await account.getToken()) || - (await this.ocean.utils.signature.signText(message, account.getId())) + (await this.ocean.utils.signature.signWithHash(message, account.getId())) return signature } diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 81a29d9..cb75f13 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -15,6 +15,33 @@ export class SignatureUtils { text: string, publicKey: string, password?: string + ): Promise { + const isMetaMask = + this.web3 && + this.web3.currentProvider && + (this.web3.currentProvider as any).isMetaMask + try { + return await this.web3.eth.personal.sign(text, publicKey, password) + } catch (e) { + if (isMetaMask) { + throw e + } + this.logger.warn('Error on personal sign.') + this.logger.warn(e) + try { + return await this.web3.eth.sign(text, publicKey) + } catch (e2) { + this.logger.error('Error on sign.') + this.logger.error(e2) + throw new Error('Error executing personal sign') + } + } + } + + public async signWithHash( + text: string, + publicKey: string, + password?: string ): Promise { const isMetaMask = this.web3 && From 5d273a98ced9661fabea5b8de5f3920af6abe38e Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 14 Apr 2020 15:01:39 +0300 Subject: [PATCH 06/12] fix brizo --- src/ocean/utils/SignatureUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index cb75f13..afa27c0 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -48,7 +48,7 @@ export class SignatureUtils { this.web3.currentProvider && (this.web3.currentProvider as any).isMetaMask try { - const hash = await this.getHash(text) + const hash = this.web3.utils.utf8ToHex(text); return await this.web3.eth.personal.sign(hash, publicKey, password) } catch (e) { if (isMetaMask) { From 2ed8237350a2eb4d161d4e17714a53680498f6ad Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 14 Apr 2020 15:32:17 +0300 Subject: [PATCH 07/12] refactor --- src/brizo/Brizo.ts | 18 ++++++++++++++++-- src/ocean/utils/SignatureUtils.ts | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 76f43fd..da42fef 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -124,7 +124,10 @@ export class Brizo extends Instantiable { let signatureMessage = address signatureMessage += (jobId && `${jobId}`) || '' signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || '' - const signature = await this.createSignature(consumerAccount, signatureMessage) + const signature = await this.createHashSignature( + consumerAccount, + signatureMessage + ) let serviceEndpoint if (serviceAgreementId) @@ -194,7 +197,18 @@ export class Brizo extends Instantiable { return result } - public async createSignature(account: Account, message: string): Promise { + public async createSignature(account: Account, agreementId: string): Promise { + const signature = + (await account.getToken()) || + (await this.ocean.utils.signature.signText( + noZeroX(agreementId), + account.getId() + )) + + return signature + } + + public async createHashSignature(account: Account, message: string): Promise { const signature = (await account.getToken()) || (await this.ocean.utils.signature.signWithHash(message, account.getId())) diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index afa27c0..21da9bd 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -48,7 +48,7 @@ export class SignatureUtils { this.web3.currentProvider && (this.web3.currentProvider as any).isMetaMask try { - const hash = this.web3.utils.utf8ToHex(text); + const hash = this.web3.utils.utf8ToHex(text) return await this.web3.eth.personal.sign(hash, publicKey, password) } catch (e) { if (isMetaMask) { From 210b42d3e1a8aa783ba9e1d24fb7ad60e1683fc0 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 14 Apr 2020 16:19:30 +0300 Subject: [PATCH 08/12] fix test fix compute test --- test/integration/ocean/Compute.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 46701a9..bf1e60d 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -117,7 +117,7 @@ describe('Compute', () => { algoMeta ) - assert.equal(response.status, ComputeJobStatus.Started) + assert.isAtLeast(response.status, ComputeJobStatus.Started) jobId = response.jobId }) From 8a856680190f88b85770be6fb508558279cc6b67 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 14 Apr 2020 17:28:50 +0300 Subject: [PATCH 09/12] add hash --- src/ocean/utils/SignatureUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 21da9bd..04cf97e 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -43,12 +43,12 @@ export class SignatureUtils { publicKey: string, password?: string ): Promise { + const hash = this.web3.utils.utf8ToHex(text) const isMetaMask = this.web3 && this.web3.currentProvider && (this.web3.currentProvider as any).isMetaMask try { - const hash = this.web3.utils.utf8ToHex(text) return await this.web3.eth.personal.sign(hash, publicKey, password) } catch (e) { if (isMetaMask) { @@ -57,7 +57,7 @@ export class SignatureUtils { this.logger.warn('Error on personal sign.') this.logger.warn(e) try { - return await this.web3.eth.sign(text, publicKey) + return await this.web3.eth.sign(hash, publicKey) } catch (e2) { this.logger.error('Error on sign.') this.logger.error(e2) From 783e90f86815af008ee30253919e1b55e75364e5 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 14 Apr 2020 18:42:32 +0300 Subject: [PATCH 10/12] bump brizo & events-handler --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c981e0..8faa400 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,9 @@ before_script: - git clone https://github.com/oceanprotocol/barge - cd barge - export AQUARIUS_VERSION=unstable - - export BRIZO_VERSION=experimental + - export BRIZO_VERSION=v0.9.5 - export KEEPER_VERSION=v0.13.2 - - export EVENTS_HANDLER_VERSION=v0.4.5 + - export EVENTS_HANDLER_VERSION=v0.4.7 - export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260" - rm -rf "${HOME}/.ocean/keeper-contracts/artifacts" - bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log & From 0f51014d71bfe057403f3a3fb71e73e90fd3eb51 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Tue, 14 Apr 2020 19:05:38 +0300 Subject: [PATCH 11/12] Update src/brizo/Brizo.ts Co-Authored-By: Matthias Kretschmann --- src/brizo/Brizo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index da42fef..fdcc5ff 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -122,7 +122,7 @@ export class Brizo extends Instantiable { const address = consumerAccount.getId() let signatureMessage = address - signatureMessage += (jobId && `${jobId}`) || '' + signatureMessage += jobId || '' signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || '' const signature = await this.createHashSignature( consumerAccount, From 2aee1bff7b747f9981fa56bcab1f8c0782627c5b Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 14 Apr 2020 19:15:05 +0300 Subject: [PATCH 12/12] comments fixes --- src/brizo/Brizo.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index fdcc5ff..b92918f 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -129,13 +129,9 @@ export class Brizo extends Instantiable { signatureMessage ) - let serviceEndpoint - if (serviceAgreementId) - serviceEndpoint = await this.getEndpointFromAgreement( - 'compute', - serviceAgreementId - ) - else serviceEndpoint = await this.getComputeEndpoint() + const serviceEndpoint = serviceAgreementId + ? await this.getEndpointFromAgreement('compute', serviceAgreementId) + : this.getComputeEndpoint() if (!serviceEndpoint) { throw new Error(