1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Add owner method on assets module.

This commit is contained in:
Pedro Gutiérrez 2019-04-15 15:30:02 +02:00 committed by Pedro Gutiérrez
parent f35878be73
commit 652d4e7575
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import { assert } from "chai"
import { config } from "../config"
import { getMetadata } from "../utils"
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
describe("Asset Owners", () => {
let ocean: Ocean
let publisher: Account
const metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
publisher = (await ocean.accounts.list())[0]
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
})
it("should be set correctly the owner of a asset", async () => {
const ddo = await ocean.assets.create(metadata as any, publisher)
const owner = await ocean.assets.owner(ddo.id)
assert.equal(owner, publisher.getId())
})
})

View File

@ -259,6 +259,24 @@ export class OceanAssets extends Instantiable {
return agreementId
}
/**
* Returns the owner of a asset.
* @param {string} did Decentralized ID.
* @return {Promise<string>} Returns Agreement ID
*/
public async owner(did: string): Promise<string> {
const ddo = await this.resolve(did)
const checksum = ddo.getChecksum()
const {creator, signatureValue} = ddo.proof
const signer = await this.ocean.utils.signature.verifyText(checksum, signatureValue)
if (signer.toLowerCase() !== creator.toLowerCase()) {
this.logger.warn(`Owner of ${ddo.id} doesn't match. Expected ${creator} instead of ${signer}.`)
}
return creator
}
/**
* Search over the assets using a query.
* @param {SearchQuery} query Query to filter the assets.