Skip to content

Commit 1a52699

Browse files
[Feature] Support DIDExchange 1.1 #1228 (#1230)
* 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]>
1 parent c65653b commit 1a52699

File tree

53 files changed

+1990
-638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1990
-638
lines changed

aries/agents/aath-backchannel/src/controllers/did_exchange.rs

+84-47
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ use actix_web::{get, post, web, Responder};
44
use aries_vcx_agent::aries_vcx::{
55
did_parser_nom::Did,
66
messages::{
7-
msg_fields::protocols::did_exchange::{request::Request, DidExchange},
7+
msg_fields::protocols::did_exchange::{
8+
v1_0::DidExchangeV1_0, v1_1::DidExchangeV1_1, v1_x::request::AnyRequest, DidExchange,
9+
},
810
AriesMessage,
911
},
10-
protocols::did_exchange::state_machine::requester::helpers::invitation_get_first_did_service,
12+
protocols::did_exchange::state_machine::requester::helpers::{
13+
invitation_get_acceptable_did_exchange_version, invitation_get_first_did_service,
14+
},
1115
};
16+
use serde_json::Value;
1217

1318
use crate::{
1419
controllers::AathRequest,
@@ -32,11 +37,13 @@ impl HarnessAgent {
3237
.aries_agent
3338
.out_of_band()
3439
.get_invitation(&invitation_id)?;
40+
41+
let version = invitation_get_acceptable_did_exchange_version(&invitation)?;
3542
let did_inviter: Did = invitation_get_first_did_service(&invitation)?;
36-
let (thid, pthid) = self
43+
let (thid, pthid, my_did) = self
3744
.aries_agent
3845
.did_exchange()
39-
.handle_msg_invitation(did_inviter.to_string(), Some(invitation_id))
46+
.handle_msg_invitation(did_inviter.to_string(), Some(invitation_id), version)
4047
.await?;
4148
if let Some(ref pthid) = pthid {
4249
self.store_mapping_pthid_thid(pthid.clone(), thid.clone());
@@ -46,18 +53,23 @@ impl HarnessAgent {
4653
);
4754
}
4855
let connection_id = pthid.unwrap_or(thid);
49-
Ok(json!({ "connection_id" : connection_id }).to_string())
56+
Ok(json!({
57+
"connection_id" : connection_id,
58+
"my_did": my_did
59+
})
60+
.to_string())
5061
}
5162

52-
pub fn queue_didexchange_request(&self, request: Request) -> HarnessResult<()> {
53-
info!("queue_didexchange_request >> request: {}", request);
63+
pub fn queue_didexchange_request(&self, request: AnyRequest) -> HarnessResult<()> {
64+
info!("queue_didexchange_request >> request: {:?}", request);
5465
let mut msg_buffer = self.didx_msg_buffer.write().map_err(|_| {
5566
HarnessError::from_msg(
5667
HarnessErrorType::InvalidState,
5768
"Failed to lock message buffer",
5869
)
5970
})?;
60-
msg_buffer.push(request.into());
71+
let m = AriesMessage::from(request);
72+
msg_buffer.push(m);
6173
Ok(())
6274
}
6375

@@ -66,13 +78,17 @@ impl HarnessAgent {
6678
&self,
6779
req: &CreateResolvableDidRequest,
6880
) -> HarnessResult<String> {
69-
let (thid, pthid) = self
81+
let (thid, pthid, my_did) = self
7082
.aries_agent
7183
.did_exchange()
72-
.handle_msg_invitation(req.their_public_did.clone(), None) // todo: separate the case with/without invitation on did_exchange handler
84+
.handle_msg_invitation(req.their_public_did.clone(), None, Default::default()) // todo: separate the case with/without invitation on did_exchange handler
7385
.await?;
7486
let connection_id = pthid.unwrap_or(thid);
75-
Ok(json!({ "connection_id": connection_id }).to_string())
87+
Ok(json!({
88+
"connection_id": connection_id,
89+
"my_did": my_did
90+
})
91+
.to_string())
7692
}
7793

7894
// Looks up an oldest unprocessed did-exchange request message
@@ -98,15 +114,21 @@ impl HarnessAgent {
98114
})?
99115
.clone()
100116
};
101-
if let AriesMessage::DidExchange(DidExchange::Request(ref request)) = request {
102-
let thid = request.decorators.thread.clone().unwrap().thid;
103-
Ok(json!({ "connection_id": thid }).to_string())
104-
} else {
105-
Err(HarnessError::from_msg(
106-
HarnessErrorType::InvalidState,
107-
"Message is not a request",
108-
))
109-
}
117+
let request = match request {
118+
AriesMessage::DidExchange(DidExchange::V1_0(DidExchangeV1_0::Request(request)))
119+
| AriesMessage::DidExchange(DidExchange::V1_1(DidExchangeV1_1::Request(request))) => {
120+
request
121+
}
122+
_ => {
123+
return Err(HarnessError::from_msg(
124+
HarnessErrorType::InvalidState,
125+
"Message is not a request",
126+
))
127+
}
128+
};
129+
130+
let thid = request.decorators.thread.clone().unwrap().thid;
131+
Ok(json!({ "connection_id": thid }).to_string())
110132
}
111133

