Skip to content

Commit

Permalink
feat(messages): Add pickup protocol support
Browse files Browse the repository at this point in the history
Signed-off-by: Naian <[email protected]>
  • Loading branch information
nain-F49FF806 committed Oct 18, 2023
1 parent 0372994 commit 5924299
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 104 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions aries_vcx/src/handlers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use messages::{
discover_features::DiscoverFeatures,
notification::Notification,
out_of_band::{invitation::Invitation as OobInvitation, OutOfBand},
pickup::Pickup,
present_proof::{
propose::{Predicate, PresentationAttr},
PresentProof,
Expand Down Expand Up @@ -180,6 +181,19 @@ pub fn verify_thread_id(thread_id: &str, message: &AriesMessage) -> VcxResult<()
AriesMessage::Routing(msg) => msg.id == thread_id,
AriesMessage::TrustPing(TrustPing::Ping(msg)) => matches_opt_thread_id!(msg, thread_id),
AriesMessage::TrustPing(TrustPing::PingResponse(msg)) => matches_thread_id!(msg, thread_id),
AriesMessage::Pickup(Pickup::Status(msg)) => matches_opt_thread_id!(msg, thread_id),
AriesMessage::Pickup(Pickup::StatusRequest(msg)) => matches_opt_thread_id!(msg, thread_id),
AriesMessage::Pickup(Pickup::Delivery(msg)) => matches_opt_thread_id!(msg, thread_id),
AriesMessage::Pickup(Pickup::DeliveryRequest(msg)) => {
matches_opt_thread_id!(msg, thread_id)
}

AriesMessage::Pickup(Pickup::MessagesReceived(msg)) => {
matches_opt_thread_id!(msg, thread_id)
}
AriesMessage::Pickup(Pickup::LiveDeliveryChange(msg)) => {
matches_opt_thread_id!(msg, thread_id)
}
};

if !is_match {
Expand Down
1 change: 1 addition & 0 deletions messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ messages_macros = { path = "../messages_macros" }
diddoc_legacy = { path = "../diddoc_legacy" }
shared_vcx = { path = "../shared_vcx" }
did_parser = { path = "../did_parser" }
serde_with = { version = "3.4.0", features = ["base64"] }
32 changes: 32 additions & 0 deletions messages/src/msg_fields/protocols/pickup/decorators.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use crate::decorators::thread::Thread;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct PickupDecoratorsCommon {
#[builder(default, setter(strip_option))]
#[serde(rename = "~thread")]
#[serde(skip_serializing_if = "Option::is_none")]
pub thread: Option<Thread>,
#[builder(default, setter(strip_option))]
#[serde(rename = "~transport")]
#[serde(skip_serializing_if = "Option::is_none")]
pub transport: Option<Transport>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct Transport {
pub return_route: ReturnRoute,
#[builder(default, setter(strip_option))]
#[serde(skip_serializing_if = "Option::is_none")]
pub return_route_thread: Option<Thread>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq)]
pub enum ReturnRoute {
#[default]
None,
All,
Thread,
}
30 changes: 30 additions & 0 deletions messages/src/msg_fields/protocols/pickup/delivery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type Delivery = MsgParts<DeliveryContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct DeliveryContent {
#[builder(default, setter(strip_option))]
#[serde(skip_serializing_if = "Option::is_none")]
pub recipient_key: Option<String>,
#[serde(rename = "~attach")]
pub attach: Vec<DeliveryAttach>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct DeliveryAttach {
pub id: String,
pub data: DeliveryAttachData,
}

#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct DeliveryAttachData {
#[serde_as(as = "Base64")]
pub base64: Vec<u8>,
}
15 changes: 15 additions & 0 deletions messages/src/msg_fields/protocols/pickup/delivery_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type DeliveryRequest = MsgParts<DeliveryRequestContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct DeliveryRequestContent {
pub limit: u32,
#[builder(default, setter(strip_option))]
#[serde(skip_serializing_if = "Option::is_none")]
pub recipient_key: Option<String>,
}
12 changes: 12 additions & 0 deletions messages/src/msg_fields/protocols/pickup/live_delivery_change.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type LiveDeliveryChange = MsgParts<LiveDeliveryChangeContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct LiveDeliveryChangeContent {
pub live_delivery: bool,
}
12 changes: 12 additions & 0 deletions messages/src/msg_fields/protocols/pickup/messages_received.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type MessagesReceived = MsgParts<MessagesReceivedContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct MessagesReceivedContent {
pub message_id_list: Vec<String>,
}
39 changes: 36 additions & 3 deletions messages/src/msg_fields/protocols/pickup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
mod decorators;
mod delivery;
mod delivery_request;
mod live_delivery_change;
mod messages_received;
mod status;
mod status_request;
use derive_more::From;
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use status::Status;

use self::status::StatusContent;
use self::{
decorators::PickupDecoratorsCommon,
delivery::{Delivery, DeliveryContent},
delivery_request::{DeliveryRequest, DeliveryRequestContent},
live_delivery_change::{LiveDeliveryChange, LiveDeliveryChangeContent},
messages_received::{MessagesReceived, MessagesReceivedContent},
status::{Status, StatusContent},
status_request::{StatusRequest, StatusRequestContent},
};
use crate::{
misc::utils::{into_msg_with_type, transit_to_aries_msg},
msg_fields::traits::DelayedSerde,
Expand All @@ -16,6 +29,11 @@ use crate::{
#[derive(Clone, Debug, From, PartialEq)]
pub enum Pickup {
Status(Status),
StatusRequest(StatusRequest),
DeliveryRequest(DeliveryRequest),
Delivery(Delivery),
MessagesReceived(MessagesReceived),
LiveDeliveryChange(LiveDeliveryChange),
}

impl DelayedSerde for Pickup {
Expand Down Expand Up @@ -46,10 +64,25 @@ impl DelayedSerde for Pickup {
{
match self {
Self::Status(v) => MsgWithType::from(v).serialize(serializer),
Self::StatusRequest(v) => MsgWithType::from(v).serialize(serializer),
Self::Delivery(v) => MsgWithType::from(v).serialize(serializer),
Self::DeliveryRequest(v) => MsgWithType::from(v).serialize(serializer),
Self::MessagesReceived(v) => MsgWithType::from(v).serialize(serializer),
Self::LiveDeliveryChange(v) => MsgWithType::from(v).serialize(serializer),
}
}
}

transit_to_aries_msg!(StatusContent, Pickup);
transit_to_aries_msg!(StatusContent: PickupDecoratorsCommon, Pickup);
transit_to_aries_msg!(StatusRequestContent: PickupDecoratorsCommon, Pickup);
transit_to_aries_msg!(DeliveryContent: PickupDecoratorsCommon, Pickup);
transit_to_aries_msg!(DeliveryRequestContent: PickupDecoratorsCommon, Pickup);
transit_to_aries_msg!(MessagesReceivedContent: PickupDecoratorsCommon, Pickup);
transit_to_aries_msg!(LiveDeliveryChangeContent: PickupDecoratorsCommon, Pickup);

into_msg_with_type!(Status, PickupTypeV2_0, Status);
into_msg_with_type!(StatusRequest, PickupTypeV2_0, StatusRequest);
into_msg_with_type!(Delivery, PickupTypeV2_0, Delivery);
into_msg_with_type!(DeliveryRequest, PickupTypeV2_0, DeliveryRequest);
into_msg_with_type!(MessagesReceived, PickupTypeV2_0, MessagesReceived);
into_msg_with_type!(LiveDeliveryChange, PickupTypeV2_0, LiveDeliveryChange);
11 changes: 0 additions & 11 deletions messages/src/msg_fields/protocols/pickup/status-request.rs

This file was deleted.

3 changes: 2 additions & 1 deletion messages/src/msg_fields/protocols/pickup/status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type Status = MsgParts<StatusContent>;
pub type Status = MsgParts<StatusContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct StatusContent {
Expand Down
14 changes: 14 additions & 0 deletions messages/src/msg_fields/protocols/pickup/status_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::decorators::PickupDecoratorsCommon;
use crate::msg_parts::MsgParts;

pub type StatusRequest = MsgParts<StatusRequestContent, PickupDecoratorsCommon>;

#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)]
pub struct StatusRequestContent {
#[builder(default, setter(strip_option))]
#[serde(skip_serializing_if = "Option::is_none")]
pub recipient_key: Option<String>,
}
88 changes: 0 additions & 88 deletions messages/src/msg_fields/protocols/pickup/structs.rs

This file was deleted.

2 changes: 1 addition & 1 deletion messages/src/msg_types/protocols/pickup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ pub enum PickupTypeV2_0 {
StatusRequest,
DeliveryRequest,
Delivery,
MessageReceived,
MessagesReceived,
LiveDeliveryChange,
}

0 comments on commit 5924299

Please sign in to comment.