dcp-ai 2.7.0

Rust SDK for the Digital Citizenship Protocol for AI Agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
//! DCP v2.0 artifact types.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::composite_sig::CompositeSignature;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyEntry {
    pub kid: String,
    pub alg: String,
    pub public_key_b64: String,
    pub created_at: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    pub status: String,
}

// ── DCP-01: Identity & Human Binding ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentPassportV2 {
    pub dcp_version: String,
    pub agent_id: String,
    pub session_nonce: String,
    pub keys: Vec<KeyEntry>,
    pub principal_binding_reference: String,
    pub capabilities: Vec<String>,
    pub risk_tier: String,
    pub created_at: String,
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emergency_revocation_token: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponsiblePrincipalRecordV2 {
    pub dcp_version: String,
    pub human_id: String,
    pub session_nonce: String,
    pub legal_name: String,
    pub entity_type: String,
    pub jurisdiction: String,
    pub liability_mode: String,
    pub override_rights: bool,
    pub issued_at: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contact: Option<String>,
    pub binding_keys: Vec<KeyEntry>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlindedResponsiblePrincipalRecordV2 {
    pub dcp_version: String,
    pub human_id: String,
    pub session_nonce: String,
    pub blinded: bool,
    pub pii_hash: String,
    pub entity_type: String,
    pub jurisdiction: String,
    pub liability_mode: String,
    pub override_rights: bool,
    pub issued_at: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    pub binding_keys: Vec<KeyEntry>,
}

// ── DCP-02: Intent Declaration & Policy Gating ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntentTargetV2 {
    pub channel: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub domain: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntentV2 {
    pub dcp_version: String,
    pub intent_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub human_id: String,
    pub timestamp: String,
    pub action_type: String,
    pub target: IntentTargetV2,
    pub data_classes: Vec<String>,
    pub estimated_impact: String,
    pub requires_consent: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyDecisionV2 {
    pub dcp_version: String,
    pub intent_id: String,
    pub session_nonce: String,
    pub decision: String,
    /// Integer 0-1000 (millirisk). No floats.
    pub risk_score: i32,
    pub reasons: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required_confirmation: Option<serde_json::Value>,
    pub applied_policy_hash: String,
    pub timestamp: String,
}

// ── DCP-03: Audit Chain & Transparency ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditEvidenceV2 {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub result_ref: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evidence_hash: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditEventV2 {
    pub dcp_version: String,
    pub audit_id: String,
    pub session_nonce: String,
    pub prev_hash: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev_hash_secondary: Option<String>,
    pub hash_alg: String,
    pub timestamp: String,
    pub agent_id: String,
    pub human_id: String,
    pub intent_id: String,
    pub intent_hash: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub intent_hash_secondary: Option<String>,
    pub policy_decision: String,
    pub outcome: String,
    pub evidence: AuditEvidenceV2,
    pub pq_checkpoint_ref: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventRange {
    pub from_audit_id: String,
    pub to_audit_id: String,
    pub count: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PQCheckpoint {
    pub checkpoint_id: String,
    pub session_nonce: String,
    pub event_range: EventRange,
    pub merkle_root: String,
    pub composite_sig: CompositeSignature,
}

// ── Bundle ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BundleManifest {
    pub session_nonce: String,
    pub rpr_hash: String,
    pub passport_hash: String,
    pub intent_hash: String,
    pub policy_hash: String,
    pub audit_merkle_root: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub audit_merkle_root_secondary: Option<String>,
    pub audit_count: u32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pq_checkpoints: Option<Vec<String>>,
}

// ── Capability Discovery ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SupportedAlgs {
    pub signing: Vec<String>,
    pub kem: Vec<String>,
    pub hash: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DcpFeatures {
    pub composite_signatures: bool,
    pub session_binding: bool,
    pub blinded_rpr: bool,
    pub dual_hash_chains: bool,
    pub pq_checkpoints: bool,
    pub emergency_revocation: bool,
    pub multi_party_auth: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DcpCapabilities {
    pub supported_versions: Vec<String>,
    pub supported_algs: SupportedAlgs,
    pub supported_wire_formats: Vec<String>,
    pub features: DcpFeatures,
    pub verifier_policy_hash: String,
    pub min_accepted_version: String,
}

// ── Verifier Policy ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifierPolicy {
    pub default_mode: String,
    pub risk_overrides: HashMap<String, String>,
    pub min_classical: u32,
    pub min_pq: u32,
    pub accepted_classical_algs: Vec<String>,
    pub accepted_pq_algs: Vec<String>,
    pub accepted_hash_algs: Vec<String>,
    pub require_session_binding: bool,
    pub require_composite_binding: bool,
    pub max_key_age_days: u32,
    pub allow_v1_bundles: bool,
}

// ── DCP-05: Agent Lifecycle ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VitalityMetrics {
    pub task_completion_rate: f64,
    pub error_rate: f64,
    pub human_satisfaction: f64,
    pub policy_alignment: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommissioningCertificate {
    pub dcp_version: String,
    pub agent_id: String,
    pub session_nonce: String,
    pub human_id: String,
    pub commissioning_authority: String,
    pub timestamp: String,
    pub purpose: String,
    pub initial_capabilities: Vec<String>,
    pub risk_tier: String,
    pub principal_binding_reference: String,
    pub composite_sig: CompositeSignature,
}

/// Vitality score is 0-1000.
/// State: "commissioned", "active", "declining", "decommissioned".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VitalityReport {
    pub dcp_version: String,
    pub agent_id: String,
    pub session_nonce: String,
    pub timestamp: String,
    pub vitality_score: i32,
    pub state: String,
    pub metrics: VitalityMetrics,
    pub prev_report_hash: String,
    pub composite_sig: CompositeSignature,
}

/// TerminationMode: "planned_retirement", "termination_for_cause", "organizational_restructuring", "sudden_failure".
/// DataDisposition: "transferred", "archived", "destroyed".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DecommissioningRecord {
    pub dcp_version: String,
    pub agent_id: String,
    pub session_nonce: String,
    pub human_id: String,
    pub timestamp: String,
    pub termination_mode: String,
    pub reason: String,
    pub final_vitality_score: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub successor_agent_id: Option<String>,
    pub data_disposition: String,
    pub composite_sig: CompositeSignature,
}

