Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Declutter issuance&presentation protocols #945

Merged
merged 42 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1d40be1
Remove libvcx-c, libvcx java, libvcx ios
Patrik-Stas Aug 18, 2023
d167095
Additional updates
Patrik-Stas Aug 19, 2023
1bb9ca0
Fix building vdr-proxy docker img
Patrik-Stas Aug 19, 2023
0ec8157
Remove disabled tests
Patrik-Stas Aug 18, 2023
e7587db
Externalize issuer mediator-coupled update methods
Patrik-Stas Aug 18, 2023
0421ce4
Relocate get_credential_proposal_messages
Patrik-Stas Aug 18, 2023
d3ec6b7
De'actionize' IssuerSM
Patrik-Stas Aug 18, 2023
aedb806
Trim down and rename Issuer::step method
Patrik-Stas Aug 18, 2023
afcc01d
Start holder cleanup
Patrik-Stas Aug 18, 2023
eaaad03
Extract holder mediation methods to separate file
Patrik-Stas Aug 18, 2023
ced9fdd
Cargo fmt
Patrik-Stas Aug 18, 2023
a98c9e3
De'actionize' HolderSM
Patrik-Stas Aug 18, 2023
e37f106
Run CI on branch push
Patrik-Stas Aug 19, 2023
58c5984
Externalize Holder's find_message_to_handle, update_state
Patrik-Stas Aug 19, 2023
bec4864
Fix test errors, compile errors
Patrik-Stas Aug 19, 2023
750338c
Add clippy exception (mediated connections code)
Patrik-Stas Aug 19, 2023
11deb0d
Externalize find_message_to_handle on issuer
Patrik-Stas Aug 19, 2023
abbfb57
Remove issaunce protocol 'actions' concept
Patrik-Stas Aug 19, 2023
aefd1ae
Externalize mediator off from holder, issuer
Patrik-Stas Aug 19, 2023
1d301f0
Rename 'ProverMessages' to 'ProverActions'
Patrik-Stas Aug 19, 2023
ee7ae7b
Extract verifier's find_message_to_handle
Patrik-Stas Aug 19, 2023
ff54fa8
Extract prover's find_message_to_handle
Patrik-Stas Aug 19, 2023
c7606f1
Delete disabled tests
Patrik-Stas Aug 19, 2023
66a221f
De'actionize' ProverSM, Prover
Patrik-Stas Aug 19, 2023
9d82f78
De'actionize' VerifierSM, Verifier
Patrik-Stas Aug 19, 2023
5012387
Fix compile errs
Patrik-Stas Aug 19, 2023
ede3cb1
Delete disabled tests
Patrik-Stas Aug 19, 2023
53f0858
Remove presentation protocol SM's 'actions'
Patrik-Stas Aug 19, 2023
434f453
Ignore unwrap() clippy warnings in deprecated/testing-only code
Patrik-Stas Aug 19, 2023
b06f5a7
Remove disabled tests
Patrik-Stas Aug 20, 2023
b1ff537
Restore thread_id verifications
Patrik-Stas Aug 20, 2023
db19087
Cater for libvcx_core unit tests
Patrik-Stas Aug 20, 2023
57e1eb5
Cargo fmt
Patrik-Stas Aug 20, 2023
ca392fa
Merge branch 'main' into sm/cleanup
Patrik-Stas Aug 21, 2023
79e97c3
Revert CI change
Patrik-Stas Aug 22, 2023
4ddee24
Removed commented code
Patrik-Stas Aug 22, 2023
0d40407
Fix logs, rename function
Patrik-Stas Aug 22, 2023
8f51797
Remove unused function arguments
Patrik-Stas Aug 22, 2023
428122b
Move prover test methods
Patrik-Stas Aug 23, 2023
80ccdfd
Move verifier test method
Patrik-Stas Aug 23, 2023
88c1da4
Move holder test methods
Patrik-Stas Aug 23, 2023
3c7a59e
Move issuer test methods, reformat
Patrik-Stas Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 25 additions & 179 deletions aries_vcx/src/handlers/issuance/holder.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use std::collections::HashMap;
use std::sync::Arc;

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::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::revocation::revoke::Revoke;
use messages::AriesMessage;
use std::sync::Arc;

use agency_client::agency_client::AgencyClient;
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 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::actions::CredentialIssuanceAction;
use crate::protocols::issuance::holder::state_machine::{HolderSM, HolderState};
use crate::protocols::SendClosure;

Expand Down Expand Up @@ -98,10 +95,6 @@ impl Holder {
self.holder_sm.is_terminal_state()
}

pub fn find_message_to_handle(&self, messages: HashMap<String, AriesMessage>) -> Option<(String, AriesMessage)> {
self.holder_sm.find_message_to_handle(messages)
}

pub fn get_state(&self) -> HolderState {
self.holder_sm.get_state()
}
Expand Down Expand Up @@ -193,178 +186,31 @@ impl Holder {
}
}

pub async fn step(
pub async fn process_aries_msg(
&mut self,
ledger: &Arc<dyn AnoncredsLedgerRead>,
anoncreds: &Arc<dyn BaseAnonCreds>,
message: CredentialIssuanceAction,
message: AriesMessage,
send_message: Option<SendClosure>,
) -> VcxResult<()> {
self.holder_sm = self
.holder_sm
.clone()
.handle_message(ledger, anoncreds, message, send_message)
.await?;
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)
.await?
}
AriesMessage::ReportProblem(report) => self.holder_sm.clone().receive_problem_report(report)?,
_ => self.holder_sm.clone(),
};
self.holder_sm = holder_sm;
Ok(())
}

