From: Chris Duncan Date: Sat, 26 Jul 2025 07:56:22 +0000 (-0700) Subject: Fix wallet id format. X-Git-Tag: v0.10.5~50^2~14 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=40c83f86b9972c4938df20bd12c5164f5a2ad42b;p=libnemo.git Fix wallet id format. --- diff --git a/src/lib/wallets/bip44-wallet.ts b/src/lib/wallets/bip44-wallet.ts index 3d49ed7..8490ca7 100644 --- a/src/lib/wallets/bip44-wallet.ts +++ b/src/lib/wallets/bip44-wallet.ts @@ -200,6 +200,7 @@ export class Bip44Wallet extends Wallet { if (typeof id !== 'string' || id === '') { throw new TypeError('Wallet ID is required to restore') } + id = id.replace('BIP-44_', '') Bip44Wallet.#isInternal = true return new this(await Entropy.import(id)) } diff --git a/src/lib/wallets/blake2b-wallet.ts b/src/lib/wallets/blake2b-wallet.ts index 9bd6f74..3b465fb 100644 --- a/src/lib/wallets/blake2b-wallet.ts +++ b/src/lib/wallets/blake2b-wallet.ts @@ -149,6 +149,7 @@ export class Blake2bWallet extends Wallet { if (typeof id !== 'string' || id === '') { throw new TypeError('Wallet ID is required to restore') } + id = id.replace('BLAKE2b_', '') Blake2bWallet.#isInternal = true return new this(await Entropy.import(id)) } diff --git a/src/lib/wallets/ledger-wallet.ts b/src/lib/wallets/ledger-wallet.ts index 2a6ea18..ce1b009 100644 --- a/src/lib/wallets/ledger-wallet.ts +++ b/src/lib/wallets/ledger-wallet.ts @@ -177,6 +177,7 @@ export class LedgerWallet extends Wallet { throw new TypeError('Wallet ID is required to restore') } try { + id = id.replace('Ledger_', '') LedgerWallet.#isInternal = true const wallet = new this(await Entropy.import(id)) return wallet @@ -512,7 +513,7 @@ export class LedgerWallet extends Wallet { async ckd (indexes: number[]): Promise { const results: KeyPair[] = [] for (const index of indexes) { - const { status, publicKey } = await this.#account(index) + const { status, publicKey } = await LedgerWallet.#account(index) if (status === 'OK' && publicKey != null) { results.push({ publicKey, index }) } else { diff --git a/src/lib/wallets/wallet.ts b/src/lib/wallets/wallet.ts index a483134..530a822 100644 --- a/src/lib/wallets/wallet.ts +++ b/src/lib/wallets/wallet.ts @@ -39,33 +39,6 @@ export abstract class Wallet { } } - /** - * Reinitializes a wallet from storage using its ID. - * - * @param {string} id - Generated when the wallet was initially created - * @returns {Wallet} Wallet locked with password used when initially created - */ - static async restore (id: string): Promise { - if (typeof id !== 'string' || id === '') { - throw new TypeError('Wallet ID is required to restore') - } - const idSplit = id.split('_') - if (idSplit.length !== 2) { - throw new Error('Invalid wallet ID') - } - const idType = idSplit[0] - if (idType !== 'BIP-44' && idType !== 'BLAKE2b' && idType !== 'Ledger') { - throw new Error('Invalid wallet ID') - } - try { - const idEntropy = await Entropy.import(idSplit[1]) - return new this(idEntropy, idType) - } catch (err) { - console.error(err) - throw new Error('Failed to restore wallet', { cause: err }) - } - } - #accounts: AccountList #id: Entropy #locked: boolean @@ -332,7 +305,7 @@ export abstract class Wallet { if (id == null) { throw new Error('ID is null') } - id = await Entropy.import(id) + id = await Entropy.import(id.split('_')[1]) if (id.hex !== this.#id.hex) { throw new Error('ID does not match') }