siera_agent/modules/
proof.rs1use crate::error::{Error, Result};
2use async_trait::async_trait;
3use serde::Deserialize;
4use serde::Serialize;
5use serde_json::Value;
6use std::str::FromStr;
7
8#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
10pub struct ProofRequestResponse {
11 pub state: String,
13
14 pub presentation_request: Value,
16
17 pub updated_at: String,
19
20 pub connection_id: String,
22
23 pub thread_id: String,
25
26 pub presentation_request_dict: Value,
28
29 pub role: String,
31
32 pub auto_present: bool,
34
35 pub presentation_exchange_id: String,
37
38 pub created_at: String,
40
41 pub initiator: String,
43}
44
45#[derive(Debug, Clone)]
50pub struct Predicate(pub String, pub String, pub String);
51
52impl FromStr for Predicate {
53 type Err = Error;
54 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
55 let mut res = s.split(',');
56 let name = res
57 .next()
58 .ok_or_else(|| Error::UnableToParseOutValue(s.to_owned()))?;
59 let operator = res
60 .next()
61 .ok_or_else(|| Error::UnableToParseOutValue(s.to_owned()))?;
62 let value = res
63 .next()
64 .ok_or_else(|| Error::UnableToParseOutValue(s.to_owned()))?;
65
66 validate_operator(operator).map_err(|_| Error::InvalidOperator(operator.to_owned()))?;
67 Ok(Self(name.to_owned(), operator.to_owned(), value.to_owned()))
68 }
69}
70
71fn validate_operator(op: &str) -> Result<()> {
73 if vec![">=", "<=", "=", ">", "<"]
74 .iter()
75 .map(|o| String::from(*o))
76 .any(|o| o == *op)
77 {
78 return Ok(());
79 };
80 Err(Error::InvalidOperator(op.to_owned()).into())
81}
82
83pub struct ProofRequestOptions {
85 pub connection_id: String,
87
88 pub name: String,
90
91 pub attributes: Vec<String>,
93
94 pub predicates: Vec<(String, String, i32)>,
96}
97
98#[async_trait]
100pub trait ProofModule {
101 async fn send_request(&self, options: ProofRequestOptions) -> Result<ProofRequestResponse>;
103}