]
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 })
data.forEach(str => hash.update(enc.encode(str)))
}
return format === 'hex'
- ? hash.digest('hex').toUpperCase()
+ ? bytes.toHex(hash.digest())
: hash.digest()
}
)\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
)\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
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