]> git.codecow.com Git - libnemo.git/commitdiff
Revert restore refactoring.
authorChris Duncan <chris@zoso.dev>
Sat, 26 Jul 2025 06:24:46 +0000 (23:24 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 26 Jul 2025 06:24:46 +0000 (23:24 -0700)
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/blake2b-wallet.ts
src/lib/wallets/ledger-wallet.ts

index 45a021f5b5062d58b84a8c4da18621da38a7a2ce..0a3056dbe06e05d5136a8935a67bb46f68d6a68f 100644 (file)
@@ -190,6 +190,20 @@ export class Bip44Wallet extends Wallet {
                return wallet\r
        }\r
 \r
+       /**\r
+       * Retrieves an existing HD wallet from storage using its ID.\r
+       *\r
+       * @param {string} id - Generated when the wallet was initially created\r
+       * @returns {Bip44Wallet} Restored locked Bip44Wallet\r
+       */\r
+       static async restore (id: string): Promise<Bip44Wallet> {\r
+               if (typeof id !== 'string' || id === '') {\r
+                       throw new TypeError('Wallet ID is required to restore')\r
+               }\r
+               Bip44Wallet.#isInternal = true\r
+               return new this(await Entropy.import(id))\r
+       }\r
+\r
        /**\r
        * Derives BIP-44 Nano account private keys.\r
        *\r
index 8dd93a4d2d447d20195d2953bdca51506d38deae..9bd6f74f1caca0ae4cd673cf42b15fc3f7fb23ed 100644 (file)
@@ -139,6 +139,20 @@ export class Blake2bWallet extends Wallet {
                return wallet\r
        }\r
 \r
+       /**\r
+       * Retrieves an existing BLAKE2b wallet from storage using its ID.\r
+       *\r
+       * @param {string} id - Generated when the wallet was initially created\r
+       * @returns {Blake2bWallet} Restored locked Blake2bWallet\r
+       */\r
+       static async restore (id: string): Promise<Blake2bWallet> {\r
+               if (typeof id !== 'string' || id === '') {\r
+                       throw new TypeError('Wallet ID is required to restore')\r
+               }\r
+               Blake2bWallet.#isInternal = true\r
+               return new this(await Entropy.import(id))\r
+       }\r
+\r
        /**\r
        * Derives BLAKE2b account private keys.\r
        *\r
index 4eb2552aaf2d9014e096f4b4b3e5bf9edce82402..2a6ea18340c8b5de6abe3acffd69119b0a6570ad 100644 (file)
@@ -166,6 +166,26 @@ export class LedgerWallet extends Wallet {
                }\r
        }\r
 \r
+       /**\r
+       * Retrieves an existing Ledger wallet from storage using its ID.\r
+       *\r
+       * @param {string} id - Generated when the wallet was initially created\r
+       * @returns {LedgerWallet} Restored LedgerWallet\r
+       */\r
+       static async restore (id: string): Promise<LedgerWallet> {\r
+               if (typeof id !== 'string' || id === '') {\r
+                       throw new TypeError('Wallet ID is required to restore')\r
+               }\r
+               try {\r
+                       LedgerWallet.#isInternal = true\r
+                       const wallet = new this(await Entropy.import(id))\r
+                       return wallet\r
+               } catch (err) {\r
+                       console.error(err)\r
+                       throw new Error('failed to restore wallet', { cause: err })\r
+               }\r
+       }\r
+\r
        /**\r
        * Sign a block with the Ledger device.\r
        *\r