Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Present Proof V2.0 message structures #1017

Merged
merged 8 commits into from
Oct 20, 2023
Merged
8 changes: 4 additions & 4 deletions agents/rust/aries-vcx-agent/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use aries_vcx::{
util::PresentationProposalData,
},
messages::{
msg_fields::protocols::present_proof::{
ack::AckPresentation, request::RequestPresentation,
msg_fields::protocols::present_proof::v1::{
ack::AckPresentationV1, request::RequestPresentationV1,
},
AriesMessage,
},
Expand Down Expand Up @@ -98,7 +98,7 @@ impl ServiceProver {
pub fn create_from_request(
&self,
connection_id: &str,
request: RequestPresentation,
request: RequestPresentationV1,
) -> AgentResult<String> {
self.service_connections.get_by_id(connection_id)?;
let prover = Prover::create_from_request("", request)?;
Expand Down Expand Up @@ -178,7 +178,7 @@ impl ServiceProver {
pub fn process_presentation_ack(
&self,
thread_id: &str,
ack: AckPresentation,
ack: AckPresentationV1,
) -> AgentResult<String> {
let ProverWrapper {
mut prover,
Expand Down
8 changes: 4 additions & 4 deletions agents/rust/aries-vcx-agent/src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use aries_vcx::{
common::proofs::proof_request::PresentationRequestData,
handlers::proof_presentation::verifier::Verifier,
messages::{
msg_fields::protocols::present_proof::{
present::Presentation, propose::ProposePresentation,
msg_fields::protocols::present_proof::v1::{
present::PresentationV1, propose::ProposePresentationV1,
},
AriesMessage,
},
Expand Down Expand Up @@ -69,7 +69,7 @@ impl ServiceVerifier {
&self,
connection_id: &str,
request: PresentationRequestData,
proposal: Option<ProposePresentation>,
proposal: Option<ProposePresentationV1>,
) -> AgentResult<String> {
let connection = self.service_connections.get_by_id(connection_id)?;
let mut verifier = if let Some(proposal) = proposal {
Expand Down Expand Up @@ -103,7 +103,7 @@ impl ServiceVerifier {
pub async fn verify_presentation(
&self,
thread_id: &str,
presentation: Presentation,
presentation: PresentationV1,
) -> AgentResult<()> {
let VerifierWrapper {
mut verifier,
Expand Down
14 changes: 5 additions & 9 deletions aries_vcx/src/handlers/out_of_band/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use messages::{
invitation::{Invitation, OobService},
OutOfBand,
},
present_proof::{present::Presentation, request::RequestPresentation, PresentProof},
present_proof::v1::{present::PresentationV1, request::RequestPresentationV1},
},
AriesMessage,
};
Expand Down Expand Up @@ -263,20 +263,18 @@ impl OutOfBandReceiver {
}
AttachmentId::PresentationRequest => {
let request =
RequestPresentation::deserialize(&attach_json).map_err(|_| {
RequestPresentationV1::deserialize(&attach_json).map_err(|_| {
AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!("Failed to deserialize attachment: {attach_json:?}"),
)
})?;

return Ok(Some(AriesMessage::PresentProof(
PresentProof::RequestPresentation(request),
)));
return Ok(Some(request.into()));
}
AttachmentId::Presentation => {
let mut presentation =
Presentation::deserialize(&attach_json).map_err(|_| {
PresentationV1::deserialize(&attach_json).map_err(|_| {
AriesVcxError::from_msg(
AriesVcxErrorKind::SerializationError,
format!("Failed to deserialize attachment: {attach_json:?}"),
Expand All @@ -285,9 +283,7 @@ impl OutOfBandReceiver {

presentation.decorators.thread.pthid = Some(self.oob.id.clone());

return Ok(Some(AriesMessage::PresentProof(
PresentProof::Presentation(presentation),
)));
return Ok(Some(presentation.into()));
}
},
None => {
Expand Down
6 changes: 4 additions & 2 deletions aries_vcx/src/handlers/out_of_band/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use messages::{
invitation::{Invitation, InvitationContent, InvitationDecorators, OobService},
OobGoalCode,
},
present_proof::PresentProof,
present_proof::{v1::PresentProofV1, PresentProof},
},
msg_types::Protocol,
AriesMessage,
Expand Down Expand Up @@ -92,7 +92,9 @@ impl OutOfBandSender {

pub fn append_a2a_message(mut self, msg: AriesMessage) -> VcxResult<Self> {
let (attach_id, attach) = match msg {
a2a_msg @ AriesMessage::PresentProof(PresentProof::RequestPresentation(_)) => (
a2a_msg @ AriesMessage::PresentProof(PresentProof::V1(
PresentProofV1::RequestPresentation(_),
)) => (
AttachmentId::PresentationRequest,
json!(&a2a_msg).to_string(),
),
Expand Down
15 changes: 11 additions & 4 deletions aries_vcx/src/handlers/proof_presentation/mediated_prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashMap;

use messages::{
msg_fields::protocols::{notification::Notification, present_proof::PresentProof},
msg_fields::protocols::{
notification::Notification,
present_proof::{v1::PresentProofV1, PresentProof},
},
AriesMessage,
};

Expand Down Expand Up @@ -32,7 +35,9 @@ pub fn prover_find_message_to_handle(
return Some((uid, message));
}
}
AriesMessage::PresentProof(PresentProof::RequestPresentation(msg)) => {
AriesMessage::PresentProof(PresentProof::V1(
PresentProofV1::RequestPresentation(msg),
)) => {
if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
Expand All @@ -45,7 +50,7 @@ pub fn prover_find_message_to_handle(
return Some((uid, message));
}
}
AriesMessage::PresentProof(PresentProof::Ack(msg)) => {
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::Ack(msg))) => {
if matches_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
Expand All @@ -60,7 +65,9 @@ pub fn prover_find_message_to_handle(
return Some((uid, message));
}
}
AriesMessage::PresentProof(PresentProof::ProblemReport(msg)) => {
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::ProblemReport(
msg,
))) => {
if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
Expand Down
21 changes: 16 additions & 5 deletions aries_vcx/src/handlers/proof_presentation/mediated_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use messages::{msg_fields::protocols::present_proof::PresentProof, AriesMessage};
use messages::{
msg_fields::protocols::present_proof::{v1::PresentProofV1, PresentProof},
AriesMessage,
};

use crate::{
handlers::{
Expand All @@ -22,21 +25,29 @@ pub fn verifier_find_message_to_handle(
for (uid, message) in messages {
match sm.get_state() {
VerifierState::Initial => match &message {
AriesMessage::PresentProof(PresentProof::ProposePresentation(_)) => {
AriesMessage::PresentProof(PresentProof::V1(
PresentProofV1::ProposePresentation(_),
)) => {
return Some((uid, message));
}
AriesMessage::PresentProof(PresentProof::RequestPresentation(_)) => {
AriesMessage::PresentProof(PresentProof::V1(
PresentProofV1::RequestPresentation(_),
)) => {
return Some((uid, message));
}
_ => {}
},
VerifierState::PresentationRequestSent => match &message {
AriesMessage::PresentProof(PresentProof::Presentation(presentation)) => {
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::Presentation(
presentation,
))) => {
if matches_thread_id!(presentation, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
}
AriesMessage::PresentProof(PresentProof::ProposePresentation(proposal)) => {
AriesMessage::PresentProof(PresentProof::V1(
PresentProofV1::ProposePresentation(proposal),
)) => {
if matches_opt_thread_id!(proposal, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
Expand Down
44 changes: 25 additions & 19 deletions aries_vcx/src/handlers/proof_presentation/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ use messages::{
msg_fields::protocols::{
notification::Notification,
present_proof::{
ack::AckPresentation,
present::Presentation,
propose::{
PresentationPreview, ProposePresentation, ProposePresentationContent,
ProposePresentationDecorators,
v1::{
ack::AckPresentationV1,
present::PresentationV1,
propose::{
PresentationPreview, ProposePresentationV1, ProposePresentationV1Content,
ProposePresentationV1Decorators,
},
request::RequestPresentationV1,
PresentProofV1,
},
request::RequestPresentation,
PresentProof,
},
},
Expand Down Expand Up @@ -49,7 +52,7 @@ impl Prover {

pub fn create_from_request(
source_id: &str,
presentation_request: RequestPresentation,
presentation_request: RequestPresentationV1,
) -> VcxResult<Prover> {
trace!(
"Prover::create_from_request >>> source_id: {}, presentation_request: {:?}",
Expand Down Expand Up @@ -107,14 +110,14 @@ impl Prover {
Ok(())
}

pub fn get_presentation_msg(&self) -> VcxResult<Presentation> {
pub fn get_presentation_msg(&self) -> VcxResult<PresentationV1> {
Ok(self.prover_sm.get_presentation_msg()?.to_owned())
}

pub async fn build_presentation_proposal(
&mut self,
proposal_data: PresentationProposalData,
) -> VcxResult<ProposePresentation> {
) -> VcxResult<ProposePresentationV1> {
trace!("Prover::build_presentation_proposal >>>");
self.prover_sm = self
.prover_sm
Expand All @@ -140,7 +143,7 @@ impl Prover {
}
}

pub fn process_presentation_ack(&mut self, ack: AckPresentation) -> VcxResult<()> {
pub fn process_presentation_ack(&mut self, ack: AckPresentationV1) -> VcxResult<()> {
trace!("Prover::process_presentation_ack >>>");
self.prover_sm = self.prover_sm.clone().receive_presentation_ack(ack)?;
Ok(())
Expand Down Expand Up @@ -191,11 +194,13 @@ impl Prover {

pub async fn process_aries_msg(&mut self, message: AriesMessage) -> VcxResult<()> {
let prover_sm = match message {
AriesMessage::PresentProof(PresentProof::RequestPresentation(request)) => self
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::RequestPresentation(
request,
))) => self
.prover_sm
.clone()
.receive_presentation_request(request)?,
AriesMessage::PresentProof(PresentProof::Ack(ack)) => {
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::Ack(ack))) => {
self.prover_sm.clone().receive_presentation_ack(ack)?
}
AriesMessage::ReportProblem(report) => {
Expand All @@ -205,10 +210,11 @@ impl Prover {
.prover_sm
.clone()
.receive_presentation_reject(report.into())?,
AriesMessage::PresentProof(PresentProof::ProblemReport(report)) => self
.prover_sm
.clone()
.receive_presentation_reject(report.into())?,
AriesMessage::PresentProof(PresentProof::V1(PresentProofV1::ProblemReport(report))) => {
self.prover_sm
.clone()
.receive_presentation_reject(report.into())?
}
_ => self.prover_sm.clone(),
};
self.prover_sm = prover_sm;
Expand Down Expand Up @@ -249,16 +255,16 @@ impl Prover {
let thread_id = self.prover_sm.get_thread_id()?;
let id = Uuid::new_v4().to_string();

let content = ProposePresentationContent::builder()
let content = ProposePresentationV1Content::builder()
.presentation_proposal(presentation_preview)
.build();

let decorators = ProposePresentationDecorators::builder()
let decorators = ProposePresentationV1Decorators::builder()
.thread(Thread::builder().thid(thread_id.to_owned()).build())
.timing(Timing::builder().out_time(Utc::now()).build())
.build();

let proposal = ProposePresentation::builder()
let proposal = ProposePresentationV1::builder()
.id(id)
.content(content)
.decorators(decorators)
Expand Down
Loading
Loading