js-multiformats
js-multiformats copied to clipboard
Glitch/TypeError: Received Buffer when Uint8Array expected
This bug affects nodejs/test-environments
Excerpt from block.js
const bytes = codec.encode(value) // <-- Returns node:Buffer
const hash = await hasher.digest(bytes) // !!! <-- Throws if not Uint8Array
Platform agnostic proposal:
let bytes = codec.encode(value)
if (!(bytes instanceof Uint8Array) && bytes?.buffer) bytes = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)
const hash = await hasher.digest(bytes)
I'll monkeypatch for now. Please take it from here, thanks.
Somewhat related to https://github.com/multiformats/js-multiformats/issues/191