diff --git a/aries/agents/rust/mediator/mediation/src/didcomm_types.rs b/aries/agents/rust/mediator/mediation/src/didcomm_types.rs deleted file mode 100644 index 627bfb38d9..0000000000 --- a/aries/agents/rust/mediator/mediation/src/didcomm_types.rs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2023 Naian G. -// SPDX-License-Identifier: Apache-2.0 - -use serde::{Deserialize, Serialize}; -pub mod type_uri { - pub const FORWARD: &str = "https://didcomm.org/routing/1.0/forward"; -} - -#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)] -pub struct ForwardMsg { - #[serde(rename = "@type")] - _type: String, - #[serde(rename = "to")] - pub recipient_key: String, - #[serde(rename = "msg")] - pub message_data: String, -} - -impl ForwardMsg { - pub fn new(recipient_key: &str, message: &str) -> ForwardMsg { - ForwardMsg { - _type: type_uri::FORWARD.to_string(), - recipient_key: recipient_key.to_string(), - message_data: message.to_string(), - } - } -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct LiveDeliveryChangeMsg { - pub live_delivery: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ProblemReportMsg { - pub description: String, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct MessageReceivedMsg { - pub message_id_list: Vec, -} - -pub mod mediator_coord_structs { - use serde::{Deserialize, Serialize}; - #[derive(Serialize, Deserialize, Debug)] - #[serde(tag = "@type")] - pub enum MediatorCoordMsgEnum { - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/mediate-request")] - MediateRequest, - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/mediate-deny")] - MediateDeny(MediateDenyData), - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/mediate-grant")] - MediateGrant(MediateGrantData), - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/keylist-update")] - KeylistUpdateRequest(KeylistUpdateRequestData), - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/keylist-update-response")] - KeylistUpdateResponse(KeylistUpdateResponseData), - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/keylist-query")] - KeylistQuery(KeylistQueryData), - #[serde(rename = "https://didcomm.org/coordinate-mediation/1.0/keylist")] - Keylist(KeylistData), - XumErrorMsg { - error: String, - }, - } - - #[derive(Serialize, Deserialize, Debug)] - pub struct MediateDenyData { - pub reason: String, - } - - #[derive(Serialize, Deserialize, Debug)] - pub struct MediateGrantData { - pub endpoint: String, - pub routing_keys: Vec, - } - - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistUpdateRequestData { - pub updates: Vec, - } - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistUpdateResponseData { - pub updated: Vec, - } - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistUpdateItem { - pub recipient_key: String, - pub action: KeylistUpdateItemAction, - pub result: Option, - } - #[derive(Serialize, Deserialize, Debug)] - pub enum KeylistUpdateItemAction { - #[serde(rename = "add")] - Add, - #[serde(rename = "remove")] - Remove, - } - #[derive(Serialize, Deserialize, Debug)] - pub enum KeylistUpdateItemResult { - ClientError, - ServerError, - NoChange, - Success, - } - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistQueryData {} - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistData { - pub keys: Vec, - } - #[derive(Serialize, Deserialize, Debug)] - pub struct KeylistItem { - pub recipient_key: String, - } -} diff --git a/aries/agents/rust/mediator/tests/common/agent_and_transport_utils.rs b/aries/agents/rust/mediator/tests/common/agent_and_transport_utils.rs index affdae211a..db163117de 100644 --- a/aries/agents/rust/mediator/tests/common/agent_and_transport_utils.rs +++ b/aries/agents/rust/mediator/tests/common/agent_and_transport_utils.rs @@ -6,18 +6,26 @@ use aries_vcx::{ }; use aries_vcx_core::wallet::base_wallet::BaseWallet; use diddoc_legacy::aries::diddoc::AriesDidDoc; -use mediation::{ - didcomm_types::mediator_coord_structs::{MediateGrantData, MediatorCoordMsgEnum}, - storage::MediatorPersistence, -}; +use mediation::storage::MediatorPersistence; use mediator::{ aries_agent::{ client::transports::{AriesReqwest, AriesTransport}, + utils::oob2did, Agent, }, utils::{structs::VerKey, GenericStringError}, }; -use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation; +use messages::{ + msg_fields::protocols::{ + coordinate_mediation::{ + keylist_update::{KeylistUpdateItem, KeylistUpdateItemAction}, + CoordinateMediation, KeylistUpdate, KeylistUpdateContent, MediateGrantContent, + MediateRequest, MediateRequestContent, + }, + out_of_band::invitation::Invitation as OOBInvitation, + }, + AriesMessage, +}; use reqwest::header::ACCEPT; use super::prelude::*; @@ -91,15 +99,62 @@ pub async fn send_message_and_pop_response_message( .unwrap(); Ok(unpacked_response.message) } +/// Register recipient keys with mediator +pub async fn gen_and_register_recipient_key( + agent: &mut Agent, + agent_aries_transport: &mut impl AriesTransport, + agent_verkey: &VerKey, + mediator_diddoc: &AriesDidDoc, +) -> Result<(VerKey, AriesDidDoc)> { + let agent_invite: OOBInvitation = agent + .get_oob_invite() + .map_err(|e| GenericStringError { msg: e.to_string() })?; + let agent_diddoc = oob2did(agent_invite); + let agent_recipient_key = agent_diddoc + .recipient_keys() + .unwrap() + .first() + .unwrap() + .clone(); + // register recipient key with mediator + let key_update = KeylistUpdate::builder() + .content( + KeylistUpdateContent::builder() + .updates(vec![KeylistUpdateItem { + recipient_key: agent_recipient_key.clone(), + action: KeylistUpdateItemAction::Add, + }]) + .build(), + ) + .id("register-key-with-mediator".to_owned()) + .build(); + let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate(key_update)); + info!("Sending {:?}", serde_json::to_string(&message).unwrap()); + let message_bytes = serde_json::to_vec(&message)?; + let _response_message = send_message_and_pop_response_message( + &message_bytes, + agent, + agent_aries_transport, + agent_verkey, + mediator_diddoc, + ) + .await?; + Ok((agent_recipient_key, agent_diddoc)) +} pub async fn get_mediator_grant_data( agent: &Agent, agent_aries_transport: &mut impl AriesTransport, agent_verkey: &VerKey, mediator_diddoc: &AriesDidDoc, -) -> MediateGrantData { +) -> MediateGrantContent { // prepare request message - let message = MediatorCoordMsgEnum::MediateRequest; + let message = AriesMessage::CoordinateMediation(CoordinateMediation::MediateRequest( + MediateRequest::builder() + .content(MediateRequestContent::default()) + .id("mediate-requets".to_owned()) + .build(), + )); let message_bytes = serde_json::to_vec(&message).unwrap(); // send message and get response let response_message = send_message_and_pop_response_message( @@ -112,11 +167,11 @@ pub async fn get_mediator_grant_data( .await .unwrap(); // extract routing parameters - if let MediatorCoordMsgEnum::MediateGrant(grant_data) = + if let AriesMessage::CoordinateMediation(CoordinateMediation::MediateGrant(grant_data)) = serde_json::from_str(&response_message).unwrap() { info!("Grant Data {:?}", grant_data); - grant_data + grant_data.content } else { panic!( "Should get response that is of type Mediator Grant. Found {:?}", diff --git a/aries/agents/rust/mediator/tests/mediator-coord-protocol.rs b/aries/agents/rust/mediator/tests/mediator-coord-protocol.rs index 868aad9941..062b36df37 100644 --- a/aries/agents/rust/mediator/tests/mediator-coord-protocol.rs +++ b/aries/agents/rust/mediator/tests/mediator-coord-protocol.rs @@ -1,9 +1,13 @@ mod common; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use mediation::didcomm_types::mediator_coord_structs::{ - KeylistData, KeylistQueryData, KeylistUpdateItem, KeylistUpdateItemAction, - KeylistUpdateRequestData, MediatorCoordMsgEnum, +use messages::{ + msg_fields::protocols::coordinate_mediation::{ + keylist_update::{KeylistUpdateItem, KeylistUpdateItemAction}, + CoordinateMediation, KeylistQuery, KeylistQueryContent, KeylistUpdate, + KeylistUpdateContent, MediateRequest, MediateRequestContent, + }, + AriesMessage, }; use crate::common::{ @@ -23,8 +27,13 @@ async fn test_mediate_grant() -> Result<()> { let (agent, mut aries_transport, our_verkey, their_diddoc) = gen_mediator_connected_agent().await?; // prepare request message - let message = MediatorCoordMsgEnum::MediateRequest; - let message_bytes = serde_json::to_vec(&message)?; + let mediate_request = CoordinateMediation::MediateRequest( + MediateRequest::builder() + .content(MediateRequestContent::default()) + .id("mediate-request-test".to_owned()) + .build(), + ); + let message_bytes = serde_json::to_vec(&AriesMessage::CoordinateMediation(mediate_request))?; // send message and get response let response_message = send_message_and_pop_response_message( &message_bytes, @@ -35,11 +44,11 @@ async fn test_mediate_grant() -> Result<()> { ) .await?; // verify response - if let MediatorCoordMsgEnum::MediateGrant(grant_data) = + if let AriesMessage::CoordinateMediation(CoordinateMediation::MediateGrant(grant_data)) = serde_json::from_str(&response_message).unwrap() { info!("Grant Data {:?}", grant_data); - } else if let MediatorCoordMsgEnum::MediateDeny(deny_data) = + } else if let AriesMessage::CoordinateMediation(CoordinateMediation::MediateDeny(deny_data)) = serde_json::from_str(&response_message).unwrap() { info!("Deny Data {:?}", deny_data); @@ -64,13 +73,19 @@ async fn test_mediate_keylist_update_add() -> Result<()> { .get_wallet_ref() .create_and_store_my_did(None, None) .await?; - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: new_vk, - action: KeylistUpdateItemAction::Add, - result: None, - }], - }); + let keylist_update_request = KeylistUpdate::builder() + .content(KeylistUpdateContent { + updates: vec![KeylistUpdateItem { + recipient_key: new_vk, + action: KeylistUpdateItemAction::Add, + }], + }) + .id("key-add".to_owned()) + .build(); + + let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate( + keylist_update_request, + )); info!("Sending {:?}", serde_json::to_string(&message).unwrap()); let message_bytes = serde_json::to_vec(&message)?; // send message and get response @@ -83,8 +98,9 @@ async fn test_mediate_keylist_update_add() -> Result<()> { ) .await?; // verify response - if let MediatorCoordMsgEnum::KeylistUpdateResponse(update_response_data) = - serde_json::from_str(&response_message)? + if let AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdateResponse( + update_response_data, + )) = serde_json::from_str(&response_message)? { info!("Received update response {:?}", update_response_data); } else { @@ -108,13 +124,19 @@ async fn test_mediate_keylist_query() -> Result<()> { .get_wallet_ref() .create_and_store_my_did(None, None) .await?; - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: new_vk, - action: KeylistUpdateItemAction::Add, - result: None, - }], - }); + let keylist_update_request = KeylistUpdate::builder() + .content(KeylistUpdateContent { + updates: vec![KeylistUpdateItem { + recipient_key: new_vk, + action: KeylistUpdateItemAction::Add, + }], + }) + .id("key-add".to_owned()) + .build(); + + let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate( + keylist_update_request, + )); let message_bytes = serde_json::to_vec(&message)?; // send message and get response let _ = send_message_and_pop_response_message( @@ -127,7 +149,12 @@ async fn test_mediate_keylist_query() -> Result<()> { .await?; info!("Proceeding to keylist query"); //prepare request message: list keys - let message = MediatorCoordMsgEnum::KeylistQuery(KeylistQueryData {}); + let keylist_query = KeylistQuery::builder() + .content(KeylistQueryContent::default()) + .id("keylist-query".to_owned()) + .build(); + let message = + AriesMessage::CoordinateMediation(CoordinateMediation::KeylistQuery(keylist_query)); info!("Sending {:?}", serde_json::to_string(&message).unwrap()); let message_bytes = serde_json::to_vec(&message)?; // send message and get response @@ -140,10 +167,10 @@ async fn test_mediate_keylist_query() -> Result<()> { ) .await?; // verify - if let MediatorCoordMsgEnum::Keylist(KeylistData { keys }) = + if let AriesMessage::CoordinateMediation(CoordinateMediation::Keylist(keylist)) = serde_json::from_str(&response_message)? { - info!("Keylist mediator sent {:?}", keys) + info!("Keylist mediator sent {:?}", keylist.content) } else { panic!( "Expected message of type Keylist. Found {:?}", @@ -165,13 +192,19 @@ async fn test_mediate_keylist_update_remove() -> Result<()> { .get_wallet_ref() .create_and_store_my_did(None, None) .await?; - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: new_vk.clone(), - action: KeylistUpdateItemAction::Add, - result: None, - }], - }); + let keylist_update_request = KeylistUpdate::builder() + .content(KeylistUpdateContent { + updates: vec![KeylistUpdateItem { + recipient_key: new_vk.clone(), + action: KeylistUpdateItemAction::Add, + }], + }) + .id("key-add".to_owned()) + .build(); + + let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate( + keylist_update_request, + )); let message_bytes = serde_json::to_vec(&message)?; // send message and get response let _ = send_message_and_pop_response_message( @@ -184,13 +217,19 @@ async fn test_mediate_keylist_update_remove() -> Result<()> { .await?; info!("Proceeding to delete"); // prepare request message: delete key - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: new_vk, - action: KeylistUpdateItemAction::Remove, - result: None, - }], - }); + let keylist_update_request = KeylistUpdate::builder() + .content(KeylistUpdateContent { + updates: vec![KeylistUpdateItem { + recipient_key: new_vk, + action: KeylistUpdateItemAction::Remove, + }], + }) + .id("key-remove".to_owned()) + .build(); + + let message = AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdate( + keylist_update_request, + )); info!("Sending {:?}", serde_json::to_string(&message).unwrap()); let message_bytes = serde_json::to_vec(&message)?; // send message and get response @@ -202,8 +241,9 @@ async fn test_mediate_keylist_update_remove() -> Result<()> { &their_diddoc, ) .await?; - if let MediatorCoordMsgEnum::KeylistUpdateResponse(update_response_data) = - serde_json::from_str(&response_message)? + if let AriesMessage::CoordinateMediation(CoordinateMediation::KeylistUpdateResponse( + update_response_data, + )) = serde_json::from_str(&response_message)? { info!("Received update response {:?}", update_response_data); } else { diff --git a/aries/agents/rust/mediator/tests/mediator-protocol-pickup.rs b/aries/agents/rust/mediator/tests/mediator-protocol-pickup.rs index 13aaa176bf..2e44127a36 100644 --- a/aries/agents/rust/mediator/tests/mediator-protocol-pickup.rs +++ b/aries/agents/rust/mediator/tests/mediator-protocol-pickup.rs @@ -2,27 +2,12 @@ mod common; use std::collections::VecDeque; use aries_vcx::utils::encryption_envelope::EncryptionEnvelope; -use aries_vcx_core::wallet::base_wallet::BaseWallet; use diddoc_legacy::aries::diddoc::AriesDidDoc; -use mediation::{ - didcomm_types::mediator_coord_structs::{ - KeylistUpdateItem, KeylistUpdateItemAction, KeylistUpdateRequestData, MediatorCoordMsgEnum, - }, - storage::MediatorPersistence, -}; -use mediator::{ - aries_agent::{ - client::transports::{AriesReqwest, AriesTransport}, - utils::oob2did, - Agent, - }, - utils::{structs::VerKey, GenericStringError}, -}; +use mediator::aries_agent::client::transports::{AriesReqwest, AriesTransport}; use messages::{ decorators::attachment::AttachmentType, msg_fields::protocols::{ basic_message::{BasicMessage, BasicMessageContent, BasicMessageDecorators}, - out_of_band::invitation::Invitation as OOBInvitation, pickup::{ DeliveryRequest, DeliveryRequestContent, DeliveryRequestDecorators, Pickup, StatusRequest, StatusRequestContent, StatusRequestDecorators, @@ -33,7 +18,7 @@ use messages::{ use crate::common::{ agent_and_transport_utils::{ - gen_mediator_connected_agent, get_mediator_grant_data, + gen_and_register_recipient_key, gen_mediator_connected_agent, get_mediator_grant_data, send_message_and_pop_response_message, }, prelude::*, @@ -42,44 +27,6 @@ use crate::common::{ static LOGGING_INIT: std::sync::Once = std::sync::Once::new(); -/// Register recipient keys with mediator -async fn gen_and_register_recipient_key( - agent: &mut Agent, - agent_aries_transport: &mut impl AriesTransport, - agent_verkey: &VerKey, - mediator_diddoc: &AriesDidDoc, -) -> Result<(VerKey, AriesDidDoc)> { - let agent_invite: OOBInvitation = agent - .get_oob_invite() - .map_err(|e| GenericStringError { msg: e.to_string() })?; - let agent_diddoc = oob2did(agent_invite); - let agent_recipient_key = agent_diddoc - .recipient_keys() - .unwrap() - .first() - .unwrap() - .clone(); - // register recipient key with mediator - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: agent_recipient_key.clone(), - action: KeylistUpdateItemAction::Add, - result: None, - }], - }); - info!("Sending {:?}", serde_json::to_string(&message).unwrap()); - let message_bytes = serde_json::to_vec(&message)?; - let _response_message = send_message_and_pop_response_message( - &message_bytes, - agent, - agent_aries_transport, - agent_verkey, - mediator_diddoc, - ) - .await?; - Ok((agent_recipient_key, agent_diddoc)) -} - async fn forward_basic_anoncrypt_message( agent_diddoc: &AriesDidDoc, message_text: &str, diff --git a/aries/agents/rust/mediator/tests/mediator-routing-forward.rs b/aries/agents/rust/mediator/tests/mediator-routing-forward.rs index e09d2ca858..f18cfeaa5f 100644 --- a/aries/agents/rust/mediator/tests/mediator-routing-forward.rs +++ b/aries/agents/rust/mediator/tests/mediator-routing-forward.rs @@ -2,25 +2,14 @@ mod common; use std::collections::VecDeque; use aries_vcx::utils::encryption_envelope::EncryptionEnvelope; -use mediation::didcomm_types::mediator_coord_structs::{ - KeylistUpdateItem, KeylistUpdateItemAction, KeylistUpdateRequestData, MediatorCoordMsgEnum, -}; -use mediator::{ - aries_agent::{ - client::transports::{AriesReqwest, AriesTransport}, - utils::oob2did, - }, - utils::GenericStringError, -}; -use messages::msg_fields::protocols::{ - basic_message::{BasicMessage, BasicMessageContent, BasicMessageDecorators}, - out_of_band::invitation::Invitation as OOBInvitation, +use mediator::aries_agent::client::transports::{AriesReqwest, AriesTransport}; +use messages::msg_fields::protocols::basic_message::{ + BasicMessage, BasicMessageContent, BasicMessageDecorators, }; use crate::common::{ agent_and_transport_utils::{ - gen_mediator_connected_agent, get_mediator_grant_data, - send_message_and_pop_response_message, + gen_and_register_recipient_key, gen_mediator_connected_agent, get_mediator_grant_data, }, prelude::*, test_setup::setup_env_logging, @@ -45,29 +34,9 @@ async fn test_forward_flow() -> Result<()> { agent .init_service(grant_data.routing_keys, grant_data.endpoint.parse()?) .await?; - let agent_invite: OOBInvitation = agent - .get_oob_invite() - .map_err(|e| GenericStringError { msg: e.to_string() })?; - let agent_diddoc = oob2did(agent_invite); - let agent_recipient_key = agent_diddoc - .recipient_keys() - .unwrap() - .first() - .unwrap() - .clone(); // register recipient key with mediator - let message = MediatorCoordMsgEnum::KeylistUpdateRequest(KeylistUpdateRequestData { - updates: vec![KeylistUpdateItem { - recipient_key: agent_recipient_key, - action: KeylistUpdateItemAction::Add, - result: None, - }], - }); - info!("Sending {:?}", serde_json::to_string(&message).unwrap()); - let message_bytes = serde_json::to_vec(&message)?; - let _response_message = send_message_and_pop_response_message( - &message_bytes, - &agent, + let (_agent_recipient_key, agent_diddoc) = gen_and_register_recipient_key( + &mut agent, &mut agent_aries_transport, &agent_verkey, &mediator_diddoc,