Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add computeDelegationId util to JS bindings #2172

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading