mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
lint
This commit is contained in:
parent
dc53af095c
commit
b29ac25de1
@ -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
|
||||
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -42,22 +42,27 @@ export class SignatureUtils {
|
||||
return this.web3.eth.personal.ecRecover(text, signature)
|
||||
}
|
||||
|
||||
public async getHash(message:string): Promise<string> {
|
||||
var hex = ''
|
||||
for(var i=0;i<message.length;i++) {
|
||||
hex += ''+message.charCodeAt(i).toString(16)
|
||||
public async getHash(message: string): Promise<string> {
|
||||
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)
|
||||
|
||||
public async signForAquarius(message: string, account: Account): Promise<string> {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user