Skip to content

Commit

Permalink
feat(mediator-client): add functions to save contact info
Browse files Browse the repository at this point in the history
Signed-off-by: Naian <[email protected]>
  • Loading branch information
nain-F49FF806 committed Oct 4, 2023
1 parent e689c99 commit f66a1b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mediator/Cargo.lock

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

2 changes: 1 addition & 1 deletion mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 10 additions & 0 deletions mediator/src/agent/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ impl Agent {
.await
.map_err(|err| err.to_string())
}
pub async fn save_completed_as_contact(
&self,
state: &InviteeConnection<Completed>,
) -> 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(())
}
}
23 changes: 15 additions & 8 deletions mediator/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(())
}
}
1 change: 1 addition & 0 deletions mediator/src/routes/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f66a1b3

Please sign in to comment.