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
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
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
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
}\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
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