"url": "git+https://zoso.dev/libnemo.git"
},
"scripts": {
- "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js ckd=dist/lib/ckd.js --outdir=dist --target=es2022 --format=esm --platform=node --bundle --minify --sourcemap",
+ "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js --outdir=dist --target=es2022 --format=esm --platform=browser --bundle --minify --sourcemap",
"test": "npm run build && node --test --test-force-exit --env-file .env",
"test:coverage": "npm run test -- --experimental-test-coverage",
"test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html"
import { buffer, hex, utf8 } from './convert.js'
import { Entropy } from './entropy.js'
+// import { Thread } from './thread.js'
const { subtle } = globalThis.crypto
const ERR_MSG = 'Failed to store item in Safe'
export class Safe {
#storage = globalThis.sessionStorage
+ // #thread = new Thread(new URL('./ckd.js', import.meta.url))
/**
* Encrypts data with a password and stores it in the Safe.
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
\r
+import blake2b from 'blake2b-wasm'\r
import { Account } from './account.js'\r
+import { nanoCKD } from './bip32-key-derivation.js'\r
import { Bip39Mnemonic } from './bip39-mnemonic.js'\r
import { ADDRESS_GAP, SEED_LENGTH_BIP44, SEED_LENGTH_BLAKE2B } from './constants.js'\r
+import { dec, hex } from './convert.js'\r
import { Entropy } from './entropy.js'\r
-import { Thread } from './thread.js'\r
import { Rpc } from './rpc.js'\r
import { Safe } from './safe.js'\r
import type { Ledger } from './ledger.js'\r
*/\r
export class Bip44Wallet extends Wallet {\r
static #isInternal: boolean = false\r
- #thread: Thread\r
\r
constructor (seed: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
if (!Bip44Wallet.#isInternal) {\r
throw new Error(`Bip44Wallet cannot be instantiated directly. Use 'await Bip44Wallet.create()' instead.`)\r
}\r
super(seed, mnemonic, id)\r
- this.#thread = new Thread(new URL('./ckd.js', import.meta.url))\r
Bip44Wallet.#isInternal = false\r
}\r
\r
* @returns {Promise<Account>}\r
*/\r
async ckd (index: number): Promise<Account> {\r
- const key = await this.#thread.work({ type: 'bip44', seed: this.seed, index })\r
+ const key = await nanoCKD(this.seed, index)\r
if (typeof key !== 'string') {\r
throw new TypeError('BIP-44 child key derivation returned invalid data')\r
}\r
*/\r
export class Blake2bWallet extends Wallet {\r
static #isInternal: boolean = false\r
- #thread: Thread\r
\r
constructor (seed: string, mnemonic?: Bip39Mnemonic, id?: string) {\r
if (!Blake2bWallet.#isInternal) {\r
throw new Error(`Blake2bWallet cannot be instantiated directly. Use 'await Blake2bWallet.create()' instead.`)\r
}\r
super(seed, mnemonic, id)\r
- this.#thread = new Thread(new URL('./ckd.js', import.meta.url))\r
Blake2bWallet.#isInternal = false\r
}\r
\r
* @returns {Promise<Account>}\r
*/\r
async ckd (index: number): Promise<Account> {\r
- const key = await this.#thread.work({ type: 'blake2b', seed: this.seed, index })\r
+ const input = `${this.seed}${dec.toHex(index, 8)}`\r
+ const key = blake2b().update(hex.toBytes(input)).digest('hex')\r
if (typeof key !== 'string') {\r
throw new TypeError('BLAKE2b child key derivation returned invalid data')\r
}\r
import { NANO_TEST_VECTORS } from './TEST_VECTORS.js'\r
import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.js'\r
\r
-const skip = true\r
-\r
// WARNING: Do not send any funds to the test vectors below\r
// Test vectors from https://docs.nano.org/integration-guides/key-management/ and elsewhere\r
describe('derive child accounts from the same seed', async function () {\r
})\r
})\r
\r
-describe('child key derivation performance', { skip }, async () => {\r
+describe('child key derivation performance', { skip: true }, async () => {\r
it('performance test of BIP-44 ckd', async function () {\r
const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r