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

Use Buffer.from for NodeJS fromHexString #283

Closed
dapplion opened this issue Dec 4, 2022 · 2 comments
Closed

Use Buffer.from for NodeJS fromHexString #283

dapplion opened this issue Dec 4, 2022 · 2 comments

Comments

@dapplion
Copy link
Contributor

dapplion commented Dec 4, 2022

@nflaig noted that SSZ uses a browser compatible but slow implementation for fromHexString

for (let i = 0; i < byteLen; i++) {
const byte = parseInt(hex.slice(i * 2, (i + 1) * 2), 16);
bytes[i] = byte;
}

We may use platform specific exports to get around it or have some logic to pick between implementations depending on platform.

Important to note that many consumers of SSZ assume everything is a Uint8Array. Buffer.slice() has different behaviour than Uint8Array.slice, so we must audit all downstream code to prevent surprises.

@nflaig
Copy link
Member

nflaig commented Jan 30, 2024

We may use platform specific exports to get around it or have some logic to pick between implementations depending on platform.

Another and much simpler solution could be to just check if Buffer.from exists as we do for base64 utils in Lodestar

packages/utils/src/base64.ts#L1

const hasBufferFrom = typeof Buffer !== "undefined" && typeof Buffer.from === "function";

However, if there are more functions that are affected, exports might be a more scalable / robust solution

@philknows
Copy link
Member

No longer a priority, fixed in Lodestar

@philknows philknows closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants