]> git.codecow.com Git - libnemo.git/commitdiff
Check for existing signature when signing blocks.
authorChris Duncan <chris@zoso.dev>
Thu, 30 Apr 2026 20:06:05 +0000 (13:06 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 30 Apr 2026 20:06:05 +0000 (13:06 -0700)
src/lib/block.ts
src/lib/ledger.ts
src/lib/wallet/sign.ts

index f59b040daafbabf2085ca5586cebcd1c0da9a5aa..69b59e32579ea68e9f77f52153f54c922ad45ad8 100644 (file)
@@ -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
index 4f517b73da429036da3a1739202004f807371584..433668d26c193df85393150c63ec63912e0dc5c6 100644 (file)
@@ -570,6 +570,9 @@ export class Ledger {
        * @returns {Promise} Status, signature, and block hash
        */
        static async #signBlock (index: number, block: Block): Promise<LedgerSignResponse> {
+               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) {
index 5b5d0002073e2d9560adbb6632e25e5c9c304b92..ce9f75647ec6dadce13f0cadd1b62b745bd50e0d 100644 (file)
@@ -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 {