From: Chris Duncan Date: Thu, 30 Apr 2026 20:06:05 +0000 (-0700) Subject: Check for existing signature when signing blocks. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=087e9b8a2986b5b38f97f2938d1e418b3460751c;p=libnemo.git Check for existing signature when signing blocks. --- 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 {