Skip to content

Commit

Permalink
hack: Enable did-exchange invitee protocol tracking by both thid and …
Browse files Browse the repository at this point in the history
…pthid

Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Mar 12, 2024
1 parent af2e543 commit 6bb1281
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
63 changes: 59 additions & 4 deletions aries/agents/rust/aries-vcx-agent/src/services/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ impl ServiceDidExchange {
&our_peer_did,
)
.await?;

// TODO: decouple this from AATH. The reason why we identify the requester's did-exchange
// protocol with pthid is because that's what AATH expects when calling GET
// /agent/command/did-exchange/{id} where {id} is actually {pthid}.
// We should have internal strategy to manage threads ourselves, and build necessary
// extensions/mappings/accommodations in AATH backchannel
let pthid = request
.clone()
.decorators
.thread
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"Request did not contain a thread id",
)
})?
.pthid
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"Request did not contain a pthread id",
)
})?;

// todo: messages must provide easier way to access this without all the shenanigans
let thid = request
.clone()
.decorators
Expand All @@ -87,7 +112,14 @@ impl ServiceDidExchange {
"Request did not contain a thread id",
)
})?
.thid;
.thid
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"Request did not contain a pthread id",
)
})?;

let ddo_their = requester.their_did_doc();
let ddo_our = requester.our_did_document();
let service = ddo_their.get_service_of_type(&ServiceType::DIDCommV1)?;
Expand All @@ -99,15 +131,20 @@ impl ServiceDidExchange {
service.id(),
)
.await?;
// todo: hack; There's issue on AATH level https://github.com/hyperledger/aries-agent-test-harness/issues/784
// but if AATH can not be changed and both thid and pthid are used to track instance
// of protocol then we need to update storage to enable identification by
// multiple IDs (both thid, pthid (or arbitrary other))
self.did_exchange.insert(&pthid, requester.clone())?;
self.did_exchange.insert(&thid, requester.clone())?;
VcxHttpClient
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
Ok(thid)
Ok(pthid)
}

// todo: one would expect this to be just IO utility - split this to process_request / process_response
// send_response
// todo: one would expect this to be just IO utility - split this to process_request /
// process_response send_response
pub async fn send_response(
&self,
request: Request,
Expand Down Expand Up @@ -164,6 +201,23 @@ impl ServiceDidExchange {

pub async fn send_complete(&self, response: Response) -> AgentResult<String> {
let thid = response.decorators.thread.thid.clone();
let pthid = response
.decorators
.thread
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"Request did not contain a thread id",
)
})?
.pthid
.ok_or_else(|| {
AgentError::from_msg(
AgentErrorKind::InvalidState,
"Request did not contain a pthread id",
)
})?;

let (requester, complete) = self
.did_exchange
.get(&thid)?
Expand All @@ -181,6 +235,7 @@ impl ServiceDidExchange {
)
.await?;
self.did_exchange.insert(&thid, requester.clone())?;
self.did_exchange.insert(&pthid, requester.clone())?;
VcxHttpClient
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn construct_didexchange_complete(request_id: String, invitation_id: String)
.thread(
Thread::builder()
.thid(request_id)
.pthid(invitation_id)
.pthid(invitation_id) // did-exchange specified pthread must be present in the <complete> message type
.build(),
)
.timing(Timing::builder().out_time(Utc::now()).build())
Expand Down

0 comments on commit 6bb1281

Please sign in to comment.