Overview
Keystore implements the Web3 Secret Storage Definition v3 for encrypting Ethereum private keys with a password. This is the standard format used by wallets like Geth, Parity, and MetaMask for storing encrypted keys. Ethereum context: Wallet storage - Standard JSON format for encrypted private key files. Used by all major Ethereum clients and wallets. Not part of on-chain protocol. Key features:- Web3 Secret Storage v3: Standard format for encrypted keystores
- KDF support: Scrypt (default, memory-hard) or PBKDF2 (faster)
- AES-128-CTR encryption: Industry-standard symmetric cipher
- MAC verification: Keccak256-based integrity check
- Constant-time comparison: Timing-attack resistant
- Customizable parameters: Tune security vs performance
Quick Start
API Reference
encrypt
Encrypts a private key to Web3 Secret Storage v3 format.privateKey- 32-byte private key (brandedUint8Array)password- Password for encryptionoptions- Optional encryption settings
KeystoreV3 object ready for JSON serialization
decrypt
Decrypts a Web3 Secret Storage v3 keystore to recover the private key.keystore- Encrypted keystore objectpassword- Password used during encryption
InvalidMacError- Wrong password or corrupted keystoreUnsupportedVersionError- Keystore version not 3UnsupportedKdfError- Unknown KDF (not scrypt/pbkdf2)DecryptionError- Other decryption failures
Types
KeystoreV3
The standard Web3 Secret Storage format:EncryptOptions
ScryptParams
Pbkdf2Params
Error Types
Keystore Format
Example keystore JSON with scrypt:KDF Comparison
Recommendation: Use scrypt (default) for maximum security. Use PBKDF2 only when scrypt is too slow for your use case.
Use Cases
Wallet Storage
Browser Storage
Password Change
Performance
Encryption/decryption time depends on KDF parameters:Related
- Keystore (Effect) - Effect.ts integration with Schema validation