112134
// Note: AVF identifies protocols by thid, but AATH sometimes tracks identifies did-exchange
@@ -139,37 +161,52 @@ impl HarnessAgent {
139161
)
140162
})?
141163
};
142-
if let AriesMessage::DidExchange(DidExchange::Request(request)) = request {
143-
let opt_invitation = match request.decorators.thread.clone().unwrap().pthid {
144-
None => None,
145-
Some(pthid) => {
146-
let invitation = self.aries_agent.out_of_band().get_invitation(&pthid)?;
147-
Some(invitation)
148-
}
149-
};
150-
let (thid, pthid) = self
151-
.aries_agent
152-
.did_exchange()
153-
.handle_msg_request(request.clone(), opt_invitation)
154-
.await?;
164+
let request = match request {
165+
AriesMessage::DidExchange(DidExchange::V1_0(DidExchangeV1_0::Request(r))) => {
166+
AnyRequest::V1_0(r)
167+
}
168+
AriesMessage::DidExchange(DidExchange::V1_1(DidExchangeV1_1::Request(r))) => {
169+
AnyRequest::V1_1(r)
170+
}
171+
_ => {
172+
return Err(HarnessError::from_msg(
173+
HarnessErrorType::InvalidState,
174+
"Message is not a request",
175+
))
176+
}
177+
};
155178

156-
if let Some(pthid) = pthid {
157-
self.store_mapping_pthid_thid(pthid, thid.clone());
158-
} else {
159-
warn!("No storing pthid->this mapping; no pthid available");
179+
let request_thread = &request.inner().decorators.thread;
180+
181+
let opt_invitation = match request_thread.as_ref().and_then(|th| th.pthid.as_ref()) {
182+
Some(pthid) => {
183+
let invitation = self.aries_agent.out_of_band().get_invitation(pthid)?;
184+
Some(invitation)
160185
}
186+
None => None,
187+
};
188+
let (thid, pthid, my_did, their_did) = self
189+
.aries_agent
190+
.did_exchange()
191+
.handle_msg_request(request, opt_invitation)
192+
.await?;
161193

162-
self.aries_agent
163-
.did_exchange()
164-
.send_response(thid.clone())
165-
.await?;
166-
Ok(json!({ "connection_id": thid }).to_string())
194+
if let Some(pthid) = pthid {
195+
self.store_mapping_pthid_thid(pthid, thid.clone());
167196
} else {
168-
Err(HarnessError::from_msg(
169-
HarnessErrorType::InvalidState,
170-
"Message is not a request",
171-
))
197+
warn!("No storing pthid->this mapping; no pthid available");
172198
}
199+
200+
self.aries_agent
201+
.did_exchange()
202+
.send_response(thid.clone())
203+
.await?;
204+
Ok(json!({
205+
"connection_id": thid,
206+
"my_did": my_did,
207+
"their_did": their_did
208+
})
209+
.to_string())
173210
}
174211

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

201238
#[post("/send-request")]
202239
async fn send_did_exchange_request(
203-
req: web::Json<AathRequest<()>>,
240+
req: web::Json<AathRequest<Value>>,
204241
agent: web::Data<RwLock<HarnessAgent>>,
205242
) -> impl Responder {
206243
agent

aries/agents/aath-backchannel/src/controllers/didcomm.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use aries_vcx_agent::aries_vcx::{
66
msg_fields::protocols::{
77
connection::Connection,
88
cred_issuance::{v1::CredentialIssuanceV1, CredentialIssuance},
9-
did_exchange::DidExchange,
9+
did_exchange::{
10+
v1_0::DidExchangeV1_0, v1_1::DidExchangeV1_1, v1_x::request::AnyRequest,
11+
DidExchange,
12+
},
1013
notification::Notification,
1114
present_proof::{v1::PresentProofV1, PresentProof},
1215
},
@@ -197,25 +200,40 @@ impl HarnessAgent {
197200

198201
async fn handle_did_exchange_msg(&self, msg: DidExchange) -> HarnessResult<()> {
199202
match msg {
200-
DidExchange::Request(request) => {
201-
self.queue_didexchange_request(request)?;
203+
DidExchange::V1_0(DidExchangeV1_0::Request(request)) => {
204+
self.queue_didexchange_request(AnyRequest::V1_0(request))?;
202205
}
203-
DidExchange::Response(response) => {
206+
DidExchange::V1_1(DidExchangeV1_1::Request(request)) => {
207+
self.queue_didexchange_request(AnyRequest::V1_1(request))?;
208+
}
209+
DidExchange::V1_0(DidExchangeV1_0::Response(response)) => {
210+
let res = self
211+
.aries_agent
212+
.did_exchange()
213+
.handle_msg_response(response.into())
214+
.await;
215+
if let Err(err) = res {
216+
error!("Error sending complete: {:?}", err);
217+
};
218+
}
219+
DidExchange::V1_1(DidExchangeV1_1::Response(response)) => {
204220
let res = self
205221
.aries_agent
206222
.did_exchange()
207-
.handle_msg_response(response)
223+
.handle_msg_response(response.into())
208224
.await;
209225
if let Err(err) = res {
210226
error!("Error sending complete: {:?}", err);
211227
};
212228
}
213-
DidExchange::Complete(complete) => {
229+
DidExchange::V1_0(DidExchangeV1_0::Complete(complete))
230+
| DidExchange::V1_1(DidExchangeV1_1::Complete(complete)) => {
214231
self.aries_agent
215232
.did_exchange()
216233
.handle_msg_complete(complete)?;
217234
}
218-
DidExchange::ProblemReport(problem_report) => {
235+
DidExchange::V1_0(DidExchangeV1_0::ProblemReport(problem_report))
236+
| DidExchange::V1_1(DidExchangeV1_1::ProblemReport(problem_report)) => {
219237
self.aries_agent
220238
.did_exchange()
221239
.receive_problem_report(problem_report)?;

0 commit comments

Comments
 (0)