pub async fn update_state(
&mut self,
ledger: &Arc<dyn AnoncredsLedgerRead>,
anoncreds: &Arc<dyn BaseAnonCreds>,
wallet: &Arc<dyn BaseWallet>,
agency_client: &AgencyClient,
connection: &MediatedConnection,
) -> VcxResult<HolderState> {
trace!("Holder::update_state >>>");
if self.is_terminal_state() {
return Ok(self.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)) = self.find_message_to_handle(messages) {
self.step(ledger, anoncreds, msg.into(), Some(send_message)).await?;
connection.update_message_status(&uid, agency_client).await?;
}
Ok(self.get_state())
}
}

pub mod test_utils {
use agency_client::agency_client::AgencyClient;
use messages::msg_fields::protocols::cred_issuance::CredentialIssuance;
use messages::AriesMessage;

use crate::errors::error::prelude::*;
use crate::handlers::connection::mediated_connection::MediatedConnection;

pub async fn get_credential_offer_messages(
agency_client: &AgencyClient,
connection: &MediatedConnection,
) -> VcxResult<String> {
let credential_offers: Vec<AriesMessage> = connection
.get_messages(agency_client)
.await?
.into_iter()
.filter_map(|(_, a2a_message)| match a2a_message {
AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(_)) => Some(a2a_message),
_ => None,
})
.collect();

Ok(json!(credential_offers).to_string())
}
}

// #[cfg(test)]
// pub mod unit_tests {

// use crate::common::test_utils::mock_profile;
// use crate::utils::devsetup::SetupMocks;
// use messages::protocols::issuance::credential::test_utils::_credential;
// use messages::protocols::issuance::credential_offer::test_utils::_credential_offer;
// use messages::protocols::issuance::credential_proposal::test_utils::_credential_proposal_data;
// use messages::protocols::issuance::credential_request::test_utils::_my_pw_did;

// use super::*;

// pub fn _send_message() -> Option<SendClosure> {
// Some(Box::new(|_: A2AMessage| Box::pin(async { VcxResult::Ok(()) })))
// }

// fn _holder_from_offer() -> Holder {
// Holder::create_from_offer("test_source_id", _credential_offer()).unwrap()
// }

// fn _holder() -> Holder {
// Holder::create("test_source_id").unwrap()
// }

// impl Holder {
// async fn to_finished_state(mut self) -> Holder {
// self.step(
// &mock_profile(),
// CredentialIssuanceAction::CredentialProposalSend(_credential_proposal_data()),
// _send_message(),
// )
// .await
// .unwrap();
// self.step(
// &mock_profile(),
// CredentialIssuanceAction::CredentialOffer(_credential_offer()),
// _send_message(),
// )
// .await
// .unwrap();
// self.step(
// &mock_profile(),
// CredentialIssuanceAction::CredentialRequestSend(_my_pw_did()),
// _send_message(),
// )
// .await
// .unwrap();
// self.step(
// &mock_profile(),
// CredentialIssuanceAction::Credential(_credential()),
// _send_message(),
// )
// .await
// .unwrap();
// self
// }
// }

// #[tokio::test]
// async fn exchange_credential_from_proposal_without_negotiation() {
// let _setup = SetupMocks::init();
// let holder = _holder().to_finished_state().await;
// assert_eq!(HolderState::Finished, holder.get_state());
// }

// #[tokio::test]
// async fn exchange_credential_from_proposal_with_negotiation() {
// let _setup = SetupMocks::init();
// let mut holder = _holder();
// assert_eq!(HolderState::Initial, holder.get_state());

// holder
// .send_proposal(_credential_proposal_data(), _send_message().unwrap())
// .await
// .unwrap();
// assert_eq!(HolderState::ProposalSent, holder.get_state());

// let messages = map!(
// "key_1".to_string() => A2AMessage::CredentialOffer(_credential_offer())
// );
// let (_, msg) = holder.find_message_to_handle(messages).unwrap();
// holder.step(&mock_profile(), msg.into(), _send_message()).await.unwrap();
// assert_eq!(HolderState::OfferReceived, holder.get_state());

// holder
// .send_proposal(_credential_proposal_data(), _send_message().unwrap())
// .await
// .unwrap();
// assert_eq!(HolderState::ProposalSent, holder.get_state());

// let messages = map!(
// "key_1".to_string() => A2AMessage::CredentialOffer(_credential_offer())
// );
// let (_, msg) = holder.find_message_to_handle(messages).unwrap();
// holder.step(&mock_profile(), msg.into(), _send_message()).await.unwrap();
// assert_eq!(HolderState::OfferReceived, holder.get_state());

// holder
// .send_request(&mock_profile(), _my_pw_did(), _send_message().unwrap())
// .await
// .unwrap();
// assert_eq!(HolderState::RequestSent, holder.get_state());

// let messages = map!(
// "key_1".to_string() => A2AMessage::Credential(_credential())
// );
// let (_, msg) = holder.find_message_to_handle(messages).unwrap();
// holder.step(&mock_profile(), msg.into(), _send_message()).await.unwrap();
// assert_eq!(HolderState::Finished, holder.get_state());
// }
// }
Loading
Loading