]> git.codecow.com Git - libnemo.git/commitdiff
Move documentation configure reusable index buffer for blake ckd function.
authorChris Duncan <chris@codecow.com>
Wed, 1 Jul 2026 07:29:35 +0000 (00:29 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 1 Jul 2026 07:29:35 +0000 (00:29 -0700)
src/lib/vault/vault-worker.ts

index 6b12f862c72cdeed6aae93030c04258fc02508b0..1d111f79767f413506c5ea70a211739e51acd530 100644 (file)
@@ -386,6 +386,20 @@ async function _autolock (): Promise<void> {
        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<ArrayBuffer>} Private key for the account
+*/
 function _ckd (index: number): Promise<ArrayBuffer> {
        if (_seed == null) {
                throw new Error('Wallet seed not found')
@@ -398,22 +412,9 @@ function _ckd (index: number): Promise<ArrayBuffer> {
                        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<ArrayBuffer>} 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)
                }
        }