Wallet Security
Private Key Management
- Never commit private keys to version control
- Use environment variables or secure secret management
- Encrypt private keys at rest
- Use hardware wallets for large treasury amounts
- Implement key rotation policies
# Use environment variables export BACON_PRIVATE_KEY="your_encrypted_key" # Or use secret management services # AWS Secrets Manager # HashiCorp Vault # GitHub Secrets
Multi-Signature Wallets
For production treasuries, use multi-signature wallets requiring multiple approvals:
// Create 2-of-3 multisig wallet
const multisig = await bacon.createMultisig({
threshold: 2,
signers: [signer1, signer2, signer3]
});
// All large transfers require 2 signatures
await multisig.proposeTransfer({
to: recipient,
amount: 10000
});
Hot and Cold Wallets
- Hot Wallet: Small balance for daily operations
- Cold Wallet: Large treasury stored offline
- Regularly transfer funds from hot to cold storage
- Set up automated alerts for hot wallet balance
Application Security
Input Validation
// Validate addresses before sending
function isValidAddress(address, blockchain) {
if (blockchain === 'bitcoin') {
return /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,62}$/.test(address);
} else if (blockchain === 'solana') {
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
}
return false;
}
// Validate amounts
function isValidAmount(amount) {
return typeof amount === 'number' &&
amount > 0 &&
amount <= MAX_REWARD_AMOUNT &&
Number.isFinite(amount);
}
Rate Limiting
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per window
message: 'Too many requests'
});
app.use('/api/', limiter);
Webhook Verification
const crypto = require('crypto');
function verifyGitHubWebhook(payload, signature, secret) {
const hmac = crypto.createHmac('sha256', secret);
const digest = 'sha256=' + hmac.update(payload).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(digest)
);
}
app.post('/webhook', (req, res) => {
const signature = req.headers['x-hub-signature-256'];
if (!verifyGitHubWebhook(req.body, signature, WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}
// Process webhook
});
Transaction Security
Pre-Transaction Checks
- Verify recipient address format
- Check treasury balance before sending
- Validate transaction amounts
- Confirm recipient is not blacklisted
- Check for duplicate transactions
Transaction Monitoring
- Log all transactions with timestamps
- Monitor for unusual patterns
- Set up alerts for large transfers
- Track failed transactions
- Monitor blockchain fees
Fraud Prevention
- Implement daily withdrawal limits
- Require approval for large amounts
- Detect and block suspicious addresses
- Monitor for Sybil attacks
- Verify GitHub account authenticity
Audit Trail
- Maintain immutable transaction logs
- Store logs off-chain and on-chain
- Regular security audits
- Compliance reporting
- Incident response procedures
Smart Contract Security
Code Audits
- Have contracts audited by professional security firms
- Conduct internal code reviews
- Use automated security scanning tools
- Implement bug bounty programs
- Regular security updates
Common Vulnerabilities
// ❌ BAD: Reentrancy vulnerability
function withdraw() {
uint amount = balances[msg.sender];
msg.sender.call{value: amount}("");
balances[msg.sender] = 0;
}
// ✅ GOOD: Protected against reentrancy
function withdraw() {
uint amount = balances[msg.sender];
balances[msg.sender] = 0;
msg.sender.call{value: amount}("");
}
// Use ReentrancyGuard
modifier nonReentrant() {
require(!locked, "No reentrancy");
locked = true;
_;
locked = false;
}
Access Control
// Implement role-based access control
const roles = {
ADMIN: 'admin',
MINTER: 'minter',
DISTRIBUTOR: 'distributor'
};
function checkRole(user, role) {
if (!userRoles[user].includes(role)) {
throw new Error('Unauthorized');
}
}
// Only admins can mint
async function mint(amount) {
checkRole(msg.sender, roles.MINTER);
await token.mint(amount);
}
Operational Security
Environment Separation
# Development BACON_NETWORK=testnet BACON_DEBUG=true # Staging BACON_NETWORK=testnet BACON_DEBUG=false # Production BACON_NETWORK=mainnet BACON_DEBUG=false BACON_REQUIRE_2FA=true
Monitoring and Alerting
// Set up alerts
bacon.on('low-balance', (balance) => {
sendAlert('Treasury balance low: ' + balance);
});
bacon.on('large-transaction', (tx) => {
sendAlert('Large transaction detected: ' + tx.amount);
});
bacon.on('failed-transaction', (error) => {
sendAlert('Transaction failed: ' + error.message);
});
Incident Response Plan
- Detection: Monitor for security incidents
- Containment: Immediately pause affected systems
- Analysis: Investigate the scope and cause
- Eradication: Remove the threat
- Recovery: Restore normal operations
- Post-Incident: Document and improve processes
Compliance and Privacy
OWASP Compliance
- Follow OWASP Top 10 security guidelines
- Implement secure coding practices
- Regular security testing and audits
- Transparent fund management
- Open-source code for community review
Data Privacy
- Minimize collection of personal data
- Encrypt sensitive information
- Comply with GDPR/CCPA if applicable
- Provide data export and deletion options
- Clear privacy policy
Regulatory Considerations
- Understand local cryptocurrency regulations
- Consult legal counsel for compliance
- Implement KYC/AML if required
- Maintain transaction records
- File appropriate tax forms
Security Checklist
Pre-Launch Checklist
- Private keys secured and encrypted
- Multi-signature wallet configured
- Hot/cold wallet strategy implemented
- Input validation on all endpoints
- Rate limiting configured
- Webhook signature verification
- Transaction monitoring set up
- Fraud detection rules defined
- Audit logging enabled
- Emergency shutdown procedure
- Incident response plan documented
- Security audit completed
- Compliance requirements met
- Team security training completed
Ongoing Security Tasks
- Daily treasury balance checks
- Weekly transaction reviews
- Monthly security audits
- Quarterly penetration testing
- Regular dependency updates
- Continuous monitoring alerts