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: restore Cloud Account Backup #5941

Merged
merged 7 commits into from
Sep 9, 2024
Merged

Conversation

jeanregisser
Copy link
Member

@jeanregisser jeanregisser commented Sep 9, 2024

Description

Cloud Account Backup broke in #5866.

That PR changed global.crypto to be polyfilled by react-native-quick-crypto and the version of @toruslabs/eccrypto pulled by our Cloud Account Backup, wasn't working out-of-the box with it.

However it got fixed in torusresearch/eccrypto#40 and landed in @toruslabs/eccrypto >= 5.0.2.

So this PR upgrades the @toruslabs libs so it pulls the latest version of @toruslabs/[email protected] which works with react-native-quick-crypto.

It's using new major versions. Scanning through the release notes, the main impact for us was the way to import the module. But let me know if there's an important detail I've missed.

Additionally, I found there was a bug in react-native-quick-crypto, getAuthTag was returning an ArrayBuffer instead of a Buffer leading to an incorrect encoding in the final encrypted string.
I contributed a fix upstream (margelo/react-native-quick-crypto#443) and created a patch to use until it's merged. And made a slight change to the wallet code so we can decrypt data if the authTag was serialized as an ArrayBuffer (e.g. "1,2,3,4,...") instead of the expected base64.

This replaces #5934

Test plan

  • Tests pass
  • Manually tested:
    • Restore from Cloud Account Backup works
    • Setup Cloud Account Backup works
    • Delete Cloud Account Backup works

Related issues

See Slack: thread 1, thread 2.

Backwards compatibility

Yes

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

@jeanregisser jeanregisser changed the title hotfix: restore Cloud Account Backup fix: restore Cloud Account Backup Sep 9, 2024
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.48%. Comparing base (84d34dd) to head (34b8e91).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5941      +/-   ##
==========================================
- Coverage   88.49%   88.48%   -0.01%     
==========================================
  Files         728      728              
  Lines       30611    30614       +3     
  Branches     5218     5518     +300     
==========================================
+ Hits        27088    27090       +2     
+ Misses       3480     3319     -161     
- Partials       43      205     +162     
Files with missing lines Coverage Δ
src/keylessBackup/encryption.ts 100.00% <100.00%> (ø)
src/keylessBackup/web3auth.ts 100.00% <100.00%> (ø)

... and 70 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84d34dd...34b8e91. Read the comment docs.

const nonce = Buffer.from(nonceBase64, 'base64')
const authTag = Buffer.from(authTagBase64, 'base64')
// There was a bug with the initial switch to react-native-quick-crypto,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my understanding, with this hack, we don't need the patch right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch is still needed so we don't create encrypted data with the incorrectly serialized authTag, moving forward.

This code here, is to recover from the case someone tried to use Cloud Account Backup with react-native-quick-crypto without the patch.
I think this would only be internal devs. But I guess probably only me got into that state, because the crypto operation failed without the @toruslabs lib update.
And no public release went out with the broken Cloud Account Backup.

Happy to clarify this more if necessary.

@jeanregisser jeanregisser added this pull request to the merge queue Sep 9, 2024
Merged via the queue into main with commit 06e4e62 Sep 9, 2024
17 checks passed
@jeanregisser jeanregisser deleted the jeanregisser/fix-cab-crypto branch September 9, 2024 17:00
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

Successfully merging this pull request may close these issues.

4 participants