]> git.codecow.com Git - libnemo.git/commitdiff
Fix wallet id format.
authorChris Duncan <chris@zoso.dev>
Sat, 26 Jul 2025 07:56:22 +0000 (00:56 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 26 Jul 2025 07:56:22 +0000 (00:56 -0700)
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/blake2b-wallet.ts
src/lib/wallets/ledger-wallet.ts
src/lib/wallets/wallet.ts

index 3d49ed79c219862f6b52c348569d76cceebd1e01..8490ca7923ee44a5fe57c8415606ec3da75f4e38 100644 (file)
@@ -200,6 +200,7 @@ export class Bip44Wallet extends Wallet {
                if (typeof id !== 'string' || id === '') {\r
                        throw new TypeError('Wallet ID is required to restore')\r
                }\r
+               id = id.replace('BIP-44_', '')\r
                Bip44Wallet.#isInternal = true\r
                return new this(await Entropy.import(id))\r
        }\r
index 9bd6f74f1caca0ae4cd673cf42b15fc3f7fb23ed..3b465fba4fc9e988a89ba02681fa649e66a7df59 100644 (file)
@@ -149,6 +149,7 @@ export class Blake2bWallet extends Wallet {
                if (typeof id !== 'string' || id === '') {\r
                        throw new TypeError('Wallet ID is required to restore')\r
                }\r
+               id = id.replace('BLAKE2b_', '')\r
                Blake2bWallet.#isInternal = true\r
                return new this(await Entropy.import(id))\r
        }\r
index 2a6ea18340c8b5de6abe3acffd69119b0a6570ad..ce1b009e9afdb88d9a3199e6448251333802f0fe 100644 (file)
@@ -177,6 +177,7 @@ export class LedgerWallet extends Wallet {
                        throw new TypeError('Wallet ID is required to restore')\r
                }\r
                try {\r
+                       id = id.replace('Ledger_', '')\r
                        LedgerWallet.#isInternal = true\r
                        const wallet = new this(await Entropy.import(id))\r
                        return wallet\r
@@ -512,7 +513,7 @@ export class LedgerWallet extends Wallet {
        async ckd (indexes: number[]): Promise<KeyPair[]> {\r
                const results: KeyPair[] = []\r
                for (const index of indexes) {\r
-                       const { status, publicKey } = await this.#account(index)\r
+                       const { status, publicKey } = await LedgerWallet.#account(index)\r
                        if (status === 'OK' && publicKey != null) {\r
                                results.push({ publicKey, index })\r
                        } else {\r
index a483134763cf67b503a09268ac18efe986ca8ee1..530a8220ef0f7de3040bee9aec26244017fee870 100644 (file)
@@ -39,33 +39,6 @@ export abstract class Wallet {
                }\r
        }\r
 \r
-       /**\r
-       * Reinitializes a wallet from storage using its ID.\r
-       *\r
-       * @param {string} id - Generated when the wallet was initially created\r
-       * @returns {Wallet} Wallet locked with password used when initially created\r
-       */\r
-       static async restore (id: string): Promise<Wallet> {\r
-               if (typeof id !== 'string' || id === '') {\r
-                       throw new TypeError('Wallet ID is required to restore')\r
-               }\r
-               const idSplit = id.split('_')\r
-               if (idSplit.length !== 2) {\r
-                       throw new Error('Invalid wallet ID')\r
-               }\r
-               const idType = idSplit[0]\r
-               if (idType !== 'BIP-44' && idType !== 'BLAKE2b' && idType !== 'Ledger') {\r
-                       throw new Error('Invalid wallet ID')\r
-               }\r
-               try {\r
-                       const idEntropy = await Entropy.import(idSplit[1])\r
-                       return new this(idEntropy, idType)\r
-               } catch (err) {\r
-                       console.error(err)\r
-                       throw new Error('Failed to restore wallet', { cause: err })\r
-               }\r
-       }\r
-\r
        #accounts: AccountList\r
        #id: Entropy\r
        #locked: boolean\r
@@ -332,7 +305,7 @@ export abstract class Wallet {
                        if (id == null) {\r
                                throw new Error('ID is null')\r
                        }\r
-                       id = await Entropy.import(id)\r
+                       id = await Entropy.import(id.split('_')[1])\r
                        if (id.hex !== this.#id.hex) {\r
                                throw new Error('ID does not match')\r
                        }\r