Skip to content

Commit

Permalink
[Feature] Support DIDExchange 1.1 #1228 (#1230)
Browse files Browse the repository at this point in the history
* move existing into v1_0 section

Signed-off-by: George Mulhearn <[email protected]>

* duplicate types

Signed-off-by: George Mulhearn <[email protected]>

* static generic types for messages created and piped thru all layers

Signed-off-by: George Mulhearn <[email protected]>

* simplify generics

Signed-off-by: George Mulhearn <[email protected]>

* change approach to use runtime versioning rather than generics

Signed-off-by: George Mulhearn <[email protected]>

* v1_1 branch processing, and some clippy

Signed-off-by: George Mulhearn <[email protected]>

* remove old todos

Signed-off-by: George Mulhearn <[email protected]>

* fixes for aath with self for 4/7 performance on RFC0793 & 4/7 on 0023

Signed-off-by: George Mulhearn <[email protected]>

* smalls patches from acapy testing

Signed-off-by: George Mulhearn <[email protected]>

* fix up mimetype handling as a result of testing acapy (text/string)

Signed-off-by: George Mulhearn <[email protected]>

* handle multikey (acapy uses this)

Signed-off-by: George Mulhearn <[email protected]>

* make invite handshake 1.1

Signed-off-by: George Mulhearn <[email protected]>

* include invitation id

Signed-off-by: George Mulhearn <[email protected]>

* pthid in response (for acapy)

Signed-off-by: George Mulhearn <[email protected]>

* merge fix and add hack for local aath testing

Signed-off-by: George Mulhearn <[email protected]>

* fixes for didpeer2

Signed-off-by: George Mulhearn <[email protected]>

* improve VM handling to understand more DIDDoc styles (acapy AATH testing)

Signed-off-by: George Mulhearn <[email protected]>

* fmt

Signed-off-by: George Mulhearn <[email protected]>

* clean switcher

Signed-off-by: George Mulhearn <[email protected]>

* label pass, and some fixes

Signed-off-by: George Mulhearn <[email protected]>

* test fixes

Signed-off-by: George Mulhearn <[email protected]>

* fix did rotate content

Signed-off-by: George Mulhearn <[email protected]>

* pass in handshake ver

Signed-off-by: George Mulhearn <[email protected]>

* any-wrapper approach

Signed-off-by: George Mulhearn <[email protected]>

* lint

Signed-off-by: George Mulhearn <[email protected]>

---------

Signed-off-by: George Mulhearn <[email protected]>
Co-authored-by: George Mulhearn <[email protected]>
  • Loading branch information
gmulhearn and gmulhearn-anonyome authored Jun 26, 2024
1 parent c65653b commit 1a52699
Show file tree
Hide file tree
Showing 53 changed files with 1,990 additions and 638 deletions.
131 changes: 84 additions & 47 deletions aries/agents/aath-backchannel/src/controllers/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ use actix_web::{get, post, web, Responder};
use aries_vcx_agent::aries_vcx::{
did_parser_nom::Did,
messages::{
msg_fields::protocols::did_exchange::{request::Request, DidExchange},
msg_fields::protocols::did_exchange::{
v1_0::DidExchangeV1_0, v1_1::DidExchangeV1_1, v1_x::request::AnyRequest, DidExchange,
},
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;

use crate::{
controllers::AathRequest,
Expand All @@ -32,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) = self
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 All @@ -46,18 +53,23 @@ impl HarnessAgent {
);
}
let connection_id = pthid.unwrap_or(thid);
Ok(json!({ "connection_id" : connection_id }).to_string())
Ok(json!({
"connection_id" : connection_id,
"my_did": my_did
})
.to_string())
}

pub fn queue_didexchange_request(&self, request: Request) -> HarnessResult<()> {
info!("queue_didexchange_request >> request: {}", request);
pub fn queue_didexchange_request(&self, request: AnyRequest) -> HarnessResult<()> {
info!("queue_didexchange_request >> request: {:?}", request);
let mut msg_buffer = self.didx_msg_buffer.write().map_err(|_| {
HarnessError::from_msg(
HarnessErrorType::InvalidState,
"Failed to lock message buffer",
)
})?;
msg_buffer.push(request.into());
let m = AriesMessage::from(request);
msg_buffer.push(m);
Ok(())
}

Expand All @@ -66,13 +78,17 @@ impl HarnessAgent {
&self,
req: &CreateResolvableDidRequest,
) -> HarnessResult<String> {
let (thid, pthid) = self
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!({ "connection_id": connection_id }).to_string())
Ok(json!({
"connection_id": connection_id,
"my_did": my_did
})
.to_string())
}

// Looks up an oldest unprocessed did-exchange request message
Expand All @@ -98,15 +114,21 @@ impl HarnessAgent {
})?
.clone()
};
if let AriesMessage::DidExchange(DidExchange::Request(ref request)) = request {
let thid = request.decorators.thread.clone().unwrap().thid;
Ok(json!({ "connection_id": thid }).to_string())
} else {
Err(HarnessError::from_msg(
HarnessErrorType::InvalidState,
"Message is not a request",
))
}
let request = match request {
AriesMessage::DidExchange(DidExchange::V1_0(DidExchangeV1_0::Request(request)))
| AriesMessage::DidExchange(DidExchange::V1_1(DidExchangeV1_1::Request(request))) => {
request
}
_ => {
return Err(HarnessError::from_msg(
HarnessErrorType::InvalidState,
"Message is not a request",
))
}
};

