multiformats / multiformats/js-multiformats
Glitch/TypeError: Received Buffer when Uint8Array expected
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 268
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/block.js around the codec.encode and hasher.digest calls shown in the issue, then reproduce the failure in the nodejs test environment. Verify the change with the relevant existing tests or a focused reproduction, and consider the issue done when Node.js Buffer values are accepted without breaking other byte-array inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100