From: Chris Duncan Date: Sat, 30 Aug 2025 08:03:58 +0000 (-0700) Subject: Fix references to deprecated blake method overload. X-Git-Tag: v0.10.5~38^2~4 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=40cafc6e19cc8aa1ed90ccf537a6d4978aaaedd5;p=libnemo.git Fix references to deprecated blake method overload. --- diff --git a/src/lib/block.ts b/src/lib/block.ts index 47f50e3..21b4da0 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -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 }) diff --git a/src/lib/tools.ts b/src/lib/tools.ts index e279c57..592f760 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -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() } diff --git a/test/test.blake2b.mjs b/test/test.blake2b.mjs index 32ffd75..7d4a832 100644 --- a/test/test.blake2b.mjs +++ b/test/test.blake2b.mjs @@ -40,8 +40,9 @@ await Promise.all([ ) } try { - const output = new Blake2b(64, key).update(input).digest('hex') - assert.equal(output, test.out) + const output = new Blake2b(64, key).update(input).digest() + const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('') + assert.equal(hex, test.out) } catch (err) { console.error(`blake2b reference test vector ${i} failed`, { cause: err }) } @@ -91,8 +92,9 @@ await Promise.all([ ) } try { - const output = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest('hex') - assert.equal(output, test.out) + const output = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest() + const hex = [...output].map(b => b.toString(16).padStart(2, '0')).join('') + assert.equal(hex, test.out) } catch (err) { console.error(`blake2b libsodium test vector ${i} failed`, { cause: err }) } diff --git a/test/test.calculate-pow.mjs b/test/test.calculate-pow.mjs index b4ed09b..6505228 100644 --- a/test/test.calculate-pow.mjs +++ b/test/test.calculate-pow.mjs @@ -40,13 +40,10 @@ await Promise.all([ const bytes = new Uint8Array([...work, ...block.previous]) assert.equal(bytes.byteLength, 40) - const hash = new Blake2b(8) - .update(bytes) - .digest('hex') - .slice(8, 16) + const hash = new Blake2b(8).update(bytes).digest() - assert.ok(parseInt(hash.slice(0, 2), 16) > 0xf0) - assert.equal(parseInt(hash.slice(2, 8), 16), 0xffffff) + assert.ok(hash[4] > 0xf0) + assert.ok(hash.subarray(5).every(b => b === 0xff)) }) }) ])