diff --git a/src/keeper/contracts/DIDRegistry.ts b/src/keeper/contracts/DIDRegistry.ts index 13f29e1..a790b20 100644 --- a/src/keeper/contracts/DIDRegistry.ts +++ b/src/keeper/contracts/DIDRegistry.ts @@ -1,3 +1,4 @@ +import { TransactionReceipt } from 'web3-core' import ContractBase from './ContractBase' import { zeroX, didPrefixed, didZeroX } from '../../utils' import { InstantiableConfig } from '../../Instantiable.abstract' @@ -60,4 +61,8 @@ export default class DIDRegistry extends ContractBase { public async getPermission(did: string, grantee: string): Promise { return this.call('getPermission', [didZeroX(did), zeroX(grantee)]) } + + public async transferDIDOwnership(did: string, owner: string, newOwner: string): Promise { + return this.send('transferDIDOwnership', owner, [zeroX(did), zeroX(newOwner)]) + } } diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 18a989a..dff3a96 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -1,3 +1,4 @@ +import { TransactionReceipt } from 'web3-core' import { SearchQuery } from '../aquarius/Aquarius' import { DDO } from '../ddo/DDO' import { MetaData } from '../ddo/MetaData' @@ -355,6 +356,17 @@ export class OceanAssets extends Instantiable { return this.ocean.keeper.didRegistry.getAttributesByOwner(owner) } + /** + * Transfer ownership of an asset. + * @param {string} did Asset DID. + * @param {string} owner Ethereum address of the current owner of the DID. + * @param {string} newOwner Ethereum address of the new owner of the DID. + * @return {Promise} Returns Web3 transaction receipt. + */ + public async transferOwnership(did: string, owner: string, newOwner: string): Promise { + return this.ocean.keeper.didRegistry.transferDIDOwnership(did, owner, newOwner) + } + /** * Returns the assets of a consumer. * @param {string} consumer Consumer address. diff --git a/test/keeper/DIDRegistry.test.ts b/test/keeper/DIDRegistry.test.ts index d1a2e34..581c81b 100644 --- a/test/keeper/DIDRegistry.test.ts +++ b/test/keeper/DIDRegistry.test.ts @@ -13,7 +13,7 @@ describe('DIDRegistry', () => { before(async () => { await TestContractHandler.prepareContracts() ocean = await Ocean.getInstance(config) - didRegistry = ocean.keeper.didRegistry + ;({ didRegistry } = ocean.keeper) }) describe('#registerAttribute()', () => { @@ -67,4 +67,22 @@ describe('DIDRegistry', () => { assert.equal(owner, `0x${'0'.repeat(40)}`) }) }) + + describe('#transferDIDOwnership()', () => { + it('should be able to transfer ownership', async () => { + // create and register DID + const ownerAccount: Account = (await ocean.accounts.list())[0] + const did = generateId() + const data = 'my nice provider, is nice' + await didRegistry.registerAttribute(did, '0123456789abcdef', [], data, ownerAccount.getId()) + + // transfer + const newOwnerAccount: Account = (await ocean.accounts.list())[1] + await didRegistry.transferDIDOwnership(did, ownerAccount.getId(), newOwnerAccount.getId()) + + // check + const newOwner = await didRegistry.getDIDOwner(did) + assert.equal(newOwner, newOwnerAccount.getId(), `Got ${newOwner} but expected ${newOwnerAccount.getId()}`) + }) + }) })