let thid = request.decorators.thread.clone().unwrap().thid;
Ok(json!({ "connection_id": thid }).to_string())
}

// Note: AVF identifies protocols by thid, but AATH sometimes tracks identifies did-exchange
Expand Down Expand Up @@ -139,37 +161,52 @@ impl HarnessAgent {
)
})?
};
if let AriesMessage::DidExchange(DidExchange::Request(request)) = request {
let opt_invitation = match request.decorators.thread.clone().unwrap().pthid {
None => None,
Some(pthid) => {
let invitation = self.aries_agent.out_of_band().get_invitation(&pthid)?;
Some(invitation)
}
};
let (thid, pthid) = self
.aries_agent
.did_exchange()
.handle_msg_request(request.clone(), opt_invitation)
.await?;
let request = match request {
AriesMessage::DidExchange(DidExchange::V1_0(DidExchangeV1_0::Request(r))) => {
AnyRequest::V1_0(r)
}
AriesMessage::DidExchange(DidExchange::V1_1(DidExchangeV1_1::Request(r))) => {
AnyRequest::V1_1(r)
}
_ => {
return Err(HarnessError::from_msg(
HarnessErrorType::InvalidState,
"Message is not a request",
))
}
};

if let Some(pthid) = pthid {
self.store_mapping_pthid_thid(pthid, thid.clone());
} else {
warn!("No storing pthid->this mapping; no pthid available");
let request_thread = &request.inner().decorators.thread;

let opt_invitation = match request_thread.as_ref().and_then(|th| th.pthid.as_ref()) {
Some(pthid) => {
let invitation = self.aries_agent.out_of_band().get_invitation(pthid)?;
Some(invitation)
}
None => None,
};
let (thid, pthid, my_did, their_did) = self
.aries_agent
.did_exchange()
.handle_msg_request(request, opt_invitation)
.await?;

self.aries_agent
.did_exchange()
.send_response(thid.clone())
.await?;
Ok(json!({ "connection_id": thid }).to_string())
if let Some(pthid) = pthid {
self.store_mapping_pthid_thid(pthid, thid.clone());
} else {
Err(HarnessError::from_msg(
HarnessErrorType::InvalidState,
"Message is not a request",
))
warn!("No storing pthid->this mapping; no pthid available");
}

self.aries_agent
.did_exchange()
.send_response(thid.clone())
.await?;
Ok(json!({
"connection_id": thid,
"my_did": my_did,
"their_did": their_did
})
.to_string())
}

pub async fn didx_get_state(&self, connection_id: &str) -> HarnessResult<String> {
Expand Down Expand Up @@ -200,7 +237,7 @@ impl HarnessAgent {

#[post("/send-request")]
async fn send_did_exchange_request(
req: web::Json<AathRequest<()>>,
req: web::Json<AathRequest<Value>>,
agent: web::Data<RwLock<HarnessAgent>>,
) -> impl Responder {
agent
Expand Down
32 changes: 25 additions & 7 deletions aries/agents/aath-backchannel/src/controllers/didcomm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use aries_vcx_agent::aries_vcx::{
msg_fields::protocols::{
connection::Connection,
cred_issuance::{v1::CredentialIssuanceV1, CredentialIssuance},
did_exchange::DidExchange,
did_exchange::{
v1_0::DidExchangeV1_0, v1_1::DidExchangeV1_1, v1_x::request::AnyRequest,
DidExchange,
},
notification::Notification,
present_proof::{v1::PresentProofV1, PresentProof},
},
Expand Down Expand Up @@ -197,25 +200,40 @@ impl HarnessAgent {

async fn handle_did_exchange_msg(&self, msg: DidExchange) -> HarnessResult<()> {
match msg {
DidExchange::Request(request) => {
self.queue_didexchange_request(request)?;
DidExchange::V1_0(DidExchangeV1_0::Request(request)) => {
self.queue_didexchange_request(AnyRequest::V1_0(request))?;
}
DidExchange::Response(response) => {
DidExchange::V1_1(DidExchangeV1_1::Request(request)) => {
self.queue_didexchange_request(AnyRequest::V1_1(request))?;
}
DidExchange::V1_0(DidExchangeV1_0::Response(response)) => {
let res = self
.aries_agent
.did_exchange()
.handle_msg_response(response.into())
.await;
if let Err(err) = res {
error!("Error sending complete: {:?}", err);
};
}
DidExchange::V1_1(DidExchangeV1_1::Response(response)) => {
let res = self
.aries_agent
.did_exchange()
.handle_msg_response(response)
.handle_msg_response(response.into())
.await;
if let Err(err) = res {
error!("Error sending complete: {:?}", err);
};
}
DidExchange::Complete(complete) => {
DidExchange::V1_0(DidExchangeV1_0::Complete(complete))
| DidExchange::V1_1(DidExchangeV1_1::Complete(complete)) => {
self.aries_agent
.did_exchange()
.handle_msg_complete(complete)?;
}
DidExchange::ProblemReport(problem_report) => {
DidExchange::V1_0(DidExchangeV1_0::ProblemReport(problem_report))
| DidExchange::V1_1(DidExchangeV1_1::ProblemReport(problem_report)) => {
self.aries_agent
.did_exchange()
.receive_problem_report(problem_report)?;
Expand Down
Loading

0 comments on commit 1a52699

Please sign in to comment.