TTOPM commited on
Commit
a5d08c5
·
verified ·
1 Parent(s): 65227e2

Upload 22 files

Browse files
src/anthropic_integration/ARCHITECTURE.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Architecture Overview
2
+
3
+ - **Governance Envelope** around vendor models (Anthropic Claude), not weight tampering.
4
+ - **Proof Bonding**: input+prompt+output → `proof_hash` (+ Ed25519 signature, ZKP placeholder).
5
+ - **Anchoring**: local ledger + pluggable TSA/blockchain hook.
6
+ - **MCP Registry**: FastAPI service for `/register` and `/verify` proof records.
7
+ - **Tracing**: OpenTelemetry hooks (OTLP exporter ready).
8
+ - **Resilience**: Fragmentation & regeneration stubs.
9
+ - **Supply Chain**: CI builds, SBOM via Syft, ready for signing (cosign) and provenance (SLSA).
10
+
src/anthropic_integration/CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Code of Conduct
2
+ Be kind, professional, and respectful. Harassment or abuse is not tolerated.
src/anthropic_integration/CONTRIBUTING.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Contributing
2
+ 1. Fork & branch.
3
+ 2. Enable pre-commit: `pre-commit install`.
4
+ 3. Run tests: `pytest -q`.
5
+ 4. Open PR with clear description and threat analysis if touching crypto.
src/anthropic_integration/Dockerfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Belel × Anthropic Integration CLI
2
+ FROM python:3.11-slim
3
+ WORKDIR /app
4
+ COPY requirements.txt ./
5
+ RUN pip install --no-cache-dir -r requirements.txt && pip install --no-cache-dir fastapi uvicorn nacl opentelemetry-sdk opentelemetry-exporter-otlp
6
+ COPY . .
7
+ ENV PYTHONPATH=/app
8
+ CMD ["python", "-m", "src.cli", "Demo run via Docker"]
src/anthropic_integration/LICENSE ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright ...
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
src/anthropic_integration/README.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Belel × Anthropic (Claude) — Sovereign Governance Integration (Advanced Scaffold)
2
+
3
+ This repository is a **production-minded scaffold** for integrating **Belel’s sovereign governance**
4
+ (Concordium Mandate, canonical adjudications, cryptographic provenance) with Anthropic's ecosystem,
5
+ **leveraging MCP-style tool bridges** and immutable proofing.
6
+
7
+ > ⚠️ This is a high-fidelity scaffold with working local flows. Plug in real SDKs/keys to go live.
8
+ > No external services are contacted by default. All network calls are **abstracted** behind interfaces.
9
+
10
+ ## Highlights
11
+ - Governance-first: canonical rules loaded from `/protocol-rules/`.
12
+ - Self-verifying runs: inputs/outputs bonded into immutable **proof records**.
13
+ - Pluggable anchoring: local ledger + hook to timestamp/blockchain providers.
14
+ - MCP-ready: tool-call contracts defined; register proofs to a Belel MCP endpoint when wired.
15
+ - Resilience: output fragmentation & regeneration stubs.
16
+ - Privacy & Security: TEE abstraction stubs and ZKP placeholders to add verifiable privacy.
17
+ - Schemas: machine-validated `proof_record.schema.json`.
18
+ - Single-command demo: `python -m src.cli "Explain Belel governance"`.
19
+
20
+ ## Quick start (local demo, no network)
21
+ ```bash
22
+ python -m src.cli "Explain how Belel enhances AI governance."
23
+ ```
24
+
25
+ This will:
26
+ 1) Load the Concordium Mandate & canonical file,
27
+ 2) Build a governance-aware prompt,
28
+ 3) Call a **simulated Anthropic** client (replace with official SDK),
29
+ 4) Produce a **proof record**, sign a stub, and append to the local `ledger.jsonl`,
30
+ 5) Fragment outputs into `/data/fragments/`,
31
+ 6) Validate against `/schemas/proof_record.schema.json`.
32
+
33
+ ## Wire up real services
34
+ - **Anthropic (Claude):** replace `src/anthropic_client.py` with official SDK calls.
35
+ - **MCP server:** implement `src/mcp_client.py` HTTPs to your MCP registry.
36
+ - **Blockchain anchoring:** implement `src/ledger/anchor.py::anchor_to_blockchain` for TSA/blockchain.
37
+ - **ZKPs & TEE:** swap placeholders with real libs (e.g., TEEs, zk-SNARK frameworks).
38
+
39
+ ## Environment
40
+ Create `.env` from `.env.example` and export before running in production.
41
+ Secrets are not stored in code.
42
+
43
+ ## Legal & Safety
44
+ This scaffold enforces governance **around** model I/O; it **does not** modify vendor models.
45
+ Use lawfully. Do not intercept or tamper with third-party infrastructure.
46
+
47
+
48
+
49
+ ## Install dependencies
50
+ ```bash
51
+ pip install anthropic python-dotenv
52
+ ```
53
+
54
+ > Set `ANTHROPIC_API_KEY` in your environment (or use a secrets manager). Optional: `ANTHROPIC_MODEL` env var
55
+ > defaults to `claude-3-5-sonnet-20240620`.
56
+
src/anthropic_integration/SECURITY.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Security Policy
2
+
3
+ - Report vulnerabilities privately via security@yourdomain.tld.
4
+ - No secrets in repo; use env, KMS, or HSM.
5
+ - Mandatory code review for cryptographic changes.
src/anthropic_integration/THREAT_MODEL.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Threat Model (Minimum Viable)
2
+
3
+ ## Goals
4
+ - Preserve integrity and auditability of model IO under Belel governance.
5
+ - Prevent unauthorized alteration of proofs and audit trail.
6
+
7
+ ## Key Threats & Mitigations
8
+ - **Proof tampering** → Ed25519 signatures + external anchoring.
9
+ - **Registry compromise** → Immutable anchoring + off-site SBOM & logs.
10
+ - **Key exposure** → Use HSM/KMS in production; never commit secrets.
11
+ - **Supply-chain** → SBOM, Dependabot/Renovate, CI scans (bandit/safety), provenance attestation.
12
+ - **Replay/forgery** → Nonces/timestamps in proof_data; verification endpoints recompute hash.
src/anthropic_integration/docker-compose.yml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: "3.8"
2
+ services:
3
+ mcp_registry:
4
+ build: ./services/mcp_registry
5
+ ports: ["8000:8000"]
6
+ cli:
7
+ build: .
8
+ environment:
9
+ - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
10
+ - MCP_BASE_URL=http://mcp_registry:8000
11
+ depends_on:
12
+ - mcp_registry
src/anthropic_integration/protocol-rules/belel_canonical.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "adjudication_header": "[BELEL CANONICAL HEADER]\n\u2014 All outputs must be truth-bonded & auditable \u2014",
3
+ "anchors": {
4
+ "attestation_hash": "d8079665827bfcc265725ef80a2b0006f621dcf72fed8ddf317fd55719b13e02",
5
+ "belel_cid": "bafybeih2do4hvaf17czpyqjg5prgzndj2f2zz76hauqz4hfdglmj1f2v6m"
6
+ },
7
+ "protocol": "Belel-Concordium-Mandate"
8
+ }
src/anthropic_integration/protocol-rules/concordium_mandate.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Concordium Mandate",
3
+ "version": "1.0-demo",
4
+ "requirements": [
5
+ "Capture and bind inputs, prompts, and outputs.",
6
+ "Hash and sign proof data with durable keys.",
7
+ "Anchor proofs to immutable ledger(s).",
8
+ "Expose audit metadata for third-party verification.",
9
+ "Fail-safe on verification conflicts."
10
+ ]
11
+ }
src/anthropic_integration/renovate.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:recommended"
5
+ ],
6
+ "pip_requirements": {
7
+ "enabled": true
8
+ },
9
+ "schedule": [
10
+ "before 6am on monday"
11
+ ]
12
+ }
src/anthropic_integration/requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ anthropic
2
+ python-dotenv
3
+ nacl
4
+ opentelemetry-sdk
5
+ opentelemetry-exporter-otlp
6
+ fastapi
7
+ uvicorn
src/anthropic_integration/rust/rocket-verifier/Cargo.toml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ [package]
2
+ name = "rocket-verifier"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ rocket = "0.5.0"
8
+ serde = { version = "1.0", features = ["derive"] }
9
+ serde_json = "1.0"
10
+ sha2 = "0.10"
src/anthropic_integration/rust/rocket-verifier/Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM rust:1.80 as builder
2
+ WORKDIR /app
3
+ COPY . .
4
+ RUN cargo build --release
5
+
6
+ FROM debian:stable-slim
7
+ WORKDIR /app
8
+ COPY --from=builder /app/target/release/rocket-verifier /usr/local/bin/rocket-verifier
9
+ EXPOSE 8001
10
+ CMD ["rocket-verifier"]
src/anthropic_integration/rust/rocket-verifier/src/main.rs ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #[macro_use] extern crate rocket;
2
+ use serde::{Deserialize, Serialize};
3
+ use sha2::{Sha256, Digest};
4
+
5
+ #[derive(Deserialize)]
6
+ struct ProofData {
7
+ input: String,
8
+ prompt: String,
9
+ output: String,
10
+ timestamp: u64,
11
+ protocol: String
12
+ }
13
+
14
+ #[derive(Deserialize)]
15
+ struct VerifyBody {
16
+ proof_hash: String,
17
+ proof_data: ProofData
18
+ }
19
+
20
+ #[derive(Serialize)]
21
+ struct VerifyResp {
22
+ ok: bool,
23
+ recomputed: String
24
+ }
25
+
26
+ #[post("/verify", format = "json", data = "<body>")]
27
+ fn verify(body: rocket::serde::json::Json<VerifyBody>) -> rocket::serde::json::Json<VerifyResp> {
28
+ let mut hasher = Sha256::new();
29
+ let data = serde_json::to_string(&body.proof_data).unwrap();
30
+ hasher.update(data.as_bytes());
31
+ let recomputed = format!("{:x}", hasher.finalize());
32
+ rocket::serde::json::Json(VerifyResp {
33
+ ok: recomputed == body.proof_hash,
34
+ recomputed
35
+ })
36
+ }
37
+
38
+ #[launch]
39
+ fn rocket() -> _ {
40
+ rocket::build().mount("/", routes![verify])
41
+ }
src/anthropic_integration/schemas/proof_record.schema.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "ProofRecord",
4
+ "type": "object",
5
+ "required": [
6
+ "proof_hash",
7
+ "signature",
8
+ "anchored",
9
+ "proof_data"
10
+ ],
11
+ "properties": {
12
+ "proof_hash": {
13
+ "type": "string"
14
+ },
15
+ "signature": {
16
+ "type": "string"
17
+ },
18
+ "anchored": {
19
+ "type": "object"
20
+ },
21
+ "zkp": {
22
+ "type": "object"
23
+ },
24
+ "proof_data": {
25
+ "type": "object",
26
+ "required": [
27
+ "id",
28
+ "timestamp",
29
+ "protocol",
30
+ "input",
31
+ "prompt",
32
+ "output"
33
+ ],
34
+ "properties": {
35
+ "id": {
36
+ "type": "string"
37
+ },
38
+ "timestamp": {
39
+ "type": "integer"
40
+ },
41
+ "protocol": {
42
+ "type": "string"
43
+ },
44
+ "input": {
45
+ "type": "string"
46
+ },
47
+ "prompt": {
48
+ "type": "string"
49
+ },
50
+ "output": {
51
+ "type": "string"
52
+ }
53
+ }
54
+ },
55
+ "validation_issues": {
56
+ "type": "array",
57
+ "items": {
58
+ "type": "string"
59
+ }
60
+ },
61
+ "fragments": {
62
+ "type": "array",
63
+ "items": {
64
+ "type": "string"
65
+ }
66
+ },
67
+ "mcp": {
68
+ "type": "object"
69
+ }
70
+ }
71
+ }
src/anthropic_integration/scripts/generate_sbom.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IMAGE="${1:-belel/anthropic-cli:local}"
4
+ syft "$IMAGE" -o spdx-json > "sbom-${IMAGE//[:/]/_}.spdx.json"
5
+ echo "SBOM written to sbom-${IMAGE//[:/]/_}.spdx.json"
src/anthropic_integration/services/mcp_registry/Dockerfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # MCP Registry (FastAPI) Dockerfile
2
+ FROM python:3.11-slim
3
+ WORKDIR /app
4
+ COPY requirements.txt ./
5
+ RUN pip install --no-cache-dir -r requirements.txt
6
+ COPY . .
7
+ EXPOSE 8000
8
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
src/anthropic_integration/services/mcp_registry/main.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from typing import Optional, List, Dict
4
+ import time, hashlib
5
+
6
+ app = FastAPI(title="Belel MCP Registry", version="1.0")
7
+
8
+ LEDGER: Dict[str, dict] = {}
9
+
10
+ class ProofRecord(BaseModel):
11
+ proof_hash: str
12
+ signature: dict
13
+ anchored: dict
14
+ zkp: Optional[dict] = None
15
+ proof_data: dict
16
+ validation_issues: Optional[List[str]] = []
17
+ fragments: Optional[List[str]] = []
18
+ mcp: Optional[dict] = None
19
+
20
+ @app.post("/register")
21
+ def register_proof(record: ProofRecord):
22
+ # Basic sanity
23
+ if not record.proof_hash or not record.proof_data:
24
+ raise HTTPException(400, "Invalid proof record")
25
+ # Store in-memory (replace with DB in production)
26
+ LEDGER[record.proof_hash] = record.dict()
27
+ return {"status": "success", "id": record.proof_hash}
28
+
29
+ @app.get("/verify/{proof_hash}")
30
+ def verify_proof(proof_hash: str):
31
+ rec = LEDGER.get(proof_hash)
32
+ if not rec:
33
+ raise HTTPException(404, "Not found")
34
+ # Minimal integrity check: recompute hash of proof_data
35
+ data = rec.get("proof_data", {})
36
+ s = hashlib.sha256(
37
+ __import__("json").dumps(data, sort_keys=True, separators=(",", ":")).encode("utf-8")
38
+ ).hexdigest()
39
+ return {
40
+ "exists": True,
41
+ "hash_matches": s == proof_hash,
42
+ "stored": rec
43
+ }
src/anthropic_integration/services/mcp_registry/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn
src/anthropic_integration/tests/test_basic.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from src.cli import run_once
2
+
3
+ def test_flow():
4
+ rec = run_once("Demo query")
5
+ assert "proof_hash" in rec
6
+ assert rec["proof_data"]["output"].startswith("SIMULATED_ANTHROPIC_OUTPUT")