From: Chris Duncan Date: Sat, 26 Jul 2025 06:24:46 +0000 (-0700) Subject: Revert restore refactoring. X-Git-Tag: v0.10.5~50^2~16 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=abd8b077acb73573449716460d912bfb31becdb9;p=libnemo.git Revert restore refactoring. --- diff --git a/src/lib/wallets/bip44-wallet.ts b/src/lib/wallets/bip44-wallet.ts index 45a021f..0a3056d 100644 --- a/src/lib/wallets/bip44-wallet.ts +++ b/src/lib/wallets/bip44-wallet.ts @@ -190,6 +190,20 @@ export class Bip44Wallet extends Wallet { return wallet } + /** + * Retrieves an existing HD wallet from storage using its ID. + * + * @param {string} id - Generated when the wallet was initially created + * @returns {Bip44Wallet} Restored locked Bip44Wallet + */ + static async restore (id: string): Promise { + if (typeof id !== 'string' || id === '') { + throw new TypeError('Wallet ID is required to restore') + } + Bip44Wallet.#isInternal = true + return new this(await Entropy.import(id)) + } + /** * Derives BIP-44 Nano account private keys. * diff --git a/src/lib/wallets/blake2b-wallet.ts b/src/lib/wallets/blake2b-wallet.ts index 8dd93a4..9bd6f74 100644 --- a/src/lib/wallets/blake2b-wallet.ts +++ b/src/lib/wallets/blake2b-wallet.ts @@ -139,6 +139,20 @@ export class Blake2bWallet extends Wallet { return wallet } + /** + * Retrieves an existing BLAKE2b wallet from storage using its ID. + * + * @param {string} id - Generated when the wallet was initially created + * @returns {Blake2bWallet} Restored locked Blake2bWallet + */ + static async restore (id: string): Promise { + if (typeof id !== 'string' || id === '') { + throw new TypeError('Wallet ID is required to restore') + } + Blake2bWallet.#isInternal = true + return new this(await Entropy.import(id)) + } + /** * Derives BLAKE2b account private keys. * diff --git a/src/lib/wallets/ledger-wallet.ts b/src/lib/wallets/ledger-wallet.ts index 4eb2552..2a6ea18 100644 --- a/src/lib/wallets/ledger-wallet.ts +++ b/src/lib/wallets/ledger-wallet.ts @@ -166,6 +166,26 @@ export class LedgerWallet extends Wallet { } } + /** + * Retrieves an existing Ledger wallet from storage using its ID. + * + * @param {string} id - Generated when the wallet was initially created + * @returns {LedgerWallet} Restored LedgerWallet + */ + static async restore (id: string): Promise { + if (typeof id !== 'string' || id === '') { + throw new TypeError('Wallet ID is required to restore') + } + try { + LedgerWallet.#isInternal = true + const wallet = new this(await Entropy.import(id)) + return wallet + } catch (err) { + console.error(err) + throw new Error('failed to restore wallet', { cause: err }) + } + } + /** * Sign a block with the Ledger device. *