Hi. I noticed hashing strings is incorrect. It hashes the zeroed input buffer instead:
blake2b(16).update('a').digest('hex')
// '7025e075d5e2f6cde3cc051a31f07660'
blake2b(16).update('b').digest('hex')
// '7025e075d5e2f6cde3cc051a31f07660'
blake2b(16).update(new Uint8Array(1)).digest('hex')
// '7025e075d5e2f6cde3cc051a31f07660'
Based on hash.update
and blake2bUpdate
, the effect seems to be like:
const arr = new Uint8Array(1)
arr[0] = 'a'
// that does nothing:
// arr[0] === 0
blake2b(16).update(arr).digest('hex')
// '7025e075d5e2f6cde3cc051a31f07660'
Related to this issue is hashing empty strings:
blake2b(16).update('').digest('hex')
// Error: input must be TypedArray or Buffer
Maybe this assert was intended for all strings, and not just the empty one? It could also use TextEncoder
and Buffer.from
for you.