diff --git a/mediator/Cargo.lock b/mediator/Cargo.lock index 91d9436143..8791239ac0 100644 --- a/mediator/Cargo.lock +++ b/mediator/Cargo.lock @@ -4810,8 +4810,8 @@ checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" [[package]] name = "xum-test-server" -version = "0.1.0" -source = "git+https://github.com/nain-F49FF806/axum-test-server.git?branch=aries-vcx-mediator-integration#f383922547eda7867d1476bb694b30a9da6fc795" +version = "0.2.0" +source = "git+https://github.com/nain-F49FF806/axum-test-server.git?branch=aries-vcx-mediator-integration#97dcad10a8227a94ab106d77c58b3db55ec79611" dependencies = [ "async-trait", "axum", diff --git a/mediator/Cargo.toml b/mediator/Cargo.toml index 65b9b08914..cb67c9c99b 100644 --- a/mediator/Cargo.toml +++ b/mediator/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "1", features = ["rt-multi-thread", "macros"] } tower-http = { version = "0.4.4", features = ["catch-panic"] } url = "2.4.1" uuid = "1.4.1" -xum-test-server = { git = "https://github.com/nain-F49FF806/axum-test-server.git", branch = "aries-vcx-mediator-integration", version = "0.1.0" } +xum-test-server = { git = "https://github.com/nain-F49FF806/axum-test-server.git", branch = "aries-vcx-mediator-integration", version = "0.2.0" } [dev-dependencies] reqwest = "0.11.20" diff --git a/mediator/src/agent/client.rs b/mediator/src/agent/client.rs index fc66cd1a6a..3305f49576 100644 --- a/mediator/src/agent/client.rs +++ b/mediator/src/agent/client.rs @@ -83,4 +83,14 @@ impl Agent { .await .map_err(|err| err.to_string()) } + pub async fn save_completed_as_contact( + &self, + state: &InviteeConnection, + ) -> Result<(), String> { + let their_vk = state.remote_vk().map_err(|e| e.to_string())?; + let our_vk = &state.pairwise_info().pw_vk; + self.create_account(&their_vk, &our_vk, state.their_did_doc()) + .await?; + Ok(()) + } } diff --git a/mediator/src/agent/mod.rs b/mediator/src/agent/mod.rs index b5719c83cb..72c1a1b7e5 100644 --- a/mediator/src/agent/mod.rs +++ b/mediator/src/agent/mod.rs @@ -14,7 +14,7 @@ use aries_vcx_core::{ }, WalletHandle, }; -use diddoc_legacy::aries::service::AriesService; +use diddoc_legacy::aries::{diddoc::AriesDidDoc, service::AriesService}; use messages::{ msg_fields::protocols::{ connection::{request::Request, response::Response, Connection}, @@ -171,16 +171,23 @@ impl Agent { ) .await .map_err(|e| e.to_string())?; - let their_keys = their_diddoc.recipient_keys().map_err(|e| e.to_string())?; - let auth_pubkey = their_keys - .first() - .ok_or("No recipient key for client :/ ?".to_owned())?; - self.create_account(vk, auth_pubkey.to_owned()).await?; + // let their_keys = their_diddoc.recipient_keys().map_err(|e| e.to_string())?; + // let auth_pubkey = their_keys + // .first() + // .ok_or("No recipient key for client :/ ?".to_owned())?; + // self.create_account(vk, auth_pubkey.to_owned()).await?; Ok(packed_response_envelope) } - pub async fn create_account(&self, _self_vk: VeriKey, their_vk: VeriKey) -> Result<(), String> { - self.persistence.create_account(&their_vk).await?; + pub async fn create_account( + &self, + their_vk: &VeriKey, + our_vk: &VeriKey, + did_doc: &AriesDidDoc, + ) -> Result<(), String> { + self.persistence + .create_account(&their_vk, our_vk, &json!(did_doc).to_string()) + .await?; Ok(()) } } diff --git a/mediator/src/routes/client.rs b/mediator/src/routes/client.rs index cb8f69577c..6c8f9f4e77 100644 --- a/mediator/src/routes/client.rs +++ b/mediator/src/routes/client.rs @@ -50,6 +50,7 @@ pub async fn handle_register( return Err(format!("Expected connection response, got {:?}", res_aries)); }; let state = agent.handle_response(state, response).await?; + agent.save_completed_as_contact(&state).await?; Ok(Json(json!({ "status": "success", "state": state