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

Bindings: Streamline address generation methods #2158

Draft
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Draft
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
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);
});
Loading