*
* @returns {Uint8Array<ArrayBuffer>} Block data hashed to a byte array
*/
- get hash (): Uint8Array<ArrayBuffer> {
+ get #hash (): Uint8Array<ArrayBuffer> {
try {
if (this.link == null) {
throw new Error('Link is required')
throw new Error('Failed to hash block', { cause: err })
}
}
+ /**
+ * Calculates the block hash using Blake2b.
+ *
+ * @returns {string} Hexadecimal representation of 32-byte hash of block data
+ */
+ get hash (): string {
+ return bytes.toHex(this.#hash)
+ }
/**
* Converts the block to JSON format as expected by the `process` RPC.
}
this.link = (typeof sendBlock === 'string')
? hex.toBytes(sendBlock)
- : sendBlock.hash
+ : hex.toBytes(sendBlock.hash)
return this
} catch (err) {
if (typeof input !== 'number' && typeof input !== 'string' && !(input instanceof Wallet)) {
throw new TypeError('Invalid signing input')
} else if (typeof input === 'string' && /^[A-F0-9]{64}$/.test(input)) {
- const sig = await NanoNaCl.detached(this.hash, hex.toBytes(input))
+ const sig = await NanoNaCl.detached(this.#hash, hex.toBytes(input))
this.signature = bytes.toHex(sig)
} else if (input instanceof Wallet && typeof param === 'number') {
const wallet = input
if (typeof key !== 'string') {
throw new Error('Invalid key')
}
- return await NanoNaCl.verify(this.hash, hex.toBytes(this.signature ?? ''), hex.toBytes(key))
+ return await NanoNaCl.verify(this.#hash, hex.toBytes(this.signature ?? ''), hex.toBytes(key))
} catch (err) {
throw new Error('Failed to verify block signature', { cause: err })
}
import { Database } from './database'\r
import { Rpc } from './rpc'\r
import { Wallet } from './wallet'\r
-import { DeviceStatus, KeyPair, LedgerAccountResponse, LedgerResponse, LedgerSignResponse, LedgerVersionResponse } from '#types'\r
+import { DeviceStatus, LedgerAccountResponse, LedgerResponse, LedgerSignResponse, LedgerVersionResponse } from '#types'\r
\r
/**\r
* Ledger hardware wallet created by communicating with a Ledger device via ADPU\r
const testOpenBlock = await new Block(testAccount.address, '0', testAccount.publicKey, testAccount.address)\r
.receive(testAccount.publicKey, 0)\r
.sign(testWallet, 0)\r
- const testSendBlock = new Block(testAccount.address, '0', bytes.toHex(testOpenBlock.hash), testAccount.address)\r
+ const testSendBlock = new Block(testAccount.address, '0', testOpenBlock.hash, testAccount.address)\r
.send(testAccount.address, 0)\r
const testSignature = await testWallet.sign(0, testOpenBlock, 'hex')\r
try {\r
return { status, signature: null }\r
}\r
if (response.byteLength === 98) {\r
- const hash = response.slice(0, 32)\r
+ const hash = bytes.toHex(response.slice(0, 32))\r
const signature = bytes.toHex(response.slice(32, 96))\r
return { status, signature, hash }\r
}\r
const { signature } = await this.#safe.request<ArrayBuffer>({\r
action: 'sign',\r
index,\r
- data: block.hash.buffer\r
+ data: hex.toBuffer(block.hash)\r
})\r
const sig = new Uint8Array(signature)\r
block.signature = bytes.toHex(sig)\r
/**
* Calculates the block hash using Blake2b.
*
- * @returns {Uint8Array<ArrayBuffer>} Block data hashed to a byte array
+ * @returns {string} Hexadecimal representation of 32-byte hash of block data
*/
- get hash (): Uint8Array<ArrayBuffer>
+ get hash (): string
/**
* Converts the block to JSON format as expected by the `process` RPC.
*
interface LedgerSignResponse extends LedgerResponse {
signature: string | null,
- hash?: Uint8Array<ArrayBuffer>
+ hash?: string
}
/**