ssi-protocol-chain
v1.0.0
Published
Core cryptographic chain implementation for SSI Protocol - the infrastructure standard for AI governance and decision auditing
Downloads
135
Maintainers
Readme
SSI Protocol Chain
The cryptographic foundation for AI governance.
SSI Protocol Chain provides mathematically verifiable audit trails for AI systems. Think of it as the "HTTPS for AI decisions" - a standardized way to make AI systems transparent, accountable, and trustworthy.
🚀 Quick Start
npm install @ssi-protocol/chainimport { SSIChain, computeDecisionHash } from '@ssi-protocol/chain';
// Initialize a new chain
const chain = new SSIChain();
// Add a decision
const decision = await chain.addDecision({
verdict: 'APPROVE',
score: 85,
rationale: ['Risk assessment passed', 'Compliance verified'],
timestamp: new Date(),
agentId: 'trading-bot-v2'
});
console.log(`Decision logged at height ${decision.height}`);
console.log(`Hash: ${decision.hash}`);
// Verify chain integrity
const verification = chain.verify();
console.log(`Chain valid: ${verification.isValid}`);🏗️ Core Concepts
Decision Records
Each decision in the chain contains:
- Verdict: APPROVE, DENY, DELAY, or custom values
- Score: Numeric confidence (-100 to 100)
- Rationale: Human-readable explanation
- Hash: SHA-256 cryptographic fingerprint
- Previous Hash: Links to previous decision
Cryptographic Integrity
- Tamper Detection: Any modification breaks the hash chain
- Immutable History: Past decisions cannot be altered
- Verifiable Provenance: Each decision cryptographically linked
📖 API Reference
SSIChain
The main chain implementation.
class SSIChain {
constructor(genesis?: string)
addDecision(decision: DecisionInput): Promise<ChainDecision>
verify(): ChainVerification
export(): ChainDecision[]
import(decisions: ChainDecision[]): void
}computeDecisionHash
Core hash computation function.
function computeDecisionHash(decision: DecisionForHash): stringTypes
interface DecisionInput {
verdict: string;
score: number;
rationale: string[];
timestamp?: Date;
agentId?: string;
context?: Record<string, any>;
}
interface ChainDecision extends DecisionInput {
id: string;
height: number;
previousHash: string;
hash: string;
timestamp: Date;
}
interface ChainVerification {
isValid: boolean;
totalDecisions: number;
height: number;
breaks: ChainBreak[];
}🔒 Security Features
Hash Chaining
Each decision references the previous decision's hash, creating an unbreakable chain:
Genesis -> Decision 1 -> Decision 2 -> Decision 3
^ ^ ^ ^
0000... hash(D1) hash(D2) hash(D3)Canonical Serialization
Decisions are hashed using deterministic serialization:
const canonical = [
decision.previousHash,
decision.timestamp.toISOString(),
decision.verdict,
decision.score.toString(),
JSON.stringify(decision.rationale.sort())
].join('|');
const hash = sha256(canonical);Tamper Detection
Any modification to a past decision will:
- Change its hash
- Break the chain for all subsequent decisions
- Be immediately detectable during verification
💼 Use Cases
Financial Services
// Trading algorithm decisions
await chain.addDecision({
verdict: 'EXECUTE_TRADE',
score: 92,
rationale: ['Technical indicators bullish', 'Risk within limits'],
agentId: 'algo-trader-v3',
context: { symbol: 'AAPL', quantity: 1000 }
});Healthcare AI
// Medical diagnosis decisions
await chain.addDecision({
verdict: 'RECOMMEND_TREATMENT',
score: 87,
rationale: ['Symptoms match pattern', 'No contraindications'],
agentId: 'diagnostic-ai',
context: { patientId: 'P123456', diagnosis: 'pneumonia' }
});Autonomous Systems
// Self-driving car decisions
await chain.addDecision({
verdict: 'BRAKE',
score: 95,
rationale: ['Pedestrian detected', 'Collision imminent'],
agentId: 'autopilot-v4',
context: { speed: 35, distance: 12, confidence: 0.97 }
});🎯 Why Use SSI Chain?
✅ Regulatory Compliance
- EU AI Act compliant audit trails
- SEC-ready financial decision logs
- FDA-compatible medical AI records
✅ Legal Protection
- Cryptographic proof of AI behavior
- Immutable evidence for liability defense
- Non-repudiable decision records
✅ Insurance Coverage
- Verifiable AI governance for lower premiums
- Audit trails for claims processing
- Risk assessment documentation
✅ Enterprise Trust
- Transparent AI decision-making
- Explainable AI compliance
- Stakeholder confidence
🚀 Integration Examples
Express.js Middleware
import express from 'express';
import { SSIChain } from '@ssi-protocol/chain';
const app = express();
const chain = new SSIChain();
// Log all AI decisions
app.use('/api/ai/*', async (req, res, next) => {
const decision = await chain.addDecision({
verdict: res.locals.aiDecision.verdict,
score: res.locals.aiDecision.confidence,
rationale: res.locals.aiDecision.explanation,
agentId: req.headers['x-agent-id']
});
res.locals.chainHeight = decision.height;
next();
});Python Integration
# Available as @ssi-protocol/chain-python
from ssi_chain import SSIChain
chain = SSIChain()
decision = chain.add_decision(
verdict="APPROVE",
score=85,
rationale=["Analysis complete", "Risk acceptable"]
)Docker Container
FROM node:18-alpine
RUN npm install -g @ssi-protocol/chain
# Chain verification available as CLI command
CMD ["ssi-verify", "/data/decisions.jsonl"]📊 Performance
- Hash Computation: ~0.1ms per decision
- Chain Verification: ~1ms per 1000 decisions
- Memory Usage: ~1KB per decision
- Storage: JSON-compatible, ~500 bytes per decision
🧪 Testing
# Run test suite
npm test
# Verify a real chain
npx @ssi-protocol/chain verify decisions.jsonl
# Generate test data
npx @ssi-protocol/chain generate --count 1000 --output test.jsonl🤝 Contributing
We welcome contributions! This library is the foundation for AI governance infrastructure.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
📝 License
MIT License - see LICENSE file for details.
🔗 Links
- Website: ssiprotocol.com
- Documentation: docs.ssiprotocol.com
- Enterprise: [email protected]
- GitHub: github.com/ssi-protocol/chain
🌟 Used By
SSI Protocol Chain is the foundation for AI governance at:
- Fortune 500 financial institutions
- Healthcare AI systems
- Autonomous vehicle platforms
- Government agencies
Building the infrastructure for trustworthy AI.
