Skip to content

Commit

Permalink
NodeJs: bring back generateEd25519Address
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Mar 7, 2024
1 parent 85d30ef commit 4f3a1b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
31 changes: 31 additions & 0 deletions bindings/nodejs/lib/secret_manager/secret-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
GenerateAddressesOptions,
PreparedTransactionData,
LedgerNanoStatus,
CoinType,
GenerateAddressOptions,
} from '../types/client';
import {
Bip44,
Expand Down Expand Up @@ -44,6 +46,35 @@ export class SecretManager {
return new SecretManager(SecretManagerMethodHandler.create(options));
}

/**
* Generate a single Ed25519 address.
*
* @returns The generated Bech32 address.
*/
async generateEd25519Address(
coinType: CoinType,
bech32Hrp: string,
accountIndex?: number,
addressIndex?: number,
address_options?: GenerateAddressOptions,
): Promise<Bech32Address> {
const options = {
coinType,
bech32Hrp,
accountIndex,
addressIndex,
options: address_options,
};
const response = await this.methodHandler.callMethod({
name: 'generateEd25519Addresses',
data: {
options,
},
});

return JSON.parse(response[0]).payload;
}

/**
* Generate multiple Ed25519 addresses at once.
*
Expand Down
21 changes: 10 additions & 11 deletions bindings/nodejs/tests/secret_manager/secret_manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('SecretManager', () => {
let bech32_hrp = Utils.iotaMainnetProtocolParameters().bech32Hrp;

const secretManager = SecretManager.create(mnemonicSecretManager);
const addresses = await secretManager.generateEd25519Addresses({
coinType: CoinType.IOTA,
bech32Hrp: bech32_hrp,
});
const address = await secretManager.generateEd25519Address(
CoinType.IOTA,
bech32_hrp,
);

expect(addresses[0]).toEqual('iota1qpg2xkj66wwgn8p2ggnp7p582gj8g6p79us5hve2tsudzpsr2ap4skprwjg');
expect(address).toEqual('iota1qpg2xkj66wwgn8p2ggnp7p582gj8g6p79us5hve2tsudzpsr2ap4skprwjg');

}, 20000);

Expand All @@ -36,13 +36,12 @@ describe('SecretManager', () => {
let bech32_hrp = Utils.shimmerMainnetProtocolParameters().bech32Hrp;

const secretManager = SecretManager.create(mnemonicSecretManager);
const addresses = await secretManager.generateEd25519Addresses({
coinType: CoinType.Shimmer,
bech32Hrp: bech32_hrp,
range: { start: 0, end: 1 },
});
const address = await secretManager.generateEd25519Address(
CoinType.Shimmer,
bech32_hrp,
);

expect(addresses[0]).toEqual('smr1qzev36lk0gzld0k28fd2fauz26qqzh4hd4cwymlqlv96x7phjxcw6ckj80y');
expect(address).toEqual('smr1qzev36lk0gzld0k28fd2fauz26qqzh4hd4cwymlqlv96x7phjxcw6ckj80y');

}, 20000);
});

0 comments on commit 4f3a1b7

Please sign in to comment.