Security
Security best practices for managing private keys and secrets.
Key Types
1. Agent Wallet Key
Signs orders on Hyperliquid
Server-side only
One key for entire platform
2. Oracle Key
Updates vault balances on-chain
Server-side only
Separate from agent key
3. Master Wallet Keys
User-controlled
Never shared with Atract
Stored in MetaMask/WalletConnect
Storage
Development
Local .env.local file (gitignored):
HL_AGENT_PRIVATE_KEY="0x..."
ORACLE_PRIVATE_KEY="0x..."Never commit to git:
Add
.env.localto.gitignoreUse
.env.examplefor documentationNever use production keys in dev
Production
Recommended: Environment variables in hosting platform
Vercel: Environment Variables section
AWS: Systems Manager Parameter Store
Docker: Secrets management
Never:
Hardcode in source code
Commit to repository
Expose in client-side code
Log to console or files
Access Control
Server-only code:
// ✅ CORRECT - Server-side only
// app/api/trade/route.ts
const agentKey = process.env.HL_AGENT_PRIVATE_KEY;
// ❌ WRONG - Never expose to client
// NEXT_PUBLIC_AGENT_KEY would be visible in browserKey separation:
Agent key: Trading only
Oracle key: Balance updates only
Never reuse keys across services
Rotation
When to rotate:
Suspected compromise
Employee offboarding
Regular schedule (quarterly)
After security incident
How to rotate:
Generate new key
Update environment variables
Restart services
Verify new key works
Revoke old key (if applicable)
For agent key:
Users must re-authorize new agent
Coordinate rotation with users
Provide migration period
Monitoring
Alert on:
Unauthorized use attempts
Key access from new IPs
High volume of signatures
Failed authentication attempts
Log (without exposing keys):
logger.info('agent_sign', 'Order signed', {
user: maskAddress(address),
signature: '[redacted]',
timestamp: Date.now()
});Backup
Backup securely:
Encrypted backup of keys
Separate from application code
Multiple secure locations
Document recovery process
Never:
Email keys
Store in Slack/Discord
Save in plaintext
Share via insecure channels
Incident Response
If key is compromised:
Immediately rotate key
Notify users (for agent key)
Audit recent activity
Review access logs
Document incident
Improve security measures
Best Practices
Do:
Use hardware wallets for high-value keys
Implement least-privilege access
Regularly audit key usage
Use separate keys per environment
Encrypt at rest
Don't:
Share keys between services
Use production keys in development
Hard-code keys in code
Expose keys in logs
Store keys in databases
Related Pages
Last updated