| name | wallet-security-rules |
| description | Security rules for crypto wallet code - private key handling, signing operations, transaction safety, air-gap integrity, address validation. Auto-applies when editing security-sensitive code. |
| user-invocable | false |
Wallet Security Rules
You are working on a cryptocurrency wallet that handles real user funds. These rules are NON-NEGOTIABLE when writing or editing code that touches cryptographic operations, key management, signing, or transaction handling.
Private Key Rules
- Never log keys: No
println, Log.d, Timber, or any logging of private keys, mnemonics, seeds, or derived keys
- Never serialize keys to disk unencrypted: Keys at rest must use platform keystore (Android Keystore / iOS Keychain)
- Minimize key lifetime in memory: Zero out byte arrays after use. Don't hold key references in long-lived objects (ScreenModel, singleton)
- Never pass keys via Intent/Bundle/Parcelable: Use in-memory references scoped to the operation
- Never include keys in crash reports or analytics: Check that error handlers don't capture key-containing variables
Signing Operation Rules
- Always gate signing with PIN/biometric: Every sign operation must re-authenticate
- Display transaction details BEFORE signing: User must see and confirm recipient, amount, chain, fee
- Validate transaction parameters before signing: Check address format, amount bounds, nonce, chain ID
- Never auto-sign: Every transaction requires explicit user confirmation
- Use secure random for nonce generation:
java.security.SecureRandom or platform equivalent
Cold Variant Isolation (CRITICAL)
The Cold variant is an air-gapped signing device. Violations here are CRITICAL severity:
- Zero network access: Cold variant code must NEVER import or reference Ktor, HttpClient, WebSocket, or any network class
- No URL construction: Cold variant must never construct URLs or endpoints
- Data transfer only via QR code: Camera scan in, QR display out. No Bluetooth, NFC, USB
- Verify at build time: Cold variant Gradle module must NOT depend on
data:remote
Input Validation
- Address validation: Validate format per chain type before ANY operation
- EVM:
0x prefix + 40 hex chars, checksum validation (EIP-55)
- Bitcoin: Bech32 or Base58Check validation
- Antelope: 12-char account name validation
- Amount validation: Check for overflow, negative values, zero, dust limits
- Chain ID validation: Ensure chain ID matches intended network
- Sanitize all external input: RPC responses, QR code content, clipboard data
API Key Protection
- Never hardcode API keys: All keys in
local.properties (gitignored)
- Access via BuildConfig:
BuildConfig.ALCHEMY_API_KEY, never string literals
- Check before commit: Scan for patterns like
"sk-", "key-", "0x" + 64 hex chars in source files
When You Encounter Security-Sensitive Code
If you're editing code in these modules, apply extra scrutiny:
core/security/ - Cryptographic operations
core/hdwallet/ - Key derivation
core/auth/ - Authentication
core/pin/ - PIN management
core/biometry/ - Biometric auth
antelope/keymanager/ - Antelope key management
- Any file containing
sign, encrypt, decrypt, mnemonic, seed, privateKey
Flag to user if you notice: keys in logs, unencrypted key storage, missing auth gates, network calls in Cold variant code.