return wallet\r
}\r
\r
- static async import (id: string) {\r
+ /**\r
+ * Retrieves an existing HD wallet from session 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
Bip44Wallet.#isInternal = true\r
+ if (typeof id !== 'string' || id === '') {\r
+ throw new TypeError('Wallet ID is required to restore')\r
+ }\r
const wallet = new this('', undefined, id)\r
+ return wallet\r
}\r
\r
/**\r
}\r
}\r
\r
- static async import (id: string) {\r
+ /**\r
+ * Retrieves an existing BLAKE2b wallet from session 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
Blake2bWallet.#isInternal = true\r
+ if (typeof id !== 'string' || id === '') {\r
+ throw new TypeError('Wallet ID is required to restore')\r
+ }\r
const wallet = new this('', undefined, id)\r
+ return wallet\r
}\r
\r
/**\r
{ message: 'Seed contains invalid hexadecimal characters.' })\r
})\r
})\r
+\r
+describe('import from storage', async () => {\r
+ it('should retrieve a Bip44Wallet from storage using an ID', async () => {\r
+ const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id\r
+ const wallet = await Bip44Wallet.restore(id)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equal(wallet.mnemonic, '')\r
+ assert.equal(wallet.seed, '')\r
+\r
+ const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equal(unlockResult, true)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equal(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
+ assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
+ })\r
+\r
+ it('should retrieve a Blake2bWallet from storage using an ID', async () => {\r
+ const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id\r
+ const wallet = await Blake2bWallet.restore(id)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equal(wallet.mnemonic, '')\r
+ assert.equal(wallet.seed, '')\r
+\r
+ const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equal(unlockResult, true)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
+ assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ })\r
+})\r