trql_client/lib.rs
1//! Transport-agnostic query client for the Affinidi Trust Registry.
2//!
3//! Queries are TRQP authorization/recognition checks carried as **Trust Task
4//! documents** (`registry/authorization/0.1`, `registry/recognition/0.1` from
5//! [`trust_tasks_rs::specs::registry`]) — the same contract the registry
6//! serves over every transport. The document is the protocol; a transport is
7//! only a pipe that moves one request document and returns the peer's reply
8//! document (see [`TrqlTransport`]).
9//!
10//! Three bindings are provided behind features:
11//!
12//! * `https` (default) — [`HttpsTransport`]: `POST <registry>/trust-tasks`,
13//! the `trust-tasks-https` wire contract.
14//! * `didcomm` — [`DidcommTransport`]: the `trust-tasks-didcomm` envelope over
15//! an ATM mediator websocket.
16//! * `tsp` — [`TspTransport`]: the `trust-tasks-tsp` envelope sealed in a TSP
17//! `Direct` message, multiplexed on the same mediator websocket.
18//!
19//! Every reply is correlated to its request (`threadId` == request `id`) and
20//! a reply that cannot be parsed is surfaced as a contract error, never as a
21//! transport failure. A registry rejection arrives as a typed
22//! [`TrqlError::Rejected`] carrying the machine-readable trust-task-error
23//! code.
24//!
25//! ```rust,ignore
26//! use std::sync::Arc;
27//! use trql_client::{HttpsTransport, HttpsTransportConfig, TrqlClient, TrqpQuery};
28//!
29//! let transport = HttpsTransport::new(HttpsTransportConfig::new("http://localhost:3232"))?;
30//! let client = TrqlClient::new(Arc::new(transport), "did:webvh:...registry");
31//!
32//! let response = client
33//! .authorization(TrqpQuery::new(
34//! "did:webvh:...signer", // entity
35//! "did:webvh:...authority", // authority
36//! "git.commit.sign", // action
37//! "openvtc", // resource
38//! ))
39//! .await?;
40//! if response.authorized { /* ... */ }
41//! ```
42
43mod client;
44mod discovery;
45mod error;
46mod transport;
47
48#[cfg(feature = "didcomm")]
49mod didcomm;
50#[cfg(feature = "https")]
51mod https;
52#[cfg(any(feature = "didcomm", feature = "tsp"))]
53mod pending;
54#[cfg(feature = "tsp")]
55mod tsp;
56
57pub use client::{TrqlClient, TrqpQuery};
58pub use discovery::{
59 DIDCOMM_SERVICE_TYPE, PREFERENCE_ORDER, REST_SERVICE_TYPE, REST_SERVICE_TYPES,
60 ServiceCapabilities, TSP_SERVICE_TYPE, TransportChoice, VTA_REST_SERVICE_TYPE,
61};
62pub use error::TrqlError;
63pub use transport::{TransportKind, TrqlTransport};
64
65#[cfg(feature = "didcomm")]
66pub use didcomm::{DidcommTransport, DidcommTransportConfig};
67#[cfg(feature = "https")]
68pub use https::{HttpsTransport, HttpsTransportConfig};
69#[cfg(feature = "tsp")]
70pub use tsp::{TspTransport, TspTransportConfig};
71
72/// The generated request/response payload types this client speaks, re-exported
73/// so consumers don't need a direct `trust-tasks-rs` dependency for the basics.
74pub mod payloads {
75 pub use trust_tasks_rs::specs::registry::authorization::v0_1::{
76 Payload as AuthorizationRequest, QueryContext as AuthorizationQueryContext,
77 Response as AuthorizationResponse,
78 };
79 pub use trust_tasks_rs::specs::registry::recognition::v0_1::{
80 Payload as RecognitionRequest, QueryContext as RecognitionQueryContext,
81 Response as RecognitionResponse,
82 };
83}