From: Chris Duncan Date: Sat, 27 Jun 2026 05:37:47 +0000 (-0700) Subject: Fix autolocking. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=da7138f4781967fd29b649e162f60676761f5a39;p=libnemo.git Fix autolocking. --- diff --git a/src/lib/vault/index.ts b/src/lib/vault/index.ts index e020c39..736add6 100644 --- a/src/lib/vault/index.ts +++ b/src/lib/vault/index.ts @@ -116,6 +116,7 @@ export class Vault { if (typeof isLocked === 'boolean' && this.#isLocked !== isLocked) { this.#isLocked = isLocked this.dispatchEvent(new Event(isLocked ? LOCKED : UNLOCKED)) + if (id === 'autolock') return } const task = this.#tasks.get(id) if (task == null) { diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index 3573311..34e3334 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -127,7 +127,7 @@ async function config (timeout?: number): Promise { throw new RangeError('Timeout must be at most 10 minutes') } _timeout = timeout * 1000 - _timer = new VaultTimer(() => lock(), _timeout) + _timer = new VaultTimer(_autolock, _timeout) } return Promise.resolve() } catch (err) { @@ -188,7 +188,7 @@ async function derive (index?: number): Promise lock(), _timeout) + _timer = new VaultTimer(_autolock, _timeout) return { index, publicKey: pub.buffer } }) } catch (err) { @@ -252,7 +252,7 @@ async function sign (index?: number, data?: ArrayBuffer): Promise lock(), _timeout) + _timer = new VaultTimer(_autolock, _timeout) return { signature: sig.buffer } }) } catch (err) { @@ -295,7 +295,7 @@ async function unlock (type?: WalletType, key?: CryptoKey, iv?: ArrayBuffer, enc _seed = seed _mnemonic = mnemonic _locked = false - _timer = new VaultTimer(lock, _timeout) + _timer = new VaultTimer(_autolock, _timeout) return Promise.resolve({ isLocked: false }) }) .catch(err => { @@ -325,7 +325,7 @@ async function update (key?: CryptoKey, salt?: ArrayBuffer): Promise { - _timer = new VaultTimer(() => lock(), _timeout) + _timer = new VaultTimer(_autolock, _timeout) return { iv, salt, encrypted } }) } catch (err) { @@ -379,6 +379,13 @@ function verify (seed?: ArrayBuffer, mnemonicPhrase?: string): Promise { + const { isLocked } = await lock() + const id = 'autolock' + BROWSER: self.postMessage({ url: location.href, id, isLocked }) + NODE: parentPort?.postMessage({ data: { url: threadId.toString(), id, isLocked } }) +} + function _ckd (index: number): Promise { if (_seed == null) { throw new Error('Wallet seed not found')