//! SPDX-License-Identifier: GPL-3.0-or-later\r
\r
import { Account, AccountList } from './account'\r
-import { ChangeBlock, ReceiveBlock, SendBlock } from './block'\r
+import { Block } from './block'\r
import { Bip39Mnemonic } from './bip39-mnemonic'\r
import { ADDRESS_GAP } from './constants'\r
import { bytes, hex, utf8 } from './convert'\r
* before being returned. The wallet must be unlocked prior to signing.\r
*\r
* @param {number} index - Account to use for signing\r
- * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - Block data to be hashed and signed\r
+ * @param {(Block)} block - Block data to be hashed and signed\r
* @returns {Promise<string>} Hexadecimal-formatted 64-byte signature\r
*/\r
- async sign (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): Promise<string> {\r
+ async sign (index: number, block: Block): Promise<Uint8Array<ArrayBuffer>>\r
+ /**\r
+ * Signs a block using the private key of the account at the wallet index\r
+ * specified. The signature is appended to the signature field of the block\r
+ * before being returned. The wallet must be unlocked prior to signing.\r
+ *\r
+ * @param {number} index - Account to use for signing\r
+ * @param {(Block)} block - Block data to be hashed and signed\r
+ * @returns {Promise<string>} Hexadecimal-formatted 64-byte signature\r
+ */\r
+ async sign (index: number, block: Block, format: 'hex'): Promise<string>\r
+ async sign (index: number, block: Block, format?: 'hex'): Promise<string | Uint8Array<ArrayBuffer>> {\r
try {\r
const { signature } = await this.#safe.request<ArrayBuffer>({\r
action: 'sign',\r
index,\r
- data: hex.toBuffer(block.hash)\r
+ data: block.hash.buffer\r
})\r
- const sig = bytes.toHex(new Uint8Array(signature))\r
- block.signature = sig\r
+ const sig = new Uint8Array(signature)\r
+ block.signature = bytes.toHex(sig)\r
clearTimeout(this.#lockTimer)\r
this.#lockTimer = setTimeout(() => this.lock(), 300000)\r
- return sig\r
+ return format === 'hex' ? sig : block.signature\r
} catch (err) {\r
throw new Error(`Failed to sign block`, { cause: err })\r
}\r