From fad42e1b48982a5650b3d3b90e96437d03efff2a Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 30 Apr 2026 21:03:24 -0700 Subject: [PATCH] Destructure account info to simplify verify method, and always destroy wallet even on exceptions. --- src/lib/ledger.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/lib/ledger.ts b/src/lib/ledger.ts index 433668d..e0f5003 100644 --- a/src/lib/ledger.ts +++ b/src/lib/ledger.ts @@ -346,21 +346,24 @@ export class Ledger { static async verify (secret: string): Promise { 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 }) } } -- 2.47.3