From 2371124213424cbbd2c92167568d0f1aad9e11ed Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 22 Oct 2020 00:30:55 -0700 Subject: [PATCH 1/3] allow compute status without signature --- src/ocean/Compute.ts | 14 ++++++++++++-- src/provider/Provider.ts | 25 ++++++++++++++----------- test/integration/ComputeFlow.test.ts | 9 +++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/ocean/Compute.ts b/src/ocean/Compute.ts index 3961e864..0255fd5c 100644 --- a/src/ocean/Compute.ts +++ b/src/ocean/Compute.ts @@ -176,12 +176,14 @@ export class Compute extends Instantiable { * @param {Account} consumerAccount The account of the consumer ordering the service. * @param {string} did Decentralized identifier. * @param {string} jobId The ID of the compute job to be stopped + * @param {boolean} sign If the provider request is going to be signed(default) (full status) or not (short status) * @return {Promise} Returns the status */ public async status( consumerAccount: Account, did?: string, - jobId?: string + jobId?: string, + sign = true ): Promise { let provider: Provider @@ -200,7 +202,15 @@ export class Compute extends Instantiable { consumerAccount, undefined, undefined, - jobId + jobId, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + sign ) return computeJobsList as ComputeJob[] diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index a9061481..4b640e7f 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -171,20 +171,24 @@ export class Provider extends Instantiable { serviceType?: string, tokenAddress?: string, algorithmTransferTxId?: string, - algorithmDataToken?: string + algorithmDataToken?: string, + sign = true ): Promise { const address = consumerAccount.getId() await this.getNonce(consumerAccount.getId()) - let signatureMessage = address - signatureMessage += jobId || '' - signatureMessage += (did && `${noZeroX(did)}`) || '' - signatureMessage += this.nonce - const signature = await this.createHashSignature(consumerAccount, signatureMessage) - - // construct Brizo URL let url = this.getComputeEndpoint() - url += `?signature=${signature}` - url += `&documentId=${noZeroX(did)}` + if (sign) { + let signatureMessage = address + signatureMessage += jobId || '' + signatureMessage += (did && `${noZeroX(did)}`) || '' + signatureMessage += this.nonce + const signature = await this.createHashSignature(consumerAccount, signatureMessage) + url += `?signature=${signature}` + url += `&documentId=${noZeroX(did)}` + } else { + url += `?documentId=${noZeroX(did)}` + } + // consitnue to construct Provider URL url += (output && `&output=${JSON.stringify(output)}`) || '' url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || '' url += @@ -215,7 +219,6 @@ export class Provider extends Instantiable { // switch fetch method let fetch - switch (method) { case 'post': fetch = this.ocean.utils.fetch.post(url, '') diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 3b33088b..9da58ace 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -350,7 +350,16 @@ describe('Compute flow', () => { jobId = response.jobId assert(response.status >= 10) }) + it('Bob should get status of a compute job without signing', async () => { + assert(jobId != null) + const response = await ocean.compute.status(bob, ddo.id, jobId, false) + assert(response[0].jobId === jobId) + }) + it('should get status of all compute jobs for an address without signing', async () => { + const response = await ocean.compute.status(bob, undefined, undefined, false) + assert(response.length > 0) + }) it('Bob should get status of a compute job', async () => { assert(jobId != null) const response = await ocean.compute.status(bob, ddo.id, jobId) From edce3812c6c0638349f406739e11b92321a08e38 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 22 Oct 2020 01:37:43 -0700 Subject: [PATCH 2/3] small refactor --- src/provider/Provider.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index 4b640e7f..ec6177d7 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -177,16 +177,14 @@ export class Provider extends Instantiable { const address = consumerAccount.getId() await this.getNonce(consumerAccount.getId()) let url = this.getComputeEndpoint() + url += `?documentId=${noZeroX(did)}` if (sign) { let signatureMessage = address signatureMessage += jobId || '' signatureMessage += (did && `${noZeroX(did)}`) || '' signatureMessage += this.nonce const signature = await this.createHashSignature(consumerAccount, signatureMessage) - url += `?signature=${signature}` - url += `&documentId=${noZeroX(did)}` - } else { - url += `?documentId=${noZeroX(did)}` + url += `&signature=${signature}` } // consitnue to construct Provider URL url += (output && `&output=${JSON.stringify(output)}`) || '' From c88040d0188a9490869c032c6924e5e305575e67 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 22 Oct 2020 01:38:50 -0700 Subject: [PATCH 3/3] typo --- src/provider/Provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index ec6177d7..fd3d5757 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -186,7 +186,7 @@ export class Provider extends Instantiable { const signature = await this.createHashSignature(consumerAccount, signatureMessage) url += `&signature=${signature}` } - // consitnue to construct Provider URL + // continue to construct Provider URL url += (output && `&output=${JSON.stringify(output)}`) || '' url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || '' url +=