Skip to content
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

fix: allocate shared buffer at runtime to fix browser compatibility #7023

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/utils/src/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ export function toHex(buffer: Uint8Array | Parameters<typeof Buffer.from>[0]): s
}

// Shared buffer to convert root to hex
const rootBuf = Buffer.alloc(32);
let rootBuf: Buffer | undefined;

/**
* Convert a Uint8Array, length 32, to 0x-prefixed hex string
*/
export function toRootHex(root: Uint8Array): string {
if (rootBuf === undefined) {
rootBuf = Buffer.alloc(32);
}
rootBuf.set(root);
return `0x${rootBuf.toString("hex")}`;
}
Expand Down
Loading