From 827a7f0bf1df93acd4236d894ef22a6c4c35a585 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 7 Aug 2026 23:33:45 -0700 Subject: [PATCH] Fix signing calls to also pass index as u32. --- src/lib/vault/parsers.ts | 8 ++++---- src/lib/vault/vault-worker.ts | 20 ++++++++++---------- src/lib/wallet/accounts.ts | 5 ++--- src/lib/wallet/sign.ts | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/lib/vault/parsers.ts b/src/lib/vault/parsers.ts index dc0705f..1fd9405 100644 --- a/src/lib/vault/parsers.ts +++ b/src/lib/vault/parsers.ts @@ -81,11 +81,11 @@ export function parseData (action: string, data: Record) { delete data.encrypted } - // Index for child account to derive or sign - if ((action === 'derive' || action === 'sign') && !(data.indexes instanceof ArrayBuffer)) { + // Index(es) for child account to derive or sign + if ((action === 'derive' || action === 'sign') && !(data.index instanceof ArrayBuffer)) { throw new TypeError('Index is required to derive an account private key') } - const indexes = typeof data.indexes instanceof ArrayBuffer + const index = data.index instanceof ArrayBuffer ? new Uint32Array(data.index) : undefined @@ -114,7 +114,7 @@ export function parseData (action: string, data: Record) { ? data.timeout : undefined - return { seed, mnemonicPhrase, mnemonicSalt, encrypted, index, count, message, timeout } + return { seed, mnemonicPhrase, mnemonicSalt, encrypted, index, message, timeout } } catch (err) { new Uint8Array(seed ?? []).fill(0) new Uint8Array(encrypted ?? []).fill(0) diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index 028bbe2..8f166a2 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -40,7 +40,7 @@ const listener = (event: MessageEvent): void => { const id = parseId(action, data) const iv = parseIv(action, data) const parsed = parseData(action, data) - const { seed, mnemonicPhrase, mnemonicSalt, indexes, encrypted, message, timeout } = parsed + const { seed, mnemonicPhrase, mnemonicSalt, index, encrypted, message, timeout } = parsed passkey(action, keySalt, data) .then((key: CryptoKey | undefined): Promise | void> => { switch (action) { @@ -56,7 +56,7 @@ const listener = (event: MessageEvent): void => { return create(type, id, key, keySalt, mnemonicSalt) } case 'derive': { - return derive(indexes) + return derive(index) } case 'load': { return load(type, id, key, keySalt, mnemonicPhrase ?? seed, mnemonicSalt) @@ -170,7 +170,7 @@ function create (type?: WalletType, id?: UUID, key?: CryptoKey, keySalt?: ArrayB * wallet seed at a specified index and then returns the public key. The wallet * must be unlocked prior to derivation. */ -function derive (indexes?: Uint32Array): Promise> { +function derive (index?: number | Uint32Array): Promise> { try { _timer.pause() if (_locked) { @@ -182,17 +182,17 @@ function derive (indexes?: Uint32Array): Promise { + const values = typeof index === 'number' ? [index] : index.values() + for (const i of values) { + promises.push(_ckd(i).then(result => { const prv = new Uint8Array(result) const pub = nano25519_derive(prv) prv.fill(0) - return { index, publicKey: pub.buffer } + return { index: i, publicKey: pub.buffer } })) } return Promise.all(promises) @@ -252,7 +252,7 @@ function lock (): Promise> { * Derives the account private key at a specified index, signs the input data, * and returns a signature. The wallet must be unlocked prior to verification. */ -function sign (index?: number, data?: ArrayBuffer): Promise> { +function sign (index?: Uint32Array, data?: ArrayBuffer): Promise> { try { _timer.pause() if (_locked) { @@ -267,7 +267,7 @@ function sign (index?: number, data?: ArrayBuffer): Promise { + return _ckd(index[0]).then(result => { const prv = new Uint8Array(result) const pub = nano25519_derive(prv) const sk = new Uint8Array([...prv, ...pub]) diff --git a/src/lib/wallet/accounts.ts b/src/lib/wallet/accounts.ts index 0ec8d86..ed5fc16 100644 --- a/src/lib/wallet/accounts.ts +++ b/src/lib/wallet/accounts.ts @@ -46,12 +46,11 @@ export async function _accounts (type: WalletType, accounts: Map({ action: 'derive', - indexes + index: buffer }) - console.log(publicKeys) for (const [index, publicKey] of Object.entries(publicKeys)) { if (typeof Number(index) === 'number' && publicKey instanceof ArrayBuffer) { const account = new Account(publicKey) diff --git a/src/lib/wallet/sign.ts b/src/lib/wallet/sign.ts index 6cf000d..500b035 100644 --- a/src/lib/wallet/sign.ts +++ b/src/lib/wallet/sign.ts @@ -40,7 +40,7 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, } else { const { signature } = await vault.request({ action: 'sign', - index, + index: new Uint32Array([index]).buffer, message: hex.toBuffer(block.hash) }) block.signature = bytes.toHex(new Uint8Array(signature)) @@ -74,7 +74,7 @@ export async function _signData (wallet: Wallet, vault: Vault, index: unknown, a } const { signature } = await vault.request({ action: 'sign', - index, + index: new Uint32Array([index]).buffer, message: utf8.toBuffer(data) }) return bytes.toHex(new Uint8Array(signature)) -- 2.52.0