diff --git a/bindings/nodejs/lib/utils/utils.ts b/bindings/nodejs/lib/utils/utils.ts index 073be7a5bb..d70e553722 100644 --- a/bindings/nodejs/lib/utils/utils.ts +++ b/bindings/nodejs/lib/utils/utils.ts @@ -26,6 +26,7 @@ import { import { AccountId, BlockId, + DelegationId, FoundryId, NftId, TokenId, @@ -77,6 +78,21 @@ export class Utils { }); } + /** + * Compute the delegation ID from a given delegation output ID. + * + * @param outputId The output ID as hex-encoded string. + * @returns The delegation ID. + */ + static computeDelegationId(outputId: OutputId): DelegationId { + return callUtilsMethod({ + name: 'blake2b256Hash', + data: { + bytes: outputId, + }, + }); + } + /** * Compute the Foundry ID. * diff --git a/bindings/nodejs/tests/utils/utils.spec.ts b/bindings/nodejs/tests/utils/utils.spec.ts index 300a918eac..683f93de8b 100644 --- a/bindings/nodejs/tests/utils/utils.spec.ts +++ b/bindings/nodejs/tests/utils/utils.spec.ts @@ -39,7 +39,7 @@ describe('Utils methods', () => { expect(isAddressValid).toBeTruthy(); }); - it('hash output id', () => { + it('compute account id', () => { const outputId = '0x0000000000000000000000000000000000000000000000000000000000000000000000000000'; @@ -50,6 +50,17 @@ describe('Utils methods', () => { ); }); + it('compute delegation id', () => { + const outputId = + '0x0000000000000000000000000000000000000000000000000000000000000000000000000000'; + + const delegationId = Utils.computeDelegationId(outputId); + + expect(delegationId).toBe( + '0x0ebc2867a240719a70faacdfc3840e857fa450b37d95297ac4f166c2f70c3345', + ); + }); + it('compute foundry id', () => { const accountId = '0xcf077d276686ba64c0404b9eb2d15556782113c5a1985f262b70f9964d3bbd7f'; diff --git a/bindings/wasm/tests/utilityMethods.spec.ts b/bindings/wasm/tests/utilityMethods.spec.ts index fbcf791456..cf6bd08e07 100644 --- a/bindings/wasm/tests/utilityMethods.spec.ts +++ b/bindings/wasm/tests/utilityMethods.spec.ts @@ -48,7 +48,7 @@ describe('Utils methods', () => { expect(isAddressValid).toBeTruthy(); }); - it('hash output id', async () => { + it('compute account id', () => { const outputId = '0x0000000000000000000000000000000000000000000000000000000000000000000000000000'; @@ -59,6 +59,17 @@ describe('Utils methods', () => { ); }); + it('compute delegation id', () => { + const outputId = + '0x0000000000000000000000000000000000000000000000000000000000000000000000000000'; + + const delegationId = Utils.computeDelegationId(outputId); + + expect(delegationId).toBe( + '0x0ebc2867a240719a70faacdfc3840e857fa450b37d95297ac4f166c2f70c3345', + ); + }); + it('account id to address', async () => { const accountId = '0x0ebc2867a240719a70faacdfc3840e857fa450b37d95297ac4f166c2f70c3345';