From 4c169ce416019a5f6c54fbd948432457a924bb0b Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 14:12:12 +0200 Subject: [PATCH 01/40] Restore thread_id verifications Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 3 ++- aries_vcx/src/protocols/issuance/issuer/state_machine.rs | 5 +---- .../protocols/proof_presentation/verifier/state_machine.rs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 55bd861c8b..21e9bc8dc9 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -19,11 +19,12 @@ use messages::msg_fields::protocols::notification::ack::{AckDecorators, AckStatu use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::AriesMessage; use uuid::Uuid; +use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use crate::common::credentials::{get_cred_rev_id, is_cred_revoked}; use crate::errors::error::prelude::*; use crate::global::settings; -use crate::handlers::util::{get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status}; +use crate::handlers::util::{get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status, verify_thread_id}; use crate::protocols::common::build_problem_report_msg; use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 4a9cead2cd..28e442c52f 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -1,10 +1,7 @@ use std::fmt::Display; use std::sync::Arc; -use crate::handlers::util::{ - get_attach_as_string, make_attach_from_str, matches_opt_thread_id, verify_thread_id, AttachmentId, OfferInfo, - Status, -}; +use crate::handlers::util::{get_attach_as_string, make_attach_from_str, matches_opt_thread_id, verify_thread_id, AttachmentId, OfferInfo, Status}; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use chrono::Utc; diff --git a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs index 74f37875d6..7771834955 100644 --- a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs +++ b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs @@ -25,7 +25,7 @@ use messages::AriesMessage; use crate::common::proofs::proof_request::PresentationRequestData; use crate::errors::error::prelude::*; -use crate::handlers::util::{make_attach_from_str, verify_thread_id, AttachmentId, Status}; +use crate::handlers::util::{make_attach_from_str, AttachmentId, Status, verify_thread_id}; use crate::protocols::common::build_problem_report_msg; use crate::protocols::proof_presentation::verifier::states::finished::FinishedState; use crate::protocols::proof_presentation::verifier::states::initial::InitialVerifierState; From c7b961c0f1f16ec8650f0ce090fb6a6a713aa2b9 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 12:40:00 +0200 Subject: [PATCH 02/40] Make IO for issuer offer-sending opt-in Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/issuer.rs | 10 +--- .../src/handlers/issuance/mediated_issuer.rs | 2 +- aries_vcx/src/handlers/mod.rs | 1 - .../issuance/issuer/state_machine.rs | 43 +++----------- .../issuance/issuer/states/initial.rs | 9 +-- .../protocols/issuance/issuer/states/mod.rs | 1 - .../issuance/issuer/states/offer_sent.rs | 59 ------------------- .../issuance/issuer/states/offer_set.rs | 45 ++++++++++++-- .../issuer/states/proposal_received.rs | 11 ++-- aries_vcx/tests/test_creds_proofs.rs | 2 +- aries_vcx/tests/utils/devsetup_faber.rs | 2 +- aries_vcx/tests/utils/scenarios.rs | 8 +-- .../api_vcx/api_handle/issuer_credential.rs | 6 -- .../vcx-napi-rs/src/api/issuer_credential.rs | 5 -- 14 files changed, 71 insertions(+), 133 deletions(-) delete mode 100644 aries_vcx/src/protocols/issuance/issuer/states/offer_sent.rs diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index 5723abcb23..f13732e81d 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -151,13 +151,9 @@ impl Issuer { Ok(offer.into()) } - pub fn mark_credential_offer_msg_sent(&mut self) -> VcxResult<()> { - self.issuer_sm = self.issuer_sm.clone().mark_credential_offer_msg_sent()?; - Ok(()) - } - + #[deprecated] pub async fn send_credential_offer(&mut self, send_message: SendClosure) -> VcxResult<()> { - self.issuer_sm = self.issuer_sm.clone().send_credential_offer(send_message).await?; + self.issuer_sm.clone().send_credential_offer(send_message).await?; Ok(()) } @@ -176,7 +172,7 @@ impl Issuer { anoncreds: &Arc, send_message: SendClosure, ) -> VcxResult<()> { - self.issuer_sm = self.issuer_sm.clone().send_credential(anoncreds, send_message).await?; + self.issuer_sm = self.issuer_sm.clone().build_credential(anoncreds, send_message).await?; Ok(()) } diff --git a/aries_vcx/src/handlers/issuance/mediated_issuer.rs b/aries_vcx/src/handlers/issuance/mediated_issuer.rs index a819d97e22..167e6a5a13 100644 --- a/aries_vcx/src/handlers/issuance/mediated_issuer.rs +++ b/aries_vcx/src/handlers/issuance/mediated_issuer.rs @@ -26,7 +26,7 @@ pub fn issuer_find_message_to_handle( return Some((uid, message)); } } - IssuerState::OfferSent => match &message { + IssuerState::OfferSet => match &message { AriesMessage::CredentialIssuance(CredentialIssuance::RequestCredential(msg)) => { if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); diff --git a/aries_vcx/src/handlers/mod.rs b/aries_vcx/src/handlers/mod.rs index 065865dd8e..a32dc58bd8 100644 --- a/aries_vcx/src/handlers/mod.rs +++ b/aries_vcx/src/handlers/mod.rs @@ -55,7 +55,6 @@ impl From for u32 { IssuerState::Initial => 0, IssuerState::ProposalReceived => 1, IssuerState::OfferSet => 2, - IssuerState::OfferSent => 3, IssuerState::RequestReceived => 4, IssuerState::CredentialSent => 5, IssuerState::Finished => 6, diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 28e442c52f..2fb0db1fa0 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -29,7 +29,6 @@ use crate::protocols::common::build_problem_report_msg; use crate::protocols::issuance::issuer::states::credential_sent::CredentialSentState; use crate::protocols::issuance::issuer::states::finished::FinishedState; use crate::protocols::issuance::issuer::states::initial::InitialIssuerState; -use crate::protocols::issuance::issuer::states::offer_sent::OfferSentState; use crate::protocols::issuance::issuer::states::offer_set::OfferSetState; use crate::protocols::issuance::issuer::states::proposal_received::ProposalReceivedState; use crate::protocols::issuance::issuer::states::requested_received::RequestReceivedState; @@ -40,7 +39,6 @@ pub enum IssuerFullState { Initial(InitialIssuerState), OfferSet(OfferSetState), ProposalReceived(ProposalReceivedState), - OfferSent(OfferSentState), RequestReceived(RequestReceivedState), CredentialSent(CredentialSentState), Finished(FinishedState), @@ -51,7 +49,6 @@ pub enum IssuerState { Initial, OfferSet, ProposalReceived, - OfferSent, RequestReceived, CredentialSent, Finished, @@ -65,7 +62,6 @@ impl Display for IssuerFullState { IssuerFullState::Initial(_) => f.write_str("Initial"), IssuerFullState::OfferSet(_) => f.write_str("OfferSet"), IssuerFullState::ProposalReceived(_) => f.write_str("ProposalReceived"), - IssuerFullState::OfferSent(_) => f.write_str("OfferSent"), IssuerFullState::RequestReceived(_) => f.write_str("RequestReceived"), IssuerFullState::CredentialSent(_) => f.write_str("CredentialSent"), IssuerFullState::Finished(_) => f.write_str("Finished"), @@ -200,7 +196,6 @@ impl IssuerSM { Some(offer_info) => offer_info.rev_reg_id.clone(), _ => None, }, - IssuerFullState::OfferSent(state) => state.rev_reg_id.clone(), IssuerFullState::RequestReceived(state) => state.rev_reg_id.clone(), IssuerFullState::CredentialSent(state) => { state @@ -261,7 +256,6 @@ impl IssuerSM { IssuerFullState::Initial(_) => IssuerState::Initial, IssuerFullState::ProposalReceived(_) => IssuerState::ProposalReceived, IssuerFullState::OfferSet(_) => IssuerState::OfferSet, - IssuerFullState::OfferSent(_) => IssuerState::OfferSent, IssuerFullState::RequestReceived(_) => IssuerState::RequestReceived, IssuerFullState::CredentialSent(_) => IssuerState::CredentialSent, IssuerFullState::Finished(ref status) => match status.status { @@ -317,7 +311,6 @@ impl IssuerSM { pub fn get_credential_offer_msg(&self) -> VcxResult { match &self.state { IssuerFullState::OfferSet(state) => Ok(state.offer.clone()), - IssuerFullState::OfferSent(state) => Ok(state.offer.clone()), _ => Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, format!("Can not get_credential_offer in current state {}.", self.state), @@ -325,25 +318,6 @@ impl IssuerSM { } } - pub fn mark_credential_offer_msg_sent(self) -> VcxResult { - let Self { - state, - source_id, - thread_id, - } = self; - let state = match state { - IssuerFullState::OfferSet(state) => IssuerFullState::OfferSent(state.into()), - IssuerFullState::OfferSent(state) => IssuerFullState::OfferSent(state), - _ => { - return Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - format!("Can not mark_as_offer_sent in current state {}.", state), - )) - } - }; - Ok(Self::step(source_id, thread_id, state)) - } - pub fn receive_proposal(self, proposal: ProposeCredential) -> VcxResult { verify_thread_id( &self.thread_id, @@ -355,7 +329,7 @@ impl IssuerSM { let state = IssuerFullState::ProposalReceived(ProposalReceivedState::new(proposal, None)); (state, thread_id) } - IssuerFullState::OfferSent(_) => { + IssuerFullState::OfferSet(_) => { let state = IssuerFullState::ProposalReceived(ProposalReceivedState::new(proposal, None)); (state, self.thread_id.clone()) } @@ -371,17 +345,18 @@ impl IssuerSM { }) } - pub async fn send_credential_offer(self, send_message: SendClosure) -> VcxResult { - Ok(match self.state { + #[deprecated] + pub async fn send_credential_offer(self, send_message: SendClosure) -> VcxResult<()> { + match self.state { IssuerFullState::OfferSet(ref state_data) => { let cred_offer_msg = state_data.offer.clone().into(); send_message(cred_offer_msg).await?; - self.mark_credential_offer_msg_sent()? } _ => { return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); } - }) + }; + Ok(()) } pub fn receive_request(self, request: RequestCredential) -> VcxResult { @@ -390,7 +365,7 @@ impl IssuerSM { &AriesMessage::CredentialIssuance(CredentialIssuance::RequestCredential(request.clone())), )?; let state = match self.state { - IssuerFullState::OfferSent(state_data) => IssuerFullState::RequestReceived((state_data, request).into()), + IssuerFullState::OfferSet(state_data) => IssuerFullState::RequestReceived((state_data, request).into()), s => { warn!("Unable to receive credential request in state {}", s); s @@ -399,7 +374,7 @@ impl IssuerSM { Ok(Self { state, ..self }) } - pub async fn send_credential( + pub async fn build_credential( self, anoncreds: &Arc, send_message: SendClosure, @@ -460,7 +435,7 @@ impl IssuerSM { pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { verify_thread_id(&self.thread_id, &AriesMessage::ReportProblem(problem_report.clone()))?; let state = match self.state { - IssuerFullState::OfferSent(state_data) => IssuerFullState::Finished((state_data, problem_report).into()), + IssuerFullState::OfferSet(state_data) => IssuerFullState::Finished((state_data, problem_report).into()), IssuerFullState::CredentialSent(state_data) => IssuerFullState::Finished((state_data).into()), s => { warn!("Unable to receive credential ack in state {}", s); diff --git a/aries_vcx/src/protocols/issuance/issuer/states/initial.rs b/aries_vcx/src/protocols/issuance/issuer/states/initial.rs index ef4972ebda..5bbeb1c1fb 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/initial.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/initial.rs @@ -1,16 +1,17 @@ use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; -use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_sent::OfferSentState}; +use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_set::OfferSetState}; #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] pub struct InitialIssuerState {} -impl From<(OfferInfo, OfferCredential)> for OfferSentState { +impl From<(OfferInfo, OfferCredential)> for OfferSetState { fn from((offer_info, offer): (OfferInfo, OfferCredential)) -> Self { trace!("SM is now in OfferSent state"); - OfferSentState { + OfferSetState { offer, - cred_data: offer_info.credential_json, + credential_json: offer_info.credential_json, + cred_def_id: offer_info.cred_def_id, rev_reg_id: offer_info.rev_reg_id, tails_file: offer_info.tails_file, } diff --git a/aries_vcx/src/protocols/issuance/issuer/states/mod.rs b/aries_vcx/src/protocols/issuance/issuer/states/mod.rs index b64b310427..a34e1a0b92 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/mod.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/mod.rs @@ -1,7 +1,6 @@ pub(super) mod credential_sent; pub(super) mod finished; pub(super) mod initial; -pub(super) mod offer_sent; pub(super) mod offer_set; pub(super) mod proposal_received; pub(super) mod requested_received; diff --git a/aries_vcx/src/protocols/issuance/issuer/states/offer_sent.rs b/aries_vcx/src/protocols/issuance/issuer/states/offer_sent.rs deleted file mode 100644 index cb51e5013c..0000000000 --- a/aries_vcx/src/protocols/issuance/issuer/states/offer_sent.rs +++ /dev/null @@ -1,59 +0,0 @@ -use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; -use messages::msg_fields::protocols::cred_issuance::request_credential::RequestCredential; -use messages::msg_fields::protocols::report_problem::ProblemReport; - -use crate::handlers::util::Status; -use crate::protocols::issuance::issuer::state_machine::RevocationInfoV1; -use crate::protocols::issuance::issuer::states::finished::FinishedState; -use crate::protocols::issuance::issuer::states::requested_received::RequestReceivedState; - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct OfferSentState { - pub offer: OfferCredential, - pub cred_data: String, - pub rev_reg_id: Option, - pub tails_file: Option, -} - -impl From for FinishedState { - fn from(state: OfferSentState) -> Self { - trace!("SM is now in Finished state"); - FinishedState { - cred_id: None, - revocation_info_v1: Some(RevocationInfoV1 { - cred_rev_id: None, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - }), - status: Status::Undefined, - } - } -} - -impl From<(OfferSentState, RequestCredential)> for RequestReceivedState { - fn from((state, request): (OfferSentState, RequestCredential)) -> Self { - trace!("SM is now in Request Received state"); - RequestReceivedState { - offer: state.offer, - cred_data: state.cred_data, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - request, - } - } -} - -impl From<(OfferSentState, ProblemReport)> for FinishedState { - fn from((state, err): (OfferSentState, ProblemReport)) -> Self { - trace!("SM is now in Finished state"); - FinishedState { - cred_id: None, - revocation_info_v1: Some(RevocationInfoV1 { - cred_rev_id: None, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - }), - status: Status::Failed(err), - } - } -} diff --git a/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs b/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs index e3d2c395a2..eed03591b2 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs @@ -1,5 +1,11 @@ -use crate::protocols::issuance::issuer::states::offer_sent::OfferSentState; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; +use messages::msg_fields::protocols::cred_issuance::request_credential::RequestCredential; +use messages::msg_fields::protocols::report_problem::ProblemReport; + +use crate::handlers::util::Status; +use crate::protocols::issuance::issuer::state_machine::RevocationInfoV1; +use crate::protocols::issuance::issuer::states::finished::FinishedState; +use crate::protocols::issuance::issuer::states::requested_received::RequestReceivedState; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct OfferSetState { @@ -28,14 +34,45 @@ impl OfferSetState { } } -impl From for OfferSentState { +impl From for FinishedState { fn from(state: OfferSetState) -> Self { - trace!("SM is now in OfferSent state"); - OfferSentState { + trace!("SM is now in Finished state"); + FinishedState { + cred_id: None, + revocation_info_v1: Some(RevocationInfoV1 { + cred_rev_id: None, + rev_reg_id: state.rev_reg_id, + tails_file: state.tails_file, + }), + status: Status::Undefined, + } + } +} + +impl From<(OfferSetState, RequestCredential)> for RequestReceivedState { + fn from((state, request): (OfferSetState, RequestCredential)) -> Self { + trace!("SM is now in Request Received state"); + RequestReceivedState { offer: state.offer, cred_data: state.credential_json, rev_reg_id: state.rev_reg_id, tails_file: state.tails_file, + request, + } + } +} + +impl From<(OfferSetState, ProblemReport)> for FinishedState { + fn from((state, err): (OfferSetState, ProblemReport)) -> Self { + trace!("SM is now in Finished state"); + FinishedState { + cred_id: None, + revocation_info_v1: Some(RevocationInfoV1 { + cred_rev_id: None, + rev_reg_id: state.rev_reg_id, + tails_file: state.tails_file, + }), + status: Status::Failed(err), } } } diff --git a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs index 84c0202072..2b1892d996 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs @@ -1,4 +1,4 @@ -use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_sent::OfferSentState}; +use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_set::OfferSetState}; use messages::msg_fields::protocols::cred_issuance::{ offer_credential::OfferCredential, propose_credential::ProposeCredential, }; @@ -18,12 +18,13 @@ impl ProposalReceivedState { } } -impl From<(OfferCredential, OfferInfo)> for OfferSentState { +impl From<(OfferCredential, OfferInfo)> for OfferSetState { fn from((offer, offer_info): (OfferCredential, OfferInfo)) -> Self { - trace!("SM is now in OfferSent state"); - OfferSentState { + trace!("SM is now in OfferSet state"); + OfferSetState { offer, - cred_data: offer_info.credential_json, + credential_json: offer_info.credential_json, + cred_def_id: offer_info.cred_def_id, rev_reg_id: offer_info.rev_reg_id, tails_file: offer_info.tails_file, } diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index c530a0b591..206c7ccd0f 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -1407,7 +1407,7 @@ mod tests { let mut issuer = accept_cred_proposal(&mut institution, &institution_to_consumer, rev_reg_id, Some(tails_dir)).await; decline_offer(&mut consumer, &consumer_to_institution, &mut holder).await; - assert_eq!(IssuerState::OfferSent, issuer.get_state()); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); tokio::time::sleep(Duration::from_millis(1000)).await; issuer_update_with_mediator(&mut issuer, &institution.agency_client, &institution_to_consumer) .await diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 901dd886cc..875da0dd6b 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -303,7 +303,7 @@ impl Faber { issuer_update_with_mediator(&mut self.issuer_credential, &self.agency_client, &self.connection) .await .unwrap(); - assert_eq!(IssuerState::OfferSent, self.issuer_credential.get_state()); + assert_eq!(IssuerState::OfferSet, self.issuer_credential.get_state()); } pub async fn send_credential(&mut self) { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index d42eda39f5..5f37e7adff 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -450,7 +450,7 @@ pub mod test_utils { ) .await .unwrap(); - assert_eq!(IssuerState::OfferSent, issuer.get_state()); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); tokio::time::sleep(Duration::from_millis(1000)).await; issuer } @@ -462,7 +462,7 @@ pub mod test_utils { rev_reg_id: Option, tails_dir: Option, ) { - assert_eq!(IssuerState::OfferSent, issuer.get_state()); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); issuer_update_with_mediator(issuer, &faber.agency_client, connection) .await .unwrap(); @@ -487,7 +487,7 @@ pub mod test_utils { ) .await .unwrap(); - assert_eq!(IssuerState::OfferSent, issuer.get_state()); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); tokio::time::sleep(Duration::from_millis(1000)).await; } @@ -556,7 +556,7 @@ pub mod test_utils { ) { info!("send_credential >>> getting offers"); let thread_id = issuer_credential.get_thread_id().unwrap(); - assert_eq!(IssuerState::OfferSent, issuer_credential.get_state()); + assert_eq!(IssuerState::OfferSet, issuer_credential.get_state()); assert!(!issuer_credential.is_revokable()); issuer_update_with_mediator(issuer_credential, &faber.agency_client, issuer_to_consumer) diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index cd8a939607..8fb869ee00 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -183,12 +183,6 @@ pub async fn build_credential_offer_msg_v2( ISSUER_CREDENTIAL_MAP.insert(credential_handle, credential) } -pub fn mark_credential_offer_msg_sent(handle: u32) -> LibvcxResult<()> { - let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; - credential.mark_credential_offer_msg_sent()?; - ISSUER_CREDENTIAL_MAP.insert(handle, credential) -} - pub fn get_credential_offer_msg(handle: u32) -> LibvcxResult { ISSUER_CREDENTIAL_MAP.get(handle, |credential| Ok(credential.get_credential_offer_msg()?)) } diff --git a/wrappers/vcx-napi-rs/src/api/issuer_credential.rs b/wrappers/vcx-napi-rs/src/api/issuer_credential.rs index 4e3fe57b7a..a0c8783635 100644 --- a/wrappers/vcx-napi-rs/src/api/issuer_credential.rs +++ b/wrappers/vcx-napi-rs/src/api/issuer_credential.rs @@ -108,11 +108,6 @@ async fn issuer_credential_send_offer_nonmediated(handle_credential: u32, handle Ok(()) } -#[napi] -fn issuer_credential_mark_offer_msg_sent(handle_credential: u32) -> napi::Result<()> { - issuer_credential::mark_credential_offer_msg_sent(handle_credential).map_err(to_napi_err) -} - #[napi] async fn issuer_credential_build_offer_msg_v2( credential_handle: u32, From 1d513b6ac249bc4955f4a6f36944f80a7e133b3b Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 12:50:29 +0200 Subject: [PATCH 03/40] Decouple revocation_notification from Issuer handler Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/issuer.rs | 30 --------------- .../handlers/revocation_notification/mod.rs | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index f13732e81d..3bb5c47d9f 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -176,36 +176,6 @@ impl Issuer { Ok(()) } - pub async fn send_revocation_notification( - &mut self, - ack_on: Vec, - comment: Option, - send_message: SendClosure, - ) -> VcxResult<()> { - // TODO: Check if actually revoked - if self.issuer_sm.is_revokable() { - // TODO: Store to allow checking not. status (sent, acked) - let config = SenderConfigBuilder::default() - .rev_reg_id(self.get_rev_reg_id()?) - .cred_rev_id(self.get_rev_id()?) - .comment(comment) - .ack_on(ack_on) - .build()?; - RevocationNotificationSender::build() - .send_revocation_notification(config, send_message) - .await?; - Ok(()) - } else { - Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - format!( - "Can't send revocation notification in state {:?}, credential is not revokable", - self.issuer_sm.get_state() - ), - )) - } - } - pub fn get_state(&self) -> IssuerState { self.issuer_sm.get_state() } diff --git a/aries_vcx/src/handlers/revocation_notification/mod.rs b/aries_vcx/src/handlers/revocation_notification/mod.rs index 19e5c09918..3ade2da98c 100644 --- a/aries_vcx/src/handlers/revocation_notification/mod.rs +++ b/aries_vcx/src/handlers/revocation_notification/mod.rs @@ -1,6 +1,43 @@ +use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; +use crate::handlers::issuance::issuer::Issuer; +use crate::handlers::revocation_notification::sender::RevocationNotificationSender; +use crate::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder; +use crate::protocols::SendClosure; +use messages::decorators::please_ack::AckOn; + pub mod receiver; pub mod sender; +pub async fn send_revocation_notification( + issuer: &Issuer, + ack_on: Vec, + comment: Option, + send_message: SendClosure, +) -> VcxResult<()> { + // TODO: Check if actually revoked + if issuer.is_revokable() { + // TODO: Store to allow checking not. status (sent, acked) + let config = SenderConfigBuilder::default() + .rev_reg_id(issuer.get_rev_reg_id()?) + .cred_rev_id(issuer.get_rev_id()?) + .comment(comment) + .ack_on(ack_on) + .build()?; + RevocationNotificationSender::build() + .send_revocation_notification(config, send_message) + .await?; + Ok(()) + } else { + Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + format!( + "Can't send revocation notification in state {:?}, credential is not revokable", + issuer.get_state() + ), + )) + } +} + pub mod test_utils { use agency_client::agency_client::AgencyClient; use messages::msg_fields::protocols::revocation::ack::AckRevoke; From 78c5aaac5e988cad67620dcd5eabb9202858ab53 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 13:45:48 +0200 Subject: [PATCH 04/40] Replace Issuer state CredentialSent by CredentialSet Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/issuer.rs | 3 +- aries_vcx/src/handlers/issuance/issuer.rs | 13 +-- .../src/handlers/issuance/mediated_issuer.rs | 2 +- aries_vcx/src/handlers/mod.rs | 2 +- .../issuance/issuer/state_machine.rs | 90 +++++++++++-------- .../{credential_sent.rs => credential_set.rs} | 8 +- .../protocols/issuance/issuer/states/mod.rs | 2 +- .../issuer/states/requested_received.rs | 16 +--- aries_vcx/tests/utils/devsetup_faber.rs | 16 ++-- aries_vcx/tests/utils/scenarios.rs | 13 ++- .../api_vcx/api_handle/issuer_credential.rs | 12 ++- 11 files changed, 91 insertions(+), 86 deletions(-) rename aries_vcx/src/protocols/issuance/issuer/states/{credential_sent.rs => credential_set.rs} (65%) diff --git a/agents/rust/aries-vcx-agent/src/services/issuer.rs b/agents/rust/aries-vcx-agent/src/services/issuer.rs index f997f75c9b..5ff9566104 100644 --- a/agents/rust/aries-vcx-agent/src/services/issuer.rs +++ b/agents/rust/aries-vcx-agent/src/services/issuer.rs @@ -125,8 +125,9 @@ impl ServiceCredentialsIssuer { }); issuer - .send_credential(&self.profile.inject_anoncreds(), send_closure) + .build_credential(&self.profile.inject_anoncreds()) .await?; + issuer.send_credential(send_closure).await; self.creds_issuer .insert(&issuer.get_thread_id()?, IssuerWrapper::new(issuer, &connection_id))?; Ok(()) diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index 3bb5c47d9f..48b614da37 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -167,15 +167,16 @@ impl Issuer { Ok(()) } - pub async fn send_credential( - &mut self, - anoncreds: &Arc, - send_message: SendClosure, - ) -> VcxResult<()> { - self.issuer_sm = self.issuer_sm.clone().build_credential(anoncreds, send_message).await?; + pub async fn build_credential(&mut self, anoncreds: &Arc) -> VcxResult<()> { + self.issuer_sm = self.issuer_sm.clone().build_credential(anoncreds).await?; Ok(()) } + #[deprecated] + pub async fn send_credential(&mut self, send_message: SendClosure) -> VcxResult<()> { + self.issuer_sm.clone().send_credential(send_message).await + } + pub fn get_state(&self) -> IssuerState { self.issuer_sm.get_state() } diff --git a/aries_vcx/src/handlers/issuance/mediated_issuer.rs b/aries_vcx/src/handlers/issuance/mediated_issuer.rs index 167e6a5a13..f4a3f7be84 100644 --- a/aries_vcx/src/handlers/issuance/mediated_issuer.rs +++ b/aries_vcx/src/handlers/issuance/mediated_issuer.rs @@ -44,7 +44,7 @@ pub fn issuer_find_message_to_handle( } _ => {} }, - IssuerState::CredentialSent => match &message { + IssuerState::CredentialSet => match &message { AriesMessage::CredentialIssuance(CredentialIssuance::Ack(msg)) => { if matches_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); diff --git a/aries_vcx/src/handlers/mod.rs b/aries_vcx/src/handlers/mod.rs index a32dc58bd8..dfd143a0eb 100644 --- a/aries_vcx/src/handlers/mod.rs +++ b/aries_vcx/src/handlers/mod.rs @@ -56,7 +56,7 @@ impl From for u32 { IssuerState::ProposalReceived => 1, IssuerState::OfferSet => 2, IssuerState::RequestReceived => 4, - IssuerState::CredentialSent => 5, + IssuerState::CredentialSet => 5, IssuerState::Finished => 6, IssuerState::Failed => 7, } diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 2fb0db1fa0..28c155a55c 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -26,7 +26,7 @@ use crate::common::credentials::encoding::encode_attributes; use crate::common::credentials::is_cred_revoked; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; use crate::protocols::common::build_problem_report_msg; -use crate::protocols::issuance::issuer::states::credential_sent::CredentialSentState; +use crate::protocols::issuance::issuer::states::credential_set::CredentialSetState; use crate::protocols::issuance::issuer::states::finished::FinishedState; use crate::protocols::issuance::issuer::states::initial::InitialIssuerState; use crate::protocols::issuance::issuer::states::offer_set::OfferSetState; @@ -40,7 +40,7 @@ pub enum IssuerFullState { OfferSet(OfferSetState), ProposalReceived(ProposalReceivedState), RequestReceived(RequestReceivedState), - CredentialSent(CredentialSentState), + CredentialSet(CredentialSetState), Finished(FinishedState), } @@ -50,7 +50,7 @@ pub enum IssuerState { OfferSet, ProposalReceived, RequestReceived, - CredentialSent, + CredentialSet, Finished, Failed, } @@ -63,7 +63,7 @@ impl Display for IssuerFullState { IssuerFullState::OfferSet(_) => f.write_str("OfferSet"), IssuerFullState::ProposalReceived(_) => f.write_str("ProposalReceived"), IssuerFullState::RequestReceived(_) => f.write_str("RequestReceived"), - IssuerFullState::CredentialSent(_) => f.write_str("CredentialSent"), + IssuerFullState::CredentialSet(_) => f.write_str("CredentialSet"), IssuerFullState::Finished(_) => f.write_str("Finished"), } } @@ -89,7 +89,7 @@ pub struct IssuerSM { pub(crate) state: IssuerFullState, } -fn build_credential_message(libindy_credential: String) -> VcxResult { +fn build_credential_message(libindy_credential: String, thread_id: String) -> IssueCredential { let id = Uuid::new_v4().to_string(); let content = IssueCredentialContent::new(vec![make_attach_from_str!( @@ -97,12 +97,10 @@ fn build_credential_message(libindy_credential: String) -> VcxResult Option { match &self.state { - IssuerFullState::CredentialSent(state) => state.revocation_info_v1.clone(), + IssuerFullState::CredentialSet(state) => state.revocation_info_v1.clone(), IssuerFullState::Finished(state) => state.revocation_info_v1.clone(), _ => None, } @@ -173,7 +171,7 @@ impl IssuerSM { "No revocation info found - is this credential revokable?", ); let rev_id = match &self.state { - IssuerFullState::CredentialSent(state) => state.revocation_info_v1.as_ref().ok_or(err)?.cred_rev_id.clone(), + IssuerFullState::CredentialSet(state) => state.revocation_info_v1.as_ref().ok_or(err)?.cred_rev_id.clone(), IssuerFullState::Finished(state) => state.revocation_info_v1.as_ref().ok_or(err)?.cred_rev_id.clone(), _ => None, }; @@ -197,7 +195,7 @@ impl IssuerSM { _ => None, }, IssuerFullState::RequestReceived(state) => state.rev_reg_id.clone(), - IssuerFullState::CredentialSent(state) => { + IssuerFullState::CredentialSet(state) => { state .revocation_info_v1 .clone() @@ -232,7 +230,7 @@ impl IssuerSM { } } match &self.state { - IssuerFullState::CredentialSent(state) => _is_revokable(&state.revocation_info_v1), + IssuerFullState::CredentialSet(state) => _is_revokable(&state.revocation_info_v1), IssuerFullState::Finished(state) => _is_revokable(&state.revocation_info_v1), _ => false, } @@ -257,7 +255,7 @@ impl IssuerSM { IssuerFullState::ProposalReceived(_) => IssuerState::ProposalReceived, IssuerFullState::OfferSet(_) => IssuerState::OfferSet, IssuerFullState::RequestReceived(_) => IssuerState::RequestReceived, - IssuerFullState::CredentialSent(_) => IssuerState::CredentialSent, + IssuerFullState::CredentialSet(_) => IssuerState::CredentialSet, IssuerFullState::Finished(ref status) => match status.status { Status::Success => IssuerState::Finished, _ => IssuerState::Failed, @@ -374,38 +372,38 @@ impl IssuerSM { Ok(Self { state, ..self }) } - pub async fn build_credential( - self, - anoncreds: &Arc, - send_message: SendClosure, - ) -> VcxResult { + pub async fn build_credential(self, anoncreds: &Arc) -> VcxResult { let state = match self.state { IssuerFullState::RequestReceived(state_data) => { - match _create_credential( + match create_credential( anoncreds, &state_data.request, &state_data.rev_reg_id, &state_data.tails_file, &state_data.offer, &state_data.cred_data, - &self.thread_id, + self.thread_id.clone(), ) .await { - Ok((mut credential_msg, cred_rev_id)) => { - credential_msg.decorators.thread.thid = self.thread_id.clone(); - credential_msg.decorators.please_ack = Some(PleaseAck::new(vec![])); // ask_for_ack sets this to an empty vec - - send_message(credential_msg.into()).await?; - IssuerFullState::CredentialSent((state_data, cred_rev_id).into()) + Ok((mut msg_issue_credential, cred_rev_id)) => { + // todo: have constructor for this + IssuerFullState::CredentialSet(CredentialSetState { + msg_issue_credential, + revocation_info_v1: Some(RevocationInfoV1 { + cred_rev_id, + rev_reg_id: state_data.rev_reg_id, + tails_file: state_data.tails_file, + }), + }) } + // todo: dont' transition, throw error, add to_failed transition() api which SM consumer can call Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!( "Failed to create credential, sending problem report {:?}", problem_report ); - send_message(problem_report.clone().into()).await?; IssuerFullState::Finished((state_data, problem_report).into()) } } @@ -417,13 +415,31 @@ impl IssuerSM { Ok(Self { state, ..self }) } + #[deprecated] + pub async fn send_credential(self, send_message: SendClosure) -> VcxResult<()> { + match self.state { + IssuerFullState::CredentialSet(ref state_data) => { + let cred_offer_msg = state_data.msg_issue_credential.clone().into(); + // todo: update timing + // let mut timing = Timing::default(); + // timing.out_time = Some(Utc::now()); + // decorators.timing = Some(timing); + send_message(cred_offer_msg).await?; + } + _ => { + return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); + } + }; + Ok(()) + } + pub fn receive_ack(self, ack: AckCredential) -> VcxResult { verify_thread_id( &self.thread_id, &AriesMessage::CredentialIssuance(CredentialIssuance::Ack(ack.clone())), )?; let state = match self.state { - IssuerFullState::CredentialSent(state_data) => IssuerFullState::Finished(state_data.into()), + IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(state_data.into()), s => { warn!("Unable to receive credential ack in state {}", s); s @@ -436,7 +452,7 @@ impl IssuerSM { verify_thread_id(&self.thread_id, &AriesMessage::ReportProblem(problem_report.clone()))?; let state = match self.state { IssuerFullState::OfferSet(state_data) => IssuerFullState::Finished((state_data, problem_report).into()), - IssuerFullState::CredentialSent(state_data) => IssuerFullState::Finished((state_data).into()), + IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished((state_data).into()), s => { warn!("Unable to receive credential ack in state {}", s); s @@ -463,19 +479,19 @@ impl IssuerSM { } } -async fn _create_credential( +async fn create_credential( anoncreds: &Arc, request: &RequestCredential, rev_reg_id: &Option, tails_file: &Option, offer: &OfferCredential, cred_data: &str, - thread_id: &str, + thread_id: String, ) -> VcxResult<(IssueCredential, Option)> { let offer = get_attach_as_string!(&offer.content.offers_attach); trace!("Issuer::_create_credential >>> request: {:?}, rev_reg_id: {:?}, tails_file: {:?}, offer: {}, cred_data: {}, thread_id: {}", request, rev_reg_id, tails_file, offer, cred_data, thread_id); - if !matches_opt_thread_id!(request, thread_id) { + if !matches_opt_thread_id!(request, thread_id.as_str()) { return Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidJson, format!("Cannot handle credential request: thread id does not match"), @@ -488,6 +504,6 @@ async fn _create_credential( let (libindy_credential, cred_rev_id, _) = anoncreds .issuer_create_credential(&offer, &request, &cred_data, rev_reg_id.clone(), tails_file.clone()) .await?; - let credential = build_credential_message(libindy_credential)?; - Ok((credential, cred_rev_id)) + let msg_issue_credential = build_credential_message(libindy_credential, thread_id); + Ok((msg_issue_credential, cred_rev_id)) } diff --git a/aries_vcx/src/protocols/issuance/issuer/states/credential_sent.rs b/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs similarity index 65% rename from aries_vcx/src/protocols/issuance/issuer/states/credential_sent.rs rename to aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs index c204495fbc..c4326d47fc 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/credential_sent.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs @@ -1,14 +1,16 @@ use crate::handlers::util::Status; use crate::protocols::issuance::issuer::state_machine::RevocationInfoV1; use crate::protocols::issuance::issuer::states::finished::FinishedState; +use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct CredentialSentState { +pub struct CredentialSetState { pub revocation_info_v1: Option, + pub msg_issue_credential: IssueCredential, } -impl From for FinishedState { - fn from(state: CredentialSentState) -> Self { +impl From for FinishedState { + fn from(state: CredentialSetState) -> Self { trace!("SM is now in Finished state"); FinishedState { cred_id: None, diff --git a/aries_vcx/src/protocols/issuance/issuer/states/mod.rs b/aries_vcx/src/protocols/issuance/issuer/states/mod.rs index a34e1a0b92..bea3523aa2 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/mod.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/mod.rs @@ -1,4 +1,4 @@ -pub(super) mod credential_sent; +pub(super) mod credential_set; pub(super) mod finished; pub(super) mod initial; pub(super) mod offer_set; diff --git a/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs index 9ceb593e8b..46189408db 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs @@ -1,7 +1,8 @@ use crate::handlers::util::Status; use crate::protocols::issuance::issuer::state_machine::RevocationInfoV1; -use crate::protocols::issuance::issuer::states::credential_sent::CredentialSentState; +use crate::protocols::issuance::issuer::states::credential_set::CredentialSetState; use crate::protocols::issuance::issuer::states::finished::FinishedState; +use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; use messages::msg_fields::protocols::cred_issuance::request_credential::RequestCredential; use messages::msg_fields::protocols::report_problem::ProblemReport; @@ -16,19 +17,6 @@ pub struct RequestReceivedState { pub request: RequestCredential, } -impl From<(RequestReceivedState, Option)> for CredentialSentState { - fn from((state, cred_rev_id): (RequestReceivedState, Option)) -> Self { - trace!("SM is now in CredentialSent state"); - CredentialSentState { - revocation_info_v1: Some(RevocationInfoV1 { - cred_rev_id, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - }), - } - } -} - impl From<(RequestReceivedState, Option)> for FinishedState { fn from((state, cred_rev_id): (RequestReceivedState, Option)) -> Self { trace!("SM is now in Finished state"); diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 875da0dd6b..0a42834313 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -313,19 +313,19 @@ impl Faber { assert_eq!(IssuerState::RequestReceived, self.issuer_credential.get_state()); self.issuer_credential - .send_credential( - &self.profile.inject_anoncreds(), - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) + .build_credential(&self.profile.inject_anoncreds()) + .await + .unwrap(); + let send_closure = self + .connection + .send_message_closure(self.profile.inject_wallet()) .await .unwrap(); + self.issuer_credential.send_credential(send_closure).await; issuer_update_with_mediator(&mut self.issuer_credential, &self.agency_client, &self.connection) .await .unwrap(); - assert_eq!(IssuerState::CredentialSent, self.issuer_credential.get_state()); + assert_eq!(IssuerState::CredentialSet, self.issuer_credential.get_state()); } pub async fn request_presentation(&mut self) { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 5f37e7adff..82ce460481 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -568,15 +568,14 @@ pub mod test_utils { info!("send_credential >>> sending credential"); issuer_credential - .send_credential( - &faber.profile.inject_anoncreds(), - issuer_to_consumer - .send_message_closure(faber.profile.inject_wallet()) - .await - .unwrap(), - ) + .build_credential(&faber.profile.inject_anoncreds()) + .await + .unwrap(); + let send_closure = issuer_to_consumer + .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); + issuer_credential.send_credential(send_closure).await; tokio::time::sleep(Duration::from_millis(1000)).await; assert_eq!(thread_id, issuer_credential.get_thread_id().unwrap()); diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index 8fb869ee00..49c895940c 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -1,3 +1,4 @@ +use libc::send; use aries_vcx::handlers::util::OfferInfo; use aries_vcx::messages::AriesMessage; use aries_vcx::protocols::SendClosure; @@ -211,12 +212,9 @@ pub async fn send_credential_offer_nonmediated(credential_handle: u32, connectio pub async fn send_credential(handle: u32, connection_handle: u32) -> LibvcxResult { let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; - credential - .send_credential( - &get_main_anoncreds()?, - mediated_connection::send_message_closure(connection_handle).await?, - ) - .await?; + credential.build_credential(&get_main_anoncreds()?).await?; + let send_closure = mediated_connection::send_message_closure(connection_handle).await?; + credential.send_credential(send_closure).await?; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) @@ -230,7 +228,7 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - credential.send_credential(&get_main_anoncreds()?, send_message).await?; + credential.build_credential(&get_main_anoncreds()?, send_message).await?; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) From bfe311ed0fd07952af627fc983a27b0eb6d992df Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 13:50:12 +0200 Subject: [PATCH 05/40] Reformat Signed-off-by: Patrik Stas --- agents/rust/aries-vcx-agent/src/services/issuer.rs | 4 +--- libvcx_core/src/api_vcx/api_handle/issuer_credential.rs | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/issuer.rs b/agents/rust/aries-vcx-agent/src/services/issuer.rs index 5ff9566104..f6cd0037e9 100644 --- a/agents/rust/aries-vcx-agent/src/services/issuer.rs +++ b/agents/rust/aries-vcx-agent/src/services/issuer.rs @@ -124,9 +124,7 @@ impl ServiceCredentialsIssuer { Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) }); - issuer - .build_credential(&self.profile.inject_anoncreds()) - .await?; + issuer.build_credential(&self.profile.inject_anoncreds()).await?; issuer.send_credential(send_closure).await; self.creds_issuer .insert(&issuer.get_thread_id()?, IssuerWrapper::new(issuer, &connection_id))?; diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index 49c895940c..b04bde5d2e 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -1,7 +1,7 @@ -use libc::send; use aries_vcx::handlers::util::OfferInfo; use aries_vcx::messages::AriesMessage; use aries_vcx::protocols::SendClosure; +use libc::send; use serde_json; use aries_vcx::handlers::issuance::issuer::Issuer; @@ -228,7 +228,9 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - credential.build_credential(&get_main_anoncreds()?, send_message).await?; + credential + .build_credential(&get_main_anoncreds()?, send_message) + .await?; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) From b7e25b22221b8117921b9bf4e5c01770e56a01fb Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 13:52:42 +0200 Subject: [PATCH 06/40] Fix libvcx_core Signed-off-by: Patrik Stas --- libvcx_core/src/api_vcx/api_handle/issuer_credential.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index b04bde5d2e..d4a26b3eaf 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -224,13 +224,12 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; let con = connection::get_cloned_generic_connection(&connection_handle)?; let wallet = get_main_wallet()?; - let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - credential - .build_credential(&get_main_anoncreds()?, send_message) + .build_credential(&get_main_anoncreds()?) .await?; + credential.send_credential(send_message).await; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) From f477cb62cee3a828330b6607aa5fd91159be4bd2 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 13:55:54 +0200 Subject: [PATCH 07/40] Sync up napi Signed-off-by: Patrik Stas --- wrappers/vcx-napi-rs/index.d.ts | 1 - wrappers/vcx-napi-rs/index.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/wrappers/vcx-napi-rs/index.d.ts b/wrappers/vcx-napi-rs/index.d.ts index ab6cdc8d90..97496b9c71 100644 --- a/wrappers/vcx-napi-rs/index.d.ts +++ b/wrappers/vcx-napi-rs/index.d.ts @@ -85,7 +85,6 @@ export function issuerCredentialSendCredential(handleCredential: number, handleC export function issuerCredentialSendCredentialNonmediated(handleCredential: number, handleConnection: number): Promise export function issuerCredentialSendOfferV2(handleCredential: number, handleConnection: number): Promise export function issuerCredentialSendOfferNonmediated(handleCredential: number, handleConnection: number): Promise -export function issuerCredentialMarkOfferMsgSent(handleCredential: number): void export function issuerCredentialBuildOfferMsgV2(credentialHandle: number, credDefHandle: number, revRegHandle: number, credentialJson: string, comment?: string | undefined | null): Promise export function issuerCredentialGetOfferMsg(credentialHandle: number): string export function issuerCredentialRelease(credentialHandle: number): void diff --git a/wrappers/vcx-napi-rs/index.js b/wrappers/vcx-napi-rs/index.js index 9f50de75ce..3f9ec9a979 100644 --- a/wrappers/vcx-napi-rs/index.js +++ b/wrappers/vcx-napi-rs/index.js @@ -252,7 +252,7 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { updateWebhookUrl, createAgencyClientForMainWallet, provisionCloudAgent, messagesUpdateStatus, generatePublicInvitation, connectionCreateInviter, connectionCreateInvitee, connectionGetThreadId, connectionGetPairwiseInfo, connectionGetRemoteDid, connectionGetRemoteVk, connectionGetState, connectionGetInvitation, connectionProcessInvite, connectionProcessRequest, connectionProcessResponse, connectionProcessAck, connectionProcessProblemReport, connectionSendResponse, connectionSendRequest, connectionSendAck, connectionSendGenericMessage, connectionSendAriesMessage, connectionCreateInvite, connectionSerialize, connectionDeserialize, connectionRelease, credentialCreateWithOffer, credentialRelease, credentialSendRequest, credentialDeclineOffer, credentialSerialize, credentialDeserialize, v2CredentialUpdateStateWithMessage, v2CredentialUpdateState, credentialGetState, credentialGetOffers, credentialGetAttributes, credentialGetAttachment, credentialGetTailsLocation, credentialGetTailsHash, credentialGetRevRegId, credentialGetThreadId, credentialdefCreateV2, credentialdefPublish, credentialdefDeserialize, credentialdefRelease, credentialdefSerialize, credentialdefGetCredDefId, credentialdefUpdateState, credentialdefGetState, disclosedProofCreateWithRequest, disclosedProofRelease, disclosedProofSendProof, disclosedProofRejectProof, disclosedProofGetProofMsg, disclosedProofSerialize, disclosedProofDeserialize, v2DisclosedProofUpdateState, v2DisclosedProofUpdateStateWithMessage, disclosedProofGetState, disclosedProofGetRequests, disclosedProofRetrieveCredentials, disclosedProofGetProofRequestAttachment, disclosedProofGenerateProof, disclosedProofDeclinePresentationRequest, disclosedProofGetThreadId, issuerCredentialDeserialize, issuerCredentialSerialize, issuerCredentialUpdateStateV2, issuerCredentialUpdateStateWithMessageV2, issuerCredentialUpdateStateWithMessageNonmediated, issuerCredentialGetState, issuerCredentialGetRevRegId, issuerCredentialCreate, issuerCredentialRevokeLocal, issuerCredentialIsRevokable, issuerCredentialGetRevocationId, issuerCredentialSendCredential, issuerCredentialSendCredentialNonmediated, issuerCredentialSendOfferV2, issuerCredentialSendOfferNonmediated, issuerCredentialMarkOfferMsgSent, issuerCredentialBuildOfferMsgV2, issuerCredentialGetOfferMsg, issuerCredentialRelease, issuerCredentialGetThreadId, getLedgerAuthorAgreement, setActiveTxnAuthorAgreementMeta, createService, createServiceV2, getServiceFromLedger, getAttrFromLedger, clearAttrFromLedger, writeEndorserDid, getVerkeyFromLedger, getLedgerTxn, initDefaultLogger, mediatedConnectionGeneratePublicInvite, mediatedConnectionGetPwDid, mediatedConnectionGetTheirPwDid, mediatedConnectionGetThreadId, mediatedConnectionGetState, mediatedConnectionGetSourceId, mediatedConnectionCreate, mediatedConnectionCreateWithInvite, mediatedConnectionSendMessage, mediatedConnectionCreateWithConnectionRequestV2, mediatedConnectionSendHandshakeReuse, mediatedConnectionUpdateStateWithMessage, mediatedConnectionHandleMessage, mediatedConnectionUpdateState, mediatedConnectionDeleteConnection, mediatedConnectionConnect, mediatedConnectionSerialize, mediatedConnectionDeserialize, mediatedConnectionRelease, mediatedConnectionInviteDetails, mediatedConnectionSendPing, mediatedConnectionSendDiscoveryFeatures, mediatedConnectionInfo, mediatedConnectionMessagesDownload, mediatedConnectionSignData, mediatedConnectionVerifySignature, outOfBandBuildHandshakeReuseAcceptedMsg, outOfBandReceiverCreate, outOfBandReceiverExtractMessage, outOfBandReceiverConnectionExists, outOfBandReceiverNonmediatedConnectionExists, outOfBandReceiverBuildConnection, outOfBandReceiverGetThreadId, outOfBandReceiverSerialize, outOfBandReceiverDeserialize, outOfBandReceiverRelease, outOfBandSenderCreate, outOfBandSenderAppendMessage, outOfBandSenderAppendService, outOfBandSenderAppendServiceDid, outOfBandSenderToMessage, outOfBandSenderGetThreadId, outOfBandSenderSerialize, outOfBandSenderDeserialize, outOfBandSenderRelease, openMainPool, closeMainPool, proofCreate, proofGetPresentationMsg, proofGetPresentationRequestAttachment, proofGetPresentationAttachment, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetVerificationStatus, proofGetThreadId, markPresentationRequestMsgSent, revocationRegistryCreate, revocationRegistryPublish, revocationRegistryPublishRevocations, revocationRegistryGetRevRegId, revocationRegistryGetTailsHash, revocationRegistrySerialize, revocationRegistryDeserialize, revocationRegistryRelease, schemaGetAttributes, schemaPrepareForEndorser, schemaCreate, schemaGetSchemaId, schemaDeserialize, schemaSerialize, schemaRelease, schemaUpdateState, schemaGetState, enableMocks, trustpingBuildResponseMsg, trustpingBuildPing, shutdown, getVersion, walletOpenAsMain, walletCreateMain, walletCloseMain, vcxInitIssuerConfig, configureIssuerWallet, unpack, createAndStoreDid, walletImport, walletExport, getVerkeyFromWallet, rotateVerkey, rotateVerkeyStart, rotateVerkeyApply } = nativeBinding +const { updateWebhookUrl, createAgencyClientForMainWallet, provisionCloudAgent, messagesUpdateStatus, generatePublicInvitation, connectionCreateInviter, connectionCreateInvitee, connectionGetThreadId, connectionGetPairwiseInfo, connectionGetRemoteDid, connectionGetRemoteVk, connectionGetState, connectionGetInvitation, connectionProcessInvite, connectionProcessRequest, connectionProcessResponse, connectionProcessAck, connectionProcessProblemReport, connectionSendResponse, connectionSendRequest, connectionSendAck, connectionSendGenericMessage, connectionSendAriesMessage, connectionCreateInvite, connectionSerialize, connectionDeserialize, connectionRelease, credentialCreateWithOffer, credentialRelease, credentialSendRequest, credentialDeclineOffer, credentialSerialize, credentialDeserialize, v2CredentialUpdateStateWithMessage, v2CredentialUpdateState, credentialGetState, credentialGetOffers, credentialGetAttributes, credentialGetAttachment, credentialGetTailsLocation, credentialGetTailsHash, credentialGetRevRegId, credentialGetThreadId, credentialdefCreateV2, credentialdefPublish, credentialdefDeserialize, credentialdefRelease, credentialdefSerialize, credentialdefGetCredDefId, credentialdefUpdateState, credentialdefGetState, disclosedProofCreateWithRequest, disclosedProofRelease, disclosedProofSendProof, disclosedProofRejectProof, disclosedProofGetProofMsg, disclosedProofSerialize, disclosedProofDeserialize, v2DisclosedProofUpdateState, v2DisclosedProofUpdateStateWithMessage, disclosedProofGetState, disclosedProofGetRequests, disclosedProofRetrieveCredentials, disclosedProofGetProofRequestAttachment, disclosedProofGenerateProof, disclosedProofDeclinePresentationRequest, disclosedProofGetThreadId, issuerCredentialDeserialize, issuerCredentialSerialize, issuerCredentialUpdateStateV2, issuerCredentialUpdateStateWithMessageV2, issuerCredentialUpdateStateWithMessageNonmediated, issuerCredentialGetState, issuerCredentialGetRevRegId, issuerCredentialCreate, issuerCredentialRevokeLocal, issuerCredentialIsRevokable, issuerCredentialGetRevocationId, issuerCredentialSendCredential, issuerCredentialSendCredentialNonmediated, issuerCredentialSendOfferV2, issuerCredentialSendOfferNonmediated, issuerCredentialBuildOfferMsgV2, issuerCredentialGetOfferMsg, issuerCredentialRelease, issuerCredentialGetThreadId, getLedgerAuthorAgreement, setActiveTxnAuthorAgreementMeta, createService, createServiceV2, getServiceFromLedger, getAttrFromLedger, clearAttrFromLedger, writeEndorserDid, getVerkeyFromLedger, getLedgerTxn, initDefaultLogger, mediatedConnectionGeneratePublicInvite, mediatedConnectionGetPwDid, mediatedConnectionGetTheirPwDid, mediatedConnectionGetThreadId, mediatedConnectionGetState, mediatedConnectionGetSourceId, mediatedConnectionCreate, mediatedConnectionCreateWithInvite, mediatedConnectionSendMessage, mediatedConnectionCreateWithConnectionRequestV2, mediatedConnectionSendHandshakeReuse, mediatedConnectionUpdateStateWithMessage, mediatedConnectionHandleMessage, mediatedConnectionUpdateState, mediatedConnectionDeleteConnection, mediatedConnectionConnect, mediatedConnectionSerialize, mediatedConnectionDeserialize, mediatedConnectionRelease, mediatedConnectionInviteDetails, mediatedConnectionSendPing, mediatedConnectionSendDiscoveryFeatures, mediatedConnectionInfo, mediatedConnectionMessagesDownload, mediatedConnectionSignData, mediatedConnectionVerifySignature, outOfBandBuildHandshakeReuseAcceptedMsg, outOfBandReceiverCreate, outOfBandReceiverExtractMessage, outOfBandReceiverConnectionExists, outOfBandReceiverNonmediatedConnectionExists, outOfBandReceiverBuildConnection, outOfBandReceiverGetThreadId, outOfBandReceiverSerialize, outOfBandReceiverDeserialize, outOfBandReceiverRelease, outOfBandSenderCreate, outOfBandSenderAppendMessage, outOfBandSenderAppendService, outOfBandSenderAppendServiceDid, outOfBandSenderToMessage, outOfBandSenderGetThreadId, outOfBandSenderSerialize, outOfBandSenderDeserialize, outOfBandSenderRelease, openMainPool, closeMainPool, proofCreate, proofGetPresentationMsg, proofGetPresentationRequestAttachment, proofGetPresentationAttachment, proofRelease, proofSendRequest, proofSendRequestNonmediated, proofGetRequestMsg, proofSerialize, proofDeserialize, v2ProofUpdateState, v2ProofUpdateStateWithMessage, proofUpdateStateWithMessageNonmediated, proofGetState, proofGetVerificationStatus, proofGetThreadId, markPresentationRequestMsgSent, revocationRegistryCreate, revocationRegistryPublish, revocationRegistryPublishRevocations, revocationRegistryGetRevRegId, revocationRegistryGetTailsHash, revocationRegistrySerialize, revocationRegistryDeserialize, revocationRegistryRelease, schemaGetAttributes, schemaPrepareForEndorser, schemaCreate, schemaGetSchemaId, schemaDeserialize, schemaSerialize, schemaRelease, schemaUpdateState, schemaGetState, enableMocks, trustpingBuildResponseMsg, trustpingBuildPing, shutdown, getVersion, walletOpenAsMain, walletCreateMain, walletCloseMain, vcxInitIssuerConfig, configureIssuerWallet, unpack, createAndStoreDid, walletImport, walletExport, getVerkeyFromWallet, rotateVerkey, rotateVerkeyStart, rotateVerkeyApply } = nativeBinding module.exports.updateWebhookUrl = updateWebhookUrl module.exports.createAgencyClientForMainWallet = createAgencyClientForMainWallet @@ -336,7 +336,6 @@ module.exports.issuerCredentialSendCredential = issuerCredentialSendCredential module.exports.issuerCredentialSendCredentialNonmediated = issuerCredentialSendCredentialNonmediated module.exports.issuerCredentialSendOfferV2 = issuerCredentialSendOfferV2 module.exports.issuerCredentialSendOfferNonmediated = issuerCredentialSendOfferNonmediated -module.exports.issuerCredentialMarkOfferMsgSent = issuerCredentialMarkOfferMsgSent module.exports.issuerCredentialBuildOfferMsgV2 = issuerCredentialBuildOfferMsgV2 module.exports.issuerCredentialGetOfferMsg = issuerCredentialGetOfferMsg module.exports.issuerCredentialRelease = issuerCredentialRelease From 963f87d1ddfef6d35930e5c74a4d1cee6a74d420 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 14:17:09 +0200 Subject: [PATCH 08/40] post-rebase conflict resolution Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 5 +++-- aries_vcx/src/protocols/issuance/issuer/state_machine.rs | 5 ++++- .../protocols/proof_presentation/verifier/state_machine.rs | 2 +- libvcx_core/src/api_vcx/api_handle/issuer_credential.rs | 4 +--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 21e9bc8dc9..e48fd2e07c 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -19,12 +19,13 @@ use messages::msg_fields::protocols::notification::ack::{AckDecorators, AckStatu use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::AriesMessage; use uuid::Uuid; -use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use crate::common::credentials::{get_cred_rev_id, is_cred_revoked}; use crate::errors::error::prelude::*; use crate::global::settings; -use crate::handlers::util::{get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status, verify_thread_id}; +use crate::handlers::util::{ + get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status, +}; use crate::protocols::common::build_problem_report_msg; use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 28c155a55c..ce855a90e2 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -1,7 +1,10 @@ use std::fmt::Display; use std::sync::Arc; -use crate::handlers::util::{get_attach_as_string, make_attach_from_str, matches_opt_thread_id, verify_thread_id, AttachmentId, OfferInfo, Status}; +use crate::handlers::util::{ + get_attach_as_string, make_attach_from_str, matches_opt_thread_id, verify_thread_id, AttachmentId, OfferInfo, + Status, +}; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use chrono::Utc; diff --git a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs index 7771834955..74f37875d6 100644 --- a/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs +++ b/aries_vcx/src/protocols/proof_presentation/verifier/state_machine.rs @@ -25,7 +25,7 @@ use messages::AriesMessage; use crate::common::proofs::proof_request::PresentationRequestData; use crate::errors::error::prelude::*; -use crate::handlers::util::{make_attach_from_str, AttachmentId, Status, verify_thread_id}; +use crate::handlers::util::{make_attach_from_str, verify_thread_id, AttachmentId, Status}; use crate::protocols::common::build_problem_report_msg; use crate::protocols::proof_presentation::verifier::states::finished::FinishedState; use crate::protocols::proof_presentation::verifier::states::initial::InitialVerifierState; diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index d4a26b3eaf..e38b1bd5fa 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -226,9 +226,7 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> let wallet = get_main_wallet()?; let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); - credential - .build_credential(&get_main_anoncreds()?) - .await?; + credential.build_credential(&get_main_anoncreds()?).await?; credential.send_credential(send_message).await; let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; From 85b1190d32dfdd45ee097a8a302ea11f31f3676f Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 23:51:51 +0200 Subject: [PATCH 09/40] Cargo fmt Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index e48fd2e07c..55bd861c8b 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -23,9 +23,7 @@ use uuid::Uuid; use crate::common::credentials::{get_cred_rev_id, is_cred_revoked}; use crate::errors::error::prelude::*; use crate::global::settings; -use crate::handlers::util::{ - get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status, -}; +use crate::handlers::util::{get_attach_as_string, make_attach_from_str, verify_thread_id, AttachmentId, Status}; use crate::protocols::common::build_problem_report_msg; use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; From 9306463c2f143c58fb6aafa5bffa99cd7079db6b Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 23:54:47 +0200 Subject: [PATCH 10/40] Fix compile errs in tests Signed-off-by: Patrik Stas --- libvcx_core/src/api_vcx/api_handle/issuer_credential.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index e38b1bd5fa..131e080c15 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -271,7 +271,6 @@ pub mod tests { #[cfg(test)] use crate::api_vcx::api_handle::mediated_connection::test_utils::build_test_connection_inviter_requested; use crate::aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; - use crate::errors::error; use aries_vcx::utils::constants::V3_OBJECT_SERIALIZE_VERSION; use aries_vcx::utils::devsetup::SetupMocks; use aries_vcx::utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_REQUEST; @@ -327,7 +326,7 @@ pub mod tests { send_credential_offer_v2(credential_handle, connection_handle) .await .unwrap(); - assert_eq!(get_state(credential_handle).unwrap(), u32::from(IssuerState::OfferSent)); + assert_eq!(get_state(credential_handle).unwrap(), u32::from(IssuerState::OfferSet)); } #[tokio::test] @@ -362,7 +361,7 @@ pub mod tests { send_credential_offer_v2(credential_handle, connection_handle) .await .unwrap(); - assert_eq!(get_state(credential_handle).unwrap(), u32::from(IssuerState::OfferSent)); + assert_eq!(get_state(credential_handle).unwrap(), u32::from(IssuerState::OfferSet)); update_state(credential_handle, Some(ARIES_CREDENTIAL_REQUEST), connection_handle) .await @@ -384,12 +383,12 @@ pub mod tests { .await .unwrap(); send_credential_offer_v2(handle_cred, handle_conn).await.unwrap(); - assert_eq!(get_state(handle_cred).unwrap(), u32::from(IssuerState::OfferSent)); + assert_eq!(get_state(handle_cred).unwrap(), u32::from(IssuerState::OfferSet)); // try to update state with nonsense message let result = update_state(handle_cred, Some(ARIES_CONNECTION_ACK), handle_conn).await; assert!(result.is_ok()); // todo: maybe we should rather return error if update_state doesn't progress state - assert_eq!(get_state(handle_cred).unwrap(), u32::from(IssuerState::OfferSent)); + assert_eq!(get_state(handle_cred).unwrap(), u32::from(IssuerState::OfferSet)); } #[tokio::test] From 957c9039279e6e9fffe3f2a1cbba3eed4477cc04 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 23:55:02 +0200 Subject: [PATCH 11/40] Remove unused constants Signed-off-by: Patrik Stas --- .../src/utils/mockdata/mockdata_credex.rs | 215 ------------------ 1 file changed, 215 deletions(-) diff --git a/aries_vcx/src/utils/mockdata/mockdata_credex.rs b/aries_vcx/src/utils/mockdata/mockdata_credex.rs index efd626b68e..58f0823d0d 100644 --- a/aries_vcx/src/utils/mockdata/mockdata_credex.rs +++ b/aries_vcx/src/utils/mockdata/mockdata_credex.rs @@ -1,22 +1,3 @@ -// Faber creates instance of issuerCredential -pub const CREDENTIAL_ISSUER_SM_INITIAL: &str = r#" -{ - "version": "2.0", - "data": { - "issuer_sm": { - "state": { - "Initial": { - "cred_def_id": "V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1", - "credential_json": "{\"name\":\"alice\",\"last_name\":\"clark\",\"sex\":\"female\",\"date\":\"05-2018\",\"degree\":\"maths\",\"age\":\"25\"}", - "rev_reg_id": "V4SGRU86Z58d6TV7PBUe6f:4:V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1:CL_ACCUM:tag1", - "tails_file": "/tmp/tails" - } - }, - "source_id": "alice_degree" - } - } -}"#; - // Faber send Cred offer to Alice pub const ARIES_CREDENTIAL_OFFER: &str = r#"{ "@id": "57b3f85d-7673-4e6f-bb09-cc27cf2653c0", @@ -142,138 +123,6 @@ pub const ARIES_CREDENTIAL_OFFER_JSON_FORMAT: &str = r#"{ ] }"#; -// Alice receives offer, serialzied credential object -pub const CREDENTIAL_SM_OFFER_RECEIVED: &str = r#" -{ - "version": "2.0", - "data": { - "holder_sm": { - "state": { - "OfferReceived": { - "offer": { - "@id": "0a794e24-c6b4-46bc-93b6-642b6dc98c98", - "credential_preview": { - "@type": "https://didcomm.org/issue-credential/1.0/credential-preview", - "attributes": [ - { - "name": "age", - "value": "25" - }, - { - "name": "date", - "value": "05-2018" - }, - { - "name": "degree", - "value": "maths" - }, - { - "name": "last_name", - "value": "clark" - }, - { - "name": "name", - "value": "alice" - }, - { - "name": "sex", - "value": "female" - } - ] - }, - "offers~attach": [ - { - "mime-type": "application/json", - "@id": "libindy-cred-offer-0", - "data": { - "base64": "eyJzY2hlbWFfaWQiOiJWNFNHUlU4Nlo1OGQ2VFY3UEJVZTZmOjI6RmFiZXJWY3g6MzguMTcuMSIsImNyZWRfZGVmX2lkIjoiVjRTR1JVODZaNThkNlRWN1BCVWU2ZjozOkNMOjE1Njp0YWcxIiwia2V5X2NvcnJlY3RuZXNzX3Byb29mIjp7ImMiOiIxODI4ODE3OTMyNjUzNzA4NzczOTYyMTk2MDk4NTY2NjAyMzkzNDg3NTE4ODYyMzAyNDQxODM4MTExMDI1ODM3MzA2MzE0OTQxMDEyMCIsInh6X2NhcCI6IjI0NDgyNzA2NjIzMTk4NjgzODU5MDUxOTc2NDEwMjYyMzYwMDQ0OTM1OTA3ODc0MTQ3ODM3ODYzNDU3NTAwNjI2MDIwMTgyNjAzNDI3Njg4ODc3Nzg1MDY1NjY5ODIwNDcwNTcxMDA2MjcyMzIyMTY0NjAyMTI3Njg3MzMxNDgzNDEwODQzMTgyNjk4MTcwNTM5MzI5NTA4NjIxNjM0MDMzMzcxMTE1NTQyMDAyMjcxMzE0MDQwNTc1NzM0NzIzODY4OTQ3ODMxODYzMTk5NzUxNDU3Mzc4NzQ5MzUwMTA5MzM5MTc0OTk2MDMzODM0MjU1OTg5NjU5NDc3ODAyMTg5ODU4NDY2Mjg3MzE3MDE5Mzc2ODYxMTQ4ODQ4OTMwMjM0NDE0NzYyMTcwNDQ2MjY1MjE1ODMwNDEzMzc3ODQ3Mjc0NDc3MDU1MDc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QzMTE5ODcwMzg3MDQxNTUxNTI2NDcyIn0=" - } - } - ] - } - } - }, - "source_id": "credential", - "thread_id": "0a794e24-c6b4-46bc-93b6-642b6dc98c98" - } - } -}"#; - -pub const CREDENTIAL_ISSUER_SM_OFFER_SENT: &str = r#" -{ - "version": "2.0", - "data": { - "issuer_sm": { - "state": { - "OfferSent": { - "offer": "{\"schema_id\":\"V4SGRU86Z58d6TV7PBUe6f:2:FaberVcx:100.3.17\",\"cred_def_id\":\"V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1\",\"key_correctness_proof\":{\"c\":\"8864890146079819966843507607084507466996537773103100015242104458151801570147\",\"xz_cap\":\"132525977827223287463967996367791660611753643437831026132133978673362652175979984960395345604117823033598843515772650970092042194998708471287667293473933602487387266144588495415616944811466910171746306576756067299147133996120610987778643167551472370650860706707489981250143016648216131940192067689731780997063617467994952948231164359737543271754978573745054322784594786983471195078199401393059600773630351754818811358191747218637239772879872305744584957954699837168611724572351569162034269703375267029483298772550673848980515525208224290008214955022684486373727968367957793088244529707858992758609642436424671530098100234617862130269644024376059636705980574590863518613785371479037964460747863\",\"xr_cap\":[[\"sex\",\"10212475160245231594800549040854372303290684256380918488632371037657339014806534940588554673668923103318206077059720668699192425379203595724258495955879134394690009722954264613493392981950745274150217838513814119475945408576517435232754189101061228937866890554581232132629336860287803380692900588369878654635587851842134163193490231540390456176691587533437539107704274260898642873639033821396021194012480721319148344547889691150132409707206905753961160393652003190095671994228552653431323771123633018647062857864156055033625475204728594378221420414003488928212382342146710978259261234513132305926681193895163367723096054346113318440172548126164414333781531199766980234151045186446173389250750\"],[\"degree\",\"181856742283453418473947649595643839643070259478938494473584568220469415234003101214923568013389712089002329509118010979819585255765334238653117932153907089227645576208149810056409291168266428333261231854714933689106351331306816560842818860955234224247467640283042193459845731039690242246162523419565162139381433436933425221922323252396259800586021811741002612505633393087999348487119018329907231223385144479615810153697792611768280290272847820566343166477570068876099556872349244742948210464728021063596957911336342418328102789261913866759741499940584934272174291759174216727901817778811694981504735794125209427214071854022871460401400559698149515333154883748572389272770720317560040712463897\"],[\"last_name\",\"43412293567073349102112370943795877043603069152786756498774529064165953390534477439420146649598887449303789243003836468145767558140820442230844681934242970120831621453186179743368507180242146094550439741968410170425735458888264171137616733641994947577653377853741974230587834360530942891162312983451291321340293070667444620919832965237004751459565905919070707692222664425077116273747444134874197630342511594972069999241272389020918350223302366912905038256257556690157536705279199282258870150174840775692849251725897411119789553994274891144344912923909296194371393823491152500258183683169146109761023058311487837541072813281306532733667848057503262367757201118550813992265344590262271483166483\"],[\"age\",\"68342866294164011784068034274328072729841816986472440793547517786819950247342073166125571525944766248482144768406472174708352715021161116977703459457196044671553753789562125231630111971572509052286957232826269542683452777397984820513540182019167192724561725096668080555141395762042804963579418584382415603000719514263625675792935811436862337394717705375498597054528271873897333941942675196453346888442959900889587403191435514572804420548366858537668848441873376613896206538002439203362350139060639241117668758869032773776414496608576676647828858037464226698788774683675796572388678801019435860058662641742186926934144365911980113050833169032386925668167616423998641959714326637643554532217927\"],[\"master_secret\",\"60004873604256882440837669482238000425353856673067906457286010426208332163294126128885588581808791972508689907661578422431435118216751145826744523616784738075865102182509689742359261285611551353667639554970046746807004041010623030438482125350153333189623356909573083022944384078323987456778721331893146299446171287036574645093201976492734355689314716208371556221655298694091873959850260058791477223797014501706197365726012893398404127387368852187102516338509783310599108227670748363371954452847108084863174642336130498792917539274492599601833452527856405146246277807281210276550206074749962019132159548975746780957482296723374263390806203268708835298174905777660267160424797736483014387864683\"],[\"date\",\"147342231503793263080838729926386421141753550322051739532890945800316221161473286924260404683208240537601816578975559097476493354445488636446930836424043194706973028057749444613329339999021747905965142733819319720303415509712171707205991530386667705361036306405728793380171364485013423072936004131892503597639074001977913486938956159872339293493930826077346851599196644812195740522922688159437382767733592015471466588476394412816911141620857591622245384369269230628756557778440089022685454958567766134358991022569505345783113088026211541418945735300261241258177732630669365390732700156680264076945134895046668269614083784528392573721268626040969213510380794408409764469331606990221467663106853\"],[\"name\",\"46402350507976620716083395016692554430921101058383359733469226024696002199385956892242058194593743795002035073758889854136413733934944023450686279086986421612064353302873838723273555536096043190932778102533172724397365106365130372069705599082758437270547570970026575560880601324063760607196158943453986432582265650934901685192243880872480587151034169399609684173921326513947204955133660721836876002637382143169397664542931310323878715494117950078756837048067536655534046663594626819353508083548306536346359549874088950193043473994946248616534386837224123826810232926853785332232969433958536376898849373637169605881974490269433669642934641299039638695661096758953398028200825360695660802669816\"]]},\"nonce\":\"69188538184527788000509\"}", - "cred_data": "{\"name\":\"alice\",\"last_name\":\"clark\",\"sex\":\"female\",\"date\":\"05-2018\",\"degree\":\"maths\",\"age\":\"25\"}", - "rev_reg_id": "V4SGRU86Z58d6TV7PBUe6f:4:V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1:CL_ACCUM:tag1", - "tails_file": "/tmp/tails", - "connection_handle": 12002013, - "thread_id": "cb54e2f9-ee17-488c-9bc7-d70c29cff802" - } - }, - "source_id": "alice_degree" - } - } -}"#; - -// Alice creates credential object from offer and serializes it -pub const SERIALIZED_CREDENTIAL_V2_OFFER_RECEIVED: &str = r#"{ - "version": "2.0", - "data": { - "holder_sm": { - "state": { - "OfferReceived": { - "offer": { - "@id": "e314d535-6996-4c97-baab-d778d498f349", - "credential_preview": { - "@type": "https://didcomm.org/issue-credential/1.0/credential-preview", - "attributes": [ - { - "name": "age", - "value": "25" - }, - { - "name": "date", - "value": "05-2018" - }, - { - "name": "degree", - "value": "maths" - }, - { - "name": "last_name", - "value": "clark" - }, - { - "name": "name", - "value": "alice" - }, - { - "name": "sex", - "value": "female" - } - ] - }, - "offers~attach": [ - { - "mime-type": "application/json", - "@id": "libindy-cred-offer-0", - "data": { - "base64": "eyJzY2hlbWFfaWQiOiJWNFNHUlU4Nlo1OGQ2VFY3UEJVZTZmOjI6RmFiZXJWY3g6MjcuNC42MSIsImNyZWRfZGVmX2lkIjoiVjRTR1JVODZaNThkNlRWN1BCVWU2ZjozOkNMOjE5OnRhZzEiL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k2MzI0OTkwMTQyNDI4NDU4NDE2OTIzNjEwNTkyOTg3MzYxMzc5NzY5NTk5MzkwNDE2Mzg0Nzk0MzE4MTY0MjQxODE5NDg0NTY0NzgzNjIzMjc3NDg0MjQ0NzgyNDUwOTE1ODEwNjkzMDczNDg5MTUzMzgwODU4ODQ4NjQ0NDI5NjQ1NDAwNzM5MjgzNDY2OTgyMzg0OTI2MDc4NTgxODM1NTM1NDk3MDQ3MzA4NzE5NDQ2NzUzNTA3MTI0NDMxODE2ODM5MDQzNzA3MzM4Nzg1OTg4MzA2ODI4OTg3MzcwNDE5MjkyMjE0MTQ0ODk4MTM0MDQ5MTI1NDc0MTE0ODk1MTIxNjIyMTQ5ODU5Nzk1MzE4MDYwMTgxNTM4OTUyNDA2OTcxODQwNjE4MjMyMTcxNDU2MDE0NzUyNjkyODg4MjE2NzQ3NTIxNTY1ODY1OTM1NDQ5MjIzNTExNjExMzI1NTE0NDU4MzAxNjk3MzA0OTI4NDMwMDI5ODAxNDM2NjE1Nzc0NzY0NDQwNjQwMTUyMjY5NTY0NjU4Njk3MjU4OTI2NSJdXX0sIm5vbmNlIjoiMTE5MTg2NjQyNTc4MzYxODg5MDk2OTI0In0=" - } - } - ] - } - } - }, - "source_id": "credential", - "thread_id": "57b3f85d-7673-4e6f-bb09-cc27cf2653c0" - } - } -}"#; // Alice sends credential request to Faber pub const ARIES_CREDENTIAL_REQUEST: &str = r#" @@ -296,45 +145,6 @@ pub const ARIES_CREDENTIAL_REQUEST: &str = r#" } }"#; -// CredentialIssuer (Faber) has received credential request -pub const CREDENTIAL_ISSUER_SM_REQUEST_RECEIVED: &str = r#" -{ - "version": "2.0", - "data": { - "issuer_sm": { - "state": { - "RequestReceived": { - "offer": "{\"schema_id\":\"V4SGRU86Z58d6TV7PBUe6f:2:FaberVcx:100.3.17\",\"cred_def_id\":\"V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1\",\"key_correctness_proof\":{\"c\":\"8864890146079819966843507607084507466996537773103100015242104458151801570147\",\"xz_cap\":\"132525977827223287463967996367791660611753643437831026132133978673362652175979984960395345604117823033598843515772650970092042194998708471287667293473933602487387266144588495415616944811466910171746306576756067299147133996120610987778643167551472370650860706707489981250143016648216131940192067689731780997063617467994952948231164359737543271754978573745054322784594786983471195078199401393059600773630351754818811358191747218637239772879872305744584957954699837168611724572351569162034269703375267029483298772550673848980515525208224290008214955022684486373727968367957793088244529707858992758609642436424671530098100234617862130269644024376059636705980574590863518613785371479037964460747863\",\"xr_cap\":[[\"sex\",\"10212475160245231594800549040854372303290684256380918488632371037657339014806534940588554673668923103318206077059720668699192425379203595724258495955879134394690009722954264613493392981950745274150217838513814119475945408576517435232754189101061228937866890554581232132629336860287803380692900588369878654635587851842134163193490231540390456176691587533437539107704274260898642873639033821396021194012480721319148344547889691150132409707206905753961160393652003190095671994228552653431323771123633018647062857864156055033625475204728594378221420414003488928212382342146710978259261234513132305926681193895163367723096054346113318440172548126164414333781531199766980234151045186446173389250750\"],[\"degree\",\"181856742283453418473947649595643839643070259478938494473584568220469415234003101214923568013389712089002329509118010979819585255765334238653117932153907089227645576208149810056409291168266428333261231854714933689106351331306816560842818860955234224247467640283042193459845731039690242246162523419565162139381433436933425221922323252396259800586021811741002612505633393087999348487119018329907231223385144479615810153697792611768280290272847820566343166477570068876099556872349244742948210464728021063596957911336342418328102789261913866759741499940584934272174291759174216727901817778811694981504735794125209427214071854022871460401400559698149515333154883748572389272770720317560040712463897\"],[\"last_name\",\"43412293567073349102112370943795877043603069152786756498774529064165953390534477439420146649598887449303789243003836468145767558140820442230844681934242970120831621453186179743368507180242146094550439741968410170425735458888264171137616733641994947577653377853741974230587834360530942891162312983451291321340293070667444620919832965237004751459565905919070707692222664425077116273747444134874197630342511594972069999241272389020918350223302366912905038256257556690157536705279199282258870150174840775692849251725897411119789553994274891144344912923909296194371393823491152500258183683169146109761023058311487837541072813281306532733667848057503262367757201118550813992265344590262271483166483\"],[\"age\",\"68342866294164011784068034274328072729841816986472440793547517786819950247342073166125571525944766248482144768406472174708352715021161116977703459457196044671553753789562125231630111971572509052286957232826269542683452777397984820513540182019167192724561725096668080555141395762042804963579418584382415603000719514263625675792935811436862337394717705375498597054528271873897333941942675196453346888442959900889587403191435514572804420548366858537668848441873376613896206538002439203362350139060639241117668758869032773776414496608576676647828858037464226698788774683675796572388678801019435860058662641742186926934144365911980113050833169032386925668167616423998641959714326637643554532217927\"],[\"master_secret\",\"60004873604256882440837669482238000425353856673067906457286010426208332163294126128885588581808791972508689907661578422431435118216751145826744523616784738075865102182509689742359261285611551353667639554970046746807004041010623030438482125350153333189623356909573083022944384078323987456778721331893146299446171287036574645093201976492734355689314716208371556221655298694091873959850260058791477223797014501706197365726012893398404127387368852187102516338509783310599108227670748363371954452847108084863174642336130498792917539274492599601833452527856405146246277807281210276550206074749962019132159548975746780957482296723374263390806203268708835298174905777660267160424797736483014387864683\"],[\"date\",\"147342231503793263080838729926386421141753550322051739532890945800316221161473286924260404683208240537601816578975559097476493354445488636446930836424043194706973028057749444613329339999021747905965142733819319720303415509712171707205991530386667705361036306405728793380171364485013423072936004131892503597639074001977913486938956159872339293493930826077346851599196644812195740522922688159437382767733592015471466588476394412816911141620857591622245384369269230628756557778440089022685454958567766134358991022569505345783113088026211541418945735300261241258177732630669365390732700156680264076945134895046668269614083784528392573721268626040969213510380794408409764469331606990221467663106853\"],[\"name\",\"46402350507976620716083395016692554430921101058383359733469226024696002199385956892242058194593743795002035073758889854136413733934944023450686279086986421612064353302873838723273555536096043190932778102533172724397365106365130372069705599082758437270547570970026575560880601324063760607196158943453986432582265650934901685192243880872480587151034169399609684173921326513947204955133660721836876002637382143169397664542931310323878715494117950078756837048067536655534046663594626819353508083548306536346359549874088950193043473994946248616534386837224123826810232926853785332232969433958536376898849373637169605881974490269433669642934641299039638695661096758953398028200825360695660802669816\"]]},\"nonce\":\"69188538184527788000509\"}", - "cred_data": "{\"name\":\"alice\",\"last_name\":\"clark\",\"sex\":\"female\",\"date\":\"05-2018\",\"degree\":\"maths\",\"age\":\"25\"}", - "rev_reg_id": "V4SGRU86Z58d6TV7PBUe6f:4:V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1:CL_ACCUM:tag1", - "tails_file": "/tmp/tails", - "connection_handle": 12002013, - "request": { - "@id": "cee5849d-7dd9-4747-b31f-9030956420a0", - "requests~attach": [ - { - "mime-type": "application/json", - "@id": "libindy-cred-request-0", - "data": { - "base64": "eyJwcm92ZXJfZGlkIjoiS0M2TktjcFhjcFZucGpMOHVLSDN0ViIsImNyZWRfZGVmX2lkIjoiVjRTR1JVODZaNThkNlRWN1BCVWU2ZjozOkNMOjY3OnRhZzEiLCJibGluZGVkX21zIjp7InUiOiI5MTY0MTI1NzEyNjg1ODU2NzA0MzEzNDU5ODcwMzk0MzAxNjQ5MTQ3NTQwMTg0OTgyMzExNzc2NzMxODIyMzU3ODE4MjAyNTk2MzMzMjgwMDQyMDU5NzU1NzEyMDAwMjc2NTQ1MjQxNzYxMzYyMjUxMTk3NDkyODg2MjI2ODYwNDM5NTQ0NDM4Mjg5NzcwNzU2NzU2MTYwNDIzOTUwMjU4MzExNzk4MTgzMjY2OTk5NTIwNzg3NzkxMzA4ODcyOTg2OTM5NTY2MDgxMTUxMjE5MTM4NjIxMTk3NTc0ODk1MjI5Njg0NjM3NDcyNjA5NjExOTU2MzYzNDIyOTk3ODcyNTgwMTY1Njk2NDAzNzk5ODU1NjMyMjU3MTgwMDM2NTczOTU5MDgxMTYwNzY5MjM3MzUwNDI4ODI3MTM3NDU4NDQ4NzE5MTkwMjA2NDEyNTc1ODQ1MTU0ODAxOTk1NDM4NTg0Njg0MzcyNzM4MzYwODA4Mjk4ODI3MjExNzE5Nzg1MDgzNTAxMzkxMjA1Mzg0ODk4NzU5NDU4MjU2Mjk1NDczMjcxODg5NjExODE2MTQyMjAzNjM2OTUwMzczNDc2ODc4MzIxNzgxODE4NTk4NjU0Njc0NjY4ODkyMjYxMjAxMjEyMzgxOTQ5NTU3MTE0NzQ1ODU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54e2f9-ee17-488c-9bc7-d70c29cff802", - "sender_order": 0, - "received_orders": {} - } - }, - "thread_id": "cb54e2f9-ee17-488c-9bc7-d70c29cff802" - } - }, - "source_id": "alice_degree" - } - } -} -"#; - // Faber sends credential pub const ARIES_CREDENTIAL_RESPONSE: &str = r#"{ "@id": "e5b39a25-36fe-49df-9534-3e486bfb6fb8", @@ -391,30 +201,5 @@ pub const CREDENTIAL_SM_FINISHED: &str = r#" } }"#; -// CredentialIssuer (Faber) has issued credential -pub const CREDENTIAL_ISSUER_SM_FINISHED: &str = r#" -{ - "version": "2.0", - "data": { - "issuer_sm": { - "state": { - "Finished": { - "cred_id": null, - "thread_id": "cb54e2f9-ee17-488c-9bc7-d70c29cff802", - "revocation_info_v1": { - "cred_rev_id": "1", - "rev_reg_id": "V4SGRU86Z58d6TV7PBUe6f:4:V4SGRU86Z58d6TV7PBUe6f:3:CL:67:tag1:CL_ACCUM:tag1", - "tails_file": "/tmp/tails" - }, - "status": "Success" - } - }, - "source_id": "alice_degree", - "thread_id": "0a794e24-c6b4-46bc-93b6-642b6dc98c98" - } - } -} -"#; - pub const OFFERED_ATTRIBUTES: &str = r#"{"sex":"female","date":"05-2018","last_name":"clark","degree":"maths","age":"25","name":"alice"}"#; From cff5145743b98ddaef6726562fa5a8dee820a932 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Sun, 20 Aug 2023 23:59:31 +0200 Subject: [PATCH 12/40] Sync up nodejs Signed-off-by: Patrik Stas --- .../vcxagent-core/src/services/service-cred-issuer.js | 7 +------ wrappers/node/src/api/common.ts | 1 - wrappers/node/src/api/issuer-credential.ts | 8 -------- .../node/test/suite1/ariesvcx-issuer-credential.test.ts | 4 ---- 4 files changed, 1 insertion(+), 19 deletions(-) diff --git a/agents/node/vcxagent-core/src/services/service-cred-issuer.js b/agents/node/vcxagent-core/src/services/service-cred-issuer.js index 635c4140d8..a1877f78cd 100644 --- a/agents/node/vcxagent-core/src/services/service-cred-issuer.js +++ b/agents/node/vcxagent-core/src/services/service-cred-issuer.js @@ -19,10 +19,7 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log }) const state1 = await issuerCred.getState() assert.equal(state1, IssuerStateType.OfferSet) - const credOfferMsg = await issuerCred.getCredentialOfferMsg() - await issuerCred.markCredentialOfferMsgSent() - const state2 = await issuerCred.getState() - assert.equal(state2, IssuerStateType.OfferSent) + const credOfferMsg = issuerCred.getCredentialOfferMsg() await saveIssuerCredential(issuerCredId, issuerCred) return credOfferMsg @@ -44,8 +41,6 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log const state1 = await issuerCred.getState() assert.equal(state1, IssuerStateType.OfferSet) await issuerCred.sendOfferV2(connection) - const state2 = await issuerCred.getState() - assert.equal(state2, IssuerStateType.OfferSent) await saveIssuerCredential(issuerCredId, issuerCred) } diff --git a/wrappers/node/src/api/common.ts b/wrappers/node/src/api/common.ts index a746ef92ac..81c8742502 100644 --- a/wrappers/node/src/api/common.ts +++ b/wrappers/node/src/api/common.ts @@ -145,7 +145,6 @@ export enum IssuerStateType { Initial = 0, ProposalReceived = 1, OfferSet = 2, - OfferSent = 3, RequestReceived = 4, CredentialSent = 5, Finished = 6, diff --git a/wrappers/node/src/api/issuer-credential.ts b/wrappers/node/src/api/issuer-credential.ts index d94d617ac0..6c5cabcf44 100644 --- a/wrappers/node/src/api/issuer-credential.ts +++ b/wrappers/node/src/api/issuer-credential.ts @@ -99,14 +99,6 @@ export class IssuerCredential extends VcxBaseWithState { - try { - return ffi.issuerCredentialMarkOfferMsgSent(this.handle); - } catch (err: any) { - throw new VCXInternalError(err); - } - } - public async buildCredentialOfferMsgV2({ credDef, attr, diff --git a/wrappers/node/test/suite1/ariesvcx-issuer-credential.test.ts b/wrappers/node/test/suite1/ariesvcx-issuer-credential.test.ts index 5ebbb61f13..3630100142 100644 --- a/wrappers/node/test/suite1/ariesvcx-issuer-credential.test.ts +++ b/wrappers/node/test/suite1/ariesvcx-issuer-credential.test.ts @@ -81,7 +81,6 @@ describe('IssuerCredential:', () => { assert.equal(await issuerCredential.getState(), IssuerStateType.OfferSet); const connection = await createConnectionInviterRequested(); await issuerCredential.sendOfferV2(connection); - assert.equal(await issuerCredential.getState(), IssuerStateType.OfferSent); }); it('build offer and mark as sent', async () => { @@ -96,9 +95,6 @@ describe('IssuerCredential:', () => { offer.credential_preview['@type'], 'https://didcomm.org/issue-credential/1.0/credential-preview', ); - - await issuerCredential.markCredentialOfferMsgSent(); - assert.equal(await issuerCredential.getState(), IssuerStateType.OfferSent); }); it('throws: not initialized', async () => { From 27ac06e311d2a199647b871c6cbfa78c253f0974 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Mon, 21 Aug 2023 00:01:09 +0200 Subject: [PATCH 13/40] Cargo fmt Signed-off-by: Patrik Stas --- aries_vcx/src/utils/mockdata/mockdata_credex.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/aries_vcx/src/utils/mockdata/mockdata_credex.rs b/aries_vcx/src/utils/mockdata/mockdata_credex.rs index 58f0823d0d..f377e75657 100644 --- a/aries_vcx/src/utils/mockdata/mockdata_credex.rs +++ b/aries_vcx/src/utils/mockdata/mockdata_credex.rs @@ -123,7 +123,6 @@ pub const ARIES_CREDENTIAL_OFFER_JSON_FORMAT: &str = r#"{ ] }"#; - // Alice sends credential request to Faber pub const ARIES_CREDENTIAL_REQUEST: &str = r#" { From 124b1f2b9264c3b0ad71ac549ce53ee4704767d7 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Mon, 21 Aug 2023 00:16:44 +0200 Subject: [PATCH 14/40] Minor refactor, renames Signed-off-by: Patrik Stas --- .../issuance/holder/state_machine.rs | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 55bd861c8b..f0cfe49148 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -70,7 +70,7 @@ impl fmt::Display for HolderFullState { } } -fn build_credential_request_msg(credential_request_attach: String, thread_id: &str) -> VcxResult { +fn build_credential_request_msg(credential_request_attach: String, thread_id: &str) -> RequestCredential { let content = RequestCredentialContent::new(vec![make_attach_from_str!( &credential_request_attach, AttachmentId::CredentialRequest.as_ref().to_string() @@ -85,11 +85,7 @@ fn build_credential_request_msg(credential_request_attach: String, thread_id: &s decorators.thread = Some(thread); decorators.timing = Some(timing); - Ok(RequestCredential::with_decorators( - Uuid::new_v4().to_string(), - content, - decorators, - )) + RequestCredential::with_decorators(Uuid::new_v4().to_string(), content, decorators) } fn build_credential_ack(thread_id: &str) -> AckCredential { @@ -197,7 +193,7 @@ impl HolderSM { ) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(state_data) => { - match _make_credential_request(ledger, anoncreds, self.thread_id.clone(), my_pw_did, &state_data.offer) + match process_credential_offer(ledger, anoncreds, self.thread_id.clone(), my_pw_did, &state_data.offer) .await { Ok((cred_request, req_meta, cred_def_json)) => { @@ -439,7 +435,10 @@ impl HolderSM { AriesVcxErrorKind::InvalidState, "Cannot get credential: credential id not found", ))?; - _delete_credential(anoncreds, &cred_id).await + anoncreds + .prover_delete_credential(&cred_id) + .await + .map_err(|err| err.into()) } _ => Err(AriesVcxError::from_msg( AriesVcxErrorKind::NotReady, @@ -524,16 +523,7 @@ async fn _store_credential( Ok((cred_id, rev_reg_def_json)) } -async fn _delete_credential(anoncreds: &Arc, cred_id: &str) -> VcxResult<()> { - trace!("Holder::_delete_credential >>> cred_id: {}", cred_id); - - anoncreds - .prover_delete_credential(cred_id) - .await - .map_err(|err| err.into()) -} - -pub async fn create_credential_request( +pub async fn create_anoncreds_credential_request( ledger: &Arc, anoncreds: &Arc, cred_def_id: &str, @@ -551,7 +541,7 @@ pub async fn create_credential_request( .map_err(|err| err.into()) } -async fn _make_credential_request( +async fn process_credential_offer( ledger: &Arc, anoncreds: &Arc, thread_id: String, @@ -569,7 +559,7 @@ async fn _make_credential_request( trace!("Parsed cred offer attachment: {}", cred_offer); let cred_def_id = parse_cred_def_id_from_cred_offer(&cred_offer)?; let (req, req_meta, _cred_def_id, cred_def_json) = - create_credential_request(ledger, anoncreds, &cred_def_id, &my_pw_did, &cred_offer).await?; + create_anoncreds_credential_request(ledger, anoncreds, &cred_def_id, &my_pw_did, &cred_offer).await?; trace!("Created cred def json: {}", cred_def_json); let credential_request_msg = build_credential_request_msg(req, &thread_id)?; Ok((credential_request_msg, req_meta, cred_def_json)) From 431415bc5734c1cf236af8fcce9ca0f86e30e6b1 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Mon, 21 Aug 2023 00:19:39 +0200 Subject: [PATCH 15/40] Restore setting up timing decorator on outgoing issue-credential message Signed-off-by: Patrik Stas --- .../src/protocols/issuance/holder/state_machine.rs | 2 +- .../src/protocols/issuance/issuer/state_machine.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index f0cfe49148..ea28222a73 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -561,6 +561,6 @@ async fn process_credential_offer( let (req, req_meta, _cred_def_id, cred_def_json) = create_anoncreds_credential_request(ledger, anoncreds, &cred_def_id, &my_pw_did, &cred_offer).await?; trace!("Created cred def json: {}", cred_def_json); - let credential_request_msg = build_credential_request_msg(req, &thread_id)?; + let credential_request_msg = build_credential_request_msg(req, &thread_id); Ok((credential_request_msg, req_meta, cred_def_json)) } diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index ce855a90e2..1e9dfe49d1 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -422,12 +422,11 @@ impl IssuerSM { pub async fn send_credential(self, send_message: SendClosure) -> VcxResult<()> { match self.state { IssuerFullState::CredentialSet(ref state_data) => { - let cred_offer_msg = state_data.msg_issue_credential.clone().into(); - // todo: update timing - // let mut timing = Timing::default(); - // timing.out_time = Some(Utc::now()); - // decorators.timing = Some(timing); - send_message(cred_offer_msg).await?; + let mut cred_offer_msg: IssueCredential = state_data.msg_issue_credential.clone().into(); + let mut timing = Timing::default(); + timing.out_time = Some(Utc::now()); + cred_offer_msg.decorators.timing = Some(timing); + send_message(cred_offer_msg.into()).await?; } _ => { return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); From 53f83d8128c10fcb76beb81a905049b72dad4101 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Mon, 21 Aug 2023 01:07:23 +0200 Subject: [PATCH 16/40] Holder: add function build_credential_request to avoid enforcing IO Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 5 +- aries_vcx/src/handlers/issuance/holder.rs | 10 ++- .../src/handlers/issuance/mediated_holder.rs | 2 +- aries_vcx/src/handlers/mod.rs | 2 +- .../issuance/holder/state_machine.rs | 62 +++++++++++++------ .../issuance/holder/states/offer_received.rs | 13 +--- .../issuance/holder/states/request_sent.rs | 10 +-- aries_vcx/tests/test_creds_proofs.rs | 30 ++++----- aries_vcx/tests/utils/devsetup_alice.rs | 15 +++-- aries_vcx/tests/utils/scenarios.rs | 24 +++---- .../src/api_vcx/api_handle/credential.rs | 10 +-- 11 files changed, 102 insertions(+), 81 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 822ceefb72..44775d243e 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -98,15 +98,14 @@ impl ServiceCredentialsHolder { let send_closure: SendClosure = Box::new(|msg: AriesMessage| { Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) }); - holder - .send_request( + .build_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), pw_did, - send_closure, ) .await?; + holder.send_credential_request(send_closure).await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 662e700b27..c32d887d70 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -52,21 +52,25 @@ impl Holder { Ok(()) } - pub async fn send_request( + // todo: is the my_pw_did really necessary? is it used under the hood? + pub async fn build_credential_request( &mut self, ledger: &Arc, anoncreds: &Arc, my_pw_did: String, - send_message: SendClosure, ) -> VcxResult<()> { self.holder_sm = self .holder_sm .clone() - .send_request(ledger, anoncreds, my_pw_did, send_message) + .build_credential_request(ledger, anoncreds, my_pw_did) .await?; Ok(()) } + pub async fn send_credential_request(&mut self, send_message: SendClosure) -> VcxResult<()> { + self.holder_sm.send_credential_request(send_message).await + } + pub async fn decline_offer<'a>(&'a mut self, comment: Option<&'a str>, send_message: SendClosure) -> VcxResult<()> { self.holder_sm = self .holder_sm diff --git a/aries_vcx/src/handlers/issuance/mediated_holder.rs b/aries_vcx/src/handlers/issuance/mediated_holder.rs index af892739ea..551eae74c5 100644 --- a/aries_vcx/src/handlers/issuance/mediated_holder.rs +++ b/aries_vcx/src/handlers/issuance/mediated_holder.rs @@ -23,7 +23,7 @@ pub fn holder_find_message_to_handle( } } } - HolderState::RequestSent => match &message { + HolderState::RequestSet => match &message { AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(credential)) => { if matches_thread_id!(credential, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); diff --git a/aries_vcx/src/handlers/mod.rs b/aries_vcx/src/handlers/mod.rs index dfd143a0eb..6be5e325f5 100644 --- a/aries_vcx/src/handlers/mod.rs +++ b/aries_vcx/src/handlers/mod.rs @@ -42,7 +42,7 @@ impl From for u32 { HolderState::Initial => 0, HolderState::ProposalSent => 1, HolderState::OfferReceived => 2, - HolderState::RequestSent => 3, + HolderState::RequestSet => 3, HolderState::Finished => 4, HolderState::Failed => 5, } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index ea28222a73..bb5b9be1bf 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -29,7 +29,7 @@ use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; use crate::protocols::issuance::holder::states::offer_received::OfferReceivedState; use crate::protocols::issuance::holder::states::proposal_sent::ProposalSentState; -use crate::protocols::issuance::holder::states::request_sent::RequestSentState; +use crate::protocols::issuance::holder::states::request_sent::RequestSetState; use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -37,7 +37,7 @@ pub enum HolderFullState { Initial(InitialHolderState), ProposalSent(ProposalSentState), OfferReceived(OfferReceivedState), - RequestSent(RequestSentState), + RequestSet(RequestSetState), Finished(FinishedHolderState), } @@ -46,7 +46,7 @@ pub enum HolderState { Initial, ProposalSent, OfferReceived, - RequestSent, + RequestSet, Finished, Failed, } @@ -64,13 +64,13 @@ impl fmt::Display for HolderFullState { HolderFullState::Initial(_) => f.write_str("Initial"), HolderFullState::ProposalSent(_) => f.write_str("ProposalSent"), HolderFullState::OfferReceived(_) => f.write_str("OfferReceived"), - HolderFullState::RequestSent(_) => f.write_str("RequestSent"), + HolderFullState::RequestSet(_) => f.write_str("RequestSent"), HolderFullState::Finished(_) => f.write_str("Finished"), } } } -fn build_credential_request_msg(credential_request_attach: String, thread_id: &str) -> RequestCredential { +fn _build_credential_request_msg(credential_request_attach: String, thread_id: &str) -> RequestCredential { let content = RequestCredentialContent::new(vec![make_attach_from_str!( &credential_request_attach, AttachmentId::CredentialRequest.as_ref().to_string() @@ -124,7 +124,7 @@ impl HolderSM { HolderFullState::Initial(_) => HolderState::Initial, HolderFullState::ProposalSent(_) => HolderState::ProposalSent, HolderFullState::OfferReceived(_) => HolderState::OfferReceived, - HolderFullState::RequestSent(_) => HolderState::RequestSent, + HolderFullState::RequestSet(_) => HolderState::RequestSet, HolderFullState::Finished(ref status) => match status.status { Status::Success => HolderState::Finished, _ => HolderState::Failed, @@ -184,21 +184,29 @@ impl HolderSM { Ok(Self { state, ..self }) } - pub async fn send_request<'a>( + pub async fn build_credential_request<'a>( self, ledger: &'a Arc, anoncreds: &'a Arc, my_pw_did: String, - send_message: SendClosure, ) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(state_data) => { - match process_credential_offer(ledger, anoncreds, self.thread_id.clone(), my_pw_did, &state_data.offer) - .await + match build_credential_request_msg( + ledger, + anoncreds, + self.thread_id.clone(), + my_pw_did, + &state_data.offer, + ) + .await { - Ok((cred_request, req_meta, cred_def_json)) => { - send_message(cred_request.into()).await?; - HolderFullState::RequestSent((state_data, req_meta, cred_def_json).into()) + Ok((msg_credential_request, req_meta, cred_def_json)) => { + HolderFullState::RequestSet(RequestSetState { + msg_credential_request, + req_meta, + cred_def_json, + }) } Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); @@ -206,7 +214,6 @@ impl HolderSM { "Failed to create credential request, sending problem report: {:?}", problem_report ); - send_message(problem_report.clone().into()).await?; HolderFullState::Finished(problem_report.into()) } } @@ -219,6 +226,23 @@ impl HolderSM { Ok(Self { state, ..self }) } + #[deprecated] + pub async fn send_credential_request(&self, send_message: SendClosure) -> VcxResult<()> { + match self.state { + HolderFullState::RequestSet(ref state) => { + let mut msg: RequestCredential = state.msg_credential_request.clone().into(); + let mut timing = Timing::default(); + timing.out_time = Some(Utc::now()); + msg.decorators.timing = Some(timing); + send_message(msg.into()).await?; + } + _ => { + return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); + } + }; + Ok(()) + } + pub async fn decline_offer(self, comment: Option, send_message: SendClosure) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(_) => { @@ -242,7 +266,7 @@ impl HolderSM { send_message: SendClosure, ) -> VcxResult { let state = match self.state { - HolderFullState::RequestSent(state_data) => { + HolderFullState::RequestSet(state_data) => { match _store_credential( ledger, anoncreds, @@ -280,7 +304,7 @@ impl HolderSM { pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { let state = match self.state { - HolderFullState::ProposalSent(_) | HolderFullState::RequestSent(_) => { + HolderFullState::ProposalSent(_) | HolderFullState::RequestSet(_) => { HolderFullState::Finished(problem_report.into()) } s => { @@ -403,7 +427,7 @@ impl HolderSM { HolderFullState::Initial(ref state) => state.is_revokable(), HolderFullState::ProposalSent(ref state) => state.is_revokable(ledger).await, HolderFullState::OfferReceived(ref state) => state.is_revokable(ledger).await, - HolderFullState::RequestSent(ref state) => state.is_revokable(), + HolderFullState::RequestSet(ref state) => state.is_revokable(), HolderFullState::Finished(ref state) => state.is_revokable(), } } @@ -541,7 +565,7 @@ pub async fn create_anoncreds_credential_request( .map_err(|err| err.into()) } -async fn process_credential_offer( +async fn build_credential_request_msg( ledger: &Arc, anoncreds: &Arc, thread_id: String, @@ -561,6 +585,6 @@ async fn process_credential_offer( let (req, req_meta, _cred_def_id, cred_def_json) = create_anoncreds_credential_request(ledger, anoncreds, &cred_def_id, &my_pw_did, &cred_offer).await?; trace!("Created cred def json: {}", cred_def_json); - let credential_request_msg = build_credential_request_msg(req, &thread_id); + let credential_request_msg = _build_credential_request_msg(req, &thread_id); Ok((credential_request_msg, req_meta, cred_def_json)) } diff --git a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs index 5c876bbc41..9e6655894d 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use crate::errors::error::prelude::*; use crate::handlers::util::get_attach_as_string; use crate::protocols::issuance::holder::state_machine::parse_cred_def_id_from_cred_offer; -use crate::protocols::issuance::holder::states::request_sent::RequestSentState; +use crate::protocols::issuance::holder::states::request_sent::RequestSetState; use crate::protocols::issuance::is_cred_def_revokable; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; @@ -13,17 +13,6 @@ pub struct OfferReceivedState { pub offer: OfferCredential, } -impl From<(OfferReceivedState, String, String)> for RequestSentState { - fn from((_state, req_meta, cred_def_json): (OfferReceivedState, String, String)) -> Self { - trace!("SM is now in RequestSent state"); - trace!("cred_def_json={:?}", cred_def_json); - RequestSentState { - req_meta, - cred_def_json, - } - } -} - impl OfferReceivedState { pub fn new(offer: OfferCredential) -> Self { OfferReceivedState { offer } diff --git a/aries_vcx/src/protocols/issuance/holder/states/request_sent.rs b/aries_vcx/src/protocols/issuance/holder/states/request_sent.rs index e24ec7bfff..c14fd8c18d 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/request_sent.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/request_sent.rs @@ -1,18 +1,20 @@ use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; +use messages::msg_fields::protocols::cred_issuance::request_credential::RequestCredential; use crate::errors::error::prelude::*; use crate::handlers::util::Status; use crate::protocols::issuance::holder::states::finished::FinishedHolderState; #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct RequestSentState { +pub struct RequestSetState { pub req_meta: String, pub cred_def_json: String, + pub msg_credential_request: RequestCredential, } -impl From<(RequestSentState, String, IssueCredential, Option)> for FinishedHolderState { +impl From<(RequestSetState, String, IssueCredential, Option)> for FinishedHolderState { fn from( - (_, cred_id, credential, rev_reg_def_json): (RequestSentState, String, IssueCredential, Option), + (_, cred_id, credential, rev_reg_def_json): (RequestSetState, String, IssueCredential, Option), ) -> Self { trace!("SM is now in Finished state"); FinishedHolderState { @@ -24,7 +26,7 @@ impl From<(RequestSentState, String, IssueCredential, Option)> for Finis } } -impl RequestSentState { +impl RequestSetState { pub fn is_revokable(&self) -> VcxResult { let parsed_cred_def: serde_json::Value = serde_json::from_str(&self.cred_def_json).map_err(|err| { AriesVcxError::from_msg( diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 206c7ccd0f..1e504b16a9 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -1704,21 +1704,22 @@ mod tests { alice.credential = Holder::create_from_offer("test", cred_offer).unwrap(); let pw_did = alice.connection.pairwise_info().pw_did.to_string(); + let send_closure = alice + .connection + .send_message_closure(alice.profile.inject_wallet()) + .await + .unwrap(); alice .credential - .send_request( + .build_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), pw_did, - alice - .connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), ) .await .unwrap(); - assert_eq!(HolderState::RequestSent, alice.credential.get_state()); + alice.credential.send_credential_request(send_closure).await.unwrap(); + assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } #[cfg(feature = "migration")] @@ -1811,22 +1812,23 @@ mod tests { .await .unwrap(); + let send_closure = alice + .connection + .send_message_closure(alice.profile.inject_wallet()) + .await + .unwrap(); let pw_did = alice.connection.pairwise_info().pw_did.to_string(); alice .credential - .send_request( + .build_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), pw_did, - alice - .connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), ) .await .unwrap(); - assert_eq!(HolderState::RequestSent, alice.credential.get_state()); + alice.credential.send_credential_request(send_closure).await.unwrap(); + assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } faber.send_credential().await; diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index c820e5e1ae..81109b21ee 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -176,20 +176,23 @@ impl Alice { self.credential = Holder::create_from_offer("degree", cred_offer).unwrap(); assert_eq!(HolderState::OfferReceived, self.credential.get_state()); + let send_closure = self + .connection + .send_message_closure(self.profile.inject_wallet()) + .await + .unwrap(); + let pw_did = self.connection.pairwise_info().pw_did.to_string(); self.credential - .send_request( + .build_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), pw_did, - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), ) .await .unwrap(); - assert_eq!(HolderState::RequestSent, self.credential.get_state()); + self.credential.send_credential_request(send_closure).await.unwrap(); + assert_eq!(HolderState::RequestSet, self.credential.get_state()); } pub async fn accept_credential(&mut self) { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 82ce460481..f2207ddd7b 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -276,18 +276,19 @@ pub mod test_utils { assert_eq!(HolderState::OfferReceived, holder.get_state()); info!("send_cred_req :: sending credential request"); let my_pw_did = connection.pairwise_info().pw_did.to_string(); + let send_closure = connection + .send_message_closure(alice.profile.inject_wallet()) + .await + .unwrap(); holder - .send_request( + .build_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), my_pw_did, - connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), ) .await .unwrap(); + holder.send_credential_request(send_closure).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; holder } @@ -505,19 +506,20 @@ pub mod test_utils { assert_eq!(HolderState::OfferReceived, holder.get_state()); assert!(holder.get_offer().is_ok()); let my_pw_did = connection.pairwise_info().pw_did.to_string(); + let send_closure = connection + .send_message_closure(alice.profile.inject_wallet()) + .await + .unwrap(); holder - .send_request( + .build_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), my_pw_did, - connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), ) .await .unwrap(); - assert_eq!(HolderState::RequestSent, holder.get_state()); + holder.send_credential_request(send_closure).await.unwrap(); + assert_eq!(HolderState::RequestSet, holder.get_state()); } pub async fn decline_offer(alice: &mut Alice, connection: &MediatedConnection, holder: &mut Holder) { diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index bcd49f9cf0..813f009ce8 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -232,13 +232,9 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib let my_pw_did = mediated_connection::get_pw_did(connection_handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; credential - .send_request( - &get_main_anoncreds_ledger_read()?, - &get_main_anoncreds()?, - my_pw_did, - send_message, - ) + .build_credential_request(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, my_pw_did) .await?; + credential.send_credential_request(send_message).await?; HANDLE_MAP.insert(handle, credential) } @@ -473,7 +469,7 @@ pub mod tests { info!("full_credential_test:: going to send_credential_request"); send_credential_request(handle_cred, handle_conn).await.unwrap(); - assert_eq!(HolderState::RequestSent as u32, get_state(handle_cred).unwrap()); + assert_eq!(HolderState::RequestSet as u32, get_state(handle_cred).unwrap()); AgencyMockDecrypted::set_next_decrypted_response(GET_MESSAGES_DECRYPTED_RESPONSE); AgencyMockDecrypted::set_next_decrypted_message(ARIES_CREDENTIAL_RESPONSE); From a7c256a850513cc1ec93ed5dd1da4494722d38a9 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 19:42:03 +0200 Subject: [PATCH 17/40] Holder: Add constructor for failed finished state Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 8 ++++---- .../src/protocols/issuance/holder/states/finished.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index bb5b9be1bf..c4fafa16fe 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -214,7 +214,7 @@ impl HolderSM { "Failed to create credential request, sending problem report: {:?}", problem_report ); - HolderFullState::Finished(problem_report.into()) + HolderFullState::Finished(FinishedHolderState::new(problem_report)) } } } @@ -248,7 +248,7 @@ impl HolderSM { HolderFullState::OfferReceived(_) => { let problem_report = build_problem_report_msg(comment, &self.thread_id); send_message(problem_report.clone().into()).await?; - HolderFullState::Finished(problem_report.into()) + HolderFullState::Finished(FinishedHolderState::new(problem_report)) } s => { warn!("Unable to decline credential offer in state {}", s); @@ -290,7 +290,7 @@ impl HolderSM { problem_report ); send_message(problem_report.clone().into()).await?; - HolderFullState::Finished(problem_report.into()) + HolderFullState::Finished(FinishedHolderState::new(problem_report)) } } } @@ -305,7 +305,7 @@ impl HolderSM { pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { let state = match self.state { HolderFullState::ProposalSent(_) | HolderFullState::RequestSet(_) => { - HolderFullState::Finished(problem_report.into()) + HolderFullState::Finished(FinishedHolderState::new(problem_report)) } s => { warn!("Unable to receive problem report in state {}", s); diff --git a/aries_vcx/src/protocols/issuance/holder/states/finished.rs b/aries_vcx/src/protocols/issuance/holder/states/finished.rs index afddb52035..8d348bdd8a 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/finished.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/finished.rs @@ -142,8 +142,8 @@ impl FinishedHolderState { } } -impl From for FinishedHolderState { - fn from(problem_report: ProblemReport) -> Self { +impl FinishedHolderState { + pub fn new(problem_report: ProblemReport) -> Self { trace!("SM is now in Finished state"); FinishedHolderState { cred_id: None, From 7fa45c16ef381fdd31fc95a82a23e5b926231a24 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 19:44:58 +0200 Subject: [PATCH 18/40] Issuer: Add constructor for CredentialSet state Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/issuer/state_machine.rs | 4 ++-- .../src/protocols/issuance/issuer/states/credential_set.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 1e9dfe49d1..e2a497277b 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -441,7 +441,7 @@ impl IssuerSM { &AriesMessage::CredentialIssuance(CredentialIssuance::Ack(ack.clone())), )?; let state = match self.state { - IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(state_data.into()), + IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)), s => { warn!("Unable to receive credential ack in state {}", s); s @@ -454,7 +454,7 @@ impl IssuerSM { verify_thread_id(&self.thread_id, &AriesMessage::ReportProblem(problem_report.clone()))?; let state = match self.state { IssuerFullState::OfferSet(state_data) => IssuerFullState::Finished((state_data, problem_report).into()), - IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished((state_data).into()), + IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)), s => { warn!("Unable to receive credential ack in state {}", s); s diff --git a/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs b/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs index c4326d47fc..50ffe42f9e 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/credential_set.rs @@ -9,8 +9,8 @@ pub struct CredentialSetState { pub msg_issue_credential: IssueCredential, } -impl From for FinishedState { - fn from(state: CredentialSetState) -> Self { +impl FinishedState { + pub fn from_credential_set_state(state: CredentialSetState) -> Self { trace!("SM is now in Finished state"); FinishedState { cred_id: None, From 634f0077638193034ff2c778e1a36abf3cd5256c Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 20:16:03 +0200 Subject: [PATCH 19/40] Replace state From conversion by constructors Signed-off-by: Patrik Stas --- .../issuance/issuer/state_machine.rs | 18 +++++++++++---- .../issuance/issuer/states/initial.rs | 17 -------------- .../issuance/issuer/states/offer_set.rs | 23 ++++--------------- .../issuer/states/proposal_received.rs | 13 ----------- .../issuer/states/requested_received.rs | 19 ++------------- 5 files changed, 19 insertions(+), 71 deletions(-) diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index e2a497277b..78a90a06cc 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -366,7 +366,9 @@ impl IssuerSM { &AriesMessage::CredentialIssuance(CredentialIssuance::RequestCredential(request.clone())), )?; let state = match self.state { - IssuerFullState::OfferSet(state_data) => IssuerFullState::RequestReceived((state_data, request).into()), + IssuerFullState::OfferSet(state_data) => { + IssuerFullState::RequestReceived(RequestReceivedState::from_offer_set_and_request(state_data, request)) + } s => { warn!("Unable to receive credential request in state {}", s); s @@ -407,7 +409,7 @@ impl IssuerSM { "Failed to create credential, sending problem report {:?}", problem_report ); - IssuerFullState::Finished((state_data, problem_report).into()) + IssuerFullState::Finished(FinishedState::from_request_and_error(state_data, problem_report)) } } } @@ -441,7 +443,9 @@ impl IssuerSM { &AriesMessage::CredentialIssuance(CredentialIssuance::Ack(ack.clone())), )?; let state = match self.state { - IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)), + IssuerFullState::CredentialSet(state_data) => { + IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)) + } s => { warn!("Unable to receive credential ack in state {}", s); s @@ -453,8 +457,12 @@ impl IssuerSM { pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { verify_thread_id(&self.thread_id, &AriesMessage::ReportProblem(problem_report.clone()))?; let state = match self.state { - IssuerFullState::OfferSet(state_data) => IssuerFullState::Finished((state_data, problem_report).into()), - IssuerFullState::CredentialSet(state_data) => IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)), + IssuerFullState::OfferSet(state_data) => { + IssuerFullState::Finished(FinishedState::from_offer_set_and_error(state_data, problem_report)) + } + IssuerFullState::CredentialSet(state_data) => { + IssuerFullState::Finished(FinishedState::from_credential_set_state(state_data)) + } s => { warn!("Unable to receive credential ack in state {}", s); s diff --git a/aries_vcx/src/protocols/issuance/issuer/states/initial.rs b/aries_vcx/src/protocols/issuance/issuer/states/initial.rs index 5bbeb1c1fb..6c45a9c4a3 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/initial.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/initial.rs @@ -1,19 +1,2 @@ -use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; - -use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_set::OfferSetState}; - #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] pub struct InitialIssuerState {} - -impl From<(OfferInfo, OfferCredential)> for OfferSetState { - fn from((offer_info, offer): (OfferInfo, OfferCredential)) -> Self { - trace!("SM is now in OfferSent state"); - OfferSetState { - offer, - credential_json: offer_info.credential_json, - cred_def_id: offer_info.cred_def_id, - rev_reg_id: offer_info.rev_reg_id, - tails_file: offer_info.tails_file, - } - } -} diff --git a/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs b/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs index eed03591b2..e3597efdf6 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/offer_set.rs @@ -34,23 +34,8 @@ impl OfferSetState { } } -impl From for FinishedState { - fn from(state: OfferSetState) -> Self { - trace!("SM is now in Finished state"); - FinishedState { - cred_id: None, - revocation_info_v1: Some(RevocationInfoV1 { - cred_rev_id: None, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - }), - status: Status::Undefined, - } - } -} - -impl From<(OfferSetState, RequestCredential)> for RequestReceivedState { - fn from((state, request): (OfferSetState, RequestCredential)) -> Self { +impl RequestReceivedState { + pub fn from_offer_set_and_request(state: OfferSetState, request: RequestCredential) -> Self { trace!("SM is now in Request Received state"); RequestReceivedState { offer: state.offer, @@ -62,8 +47,8 @@ impl From<(OfferSetState, RequestCredential)> for RequestReceivedState { } } -impl From<(OfferSetState, ProblemReport)> for FinishedState { - fn from((state, err): (OfferSetState, ProblemReport)) -> Self { +impl FinishedState { + pub fn from_offer_set_and_error(state: OfferSetState, err: ProblemReport) -> Self { trace!("SM is now in Finished state"); FinishedState { cred_id: None, diff --git a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs index 2b1892d996..b113304755 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs @@ -17,16 +17,3 @@ impl ProposalReceivedState { } } } - -impl From<(OfferCredential, OfferInfo)> for OfferSetState { - fn from((offer, offer_info): (OfferCredential, OfferInfo)) -> Self { - trace!("SM is now in OfferSet state"); - OfferSetState { - offer, - credential_json: offer_info.credential_json, - cred_def_id: offer_info.cred_def_id, - rev_reg_id: offer_info.rev_reg_id, - tails_file: offer_info.tails_file, - } - } -} diff --git a/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs index 46189408db..ec021c301e 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/requested_received.rs @@ -17,23 +17,8 @@ pub struct RequestReceivedState { pub request: RequestCredential, } -impl From<(RequestReceivedState, Option)> for FinishedState { - fn from((state, cred_rev_id): (RequestReceivedState, Option)) -> Self { - trace!("SM is now in Finished state"); - FinishedState { - cred_id: None, - revocation_info_v1: Some(RevocationInfoV1 { - cred_rev_id, - rev_reg_id: state.rev_reg_id, - tails_file: state.tails_file, - }), - status: Status::Success, - } - } -} - -impl From<(RequestReceivedState, ProblemReport)> for FinishedState { - fn from((state, err): (RequestReceivedState, ProblemReport)) -> Self { +impl FinishedState { + pub fn from_request_and_error(state: RequestReceivedState, err: ProblemReport) -> Self { trace!("SM is now in Finished state"); FinishedState { cred_id: None, From 0f98a3df4de0cfeb514cacc8a794ad136d8f8943 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 20:18:57 +0200 Subject: [PATCH 20/40] Sync up Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index c4fafa16fe..e62bf6d46d 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -64,7 +64,7 @@ impl fmt::Display for HolderFullState { HolderFullState::Initial(_) => f.write_str("Initial"), HolderFullState::ProposalSent(_) => f.write_str("ProposalSent"), HolderFullState::OfferReceived(_) => f.write_str("OfferReceived"), - HolderFullState::RequestSet(_) => f.write_str("RequestSent"), + HolderFullState::RequestSet(_) => f.write_str("RequestSet"), HolderFullState::Finished(_) => f.write_str("Finished"), } } From eed0af63cf95a1e1ec22c098867efd5cca09d710 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 20:21:58 +0200 Subject: [PATCH 21/40] Add deprecation comments Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 2 ++ aries_vcx/src/protocols/issuance/issuer/state_machine.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index e62bf6d46d..7b5669f580 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -227,6 +227,8 @@ impl HolderSM { } #[deprecated] + // convenience function for sending the credential request. This will be removed in the future + // and some form of replacement will be provided instead outside of state machines. pub async fn send_credential_request(&self, send_message: SendClosure) -> VcxResult<()> { match self.state { HolderFullState::RequestSet(ref state) => { diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 78a90a06cc..6dd8790cf9 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -347,6 +347,8 @@ impl IssuerSM { } #[deprecated] + // Convenience function for sending the credential offer. This will be removed in the future + // and some form of replacement will be provided instead outside of state machines. pub async fn send_credential_offer(self, send_message: SendClosure) -> VcxResult<()> { match self.state { IssuerFullState::OfferSet(ref state_data) => { @@ -421,6 +423,8 @@ impl IssuerSM { } #[deprecated] + // Convenience function for sending the credential. This will be removed in the future + // and some form of replacement will be provided instead outside of state machines. pub async fn send_credential(self, send_message: SendClosure) -> VcxResult<()> { match self.state { IssuerFullState::CredentialSet(ref state_data) => { From 957005d56f7db819e052936dba1e73170e53f694 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 22:46:46 +0200 Subject: [PATCH 22/40] Fix filename Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 2 +- aries_vcx/src/protocols/issuance/holder/states/mod.rs | 2 +- .../src/protocols/issuance/holder/states/offer_received.rs | 2 +- .../issuance/holder/states/{request_sent.rs => request_set.rs} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename aries_vcx/src/protocols/issuance/holder/states/{request_sent.rs => request_set.rs} (100%) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 7b5669f580..16127bad50 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -29,7 +29,7 @@ use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; use crate::protocols::issuance::holder::states::offer_received::OfferReceivedState; use crate::protocols::issuance::holder::states::proposal_sent::ProposalSentState; -use crate::protocols::issuance::holder::states::request_sent::RequestSetState; +use crate::protocols::issuance::holder::states::request_set::RequestSetState; use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/aries_vcx/src/protocols/issuance/holder/states/mod.rs b/aries_vcx/src/protocols/issuance/holder/states/mod.rs index b9dfdb227d..a4331730d6 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/mod.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/mod.rs @@ -2,4 +2,4 @@ pub(super) mod finished; pub(super) mod initial; pub(super) mod offer_received; pub(super) mod proposal_sent; -pub(super) mod request_sent; +pub(super) mod request_set; diff --git a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs index 9e6655894d..a4aa1563b2 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use crate::errors::error::prelude::*; use crate::handlers::util::get_attach_as_string; use crate::protocols::issuance::holder::state_machine::parse_cred_def_id_from_cred_offer; -use crate::protocols::issuance::holder::states::request_sent::RequestSetState; +use crate::protocols::issuance::holder::states::request_set::RequestSetState; use crate::protocols::issuance::is_cred_def_revokable; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; diff --git a/aries_vcx/src/protocols/issuance/holder/states/request_sent.rs b/aries_vcx/src/protocols/issuance/holder/states/request_set.rs similarity index 100% rename from aries_vcx/src/protocols/issuance/holder/states/request_sent.rs rename to aries_vcx/src/protocols/issuance/holder/states/request_set.rs From db250b1b35f5ff1ff220cc1afb3cdba98386a4fe Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 22:50:09 +0200 Subject: [PATCH 23/40] Rename Holder's ProposalSent to ProposalSet Signed-off-by: Patrik Stas --- .../issuance/holder/state_machine.rs | 22 +++++++++---------- .../protocols/issuance/holder/states/mod.rs | 2 +- .../{proposal_sent.rs => proposal_set.rs} | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) rename aries_vcx/src/protocols/issuance/holder/states/{proposal_sent.rs => proposal_set.rs} (92%) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 16127bad50..3e47accbcd 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -28,14 +28,14 @@ use crate::protocols::common::build_problem_report_msg; use crate::protocols::issuance::holder::states::finished::FinishedHolderState; use crate::protocols::issuance::holder::states::initial::InitialHolderState; use crate::protocols::issuance::holder::states::offer_received::OfferReceivedState; -use crate::protocols::issuance::holder::states::proposal_sent::ProposalSentState; +use crate::protocols::issuance::holder::states::proposal_set::ProposalSetState; use crate::protocols::issuance::holder::states::request_set::RequestSetState; use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum HolderFullState { Initial(InitialHolderState), - ProposalSent(ProposalSentState), + ProposalSet(ProposalSetState), OfferReceived(OfferReceivedState), RequestSet(RequestSetState), Finished(FinishedHolderState), @@ -44,7 +44,7 @@ pub enum HolderFullState { #[derive(Debug, PartialEq, Eq)] pub enum HolderState { Initial, - ProposalSent, + ProposalSet, OfferReceived, RequestSet, Finished, @@ -62,7 +62,7 @@ impl fmt::Display for HolderFullState { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match *self { HolderFullState::Initial(_) => f.write_str("Initial"), - HolderFullState::ProposalSent(_) => f.write_str("ProposalSent"), + HolderFullState::ProposalSet(_) => f.write_str("ProposalSet"), HolderFullState::OfferReceived(_) => f.write_str("OfferReceived"), HolderFullState::RequestSet(_) => f.write_str("RequestSet"), HolderFullState::Finished(_) => f.write_str("Finished"), @@ -122,7 +122,7 @@ impl HolderSM { pub fn get_state(&self) -> HolderState { match self.state { HolderFullState::Initial(_) => HolderState::Initial, - HolderFullState::ProposalSent(_) => HolderState::ProposalSent, + HolderFullState::ProposalSet(_) => HolderState::ProposalSet, HolderFullState::OfferReceived(_) => HolderState::OfferReceived, HolderFullState::RequestSet(_) => HolderState::RequestSet, HolderFullState::Finished(ref status) => match status.status { @@ -135,7 +135,7 @@ impl HolderSM { #[allow(dead_code)] pub fn get_proposal(&self) -> VcxResult { match &self.state { - HolderFullState::ProposalSent(state) => Ok(state.credential_proposal.clone()), + HolderFullState::ProposalSet(state) => Ok(state.credential_proposal.clone()), _ => Err(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, "Proposal not available in this state", @@ -153,13 +153,13 @@ impl HolderSM { let mut proposal = proposal; proposal.id = self.thread_id.clone(); send_message(proposal.clone().into()).await?; - HolderFullState::ProposalSent(ProposalSentState::new(proposal)) + HolderFullState::ProposalSet(ProposalSetState::new(proposal)) } HolderFullState::OfferReceived(_) => { let mut proposal = proposal; proposal.id = self.thread_id.clone(); send_message(proposal.clone().into()).await?; - HolderFullState::ProposalSent(ProposalSentState::new(proposal)) + HolderFullState::ProposalSet(ProposalSetState::new(proposal)) } s => { warn!("Unable to send credential proposal in state {}", s); @@ -175,7 +175,7 @@ impl HolderSM { &AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(offer.clone())), )?; let state = match self.state { - HolderFullState::ProposalSent(_) => HolderFullState::OfferReceived(OfferReceivedState::new(offer)), + HolderFullState::ProposalSet(_) => HolderFullState::OfferReceived(OfferReceivedState::new(offer)), s => { warn!("Unable to receive credential offer in state {}", s); s @@ -306,7 +306,7 @@ impl HolderSM { pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { let state = match self.state { - HolderFullState::ProposalSent(_) | HolderFullState::RequestSet(_) => { + HolderFullState::ProposalSet(_) | HolderFullState::RequestSet(_) => { HolderFullState::Finished(FinishedHolderState::new(problem_report)) } s => { @@ -427,7 +427,7 @@ impl HolderSM { pub async fn is_revokable(&self, ledger: &Arc) -> VcxResult { match self.state { HolderFullState::Initial(ref state) => state.is_revokable(), - HolderFullState::ProposalSent(ref state) => state.is_revokable(ledger).await, + HolderFullState::ProposalSet(ref state) => state.is_revokable(ledger).await, HolderFullState::OfferReceived(ref state) => state.is_revokable(ledger).await, HolderFullState::RequestSet(ref state) => state.is_revokable(), HolderFullState::Finished(ref state) => state.is_revokable(), diff --git a/aries_vcx/src/protocols/issuance/holder/states/mod.rs b/aries_vcx/src/protocols/issuance/holder/states/mod.rs index a4331730d6..4c8f63598c 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/mod.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/mod.rs @@ -1,5 +1,5 @@ pub(super) mod finished; pub(super) mod initial; pub(super) mod offer_received; -pub(super) mod proposal_sent; +pub(super) mod proposal_set; pub(super) mod request_set; diff --git a/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs b/aries_vcx/src/protocols/issuance/holder/states/proposal_set.rs similarity index 92% rename from aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs rename to aries_vcx/src/protocols/issuance/holder/states/proposal_set.rs index 484e1b89ad..8e55b4df3f 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/proposal_sent.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/proposal_set.rs @@ -7,11 +7,11 @@ use crate::errors::error::prelude::*; use crate::protocols::issuance::is_cred_def_revokable; #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ProposalSentState { +pub struct ProposalSetState { pub credential_proposal: ProposeCredential, } -impl ProposalSentState { +impl ProposalSetState { pub fn new(credential_proposal: ProposeCredential) -> Self { Self { credential_proposal } } From 66daf86bf2e5a0635f0c65b22799b60e23883b70 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 23:38:27 +0200 Subject: [PATCH 24/40] Update Holder proposal API Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 9 ++---- aries_vcx/src/handlers/issuance/holder.rs | 6 ++-- .../src/handlers/issuance/mediated_holder.rs | 2 +- aries_vcx/src/handlers/mod.rs | 2 +- .../issuance/holder/state_machine.rs | 4 +-- aries_vcx/tests/utils/scenarios.rs | 28 ++++--------------- 6 files changed, 14 insertions(+), 37 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 44775d243e..fedc6c081c 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -57,17 +57,14 @@ impl ServiceCredentialsHolder { pub async fn send_credential_proposal( &self, connection_id: &str, - proposal_data: ProposeCredential, + propose_credential: ProposeCredential, ) -> AgentResult { let connection = self.service_connections.get_by_id(connection_id)?; let wallet = self.profile.inject_wallet(); - let send_closure: SendClosure = Box::new(|msg: AriesMessage| { - Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) - }); - let mut holder = Holder::create("")?; - holder.send_proposal(proposal_data, send_closure).await?; + holder.set_proposal(propose_credential)?; + connection.send_message(&wallet, &propose_credential.into(), &HttpClient).await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, connection_id)) diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index c32d887d70..8c990e851a 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -39,16 +39,14 @@ impl Holder { Ok(Holder { holder_sm }) } - pub async fn send_proposal( + pub fn set_proposal( &mut self, credential_proposal: ProposeCredential, - send_message: SendClosure, ) -> VcxResult<()> { self.holder_sm = self .holder_sm .clone() - .send_proposal(credential_proposal, send_message) - .await?; + .set_proposal(credential_proposal)?; Ok(()) } diff --git a/aries_vcx/src/handlers/issuance/mediated_holder.rs b/aries_vcx/src/handlers/issuance/mediated_holder.rs index 551eae74c5..b45e5cae57 100644 --- a/aries_vcx/src/handlers/issuance/mediated_holder.rs +++ b/aries_vcx/src/handlers/issuance/mediated_holder.rs @@ -16,7 +16,7 @@ pub fn holder_find_message_to_handle( trace!("holder_find_message_to_handle >>>"); for (uid, message) in messages { match sm.get_state() { - HolderState::ProposalSent => { + HolderState::ProposalSet => { if let AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(offer)) = &message { if matches_opt_thread_id!(offer, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); diff --git a/aries_vcx/src/handlers/mod.rs b/aries_vcx/src/handlers/mod.rs index 6be5e325f5..dda90f09b7 100644 --- a/aries_vcx/src/handlers/mod.rs +++ b/aries_vcx/src/handlers/mod.rs @@ -40,7 +40,7 @@ impl From for u32 { fn from(state: HolderState) -> u32 { match state { HolderState::Initial => 0, - HolderState::ProposalSent => 1, + HolderState::ProposalSet => 1, HolderState::OfferReceived => 2, HolderState::RequestSet => 3, HolderState::Finished => 4, diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 3e47accbcd..013b1a58a7 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -143,7 +143,7 @@ impl HolderSM { } } - pub async fn send_proposal(self, proposal: ProposeCredential, send_message: SendClosure) -> VcxResult { + pub fn set_proposal(self, proposal: ProposeCredential) -> VcxResult { verify_thread_id( &self.thread_id, &AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(proposal.clone())), @@ -152,13 +152,11 @@ impl HolderSM { HolderFullState::Initial(_) => { let mut proposal = proposal; proposal.id = self.thread_id.clone(); - send_message(proposal.clone().into()).await?; HolderFullState::ProposalSet(ProposalSetState::new(proposal)) } HolderFullState::OfferReceived(_) => { let mut proposal = proposal; proposal.id = self.thread_id.clone(); - send_message(proposal.clone().into()).await?; HolderFullState::ProposalSet(ProposalSetState::new(proposal)) } s => { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index f2207ddd7b..54c80c7cf0 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -333,17 +333,9 @@ pub mod test_utils { let proposal = ProposeCredential::with_decorators(id, content, decorators); let mut holder = Holder::create("TEST_CREDENTIAL").unwrap(); assert_eq!(HolderState::Initial, holder.get_state()); - holder - .send_proposal( - proposal, - connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - assert_eq!(HolderState::ProposalSent, holder.get_state()); + holder.set_proposal(proposal.clone()).unwrap(); + assert_eq!(HolderState::ProposalSet, holder.get_state()); + connection.send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; holder } @@ -399,17 +391,9 @@ pub mod test_utils { let decorators = ProposeCredentialDecorators::default(); let proposal = ProposeCredential::with_decorators(id, content, decorators); - holder - .send_proposal( - proposal, - connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), - ) - .await - .unwrap(); - assert_eq!(HolderState::ProposalSent, holder.get_state()); + holder.set_proposal(proposal.clone()).unwrap(); + assert_eq!(HolderState::ProposalSet, holder.get_state()); + connection.send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; } From fbb1223fa33c60ff974d92b9f3929b94036bc5ba Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 23:40:13 +0200 Subject: [PATCH 25/40] Remove unused imports Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/issuer.rs | 5 ----- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 1 - .../src/protocols/issuance/holder/states/offer_received.rs | 1 - .../protocols/issuance/issuer/states/proposal_received.rs | 6 ++---- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index 48b614da37..2f0d5eefd0 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -1,6 +1,3 @@ -use std::collections::HashMap; - -use messages::decorators::please_ack::AckOn; use messages::misc::MimeType; use messages::msg_fields::protocols::cred_issuance::ack::AckCredential; use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; @@ -16,10 +13,8 @@ use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::msg_parts::MsgParts; use crate::errors::error::prelude::*; -use crate::handlers::revocation_notification::sender::RevocationNotificationSender; use crate::handlers::util::OfferInfo; use crate::protocols::issuance::issuer::state_machine::{IssuerSM, IssuerState, RevocationInfoV1}; -use crate::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder; use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone, Default)] diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 013b1a58a7..590e02085a 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::fmt; use std::sync::Arc; diff --git a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs index a4aa1563b2..e42e54d8f2 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/offer_received.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use crate::errors::error::prelude::*; use crate::handlers::util::get_attach_as_string; use crate::protocols::issuance::holder::state_machine::parse_cred_def_id_from_cred_offer; -use crate::protocols::issuance::holder::states::request_set::RequestSetState; use crate::protocols::issuance::is_cred_def_revokable; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; diff --git a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs index b113304755..1caf63e24a 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs @@ -1,7 +1,5 @@ -use crate::{handlers::util::OfferInfo, protocols::issuance::issuer::states::offer_set::OfferSetState}; -use messages::msg_fields::protocols::cred_issuance::{ - offer_credential::OfferCredential, propose_credential::ProposeCredential, -}; +use crate::handlers::util::OfferInfo; +use messages::msg_fields::protocols::cred_issuance:: propose_credential::ProposeCredential; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ProposalReceivedState { From ffb979bd24730140051a551151e7ed7f9d139671 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 23 Aug 2023 23:42:43 +0200 Subject: [PATCH 26/40] Cargo fmt Signed-off-by: Patrik Stas --- agents/rust/aries-vcx-agent/src/services/holder.rs | 4 +++- aries_vcx/src/handlers/issuance/holder.rs | 10 ++-------- .../issuance/issuer/states/proposal_received.rs | 2 +- aries_vcx/tests/utils/scenarios.rs | 10 ++++++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index fedc6c081c..99c8f67397 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -64,7 +64,9 @@ impl ServiceCredentialsHolder { let mut holder = Holder::create("")?; holder.set_proposal(propose_credential)?; - connection.send_message(&wallet, &propose_credential.into(), &HttpClient).await?; + connection + .send_message(&wallet, &propose_credential.into(), &HttpClient) + .await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, connection_id)) diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 8c990e851a..1914731d89 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -39,14 +39,8 @@ impl Holder { Ok(Holder { holder_sm }) } - pub fn set_proposal( - &mut self, - credential_proposal: ProposeCredential, - ) -> VcxResult<()> { - self.holder_sm = self - .holder_sm - .clone() - .set_proposal(credential_proposal)?; + pub fn set_proposal(&mut self, credential_proposal: ProposeCredential) -> VcxResult<()> { + self.holder_sm = self.holder_sm.clone().set_proposal(credential_proposal)?; Ok(()) } diff --git a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs index 1caf63e24a..cf79ec3633 100644 --- a/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs +++ b/aries_vcx/src/protocols/issuance/issuer/states/proposal_received.rs @@ -1,5 +1,5 @@ use crate::handlers::util::OfferInfo; -use messages::msg_fields::protocols::cred_issuance:: propose_credential::ProposeCredential; +use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ProposalReceivedState { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 54c80c7cf0..1d369c043b 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -335,7 +335,10 @@ pub mod test_utils { assert_eq!(HolderState::Initial, holder.get_state()); holder.set_proposal(proposal.clone()).unwrap(); assert_eq!(HolderState::ProposalSet, holder.get_state()); - connection.send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()).await.unwrap(); + connection + .send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()) + .await + .unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; holder } @@ -393,7 +396,10 @@ pub mod test_utils { let proposal = ProposeCredential::with_decorators(id, content, decorators); holder.set_proposal(proposal.clone()).unwrap(); assert_eq!(HolderState::ProposalSet, holder.get_state()); - connection.send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()).await.unwrap(); + connection + .send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()) + .await + .unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; } From 440717da83d668750b9d7a52538faf8719a480f5 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Thu, 24 Aug 2023 17:49:48 +0200 Subject: [PATCH 27/40] Tweak issuance protocol initiation via holder's proposal Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/holder.rs | 10 ++++++++++ aries_vcx/src/handlers/issuance/mediated_issuer.rs | 9 +++++++++ .../src/protocols/issuance/holder/state_machine.rs | 9 +++++++++ .../src/protocols/issuance/issuer/state_machine.rs | 1 + aries_vcx/tests/utils/scenarios.rs | 7 +++---- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 1914731d89..fd18f1eed9 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -29,6 +29,16 @@ impl Holder { Ok(Holder { holder_sm }) } + pub fn create_with_proposal(source_id: &str, propose_credential: ProposeCredential) -> VcxResult { + trace!( + "Holder::create_with_proposal >>> source_id: {:?}, propose_credential: {:?}", + source_id, + propose_credential + ); + let holder_sm = HolderSM::with_proposal(propose_credential, source_id.to_string()); + Ok(Holder { holder_sm }) + } + pub fn create_from_offer(source_id: &str, credential_offer: OfferCredential) -> VcxResult { trace!( "Holder::create_from_offer >>> source_id: {:?}, credential_offer: {:?}", diff --git a/aries_vcx/src/handlers/issuance/mediated_issuer.rs b/aries_vcx/src/handlers/issuance/mediated_issuer.rs index f4a3f7be84..7edf21b963 100644 --- a/aries_vcx/src/handlers/issuance/mediated_issuer.rs +++ b/aries_vcx/src/handlers/issuance/mediated_issuer.rs @@ -23,21 +23,27 @@ pub fn issuer_find_message_to_handle( match sm.get_state() { IssuerState::Initial => { if let AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(_)) = &message { + info!("In state IssuerState::OfferSet, found matching message ProposeCredential"); return Some((uid, message)); } } IssuerState::OfferSet => match &message { AriesMessage::CredentialIssuance(CredentialIssuance::RequestCredential(msg)) => { + info!("In state IssuerState::OfferSet, found potentially matching message RequestCredential"); + warn!("Matching for {}", sm.get_thread_id().unwrap().as_str()); // todo: the state machine has "test" thid, and doesnt match msg + warn!("Msg: {msg:?}"); if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } } AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(msg)) => { + info!("In state IssuerState::OfferSet, found potentially matching message ProposeCredential"); if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } } AriesMessage::ReportProblem(msg) => { + info!("In state IssuerState::OfferSet, found matching message ReportProblem"); if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } @@ -46,16 +52,19 @@ pub fn issuer_find_message_to_handle( }, IssuerState::CredentialSet => match &message { AriesMessage::CredentialIssuance(CredentialIssuance::Ack(msg)) => { + info!("In state IssuerState::CredentialSet, found matching message CredentialIssuance::Ack"); if matches_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } } AriesMessage::Notification(Notification::Ack(msg)) => { + info!("In state IssuerState::CredentialSet, found matching message Notification::Ack"); if matches_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } } AriesMessage::ReportProblem(msg) => { + info!("In state IssuerState::CredentialSet, found matching message ReportProblem"); if matches_opt_thread_id!(msg, sm.get_thread_id().unwrap().as_str()) { return Some((uid, message)); } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 590e02085a..700ba7dcbf 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -114,6 +114,14 @@ impl HolderSM { } } + pub fn with_proposal(propose_credential: ProposeCredential, source_id: String) -> Self { + HolderSM { + thread_id: propose_credential.id.clone(), + state: HolderFullState::ProposalSet(ProposalSetState::new(propose_credential)), + source_id, + } + } + pub fn get_source_id(&self) -> String { self.source_id.clone() } @@ -233,6 +241,7 @@ impl HolderSM { let mut timing = Timing::default(); timing.out_time = Some(Utc::now()); msg.decorators.timing = Some(timing); + error!("Sending msg {msg:?}"); // TODO: it looks like received message has thread "test", but doesnt look like thats what we sending send_message(msg.into()).await?; } _ => { diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 6dd8790cf9..4e12056784 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -288,6 +288,7 @@ impl IssuerSM { source_id, thread_id, } = self; + warn!("IssuerSM::build_credential_offer_msg >>> thread_id: {thread_id}"); let state = match state { IssuerFullState::Initial(_) | IssuerFullState::OfferSet(_) | IssuerFullState::ProposalReceived(_) => { let cred_offer_msg = build_credential_offer(&thread_id, credential_offer, credential_preview, comment)?; diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 1d369c043b..12146da3ba 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -301,7 +301,6 @@ pub mod test_utils { comment: &str, ) -> Holder { let (address1, address2, city, state, zip) = attr_names(); - let id = "test".to_owned(); let mut attrs = Vec::new(); let mut attr = CredentialAttr::new(address1, "123 Main Str".to_owned()); @@ -330,10 +329,9 @@ pub mod test_utils { let decorators = ProposeCredentialDecorators::default(); + let id = "test".to_owned(); let proposal = ProposeCredential::with_decorators(id, content, decorators); - let mut holder = Holder::create("TEST_CREDENTIAL").unwrap(); - assert_eq!(HolderState::Initial, holder.get_state()); - holder.set_proposal(proposal.clone()).unwrap(); + let mut holder = Holder::create_with_proposal("TEST_CREDENTIAL", proposal.clone()).unwrap(); assert_eq!(HolderState::ProposalSet, holder.get_state()); connection .send_a2a_message(&alice.profile.inject_wallet(), &proposal.into()) @@ -420,6 +418,7 @@ pub mod test_utils { .await .unwrap(); let mut issuer = Issuer::create_from_proposal("TEST_CREDENTIAL", proposal).unwrap(); + assert_eq!(proposal.id, issuer.get_thread_id().unwrap()); assert_eq!(IssuerState::ProposalReceived, issuer.get_state()); assert_eq!(proposal.clone(), issuer.get_proposal().unwrap()); let offer_info = OfferInfo { From 1ac22c7b3d2df735bc18f7b23b5da3154f1587fa Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 30 Aug 2023 17:13:56 +0200 Subject: [PATCH 28/40] Remove forgotten log Signed-off-by: Patrik Stas --- aries_vcx/src/protocols/issuance/holder/state_machine.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 700ba7dcbf..18f144fa94 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -241,7 +241,6 @@ impl HolderSM { let mut timing = Timing::default(); timing.out_time = Some(Utc::now()); msg.decorators.timing = Some(timing); - error!("Sending msg {msg:?}"); // TODO: it looks like received message has thread "test", but doesnt look like thats what we sending send_message(msg.into()).await?; } _ => { From fccc4c81d6274fdbbe226ccce8139bf063e1b0d9 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Wed, 30 Aug 2023 17:38:41 +0200 Subject: [PATCH 29/40] Add get_problem_report() method for Issuer, Holder Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 2 +- aries_vcx/src/handlers/issuance/holder.rs | 5 +++++ aries_vcx/src/handlers/issuance/issuer.rs | 4 ++++ .../issuance/holder/state_machine.rs | 17 ++++++++++++++++ .../issuance/issuer/state_machine.rs | 20 ++++++++++++++++++- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 99c8f67397..2b9172485f 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -63,7 +63,7 @@ impl ServiceCredentialsHolder { let wallet = self.profile.inject_wallet(); let mut holder = Holder::create("")?; - holder.set_proposal(propose_credential)?; + holder.set_proposal(propose_credential.clone())?; connection .send_message(&wallet, &propose_credential.into(), &HttpClient) .await?; diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index fd18f1eed9..7afe240d3e 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -7,6 +7,7 @@ use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCrede use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; +use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::msg_fields::protocols::revocation::revoke::Revoke; use messages::AriesMessage; @@ -192,6 +193,10 @@ impl Holder { } } + pub fn get_problem_report(&self) -> VcxResult { + self.holder_sm.get_problem_report() + } + pub async fn process_aries_msg( &mut self, ledger: &Arc, diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index 2f0d5eefd0..a657df950c 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -268,6 +268,10 @@ impl Issuer { Ok(()) } + pub fn get_problem_report(&self) -> VcxResult { + self.issuer_sm.get_problem_report() + } + // todo: will ultimately end up in generic SM layer pub async fn process_aries_msg(&mut self, msg: AriesMessage) -> VcxResult<()> { let issuer_sm = match msg { diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 18f144fa94..36a499e8a1 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -477,6 +477,23 @@ impl HolderSM { )), } } + + pub fn get_problem_report(&self) -> VcxResult { + match self.state { + HolderFullState::Finished(ref state) => match &state.status { + Status::Failed(problem_report) => Ok(problem_report.clone()), + Status::Declined(problem_report) => Ok(problem_report.clone()), + _ => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::NotReady, + "No problem report available in current state", + )), + }, + _ => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::NotReady, + "No problem report available in current state", + )), + } + } } pub fn parse_cred_def_id_from_cred_offer(cred_offer: &str) -> VcxResult { diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 4e12056784..7674719840 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -405,7 +405,8 @@ impl IssuerSM { }), }) } - // todo: dont' transition, throw error, add to_failed transition() api which SM consumer can call + // todo: 1. Don't transition, throw error, add to_failed transition() api which SM consumer can call + // 2. Also create separate "Failed" state Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!( @@ -492,6 +493,23 @@ impl IssuerSM { pub fn thread_id(&self) -> VcxResult { Ok(self.thread_id.clone()) } + + pub fn get_problem_report(&self) -> VcxResult { + match self.state { + IssuerFullState::Finished(ref state) => match &state.status { + Status::Failed(problem_report) => Ok(problem_report.clone()), + Status::Declined(problem_report) => Ok(problem_report.clone()), + _ => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::NotReady, + "No problem report available in current state", + )), + }, + _ => Err(AriesVcxError::from_msg( + AriesVcxErrorKind::NotReady, + "No problem report available in current state", + )), + } + } } async fn create_credential( From 5b8006c3e3c1f8a7db2871086a8dd68fc61324d3 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Thu, 31 Aug 2023 20:19:24 +0200 Subject: [PATCH 30/40] Send problem reports Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 10 +++++++- .../aries-vcx-agent/src/services/issuer.rs | 10 +++++++- .../issuance/issuer/state_machine.rs | 2 +- .../src/api_vcx/api_handle/credential.rs | 11 ++++++++- .../api_vcx/api_handle/issuer_credential.rs | 23 ++++++++++++++++--- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 2b9172485f..06ebbeb6a1 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -104,7 +104,15 @@ impl ServiceCredentialsHolder { pw_did, ) .await?; - holder.send_credential_request(send_closure).await?; + match holder.get_state() { + HolderState::Failed => { + let problem_report = holder.get_problem_report()?; + send_closure(problem_report.into()).await?; + } + _ => { + holder.send_credential_request(send_closure).await?; + } + } self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/agents/rust/aries-vcx-agent/src/services/issuer.rs b/agents/rust/aries-vcx-agent/src/services/issuer.rs index f6cd0037e9..5c7c09652f 100644 --- a/agents/rust/aries-vcx-agent/src/services/issuer.rs +++ b/agents/rust/aries-vcx-agent/src/services/issuer.rs @@ -125,7 +125,15 @@ impl ServiceCredentialsIssuer { }); issuer.build_credential(&self.profile.inject_anoncreds()).await?; - issuer.send_credential(send_closure).await; + match issuer.get_state() { + IssuerState::Failed => { + let problem_report = issuer.get_problem_report()?; + send_closure(problem_report.into()).await?; + } + _ => { + issuer.send_credential(send_closure).await?; + } + } self.creds_issuer .insert(&issuer.get_thread_id()?, IssuerWrapper::new(issuer, &connection_id))?; Ok(()) diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 7674719840..d50bb6f408 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -410,7 +410,7 @@ impl IssuerSM { Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!( - "Failed to create credential, sending problem report {:?}", + "Failed to create credential, generated problem report {:?}", problem_report ); IssuerFullState::Finished(FinishedState::from_request_and_error(state_data, problem_report)) diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 813f009ce8..3cbb4538e7 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -6,6 +6,7 @@ use serde_json; use aries_vcx::agency_client::testing::mocking::AgencyMockDecrypted; use aries_vcx::handlers::issuance::holder::Holder; use aries_vcx::handlers::issuance::mediated_holder::holder_find_message_to_handle; +use aries_vcx::protocols::issuance::holder::state_machine::HolderState; use aries_vcx::utils::constants::GET_MESSAGES_DECRYPTED_RESPONSE; use aries_vcx::{global::settings::indy_mocks_enabled, utils::mockdata::mockdata_credex::ARIES_CREDENTIAL_OFFER}; @@ -234,7 +235,15 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib credential .build_credential_request(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, my_pw_did) .await?; - credential.send_credential_request(send_message).await?; + match credential.get_state() { + HolderState::Failed => { + let problem_report = credential.get_problem_report()?; + send_message(problem_report.into()).await?; + } + _ => { + credential.send_credential_request(send_message).await?; + } + } HANDLE_MAP.insert(handle, credential) } diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index 131e080c15..3706b860c0 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -6,6 +6,7 @@ use serde_json; use aries_vcx::handlers::issuance::issuer::Issuer; use aries_vcx::handlers::issuance::mediated_issuer::issuer_find_message_to_handle; +use aries_vcx::protocols::issuance::issuer::state_machine::IssuerState; use crate::api_vcx::api_global::profile::{get_main_anoncreds, get_main_wallet}; use crate::api_vcx::api_handle::connection; @@ -214,7 +215,15 @@ pub async fn send_credential(handle: u32, connection_handle: u32) -> LibvcxResul let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; credential.build_credential(&get_main_anoncreds()?).await?; let send_closure = mediated_connection::send_message_closure(connection_handle).await?; - credential.send_credential(send_closure).await?; + match credential.get_state() { + IssuerState::Failed => { + let problem_report = credential.get_problem_report()?; + send_closure(problem_report.into()).await?; + } + _ => { + credential.send_credential(send_closure).await?; + } + } let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) @@ -224,10 +233,18 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(handle)?; let con = connection::get_cloned_generic_connection(&connection_handle)?; let wallet = get_main_wallet()?; - let send_message: SendClosure = + let send_closure: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); credential.build_credential(&get_main_anoncreds()?).await?; - credential.send_credential(send_message).await; + match credential.get_state() { + IssuerState::Failed => { + let problem_report = credential.get_problem_report()?; + send_closure(problem_report.into()).await?; + } + _ => { + credential.send_credential(send_closure).await?; + } + } let state: u32 = credential.get_state().into(); ISSUER_CREDENTIAL_MAP.insert(handle, credential)?; Ok(state) From e9cfc4560bffe0491f60bcfe2e994ff7a631a946 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 12:19:27 +0200 Subject: [PATCH 31/40] Holder: Assure sending problem-report, sending credential-ack Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 10 +++- aries_vcx/src/handlers/issuance/holder.rs | 60 ++++++++++++++++--- .../issuance/holder/state_machine.rs | 21 +------ .../src/api_vcx/api_handle/credential.rs | 31 +++++----- 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 06ebbeb6a1..db030ec0dc 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -117,7 +117,11 @@ impl ServiceCredentialsHolder { .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } - pub async fn process_credential(&self, thread_id: &str, credential: IssueCredential) -> AgentResult { + pub async fn process_credential( + &self, + thread_id: &str, + msg_issue_credential: IssueCredential, + ) -> AgentResult { let mut holder = self.get_holder(thread_id)?; let connection_id = self.get_connection_id(thread_id)?; let connection = self.service_connections.get_by_id(&connection_id)?; @@ -131,10 +135,10 @@ impl ServiceCredentialsHolder { .process_credential( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), - credential, - send_closure, + msg_issue_credential.clone(), ) .await?; + holder.try_reply(send_closure, msg_issue_credential.into()).await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 7afe240d3e..2d6fe08d62 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -1,12 +1,18 @@ +use chrono::Utc; use std::sync::Arc; +use uuid::Uuid; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use aries_vcx_core::wallet::base_wallet::BaseWallet; +use messages::decorators::thread::Thread; +use messages::decorators::timing::Timing; +use messages::msg_fields::protocols::cred_issuance::ack::{AckCredential, AckCredentialContent}; use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; +use messages::msg_fields::protocols::notification::ack::{AckDecorators, AckStatus}; use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::msg_fields::protocols::revocation::revoke::Revoke; use messages::AriesMessage; @@ -18,6 +24,16 @@ use crate::handlers::revocation_notification::receiver::RevocationNotificationRe use crate::protocols::issuance::holder::state_machine::{HolderSM, HolderState}; use crate::protocols::SendClosure; +fn build_credential_ack(thread_id: &str) -> AckCredential { + let content = AckCredentialContent::new(AckStatus::Ok); + let mut decorators = AckDecorators::new(Thread::new(thread_id.to_owned())); + let mut timing = Timing::default(); + timing.out_time = Some(Utc::now()); + decorators.timing = Some(timing); + + AckCredential::with_decorators(Uuid::new_v4().to_string(), content, decorators) +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Holder { holder_sm: HolderSM, @@ -83,17 +99,17 @@ impl Holder { Ok(()) } + // todo 0109: send ack/problem-report in upper layer pub async fn process_credential( &mut self, ledger: &Arc, anoncreds: &Arc, credential: IssueCredential, - send_message: SendClosure, ) -> VcxResult<()> { self.holder_sm = self .holder_sm .clone() - .receive_credential(ledger, anoncreds, credential, send_message) + .receive_credential(ledger, anoncreds, credential) .await?; Ok(()) } @@ -197,25 +213,21 @@ impl Holder { self.holder_sm.get_problem_report() } + // todo 0109: send ack/problem-report in upper layer pub async fn process_aries_msg( &mut self, ledger: &Arc, anoncreds: &Arc, message: AriesMessage, - send_message: Option, ) -> VcxResult<()> { let holder_sm = match message { AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(offer)) => { self.holder_sm.clone().receive_offer(offer)? } AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(credential)) => { - let send_message = send_message.ok_or(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - "Attempted to call undefined send_message callback", - ))?; self.holder_sm .clone() - .receive_credential(ledger, anoncreds, credential, send_message) + .receive_credential(ledger, anoncreds, credential) .await? } AriesMessage::ReportProblem(report) => self.holder_sm.clone().receive_problem_report(report)?, @@ -224,4 +236,36 @@ impl Holder { self.holder_sm = holder_sm; Ok(()) } + + // While we have removed message sending logic from state machine layer, we still want to preserve + // the logic on the upper layers (vcx, rust-agent, ...) + // Instead of having to reimplement the message sending logic on upper layers, this provide shared + // reusable logic. Yet this is just helper function, and should not be used in tests or any new code. + // + // This function is mean to be called after processing a message. Currently the state machines + // mutate themselves and after processing the message, the state machine might be in subsequent state, + // or might be in Failed state. + // Based on what state is, different reply shall be sent to counterparty. This function handles these cases. + #[deprecated] + pub async fn try_reply(&mut self, send_message: SendClosure, last_message: AriesMessage) -> VcxResult<()> { + match self.get_state() { + HolderState::Failed => { + let problem_report = self.get_problem_report()?; + send_message(problem_report.into()).await?; + } + HolderState::Finished => match last_message { + AriesMessage::CredentialIssuance(message) => match message { + CredentialIssuance::IssueCredential(message) => { + if message.decorators.please_ack.is_some() { + send_message(build_credential_ack(&self.get_thread_id()?).into()); + } + } + _ => {} + }, + _ => {} + }, + _ => {} + } + Ok(()) + } } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 36a499e8a1..598e037618 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -87,16 +87,6 @@ fn _build_credential_request_msg(credential_request_attach: String, thread_id: & RequestCredential::with_decorators(Uuid::new_v4().to_string(), content, decorators) } -fn build_credential_ack(thread_id: &str) -> AckCredential { - let content = AckCredentialContent::new(AckStatus::Ok); - let mut decorators = AckDecorators::new(Thread::new(thread_id.to_owned())); - let mut timing = Timing::default(); - timing.out_time = Some(Utc::now()); - decorators.timing = Some(timing); - - AckCredential::with_decorators(Uuid::new_v4().to_string(), content, decorators) -} - impl HolderSM { pub fn new(source_id: String) -> Self { HolderSM { @@ -270,7 +260,6 @@ impl HolderSM { ledger: &'a Arc, anoncreds: &'a Arc, credential: IssueCredential, - send_message: SendClosure, ) -> VcxResult { let state = match self.state { HolderFullState::RequestSet(state_data) => { @@ -284,19 +273,11 @@ impl HolderSM { .await { Ok((cred_id, rev_reg_def_json)) => { - if credential.decorators.please_ack.is_some() { - let ack = build_credential_ack(&self.thread_id); - send_message(ack.into()).await?; - } HolderFullState::Finished((state_data, cred_id, credential, rev_reg_def_json).into()) } Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); - error!( - "Failed to process or save received credential, sending problem report: {:?}", - problem_report - ); - send_message(problem_report.clone().into()).await?; + error!("Failed to process or save received credential: {problem_report:?}"); HolderFullState::Finished(FinishedHolderState::new(problem_report)) } } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 3cbb4538e7..a2918259bf 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -118,7 +118,6 @@ pub async fn credential_create_with_msgid( pub async fn update_state(credential_handle: u32, message: Option<&str>, connection_handle: u32) -> LibvcxResult { let mut credential = HANDLE_MAP.get_cloned(credential_handle)?; - let profile = get_main_profile(); trace!("credential::update_state >>> "); if credential.is_terminal_state() { @@ -126,33 +125,37 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect } let send_message = mediated_connection::send_message_closure(connection_handle).await?; - if let Some(message) = message { + let (mediator_uid, aries_msg) = if let Some(message) = message { let message: AriesMessage = serde_json::from_str(message).map_err(|err| { LibvcxError::from_msg( LibvcxErrorKind::InvalidOption, format!("Cannot update state: Message deserialization failed: {:?}", err), ) })?; - credential - .process_aries_msg( - &get_main_anoncreds_ledger_read()?, - &get_main_anoncreds()?, - message.into(), - Some(send_message), - ) - .await?; + (None, Some(message)) } else { let messages = mediated_connection::get_messages(connection_handle).await?; - if let Some((uid, msg)) = holder_find_message_to_handle(&credential, messages) { + match holder_find_message_to_handle(&credential, messages) { + None => (None, None), + Some((uid, msg)) => (Some(uid), Some(msg)), + } + }; + match aries_msg { + None => { + trace!("credential::update_state >>> no suitable messages found to progress the protocol"); + } + Some(aries_msg) => { credential .process_aries_msg( &get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, - msg.into(), - Some(send_message), + aries_msg.clone(), ) .await?; - mediated_connection::update_message_status(connection_handle, &uid).await?; + if let Some(uid) = mediator_uid { + mediated_connection::update_message_status(connection_handle, &uid).await?; + } + credential.try_reply(send_message, aries_msg).await?; } } let state = credential.get_state().into(); From 6187799acc78f87988aac6d33e0dc29b6d1bce2d Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 12:56:49 +0200 Subject: [PATCH 32/40] holder: eliminate 'send_credential_request' in favor of 'get_msg_credential_request'; rename 'build_credential_request' to 'prepare_credential_request' Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 5 +++-- aries_vcx/src/handlers/issuance/holder.rs | 22 ++++++++++++++----- .../issuance/holder/state_machine.rs | 21 +----------------- aries_vcx/tests/test_creds_proofs.rs | 10 +++++---- aries_vcx/tests/utils/devsetup_alice.rs | 5 +++-- aries_vcx/tests/utils/scenarios.rs | 10 +++++---- .../src/api_vcx/api_handle/credential.rs | 5 +++-- 7 files changed, 38 insertions(+), 40 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index db030ec0dc..8a05a252ef 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -98,7 +98,7 @@ impl ServiceCredentialsHolder { Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) }); holder - .build_credential_request( + .prepare_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), pw_did, @@ -110,7 +110,8 @@ impl ServiceCredentialsHolder { send_closure(problem_report.into()).await?; } _ => { - holder.send_credential_request(send_closure).await?; + let credential_request = holder.get_msg_credential_request()?; + send_closure(credential_request.into()).await?; } } self.creds_holder diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 2d6fe08d62..0fc1fb6fb7 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -11,6 +11,7 @@ use messages::msg_fields::protocols::cred_issuance::ack::{AckCredential, AckCred use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; use messages::msg_fields::protocols::cred_issuance::propose_credential::ProposeCredential; +use messages::msg_fields::protocols::cred_issuance::request_credential::RequestCredential; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use messages::msg_fields::protocols::notification::ack::{AckDecorators, AckStatus}; use messages::msg_fields::protocols::report_problem::ProblemReport; @@ -21,7 +22,7 @@ use crate::common::credentials::get_cred_rev_id; use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::revocation_notification::receiver::RevocationNotificationReceiver; -use crate::protocols::issuance::holder::state_machine::{HolderSM, HolderState}; +use crate::protocols::issuance::holder::state_machine::{HolderFullState, HolderSM, HolderState}; use crate::protocols::SendClosure; fn build_credential_ack(thread_id: &str) -> AckCredential { @@ -72,7 +73,7 @@ impl Holder { } // todo: is the my_pw_did really necessary? is it used under the hood? - pub async fn build_credential_request( + pub async fn prepare_credential_request( &mut self, ledger: &Arc, anoncreds: &Arc, @@ -81,13 +82,23 @@ impl Holder { self.holder_sm = self .holder_sm .clone() - .build_credential_request(ledger, anoncreds, my_pw_did) + .prepare_credential_request(ledger, anoncreds, my_pw_did) .await?; Ok(()) } - pub async fn send_credential_request(&mut self, send_message: SendClosure) -> VcxResult<()> { - self.holder_sm.send_credential_request(send_message).await + // ultimately this will be eliminated, as with state pattern, state transition will yield reply message + pub fn get_msg_credential_request(&mut self) -> VcxResult { + match self.holder_sm.state { + HolderFullState::RequestSet(ref state) => { + let mut msg: RequestCredential = state.msg_credential_request.clone().into(); + let mut timing = Timing::default(); + timing.out_time = Some(Utc::now()); + msg.decorators.timing = Some(timing); + Ok(msg) + } + _ => Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")), + } } pub async fn decline_offer<'a>(&'a mut self, comment: Option<&'a str>, send_message: SendClosure) -> VcxResult<()> { @@ -99,7 +110,6 @@ impl Holder { Ok(()) } - // todo 0109: send ack/problem-report in upper layer pub async fn process_credential( &mut self, ledger: &Arc, diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 598e037618..0e002d73e5 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -179,7 +179,7 @@ impl HolderSM { Ok(Self { state, ..self }) } - pub async fn build_credential_request<'a>( + pub async fn prepare_credential_request<'a>( self, ledger: &'a Arc, anoncreds: &'a Arc, @@ -221,25 +221,6 @@ impl HolderSM { Ok(Self { state, ..self }) } - #[deprecated] - // convenience function for sending the credential request. This will be removed in the future - // and some form of replacement will be provided instead outside of state machines. - pub async fn send_credential_request(&self, send_message: SendClosure) -> VcxResult<()> { - match self.state { - HolderFullState::RequestSet(ref state) => { - let mut msg: RequestCredential = state.msg_credential_request.clone().into(); - let mut timing = Timing::default(); - timing.out_time = Some(Utc::now()); - msg.decorators.timing = Some(timing); - send_message(msg.into()).await?; - } - _ => { - return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); - } - }; - Ok(()) - } - pub async fn decline_offer(self, comment: Option, send_message: SendClosure) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(_) => { diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 1e504b16a9..f5a6c437f6 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -1711,14 +1711,15 @@ mod tests { .unwrap(); alice .credential - .build_credential_request( + .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), pw_did, ) .await .unwrap(); - alice.credential.send_credential_request(send_closure).await.unwrap(); + let request = alice.credential.get_msg_credential_request().unwrap(); + send_closure(request.into()).await.unwrap(); assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } @@ -1820,14 +1821,15 @@ mod tests { let pw_did = alice.connection.pairwise_info().pw_did.to_string(); alice .credential - .build_credential_request( + .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), pw_did, ) .await .unwrap(); - alice.credential.send_credential_request(send_closure).await.unwrap(); + let request = alice.credential.get_msg_credential_request().unwrap(); + send_closure(request.into()).await.unwrap(); assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index 81109b21ee..ceedd05064 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -184,14 +184,15 @@ impl Alice { let pw_did = self.connection.pairwise_info().pw_did.to_string(); self.credential - .build_credential_request( + .prepare_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), pw_did, ) .await .unwrap(); - self.credential.send_credential_request(send_closure).await.unwrap(); + let request = self.credential.get_msg_credential_request().unwrap(); + send_closure(request.into()).await.unwrap(); assert_eq!(HolderState::RequestSet, self.credential.get_state()); } diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 12146da3ba..bc53be6870 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -281,14 +281,15 @@ pub mod test_utils { .await .unwrap(); holder - .build_credential_request( + .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), my_pw_did, ) .await .unwrap(); - holder.send_credential_request(send_closure).await.unwrap(); + let request = holder.get_msg_credential_request().unwrap(); + send_closure(request.into()).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; holder } @@ -500,14 +501,15 @@ pub mod test_utils { .await .unwrap(); holder - .build_credential_request( + .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), my_pw_did, ) .await .unwrap(); - holder.send_credential_request(send_closure).await.unwrap(); + let request = holder.get_msg_credential_request().unwrap(); + send_closure(request.into()).await.unwrap(); assert_eq!(HolderState::RequestSet, holder.get_state()); } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index a2918259bf..87662bcb94 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -236,7 +236,7 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib let my_pw_did = mediated_connection::get_pw_did(connection_handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; credential - .build_credential_request(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, my_pw_did) + .prepare_credential_request(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, my_pw_did) .await?; match credential.get_state() { HolderState::Failed => { @@ -244,7 +244,8 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib send_message(problem_report.into()).await?; } _ => { - credential.send_credential_request(send_message).await?; + let request = credential.get_msg_credential_request()?; + send_message(request.into()).await?; } } HANDLE_MAP.insert(handle, credential) From c2f334e90c54d0438870a48dcaca34edda51b32d Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 13:21:53 +0200 Subject: [PATCH 33/40] holder: remove msg sending from decline_offer Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/holder.rs | 10 +++------- .../src/protocols/issuance/holder/state_machine.rs | 3 +-- aries_vcx/tests/utils/scenarios.rs | 12 ++++-------- libvcx_core/src/api_vcx/api_handle/credential.rs | 3 ++- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 0fc1fb6fb7..a40e3d81ae 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -101,13 +101,9 @@ impl Holder { } } - pub async fn decline_offer<'a>(&'a mut self, comment: Option<&'a str>, send_message: SendClosure) -> VcxResult<()> { - self.holder_sm = self - .holder_sm - .clone() - .decline_offer(comment.map(String::from), send_message) - .await?; - Ok(()) + pub fn decline_offer<'a>(&'a mut self, comment: Option<&'a str>) -> VcxResult { + self.holder_sm = self.holder_sm.clone().decline_offer(comment.map(String::from))?; + self.get_problem_report() } pub async fn process_credential( diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 0e002d73e5..2c3c306299 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -221,11 +221,10 @@ impl HolderSM { Ok(Self { state, ..self }) } - pub async fn decline_offer(self, comment: Option, send_message: SendClosure) -> VcxResult { + pub async fn decline_offer(self, comment: Option) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(_) => { let problem_report = build_problem_report_msg(comment, &self.thread_id); - send_message(problem_report.clone().into()).await?; HolderFullState::Finished(FinishedHolderState::new(problem_report)) } s => { diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index bc53be6870..f73b3fb832 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -525,16 +525,12 @@ pub mod test_utils { .await .unwrap(); assert_eq!(HolderState::OfferReceived, holder.get_state()); - holder - .decline_offer( - Some("Have a nice day"), - connection - .send_message_closure(alice.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_message = connection + .send_message_closure(alice.profile.inject_wallet()) .await .unwrap(); + let problem_report = holder.decline_offer(Some("Have a nice day")).unwrap(); + send_message(problem_report.into()).await.unwrap(); assert_eq!(HolderState::Failed, holder.get_state()); } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 87662bcb94..df8a71ffce 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -367,7 +367,8 @@ pub fn get_thread_id(handle: u32) -> LibvcxResult { pub async fn decline_offer(handle: u32, connection_handle: u32, comment: Option<&str>) -> LibvcxResult<()> { let mut credential = HANDLE_MAP.get_cloned(handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; - credential.decline_offer(comment, send_message).await?; + let problem_report = credential.decline_offer(comment).await?; + send_message(problem_report.into()).await?; HANDLE_MAP.insert(handle, credential) } From af2c7d3186b799a903a35ab0e00e60ec18bcb27b Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 13:41:16 +0200 Subject: [PATCH 34/40] Fix compile errs Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 16 +++------ aries_vcx/src/handlers/issuance/holder.rs | 33 ++++++++++++++----- .../issuance/holder/state_machine.rs | 2 +- aries_vcx/tests/utils/devsetup_util.rs | 4 +-- .../src/api_vcx/api_handle/credential.rs | 4 +-- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 8a05a252ef..88194bbcc7 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -104,16 +104,8 @@ impl ServiceCredentialsHolder { pw_did, ) .await?; - match holder.get_state() { - HolderState::Failed => { - let problem_report = holder.get_problem_report()?; - send_closure(problem_report.into()).await?; - } - _ => { - let credential_request = holder.get_msg_credential_request()?; - send_closure(credential_request.into()).await?; - } - } + + holder.try_reply(send_closure, None).await; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } @@ -139,7 +131,9 @@ impl ServiceCredentialsHolder { msg_issue_credential.clone(), ) .await?; - holder.try_reply(send_closure, msg_issue_credential.into()).await?; + holder + .try_reply(send_closure, Some(msg_issue_credential.into())) + .await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index a40e3d81ae..9214e38d0c 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -88,7 +88,7 @@ impl Holder { } // ultimately this will be eliminated, as with state pattern, state transition will yield reply message - pub fn get_msg_credential_request(&mut self) -> VcxResult { + pub fn get_msg_credential_request(&self) -> VcxResult { match self.holder_sm.state { HolderFullState::RequestSet(ref state) => { let mut msg: RequestCredential = state.msg_credential_request.clone().into(); @@ -253,24 +253,39 @@ impl Holder { // or might be in Failed state. // Based on what state is, different reply shall be sent to counterparty. This function handles these cases. #[deprecated] - pub async fn try_reply(&mut self, send_message: SendClosure, last_message: AriesMessage) -> VcxResult<()> { + pub async fn try_reply(&self, send_message: SendClosure, last_message: Option) -> VcxResult<()> { match self.get_state() { HolderState::Failed => { let problem_report = self.get_problem_report()?; send_message(problem_report.into()).await?; } HolderState::Finished => match last_message { - AriesMessage::CredentialIssuance(message) => match message { - CredentialIssuance::IssueCredential(message) => { - if message.decorators.please_ack.is_some() { - send_message(build_credential_ack(&self.get_thread_id()?).into()); + // todo: add please_ack flag to state machine so we don't have to provide last_message arg to this function + None => { + return Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + "Holder::try_reply called, but expected to be provided last received message", + )) + } + Some(last_message) => match last_message { + AriesMessage::CredentialIssuance(message) => match message { + CredentialIssuance::IssueCredential(message) => { + if message.decorators.please_ack.is_some() { + send_message(build_credential_ack(&self.get_thread_id()?).into()); + } } - } + _ => {} + }, _ => {} }, - _ => {} }, - _ => {} + HolderState::Initial => {} + HolderState::ProposalSet => {} + HolderState::OfferReceived => {} + HolderState::RequestSet => { + let credential_request = self.get_msg_credential_request()?; + send_message(credential_request.into()).await?; + } } Ok(()) } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 2c3c306299..60beb2bf8c 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -221,7 +221,7 @@ impl HolderSM { Ok(Self { state, ..self }) } - pub async fn decline_offer(self, comment: Option) -> VcxResult { + pub fn decline_offer(self, comment: Option) -> VcxResult { let state = match self.state { HolderFullState::OfferReceived(_) => { let problem_report = build_problem_report_msg(comment, &self.thread_id); diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index 69bbb11255..845bb0e21e 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -165,9 +165,9 @@ pub async fn holder_update_with_mediator( let messages = connection.get_messages(agency_client).await?; if let Some((uid, msg)) = mediated_holder::holder_find_message_to_handle(sm, messages) { - sm.process_aries_msg(ledger, anoncreds, msg.into(), Some(send_message)) - .await?; + sm.process_aries_msg(ledger, anoncreds, msg.clone()).await?; connection.update_message_status(&uid, agency_client).await?; + sm.try_reply(send_message, Some(msg)).await?; } Ok(sm.get_state()) } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index df8a71ffce..28cf9ed532 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -155,7 +155,7 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect if let Some(uid) = mediator_uid { mediated_connection::update_message_status(connection_handle, &uid).await?; } - credential.try_reply(send_message, aries_msg).await?; + credential.try_reply(send_message, Some(aries_msg)).await?; } } let state = credential.get_state().into(); @@ -367,7 +367,7 @@ pub fn get_thread_id(handle: u32) -> LibvcxResult { pub async fn decline_offer(handle: u32, connection_handle: u32, comment: Option<&str>) -> LibvcxResult<()> { let mut credential = HANDLE_MAP.get_cloned(handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let problem_report = credential.decline_offer(comment).await?; + let problem_report = credential.decline_offer(comment)?; send_message(problem_report.into()).await?; HANDLE_MAP.insert(handle, credential) } From e3b7e1bc5389e33e20b21afb69fa20f16d67ac84 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 16:23:44 +0200 Subject: [PATCH 35/40] Holder: fix: make sure to send ack message if requested Signed-off-by: Patrik Stas --- agents/node/vcxagent-core/demo/alice.js | 2 +- agents/node/vcxagent-core/demo/faber.js | 4 +++- agents/node/vcxagent-core/demo/logger.js | 3 ++- .../src/services/service-cred-issuer.js | 4 +++- .../aries-vcx-agent/src/services/holder.rs | 2 +- aries_vcx/src/handlers/issuance/holder.rs | 20 ++++++++++++++++--- .../issuance/holder/state_machine.rs | 6 ++++++ .../issuance/issuer/state_machine.rs | 1 + .../src/api_vcx/api_handle/credential.rs | 1 + 9 files changed, 35 insertions(+), 8 deletions(-) diff --git a/agents/node/vcxagent-core/demo/alice.js b/agents/node/vcxagent-core/demo/alice.js index 88add09da9..5b3b0df949 100644 --- a/agents/node/vcxagent-core/demo/alice.js +++ b/agents/node/vcxagent-core/demo/alice.js @@ -41,7 +41,7 @@ async function getInvitationString (fetchInviteUrl) { } async function runAlice (options) { - logger.info('Starting.') + logger.info('Starting alice.') initRustLogger(process.env.RUST_LOG || 'vcx=error') const agentName = `alice-${uuid.v4()}` diff --git a/agents/node/vcxagent-core/demo/faber.js b/agents/node/vcxagent-core/demo/faber.js index 5b85336563..8a03749fc4 100644 --- a/agents/node/vcxagent-core/demo/faber.js +++ b/agents/node/vcxagent-core/demo/faber.js @@ -17,7 +17,7 @@ const { testTailsUrl, initRustLogger } = require('../src') const tailsDir = '/tmp/tails' async function runFaber (options) { - logger.info(`Starting. Revocation enabled=${options.revocation}`) + logger.info(`Starting Faber. Revocation enabled=${options.revocation}`) initRustLogger(process.env.RUST_LOG || 'vcx=error') let faberServer @@ -84,7 +84,9 @@ async function runFaber (options) { const schemaAttrs = getAliceSchemaAttrs() await vcxAgent.serviceCredIssuer.sendOfferAndCredential(issuerCredId, revRegId, connectionId, credDefId, schemaAttrs) if (options.revocation === true) { + logger.info('Faber is revoking issued credential') await vcxAgent.serviceCredIssuer.revokeCredentialLocal(issuerCredId) + logger.info('Faber is publishing revocation') await revReg.publishRevocations() } diff --git a/agents/node/vcxagent-core/demo/logger.js b/agents/node/vcxagent-core/demo/logger.js index 1968ec8903..c4441099ec 100644 --- a/agents/node/vcxagent-core/demo/logger.js +++ b/agents/node/vcxagent-core/demo/logger.js @@ -5,7 +5,7 @@ const prettyFormatter = format.combine( format.printf( msg => { const extras = (global.expect) ? `${global.expect.getState().currentTestName}` : '' - return `[${msg.timestamp}] [${msg.filename}] [${msg.level}] ${extras}: ${msg.message}` + return `[${msg.timestamp}] [${msg.filename}] [${msg.label}] [${msg.level}] ${extras}: ${msg.message}` } ) ) @@ -14,6 +14,7 @@ module.exports = loggerLabel => { return createLogger({ level: 'debug', format: format.combine( + format.label({ label: loggerLabel }), format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), diff --git a/agents/node/vcxagent-core/src/services/service-cred-issuer.js b/agents/node/vcxagent-core/src/services/service-cred-issuer.js index a1877f78cd..b9ad7b9ddb 100644 --- a/agents/node/vcxagent-core/src/services/service-cred-issuer.js +++ b/agents/node/vcxagent-core/src/services/service-cred-issuer.js @@ -103,9 +103,11 @@ module.exports.createServiceCredIssuer = function createServiceCredIssuer ({ log async function _progressIssuerCredentialToState (issuerCredential, connection, credentialStateTarget, attemptsThreshold, timeoutMs) { async function progressToAcceptedState () { - if (await issuerCredential.updateStateV2(connection) !== credentialStateTarget) { + const currentState = await issuerCredential.updateStateV2(connection) + if (currentState !== credentialStateTarget) { return { result: undefined, isFinished: false } } else { + logger.debug(`Cred issuer: _progressIssuerCredentialToState, currentState: ${currentState}, credentialStateTarget: ${credentialStateTarget}`) return { result: null, isFinished: true } } } diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 88194bbcc7..b103654702 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -105,7 +105,7 @@ impl ServiceCredentialsHolder { ) .await?; - holder.try_reply(send_closure, None).await; + holder.try_reply(send_closure, None).await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 9214e38d0c..142e2394ed 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -254,6 +254,7 @@ impl Holder { // Based on what state is, different reply shall be sent to counterparty. This function handles these cases. #[deprecated] pub async fn try_reply(&self, send_message: SendClosure, last_message: Option) -> VcxResult<()> { + trace!("Holder::try_reply >>> trying to send reply to counterparty"); match self.get_state() { HolderState::Failed => { let problem_report = self.get_problem_report()?; @@ -270,13 +271,26 @@ impl Holder { Some(last_message) => match last_message { AriesMessage::CredentialIssuance(message) => match message { CredentialIssuance::IssueCredential(message) => { + trace!("Holder::try_reply >>> checking if counterparty requested credential ack"); if message.decorators.please_ack.is_some() { - send_message(build_credential_ack(&self.get_thread_id()?).into()); + let ack_msg = build_credential_ack(&self.get_thread_id()?); + trace!("Holder::try_reply >>> sending credential ack"); + send_message(ack_msg.into()).await?; } } - _ => {} + _ => { + return Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + "Holder::try_reply called, but unexpected last message type was supplied", + )) + } }, - _ => {} + _ => { + return Err(AriesVcxError::from_msg( + AriesVcxErrorKind::InvalidState, + "Holder::try_reply called, but unexpected last message family was supplied", + )) + } }, }, HolderState::Initial => {} diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 60beb2bf8c..d95aa197c7 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -141,6 +141,7 @@ impl HolderSM { } pub fn set_proposal(self, proposal: ProposeCredential) -> VcxResult { + trace!("HolderSM::set_proposal >>"); verify_thread_id( &self.thread_id, &AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(proposal.clone())), @@ -165,6 +166,7 @@ impl HolderSM { } pub fn receive_offer(self, offer: OfferCredential) -> VcxResult { + trace!("HolderSM::receive_offer >>"); verify_thread_id( &self.thread_id, &AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(offer.clone())), @@ -185,6 +187,7 @@ impl HolderSM { anoncreds: &'a Arc, my_pw_did: String, ) -> VcxResult { + trace!("HolderSM::prepare_credential_request >>"); let state = match self.state { HolderFullState::OfferReceived(state_data) => { match build_credential_request_msg( @@ -222,6 +225,7 @@ impl HolderSM { } pub fn decline_offer(self, comment: Option) -> VcxResult { + trace!("HolderSM::decline_offer >>"); let state = match self.state { HolderFullState::OfferReceived(_) => { let problem_report = build_problem_report_msg(comment, &self.thread_id); @@ -241,6 +245,7 @@ impl HolderSM { anoncreds: &'a Arc, credential: IssueCredential, ) -> VcxResult { + trace!("HolderSM::receive_credential >>"); let state = match self.state { HolderFullState::RequestSet(state_data) => { match _store_credential( @@ -271,6 +276,7 @@ impl HolderSM { } pub fn receive_problem_report(self, problem_report: ProblemReport) -> VcxResult { + warn!("HolderSM::receive_problem_report >> problem_report: {problem_report:?}"); let state = match self.state { HolderFullState::ProposalSet(_) | HolderFullState::RequestSet(_) => { HolderFullState::Finished(FinishedHolderState::new(problem_report)) diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index d50bb6f408..3c9b37d7c8 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -354,6 +354,7 @@ impl IssuerSM { match self.state { IssuerFullState::OfferSet(ref state_data) => { let cred_offer_msg = state_data.offer.clone().into(); + trace!("IssuerSM::send_credential_offer >> sending credential offer message"); send_message(cred_offer_msg).await?; } _ => { diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 28cf9ed532..e2f3b9dcea 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -153,6 +153,7 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect ) .await?; if let Some(uid) = mediator_uid { + trace!("credential::update_state >>> updating messages status in mediator"); mediated_connection::update_message_status(connection_handle, &uid).await?; } credential.try_reply(send_message, Some(aries_msg)).await?; From 2a569c57e499d4285eaa821026a6c9a0d87bae30 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 16:44:46 +0200 Subject: [PATCH 36/40] isser: remove usage of SendClosure Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/issuer.rs | 6 ++- aries_vcx/src/handlers/issuance/issuer.rs | 13 ++--- .../issuance/issuer/state_machine.rs | 35 +++---------- aries_vcx/tests/utils/devsetup_faber.rs | 15 +++--- aries_vcx/tests/utils/scenarios.rs | 50 ++++++++----------- .../api_vcx/api_handle/issuer_credential.rs | 14 ++++-- 6 files changed, 50 insertions(+), 83 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/issuer.rs b/agents/rust/aries-vcx-agent/src/services/issuer.rs index 5c7c09652f..78b515cdb1 100644 --- a/agents/rust/aries-vcx-agent/src/services/issuer.rs +++ b/agents/rust/aries-vcx-agent/src/services/issuer.rs @@ -84,7 +84,8 @@ impl ServiceCredentialsIssuer { Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) }); - issuer.send_credential_offer(send_closure).await?; + let credential_offer = issuer.get_credential_offer_msg()?; + send_closure(credential_offer).await?; self.creds_issuer .insert(&issuer.get_thread_id()?, IssuerWrapper::new(issuer, &connection_id)) } @@ -131,7 +132,8 @@ impl ServiceCredentialsIssuer { send_closure(problem_report.into()).await?; } _ => { - issuer.send_credential(send_closure).await?; + let msg_issue_credential = issuer.get_msg_issue_credential()?; + send_closure(msg_issue_credential.into()).await?; } } self.creds_issuer diff --git a/aries_vcx/src/handlers/issuance/issuer.rs b/aries_vcx/src/handlers/issuance/issuer.rs index a657df950c..0acffcc48f 100644 --- a/aries_vcx/src/handlers/issuance/issuer.rs +++ b/aries_vcx/src/handlers/issuance/issuer.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; +use messages::msg_fields::protocols::cred_issuance::issue_credential::IssueCredential; use messages::msg_fields::protocols::notification::Notification; use messages::msg_fields::protocols::report_problem::ProblemReport; use messages::msg_parts::MsgParts; @@ -15,7 +16,6 @@ use messages::msg_parts::MsgParts; use crate::errors::error::prelude::*; use crate::handlers::util::OfferInfo; use crate::protocols::issuance::issuer::state_machine::{IssuerSM, IssuerState, RevocationInfoV1}; -use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Issuer { @@ -146,12 +146,6 @@ impl Issuer { Ok(offer.into()) } - #[deprecated] - pub async fn send_credential_offer(&mut self, send_message: SendClosure) -> VcxResult<()> { - self.issuer_sm.clone().send_credential_offer(send_message).await?; - Ok(()) - } - pub fn process_credential_request(&mut self, request: RequestCredential) -> VcxResult<()> { self.issuer_sm = self.issuer_sm.clone().receive_request(request)?; Ok(()) @@ -167,9 +161,8 @@ impl Issuer { Ok(()) } - #[deprecated] - pub async fn send_credential(&mut self, send_message: SendClosure) -> VcxResult<()> { - self.issuer_sm.clone().send_credential(send_message).await + pub fn get_msg_issue_credential(&mut self) -> VcxResult { + self.issuer_sm.clone().get_msg_issue_credential() } pub fn get_state(&self) -> IssuerState { diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index 3c9b37d7c8..dc7d731071 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -347,23 +347,6 @@ impl IssuerSM { }) } - #[deprecated] - // Convenience function for sending the credential offer. This will be removed in the future - // and some form of replacement will be provided instead outside of state machines. - pub async fn send_credential_offer(self, send_message: SendClosure) -> VcxResult<()> { - match self.state { - IssuerFullState::OfferSet(ref state_data) => { - let cred_offer_msg = state_data.offer.clone().into(); - trace!("IssuerSM::send_credential_offer >> sending credential offer message"); - send_message(cred_offer_msg).await?; - } - _ => { - return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); - } - }; - Ok(()) - } - pub fn receive_request(self, request: RequestCredential) -> VcxResult { verify_thread_id( &self.thread_id, @@ -425,23 +408,17 @@ impl IssuerSM { Ok(Self { state, ..self }) } - #[deprecated] - // Convenience function for sending the credential. This will be removed in the future - // and some form of replacement will be provided instead outside of state machines. - pub async fn send_credential(self, send_message: SendClosure) -> VcxResult<()> { + pub fn get_msg_issue_credential(self) -> VcxResult { match self.state { IssuerFullState::CredentialSet(ref state_data) => { - let mut cred_offer_msg: IssueCredential = state_data.msg_issue_credential.clone().into(); + let mut msg_issue_credential: IssueCredential = state_data.msg_issue_credential.clone().into(); let mut timing = Timing::default(); timing.out_time = Some(Utc::now()); - cred_offer_msg.decorators.timing = Some(timing); - send_message(cred_offer_msg.into()).await?; - } - _ => { - return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")); + msg_issue_credential.decorators.timing = Some(timing); + Ok(msg_issue_credential) } - }; - Ok(()) + _ => Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action")), + } } pub fn receive_ack(self, ack: AckCredential) -> VcxResult { diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 0a42834313..b0e52dfd09 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -291,15 +291,13 @@ impl Faber { .build_credential_offer_msg(&self.profile.inject_anoncreds(), offer_info, None) .await .unwrap(); - self.issuer_credential - .send_credential_offer( - self.connection - .send_message_closure(self.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_message = self + .connection + .send_message_closure(self.profile.inject_wallet()) .await .unwrap(); + let credential_offer = self.issuer_credential.get_credential_offer_msg().unwrap(); + send_message(credential_offer).await.unwrap(); issuer_update_with_mediator(&mut self.issuer_credential, &self.agency_client, &self.connection) .await .unwrap(); @@ -321,7 +319,8 @@ impl Faber { .send_message_closure(self.profile.inject_wallet()) .await .unwrap(); - self.issuer_credential.send_credential(send_closure).await; + let msg_issue_credential = self.issuer_credential.get_msg_issue_credential().unwrap(); + send_closure(msg_issue_credential.into()).await.unwrap(); issuer_update_with_mediator(&mut self.issuer_credential, &self.agency_client, &self.connection) .await .unwrap(); diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index f73b3fb832..da0ee52d45 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -201,15 +201,13 @@ pub mod test_utils { .build_credential_offer_msg(&faber.profile.inject_anoncreds(), offer_info, comment.map(String::from)) .await .unwrap(); - issuer - .send_credential_offer( - connection - .send_message_closure(faber.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_closure = connection + .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); + let credential_offer = issuer.get_credential_offer_msg().unwrap(); + send_closure(credential_offer).await.unwrap(); + info!("create_and_send_nonrevocable_cred_offer :: credential offer was sent"); tokio::time::sleep(Duration::from_millis(1000)).await; issuer @@ -235,15 +233,12 @@ pub mod test_utils { .build_credential_offer_msg(&faber.profile.inject_anoncreds(), offer_info, comment.map(String::from)) .await .unwrap(); - issuer - .send_credential_offer( - connection - .send_message_closure(faber.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_closure = connection + .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); + let credential_offer = issuer.get_credential_offer_msg().unwrap(); + send_closure(credential_offer).await.unwrap(); info!("create_and_send_cred_offer :: credential offer was sent"); tokio::time::sleep(Duration::from_millis(1000)).await; issuer @@ -432,15 +427,13 @@ pub mod test_utils { .build_credential_offer_msg(&faber.profile.inject_anoncreds(), offer_info, Some("comment".into())) .await .unwrap(); - issuer - .send_credential_offer( - connection - .send_message_closure(faber.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_closure = connection + .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); + let credential_offer = issuer.get_credential_offer_msg().unwrap(); + send_closure(credential_offer).await.unwrap(); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); tokio::time::sleep(Duration::from_millis(1000)).await; issuer @@ -469,15 +462,13 @@ pub mod test_utils { .build_credential_offer_msg(&faber.profile.inject_anoncreds(), offer_info, Some("comment".into())) .await .unwrap(); - issuer - .send_credential_offer( - connection - .send_message_closure(faber.profile.inject_wallet()) - .await - .unwrap(), - ) + let send_closure = connection + .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); + let credential_offer = issuer.get_credential_offer_msg().unwrap(); + send_closure(credential_offer).await.unwrap(); + assert_eq!(IssuerState::OfferSet, issuer.get_state()); tokio::time::sleep(Duration::from_millis(1000)).await; } @@ -564,7 +555,8 @@ pub mod test_utils { .send_message_closure(faber.profile.inject_wallet()) .await .unwrap(); - issuer_credential.send_credential(send_closure).await; + let msg_issue_credential = issuer_credential.get_msg_issue_credential().unwrap(); + send_closure(msg_issue_credential.into()).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; assert_eq!(thread_id, issuer_credential.get_thread_id().unwrap()); diff --git a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs index 3706b860c0..172e0916e7 100644 --- a/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/issuer_credential.rs @@ -191,8 +191,9 @@ pub fn get_credential_offer_msg(handle: u32) -> LibvcxResult { pub async fn send_credential_offer_v2(credential_handle: u32, connection_handle: u32) -> LibvcxResult<()> { let mut credential = ISSUER_CREDENTIAL_MAP.get_cloned(credential_handle)?; - let send_message = mediated_connection::send_message_closure(connection_handle).await?; - credential.send_credential_offer(send_message).await?; + let send_closure = mediated_connection::send_message_closure(connection_handle).await?; + let credential_offer = credential.get_credential_offer_msg()?; + send_closure(credential_offer).await?; ISSUER_CREDENTIAL_MAP.insert(credential_handle, credential)?; Ok(()) } @@ -205,8 +206,9 @@ pub async fn send_credential_offer_nonmediated(credential_handle: u32, connectio let send_message: SendClosure = Box::new(|msg: AriesMessage| Box::pin(async move { con.send_message(&wallet, &msg, &HttpClient).await })); + let credential_offer = credential.get_credential_offer_msg()?; + send_message(credential_offer).await?; - credential.send_credential_offer(send_message).await?; ISSUER_CREDENTIAL_MAP.insert(credential_handle, credential)?; Ok(()) } @@ -221,7 +223,8 @@ pub async fn send_credential(handle: u32, connection_handle: u32) -> LibvcxResul send_closure(problem_report.into()).await?; } _ => { - credential.send_credential(send_closure).await?; + let msg_issue_credential = credential.get_msg_issue_credential()?; + send_closure(msg_issue_credential.into()).await?; } } let state: u32 = credential.get_state().into(); @@ -242,7 +245,8 @@ pub async fn send_credential_nonmediated(handle: u32, connection_handle: u32) -> send_closure(problem_report.into()).await?; } _ => { - credential.send_credential(send_closure).await?; + let msg_issue_credential = credential.get_msg_issue_credential()?; + send_closure(msg_issue_credential.into()).await?; } } let state: u32 = credential.get_state().into(); From a48ec8879d7fda4ed79cce35c463fbd7986cfd15 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 16:54:13 +0200 Subject: [PATCH 37/40] Edit todo notes Signed-off-by: Patrik Stas --- aries_vcx/src/handlers/issuance/holder.rs | 1 - aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 142e2394ed..ddf9f72f54 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -72,7 +72,6 @@ impl Holder { Ok(()) } - // todo: is the my_pw_did really necessary? is it used under the hood? pub async fn prepare_credential_request( &mut self, ledger: &Arc, diff --git a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs index aba2a23f1a..5fb2719225 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_anoncreds.rs @@ -119,6 +119,7 @@ impl BaseAnonCreds for MockAnoncreds { } } + // todo: change _prover_did argument, see: https://github.com/hyperledger/aries-vcx/issues/950 async fn prover_create_credential_req( &self, _prover_did: &str, From 8a1f084b989c2629c75a7a8a30de6e20d4d8404e Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 17:32:45 +0200 Subject: [PATCH 38/40] holder: Return response AriesMessage from prepare_credential_request Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 5 ++--- aries_vcx/src/handlers/issuance/holder.rs | 20 ++++++++++++------- .../issuance/holder/state_machine.rs | 7 +++---- .../issuance/issuer/state_machine.rs | 6 +----- aries_vcx/tests/test_creds_proofs.rs | 10 ++++------ aries_vcx/tests/utils/devsetup_alice.rs | 6 +++--- aries_vcx/tests/utils/scenarios.rs | 10 ++++------ .../src/api_vcx/api_handle/credential.rs | 13 ++---------- 8 files changed, 32 insertions(+), 45 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index b103654702..3a25df8a8f 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -97,15 +97,14 @@ impl ServiceCredentialsHolder { let send_closure: SendClosure = Box::new(|msg: AriesMessage| { Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) }); - holder + let msg_response = holder .prepare_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), pw_did, ) .await?; - - holder.try_reply(send_closure, None).await?; + send_closure(msg_response).await?; self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index ddf9f72f54..2a0a88e8da 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -77,16 +77,25 @@ impl Holder { ledger: &Arc, anoncreds: &Arc, my_pw_did: String, - ) -> VcxResult<()> { + ) -> VcxResult { self.holder_sm = self .holder_sm .clone() .prepare_credential_request(ledger, anoncreds, my_pw_did) .await?; - Ok(()) + match self.get_state() { + HolderState::Failed => { + Ok(self.get_problem_report()?.into()) + } + HolderState::RequestSet => { + Ok(self.get_msg_credential_request()?.into()) + } + _ => { + Err(AriesVcxError::from_msg(AriesVcxErrorKind::InvalidState, "Holder::prepare_credential_request >> reached unexpected state after calling prepare_credential_request")) + } + } } - // ultimately this will be eliminated, as with state pattern, state transition will yield reply message pub fn get_msg_credential_request(&self) -> VcxResult { match self.holder_sm.state { HolderFullState::RequestSet(ref state) => { @@ -295,10 +304,7 @@ impl Holder { HolderState::Initial => {} HolderState::ProposalSet => {} HolderState::OfferReceived => {} - HolderState::RequestSet => { - let credential_request = self.get_msg_credential_request()?; - send_message(credential_request.into()).await?; - } + HolderState::RequestSet => {} } Ok(()) } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index d95aa197c7..3e7b5cfb79 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -29,7 +29,6 @@ use crate::protocols::issuance::holder::states::initial::InitialHolderState; use crate::protocols::issuance::holder::states::offer_received::OfferReceivedState; use crate::protocols::issuance::holder::states::proposal_set::ProposalSetState; use crate::protocols::issuance::holder::states::request_set::RequestSetState; -use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum HolderFullState { @@ -158,7 +157,7 @@ impl HolderSM { HolderFullState::ProposalSet(ProposalSetState::new(proposal)) } s => { - warn!("Unable to send credential proposal in state {}", s); + warn!("Unable to set credential proposal in state {}", s); s } }; @@ -209,7 +208,7 @@ impl HolderSM { Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!( - "Failed to create credential request, sending problem report: {:?}", + "Failed to create credential request, generating problem report: {:?}", problem_report ); HolderFullState::Finished(FinishedHolderState::new(problem_report)) @@ -217,7 +216,7 @@ impl HolderSM { } } s => { - warn!("Unable to send credential request in state {}", s); + warn!("Unable to set credential request in state {}", s); s } }; diff --git a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs index dc7d731071..54f2c7d737 100644 --- a/aries_vcx/src/protocols/issuance/issuer/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/issuer/state_machine.rs @@ -35,7 +35,6 @@ use crate::protocols::issuance::issuer::states::initial::InitialIssuerState; use crate::protocols::issuance::issuer::states::offer_set::OfferSetState; use crate::protocols::issuance::issuer::states::proposal_received::ProposalReceivedState; use crate::protocols::issuance::issuer::states::requested_received::RequestReceivedState; -use crate::protocols::SendClosure; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum IssuerFullState { @@ -393,10 +392,7 @@ impl IssuerSM { // 2. Also create separate "Failed" state Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); - error!( - "Failed to create credential, generated problem report {:?}", - problem_report - ); + error!("Failed to create credential, generated problem report {problem_report:?}",); IssuerFullState::Finished(FinishedState::from_request_and_error(state_data, problem_report)) } } diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index f5a6c437f6..a2d2745563 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -1709,7 +1709,7 @@ mod tests { .send_message_closure(alice.profile.inject_wallet()) .await .unwrap(); - alice + let msg_response = alice .credential .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), @@ -1718,8 +1718,7 @@ mod tests { ) .await .unwrap(); - let request = alice.credential.get_msg_credential_request().unwrap(); - send_closure(request.into()).await.unwrap(); + send_closure(msg_response).await.unwrap(); assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } @@ -1819,7 +1818,7 @@ mod tests { .await .unwrap(); let pw_did = alice.connection.pairwise_info().pw_did.to_string(); - alice + let msg_response = alice .credential .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), @@ -1828,8 +1827,7 @@ mod tests { ) .await .unwrap(); - let request = alice.credential.get_msg_credential_request().unwrap(); - send_closure(request.into()).await.unwrap(); + send_closure(msg_response).await.unwrap(); assert_eq!(HolderState::RequestSet, alice.credential.get_state()); } diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index ceedd05064..505fcda3a0 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -183,7 +183,8 @@ impl Alice { .unwrap(); let pw_did = self.connection.pairwise_info().pw_did.to_string(); - self.credential + let msg_response = self + .credential .prepare_credential_request( &self.profile.inject_anoncreds_ledger_read(), &self.profile.inject_anoncreds(), @@ -191,8 +192,7 @@ impl Alice { ) .await .unwrap(); - let request = self.credential.get_msg_credential_request().unwrap(); - send_closure(request.into()).await.unwrap(); + send_closure(msg_response).await.unwrap(); assert_eq!(HolderState::RequestSet, self.credential.get_state()); } diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index da0ee52d45..ae9ef44b69 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -275,7 +275,7 @@ pub mod test_utils { .send_message_closure(alice.profile.inject_wallet()) .await .unwrap(); - holder + let msg_response = holder .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), @@ -283,8 +283,7 @@ pub mod test_utils { ) .await .unwrap(); - let request = holder.get_msg_credential_request().unwrap(); - send_closure(request.into()).await.unwrap(); + send_closure(msg_response).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; holder } @@ -491,7 +490,7 @@ pub mod test_utils { .send_message_closure(alice.profile.inject_wallet()) .await .unwrap(); - holder + let msg_response = holder .prepare_credential_request( &alice.profile.inject_anoncreds_ledger_read(), &alice.profile.inject_anoncreds(), @@ -499,8 +498,7 @@ pub mod test_utils { ) .await .unwrap(); - let request = holder.get_msg_credential_request().unwrap(); - send_closure(request.into()).await.unwrap(); + send_closure(msg_response).await.unwrap(); assert_eq!(HolderState::RequestSet, holder.get_state()); } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index e2f3b9dcea..4185810265 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -236,19 +236,10 @@ pub async fn send_credential_request(handle: u32, connection_handle: u32) -> Lib let mut credential = HANDLE_MAP.get_cloned(handle)?; let my_pw_did = mediated_connection::get_pw_did(connection_handle)?; let send_message = mediated_connection::send_message_closure(connection_handle).await?; - credential + let msg_response = credential .prepare_credential_request(&get_main_anoncreds_ledger_read()?, &get_main_anoncreds()?, my_pw_did) .await?; - match credential.get_state() { - HolderState::Failed => { - let problem_report = credential.get_problem_report()?; - send_message(problem_report.into()).await?; - } - _ => { - let request = credential.get_msg_credential_request()?; - send_message(request.into()).await?; - } - } + send_message(msg_response).await?; HANDLE_MAP.insert(handle, credential) } From 6e48283e2adae1d1d72aadc9a1918b466e2ff61a Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 17:56:14 +0200 Subject: [PATCH 39/40] Holder: Remove 'try_reply(..)', add 'get_final_message()' instead. Track whether ack was requested Signed-off-by: Patrik Stas --- .../aries-vcx-agent/src/services/holder.rs | 16 +++-- aries_vcx/src/handlers/issuance/holder.rs | 68 ++++--------------- .../issuance/holder/state_machine.rs | 13 +++- .../issuance/holder/states/finished.rs | 2 + .../issuance/holder/states/request_set.rs | 10 ++- aries_vcx/tests/utils/devsetup_util.rs | 10 ++- .../src/api_vcx/api_handle/credential.rs | 10 ++- 7 files changed, 55 insertions(+), 74 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index 3a25df8a8f..ca5bb6a27f 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -119,10 +119,6 @@ impl ServiceCredentialsHolder { let connection = self.service_connections.get_by_id(&connection_id)?; let wallet = self.profile.inject_wallet(); - let send_closure: SendClosure = Box::new(|msg: AriesMessage| { - Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) - }); - holder .process_credential( &self.profile.inject_anoncreds_ledger_read(), @@ -130,9 +126,15 @@ impl ServiceCredentialsHolder { msg_issue_credential.clone(), ) .await?; - holder - .try_reply(send_closure, Some(msg_issue_credential.into())) - .await?; + match holder.get_final_message() { + None => {} + Some(msg_response) => { + let send_closure: SendClosure = Box::new(|msg: AriesMessage| { + Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await }) + }); + send_closure(msg_response).await?; + } + } self.creds_holder .insert(&holder.get_thread_id()?, HolderWrapper::new(holder, &connection_id)) } diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 2a0a88e8da..56c4f9b141 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -23,7 +23,6 @@ use crate::errors::error::prelude::*; use crate::handlers::connection::mediated_connection::MediatedConnection; use crate::handlers::revocation_notification::receiver::RevocationNotificationReceiver; use crate::protocols::issuance::holder::state_machine::{HolderFullState, HolderSM, HolderState}; -use crate::protocols::SendClosure; fn build_credential_ack(thread_id: &str) -> AckCredential { let content = AckCredentialContent::new(AckStatus::Ok); @@ -251,61 +250,18 @@ impl Holder { Ok(()) } - // While we have removed message sending logic from state machine layer, we still want to preserve - // the logic on the upper layers (vcx, rust-agent, ...) - // Instead of having to reimplement the message sending logic on upper layers, this provide shared - // reusable logic. Yet this is just helper function, and should not be used in tests or any new code. - // - // This function is mean to be called after processing a message. Currently the state machines - // mutate themselves and after processing the message, the state machine might be in subsequent state, - // or might be in Failed state. - // Based on what state is, different reply shall be sent to counterparty. This function handles these cases. - #[deprecated] - pub async fn try_reply(&self, send_message: SendClosure, last_message: Option) -> VcxResult<()> { - trace!("Holder::try_reply >>> trying to send reply to counterparty"); - match self.get_state() { - HolderState::Failed => { - let problem_report = self.get_problem_report()?; - send_message(problem_report.into()).await?; - } - HolderState::Finished => match last_message { - // todo: add please_ack flag to state machine so we don't have to provide last_message arg to this function - None => { - return Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - "Holder::try_reply called, but expected to be provided last received message", - )) - } - Some(last_message) => match last_message { - AriesMessage::CredentialIssuance(message) => match message { - CredentialIssuance::IssueCredential(message) => { - trace!("Holder::try_reply >>> checking if counterparty requested credential ack"); - if message.decorators.please_ack.is_some() { - let ack_msg = build_credential_ack(&self.get_thread_id()?); - trace!("Holder::try_reply >>> sending credential ack"); - send_message(ack_msg.into()).await?; - } - } - _ => { - return Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - "Holder::try_reply called, but unexpected last message type was supplied", - )) - } - }, - _ => { - return Err(AriesVcxError::from_msg( - AriesVcxErrorKind::InvalidState, - "Holder::try_reply called, but unexpected last message family was supplied", - )) + pub fn get_final_message(&self) -> Option { + match &self.holder_sm.state { + HolderFullState::Finished(state) => { + if let Some(ack_requested) = state.ack_requested { + if ack_requested { + let ack_msg = build_credential_ack(&self.get_thread_id()?); + return Some(ack_msg.into()); } - }, - }, - HolderState::Initial => {} - HolderState::ProposalSet => {} - HolderState::OfferReceived => {} - HolderState::RequestSet => {} - } - Ok(()) + } + } + _ => {} + }; + return None; } } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 3e7b5cfb79..439be93266 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -256,9 +256,16 @@ impl HolderSM { ) .await { - Ok((cred_id, rev_reg_def_json)) => { - HolderFullState::Finished((state_data, cred_id, credential, rev_reg_def_json).into()) - } + Ok((cred_id, rev_reg_def_json)) => HolderFullState::Finished( + ( + state_data, + cred_id, + credential, + rev_reg_def_json, + credential.decorators.please_ack.is_some(), + ) + .into(), + ), Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!("Failed to process or save received credential: {problem_report:?}"); diff --git a/aries_vcx/src/protocols/issuance/holder/states/finished.rs b/aries_vcx/src/protocols/issuance/holder/states/finished.rs index 8d348bdd8a..35e75308ed 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/finished.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/finished.rs @@ -10,6 +10,7 @@ pub struct FinishedHolderState { pub credential: Option, pub status: Status, pub rev_reg_def_json: Option, + pub ack_requested: Option, } impl FinishedHolderState { @@ -146,6 +147,7 @@ impl FinishedHolderState { pub fn new(problem_report: ProblemReport) -> Self { trace!("SM is now in Finished state"); FinishedHolderState { + ack_requested: None, cred_id: None, credential: None, status: Status::Failed(problem_report), diff --git a/aries_vcx/src/protocols/issuance/holder/states/request_set.rs b/aries_vcx/src/protocols/issuance/holder/states/request_set.rs index c14fd8c18d..06f0746c3d 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/request_set.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/request_set.rs @@ -14,14 +14,20 @@ pub struct RequestSetState { impl From<(RequestSetState, String, IssueCredential, Option)> for FinishedHolderState { fn from( - (_, cred_id, credential, rev_reg_def_json): (RequestSetState, String, IssueCredential, Option), + (_, cred_id, credential, rev_reg_def_json, ack_requested): ( + RequestSetState, + String, + IssueCredential, + Option, + bool, + ), ) -> Self { - trace!("SM is now in Finished state"); FinishedHolderState { cred_id: Some(cred_id), credential: Some(credential), status: Status::Success, rev_reg_def_json, + ack_requested: Some(ack_requested), } } } diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index 845bb0e21e..ca333983fc 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -161,13 +161,17 @@ pub async fn holder_update_with_mediator( if sm.is_terminal_state() { return Ok(sm.get_state()); } - let send_message = connection.send_message_closure(Arc::clone(wallet)).await?; - let messages = connection.get_messages(agency_client).await?; if let Some((uid, msg)) = mediated_holder::holder_find_message_to_handle(sm, messages) { sm.process_aries_msg(ledger, anoncreds, msg.clone()).await?; connection.update_message_status(&uid, agency_client).await?; - sm.try_reply(send_message, Some(msg)).await?; + match sm.get_final_message() { + None => {} + Some(msg_response) => { + let send_message = connection.send_message_closure(Arc::clone(wallet)).await?; + send_message(msg_response).await?; + } + } } Ok(sm.get_state()) } diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 4185810265..2eee45a835 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -123,8 +123,6 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect if credential.is_terminal_state() { return Ok(credential.get_state().into()); } - let send_message = mediated_connection::send_message_closure(connection_handle).await?; - let (mediator_uid, aries_msg) = if let Some(message) = message { let message: AriesMessage = serde_json::from_str(message).map_err(|err| { LibvcxError::from_msg( @@ -156,7 +154,13 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect trace!("credential::update_state >>> updating messages status in mediator"); mediated_connection::update_message_status(connection_handle, &uid).await?; } - credential.try_reply(send_message, Some(aries_msg)).await?; + match credential.get_final_message() { + None => {} + Some(msg_response) => { + let send_message = mediated_connection::send_message_closure(connection_handle).await?; + send_message(msg_response).await?; + } + } } } let state = credential.get_state().into(); From 9c7b4f0c38d2607e781c1a6d124b7e0702e62413 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Fri, 1 Sep 2023 19:12:29 +0200 Subject: [PATCH 40/40] Fix compile errs Signed-off-by: Patrik Stas --- agents/rust/aries-vcx-agent/src/services/holder.rs | 2 +- aries_vcx/src/handlers/issuance/holder.rs | 6 +++--- .../src/protocols/issuance/holder/state_machine.rs | 13 +++---------- .../protocols/issuance/holder/states/request_set.rs | 9 ++------- aries_vcx/tests/utils/devsetup_util.rs | 2 +- libvcx_core/src/api_vcx/api_handle/credential.rs | 2 +- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/holder.rs b/agents/rust/aries-vcx-agent/src/services/holder.rs index ca5bb6a27f..cfb91fcbc2 100644 --- a/agents/rust/aries-vcx-agent/src/services/holder.rs +++ b/agents/rust/aries-vcx-agent/src/services/holder.rs @@ -126,7 +126,7 @@ impl ServiceCredentialsHolder { msg_issue_credential.clone(), ) .await?; - match holder.get_final_message() { + match holder.get_final_message()? { None => {} Some(msg_response) => { let send_closure: SendClosure = Box::new(|msg: AriesMessage| { diff --git a/aries_vcx/src/handlers/issuance/holder.rs b/aries_vcx/src/handlers/issuance/holder.rs index 56c4f9b141..b5e167915c 100644 --- a/aries_vcx/src/handlers/issuance/holder.rs +++ b/aries_vcx/src/handlers/issuance/holder.rs @@ -250,18 +250,18 @@ impl Holder { Ok(()) } - pub fn get_final_message(&self) -> Option { + pub fn get_final_message(&self) -> VcxResult> { match &self.holder_sm.state { HolderFullState::Finished(state) => { if let Some(ack_requested) = state.ack_requested { if ack_requested { let ack_msg = build_credential_ack(&self.get_thread_id()?); - return Some(ack_msg.into()); + return Ok(Some(ack_msg.into())); } } } _ => {} }; - return None; + return Ok(None); } } diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index 439be93266..3e7b5cfb79 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -256,16 +256,9 @@ impl HolderSM { ) .await { - Ok((cred_id, rev_reg_def_json)) => HolderFullState::Finished( - ( - state_data, - cred_id, - credential, - rev_reg_def_json, - credential.decorators.please_ack.is_some(), - ) - .into(), - ), + Ok((cred_id, rev_reg_def_json)) => { + HolderFullState::Finished((state_data, cred_id, credential, rev_reg_def_json).into()) + } Err(err) => { let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id); error!("Failed to process or save received credential: {problem_report:?}"); diff --git a/aries_vcx/src/protocols/issuance/holder/states/request_set.rs b/aries_vcx/src/protocols/issuance/holder/states/request_set.rs index 06f0746c3d..fe2293f087 100644 --- a/aries_vcx/src/protocols/issuance/holder/states/request_set.rs +++ b/aries_vcx/src/protocols/issuance/holder/states/request_set.rs @@ -14,14 +14,9 @@ pub struct RequestSetState { impl From<(RequestSetState, String, IssueCredential, Option)> for FinishedHolderState { fn from( - (_, cred_id, credential, rev_reg_def_json, ack_requested): ( - RequestSetState, - String, - IssueCredential, - Option, - bool, - ), + (_, cred_id, credential, rev_reg_def_json): (RequestSetState, String, IssueCredential, Option), ) -> Self { + let ack_requested = credential.decorators.please_ack.is_some(); FinishedHolderState { cred_id: Some(cred_id), credential: Some(credential), diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index ca333983fc..6a99f8fd42 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -165,7 +165,7 @@ pub async fn holder_update_with_mediator( if let Some((uid, msg)) = mediated_holder::holder_find_message_to_handle(sm, messages) { sm.process_aries_msg(ledger, anoncreds, msg.clone()).await?; connection.update_message_status(&uid, agency_client).await?; - match sm.get_final_message() { + match sm.get_final_message()? { None => {} Some(msg_response) => { let send_message = connection.send_message_closure(Arc::clone(wallet)).await?; diff --git a/libvcx_core/src/api_vcx/api_handle/credential.rs b/libvcx_core/src/api_vcx/api_handle/credential.rs index 2eee45a835..13e320e69e 100644 --- a/libvcx_core/src/api_vcx/api_handle/credential.rs +++ b/libvcx_core/src/api_vcx/api_handle/credential.rs @@ -154,7 +154,7 @@ pub async fn update_state(credential_handle: u32, message: Option<&str>, connect trace!("credential::update_state >>> updating messages status in mediator"); mediated_connection::update_message_status(connection_handle, &uid).await?; } - match credential.get_final_message() { + match credential.get_final_message()? { None => {} Some(msg_response) => { let send_message = mediated_connection::send_message_closure(connection_handle).await?;