From 00b9e1c40cbed3ac913a2e67f2bee89c6a06288f Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 23 Jul 2025 08:23:06 -0700 Subject: [PATCH] Remove ability to sign block from Block using its account since password is not an argument at this time and signing with a locked account should be done from the account itself. --- src/lib/block.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index c424ec9..be9a740 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -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 }) } } -- 2.47.3