-
Notifications
You must be signed in to change notification settings - Fork 109
feat(encoding,block): accept Uint8Array as input alongside Buffer #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
db24f46
45d8b3e
121d48b
18e6f55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,9 @@ var BufferReader = function BufferReader(buf) { | |||||
| if (_.isUndefined(buf)) { | ||||||
| return; | ||||||
| } | ||||||
| if (Buffer.isBuffer(buf)) { | ||||||
| if (buf instanceof Uint8Array) { | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Preserve Buffer detection when widening the input check Replacing Buffer.isBuffer with instanceof Uint8Array rejects browser Buffers created in another realm, such as an iframe. The configured browser Buffer polyfill recognizes these values with Buffer.isBuffer, but they fail the receiving realm's instanceof check. They consequently enter the generic object branch, which leaves this.buf undefined, and the first read throws. Using separately evaluated copies of the installed browser Buffer polyfill, the base successfully read 67305985 from the supplied bytes while this head threw a TypeError in readUInt32LE. Preserve the original Buffer check alongside Uint8Array detection and add a cross-realm regression test.
Suggested change
source: ['claude'] |
||||||
| this.set({ | ||||||
| buf: buf, | ||||||
| buf: Buffer.isBuffer(buf) ? buf : Buffer.from(buf), | ||||||
| }); | ||||||
| } else if (_.isString(buf)) { | ||||||
| this.set({ | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: Expose the new BlockHeader input in the published TypeScript declaration
The newly documented Uint8Array construction path is not exposed by the package's TypeScript API: index.d.ts exports typings/block/BlockHeader.d.ts, which still declares only constructor(). Compiling an import from the package followed by new BlockHeader(new Uint8Array(80)) produces TS2554: 'Expected 0 arguments, but got 1.' Although the constructor declaration was already incomplete, accepting this newly supported input is necessary to expose this PR's feature to TypeScript consumers. Add a constructor signature accepting Uint8Array and a test-d assertion exercising it; the existing type test only imports BlockHeader and does not detect this gap.
source: ['claude']