-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for processing forward messages (#1028)
Support for processing forward messages (#1028) Signed-off-by: Naian <[email protected]>
- Loading branch information
1 parent
9846060
commit 939ec0e
Showing
14 changed files
with
341 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use axum::{extract::State, Json}; | ||
use mediation::{didcomm_types::ForwardMsg, routes::forward::handle_forward}; | ||
use messages::msg_fields::protocols::routing::Forward; | ||
|
||
use super::{utils::prelude::*, ArcAgent}; | ||
|
||
pub async fn handle_routing_forward( | ||
agent: ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>, | ||
forward: Forward, | ||
) -> Result<(), String> { | ||
info!("{:?}", forward); | ||
let forward_msg_content_str = serde_json::to_string(&forward.content.msg).unwrap(); | ||
let forward_msg: ForwardMsg = ForwardMsg::new(&forward.content.to, &forward_msg_content_str); | ||
|
||
let _ = handle_forward(State(agent.get_persistence_ref()), Json(forward_msg)).await; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pub type VeriKey = String; | ||
pub type VerKey = String; |
82 changes: 82 additions & 0 deletions
82
agents/rust/mediator/tests/common/agent_and_transport_utils.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::collections::VecDeque; | ||
|
||
use aries_vcx::protocols::connection::invitee::{states::completed::Completed, InviteeConnection}; | ||
use aries_vcx_core::wallet::base_wallet::BaseWallet; | ||
use diddoc_legacy::aries::diddoc::AriesDidDoc; | ||
use mediation::storage::MediatorPersistence; | ||
use mediator::{ | ||
aries_agent::{ | ||
transports::{AriesReqwest, AriesTransport}, | ||
Agent, | ||
}, | ||
utils::{structs::VerKey, GenericStringError}, | ||
}; | ||
use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation; | ||
use reqwest::header::ACCEPT; | ||
|
||
use super::prelude::*; | ||
|
||
const ENDPOINT_ROOT: &str = "http://localhost:8005"; | ||
|
||
pub async fn didcomm_connection( | ||
agent: &Agent<impl BaseWallet + 'static, impl MediatorPersistence>, | ||
aries_transport: &mut impl AriesTransport, | ||
) -> Result<InviteeConnection<Completed>> { | ||
let client = reqwest::Client::new(); | ||
let base: Url = ENDPOINT_ROOT.parse().unwrap(); | ||
let endpoint_register = base.join("register").unwrap(); | ||
|
||
let oobi: OOBInvitation = client | ||
.get(endpoint_register) | ||
.header(ACCEPT, "application/json") | ||
.send() | ||
.await? | ||
.error_for_status()? | ||
.json() | ||
.await?; | ||
info!("Got invitation from register endpoint {:?}", oobi); | ||
|
||
let state: InviteeConnection<Completed> = | ||
agent.establish_connection(oobi, aries_transport).await?; | ||
|
||
Ok(state) | ||
} | ||
|
||
/// Returns agent, aries transport for agent, agent's verkey, and mediator's diddoc. | ||
pub async fn gen_mediator_connected_agent() -> Result<( | ||
Agent<impl BaseWallet + 'static, impl MediatorPersistence>, | ||
impl AriesTransport, | ||
VerKey, | ||
AriesDidDoc, | ||
)> { | ||
let agent = mediator::aries_agent::AgentBuilder::new_demo_agent().await?; | ||
let mut aries_transport = AriesReqwest { | ||
response_queue: VecDeque::new(), | ||
client: reqwest::Client::new(), | ||
}; | ||
let completed_connection = didcomm_connection(&agent, &mut aries_transport).await?; | ||
let our_verkey: VerKey = completed_connection.pairwise_info().pw_vk.clone(); | ||
let their_diddoc = completed_connection.their_did_doc().clone(); | ||
Ok((agent, aries_transport, our_verkey, their_diddoc)) | ||
} | ||
|
||
/// Sends message over didcomm connection and returns unpacked response message | ||
pub async fn send_message_and_pop_response_message( | ||
message_bytes: &[u8], | ||
agent: &Agent<impl BaseWallet + 'static, impl MediatorPersistence>, | ||
aries_transport: &mut impl AriesTransport, | ||
our_verkey: &VerKey, | ||
their_diddoc: &AriesDidDoc, | ||
) -> Result<String> { | ||
agent | ||
.pack_and_send_didcomm(message_bytes, our_verkey, their_diddoc, aries_transport) | ||
.await | ||
.map_err(|err| GenericStringError { msg: err })?; | ||
// unpack | ||
let response = aries_transport.pop_aries_envelope()?; | ||
let unpacked_response = agent | ||
.unpack_didcomm(&serde_json::to_vec(&response).unwrap()) | ||
.await | ||
.unwrap(); | ||
Ok(unpacked_response.message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.