Secure Storage
How Bagel protects your private keys
Secure Storage Implementation
Bagel implements a robust secure storage system for sensitive cryptographic keys to ensure your funds remain private and under your control.
Security Architecture
PIN-Based Encryption
Bagel uses strong encryption to protect your sensitive data:
- All sensitive keys are encrypted using AES-GCM with 256-bit keys
- Encryption keys are derived from your PIN code using PBKDF2 with 100,000 iterations
- Each encrypted item includes its own salt and initialization vector (IV) for stronger security
- All cryptographic operations use the Web Crypto API for secure implementation
Key Separation and Storage
Bagel uses a layered approach to key storage:
- Private Keys: Viewing and spending private keys are stored encrypted in IndexedDB
- In-Memory Session: Decrypted keys are held in memory only during active sessions
- Multiple Wallets: Support for multiple wallets in a single application instance
- Secure Registry: Encrypted registry of all managed wallets with metadata
Auto-Lock Mechanism
Bagel implements automatic protection of your keys:
- Wallet automatically locks after 10 minutes of inactivity
- All in-memory keys are purged when locked
- Requires PIN code re-entry to access keys again
- Manual lock option for immediate security
Key Recovery
Bagel ensures you never lose access to your funds:
- Keys can be deterministically re-derived from the original wallet signature
- No risk of permanent loss if secure storage is reset, as long as the main wallet is accessible
Implementation Details
Storage Structure
Bagel uses IndexedDB with multiple object stores:
encryptedKeys
- Stores the encrypted key datacryptoMetadata
- Stores information needed for decryptionwallet-registry
- Manages multiple wallets within the applicationapp-settings
- Stores non-sensitive application settings
Encryption Process
-
Key Derivation
-
Data Encryption
-
Secure Storage
Multi-Wallet Support
Bagel allows you to manage multiple wallets in a single instance:
- Each wallet has a unique ID
- Wallets can be added, removed, and switched
- All wallet metadata is stored in an encrypted registry
- Example:
User Experience
- Secure Onboarding: Users set a PIN code during initial wallet setup
- Unlock Flow: PIN code is required to decrypt and access private keys
- Session Management: Timeout-based auto-locking for security
- Manual Locking: Users can manually lock their wallet for additional security
This implementation ensures sensitive key material is never exposed in plaintext storage, balancing security with usability through temporary in-memory caching of unlocked keys during active sessions and simple PIN-based authentication.