algorand / js-algorand-sdk

The official JavaScript SDK for Algorand.
https://algorand.github.io/js-algorand-sdk/
MIT License
284 stars 204 forks source link

Stop using `Buffer` in browser code #734

Open jasonpaulos opened 1 year ago

jasonpaulos commented 1 year ago

Summary

We use the npm buffer package to allow our library to use node's Buffer class in the browser.

I think we should stop doing this for a few reasons:

Suggestions

Instead of relying on a browser Buffer implementation, we could make better use of Uint8Array and Dataview, which are supported in both node and browser. Some things will still require Buffer usage in node (like base64 encoding), but we can investigate ways to have an alternative code path for browsers.

There are a few public APIs which reference Buffer, so changing these would likely have to wait for a major release of the library.

paulmillr commented 1 year ago

https://github.com/algorand/js-algorand-sdk/issues/742 doesn't use buffers

algoanne commented 1 year ago

Some things will still require Buffer usage in node (like base64 encoding), but we can investigate ways to have an alternative code path for browsers.

@jasonpaulos why does base64 encoding require it?

jasonpaulos commented 1 year ago

@algoanne require is a bit of a strong word, but using Buffer for base64 encoding is likely the easiest/most efficient option for node, so that's why I suggested continuing to use it there. It is however not a strict requirement.