]> zoso.dev Git - libnemo.git/commitdiff
Directly calculate blake2b hash as part of block verification so that Tools import...
authorChris Duncan <chris@zoso.dev>
Mon, 2 Dec 2024 19:51:00 +0000 (11:51 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 2 Dec 2024 19:51:00 +0000 (11:51 -0800)
src/lib/block.ts

index 273d72099755ca05d2093adaeabe68752581a233..bbe6e729bd96d7b82ad43883a652c49e768d6a40 100644 (file)
@@ -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)
                )