siera-agent 0.2.0

Structures and traits related to an Aries agent.
Documentation
use crate::error::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Response from the cloudagent when an invitation is created
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct OobConnectionCreateInvitationResponse {
    /// the invitation message id generated by the cloudagent
    /// this will be used for further functionality
    #[serde(rename = "invi_msg_id")]
    pub invitation_message_id: String,

    /// Invitation object which contains some metadata about the invitation
    pub invitation: Value,

    /// The OOB id that can be used to identify the OOb connection/invite
    pub oob_id: Option<String>,

    /// URL that can be parsed by another agent to accept the invitation
    pub invitation_url: String,

    /// Optional alias if it was supplied when creating the invitation
    pub alias: Option<String>,
}

/// A single connection structure
#[derive(Debug, Serialize, Deserialize)]
pub struct OobConnection {
    /// Their role in the connection process
    pub their_role: String,

    /// When the connection is created
    pub created_at: String,

    /// Your did used in the connection process
    pub my_did: Option<String>,

    /// The connection id used for further functionality
    pub connection_id: String,

    /// Optional their did used in the connection proces
    pub their_did: Option<String>,

    /// The invitation key used
    pub invitation_key: Option<String>,

    /// The current connection state
    pub state: String,

    /// The routing state of the current connection
    pub routing_state: String,

    /// TODO
    pub accept: String,

    /// Their label as set when the connection is initialized
    pub their_label: Option<String>,

    /// What the mode of the invitation is
    pub invitation_mode: String,

    /// State of the connection according to rfc23
    pub rfc23_state: String,

    /// Last time that the connection was updated
    pub updated_at: String,

    /// Alias used when creating the invitation
    pub alias: Option<String>,

    /// Id of the request
    pub request_id: Option<String>,

    /// Id of the invitation message
    pub invitation_msg_id: Option<String>,
}

/// Options supplied by the frontend for creating an invitation
#[derive(Debug, Default)]
pub struct OobConnectionCreateInvitationOptions {
    /// Whether we want to auto accept the connection process
    pub auto_accept: bool,

    /// Whether a QR should be outputted to the user
    pub qr: bool,

    /// TODO: Protocol from enum
    /// The handshake  protocol to use
    pub handshake_protocol: String,

    /// Whether the invitation is reuseable
    pub multi_use: bool,

    /// Optional custom alias for the connection
    pub alias: Option<String>,
}

/// Skip validation and just pass the object - validation happens on aca-py
/// We can possibly validate this here as well later.
/// Generic OOB invitation to receive
pub type OobConnectionReceiveInvitationOptions = Value;

/// Generic cloudagent oob module
#[async_trait]
pub trait OobModule {
    /// Create an oob invitation
    async fn create_invitation(
        &self,
        options: OobConnectionCreateInvitationOptions,
    ) -> Result<OobConnectionCreateInvitationResponse>;

    /// Receive and accept an oob connection
    async fn receive_invitation(
        &self,
        invitation: OobConnectionReceiveInvitationOptions,
    ) -> Result<OobConnection>;
}