1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
This commit is contained in:
alexcos20 2020-02-11 22:15:42 +02:00
parent dc53af095c
commit b29ac25de1
3 changed files with 41 additions and 19 deletions

View File

@ -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<String>} Result.
*/
public async transferOwnership(did: DID | string, newOwner: string, updated: string, signature: string): Promise<String> {
public async transferOwnership(
did: DID | string,
newOwner: string,
updated: string,
signature: string
): Promise<string> {
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

View File

@ -430,9 +430,17 @@ export class OceanAssets extends Instantiable {
oldOwner
)
// get a signature
const signature=await this.ocean.utils.signature.signForAquarius(oldDdo.updated, account)
const signature = await this.ocean.utils.signature.signForAquarius(
oldDdo.updated,
account
)
if (signature != null)
await this.ocean.aquarius.transferOwnership(did,newOwner,oldDdo.updated,signature)
await this.ocean.aquarius.transferOwnership(
did,
newOwner,
oldDdo.updated,
signature
)
return txReceipt
}

View File

@ -43,13 +43,14 @@ export class SignatureUtils {
}
public async getHash(message: string): Promise<string> {
var hex = ''
for(var i=0;i<message.length;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<string> {
const hash = await this.getHash(message)
const isMetaMask =
@ -57,7 +58,11 @@ export class SignatureUtils {
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
}
}
}