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(core): perform byte array <-> b64 conversions w/ native JS #153

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

drichar
Copy link
Collaborator

@drichar drichar commented Apr 8, 2024

Instead of requiring consuming applications to use the Node.js Buffer API polyfill to convert Uint8Array byte arrays to and from base 64 strings, wallet clients will now use native JavaScript methods atob and btoa.

Credit to PureStake, as utility functions for AlgoSigner were starting points for the functions now being used here: https://github.com/PureStake/algosigner/blob/master/packages/common/src/encoding.ts

Other Changes

I've also updated the core library's tsconfig to no longer enforce noUncheckedIndexedAccess, which forces me to use non-null assertion operators to access numbered array elements. This trade-off for the benefit it provides by strictly enforcing declared object properties doesn't seem worth it. I would've had to use it (again) in the byteArrayToString function. See https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess

This tsconfig setting adds `| undefined` whenever you access undeclared properties of an object/array. It defaults to false.

Overriding the default and setting this to true forces the use of non-null assertion operators in places where I've already confirmed a property exists. The extra protection it adds isn't worth the trade-off.

See https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
@drichar
Copy link
Collaborator Author

drichar commented Apr 8, 2024

@acfunk would be great to have you take a look at this 🙏

@drichar drichar added this to the v3.0.0 stable release milestone Apr 8, 2024
@drichar drichar added the bug Something isn't working label Apr 8, 2024
@acfunk
Copy link
Contributor

acfunk commented Apr 8, 2024

@acfunk would be great to have you take a look at this 🙏

lgtm

@drichar drichar merged commit 054947c into v3 Apr 9, 2024
1 check passed
@drichar drichar deleted the fix/buffer-to-b64-in-browser branch April 9, 2024 18:10
@drichar drichar added the v3 label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants