diff --git a/.travis.yml b/.travis.yml index 4da682b..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=v0.9.3 + - 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 & diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index bbb3e29..b92918f 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -119,13 +119,20 @@ export class Brizo extends Instantiable { jobId?: string, output?: Output ): Promise { - const signature = await this.createSignature(consumerAccount, serviceAgreementId) const address = consumerAccount.getId() - const serviceEndpoint = await this.getEndpointFromAgreement( - 'compute', - serviceAgreementId + + let signatureMessage = address + signatureMessage += jobId || '' + signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || '' + const signature = await this.createHashSignature( + consumerAccount, + signatureMessage ) + const serviceEndpoint = serviceAgreementId + ? await this.getEndpointFromAgreement('compute', serviceAgreementId) + : this.getComputeEndpoint() + if (!serviceEndpoint) { throw new Error( 'Computing on asset failed, service definition is missing the `serviceEndpoint`.' @@ -197,6 +204,14 @@ export class Brizo extends Instantiable { return signature } + public async createHashSignature(account: Account, message: string): Promise { + const signature = + (await account.getToken()) || + (await this.ocean.utils.signature.signWithHash(message, account.getId())) + + return signature + } + public async encrypt( did: string, signature: string, diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 2f269ae..04cf97e 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -38,6 +38,34 @@ export class SignatureUtils { } } + public async signWithHash( + text: string, + 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 { + return await this.web3.eth.personal.sign(hash, 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(hash, publicKey) + } catch (e2) { + this.logger.error('Error on sign.') + this.logger.error(e2) + throw new Error('Error executing personal sign') + } + } + } + public async verifyText(text: string, signature: string): Promise { return this.web3.eth.personal.ecRecover(text, signature) } diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 965221a..bf1e60d 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -33,16 +33,17 @@ describe('Compute', () => { let dataset: DDO let algorithm: DDO let computeService: ServiceCompute + let jobId: string before(async () => { ocean = await Ocean.getInstance(customConfig) ;[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( @@ -116,6 +117,19 @@ describe('Compute', () => { algoMeta ) - assert.equal(response.status, ComputeJobStatus.Started) + assert.isAtLeast(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) }) })