From 1e2f2113ccb00f5428d6a2ad9b7c2a2ca6044297 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 1 Jul 2026 00:29:35 -0700 Subject: [PATCH] Move documentation configure reusable index buffer for blake ckd function. --- src/lib/vault/vault-worker.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index 6b12f86..1d111f7 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -386,6 +386,20 @@ async function _autolock (): Promise { NODE: parentPort?.postMessage({ data: { url: threadId.toString(), id, isLocked } }) } +const _index = new DataView(new ArrayBuffer(4)) +/** + * Derives account private keys from the wallet seed using either the BIP-44 + * derivation algorithm or the BLAKE2b hashing algorithm. + * + * Separately, account public keys are derived from the private key using the + * Ed25519 key algorithm, and account addresses are derived from the public key + * as described in the Nano documentation. + * + * https://docs.nano.org/integration-guides/the-basics/ + * + * @param {number} index - 4-byte index of account to derive + * @returns {Promise} Private key for the account +*/ function _ckd (index: number): Promise { if (_seed == null) { throw new Error('Wallet seed not found') @@ -398,22 +412,9 @@ function _ckd (index: number): Promise { return Bip44('Bitcoin seed', _seed, 0x100, index, 0, 0) } default: { - /** - * Derives account private keys from a wallet seed using the BLAKE2b hashing - * algorithm. - * - * Separately, account public keys are derived from the private key using the - * Ed25519 key algorithm, and account addresses are derived from the public key - * as described in the Nano documentation. - * https://docs.nano.org/integration-guides/the-basics/ - * - * @param {ArrayBuffer} seed - 32-byte secret seed of the wallet - * @param {number} index - 4-byte index of account to derive - * @returns {Promise} Private key for the account - */ - const i = new ArrayBuffer(4) - new DataView(i).setUint32(0, index, false) - const sk = new Blake2b(32).update(_seed).update(i).digest() + _index.setUint32(0, index, false) + const sk = new Blake2b(32).update(_seed).update(_index.buffer).digest() + _index.setUint32(0, 0) return Promise.resolve(sk.buffer) } } -- 2.52.0