diff --git a/packages/sdk/src/addresses/index.ts b/packages/sdk/src/addresses/index.ts index af8ed53f..9bc5b56d 100644 --- a/packages/sdk/src/addresses/index.ts +++ b/packages/sdk/src/addresses/index.ts @@ -143,18 +143,19 @@ export function getAccountDataFromHdNode({ return accountData } -export function getAllAccountsFromHdNode({ hdNode, network = "testnet" }: GetAllAccountsFromHDNodeOptions) { +export function getAllAccountsFromHdNode({ hdNode, network = "testnet", account = 0, addressIndex = 0 }: GetAllAccountsFromHDNodeOptions) { const accounts: Account[] = [] const addressTypesList = Object.values(addressTypeToName) as AddressFormats[] addressTypesList.forEach((addrType) => { - const account = getAccountDataFromHdNode({ + const walletAccount = getAccountDataFromHdNode({ hdNode, format: addrType, - network + network, + account, addressIndex }) - accounts.push(account) + accounts.push(walletAccount) }) return accounts diff --git a/packages/sdk/src/wallet/Ordit.ts b/packages/sdk/src/wallet/Ordit.ts index dba34bd5..aa2a29d0 100644 --- a/packages/sdk/src/wallet/Ordit.ts +++ b/packages/sdk/src/wallet/Ordit.ts @@ -37,7 +37,7 @@ export class Ordit { selectedAddressType: AddressFormats | undefined selectedAddress: string | undefined - constructor({ wif, seed, privateKey, bip39, network = "testnet", type = "legacy" }: WalletOptions) { + constructor({ wif, seed, privateKey, bip39, network = "testnet", type = "legacy", account = 0, addressIndex = 0 }: WalletOptions) { this.#network = network const networkObj = getNetwork(network) const format = addressNameToType[type] @@ -65,7 +65,7 @@ export class Ordit { this.#hdNode = hdNode - const accounts = getAllAccountsFromHdNode({ hdNode, network }) + const accounts = getAllAccountsFromHdNode({ hdNode, network, account, addressIndex }) const pkBuf = Buffer.from(accounts[0].priv, "hex") this.#keyPair = ECPair.fromPrivateKey(pkBuf, { network: networkObj }) @@ -79,7 +79,7 @@ export class Ordit { this.#hdNode = hdNode - const accounts = getAllAccountsFromHdNode({ hdNode, network }) + const accounts = getAllAccountsFromHdNode({ hdNode, network, account, addressIndex }) this.#keyPair = accounts[0].child this.publicKey = this.#keyPair.publicKey.toString("hex") @@ -266,6 +266,8 @@ export type WalletOptions = { bip39?: string network?: Network type?: AddressFormats + account?: number; + addressIndex?: number; } export type Address = ReturnType[0]