js-multiformats icon indicating copy to clipboard operation
js-multiformats copied to clipboard

Glitch/TypeError: Received Buffer when Uint8Array expected

Open telamon opened this issue 1 year ago • 1 comments

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.

telamon avatar Jul 11 '23 00:07 telamon

Somewhat related to https://github.com/multiformats/js-multiformats/issues/191

tabcat avatar Jul 11 '23 14:07 tabcat