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:
parent
f35878be73
commit
652d4e7575
31
integration/ocean/AssetOwners.test.ts
Normal file
31
integration/ocean/AssetOwners.test.ts
Normal 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())
|
||||||
|
})
|
||||||
|
})
|
@ -259,6 +259,24 @@ export class OceanAssets extends Instantiable {
|
|||||||
return agreementId
|
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.
|
* Search over the assets using a query.
|
||||||
* @param {SearchQuery} query Query to filter the assets.
|
* @param {SearchQuery} query Query to filter the assets.
|
||||||
|
Loading…
Reference in New Issue
Block a user