-
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.
feat(mediator-client): complete connection
Signed-off-by: nain-F49FF806 <[email protected]>
- Loading branch information
1 parent
f2c04ac
commit 54026f3
Showing
6 changed files
with
101 additions
and
64 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,20 +1,60 @@ | ||
use super::*; | ||
use crate::agent::utils::oob2did; | ||
use crate::utils::prelude::*; | ||
use futures::TryFutureExt; | ||
use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation; | ||
use serde_json::json; | ||
|
||
#[debug_handler] | ||
pub async fn connection_request( | ||
pub async fn handle_register( | ||
State(agent): State<ArcAgent<IndySdkWallet>>, | ||
Json(oob_invite): Json<OOBInvitation>, | ||
) -> Result<Json<Value>, String> { | ||
let (state, response) = agent.client_connect_req(oob_invite.clone()).await?; | ||
todo!() | ||
let (state, EncryptionEnvelope(packed_aries_msg_bytes)) = agent.gen_client_connect_req(oob_invite.clone()).await?; | ||
let packed_aries_msg_json: Value = | ||
serde_json::from_slice(&packed_aries_msg_bytes[..]).expect("Envelope content should be serializable json"); | ||
info!( | ||
"Sending Connection Request Envelope: {},", | ||
serde_json::to_string_pretty(&packed_aries_msg_json).unwrap() | ||
); | ||
let oob_invited_endpoint = oob2did(oob_invite).get_endpoint().expect("Service needs an endpoint"); | ||
let http_client = reqwest::Client::new(); | ||
let res = http_client | ||
.post(oob_invited_endpoint) | ||
.json(&packed_aries_msg_json) | ||
.send() | ||
.await | ||
.map_err(|err| format!("Something went wrong while sending/receiving {:?}", err))?; | ||
debug!("Received response to connection request, {:#?}", res); | ||
let Ok(_res_ref) = res.error_for_status_ref() else { | ||
return Err(format!("{:#?} {:#?}", res.status().as_u16(), res.text().await)); | ||
}; | ||
let res_status = res.status().as_u16(); | ||
let res_bytes = res.bytes().await.map_err(|err| err.to_string())?; | ||
let res_json: Value = serde_json::from_slice(&res_bytes).map_err(|err| err.to_string())?; | ||
info!( | ||
"Received Response {:#?} {:#?}", | ||
res_status, | ||
serde_json::to_string_pretty(&res_json).unwrap() | ||
); | ||
let res_unpack = agent.unpack_didcomm(&res_bytes).await?; | ||
let res_aries: AriesMessage = serde_json::from_str(&res_unpack.message).map_err(|err| err.to_string())?; | ||
info!("Unpacked response {:#?}", res_aries); | ||
let AriesMessage::Connection(Connection::Response(response)) = res_aries else { | ||
return Err(format!("Expected connection response, got {:?}", res_aries)); | ||
}; | ||
let state = agent.handle_response(state, response).await?; | ||
let state_json = serde_json::to_string_pretty(&state).map_err(|err| err.to_string())?; | ||
Ok(Json(json!({ | ||
"status": "success", | ||
"state": state | ||
}))) | ||
} | ||
|
||
pub async fn build_client_router() -> Router { | ||
let agent = Agent::new_demo_agent().await.unwrap(); | ||
Router::default() | ||
.route("/client/register", post(connection_request)) | ||
.route("/client/register", post(handle_register)) | ||
.layer(tower_http::catch_panic::CatchPanicLayer::new()) | ||
.with_state(Arc::new(agent)) | ||
} |
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