-
Notifications
You must be signed in to change notification settings - Fork 2
Add passphrase-encrypted wallet export flow #110
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a passphrase-encrypted wallet export flow that encrypts wallet mnemonics with a user-provided passphrase before transmission from the iframe. Users enter and confirm a passphrase through a new UI form, and the encrypted data is sent to the parent frame as base64-encoded content instead of plaintext.
Key changes:
- Implements AES-GCM-256 encryption with PBKDF2 key derivation (100,000 iterations)
- Adds a new
INJECT_WALLET_EXPORT_BUNDLE_ENCRYPTEDmessage type and corresponding handler - Creates a passphrase form UI with validation (8-character minimum, matching confirmation)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| export/index.template.html | Adds encryption/decryption utilities, passphrase form UI with styling, and message handler for encrypted wallet export flow |
| export/index.test.js | Adds 5 unit tests covering encryption, decryption, wrong passphrase handling, salt/IV randomness, and end-to-end base64 encoding |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… overflow on large payloads
815a958 to
ec9eac5
Compare
ec9eac5 to
8773586
Compare
Add passphrase-encrypted wallet export flow
Note: this PR was initially generated by Cursor using Claude Opus 4.5 based on the details provided in REQ-275. I have since made multiple edits and fixes. This is step 1, with additional work needed in the SDK and an example to be enumerated in mono.
Summary
This PR adds a new encrypted wallet export flow that allows users to encrypt their wallet mnemonic with a passphrase before it leaves the iframe. Instead of displaying the plaintext mnemonic in the DOM, users are prompted to enter and confirm a passphrase, and the encrypted result is sent to the parent frame as base64-encoded data.
Changes
New Encryption Utilities (TKHQ Module)
encryptWithPassphrase(buf, passphrase)- Encrypts aUint8Arrayusing:salt (16 bytes) || iv (12 bytes) || ciphertextdecryptWithPassphrase(encryptedBuf, passphrase)- Decrypts data encrypted by the above functionNew Message Type
INJECT_WALLET_EXPORT_BUNDLE_ENCRYPTED- New message type that triggers the passphrase-protected export flow instead of displaying the mnemonic directlyNew UI Components
displayPassphraseForm(mnemonic, requestId)- Renders a form with:displayPassphraseForm(mnemonic, requestId)- Renders a<form>with:autocomplete="new-password"andrequiredautocomplete="new-password"andrequiredNew Output Message
ENCRYPTED_WALLET_EXPORT- Sent to parent frame with base64-encoded encrypted wallet data upon successful encryptionStyling
Testing
Encryption tests (5):
✅ Encrypts data with passphrase correctly
✅ Decrypts data encrypted by encryptWithPassphrase correctly
✅ Fails to decrypt with wrong passphrase
✅ Produces different ciphertext for same plaintext (random salt/IV)
✅ Handles encryption of wallet mnemonic end-to-end
Passphrase Form Validation tests (10):
✅ Shows error when passphrase is too short
✅ Shows error when passphrase is exactly 7 characters
✅ Accepts passphrase with exactly 8 characters
✅ Shows error when passphrases do not match
✅ Shows length error before mismatch error
✅ Hides error message on successful validation
✅ Accepts empty confirmation when passphrase is too short (length check first)
✅ Validates with special characters in passphrase
✅ Validates with unicode characters in passphrase
✅ Is case-sensitive when comparing passphrases
All 33 tests passing.
Usage
Parent frame sends:
Parent frame receives (after user enters passphrase):
Security Notes
Array.frominstead ofString.fromCharCode.applyto prevent stack overflow on large payloads