dcp-ai — Rust SDK
Official Rust SDK for the Digital Citizenship Protocol (DCP). Serde-based types, Ed25519 via ed25519-dalek, and optional WebAssembly support.
Installation
Add to Cargo.toml:
[]
= "1.0"
For WebAssembly support:
[]
= { = "1.0", = ["wasm"] }
Quickstart
use ;
use json;
Verify a Signed Bundle
use verify_signed_bundle;
use serde_json;
use fs;
API Reference
Crypto (dcp_ai::crypto)
| Function | Signature | Description |
|---|---|---|
generate_keypair() |
() -> (String, String) |
Returns (public_key_b64, secret_key_b64) |
sign_object(obj, secret_key_b64) |
(&Value, &str) -> Result<String, String> |
Signs, returns base64 |
verify_object(obj, sig_b64, pub_b64) |
(&Value, &str, &str) -> Result<bool, String> |
Verifies signature |
canonicalize(obj) |
(&Value) -> String |
Deterministic JSON |
hash_object(obj) |
(&Value) -> String |
SHA-256 hex |
merkle_root_from_hex_leaves(leaves) |
(&[String]) -> Option<String> |
Merkle root |
Verification (dcp_ai::verify)
Verifies: Ed25519 signature, bundle_hash, merkle_root, intent_hash chain, prev_hash chain.
Types (dcp_ai::types)
All structs implement Serialize + Deserialize (serde).
V2 Types (dcp_ai::v2::types)
V2 includes Serde-derived structs for all DCP-05 through DCP-09 artifacts:
| Spec | Types |
|---|---|
| DCP-05 | LifecycleState, CommissioningCertificate, VitalityReport, VitalityMetrics, DecommissioningRecord, TerminationMode, DataDisposition |
| DCP-06 | DigitalTestament, SuccessionRecord, MemoryTransferManifest, MemoryTransferEntry, SuccessorPreference, MemoryClassification, TransitionType, MemoryDisposition |
| DCP-07 | DisputeRecord, ArbitrationResolution, JurisprudenceBundle, ObjectionRecord, DisputeType, EscalationLevel, DisputeStatus, ObjectionType, AuthorityLevel |
| DCP-08 | RightsDeclaration, RightEntry, ObligationRecord, RightsViolationReport, RightType, ComplianceStatus |
| DCP-09 | DelegationMandate, AdvisoryDeclaration, PrincipalMirror, InteractionRecord, AwarenessThreshold, ThresholdRule, AuthorityScopeEntry |
Domain separation constants: CTX_LIFECYCLE, CTX_SUCCESSION, CTX_DISPUTE, CTX_RIGHTS, CTX_DELEGATION, CTX_AWARENESS
All structs derive Debug, Clone, Serialize, Deserialize. Enums use #[serde(rename_all = "snake_case")]. Optional fields use Option<T> with #[serde(skip_serializing_if = "Option::is_none")].
Feature wasm
When the wasm feature is enabled, the crate exposes WebAssembly bindings:
// Available via wasm-bindgen
;
;
;
Compile for WASM:
Development
# Build
# Tests
# Build with WASM
# Build for WASM target
Dependencies
serde+serde_json— Serializationsha2— SHA-256ed25519-dalek— Ed25519 cryptographyrand— Random number generationbase64— Base64 encodinghex— Hex encodingwasm-bindgen(optional) — WASM bindings
License
Apache-2.0