fix(utils): replace Buffer base64 usage with uint8arrays for browser …#7178
fix(utils): replace Buffer base64 usage with uint8arrays for browser …#7178Sushil-19 wants to merge 4 commits intoWalletConnect:v2.0from
Conversation
|
All contributors have signed the CTA ✍️ ✅ |
|
I have read the CTA Document and I hereby sign the CTA |
|
hey, thanks for tackling the issue. There are few ways to improve though
Ideally, a test should either:
|
|
Thanks for the feedback — that makes sense. You're right that the current PR only replaces the I'll extend the changes to replace all I'll also add a browser-like test environment (e.g., jsdom) to ensure the code works without I'll push an update shortly addressing these points. |
0d51690 to
70a12f2
Compare
|
Following up on the earlier changes in this PR. We updated the implementation across the utils files to remove usage of Node.js Additionally, the
I also re-ran the full test suite locally. The two failing No other behavior was modified — the goal of this PR remains limited to removing |
|
hello @ganchoradkov , can you please check this? If any changes needed, I can work on it asap so that I can work on next issue. |
|
Suggestions:
import { toString } from "uint8arrays";
export function old_toBase64(input: string, removePadding = false): string {
const encoded = Buffer.from(input).toString("base64");
return removePadding ? encoded.replace(/[=]/g, "") : encoded;
}
export function new_toBase64(input: string, removePadding = false): string {
const encoded = toString(new TextEncoder().encode(input), "base64");
return removePadding ? encoded.replace(/[=]/g, "") : encoded;
}
console.log(old_toBase64("1", false), "should equal", new_toBase64("1", false));
// Outputs: MQ== should equal MQ
console.log(old_toBase64("1", true), "should equal", new_toBase64("1", true));
// Outputs: MQ should equal MQ |
Summary
Replaces Node.js Buffer base64 decoding usage in @walletconnect/utils
with uint8arrays helpers to improve browser compatibility.
Changes
Testing