diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index 8a757d2..dbaa6a8 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -3,7 +3,6 @@ import { DDO } from '../ddo/DDO' import DID from '../ocean/DID' import { Logger } from '../utils' import { WebServiceConnector } from '../ocean/utils/WebServiceConnector' -import { Account } from '../squid' const apiPath = '/api/v1/aquarius/assets/ddo' @@ -250,7 +249,6 @@ export class Aquarius { return result } - /** * Transfer ownership of a DDO * @param {DID | string} did DID of the asset to update. @@ -259,11 +257,23 @@ export class Aquarius { * @param {String} signature Signature using updated field to verify that the consumer has rights * @return {Promise} Result. */ - public async transferOwnership(did: DID | string, newOwner: string, updated: string, signature: string): Promise { + public async transferOwnership( + did: DID | string, + newOwner: string, + updated: string, + signature: string + ): Promise { did = did && DID.parse(did) const fullUrl = `${this.url}${apiPath}/transferownership/${did.getDid()}` const result = await this.fetch - .put(fullUrl, JSON.stringify({signature: signature, updated: updated, newowner: newOwner})) + .put( + fullUrl, + JSON.stringify({ + signature: signature, + updated: updated, + newowner: newOwner + }) + ) .then((response: any) => { if (response.ok) { return response.text @@ -273,9 +283,9 @@ export class Aquarius { response.status, response.statusText ) - return null + return null }) - + .catch(error => { this.logger.error('Error updating metadata: ', error) return null diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 7a25689..69db15d 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -429,10 +429,18 @@ export class OceanAssets extends Instantiable { newOwner, oldOwner ) - //get a signature - const signature=await this.ocean.utils.signature.signForAquarius(oldDdo.updated, account) - if(signature!=null) - await this.ocean.aquarius.transferOwnership(did,newOwner,oldDdo.updated,signature) + // get a signature + const signature = await this.ocean.utils.signature.signForAquarius( + oldDdo.updated, + account + ) + if (signature != null) + await this.ocean.aquarius.transferOwnership( + did, + newOwner, + oldDdo.updated, + signature + ) return txReceipt } diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 23d7beb..2f269ae 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -42,22 +42,27 @@ export class SignatureUtils { return this.web3.eth.personal.ecRecover(text, signature) } - public async getHash(message:string): Promise { - var hex = '' - for(var i=0;i { + let hex = '' + for (let i = 0; i < message.length; i++) { + hex += '' + message.charCodeAt(i).toString(16) } - var hexMessage = "0x" + hex + const hexMessage = '0x' + hex return hexMessage as string } - public async signForAquarius(message:string, account:Account): Promise { - const hash=await this.getHash(message) + + public async signForAquarius(message: string, account: Account): Promise { + const hash = await this.getHash(message) const isMetaMask = this.web3 && this.web3.currentProvider && (this.web3.currentProvider as any).isMetaMask try { - return this.web3.eth.personal.sign(hash, account.getId(),account.getPassword()) + return this.web3.eth.personal.sign( + hash, + account.getId(), + account.getPassword() + ) } catch (e) { if (isMetaMask) { throw e @@ -66,6 +71,5 @@ export class SignatureUtils { this.logger.warn(e) return null } - } }