]> git.codecow.com Git - libnemo.git/commitdiff
Fix wallet import from libnemo ID.
authorChris Duncan <chris@zoso.dev>
Tue, 15 Jul 2025 21:14:56 +0000 (14:14 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 15 Jul 2025 21:14:56 +0000 (14:14 -0700)
src/lib/bip39-mnemonic.ts
src/lib/entropy.ts
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/wallet.ts
test/test.import-wallet.mjs
test/test.main.mjs

index 82645987c9037bab75b15bbe58cfb8b67f6e7836..c1d7cfe4d6e38d3efb930b02c3a28a86147b3445 100644 (file)
@@ -129,7 +129,7 @@ export class Bip39Mnemonic {
                return true\r
        }\r
 \r
-       async toBip39Seed (passphrase: string): Promise<Uint8Array>\r
+       async toBip39Seed (passphrase: string): Promise<Uint8Array<ArrayBuffer>>\r
        /**\r
        * Converts the mnemonic phrase to a BIP-39 seed.\r
        *\r
index f3563a6e768cb76cb90ab20cf1d02cb94e4ee04d..23bc8884264a8ac370e39692ffb051ea59117447 100644 (file)
@@ -87,6 +87,7 @@ export class Entropy {
                                        throw new RangeError('Entropy contains invalid hexadecimal characters')
                                }
                                Entropy.#isInternal = true
+                               debugger
                                resolve(new this(hex.toBytes(input)))
                        }
 
index f6fb518d87fe558da41fc8391a926975999dcd97..200147d6852f0786be35c6c024836959af743e61 100644 (file)
@@ -34,12 +34,12 @@ import { Bip44CkdWorker } from '#workers'
 export class Bip44Wallet extends Wallet {\r
        static #isInternal: boolean = false\r
 \r
-       constructor (id: Entropy, seed: string, mnemonic?: Bip39Mnemonic) {\r
+       constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
                if (!Bip44Wallet.#isInternal) {\r
                        throw new Error(`Bip44Wallet cannot be instantiated directly. Use 'await Bip44Wallet.create()' instead.`)\r
                }\r
                Bip44Wallet.#isInternal = false\r
-               super(id, hex.toBytes(seed), mnemonic)\r
+               super(id, seed, mnemonic)\r
        }\r
 \r
        /**\r
@@ -96,7 +96,7 @@ export class Bip44Wallet extends Wallet {
                        const id = await Entropy.create()\r
                        const e = await Entropy.import(entropy)\r
                        const m = await Bip39Mnemonic.fromEntropy(e.hex)\r
-                       const s = await m.toBip39Seed(salt, 'hex')\r
+                       const s = await m.toBip39Seed(salt)\r
                        Bip44Wallet.#isInternal = true\r
                        wallet = new this(id, s, m)\r
                } catch (err) {\r
@@ -135,7 +135,7 @@ export class Bip44Wallet extends Wallet {
                try {\r
                        const id = await Entropy.create()\r
                        const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
-                       const s = await m.toBip39Seed(salt, 'hex')\r
+                       const s = await m.toBip39Seed(salt)\r
                        Bip44Wallet.#isInternal = true\r
                        wallet = new this(id, s, m)\r
                } catch (err) {\r
@@ -180,7 +180,7 @@ export class Bip44Wallet extends Wallet {
                }\r
                const id = await Entropy.create()\r
                Bip44Wallet.#isInternal = true\r
-               const wallet = new this(id, seed)\r
+               const wallet = new this(id, hex.toBytes(seed))\r
                try {\r
                        await wallet.lock(passkey)\r
                } catch (err) {\r
@@ -202,7 +202,7 @@ export class Bip44Wallet extends Wallet {
                }\r
                Bip44Wallet.#isInternal = true\r
                id = id.replace('libnemo_', '')\r
-               return new this(await Entropy.import(id), '')\r
+               return new this(await Entropy.import(id))\r
        }\r
 \r
        /**\r
index fec4e39a37a3ebbca3ab10437f54da3375e921c3..4cf3c61b6c8443224dfea426049ba59b764a7abd 100644 (file)
@@ -39,7 +39,7 @@ export abstract class Wallet {
                this.#accounts = new AccountList()\r
                this.#id = id\r
                this.#m = mnemonic ?? null\r
-               this.#s = seed ?? new Uint8Array(32)\r
+               this.#s = seed ?? new Uint8Array(0)\r
        }\r
 \r
        /**\r
index df2423e227448b8fbaa2dcae8bbca728cf95f235..938cd8ccbbf0461dcd5dc38318cce41bca2e525e 100644 (file)
@@ -7,7 +7,7 @@ import { assert, suite, test } from './GLOBALS.mjs'
 import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from './VECTORS.js'\r
 import { Account, Bip44Wallet, Blake2bWallet } from '../dist/main.min.js'\r
 \r
-await suite('Import wallets', async () => {\r
+await suite('Import wallets', { skip: true }, async () => {\r
 \r
        await test('nano.org BIP-44 test vector mnemonic', async () => {\r
                const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
@@ -236,7 +236,6 @@ await suite('Retrieve wallets from session storage using a wallet-generated ID',
 \r
        await test('Bip44Wallet', async () => {\r
                const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id\r
-               debugger\r
                const wallet = await Bip44Wallet.restore(id)\r
 \r
                assert.ok('mnemonic' in wallet)\r
index 90f764482ce76a841260bac3a6225b97f7470dc4..c179f9c266d1a479270918662aedc2679163defb 100644 (file)
@@ -1,14 +1,14 @@
 // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-import './test.blake2b.mjs'
-import './test.calculate-pow.mjs'
-import './test.create-wallet.mjs'
-import './test.derive-accounts.mjs'
+// import './test.blake2b.mjs'
+// import './test.calculate-pow.mjs'
+// import './test.create-wallet.mjs'
+// import './test.derive-accounts.mjs'
 import './test.import-wallet.mjs'
 import './test.ledger.mjs'
-import './test.lock-unlock.mjs'
-import './test.manage-rolodex.mjs'
+// import './test.lock-unlock.mjs'
+// import './test.manage-rolodex.mjs'
 import './test.refresh-accounts.mjs'
 import './test.sign-blocks.mjs'
 import './test.tools.mjs'