Skip to content

Fix TypeScript type mismatch errors between Buffer and Uint8Array #444

@Mohit-Davar

Description

@Mohit-Davar

Description

The project is currently experiencing TypeScript errors in src/utils/event.ts due to stricter type checking regarding Buffer and Uint8Array compatibility.

In modern TypeScript/Node.js type definitions, Buffer is not always directly assignable to parameters expecting Uint8Array<ArrayBuffer> because Buffer.buffer can be a SharedArrayBuffer, which is missing properties required by the standard ArrayBuffer interface (like resizable, transfer, etc.).

Observed Errors

The following errors were found in src/utils/event.ts:

  1. In getEventHash (Line 108):
    Argument of type 'Buffer' is not assignable to parameter of type 'Uint8Array<ArrayBufferLike>'.
  2. In encryptKind4Event / getSharedSecret (Line 165):
    Argument of type 'string | Buffer' is not assignable to parameter of type 'PrivKey'.
  3. In encryptKind4Event / createCipheriv (Line 171):
    Argument of type 'Buffer' is not assignable to parameter of type 'CipherKey'.

Proposed Fix

Convert Buffer instances to Uint8Array explicitly when passing them to functions that strictly expect Uint8Array<ArrayBuffer>.

For example, using new Uint8Array(myBuffer) instead of passing the buffer directly ensures that the type system treats the input as a standard Uint8Array.

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions