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
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
}\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
- const transport = LedgerWallet.checkBrowserSupport()\r
- LedgerWallet.#isInternal = true\r
- const wallet = new this(await Entropy.import(id))\r
- wallet.DynamicTransport = transport\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
}\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
#s?: Uint8Array<ArrayBuffer>\r
#type: WalletType\r
\r
- get id () { return this.#id.hex }\r
+ get id () { return `${this.type}_${this.#id.hex}` }\r
get isLocked () { return this.#locked }\r
get isUnlocked () { return !this.#locked }\r
get mnemonic () {\r