siera_agent/modules/
oob.rs

1use crate::error::Result;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Response from the cloudagent when an invitation is created
7#[derive(Debug, Default, Serialize, Deserialize)]
8pub struct OobConnectionCreateInvitationResponse {
9    /// the invitation message id generated by the cloudagent
10    /// this will be used for further functionality
11    #[serde(rename = "invi_msg_id")]
12    pub invitation_message_id: String,
13
14    /// Invitation object which contains some metadata about the invitation
15    pub invitation: Value,
16
17    /// The OOB id that can be used to identify the OOb connection/invite
18    pub oob_id: Option<String>,
19
20    /// URL that can be parsed by another agent to accept the invitation
21    pub invitation_url: String,
22
23    /// Optional alias if it was supplied when creating the invitation
24    pub alias: Option<String>,
25}
26
27/// A single connection structure
28#[derive(Debug, Serialize, Deserialize)]
29pub struct OobConnection {
30    /// Their role in the connection process
31    pub their_role: String,
32
33    /// When the connection is created
34    pub created_at: String,
35
36    /// Your did used in the connection process
37    pub my_did: Option<String>,
38
39    /// The connection id used for further functionality
40    pub connection_id: String,
41
42    /// Optional their did used in the connection proces
43    pub their_did: Option<String>,
44
45    /// The invitation key used
46    pub invitation_key: Option<String>,
47
48    /// The current connection state
49    pub state: String,
50
51    /// The routing state of the current connection
52    pub routing_state: String,
53
54    /// TODO
55    pub accept: String,
56
57    /// Their label as set when the connection is initialized
58    pub their_label: Option<String>,
59
60    /// What the mode of the invitation is
61    pub invitation_mode: String,
62
63    /// State of the connection according to rfc23
64    pub rfc23_state: String,
65
66    /// Last time that the connection was updated
67    pub updated_at: String,
68
69    /// Alias used when creating the invitation
70    pub alias: Option<String>,
71
72    /// Id of the request
73    pub request_id: Option<String>,
74
75    /// Id of the invitation message
76    pub invitation_msg_id: Option<String>,
77}
78
79/// Options supplied by the frontend for creating an invitation
80#[derive(Debug, Default)]
81pub struct OobConnectionCreateInvitationOptions {
82    /// Whether we want to auto accept the connection process
83    pub auto_accept: bool,
84
85    /// Whether a QR should be outputted to the user
86    pub qr: bool,
87
88    /// TODO: Protocol from enum
89    /// The handshake  protocol to use
90    pub handshake_protocol: String,
91
92    /// Whether the invitation is reuseable
93    pub multi_use: bool,
94
95    /// Optional custom alias for the connection
96    pub alias: Option<String>,
97}
98
99/// Skip validation and just pass the object - validation happens on aca-py
100/// We can possibly validate this here as well later.
101/// Generic OOB invitation to receive
102pub type OobConnectionReceiveInvitationOptions = Value;
103
104/// Generic cloudagent oob module
105#[async_trait]
106pub trait OobModule {
107    /// Create an oob invitation
108    async fn create_invitation(
109        &self,
110        options: OobConnectionCreateInvitationOptions,
111    ) -> Result<OobConnectionCreateInvitationResponse>;
112
113    /// Receive and accept an oob connection
114    async fn receive_invitation(
115        &self,
116        invitation: OobConnectionReceiveInvitationOptions,
117    ) -> Result<OobConnection>;
118}