From: Chris Duncan Date: Fri, 1 May 2026 04:03:24 +0000 (-0700) Subject: Destructure account info to simplify verify method, and always destroy wallet even... X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=fad42e1b48982a5650b3d3b90e96437d03efff2a;p=libnemo.git Destructure account info to simplify verify method, and always destroy wallet even on exceptions. --- 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 }) } }