]> git.codecow.com Git - libnemo.git/commitdiff
Fix wallet auto lock timing. Fix wallet verify method.
authorChris Duncan <chris@zoso.dev>
Sat, 2 Aug 2025 07:53:53 +0000 (00:53 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 2 Aug 2025 07:53:53 +0000 (00:53 -0700)
src/lib/wallet.ts

index 1543c868f1d3230a7789c64d71fd8094c2747a9f..a85a02e86ee13e95753fd63e8607d7723bb309b5 100644 (file)
@@ -396,7 +396,7 @@ export class Wallet {
                                throw new Error('Unlock request to Safe failed')\r
                        }\r
                        clearTimeout(this.#lockTimer)\r
-                       this.#lockTimer = setTimeout(() => this.lock(), 120000)\r
+                       this.#lockTimer = setTimeout(() => this.lock(), 300000)\r
                        return isUnlocked\r
                } catch (err) {\r
                        throw new Error('Failed to unlock wallet', { cause: err })\r
@@ -453,24 +453,22 @@ export class Wallet {
        async verify (mnemonic: string): Promise<boolean>\r
        async verify (secret: string): Promise<boolean> {\r
                try {\r
-                       const data: NamedData<string> = {\r
+                       clearTimeout(this.#lockTimer)\r
+                       const data: NamedData = {\r
                                action: 'verify'\r
                        }\r
                        if (/^[A-Fa-f0-9]+$/.test(secret)) {\r
-                               data.seed = secret\r
+                               data.seed = hex.toBuffer(secret)\r
                        } else {\r
                                data.mnemonicPhrase = secret\r
                        }\r
                        const result = await this.#safe.request<boolean>(data)\r
-                       const { isUnlocked } = result\r
-                       if (!isUnlocked) {\r
-                               throw new Error('Unlock request to Safe failed')\r
-                       }\r
-                       clearTimeout(this.#lockTimer)\r
-                       this.#lockTimer = setTimeout(() => this.lock(), 120)\r
-                       return isUnlocked\r
+                       const { isVerified } = result\r
+                       return isVerified\r
                } catch (err) {\r
-                       throw new Error('Failed to unlock wallet', { cause: err })\r
+                       throw new Error('Failed to verify wallet', { cause: err })\r
+               } finally {\r
+                       this.#lockTimer = setTimeout(() => this.lock(), 300000)\r
                }\r
        }\r
 }\r