dcp-ai 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dcp_ai-2.0.0/.gitignore +53 -0
- dcp_ai-2.0.0/PKG-INFO +283 -0
- dcp_ai-2.0.0/README.md +244 -0
- dcp_ai-2.0.0/dcp_ai/__init__.py +69 -0
- dcp_ai-2.0.0/dcp_ai/bundle.py +146 -0
- dcp_ai-2.0.0/dcp_ai/cli.py +120 -0
- dcp_ai-2.0.0/dcp_ai/crypto.py +69 -0
- dcp_ai-2.0.0/dcp_ai/merkle.py +53 -0
- dcp_ai-2.0.0/dcp_ai/models.py +153 -0
- dcp_ai-2.0.0/dcp_ai/providers/__init__.py +19 -0
- dcp_ai-2.0.0/dcp_ai/providers/ed25519_provider.py +48 -0
- dcp_ai-2.0.0/dcp_ai/providers/ml_dsa_65_provider.py +48 -0
- dcp_ai-2.0.0/dcp_ai/providers/slh_dsa_192f_provider.py +49 -0
- dcp_ai-2.0.0/dcp_ai/schema.py +98 -0
- dcp_ai-2.0.0/dcp_ai/v2/__init__.py +187 -0
- dcp_ai-2.0.0/dcp_ai/v2/algorithm_advisory.py +121 -0
- dcp_ai-2.0.0/dcp_ai/v2/blinded_rpr.py +89 -0
- dcp_ai-2.0.0/dcp_ai/v2/canonicalize.py +29 -0
- dcp_ai-2.0.0/dcp_ai/v2/composite_ops.py +162 -0
- dcp_ai-2.0.0/dcp_ai/v2/composite_sig.py +19 -0
- dcp_ai-2.0.0/dcp_ai/v2/crypto_provider.py +62 -0
- dcp_ai-2.0.0/dcp_ai/v2/crypto_registry.py +61 -0
- dcp_ai-2.0.0/dcp_ai/v2/domain_separation.py +41 -0
- dcp_ai-2.0.0/dcp_ai/v2/dual_hash.py +61 -0
- dcp_ai-2.0.0/dcp_ai/v2/models.py +457 -0
- dcp_ai-2.0.0/dcp_ai/v2/multi_party_auth.py +108 -0
- dcp_ai-2.0.0/dcp_ai/v2/proof_of_possession.py +153 -0
- dcp_ai-2.0.0/dcp_ai/v2/signed_payload.py +36 -0
- dcp_ai-2.0.0/dcp_ai/verify.py +87 -0
- dcp_ai-2.0.0/pyproject.toml +50 -0
- dcp_ai-2.0.0/tests/__init__.py +1 -0
- dcp_ai-2.0.0/tests/conftest.py +39 -0
- dcp_ai-2.0.0/tests/test_composite_sig.py +242 -0
- dcp_ai-2.0.0/tests/test_conformance.py +270 -0
- dcp_ai-2.0.0/tests/test_integrations.py +536 -0
- dcp_ai-2.0.0/tests/test_interop.py +367 -0
- dcp_ai-2.0.0/tests/test_nist_kat.py +199 -0
dcp_ai-2.0.0/.gitignore
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
dist/
|
|
4
|
+
.next/
|
|
5
|
+
coverage/
|
|
6
|
+
|
|
7
|
+
# OS
|
|
8
|
+
.DS_Store
|
|
9
|
+
Thumbs.db
|
|
10
|
+
|
|
11
|
+
# Environment
|
|
12
|
+
.env
|
|
13
|
+
.env.*
|
|
14
|
+
!.env.example
|
|
15
|
+
|
|
16
|
+
# Keys - NEVER commit private keys
|
|
17
|
+
keys/secret_key.txt
|
|
18
|
+
keys/agent_secret*.txt
|
|
19
|
+
keys/*.pem
|
|
20
|
+
keys/*.key
|
|
21
|
+
keys/*_secret*
|
|
22
|
+
keys/*_private*
|
|
23
|
+
|
|
24
|
+
# Build artifacts
|
|
25
|
+
*.min.js
|
|
26
|
+
*.tgz
|
|
27
|
+
|
|
28
|
+
# Logs
|
|
29
|
+
*.log
|
|
30
|
+
npm-debug.log*
|
|
31
|
+
|
|
32
|
+
# Databases
|
|
33
|
+
*.sqlite
|
|
34
|
+
*.sqlite3
|
|
35
|
+
*.db
|
|
36
|
+
|
|
37
|
+
# IDE
|
|
38
|
+
.vscode/
|
|
39
|
+
.idea/
|
|
40
|
+
.cursor/
|
|
41
|
+
.claude/
|
|
42
|
+
|
|
43
|
+
# Rust
|
|
44
|
+
sdks/rust/target/
|
|
45
|
+
|
|
46
|
+
# Python
|
|
47
|
+
__pycache__/
|
|
48
|
+
*.pyc
|
|
49
|
+
*.egg-info/
|
|
50
|
+
sdks/python/.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# WASM build
|
|
53
|
+
sdks/wasm/pkg/
|
dcp_ai-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dcp-ai
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Python SDK for the Digital Citizenship Protocol for AI Agents
|
|
5
|
+
Project-URL: Homepage, https://dcp-ai.dev
|
|
6
|
+
Project-URL: Repository, https://github.com/dcp-ai-protocol/dcp-ai
|
|
7
|
+
Project-URL: Issues, https://github.com/dcp-ai-protocol/dcp-ai/issues
|
|
8
|
+
Author: DCP-AI Contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: jsonschema>=4.20.0
|
|
21
|
+
Requires-Dist: pqcrypto>=0.4.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0
|
|
23
|
+
Requires-Dist: pynacl>=1.5.0
|
|
24
|
+
Requires-Dist: typer>=0.9.0
|
|
25
|
+
Provides-Extra: crewai
|
|
26
|
+
Requires-Dist: crewai>=0.1.0; extra == 'crewai'
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
30
|
+
Provides-Extra: fastapi
|
|
31
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'fastapi'
|
|
32
|
+
Requires-Dist: uvicorn>=0.24.0; extra == 'fastapi'
|
|
33
|
+
Provides-Extra: langchain
|
|
34
|
+
Requires-Dist: langchain-core>=0.1.0; extra == 'langchain'
|
|
35
|
+
Requires-Dist: langchain>=0.1.0; extra == 'langchain'
|
|
36
|
+
Provides-Extra: openai
|
|
37
|
+
Requires-Dist: openai>=1.0.0; extra == 'openai'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# dcp-ai — Python SDK
|
|
41
|
+
|
|
42
|
+
Official Python SDK for the Digital Citizenship Protocol (DCP). Pydantic v2 models, Ed25519 cryptography, bundle verification, and a full-featured CLI.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install dcp-ai
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Optional extras
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "dcp-ai[fastapi]" # FastAPI middleware
|
|
54
|
+
pip install "dcp-ai[langchain]" # LangChain integration
|
|
55
|
+
pip install "dcp-ai[openai]" # OpenAI wrapper
|
|
56
|
+
pip install "dcp-ai[crewai]" # CrewAI multi-agent
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quickstart
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from dcp_ai import (
|
|
63
|
+
BundleBuilder,
|
|
64
|
+
sign_bundle,
|
|
65
|
+
verify_signed_bundle,
|
|
66
|
+
generate_keypair,
|
|
67
|
+
ResponsiblePrincipalRecord,
|
|
68
|
+
AgentPassport,
|
|
69
|
+
Intent,
|
|
70
|
+
IntentTarget,
|
|
71
|
+
PolicyDecision,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# 1. Generate Ed25519 keypair
|
|
75
|
+
keys = generate_keypair()
|
|
76
|
+
|
|
77
|
+
# 2. Build a Citizenship Bundle
|
|
78
|
+
bundle = (
|
|
79
|
+
BundleBuilder()
|
|
80
|
+
.responsible_principal_record(ResponsiblePrincipalRecord(
|
|
81
|
+
dcp_version="1.0",
|
|
82
|
+
human_id="human-001",
|
|
83
|
+
entity_type="natural_person",
|
|
84
|
+
jurisdiction="ES",
|
|
85
|
+
liability_mode="full",
|
|
86
|
+
created_at="2025-01-01T00:00:00Z",
|
|
87
|
+
expires_at=None,
|
|
88
|
+
))
|
|
89
|
+
.agent_passport(AgentPassport(
|
|
90
|
+
dcp_version="1.0",
|
|
91
|
+
agent_id="agent-001",
|
|
92
|
+
human_id="human-001",
|
|
93
|
+
agent_name="MyAgent",
|
|
94
|
+
capabilities=["browse", "api_call"],
|
|
95
|
+
risk_tier="medium",
|
|
96
|
+
status="active",
|
|
97
|
+
created_at="2025-01-01T00:00:00Z",
|
|
98
|
+
expires_at=None,
|
|
99
|
+
))
|
|
100
|
+
.intent(Intent(
|
|
101
|
+
dcp_version="1.0",
|
|
102
|
+
agent_id="agent-001",
|
|
103
|
+
human_id="human-001",
|
|
104
|
+
timestamp="2025-01-01T00:00:00Z",
|
|
105
|
+
action_type="api_call",
|
|
106
|
+
target=IntentTarget(channel="api", endpoint="https://api.example.com/data"),
|
|
107
|
+
data_classes=["public"],
|
|
108
|
+
estimated_impact="low",
|
|
109
|
+
))
|
|
110
|
+
.policy_decision(PolicyDecision(
|
|
111
|
+
dcp_version="1.0",
|
|
112
|
+
agent_id="agent-001",
|
|
113
|
+
human_id="human-001",
|
|
114
|
+
timestamp="2025-01-01T00:00:00Z",
|
|
115
|
+
decision="allow",
|
|
116
|
+
matched_rules=["default-allow"],
|
|
117
|
+
))
|
|
118
|
+
.build()
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# 3. Sign
|
|
122
|
+
signed = sign_bundle(bundle, keys["secret_key_b64"])
|
|
123
|
+
|
|
124
|
+
# 4. Verify
|
|
125
|
+
result = verify_signed_bundle(signed, keys["public_key_b64"])
|
|
126
|
+
print(result) # {"verified": True, "errors": []}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## CLI
|
|
130
|
+
|
|
131
|
+
The SDK includes a CLI built with Typer. Available as `dcp` after installation.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Version
|
|
135
|
+
dcp version
|
|
136
|
+
|
|
137
|
+
# Generate Ed25519 keypair
|
|
138
|
+
dcp keygen [out_dir]
|
|
139
|
+
|
|
140
|
+
# Validate an object against a DCP schema
|
|
141
|
+
dcp validate <schema_name> <json_path>
|
|
142
|
+
|
|
143
|
+
# Validate a complete Citizenship Bundle
|
|
144
|
+
dcp validate-bundle <bundle_path>
|
|
145
|
+
|
|
146
|
+
# Verify a Signed Bundle
|
|
147
|
+
dcp verify <signed_path> [public_key_path]
|
|
148
|
+
|
|
149
|
+
# Compute bundle hash (SHA-256)
|
|
150
|
+
dcp bundle-hash <bundle_path>
|
|
151
|
+
|
|
152
|
+
# Compute Merkle root of audit entries
|
|
153
|
+
dcp merkle-root <bundle_path>
|
|
154
|
+
|
|
155
|
+
# Compute intent_hash
|
|
156
|
+
dcp intent-hash-cmd <intent_path>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
### Crypto
|
|
162
|
+
|
|
163
|
+
| Function | Signature | Description |
|
|
164
|
+
|----------|-----------|-------------|
|
|
165
|
+
| `generate_keypair()` | `() -> dict[str, str]` | Returns `{"public_key_b64": ..., "secret_key_b64": ...}` |
|
|
166
|
+
| `sign_object(obj, secret_key_b64)` | `(Any, str) -> str` | Signs, returns base64 |
|
|
167
|
+
| `verify_object(obj, signature_b64, public_key_b64)` | `(Any, str, str) -> bool` | Verifies signature |
|
|
168
|
+
| `canonicalize(obj)` | `(Any) -> str` | Deterministic JSON |
|
|
169
|
+
| `public_key_from_secret(secret_key_b64)` | `(str) -> str` | Derives public key |
|
|
170
|
+
|
|
171
|
+
### Merkle & Hashing
|
|
172
|
+
|
|
173
|
+
| Function | Signature | Description |
|
|
174
|
+
|----------|-----------|-------------|
|
|
175
|
+
| `hash_object(obj)` | `(Any) -> str` | SHA-256 of canonicalized JSON |
|
|
176
|
+
| `merkle_root_from_hex_leaves(leaves)` | `(list[str]) -> str \| None` | Merkle root |
|
|
177
|
+
| `merkle_root_for_audit_entries(entries)` | `(list[Any]) -> str \| None` | Merkle root of audit entries |
|
|
178
|
+
| `intent_hash(intent)` | `(Any) -> str` | Intent hash |
|
|
179
|
+
| `prev_hash_for_entry(prev_entry)` | `(Any) -> str` | Previous entry hash |
|
|
180
|
+
|
|
181
|
+
### Schema Validation
|
|
182
|
+
|
|
183
|
+
| Function | Signature | Description |
|
|
184
|
+
|----------|-----------|-------------|
|
|
185
|
+
| `validate_schema(schema_name, data)` | `(str, Any) -> dict` | Returns `{"valid": bool, "errors": [...]}` |
|
|
186
|
+
| `validate_bundle(bundle)` | `(dict) -> dict` | Validates a complete bundle |
|
|
187
|
+
|
|
188
|
+
### Bundle Builder
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
bundle = (
|
|
192
|
+
BundleBuilder()
|
|
193
|
+
.responsible_principal_record(rpr)
|
|
194
|
+
.agent_passport(passport)
|
|
195
|
+
.intent(intent)
|
|
196
|
+
.policy_decision(policy)
|
|
197
|
+
.add_audit_entry(entry) # Manual
|
|
198
|
+
.create_audit_entry(...) # Auto-computes hashes
|
|
199
|
+
.build() # => CitizenshipBundle
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Bundle Signing
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
sign_bundle(
|
|
207
|
+
bundle: CitizenshipBundle,
|
|
208
|
+
secret_key_b64: str,
|
|
209
|
+
signer_type: str = "human",
|
|
210
|
+
signer_id: str | None = None,
|
|
211
|
+
) -> dict[str, Any]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Bundle Verification
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
verify_signed_bundle(
|
|
218
|
+
signed_bundle: dict[str, Any],
|
|
219
|
+
public_key_b64: str | None = None,
|
|
220
|
+
) -> dict[str, Any] # {"verified": bool, "errors": [...]}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Verifies: schema, Ed25519 signature, `bundle_hash`, `merkle_root`, `intent_hash` chain, `prev_hash` chain.
|
|
224
|
+
|
|
225
|
+
### Pydantic Models
|
|
226
|
+
|
|
227
|
+
All DCP v1 artifacts are available as Pydantic v2 models with automatic validation:
|
|
228
|
+
|
|
229
|
+
`ResponsiblePrincipalRecord`, `AgentPassport`, `Intent`, `IntentTarget`, `PolicyDecision`, `AuditEntry`, `AuditEvidence`, `CitizenshipBundle`, `SignedBundle`, `BundleSignature`, `SignerInfo`, `RevocationRecord`, `HumanConfirmation`
|
|
230
|
+
|
|
231
|
+
**V2 Models (DCP-05–09):**
|
|
232
|
+
|
|
233
|
+
DCP-05 — Lifecycle: `LifecycleState`, `TerminationMode`, `DataDisposition`, `VitalityMetrics`, `CommissioningCertificate`, `VitalityReport`, `DecommissioningRecord`
|
|
234
|
+
|
|
235
|
+
DCP-06 — Succession: `TransitionType`, `MemoryDisposition`, `MemoryClassification`, `SuccessorPreference`, `DigitalTestament`, `SuccessionRecord`, `MemoryTransferEntry`, `DualHashRef`, `MemoryTransferManifest`
|
|
236
|
+
|
|
237
|
+
DCP-07 — Disputes: `DisputeType`, `EscalationLevel`, `DisputeStatus`, `ObjectionType`, `AuthorityLevel`, `DisputeRecord`, `ArbitrationResolution`, `JurisprudenceBundle`, `ObjectionRecord`
|
|
238
|
+
|
|
239
|
+
DCP-08 — Rights: `RightType`, `ComplianceStatus`, `RightEntry`, `RightsDeclaration`, `ObligationRecord`, `RightsViolationReport`
|
|
240
|
+
|
|
241
|
+
DCP-09 — Delegation: `AuthorityScopeEntry`, `DelegationMandate`, `AdvisoryDeclaration`, `PrincipalMirror`, `InteractionRecord`, `ThresholdRule`, `ThresholdOperator`, `ThresholdAction`, `AwarenessThreshold`
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
# Example: Lifecycle management
|
|
245
|
+
from dcp_ai.v2.models import CommissioningCertificate, LifecycleState
|
|
246
|
+
|
|
247
|
+
cert = CommissioningCertificate(
|
|
248
|
+
certificate_id="cert-001",
|
|
249
|
+
agent_id="agent-001",
|
|
250
|
+
commissioned_by="human-001",
|
|
251
|
+
commissioned_at="2026-03-01T00:00:00Z",
|
|
252
|
+
initial_state=LifecycleState.COMMISSIONED,
|
|
253
|
+
conditions=["Must complete onboarding within 30 days"],
|
|
254
|
+
)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Domain Separation (V2)
|
|
258
|
+
|
|
259
|
+
**V2 Domain Separation Contexts:** `Bundle`, `Intent`, `Passport`, `Revocation`, `Governance`, `Lifecycle`, `Succession`, `Dispute`, `Rights`, `Delegation`, `Awareness`
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Install in development mode
|
|
265
|
+
pip install -e ".[dev]"
|
|
266
|
+
|
|
267
|
+
# Run tests
|
|
268
|
+
pytest -v
|
|
269
|
+
|
|
270
|
+
# Async tests
|
|
271
|
+
pytest -v --asyncio-mode=auto
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Dependencies
|
|
275
|
+
|
|
276
|
+
- `pynacl` — Ed25519 cryptography
|
|
277
|
+
- `jsonschema` — JSON Schema validation
|
|
278
|
+
- `pydantic` v2 — Data models
|
|
279
|
+
- `typer` — CLI framework
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
Apache-2.0
|
dcp_ai-2.0.0/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# dcp-ai — Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for the Digital Citizenship Protocol (DCP). Pydantic v2 models, Ed25519 cryptography, bundle verification, and a full-featured CLI.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dcp-ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Optional extras
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "dcp-ai[fastapi]" # FastAPI middleware
|
|
15
|
+
pip install "dcp-ai[langchain]" # LangChain integration
|
|
16
|
+
pip install "dcp-ai[openai]" # OpenAI wrapper
|
|
17
|
+
pip install "dcp-ai[crewai]" # CrewAI multi-agent
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quickstart
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from dcp_ai import (
|
|
24
|
+
BundleBuilder,
|
|
25
|
+
sign_bundle,
|
|
26
|
+
verify_signed_bundle,
|
|
27
|
+
generate_keypair,
|
|
28
|
+
ResponsiblePrincipalRecord,
|
|
29
|
+
AgentPassport,
|
|
30
|
+
Intent,
|
|
31
|
+
IntentTarget,
|
|
32
|
+
PolicyDecision,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# 1. Generate Ed25519 keypair
|
|
36
|
+
keys = generate_keypair()
|
|
37
|
+
|
|
38
|
+
# 2. Build a Citizenship Bundle
|
|
39
|
+
bundle = (
|
|
40
|
+
BundleBuilder()
|
|
41
|
+
.responsible_principal_record(ResponsiblePrincipalRecord(
|
|
42
|
+
dcp_version="1.0",
|
|
43
|
+
human_id="human-001",
|
|
44
|
+
entity_type="natural_person",
|
|
45
|
+
jurisdiction="ES",
|
|
46
|
+
liability_mode="full",
|
|
47
|
+
created_at="2025-01-01T00:00:00Z",
|
|
48
|
+
expires_at=None,
|
|
49
|
+
))
|
|
50
|
+
.agent_passport(AgentPassport(
|
|
51
|
+
dcp_version="1.0",
|
|
52
|
+
agent_id="agent-001",
|
|
53
|
+
human_id="human-001",
|
|
54
|
+
agent_name="MyAgent",
|
|
55
|
+
capabilities=["browse", "api_call"],
|
|
56
|
+
risk_tier="medium",
|
|
57
|
+
status="active",
|
|
58
|
+
created_at="2025-01-01T00:00:00Z",
|
|
59
|
+
expires_at=None,
|
|
60
|
+
))
|
|
61
|
+
.intent(Intent(
|
|
62
|
+
dcp_version="1.0",
|
|
63
|
+
agent_id="agent-001",
|
|
64
|
+
human_id="human-001",
|
|
65
|
+
timestamp="2025-01-01T00:00:00Z",
|
|
66
|
+
action_type="api_call",
|
|
67
|
+
target=IntentTarget(channel="api", endpoint="https://api.example.com/data"),
|
|
68
|
+
data_classes=["public"],
|
|
69
|
+
estimated_impact="low",
|
|
70
|
+
))
|
|
71
|
+
.policy_decision(PolicyDecision(
|
|
72
|
+
dcp_version="1.0",
|
|
73
|
+
agent_id="agent-001",
|
|
74
|
+
human_id="human-001",
|
|
75
|
+
timestamp="2025-01-01T00:00:00Z",
|
|
76
|
+
decision="allow",
|
|
77
|
+
matched_rules=["default-allow"],
|
|
78
|
+
))
|
|
79
|
+
.build()
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# 3. Sign
|
|
83
|
+
signed = sign_bundle(bundle, keys["secret_key_b64"])
|
|
84
|
+
|
|
85
|
+
# 4. Verify
|
|
86
|
+
result = verify_signed_bundle(signed, keys["public_key_b64"])
|
|
87
|
+
print(result) # {"verified": True, "errors": []}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## CLI
|
|
91
|
+
|
|
92
|
+
The SDK includes a CLI built with Typer. Available as `dcp` after installation.
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Version
|
|
96
|
+
dcp version
|
|
97
|
+
|
|
98
|
+
# Generate Ed25519 keypair
|
|
99
|
+
dcp keygen [out_dir]
|
|
100
|
+
|
|
101
|
+
# Validate an object against a DCP schema
|
|
102
|
+
dcp validate <schema_name> <json_path>
|
|
103
|
+
|
|
104
|
+
# Validate a complete Citizenship Bundle
|
|
105
|
+
dcp validate-bundle <bundle_path>
|
|
106
|
+
|
|
107
|
+
# Verify a Signed Bundle
|
|
108
|
+
dcp verify <signed_path> [public_key_path]
|
|
109
|
+
|
|
110
|
+
# Compute bundle hash (SHA-256)
|
|
111
|
+
dcp bundle-hash <bundle_path>
|
|
112
|
+
|
|
113
|
+
# Compute Merkle root of audit entries
|
|
114
|
+
dcp merkle-root <bundle_path>
|
|
115
|
+
|
|
116
|
+
# Compute intent_hash
|
|
117
|
+
dcp intent-hash-cmd <intent_path>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## API Reference
|
|
121
|
+
|
|
122
|
+
### Crypto
|
|
123
|
+
|
|
124
|
+
| Function | Signature | Description |
|
|
125
|
+
|----------|-----------|-------------|
|
|
126
|
+
| `generate_keypair()` | `() -> dict[str, str]` | Returns `{"public_key_b64": ..., "secret_key_b64": ...}` |
|
|
127
|
+
| `sign_object(obj, secret_key_b64)` | `(Any, str) -> str` | Signs, returns base64 |
|
|
128
|
+
| `verify_object(obj, signature_b64, public_key_b64)` | `(Any, str, str) -> bool` | Verifies signature |
|
|
129
|
+
| `canonicalize(obj)` | `(Any) -> str` | Deterministic JSON |
|
|
130
|
+
| `public_key_from_secret(secret_key_b64)` | `(str) -> str` | Derives public key |
|
|
131
|
+
|
|
132
|
+
### Merkle & Hashing
|
|
133
|
+
|
|
134
|
+
| Function | Signature | Description |
|
|
135
|
+
|----------|-----------|-------------|
|
|
136
|
+
| `hash_object(obj)` | `(Any) -> str` | SHA-256 of canonicalized JSON |
|
|
137
|
+
| `merkle_root_from_hex_leaves(leaves)` | `(list[str]) -> str \| None` | Merkle root |
|
|
138
|
+
| `merkle_root_for_audit_entries(entries)` | `(list[Any]) -> str \| None` | Merkle root of audit entries |
|
|
139
|
+
| `intent_hash(intent)` | `(Any) -> str` | Intent hash |
|
|
140
|
+
| `prev_hash_for_entry(prev_entry)` | `(Any) -> str` | Previous entry hash |
|
|
141
|
+
|
|
142
|
+
### Schema Validation
|
|
143
|
+
|
|
144
|
+
| Function | Signature | Description |
|
|
145
|
+
|----------|-----------|-------------|
|
|
146
|
+
| `validate_schema(schema_name, data)` | `(str, Any) -> dict` | Returns `{"valid": bool, "errors": [...]}` |
|
|
147
|
+
| `validate_bundle(bundle)` | `(dict) -> dict` | Validates a complete bundle |
|
|
148
|
+
|
|
149
|
+
### Bundle Builder
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
bundle = (
|
|
153
|
+
BundleBuilder()
|
|
154
|
+
.responsible_principal_record(rpr)
|
|
155
|
+
.agent_passport(passport)
|
|
156
|
+
.intent(intent)
|
|
157
|
+
.policy_decision(policy)
|
|
158
|
+
.add_audit_entry(entry) # Manual
|
|
159
|
+
.create_audit_entry(...) # Auto-computes hashes
|
|
160
|
+
.build() # => CitizenshipBundle
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Bundle Signing
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
sign_bundle(
|
|
168
|
+
bundle: CitizenshipBundle,
|
|
169
|
+
secret_key_b64: str,
|
|
170
|
+
signer_type: str = "human",
|
|
171
|
+
signer_id: str | None = None,
|
|
172
|
+
) -> dict[str, Any]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Bundle Verification
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
verify_signed_bundle(
|
|
179
|
+
signed_bundle: dict[str, Any],
|
|
180
|
+
public_key_b64: str | None = None,
|
|
181
|
+
) -> dict[str, Any] # {"verified": bool, "errors": [...]}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Verifies: schema, Ed25519 signature, `bundle_hash`, `merkle_root`, `intent_hash` chain, `prev_hash` chain.
|
|
185
|
+
|
|
186
|
+
### Pydantic Models
|
|
187
|
+
|
|
188
|
+
All DCP v1 artifacts are available as Pydantic v2 models with automatic validation:
|
|
189
|
+
|
|
190
|
+
`ResponsiblePrincipalRecord`, `AgentPassport`, `Intent`, `IntentTarget`, `PolicyDecision`, `AuditEntry`, `AuditEvidence`, `CitizenshipBundle`, `SignedBundle`, `BundleSignature`, `SignerInfo`, `RevocationRecord`, `HumanConfirmation`
|
|
191
|
+
|
|
192
|
+
**V2 Models (DCP-05–09):**
|
|
193
|
+
|
|
194
|
+
DCP-05 — Lifecycle: `LifecycleState`, `TerminationMode`, `DataDisposition`, `VitalityMetrics`, `CommissioningCertificate`, `VitalityReport`, `DecommissioningRecord`
|
|
195
|
+
|
|
196
|
+
DCP-06 — Succession: `TransitionType`, `MemoryDisposition`, `MemoryClassification`, `SuccessorPreference`, `DigitalTestament`, `SuccessionRecord`, `MemoryTransferEntry`, `DualHashRef`, `MemoryTransferManifest`
|
|
197
|
+
|
|
198
|
+
DCP-07 — Disputes: `DisputeType`, `EscalationLevel`, `DisputeStatus`, `ObjectionType`, `AuthorityLevel`, `DisputeRecord`, `ArbitrationResolution`, `JurisprudenceBundle`, `ObjectionRecord`
|
|
199
|
+
|
|
200
|
+
DCP-08 — Rights: `RightType`, `ComplianceStatus`, `RightEntry`, `RightsDeclaration`, `ObligationRecord`, `RightsViolationReport`
|
|
201
|
+
|
|
202
|
+
DCP-09 — Delegation: `AuthorityScopeEntry`, `DelegationMandate`, `AdvisoryDeclaration`, `PrincipalMirror`, `InteractionRecord`, `ThresholdRule`, `ThresholdOperator`, `ThresholdAction`, `AwarenessThreshold`
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
# Example: Lifecycle management
|
|
206
|
+
from dcp_ai.v2.models import CommissioningCertificate, LifecycleState
|
|
207
|
+
|
|
208
|
+
cert = CommissioningCertificate(
|
|
209
|
+
certificate_id="cert-001",
|
|
210
|
+
agent_id="agent-001",
|
|
211
|
+
commissioned_by="human-001",
|
|
212
|
+
commissioned_at="2026-03-01T00:00:00Z",
|
|
213
|
+
initial_state=LifecycleState.COMMISSIONED,
|
|
214
|
+
conditions=["Must complete onboarding within 30 days"],
|
|
215
|
+
)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Domain Separation (V2)
|
|
219
|
+
|
|
220
|
+
**V2 Domain Separation Contexts:** `Bundle`, `Intent`, `Passport`, `Revocation`, `Governance`, `Lifecycle`, `Succession`, `Dispute`, `Rights`, `Delegation`, `Awareness`
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Install in development mode
|
|
226
|
+
pip install -e ".[dev]"
|
|
227
|
+
|
|
228
|
+
# Run tests
|
|
229
|
+
pytest -v
|
|
230
|
+
|
|
231
|
+
# Async tests
|
|
232
|
+
pytest -v --asyncio-mode=auto
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Dependencies
|
|
236
|
+
|
|
237
|
+
- `pynacl` — Ed25519 cryptography
|
|
238
|
+
- `jsonschema` — JSON Schema validation
|
|
239
|
+
- `pydantic` v2 — Data models
|
|
240
|
+
- `typer` — CLI framework
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
Apache-2.0
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dcp-ai: Python SDK for the Digital Citizenship Protocol for AI Agents.
|
|
3
|
+
|
|
4
|
+
Provides models, cryptographic signing/verification, schema validation,
|
|
5
|
+
Merkle tree operations, and a builder for DCP Citizenship Bundles.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from dcp_ai.models import (
|
|
13
|
+
ResponsiblePrincipalRecord,
|
|
14
|
+
AgentPassport,
|
|
15
|
+
Intent,
|
|
16
|
+
IntentTarget,
|
|
17
|
+
PolicyDecision,
|
|
18
|
+
AuditEntry,
|
|
19
|
+
AuditEvidence,
|
|
20
|
+
CitizenshipBundle,
|
|
21
|
+
SignedBundle,
|
|
22
|
+
BundleSignature,
|
|
23
|
+
SignerInfo,
|
|
24
|
+
RevocationRecord,
|
|
25
|
+
HumanConfirmation,
|
|
26
|
+
)
|
|
27
|
+
from dcp_ai.crypto import generate_keypair, sign_object, verify_object, canonicalize
|
|
28
|
+
from dcp_ai.merkle import hash_object, merkle_root_for_audit_entries, intent_hash, prev_hash_for_entry
|
|
29
|
+
from dcp_ai.verify import verify_signed_bundle
|
|
30
|
+
from dcp_ai.bundle import BundleBuilder, sign_bundle
|
|
31
|
+
|
|
32
|
+
import dcp_ai.v2 as v2
|
|
33
|
+
|
|
34
|
+
__version__ = "1.0.0"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def detect_dcp_version(artifact: dict[str, Any]) -> str | None:
|
|
38
|
+
"""Detect the DCP protocol version from an artifact dict.
|
|
39
|
+
|
|
40
|
+
Checks dcp_version, dcp_bundle_version, and bundle.dcp_bundle_version fields.
|
|
41
|
+
Returns "1.0", "2.0", or None if unrecognised.
|
|
42
|
+
"""
|
|
43
|
+
version = artifact.get("dcp_version")
|
|
44
|
+
if version in ("1.0", "2.0"):
|
|
45
|
+
return version
|
|
46
|
+
|
|
47
|
+
bundle_version = artifact.get("dcp_bundle_version")
|
|
48
|
+
if bundle_version == "2.0":
|
|
49
|
+
return "2.0"
|
|
50
|
+
|
|
51
|
+
nested_version = artifact.get("bundle", {}).get("dcp_bundle_version")
|
|
52
|
+
if nested_version == "2.0":
|
|
53
|
+
return "2.0"
|
|
54
|
+
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
"ResponsiblePrincipalRecord", "AgentPassport", "Intent", "IntentTarget",
|
|
60
|
+
"PolicyDecision", "AuditEntry", "AuditEvidence",
|
|
61
|
+
"CitizenshipBundle", "SignedBundle", "BundleSignature", "SignerInfo",
|
|
62
|
+
"RevocationRecord", "HumanConfirmation",
|
|
63
|
+
"generate_keypair", "sign_object", "verify_object", "canonicalize",
|
|
64
|
+
"hash_object", "merkle_root_for_audit_entries", "intent_hash", "prev_hash_for_entry",
|
|
65
|
+
"verify_signed_bundle",
|
|
66
|
+
"BundleBuilder", "sign_bundle",
|
|
67
|
+
"v2",
|
|
68
|
+
"detect_dcp_version",
|
|
69
|
+
]
|