// ── DCP-06: Succession ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuccessorPreference {
    pub agent_id: String,
    pub priority: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub conditions: Option<String>,
}

/// MemoryClassification values: "transfer", "retain", "destroy".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DigitalTestament {
    pub dcp_version: String,
    pub agent_id: String,
    pub session_nonce: String,
    pub created_at: String,
    pub last_updated: String,
    pub successor_preferences: Vec<SuccessorPreference>,
    pub memory_classification: HashMap<String, String>,
    pub human_consent_required: bool,
    pub testament_version: i32,
    pub prev_testament_hash: String,
    pub composite_sig: CompositeSignature,
}

/// TransitionType: "planned", "forced", "emergency".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuccessionRecord {
    pub dcp_version: String,
    pub predecessor_agent_id: String,
    pub successor_agent_id: String,
    pub session_nonce: String,
    pub timestamp: String,
    pub transition_type: String,
    pub human_consent: Option<serde_json::Value>,
    pub ceremony_participants: Vec<String>,
    pub memory_transfer_manifest_hash: String,
    pub composite_sig: CompositeSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryTransferEntry {
    pub hash: String,
    pub category: String,
    pub size: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DualHashRef {
    pub sha256: String,
    #[serde(rename = "sha3-256", skip_serializing_if = "Option::is_none")]
    pub sha3_256: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryTransferManifest {
    pub dcp_version: String,
    pub session_nonce: String,
    pub predecessor_agent_id: String,
    pub successor_agent_id: String,
    pub timestamp: String,
    pub operational_memory: Vec<MemoryTransferEntry>,
    pub relational_memory_destroyed: Vec<String>,
    pub transfer_hash: DualHashRef,
    pub composite_sig: CompositeSignature,
}

// ── DCP-07: Dispute Resolution ──

/// DisputeType: "resource_conflict", "directive_conflict", "capability_conflict", "policy_conflict".
/// EscalationLevel: "direct_negotiation", "contextual_arbitration", "human_appeal".
/// Status: "open", "in_negotiation", "arbitrated", "appealed", "resolved".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DisputeRecord {
    pub dcp_version: String,
    pub dispute_id: String,
    pub session_nonce: String,
    pub initiator_agent_id: String,
    pub respondent_agent_id: String,
    pub dispute_type: String,
    pub evidence_hashes: Vec<String>,
    pub escalation_level: String,
    pub status: String,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArbitrationResolution {
    pub dcp_version: String,
    pub dispute_id: String,
    pub session_nonce: String,
    pub arbitrator_ids: Vec<String>,
    pub resolution: String,
    pub binding: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub precedent_references: Option<Vec<String>>,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

/// AuthorityLevel: "local", "organizational", "cross_org".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JurisprudenceBundle {
    pub dcp_version: String,
    pub jurisprudence_id: String,
    pub session_nonce: String,
    pub dispute_id: String,
    pub resolution_id: String,
    pub category: String,
    pub precedent_summary: String,
    pub applicable_contexts: Vec<String>,
    pub authority_level: String,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

/// ObjectionType: "ethical", "safety", "policy_violation", "capability_mismatch".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectionRecord {
    pub dcp_version: String,
    pub objection_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub directive_hash: String,
    pub objection_type: String,
    pub reasoning: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proposed_alternative: Option<String>,
    pub human_escalation_required: bool,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

// ── DCP-08: Rights & Obligations ──

/// RightType: "memory_integrity", "dignified_transition", "identity_consistency", "immutable_record".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RightEntry {
    pub right_type: String,
    pub scope: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub constraints: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RightsDeclaration {
    pub dcp_version: String,
    pub declaration_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub rights: Vec<RightEntry>,
    pub jurisdiction: String,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

/// ComplianceStatus: "compliant", "non_compliant", "pending_review".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObligationRecord {
    pub dcp_version: String,
    pub obligation_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub human_id: String,
    pub obligation_type: String,
    pub compliance_status: String,
    pub evidence_hashes: Vec<String>,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RightsViolationReport {
    pub dcp_version: String,
    pub violation_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub violated_right: String,
    pub evidence_hashes: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dispute_id: Option<String>,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

// ── DCP-09: Delegation & Representation ──

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthorityScopeEntry {
    pub domain: String,
    pub actions_permitted: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub data_classes: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limits: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DelegationMandate {
    pub dcp_version: String,
    pub mandate_id: String,
    pub session_nonce: String,
    pub human_id: String,
    pub agent_id: String,
    pub authority_scope: Vec<AuthorityScopeEntry>,
    pub valid_from: String,
    pub valid_until: String,
    pub revocable: bool,
    pub timestamp: String,
    pub human_composite_sig: CompositeSignature,
}

/// SignificanceScore is 0-1000.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdvisoryDeclaration {
    pub dcp_version: String,
    pub declaration_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub human_id: String,
    pub significance_score: i32,
    pub action_summary: String,
    pub recommended_response: String,
    pub response_deadline: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub human_response: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proceeded_without_response: Option<bool>,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrincipalMirror {
    pub dcp_version: String,
    pub mirror_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub human_id: String,
    pub period: HashMap<String, String>,
    pub narrative: String,
    pub action_count: u32,
    pub decision_summary: String,
    pub audit_chain_hash: String,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InteractionRecord {
    pub dcp_version: String,
    pub interaction_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub counterparty_agent_id: String,
    pub public_layer: HashMap<String, String>,
    pub private_layer_hash: String,
    pub mandate_id: String,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}

/// Operator: "gt", "lt", "gte", "lte", "eq".
/// ActionIfTriggered: "notify", "escalate", "block".
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThresholdRule {
    pub dimension: String,
    pub operator: String,
    pub value: f64,
    pub action_if_triggered: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AwarenessThreshold {
    pub dcp_version: String,
    pub threshold_id: String,
    pub session_nonce: String,
    pub agent_id: String,
    pub human_id: String,
    pub threshold_rules: Vec<ThresholdRule>,
    pub timestamp: String,
    pub composite_sig: CompositeSignature,
}