]> git.codecow.com Git - libnemo.git/commitdiff
Fix references to deprecated blake method overload.
authorChris Duncan <chris@zoso.dev>
Sat, 30 Aug 2025 08:03:58 +0000 (01:03 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 30 Aug 2025 08:03:58 +0000 (01:03 -0700)
src/lib/block.ts
src/lib/tools.ts
test/test.blake2b.mjs
test/test.calculate-pow.mjs

index 47f50e359af55c74c45b691df158c4254ad84bfe..21b4da0597959c2b5f173e5c0e4f4fad5e5887cc 100644 (file)
@@ -146,7 +146,7 @@ export class Block {
                        ]
                        const hash = new Blake2b(32)
                        data.forEach(d => typeof d === 'string' ? hash.update(hex.toBytes(d)) : hash.update(d))
-                       return format === 'hex' ? hash.digest(format) : hash.digest()
+                       return format === 'hex' ? bytes.toHex(hash.digest()) : hash.digest()
                } catch (err) {
                        console.error(err)
                        throw new Error('Failed to hash block', { cause: err })
index e279c57d2bec6c6c6bef2acf05bfb3dda88857f1..592f760bce6309cb1ce174820a74712f86167b07 100644 (file)
@@ -89,7 +89,7 @@ function hash (data: string | string[], encoding?: 'hex', format?: 'hex'): strin
                data.forEach(str => hash.update(enc.encode(str)))
        }
        return format === 'hex'
-               ? hash.digest('hex').toUpperCase()
+               ? bytes.toHex(hash.digest())
                : hash.digest()
 }
 
index 32ffd752f8baa71fb179684238a50f840cbb9e87..7d4a83252d073a74510955789c4a71b45af8a229 100644 (file)
@@ -40,8 +40,9 @@ await Promise.all([
                                        )\r
                                }\r
                                try {\r
-                                       const output = new Blake2b(64, key).update(input).digest('hex')\r
-                                       assert.equal(output, test.out)\r
+                                       const output = new Blake2b(64, key).update(input).digest()\r
+                                       const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('')\r
+                                       assert.equal(hex, test.out)\r
                                } catch (err) {\r
                                        console.error(`blake2b reference test vector ${i} failed`, { cause: err })\r
                                }\r
@@ -91,8 +92,9 @@ await Promise.all([
                                        )\r
                                }\r
                                try {\r
-                                       const output = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest('hex')\r
-                                       assert.equal(output, test.out)\r
+                                       const output = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest()\r
+                                       const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('')\r
+                                       assert.equal(hex, test.out)\r
                                } catch (err) {\r
                                        console.error(`blake2b libsodium test vector ${i} failed`, { cause: err })\r
                                }\r
index b4ed09bb48adb2d3c27d02823b4c00fc6d2b7d84..650522896313671766601497867c44cfc26fb691 100644 (file)
@@ -40,13 +40,10 @@ await Promise.all([
                        const bytes = new Uint8Array([...work, ...block.previous])\r
                        assert.equal(bytes.byteLength, 40)\r
 \r
-                       const hash = new Blake2b(8)\r
-                               .update(bytes)\r
-                               .digest('hex')\r
-                               .slice(8, 16)\r
+                       const hash = new Blake2b(8).update(bytes).digest()\r
 \r
-                       assert.ok(parseInt(hash.slice(0, 2), 16) > 0xf0)\r
-                       assert.equal(parseInt(hash.slice(2, 8), 16), 0xffffff)\r
+                       assert.ok(hash[4] > 0xf0)\r
+                       assert.ok(hash.subarray(5).every(b => b === 0xff))\r
                })\r
        })\r
 ])\r