]> git.codecow.com Git - libnemo.git/commitdiff
Reduce lock timeout to two minutes from five.
authorChris Duncan <chris@zoso.dev>
Mon, 18 Aug 2025 19:23:53 +0000 (12:23 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 18 Aug 2025 19:23:53 +0000 (12:23 -0700)
src/lib/vault/vault.ts
test/test.lock-unlock.mjs

index fcf15917ccdf34997de7fcc9b9912d7cbb94e6bf..fa72b9c01eb17eaaff7b49876309625cfcae4a51 100644 (file)
@@ -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<boolean> {
-               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 })
                }
        }
 
index 6ea00772099c61298d15e1a044bfd5cd7e7add9c..23f80413a6f14df8b9d9166001680e74926beee1 100644 (file)
@@ -115,7 +115,7 @@ await Promise.all([
                        await assert.resolves(wallet.destroy())\r
                })\r
 \r
-               await test('wallet automatic lock resets after user activity', { skip: true }, async () => {\r
+               await test('wallet automatic lock resets after user activity', { skip: false }, async () => {\r
                        const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
                        await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
 \r
@@ -123,34 +123,34 @@ await Promise.all([
                        assert.ok(await wallet.verify(NANO_TEST_VECTORS.BIP39_SEED))\r
 \r
                        await new Promise(async (resolve) => {\r
-                               console.log('Waiting 3 minutes...')\r
+                               console.log('Waiting 1 minute...')\r
                                setTimeout(async () => {\r
                                        // should still be unlocked\r
                                        const account = await wallet.account(0)\r
                                        assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
                                        resolve(null)\r
-                               }, 180000)\r
+                               }, 60000)\r
                        })\r
 \r
                        await new Promise(async (resolve) => {\r
-                               console.log('Timer should be reset, waiting 3 minutes...')\r
+                               console.log('Timer should be reset, waiting 1 minute...')\r
                                setTimeout(async () => {\r
                                        // should still be unlocked from account() reset and not initial unlock\r
                                        assert.ok(await wallet.verify(NANO_TEST_VECTORS.MNEMONIC))\r
                                        assert.ok(await wallet.verify(NANO_TEST_VECTORS.BIP39_SEED))\r
                                        resolve(null)\r
-                               }, 180000)\r
+                               }, 60000)\r
                        })\r
 \r
                        await new Promise(async (resolve) => {\r
-                               console.log('Timer should not be reset by verify, waiting 3 minutes...')\r
+                               console.log('Timer should not be reset by verify, waiting 1 minute...')\r
                                setTimeout(async () => {\r
                                        // should be locked from account() reset and not reset by verify()\r
                                        await assert.rejects(wallet.verify(NANO_TEST_VECTORS.MNEMONIC))\r
                                        await assert.rejects(wallet.verify(NANO_TEST_VECTORS.BIP39_SEED))\r
                                        await assert.resolves(wallet.destroy())\r
                                        resolve(null)\r
-                               }, 180000)\r
+                               }, 60000)\r
                        })\r
                })\r
        })\r