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

Remove msg-sending IO for issuer and holder #946

Merged
merged 40 commits into from
Sep 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4c169ce
Restore thread_id verifications
Patrik-Stas Aug 20, 2023
c7b961c
Make IO for issuer offer-sending opt-in
Patrik-Stas Aug 20, 2023
1d513b6
Decouple revocation_notification from Issuer handler
Patrik-Stas Aug 20, 2023
78c5aaa
Replace Issuer state CredentialSent by CredentialSet
Patrik-Stas Aug 20, 2023
bfe311e
Reformat
Patrik-Stas Aug 20, 2023
b7e25b2
Fix libvcx_core
Patrik-Stas Aug 20, 2023
f477cb6
Sync up napi
Patrik-Stas Aug 20, 2023
963f87d
post-rebase conflict resolution
Patrik-Stas Aug 20, 2023
85b1190
Cargo fmt
Patrik-Stas Aug 20, 2023
9306463
Fix compile errs in tests
Patrik-Stas Aug 20, 2023
957c903
Remove unused constants
Patrik-Stas Aug 20, 2023
cff5145
Sync up nodejs
Patrik-Stas Aug 20, 2023
27ac06e
Cargo fmt
Patrik-Stas Aug 20, 2023
124b1f2
Minor refactor, renames
Patrik-Stas Aug 20, 2023
431415b
Restore setting up timing decorator on outgoing issue-credential message
Patrik-Stas Aug 20, 2023
53f83d8
Holder: add function build_credential_request to avoid enforcing IO
Patrik-Stas Aug 20, 2023
a7c256a
Holder: Add constructor for failed finished state
Patrik-Stas Aug 23, 2023
7fa45c1
Issuer: Add constructor for CredentialSet state
Patrik-Stas Aug 23, 2023
634f007
Replace state From conversion by constructors
Patrik-Stas Aug 23, 2023
0f98a3d
Sync up
Patrik-Stas Aug 23, 2023
eed0af6
Add deprecation comments
Patrik-Stas Aug 23, 2023
957005d
Fix filename
Patrik-Stas Aug 23, 2023
db250b1
Rename Holder's ProposalSent to ProposalSet
Patrik-Stas Aug 23, 2023
66daf86
Update Holder proposal API
Patrik-Stas Aug 23, 2023
fbb1223
Remove unused imports
Patrik-Stas Aug 23, 2023
ffb979b
Cargo fmt
Patrik-Stas Aug 23, 2023
440717d
Tweak issuance protocol initiation via holder's proposal
Patrik-Stas Aug 24, 2023
1ac22c7
Remove forgotten log
Patrik-Stas Aug 30, 2023
fccc4c8
Add get_problem_report() method for Issuer, Holder
Patrik-Stas Aug 30, 2023
5b8006c
Send problem reports
Patrik-Stas Aug 31, 2023
e9cfc45
Holder: Assure sending problem-report, sending credential-ack
Patrik-Stas Sep 1, 2023
6187799
holder: eliminate 'send_credential_request' in favor of 'get_msg_cred…
Patrik-Stas Sep 1, 2023
c2f334e
holder: remove msg sending from decline_offer
Patrik-Stas Sep 1, 2023
af2c7d3
Fix compile errs
Patrik-Stas Sep 1, 2023
e3b7e1b
Holder: fix: make sure to send ack message if requested
Patrik-Stas Sep 1, 2023
2a569c5
isser: remove usage of SendClosure
Patrik-Stas Sep 1, 2023
a48ec88
Edit todo notes
Patrik-Stas Sep 1, 2023
8a1f084
holder: Return response AriesMessage from prepare_credential_request
Patrik-Stas Sep 1, 2023
6e48283
Holder: Remove 'try_reply(..)', add 'get_final_message()' instead. Tr…
Patrik-Stas Sep 1, 2023
9c7b4f0
Fix compile errs
Patrik-Stas Sep 1, 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
Prev Previous commit
Next Next commit
holder: eliminate 'send_credential_request' in favor of 'get_msg_cred…
…ential_request'; rename 'build_credential_request' to 'prepare_credential_request'

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
Patrik-Stas committed Sep 1, 2023
commit 6187799acc78f87988aac6d33e0dc29b6d1bce2d
5 changes: 3 additions & 2 deletions agents/rust/aries-vcx-agent/src/services/holder.rs
Original file line number Diff line number Diff line change
@@ -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
22 changes: 16 additions & 6 deletions aries_vcx/src/handlers/issuance/holder.rs
Original file line number Diff line number Diff line change
@@ -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<dyn AnoncredsLedgerRead>,
anoncreds: &Arc<dyn BaseAnonCreds>,
@@ -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<RequestCredential> {
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<dyn AnoncredsLedgerRead>,
21 changes: 1 addition & 20 deletions aries_vcx/src/protocols/issuance/holder/state_machine.rs
Original file line number Diff line number Diff line change
@@ -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<dyn AnoncredsLedgerRead>,
anoncreds: &'a Arc<dyn BaseAnonCreds>,
@@ -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<String>, send_message: SendClosure) -> VcxResult<Self> {
let state = match self.state {
HolderFullState::OfferReceived(_) => {
10 changes: 6 additions & 4 deletions aries_vcx/tests/test_creds_proofs.rs
Original file line number Diff line number Diff line change
@@ -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());
}

5 changes: 3 additions & 2 deletions aries_vcx/tests/utils/devsetup_alice.rs
Original file line number Diff line number Diff line change
@@ -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());
}

10 changes: 6 additions & 4 deletions aries_vcx/tests/utils/scenarios.rs
Original file line number Diff line number Diff line change
@@ -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());
}

5 changes: 3 additions & 2 deletions libvcx_core/src/api_vcx/api_handle/credential.rs
Original file line number Diff line number Diff line change
@@ -236,15 +236,16 @@ 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 => {
let problem_report = credential.get_problem_report()?;
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)