Skip to content

feat: implement platform-managed custodial wallets#611

Open
Bigmehelen wants to merge 1 commit into
code-flexing:mainfrom
Bigmehelen:Implementcustodialwalletcreationforonboardingnewusers
Open

feat: implement platform-managed custodial wallets#611
Bigmehelen wants to merge 1 commit into
code-flexing:mainfrom
Bigmehelen:Implementcustodialwalletcreationforonboardingnewusers

Conversation

@Bigmehelen

Copy link
Copy Markdown

closed #1055

CustodialWalletService: Created to securely generate and encrypt Stellar keypairs on behalf of users.
Strong Encryption (Zero-Knowledge Custody):
Integrated Argon2id for robust key derivation from the user's plaintext password.
Implemented AES-256-GCM encryption for the Stellar secret key, generating a unique IV and Auth Tag for each encryption.
Mixed a server-side pepper (CUSTODIAL_WALLET_ENCRYPTION_PEPPER) into the salt, ensuring that even a complete database dump cannot be cracked without the environment variable.
Auth Flow Integration: Updated AuthService and RegisterDto to accept the use_custodial_wallet flag. If selected, the backend generates the wallet upon registration and associates the public key with the user.
Export Endpoint: Added a securely rate-limited endpoint (POST /api/v1/wallets/custodial/export-key) that decrypts and returns the user's private key when they supply their current plaintext password.
Database Schema:
Added the custodial_wallets table to store the encrypted key materials and Argon2 parameters.
Added the wallet_type enum (none, self-custody, custodial) to the users table to track wallet provisioning.
Frontend 🖥️
Signup Flow Update: Added a "Wallet Setup" step to the registration page (app/signup/page.tsx). Users can clearly choose between the beginner-friendly "Platform-Managed (Custodial)" option and the advanced "Self-Custody (Freighter)" option.
auth-store.ts Updates: Modified the signup action to include the wallet type and gracefully handle the conditional stellar_address requirement.
CustodialWalletBadge: A sleek UI badge component added to help users visually distinguish their custodial wallet status.
ExportKeyModal: An interactive modal that prompts the user for their password, securely fetches the decrypted Stellar secret key, and displays it in a hidden-by-default, copyable format with prominent security warnings.
Documentation 📄
docs/custodial-wallet-security.md: Added comprehensive documentation detailing the threat model, key derivation design, encryption parameters, export flow, and compliance notes.
Deployment Notes
WARNING

Environment Variables: You MUST set the CUSTODIAL_WALLET_ENCRYPTION_PEPPER environment variable in your production secrets manager. This must be a secure, 32-byte hex string. If not set, custodial wallets will fall back to an insecure hardcoded pepper and log errors.

- Add CustodialWalletService with Argon2id + AES-256-GCM encryption for zero-knowledge key custody

- Integrate custodial wallet generation into user registration

- Update signup UI to allow choosing between custodial and self-custody wallets

- Create ExportKeyModal for users to safely export their private keys

- Add custodial_wallets table migration and wallet_type to users

- Add security documentation for the custodial wallet architecture
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Bigmehelen is attempting to deploy a commit to the vic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Bigmehelen Bigmehelen closed this Jun 27, 2026
@Bigmehelen Bigmehelen reopened this Jun 27, 2026
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.

1 participant