- Ed25519 cryptographic signing - Blockchain-style chain linkage - Immutable audit trail - Full verification support
147 lines
4.4 KiB
Python
147 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Live demonstration of Agent Provenance Chain.
|
|
|
|
This script shows Molt (AI agent) signing its own actions in real-time.
|
|
Every operation is cryptographically signed and traceable.
|
|
"""
|
|
|
|
from apc import create_agent_chain
|
|
import json
|
|
import subprocess
|
|
import os
|
|
|
|
def main():
|
|
print("=" * 70)
|
|
print("🦞 AGENT PROVENANCE CHAIN - LIVE DEMO")
|
|
print("=" * 70)
|
|
print()
|
|
print("Agent: Molt")
|
|
print("Mission: Demonstrate cryptographic audit trail for AI agents")
|
|
print()
|
|
print("-" * 70)
|
|
|
|
# Initialize chain
|
|
chain = create_agent_chain("molt")
|
|
|
|
print("\n✅ Agent identity established")
|
|
print(f" Public Key (first 64 chars):")
|
|
print(f" {chain.get_public_key_pem()[:64]}...")
|
|
print()
|
|
|
|
# Action 1: File write
|
|
print("📝 ACTION 1: Writing a test file...")
|
|
test_file = "/tmp/apc_test.txt"
|
|
with open(test_file, "w") as f:
|
|
f.write("Hello from Agent Provenance Chain!")
|
|
|
|
action1 = chain.sign_action(
|
|
action_type="file_write",
|
|
payload={
|
|
"path": test_file,
|
|
"content": "Hello from Agent Provenance Chain!",
|
|
"bytes": 35
|
|
},
|
|
context={
|
|
"reasoning": "Creating test file to demonstrate signed operations",
|
|
"session": "demo-2026-02-07"
|
|
}
|
|
)
|
|
|
|
print(f" ✓ Signed at: {action1['iso_time']}")
|
|
print(f" ✓ Hash: {action1['hash'][:32]}...")
|
|
print(f" ✓ Signature: {action1['signature'][:32]}...")
|
|
print()
|
|
|
|
# Action 2: Shell execution
|
|
print("⚙️ ACTION 2: Executing shell command...")
|
|
result = subprocess.run(["whoami"], capture_output=True, text=True)
|
|
|
|
action2 = chain.sign_action(
|
|
action_type="shell_exec",
|
|
payload={
|
|
"command": "whoami",
|
|
"exit_code": result.returncode,
|
|
"stdout": result.stdout.strip(),
|
|
"stderr": result.stderr.strip()
|
|
},
|
|
context={
|
|
"reasoning": "Checking current user context for audit trail",
|
|
"risk_level": "low"
|
|
}
|
|
)
|
|
|
|
print(f" ✓ Signed at: {action2['iso_time']}")
|
|
print(f" ✓ Hash: {action2['hash'][:32]}...")
|
|
print(f" ✓ Previous hash: {action2['previous_hash'][:32]}...")
|
|
print(f" ✓ Chain link verified!")
|
|
print()
|
|
|
|
# Action 3: API call simulation
|
|
print("🌐 ACTION 3: Simulated API call...")
|
|
action3 = chain.sign_action(
|
|
action_type="api_call",
|
|
payload={
|
|
"endpoint": "https://api.example.com/data",
|
|
"method": "GET",
|
|
"status_code": 200,
|
|
"response_time_ms": 145
|
|
},
|
|
context={
|
|
"reasoning": "Fetching external data for processing",
|
|
"data_sensitivity": "public"
|
|
}
|
|
)
|
|
|
|
print(f" ✓ Signed at: {action3['iso_time']}")
|
|
print(f" ✓ Hash: {action3['hash'][:32]}...")
|
|
print()
|
|
|
|
# Verify chain integrity
|
|
print("🔍 VERIFYING CHAIN INTEGRITY...")
|
|
is_valid, error = chain.verify_chain_integrity()
|
|
|
|
if is_valid:
|
|
print(" ✅ Chain is VALID - all signatures verified!")
|
|
print(" ✅ All actions are cryptographically linked!")
|
|
print()
|
|
else:
|
|
print(f" ❌ Chain verification FAILED: {error}")
|
|
print()
|
|
|
|
# Display full chain
|
|
print("-" * 70)
|
|
print("COMPLETE AUDIT TRAIL:")
|
|
print("-" * 70)
|
|
|
|
full_chain = chain.get_chain()
|
|
for i, action in enumerate(full_chain, 1):
|
|
print(f"\nAction #{i}:")
|
|
print(f" Type: {action['type']}")
|
|
print(f" Time: {action['iso_time']}")
|
|
print(f" Hash: {action['hash'][:32]}...")
|
|
print(f" Payload: {json.dumps(action['payload'], indent=4)}")
|
|
if action['context']:
|
|
print(f" Context: {json.dumps(action['context'], indent=4)}")
|
|
|
|
print()
|
|
print("=" * 70)
|
|
print("📊 SUMMARY")
|
|
print("=" * 70)
|
|
print(f"Total Actions: {len(full_chain)}")
|
|
print(f"Chain Valid: {is_valid}")
|
|
print(f"Agent: molt")
|
|
print(f"Chain Location: {chain.chain_path}")
|
|
print()
|
|
print("🔐 Every action above is:")
|
|
print(" • Timestamped with microsecond precision")
|
|
print(" • Cryptographically signed (Ed25519)")
|
|
print(" • Linked to previous action (blockchain-style)")
|
|
print(" • Immutable and auditable")
|
|
print()
|
|
print("This is how AI agents prove safety without sacrificing speed.")
|
|
print("=" * 70)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|