diff --git a/bindings/nodejs/lib/secret_manager/secret-manager.ts b/bindings/nodejs/lib/secret_manager/secret-manager.ts index 3f65aa864d..235bf2c255 100644 --- a/bindings/nodejs/lib/secret_manager/secret-manager.ts +++ b/bindings/nodejs/lib/secret_manager/secret-manager.ts @@ -6,6 +6,8 @@ import type { GenerateAddressesOptions, PreparedTransactionData, LedgerNanoStatus, + CoinType, + GenerateAddressOptions, } from '../types/client'; import { Bip44, @@ -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 { + 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. * diff --git a/bindings/nodejs/tests/secret_manager/secret_manager.spec.ts b/bindings/nodejs/tests/secret_manager/secret_manager.spec.ts index 98a4a00336..3a79d919d5 100644 --- a/bindings/nodejs/tests/secret_manager/secret_manager.spec.ts +++ b/bindings/nodejs/tests/secret_manager/secret_manager.spec.ts @@ -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); @@ -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); });