Skip to content

Commit

Permalink
pass in handshake ver
Browse files Browse the repository at this point in the history
Signed-off-by: George Mulhearn <[email protected]>
  • Loading branch information
gmulhearn-anonyome committed Jun 24, 2024
1 parent ed46a35 commit 5f5133d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
10 changes: 7 additions & 3 deletions aries/agents/aath-backchannel/src/controllers/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use aries_vcx_agent::aries_vcx::{
},
AriesMessage,
},
protocols::did_exchange::state_machine::requester::helpers::invitation_get_first_did_service,
protocols::did_exchange::state_machine::requester::helpers::{
invitation_get_acceptable_did_exchange_version, invitation_get_first_did_service,
},
};
use serde_json::Value;

Expand All @@ -35,11 +37,13 @@ impl HarnessAgent {
.aries_agent
.out_of_band()
.get_invitation(&invitation_id)?;

let version = invitation_get_acceptable_did_exchange_version(&invitation)?;
let did_inviter: Did = invitation_get_first_did_service(&invitation)?;
let (thid, pthid, my_did) = self
.aries_agent
.did_exchange()
.handle_msg_invitation(did_inviter.to_string(), Some(invitation_id))
.handle_msg_invitation(did_inviter.to_string(), Some(invitation_id), version)
.await?;
if let Some(ref pthid) = pthid {
self.store_mapping_pthid_thid(pthid.clone(), thid.clone());
Expand Down Expand Up @@ -77,7 +81,7 @@ impl HarnessAgent {
let (thid, pthid, my_did) = self
.aries_agent
.did_exchange()
.handle_msg_invitation(req.their_public_did.clone(), None) // todo: separate the case with/without invitation on did_exchange handler
.handle_msg_invitation(req.their_public_did.clone(), None, Default::default()) // todo: separate the case with/without invitation on did_exchange handler
.await?;
let connection_id = pthid.unwrap_or(thid);
Ok(json!({
Expand Down
3 changes: 3 additions & 0 deletions aries/agents/aries-vcx-agent/src/handlers/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use aries_vcx::{
},
out_of_band::invitation::Invitation as OobInvitation,
},
msg_types::protocols::did_exchange::DidExchangeTypeV1,
AriesMessage,
},
protocols::did_exchange::{
Expand Down Expand Up @@ -63,6 +64,7 @@ impl<T: BaseWallet> DidcommHandlerDidExchange<T> {
&self,
their_did: String,
invitation_id: Option<String>,
version: DidExchangeTypeV1,
) -> AgentResult<(String, Option<String>, String)> {
// todo: type the return type
let (our_peer_did, _our_verkey) =
Expand All @@ -76,6 +78,7 @@ impl<T: BaseWallet> DidcommHandlerDidExchange<T> {
&their_did,
&our_peer_did,
"".to_owned(),
version,
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ use did_doc::schema::did_doc::DidDocument;
use did_parser_nom::Did;
use did_peer::peer_did::{numalgos::numalgo4::Numalgo4, PeerDid};
use did_resolver_registry::ResolverRegistry;
use messages::msg_fields::protocols::did_exchange::{
v1_1::request::Request,
v1_x::{complete::Complete, problem_report::ProblemReport, response::AnyResponse},
use messages::{
msg_fields::protocols::did_exchange::{
v1_1::request::Request,
v1_x::{complete::Complete, problem_report::ProblemReport, response::AnyResponse},
},
msg_types::protocols::did_exchange::DidExchangeTypeV1,
};
use public_key::Key;
pub use thin_state::ThinState;
Expand Down Expand Up @@ -90,6 +93,7 @@ impl GenericDidExchange {
their_did: &Did,
our_peer_did: &PeerDid<Numalgo4>,
our_label: String,
version: DidExchangeTypeV1,
) -> Result<(Self, Request), AriesVcxError> {
let TransitionResult { state, output } =
DidExchangeRequester::<RequestSent>::construct_request(
Expand All @@ -98,6 +102,7 @@ impl GenericDidExchange {
their_did,
our_peer_did,
our_label,
version,
)
.await?;
Ok((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use messages::{
},
out_of_band::invitation::{Invitation, OobService},
},
msg_types::protocols::did_exchange::DidExchangeTypeV1,
msg_types::{
protocols::did_exchange::{DidExchangeType, DidExchangeTypeV1},
Protocol,
},
};
use shared::maybe_known::MaybeKnown;
use uuid::Uuid;
Expand Down Expand Up @@ -94,3 +97,39 @@ pub fn invitation_get_first_did_service(invitation: &Invitation) -> VcxResult<Di
"Invitation does not contain did service",
))
}

/// Finds the best suitable DIDExchange V1.X version specified in an invitation, or an error if
/// none.
pub fn invitation_get_acceptable_did_exchange_version(
invitation: &Invitation,
) -> VcxResult<DidExchangeTypeV1> {
// determine acceptable protocol
let mut did_exch_v1_1_accepted = false;
let mut did_exch_v1_0_accepted = false;
for proto in invitation.content.handshake_protocols.iter().flatten() {
let MaybeKnown::Known(Protocol::DidExchangeType(DidExchangeType::V1(exch_proto))) = proto
else {
continue;
};
if matches!(exch_proto, DidExchangeTypeV1::V1_1(_)) {
did_exch_v1_1_accepted = true;
continue;
}
if matches!(exch_proto, DidExchangeTypeV1::V1_0(_)) {
did_exch_v1_0_accepted = true;
}
}

let version = match (did_exch_v1_1_accepted, did_exch_v1_0_accepted) {
(true, _) => DidExchangeTypeV1::new_v1_1(),
(false, true) => DidExchangeTypeV1::new_v1_0(),
_ => {
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidInput,
"OOB invitation does not have a suitable handshake protocol for DIDExchange",
))
}
};

Ok(version)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl DidExchangeRequester<RequestSent> {
their_did: &Did,
our_peer_did: &PeerDid<Numalgo4>,
our_label: String,
version: DidExchangeTypeV1,
) -> Result<TransitionResult<Self, Request>, AriesVcxError> {
debug!(
"DidExchangeRequester<RequestSent>::construct_request >> their_did: {}, our_peer_did: \
Expand All @@ -47,7 +48,7 @@ impl DidExchangeRequester<RequestSent> {
invitation_id.clone(),
our_peer_did.to_string(),
our_label,
DidExchangeTypeV1::new_v1_1(),
version,
);

debug!(
Expand Down
6 changes: 4 additions & 2 deletions aries/aries_vcx/tests/test_did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ use did_peer::resolver::PeerDidResolver;
use did_resolver_registry::ResolverRegistry;
use did_resolver_sov::resolution::DidSovResolver;
use log::info;
use messages::msg_fields::protocols::out_of_band::invitation::{
Invitation, InvitationContent, OobService,
use messages::{
msg_fields::protocols::out_of_band::invitation::{Invitation, InvitationContent, OobService},
msg_types::protocols::did_exchange::DidExchangeTypeV1,
};
use pretty_assertions::assert_eq;
use test_utils::devsetup::{dev_build_profile_vdr_ledger, SetupPoolDirectory};
Expand Down Expand Up @@ -129,6 +130,7 @@ async fn did_exchange_test() -> Result<(), Box<dyn Error>> {
&did_inviter,
&requesters_peer_did,
"some-label".to_owned(),
DidExchangeTypeV1::new_v1_1(),
)
.await
.unwrap();
Expand Down
6 changes: 6 additions & 0 deletions aries/messages/src/msg_types/protocols/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pub enum DidExchangeTypeV1_1 {
Complete,
}

impl Default for DidExchangeTypeV1 {
fn default() -> Self {
Self::new_v1_1()
}
}

#[cfg(test)]
mod tests {
use serde_json::json;
Expand Down

0 comments on commit 5f5133d

Please sign in to comment.