Skip to content

Commit

Permalink
feat(mediator): support for pickup protocol processing (#1029)
Browse files Browse the repository at this point in the history
feat(mediator): support for pickup protocol processing (#1029)

Signed-off-by: Naian <[email protected]>
  • Loading branch information
nain-F49FF806 authored Nov 2, 2023
1 parent 88f6e8e commit ad26ecf
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 213 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions agents/rust/mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ mediation = { path = "./mediation" }
test_utils = { path = "../../../tools/test_utils" }

[dev-dependencies]
base64-url = "2.0.0"
chrono = "0.4.31"
reqwest = { version = "0.11.20", features = ["blocking"] }
7 changes: 5 additions & 2 deletions agents/rust/mediator/mediation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mediation"
version = "0.2.3"
version = "0.2.4"
edition = "2021"

[lib]
Expand All @@ -10,23 +10,26 @@ path = "src/lib.rs"
[features]
default = ["mysql_db", "mediator_persistence_extras"]
# postgres_db=["sqlx/postgres"]
mysql_db=["sqlx/mysql"]
mysql_db = ["sqlx/mysql"]
# any_db=["sqlx/all-databases"]
mediator_persistence_extras = []

[dependencies]
async-trait = "0.1.72"
axum = "0.6.18"
base64-url = "2.0.0"
dotenvy = "0.15.7"
env_logger = "0.10.0"
futures = "0.3.28"
log = "0.4.19"
messages = { path = "../../../../messages" }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.104"
serde_with = { version = "3.1.0", features = ["base64"] }
sqlx = { version = "0.7", features = ["runtime-tokio"], optional = true }
# sqlx = { version = "0.5.8", git = "https://github.com/jovfer/sqlx", branch = "feature/json_no_preserve_order_v5", features = [ "sqlite", "mysql", "json_no_preserve_order", "runtime-tokio-rustls"], optional = true }
tokio = { version = "1.28.2", features = ["rt-multi-thread", "macros"] }
uuid = { version = "1.5.0", features = ["v4"] }

# Workaround required because of bug in sqlx pre v6 https://github.com/launchbadge/sqlx/issues/2418
# [build-dependencies]
Expand Down
49 changes: 3 additions & 46 deletions agents/rust/mediator/mediation/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,5 @@
> 🚧🚧**WIP**🚧🚧: Integration into aries-vcx in process. See main branch for the MVP http service.
# Aries mediator mediation

# Aries mediator service (http)
## Mediator service business logic

## History

This repo was intended to be a test project to try Rust and Axum features.

Over time it has turned into a ~fully functional aries mediator service supporting the following Aries concepts over ***http*** endpoints.

> **Caveat**: Authentication must be handled at another layer. Integration with [aries-vcx] is intended to enable this.
- [Mediator coordination protocol](https://github.com/hyperledger/aries-rfcs/blob/main/features/0211-route-coordination/README.md)
- [Core:Routing: Forward Message](https://github.com/hyperledger/aries-rfcs/blob/main/concepts/0094-cross-domain-messaging/README.md#corerouting10forward)
- [Pickup protocol 2.0](https://github.com/hyperledger/aries-rfcs/tree/main/features/0685-pickup-v2)

[aries-vcx]: https://github.com/hyperledger/aries-vcx

Original readme is available below.

> # axum-test-server
>
> A axum server app to test and learn Rust and Axum features.
>
> The commits are made in such a way as to demonstrate and try one feature or workflow (refactoring) at a time.
> So the git log could be educative.
>
> ## Some Interesting commits
>
> 1. [feat(main.rs): :thread: Demo server as in axum docs](https://github.com/nain-F49FF806/axum-test-server/commit/d7fceaf9b731251cdbe8642c716dfaa3a697349a)
>
> 2. [refactor: `use` too bring names into local namespace](https://github.com/nain-F49FF806/axum-test-server/commit/f3a58597fc05fe5353140e764d532446ff10000e)
>
> 3. [refactor: break off some code into module and load module in main](https://github.com/nain-F49FF806/axum-test-server/commit/253956dc30866f516f484c6ef549c55054cb9f3f)
>
> 4. [refactor: Use functions in sibling module by declaring their path from root crate](https://github.com/nain-F49FF806/axum-test-server/commit/f7a5020ba52876e463c86efb3390af527e09990c#r121244243)
>
> 5. [refactor: modules can have sub-modules, which can then be loaded by others using path from root crate (*if made public*)](https://github.com/nain-F49FF806/axum-test-server/commit/877cf3bac05d9cf786db3ae45202b2d4d9a98a5c)
>
> 6. [feat(json): serde macros help with serializing, deserializing from Rust structs to JSON wire format](https://github.com/nain-F49FF806/axum-test-server/commit/505ec1ec8fc6169620be235231643f678bab20ff)
>
>
> ## Notess
>
> You can also look at a blog post with some personal notes (mostly for the Rust side) here : [running-notes-on-rust-and-axum-framework]
>
> [running-notes-on-rust-and-axum-framework]: https://envs.net/~nain/aries-vcx-diaries/running-notes-on-rust-and-axum-framework-ft-tutorial-course-by-brooks-builds.html
>
## Mediator Persistence
90 changes: 0 additions & 90 deletions agents/rust/mediator/mediation/src/didcomm_types.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// Copyright 2023 Naian G.
// SPDX-License-Identifier: Apache-2.0

pub use pickup_delivery_message_structs::*;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

pub mod type_uri {
pub const FORWARD: &str = "https://didcomm.org/routing/1.0/forward";
pub const PICKUP_STATUS_REQ: &str = "https://didcomm.org/messagepickup/2.0/status-request";
pub const PICKUP_STATUS: &str = "https://didcomm.org/messagepickup/2.0/status";
pub const PICKUP_DELIVERY_REQ: &str = "https://didcomm.org/messagepickup/2.0/delivery-request";
pub const PICKUP_DELIVERY: &str = "https://didcomm.org/messagepickup/2.0/delivery";
pub const PICKUP_RECEIVED: &str = "https://didcomm.org/messagepickup/2.0/messages-received";
}

#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
Expand All @@ -34,86 +26,6 @@ impl ForwardMsg {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "@type")]
pub enum PickupMsgEnum {
#[serde(rename = "https://didcomm.org/messagepickup/2.0/status")]
PickupStatusMsg(PickupStatusMsg),
#[serde(rename = "https://didcomm.org/messagepickup/2.0/status-request")]
PickupStatusReqMsg(PickupStatusReqMsg),
#[serde(rename = "https://didcomm.org/messagepickup/2.0/delivery-request")]
PickupDeliveryReq(PickupDeliveryReqMsg),
#[serde(rename = "https://didcomm.org/messagepickup/2.0/delivery")]
PickupDelivery(PickupDeliveryMsg),
#[serde(rename = "https://didcomm.org/messagepickup/2.0/messages-received")]
MessageReceived(MessageReceivedMsg),
#[serde(rename = "https://didcomm.org/messagepickup/2.0/live-delivery-change")]
LiveDeliveryChange(LiveDeliveryChangeMsg),
#[serde(rename = "https://didcomm.org/notification/1.0/problem-report")]
ProblemReport(ProblemReportMsg),
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct PickupStatusMsg {
pub message_count: u32,
pub recipient_key: Option<String>,
}

impl PickupStatusMsg {
pub fn new(message_count: u32, recipient_key: Option<String>) -> PickupStatusMsg {
PickupStatusMsg {
message_count,
recipient_key,
}
}
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct PickupStatusReqMsg {
#[serde(default)]
pub auth_pubkey: String,
pub recipient_key: Option<String>,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct PickupDeliveryReqMsg {
#[serde(default)]
pub auth_pubkey: String,
pub limit: u32,
pub recipient_key: Option<String>,
}

pub mod pickup_delivery_message_structs {
use serde_with::{base64::Base64, serde_as};

use super::{skip_serializing_none, Deserialize, Serialize};

#[serde_as]
#[derive(Serialize, Deserialize, Debug)]
pub struct PickupDeliveryMsgAttachData {
#[serde_as(as = "Base64")]
pub base64: Vec<u8>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct PickupDeliveryMsgAttach {
pub id: String,
#[serde(rename = "data")]
pub data: PickupDeliveryMsgAttachData,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct PickupDeliveryMsg {
pub recipient_key: Option<String>,
#[serde(rename = "~attach")]
pub attach: Vec<PickupDeliveryMsgAttach>,
}
}

#[derive(Serialize, Deserialize, Debug)]
pub struct LiveDeliveryChangeMsg {
pub live_delivery: bool,
Expand All @@ -131,8 +43,6 @@ pub struct MessageReceivedMsg {

pub mod mediator_coord_structs {
use serde::{Deserialize, Serialize};
// use serde_with::skip_serializing_none;

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "@type")]
pub enum MediatorCoordMsgEnum {
Expand Down
7 changes: 2 additions & 5 deletions agents/rust/mediator/mediation/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use axum::{
};

use crate::{
routes::{
forward::handle_forward, hello_world, json, json::respond_message_json,
pickup::handle_pickup,
},
routes::{forward::handle_forward, hello_world, json, json::respond_message_json},
storage,
};

Expand All @@ -30,7 +27,7 @@ pub async fn create_router() -> Router {
get(json::echo_message_json).post(respond_message_json),
)
.route("/forward", post(handle_forward))
.route("/pickup", post(handle_pickup))
// .route("/pickup", post(handle_pickup))
// .route("/coord", post(handle_coord))
.with_state(Arc::new(storage))
}
Loading

0 comments on commit ad26ecf

Please sign in to comment.