]> git.codecow.com Git - libnemo.git/commitdiff
Destructure account info to simplify verify method, and always destroy wallet even...
authorChris Duncan <chris@zoso.dev>
Fri, 1 May 2026 04:03:24 +0000 (21:03 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 1 May 2026 04:03:24 +0000 (21:03 -0700)
src/lib/ledger.ts

index 433668d26c193df85393150c63ec63912e0dc5c6..e0f50031c1bcdf77678a0502033920ab00c2a679 100644 (file)
@@ -346,21 +346,24 @@ export class Ledger {
        static async verify (secret: string): Promise<boolean> {
                const testWallet = await Wallet.load('BIP-44', '', secret)
                secret = ''
-               await testWallet.unlock('')
-               const testAccount = await testWallet.account(0)
-               const testOpenBlock = await new Block(testAccount.address, '0', testAccount.publicKey, testAccount.address)
-                       .receive(testAccount.publicKey, 0)
-                       .sign(testWallet, 0)
-               const testSendBlock = await new Block(testAccount.address, '0', testOpenBlock.hash, testAccount.address)
-                       .send(testAccount.address, 0)
-                       .sign(testWallet, 0)
-               const testSignature = testSendBlock.signature
                try {
+                       await testWallet.unlock('')
+                       const { address, publicKey } = await testWallet.account(0)
+                       const testOpenBlock = await new Block(address, '0', publicKey, address)
+                               .receive(publicKey, 0)
+                               .sign(testWallet, 0)
+                       const testSendBlock = await new Block(address, '0', testOpenBlock.hash, address)
+                               .send(address, 0)
+                               .sign(testWallet, 0)
+                       const testSignature = testSendBlock.signature
+                       try {
+                               const ledgerSignature = await this.sign(0, testSendBlock, testOpenBlock)
+                               return ledgerSignature === testSignature
+                       } catch (err) {
+                               throw new Error('Failed to verify wallet', { cause: err })
+                       }
+               } finally {
                        await testWallet.destroy()
-                       const ledgerSignature = await this.sign(0, testSendBlock, testOpenBlock)
-                       return ledgerSignature === testSignature
-               } catch (err) {
-                       throw new Error('Failed to verify wallet', { cause: err })
                }
        }