Skip to main content

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, TRUST_REGISTRY_SERVICE_TYPE, TSP_SERVICE_TYPE, TransportChoice,
61    VTA_REST_SERVICE_TYPE, registry_referral,
62};
63pub use error::TrqlError;
64pub use transport::{TransportKind, TrqlTransport};
65
66#[cfg(feature = "didcomm")]
67pub use didcomm::{DidcommTransport, DidcommTransportConfig};
68#[cfg(feature = "https")]
69pub use https::{HttpsTransport, HttpsTransportConfig};
70#[cfg(feature = "tsp")]
71pub use tsp::{TspTransport, TspTransportConfig};
72
73/// The generated request/response payload types this client speaks, re-exported
74/// so consumers don't need a direct `trust-tasks-rs` dependency for the basics.
75pub mod payloads {
76    pub use trust_tasks_rs::specs::registry::authorization::v0_1::{
77        Payload as AuthorizationRequest, QueryContext as AuthorizationQueryContext,
78        Response as AuthorizationResponse,
79    };
80    pub use trust_tasks_rs::specs::registry::recognition::v0_1::{
81        Payload as RecognitionRequest, QueryContext as RecognitionQueryContext,
82        Response as RecognitionResponse,
83    };
84}