Skip to main content

agent_cid/
types.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Signature {
10    pub signer_did: String,
11    pub alg: String,
12    pub sig: String,
13}
14
15#[derive(Debug, Clone, Default, Serialize, Deserialize)]
16pub struct Retention {
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub stale_after: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub expires_at: Option<String>,
21}
22
23/// Manifest kept as a generic JSON value so canonicalization round-trips
24/// byte-for-byte with the TypeScript reference.
25pub type Manifest = Value;
26
27pub type SignFn = Arc<
28    dyn Fn(Vec<u8>) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, crate::Error>> + Send>>
29        + Send
30        + Sync,
31>;
32
33#[derive(Clone)]
34pub struct SignerInput {
35    pub did: String,
36    pub sign_fn: SignFn,
37}
38
39#[derive(Clone)]
40pub struct BuildOpts {
41    pub producer_did: String,
42    pub schema_uri: String,
43    pub media_type: String,
44    pub signers: Vec<SignerInput>,
45    pub parent_cid: Option<String>,
46    pub retention: Option<Retention>,
47    pub created_at: Option<String>,
48}
49
50pub type DidResolver = Arc<
51    dyn Fn(String) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, crate::Error>> + Send>>
52        + Send
53        + Sync,
54>;
55
56pub struct VerifyOptions {
57    pub resolver: Option<DidResolver>,
58    pub resolver_cache: bool,
59    pub resolver_timeout_ms: u64,
60    pub ignore_expiry: bool,
61    pub now_ms: Option<i64>,
62}
63
64impl Default for VerifyOptions {
65    fn default() -> Self {
66        Self {
67            resolver: None,
68            resolver_cache: true,
69            resolver_timeout_ms: 5000,
70            ignore_expiry: false,
71            now_ms: None,
72        }
73    }
74}
75
76#[derive(Debug, Default)]
77pub struct VerifyResult {
78    pub ok: bool,
79    pub errors: Vec<String>,
80    pub warnings: Vec<String>,
81}