This document outlines the complete security functionality that needs to be implemented in the separate @enactprotocol/security npm package to replace the current embedded security implementation in enact-cli.
The enact-security package should provide a comprehensive security framework for the Enact Protocol, handling cryptographic signing, verification, policy enforcement, and command safety analysis.
interface KeyManager {
generateKeyPair(algorithm: 'ecdsa-p256' | 'secp256k1'): Promise<KeyPair>
storeKey(keyId: string, key: PrivateKey, keyPath?: string): Promise<void>
loadKey(keyId: string, keyPath?: string): Promise<PrivateKey>
listKeys(keyPath?: string): Promise<string[]>
deleteKey(keyId: string, keyPath?: string): Promise<void>
exportPublicKey(keyId: string): Promise<string>
importTrustedKey(keyId: string, publicKey: string): Promise<void>
getTrustedKeys(): Promise<Map<string, PublicKey>>
}interface ToolSigner {
signTool(tool: EnactTool, keyId: string, role?: string): Promise<Signature>
signCriticalFields(tool: EnactTool, keyId: string, role?: string): Promise<Signature>
addSignature(tool: EnactTool, signature: Signature): EnactTool
removeSignature(tool: EnactTool, signerId: string): EnactTool
getCanonicalRepresentation(tool: EnactTool): string
}interface VerificationEngine {
verifySignature(tool: EnactTool, signature: Signature): Promise<boolean>
verifyAllSignatures(tool: EnactTool): Promise<VerificationResult[]>
verifyPolicy(tool: EnactTool, policy: VerificationPolicy): Promise<PolicyResult>
validateSignatureChain(tool: EnactTool): Promise<ChainValidationResult>
}enum VerificationPolicy {
PERMISSIVE = 'permissive', // 1 valid signature required
ENTERPRISE = 'enterprise', // Author + reviewer (2 minimum)
PARANOID = 'paranoid', // Author + reviewer + approver (3 minimum)
CUSTOM = 'custom' // User-defined policy
}
interface PolicyConfig {
policy: VerificationPolicy
requiredRoles?: string[]
minimumSignatures?: number
trustedSigners?: string[]
customValidation?: (tool: EnactTool) => Promise<boolean>
}interface PolicyEnforcer {
enforcePolicy(tool: EnactTool, config: PolicyConfig): Promise<PolicyResult>
validateRoles(signatures: Signature[], requiredRoles: string[]): boolean
checkSignatureThreshold(signatures: Signature[], minimum: number): boolean
auditVerification(tool: EnactTool, result: PolicyResult): Promise<void>
}interface CommandSafetyAnalyzer {
analyzeCommand(command: string): SafetyAnalysis
validateEnvironmentVariables(env: Record<string, string>): ValidationResult
checkDestructivePatterns(command: string): DestructivePattern[]
validateVersionPinning(command: string): PinningValidation
sanitizeInput(input: string): string
}
interface SafetyAnalysis {
isSafe: boolean
risks: SecurityRisk[]
warnings: SecurityWarning[]
recommendations: string[]
}interface SecurityRisk {
level: 'low' | 'medium' | 'high' | 'critical'
category: 'destructive' | 'network' | 'filesystem' | 'execution' | 'injection'
description: string
pattern?: string
mitigation?: string
}interface VerificationEnforcer {
shouldVerifyTool(tool: EnactTool, context: ExecutionContext): boolean
enforceVerification(tool: EnactTool, policy: PolicyConfig): Promise<EnforcementResult>
bypassVerification(tool: EnactTool, reason: string): Promise<void>
auditSecurityEvent(event: SecurityEvent): Promise<void>
}
interface ExecutionContext {
source: 'local' | 'registry' | 'remote'
environment: 'development' | 'production' | 'testing'
user?: string
origin?: string
}interface EnactTool {
name: string
description: string
command: string
enact?: string
version?: string
from?: string
timeout?: string
signatures?: Signature[]
[key: string]: any
}
interface Signature {
signer: string
algorithm: 'sha256'
type: 'ecdsa-p256' | 'secp256k1'
value: string
created: string
role?: string
}
interface KeyPair {
publicKey: string
privateKey: string
algorithm: string
}
interface VerificationResult {
valid: boolean
signer: string
error?: string
timestamp: string
}
interface PolicyResult {
passed: boolean
policy: VerificationPolicy
requiredSignatures: number
validSignatures: number
missingRoles: string[]
errors: string[]
}- Sign only security-critical fields:
name,description,command,from,timeout,enact - Exclude non-critical fields like
examples,doc,authors - Handle legacy field mappings
- Exclude null/undefined/empty values
- Generate deterministic canonical representations
- Support multiple signers per tool
- Role-based signatures (author, reviewer, approver)
- Signature aggregation and validation
- Conflict resolution for multiple signatures
- Browser-compatible cryptography (Web Crypto API)
- Node.js native crypto support
- React Native compatibility
- Consistent behavior across platforms
- Secure key storage in
~/.enact/trusted-keys/ - Key import/export functionality
- Trusted key management
- Key rotation support
- Comprehensive security event logging
- Verification audit trails
- Performance metrics
- Error tracking and reporting
- Dangerous command pattern detection
- Environment variable sanitization
- Version pinning validation
- Network access validation
- Destructive operation detection
// The package should export these main interfaces
export {
ToolSigner,
VerificationEngine,
PolicyEnforcer,
CommandSafetyAnalyzer,
VerificationEnforcer,
KeyManager,
VerificationPolicy,
type EnactTool,
type Signature,
type PolicyConfig,
type SafetyAnalysis
}interface SecurityConfig {
keyStorePath?: string
defaultPolicy?: VerificationPolicy
trustedKeyRegistries?: string[]
auditLogPath?: string
bypassDevelopment?: boolean
enableCommandSafety?: boolean
}- Signature verification: < 100ms per signature
- Command safety analysis: < 50ms per command
- Key operations: < 200ms
- Memory usage: < 50MB for typical workloads
- Support for concurrent operations
- Use industry-standard cryptographic algorithms (ECDSA P-256, secp256k1)
- Secure key storage with appropriate file permissions
- Protection against timing attacks
- Input validation and sanitization
- Secure random number generation
- No secret logging or exposure
- Cryptographic operation validation
- Policy enforcement testing
- Command safety analysis
- Key management operations
- Error handling and edge cases
- Cross-platform compatibility
- Performance benchmarks
- Security vulnerability testing
- Real-world tool signing scenarios
- Cryptographic strength validation
- Side-channel attack resistance
- Input fuzzing and validation
- Key material protection
- Complete TypeScript definitions
- Usage examples for all interfaces
- Migration guide from embedded security
- Best practices and security guidelines
- Threat model analysis
- Security policy explanations
- Cryptographic algorithm justification
- Audit and compliance information
- Create npm package structure
- Implement core cryptographic functions
- Add basic signing and verification
- Create unit tests
- Implement policy framework
- Add command safety analysis
- Complete key management
- Add integration tests
- Update enact-cli to use the package
- Remove embedded security code
- Update documentation
- Performance optimization
- Security audit
- Performance benchmarking
- Documentation completion
- Release and deployment
@noble/secp256k1- secp256k1 cryptography@noble/curves- ECDSA P-256 cryptographycanonicalize- JSON canonicalization
winston- Logging frameworkjoi- Input validationfs-extra- Enhanced file operations
@enactprotocol/security/
├── src/
│ ├── crypto/
│ │ ├── signing.ts
│ │ ├── verification.ts
│ │ └── keys.ts
│ ├── policy/
│ │ ├── enforcer.ts
│ │ └── policies.ts
│ ├── safety/
│ │ ├── analyzer.ts
│ │ └── patterns.ts
│ ├── storage/
│ │ └── keystore.ts
│ ├── types/
│ │ └── index.ts
│ └── index.ts
├── tests/
├── docs/
└── package.json
This security package will provide a complete, standalone security solution that can be used across all Enact Protocol implementations while maintaining the high security standards required for a cryptographic signing system.