}
/**
- * 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
*/
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 })
}
}