]> git.codecow.com Git - libnemo.git/commitdiff
Remove ability to sign block from Block using its account since password is not an...
authorChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 15:23:06 +0000 (08:23 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 15:23:06 +0000 (08:23 -0700)
src/lib/block.ts

index c424ec9fc27a656e7e4df203d955e4a1b13aee56..be9a740d3b9e85bc6c06d8c79dc32a228a9b38a5 100644 (file)
@@ -127,12 +127,8 @@ abstract class Block {
        }
 
        /**
-       * Signs the block using a private key. If a key is not provided, the private
-       * key of the block's account will be used if it exists. If that fails, an
-       * error is thrown.
-       *
-       * If successful, the result is stored in the object's `signature`
-       * property.
+       * Signs the block using a private key. If successful, the result is stored in
+       * the object's `signature` property.
        *
        * @param {string} [key] - Hexadecimal-formatted private key to use for signing
        */
@@ -166,15 +162,15 @@ abstract class Block {
                                throw new Error(result.status)
                        }
                        this.signature = result.signature
-               } else {
+               } else if (typeof input === 'string') {
                        try {
-                               const account = (typeof input === 'string')
-                                       ? await Account.import({ index: 0, privateKey: input }, '')
-                                       : this.account
+                               const account = await Account.import({ index: 0, privateKey: input }, '')
                                this.signature = await account.sign(this, '')
                        } catch (err) {
                                throw new Error(`Failed to sign block`, { cause: err })
                        }
+               } else {
+                       throw new TypeError('invalid key for block signature', { cause: typeof input })
                }
        }