From 6bfffa7412c73ec2d59ab74fa1d3e530860fc937 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 2 Dec 2024 11:51:00 -0800 Subject: [PATCH] Directly calculate blake2b hash as part of block verification so that Tools import can be eliminated. --- src/lib/block.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 273d720..bbe6e72 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -8,7 +8,6 @@ import { bytes, dec, hex } from './convert.js' import { NanoNaCl } from './nano-nacl.js' import { Pool } from './pool.js' import { Rpc } from './rpc.js' -import Tools from './tools.js' import { Pow } from './workers.js' /** @@ -206,9 +205,11 @@ abstract class Block { dec.toHex(this.balance, 32), this.link ] - const hash = await Tools.hash(data, 'hex') + const hash = new Blake2b(32) + data.forEach(str => hash.update(hex.toBytes(str))) + const blockHash = hash.digest('hex').toUpperCase() return NanoNaCl.verify( - hex.toBytes(hash), + hex.toBytes(blockHash), hex.toBytes(this.signature ?? ''), hex.toBytes(key) ) -- 2.34.1