From: Chris Duncan Date: Mon, 18 Aug 2025 19:23:53 +0000 (-0700) Subject: Reduce lock timeout to two minutes from five. X-Git-Tag: v0.10.5~41^2~63 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=5edb6769cb5a224f7516b063f448c7c546f44410;p=libnemo.git Reduce lock timeout to two minutes from five. --- diff --git a/src/lib/vault/vault.ts b/src/lib/vault/vault.ts index fcf1591..fa72b9c 100644 --- a/src/lib/vault/vault.ts +++ b/src/lib/vault/vault.ts @@ -152,7 +152,7 @@ export class Vault { ? await Bip44.ckd(this.#seed, BIP44_COIN_NANO, index) : await this.#deriveBlake2bPrivateKey(this.#seed, index) const pub = await NanoNaCl.convert(new Uint8Array(prv)) - this.#timeout = new Timer(() => this.lock(), 300000) + this.#timeout = new Timer(() => this.lock(), 120000) return { index, publicKey: pub.buffer } } catch (err) { console.error(err) @@ -181,10 +181,10 @@ export class Vault { } static lock (): NamedData { - this.#timeout?.pause() this.#mnemonic = undefined this.#seed = undefined this.#locked = true + this.#timeout?.pause() return { isLocked: this.#locked } } @@ -211,7 +211,7 @@ export class Vault { ? await Bip44.ckd(this.#seed, BIP44_COIN_NANO, index) : await this.#deriveBlake2bPrivateKey(this.#seed, index) const sig = await NanoNaCl.detached(new Uint8Array(data), new Uint8Array(prv)) - this.#timeout = new Timer(() => this.lock(), 300000) + this.#timeout = new Timer(() => this.lock(), 120000) return { signature: sig.buffer } } catch (err) { console.error(err) @@ -246,7 +246,7 @@ export class Vault { throw new TypeError('Invalid mnemonic') } this.#locked = false - this.#timeout = new Timer(() => this.lock(), 300000) + this.#timeout = new Timer(() => this.lock(), 120000) return { isUnlocked: !this.#locked } } catch (err) { console.error(err) @@ -271,7 +271,7 @@ export class Vault { } this.#timeout.pause() const { iv, encrypted } = await this.#encryptWallet(key) - this.#timeout = new Timer(() => this.lock(), 300000) + this.#timeout = new Timer(() => this.lock(), 120000) return { iv, salt: keySalt, encrypted } } catch (err) { console.error(err) @@ -320,7 +320,7 @@ export class Vault { return { isVerified } } catch (err) { console.error(err) - throw new Error('Failed to export wallet', { cause: err }) + throw new Error('Failed to verify wallet', { cause: err }) } } diff --git a/test/test.lock-unlock.mjs b/test/test.lock-unlock.mjs index 6ea0077..23f8041 100644 --- a/test/test.lock-unlock.mjs +++ b/test/test.lock-unlock.mjs @@ -115,7 +115,7 @@ await Promise.all([ await assert.resolves(wallet.destroy()) }) - await test('wallet automatic lock resets after user activity', { skip: true }, async () => { + await test('wallet automatic lock resets after user activity', { skip: false }, async () => { const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -123,34 +123,34 @@ await Promise.all([ assert.ok(await wallet.verify(NANO_TEST_VECTORS.BIP39_SEED)) await new Promise(async (resolve) => { - console.log('Waiting 3 minutes...') + console.log('Waiting 1 minute...') setTimeout(async () => { // should still be unlocked const account = await wallet.account(0) assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0) resolve(null) - }, 180000) + }, 60000) }) await new Promise(async (resolve) => { - console.log('Timer should be reset, waiting 3 minutes...') + console.log('Timer should be reset, waiting 1 minute...') setTimeout(async () => { // should still be unlocked from account() reset and not initial unlock assert.ok(await wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) assert.ok(await wallet.verify(NANO_TEST_VECTORS.BIP39_SEED)) resolve(null) - }, 180000) + }, 60000) }) await new Promise(async (resolve) => { - console.log('Timer should not be reset by verify, waiting 3 minutes...') + console.log('Timer should not be reset by verify, waiting 1 minute...') setTimeout(async () => { // should be locked from account() reset and not reset by verify() await assert.rejects(wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) await assert.rejects(wallet.verify(NANO_TEST_VECTORS.BIP39_SEED)) await assert.resolves(wallet.destroy()) resolve(null) - }, 180000) + }, 60000) }) }) })