vta_sdk/lib.rs
1//! # `vta-sdk` — SDK for Verifiable Trust Agents
2//!
3//! A Verifiable Trust Agent (VTA) holds a BIP-39 master seed, derives keys
4//! via BIP-32, and exposes a REST + DIDComm API to operators and integrations.
5//! This crate is the typed client that lets a Rust service:
6//!
7//! * authenticate against a VTA over REST or DIDComm,
8//! * call into every management surface (keys, contexts, ACL, DID templates,
9//! audit, backup, WebVH),
10//! * receive secret-bearing bundles via the `sealed_transfer` envelope
11//! (HPKE + ASCII armor + producer assertion),
12//! * provision integrations (mediators, WebVH hosts, app identities) end-to-end
13//! via VP-framed bootstrap requests + VC-issued admin authorization.
14//!
15//! ## Quick start
16//!
17//! Two-step pattern: import a credential, then call the typed client.
18//!
19//! ```rust,no_run,ignore
20//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
21//! use vta_sdk::client::VtaClient;
22//! use vta_sdk::credentials::CredentialBundle;
23//!
24//! // The credential is what the operator hands you (a base64 blob the VTA
25//! // setup wizard printed, or the result of `pnm bootstrap connect`).
26//! let credential = CredentialBundle::decode("<base64-credential>")?;
27//! let client = VtaClient::from_credential(&credential, None).await?;
28//!
29//! // Typed REST surface — `?` returns a `VtaError` with HTTP-aware variants
30//! // (Conflict, Gone, Forbidden, NotFound, …) so callers can surface targeted
31//! // operator errors instead of stringifying generic failures.
32//! let contexts = client.list_contexts().await?;
33//! for ctx in contexts {
34//! println!("{} — {}", ctx.id, ctx.label);
35//! }
36//! # Ok(()) }
37//! ```
38//!
39//! ## Sealed-transfer round-trip
40//!
41//! See [`sealed_transfer`] for the HPKE envelope used to move credentials,
42//! mediator secrets, and DID-secrets bundles between operator hosts:
43//!
44//! ```rust,ignore
45//! use vta_sdk::sealed_transfer::{seal_payload, open_bundle, generate_keypair, ...};
46//! ```
47//!
48//! ## Feature flags
49//!
50//! The crate is split into opt-in features so a thin types-only consumer
51//! doesn't pay the dependency cost of the full client. Pick the smallest
52//! set that compiles for your use case.
53//!
54//! | Feature | What it enables |
55//! |---|---|
56//! | `client` | Synchronous REST [`client::VtaClient`] (depends on reqwest, ed25519) |
57//! | `didcomm` | DIDComm transport types and message helpers |
58//! | `session` | Session storage + auth state machine. Needs a persistence backend (`keyring` or `config-session`). |
59//! | `keyring` | OS-native session storage via `keyring-core` (macOS Keychain / Windows Credential Manager / Linux Secret Service) |
60//! | `config-session` | Plaintext on-disk session storage (dev / non-sensitive contexts only) |
61//! | `azure-secrets` | Azure Key Vault session backend (requires `azure-secrets` env). Mutually exclusive with `keyring` at the SDK level. |
62//! | `sealed-transfer` | HPKE-sealed bundle envelope (seal, open, armor, producer assertions) |
63//! | `provision-integration` | VP-framed bootstrap requests + VC-issued admin authorization |
64//! | `provision-client` | Higher-level orchestration over `provision-integration` (TUI-agnostic) |
65//! | `attest-verify` | Full AWS Nitro attestation verification (cert chain to AWS root) |
66//! | `vp` | DCQL credential selection + holder-bound OID4VP `vp_token` assembly ([`vp`]) |
67//! | `integration` | Pull-bundle service-startup pattern (combines `client` + `session`) |
68//! | `test-support` | In-memory mocks (`SessionBackend`, fixtures) for downstream tests |
69//!
70//! ## Module map
71//!
72//! * [`client`] — synchronous REST client + typed request/response shapes
73//! * `agent_session` (feature `session`) — high-level personal-AI-agent runtime:
74//! enroll + heartbeat + inbound-wake loop on top of the DIDComm client
75//! * [`didcomm_session`] / [`didcomm_light`] — DIDComm transport
76//! * [`session`] — credential storage, login, refresh-token rotation
77//! * [`sealed_transfer`] — HPKE envelope (seal/open/armor/verify)
78//! * [`provision_integration`] — VP/VC bootstrap flow + typestate verifier
79//! * `integration` (feature-gated) — service-startup pull pattern with offline-cache resilience
80//! * [`did_templates`] — render-side helpers for the VTA's template registry
81//! * [`error`] — [`error::VtaError`] (typed, HTTP-aware, DIDComm-aware)
82
83pub mod error;
84pub mod hex;
85// Pure, dependency-light validators shared with clients so they apply the
86// VTA's canonical context-path / identifier rules without mirroring them.
87pub mod acl;
88pub mod context_path;
89pub mod identifier;
90// The declarative approvals model. Unconditional (no feature gate): the VTA,
91// the policy subsystem, and the CLI all derive the same Rego from it, and a
92// synthesizer that differed per feature set would break the byte-compare the
93// server relies on.
94pub mod approvals;
95
96#[cfg(feature = "acl-setup")]
97pub mod acl_setup;
98#[cfg(feature = "session")]
99pub mod agent_session;
100#[cfg(feature = "attest-verify")]
101pub mod attestation;
102#[cfg(feature = "client")]
103pub mod auth_di;
104#[cfg(feature = "client")]
105pub mod auth_light;
106#[cfg(feature = "client")]
107pub mod client;
108pub mod context_policy;
109pub mod context_provision;
110pub mod contexts;
111pub mod credentials;
112pub mod did_key;
113pub mod did_secrets;
114pub mod did_templates;
115// DID → human-readable display name. The single seam every operator-facing
116// surface (PNM/CNM CLIs, VTC operator CLI, VTC admin UI) renders DIDs
117// through. Core is dependency-light and always compiled; the one source that
118// needs the network (a verified agent name) is behind `agent-names`.
119#[cfg(feature = "client")]
120pub mod didcomm_light;
121#[cfg(feature = "session")]
122pub mod didcomm_session;
123pub mod display_name;
124// Pins rustls to the aws-lc-rs backend; every binary calls this at startup.
125#[cfg(feature = "crypto-provider")]
126pub mod crypto_init;
127#[cfg(feature = "client")]
128pub mod http;
129#[cfg(feature = "keyring")]
130pub mod keyring_init;
131pub mod keys;
132pub mod prelude;
133// `resolver` wraps `affinidi-did-resolver-cache-sdk`, which is only a
134// dependency under the `didcomm` feature.
135#[cfg(feature = "didcomm")]
136pub mod resolver;
137// `protocol` itself is always-on (its `services` submodule holds pure
138// wire types + the shared `validate_service_url` validator that
139// vta-service uses without ever talking to a `VtaClient`). The
140// `impl VtaClient` blocks inside are individually `cfg(feature = "client")`-
141// gated, so disabling the `client` feature still drops the network
142// machinery — but consumers no longer need to flip the feature on
143// just to import `protocol::services::validate_service_url`.
144pub mod protocol;
145pub mod protocols;
146#[cfg(feature = "provision-client")]
147pub mod provision_client;
148#[cfg(feature = "provision-integration")]
149pub mod provision_integration;
150#[cfg(feature = "sealed-transfer")]
151pub mod sealed_transfer;
152#[cfg(feature = "session")]
153pub mod session;
154// One TDK + one ATM per process, with a session per identity on it. Every
155// session type in this SDK runs on a hub; the legacy constructors just build a
156// private one (#830).
157#[cfg(feature = "session")]
158pub mod session_hub;
159/// Holder-signing for Trust Task documents — the shared `eddsa-jcs-2022`
160/// primitive both services' holder surfaces verify against.
161#[cfg(feature = "client")]
162pub mod trust_task_sign;
163/// Canonical Trust-Task URLs for VTA operations. Mirrors
164/// `did-hosting-common::did_hosting_tasks` for the webvh-service side.
165pub mod trust_tasks;
166// Reply correlation for TSP, shared by `TspSession` and the `DIDCommSession`
167// TSP leg. Internal: consumers see the sessions, not the bookkeeping.
168#[cfg(all(feature = "session", feature = "tsp"))]
169mod tsp_demux;
170// DCQL credential selection + holder-bound OID4VP `vp_token` assembly. The
171// client-side counterpart to the `join-requests` / `credential-exchange`
172// protocol types: turns a verifier's `presentation_definition` + held
173// credentials into a signed `vp_token` the VTC's join verifier accepts.
174#[cfg(feature = "vp")]
175pub mod vp;
176pub mod webvh;
177
178#[cfg(feature = "integration")]
179pub mod integration;