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

Refactor & make base64 functions browser-safe #3818

Merged
merged 3 commits into from
Oct 20, 2023
Merged

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Oct 20, 2023

We had two identical sets of base64 functions in the js-sdk, both using Buffer which isn't really available in the browser unless you're using an old webpack (ie. what element-web uses). This PR:

  • Takes the crypto base64 file and moves it out of crypto (because we use base64 for much more than just crypto)
  • Makes them work in a browser without the Buffer global
  • Removes the other base64 functions
  • Changes everything to use the new common ones
  • Adds a comment explaining why the function is kinda ugly and how soul destroyingly awful the JS ecosystem is.
  • Runs the tests with both impls
  • Changes the test to not just test the decoder against the encoder
  • Adds explicit support & tests for (decoding) base64Url (I'll add an encode method later, no need for that to go in this PR too).

A fair amount, but most of it is just updating refs to the relocated file, so hopefully readily digestible.

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Here's what your changelog entry will look like:

🚨 BREAKING CHANGES

  • Refactor & make base64 functions browser-safe (#3818).

We had two identical sets of base64 functions in the js-sdk, both
using Buffer which isn't really available in the browser unless you're
using an old webpack (ie. what element-web uses). This PR:

 * Takes the crypto base64 file and moves it out of crypto (because
   we use base64 for much more than just crypto)
 * Makes them work in a browser without the Buffer global
 * Removes the other base64 functions
 * Changes everything to use the new common ones
 * Adds a comment explaining why the function is kinda ugly and how
   soul destroyingly awful the JS ecosystem is.
 * Runs the tests with both impls
 * Changes the test to not just test the decoder against the encoder
 * Adds explicit support & tests for (decoding) base64Url (I'll add an
   encode method later, no need for that to go in this PR too).
@dbkr dbkr added the T-Task Tasks for the team like planning label Oct 20, 2023
@dbkr dbkr requested a review from a team as a code owner October 20, 2023 15:10
@dbkr dbkr requested review from germain-gg and t3chguy October 20, 2023 15:10
@dbkr
Copy link
Member Author

dbkr commented Oct 20, 2023

Sonarcloud is unhappy because some of the lines where I've changed the import are untested. I don't think it's really appropriate for this to extend further into a mission writing tests for the crypto code.

src/base64.ts Show resolved Hide resolved
src/base64.ts Show resolved Hide resolved
src/base64.ts Show resolved Hide resolved
@dbkr dbkr merged commit 7a52dba into develop Oct 20, 2023
18 of 19 checks passed
@dbkr dbkr deleted the dbkr/all_your_base64 branch October 20, 2023 15:47
@richvdh richvdh mentioned this pull request Oct 20, 2023
3 tasks
@richvdh richvdh added X-Breaking-Change T-Deprecation A pull request that makes something deprecated and removed T-Task Tasks for the team like planning labels Oct 20, 2023
@richvdh
Copy link
Member

richvdh commented Oct 20, 2023

giving this an X-Breaking-Change label as it did actually break the react sdk

dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Oct 20, 2023
Apologies, I broke this with matrix-org/matrix-js-sdk#3818

This fixes it, but needs matrix-org/matrix-js-sdk#3820
dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Deprecation A pull request that makes something deprecated X-Breaking-Change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants