Skip to content

Commit

Permalink
Merge branch '2.0' into python-compute-delegation-id
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Mar 12, 2024
2 parents bae2e59 + 0a3228c commit 83752f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import {
AccountId,
BlockId,
DelegationId,
FoundryId,
NftId,
TokenId,
Expand Down Expand Up @@ -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.
*
Expand Down
13 changes: 12 additions & 1 deletion bindings/nodejs/tests/utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Utils methods', () => {
expect(isAddressValid).toBeTruthy();
});

it('hash output id', () => {
it('compute account id', () => {
const outputId =
'0x0000000000000000000000000000000000000000000000000000000000000000000000000000';

Expand All @@ -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';
Expand Down
13 changes: 12 additions & 1 deletion bindings/wasm/tests/utilityMethods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Utils methods', () => {
expect(isAddressValid).toBeTruthy();
});

it('hash output id', async () => {
it('compute account id', () => {
const outputId =
'0x0000000000000000000000000000000000000000000000000000000000000000000000000000';

Expand All @@ -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';
Expand Down

0 comments on commit 83752f5

Please sign in to comment.