From 087e9b8a2986b5b38f97f2938d1e418b3460751c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 30 Apr 2026 13:06:05 -0700 Subject: [PATCH] Check for existing signature when signing blocks. --- src/lib/block.ts | 3 +++ src/lib/ledger.ts | 3 +++ src/lib/wallet/sign.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/lib/block.ts b/src/lib/block.ts index f59b040..69b59e3 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -411,6 +411,9 @@ export class Block { 'NotAllowedError' ) } + if (this.signature !== undefined) { + throw new TypeError('Block signature already exists', { cause: this.signature }) + } if (typeof input === 'string' && /^[A-F0-9]{128}$/i.test(input)) { this.signature = input return this diff --git a/src/lib/ledger.ts b/src/lib/ledger.ts index 4f517b7..433668d 100644 --- a/src/lib/ledger.ts +++ b/src/lib/ledger.ts @@ -570,6 +570,9 @@ export class Ledger { * @returns {Promise} Status, signature, and block hash */ static async #signBlock (index: number, block: Block): Promise { + if (block.signature !== undefined) { + throw new TypeError('Block signature already exists', { cause: block.signature }) + } return this.#enqueue(async () => { try { if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) { diff --git a/src/lib/wallet/sign.ts b/src/lib/wallet/sign.ts index 5b5d000..ce9f756 100644 --- a/src/lib/wallet/sign.ts +++ b/src/lib/wallet/sign.ts @@ -19,6 +19,9 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, if (!(block instanceof Block)) { throw new TypeError('Invalid Block', { cause: block }) } + if (block.signature !== undefined) { + throw new TypeError('Block signature already exists', { cause: block.signature }) + } if (wallet.type === 'Ledger') { if (frontier instanceof Block) { try { -- 2.47.3