From: Chris Duncan Date: Mon, 2 Dec 2024 19:51:00 +0000 (-0800) Subject: Directly calculate blake2b hash as part of block verification so that Tools import... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6bfffa7412c73ec2d59ab74fa1d3e530860fc937;p=libnemo.git Directly calculate blake2b hash as part of block verification so that Tools import can be eliminated. --- 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) )