/**
* Hashes the block using Blake2b.
*
- * @returns {Promise<Uint8Array>} Block data hashed to a byte array
+ * @returns {Promise<string>} Block data hashed to a byte array
*/
- async hash (): Promise<Uint8Array> {
+ async hash (): Promise<string> {
const data = [
PREAMBLE,
this.account.publicKey,
this.link
]
const hash = await Tools.hash(data, 'hex')
- return hex.toBytes(hash)
+ return hash
}
/**
throw new Error('No valid key found to sign block')
}
const signature = Ed25519.sign(
- await this.hash(),
+ hex.toBytes(await this.hash()),
hex.toBytes(key)
)
this.signature = bytes.toHex(signature)
it('should create a valid signature for an open block', async () => {\r
const block = new ReceiveBlock(\r
NANO_TEST_VECTORS.OPEN_BLOCK.account,\r
- NANO_TEST_VECTORS.OPEN_BLOCK.balance,\r
- NANO_TEST_VECTORS.OPEN_BLOCK.link,\r
'0',\r
+ NANO_TEST_VECTORS.OPEN_BLOCK.link,\r
+ NANO_TEST_VECTORS.OPEN_BLOCK.balance,\r
NANO_TEST_VECTORS.OPEN_BLOCK.representative,\r
NANO_TEST_VECTORS.OPEN_BLOCK.previous,\r
NANO_TEST_VECTORS.OPEN_BLOCK.work\r
)\r
await block.sign(NANO_TEST_VECTORS.OPEN_BLOCK.key)\r
+ assert.equal(await block.hash(), NANO_TEST_VECTORS.OPEN_BLOCK.hash)\r
assert.equal(block.signature, NANO_TEST_VECTORS.OPEN_BLOCK.signature)\r
})\r
\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.work\r
)\r
await block.sign(NANO_TEST_VECTORS.RECEIVE_BLOCK.key)\r
+ assert.equal(await block.hash(), NANO_TEST_VECTORS.RECEIVE_BLOCK.hash)\r
assert.equal(block.signature, NANO_TEST_VECTORS.RECEIVE_BLOCK.signature)\r
})\r
\r
NANO_TEST_VECTORS.RECEIVE_BLOCK.previous\r
)\r
await block.sign(NANO_TEST_VECTORS.RECEIVE_BLOCK.key)\r
+ assert.equal(await block.hash(), NANO_TEST_VECTORS.RECEIVE_BLOCK.hash)\r
assert.equal(block.signature, NANO_TEST_VECTORS.RECEIVE_BLOCK.signature)\r
assert.equal(block.work, '')\r
})\r
NANO_TEST_VECTORS.SEND_BLOCK.work\r
)\r
await block.sign(NANO_TEST_VECTORS.SEND_BLOCK.key)\r
+ assert.equal(await block.hash(), NANO_TEST_VECTORS.SEND_BLOCK.hash)\r
assert.equal(block.signature, NANO_TEST_VECTORS.SEND_BLOCK.signature)\r
})\r
\r
NANO_TEST_VECTORS.SEND_BLOCK.previous\r
)\r
await block.sign(NANO_TEST_VECTORS.SEND_BLOCK.key)\r
+ assert.equal(await block.hash(), NANO_TEST_VECTORS.SEND_BLOCK.hash)\r
assert.equal(block.signature, NANO_TEST_VECTORS.SEND_BLOCK.signature)\r
assert.equal(block.work, '')\r
})\r