Skip to content

Commit

Permalink
Issue Credential V2.0 message structures (#990)
Browse files Browse the repository at this point in the history
Issue Credential V2.0 message structures (#990)

Signed-off-by: George Mulhearn <[email protected]>
  • Loading branch information
gmulhearn-anonyome authored Sep 28, 2023
1 parent d8e7602 commit ed39a52
Show file tree
Hide file tree
Showing 44 changed files with 1,783 additions and 514 deletions.
12 changes: 6 additions & 6 deletions agents/rust/aries-vcx-agent/src/services/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use aries_vcx::{
core::profile::profile::Profile,
handlers::issuance::holder::Holder,
messages::{
msg_fields::protocols::cred_issuance::{
issue_credential::IssueCredential, offer_credential::OfferCredential,
propose_credential::ProposeCredential,
msg_fields::protocols::cred_issuance::v1::{
issue_credential::IssueCredentialV1, offer_credential::OfferCredentialV1,
propose_credential::ProposeCredentialV1,
},
AriesMessage,
},
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ServiceCredentialsHolder {
pub async fn send_credential_proposal(
&self,
connection_id: &str,
propose_credential: ProposeCredential,
propose_credential: ProposeCredentialV1,
) -> AgentResult<String> {
let connection = self.service_connections.get_by_id(connection_id)?;
let wallet = self.profile.inject_wallet();
Expand All @@ -83,7 +83,7 @@ impl ServiceCredentialsHolder {
pub fn create_from_offer(
&self,
connection_id: &str,
offer: OfferCredential,
offer: OfferCredentialV1,
) -> AgentResult<String> {
self.service_connections.get_by_id(connection_id)?;
let holder = Holder::create_from_offer("", offer)?;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl ServiceCredentialsHolder {
pub async fn process_credential(
&self,
thread_id: &str,
msg_issue_credential: IssueCredential,
msg_issue_credential: IssueCredentialV1,
) -> AgentResult<String> {
let mut holder = self.get_holder(thread_id)?;
let connection_id = self.get_connection_id(thread_id)?;
Expand Down
14 changes: 7 additions & 7 deletions agents/rust/aries-vcx-agent/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use aries_vcx::{
core::profile::profile::Profile,
handlers::{issuance::issuer::Issuer, util::OfferInfo},
messages::{
msg_fields::protocols::cred_issuance::{
ack::AckCredential, propose_credential::ProposeCredential,
request_credential::RequestCredential,
msg_fields::protocols::cred_issuance::v1::{
ack::AckCredentialV1, propose_credential::ProposeCredentialV1,
request_credential::RequestCredentialV1,
},
AriesMessage,
},
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ServiceCredentialsIssuer {
pub async fn accept_proposal(
&self,
connection_id: &str,
proposal: &ProposeCredential,
proposal: &ProposeCredentialV1,
) -> AgentResult<String> {
let issuer = Issuer::create_from_proposal("", proposal)?;
self.creds_issuer.insert(
Expand Down Expand Up @@ -106,7 +106,7 @@ impl ServiceCredentialsIssuer {
pub fn process_credential_request(
&self,
thread_id: &str,
request: RequestCredential,
request: RequestCredentialV1,
) -> AgentResult<()> {
let IssuerWrapper {
mut issuer,
Expand All @@ -120,7 +120,7 @@ impl ServiceCredentialsIssuer {
Ok(())
}

pub fn process_credential_ack(&self, thread_id: &str, ack: AckCredential) -> AgentResult<()> {
pub fn process_credential_ack(&self, thread_id: &str, ack: AckCredentialV1) -> AgentResult<()> {
let IssuerWrapper {
mut issuer,
connection_id,
Expand Down Expand Up @@ -180,7 +180,7 @@ impl ServiceCredentialsIssuer {
issuer.get_rev_id().map_err(|err| err.into())
}

pub fn get_proposal(&self, thread_id: &str) -> AgentResult<ProposeCredential> {
pub fn get_proposal(&self, thread_id: &str) -> AgentResult<ProposeCredentialV1> {
let issuer = self.get_issuer(thread_id)?;
issuer.get_proposal().map_err(|err| err.into())
}
Expand Down
43 changes: 24 additions & 19 deletions aries_vcx/src/handlers/issuance/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ use messages::{
decorators::{thread::Thread, timing::Timing},
msg_fields::protocols::{
cred_issuance::{
ack::{AckCredential, AckCredentialContent},
issue_credential::IssueCredential,
offer_credential::OfferCredential,
propose_credential::ProposeCredential,
request_credential::RequestCredential,
v1::{
ack::{AckCredentialV1, AckCredentialV1Content},
issue_credential::IssueCredentialV1,
offer_credential::OfferCredentialV1,
propose_credential::ProposeCredentialV1,
request_credential::RequestCredentialV1,
CredentialIssuanceV1,
},
CredentialIssuance,
},
notification::ack::{AckContent, AckDecorators, AckStatus},
Expand All @@ -34,16 +37,16 @@ use crate::{
protocols::issuance::holder::state_machine::{HolderFullState, HolderSM, HolderState},
};

fn build_credential_ack(thread_id: &str) -> AckCredential {
let content = AckCredentialContent::builder()
fn build_credential_ack(thread_id: &str) -> AckCredentialV1 {
let content = AckCredentialV1Content::builder()
.inner(AckContent::builder().status(AckStatus::Ok).build())
.build();
let decorators = AckDecorators::builder()
.thread(Thread::builder().thid(thread_id.to_owned()).build())
.timing(Timing::builder().out_time(Utc::now()).build())
.build();

AckCredential::builder()
AckCredentialV1::builder()
.id(Uuid::new_v4().to_string())
.content(content)
.decorators(decorators)
Expand All @@ -64,7 +67,7 @@ impl Holder {

pub fn create_with_proposal(
source_id: &str,
propose_credential: ProposeCredential,
propose_credential: ProposeCredentialV1,
) -> VcxResult<Holder> {
trace!(
"Holder::create_with_proposal >>> source_id: {:?}, propose_credential: {:?}",
Expand All @@ -77,7 +80,7 @@ impl Holder {

pub fn create_from_offer(
source_id: &str,
credential_offer: OfferCredential,
credential_offer: OfferCredentialV1,
) -> VcxResult<Holder> {
trace!(
"Holder::create_from_offer >>> source_id: {:?}, credential_offer: {:?}",
Expand All @@ -88,7 +91,7 @@ impl Holder {
Ok(Holder { holder_sm })
}

pub fn set_proposal(&mut self, credential_proposal: ProposeCredential) -> VcxResult<()> {
pub fn set_proposal(&mut self, credential_proposal: ProposeCredentialV1) -> VcxResult<()> {
self.holder_sm = self.holder_sm.clone().set_proposal(credential_proposal)?;
Ok(())
}
Expand All @@ -115,10 +118,10 @@ impl Holder {
}
}

pub fn get_msg_credential_request(&self) -> VcxResult<RequestCredential> {
pub fn get_msg_credential_request(&self) -> VcxResult<RequestCredentialV1> {
match self.holder_sm.state {
HolderFullState::RequestSet(ref state) => {
let mut msg: RequestCredential = state.msg_credential_request.clone();
let mut msg: RequestCredentialV1 = state.msg_credential_request.clone();
let timing = Timing::builder().out_time(Utc::now()).build();
msg.decorators.timing = Some(timing);
Ok(msg)
Expand All @@ -142,7 +145,7 @@ impl Holder {
&mut self,
ledger: &Arc<dyn AnoncredsLedgerRead>,
anoncreds: &Arc<dyn BaseAnonCreds>,
credential: IssueCredential,
credential: IssueCredentialV1,
) -> VcxResult<()> {
self.holder_sm = self
.holder_sm
Expand Down Expand Up @@ -176,7 +179,7 @@ impl Holder {
self.holder_sm.get_attachment()
}

pub fn get_offer(&self) -> VcxResult<OfferCredential> {
pub fn get_offer(&self) -> VcxResult<OfferCredentialV1> {
self.holder_sm.get_offer()
}

Expand Down Expand Up @@ -261,10 +264,12 @@ impl Holder {
message: AriesMessage,
) -> VcxResult<()> {
let holder_sm = match message {
AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(offer)) => {
self.holder_sm.clone().receive_offer(offer)?
}
AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(credential)) => {
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::OfferCredential(offer),
)) => self.holder_sm.clone().receive_offer(offer)?,
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::IssueCredential(credential),
)) => {
self.holder_sm
.clone()
.receive_credential(ledger, anoncreds, credential)
Expand Down
55 changes: 30 additions & 25 deletions aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use messages::{
misc::MimeType,
msg_fields::protocols::{
cred_issuance::{
ack::AckCredential, issue_credential::IssueCredential,
offer_credential::OfferCredential, propose_credential::ProposeCredential,
request_credential::RequestCredential, CredentialAttr, CredentialIssuance,
CredentialPreview,
common::CredentialAttr,
v1::{
ack::AckCredentialV1, issue_credential::IssueCredentialV1,
offer_credential::OfferCredentialV1, propose_credential::ProposeCredentialV1,
request_credential::RequestCredentialV1, CredentialIssuanceV1, CredentialPreviewV1,
},
CredentialIssuance,
},
notification::Notification,
report_problem::ProblemReport,
Expand All @@ -36,7 +39,7 @@ pub struct IssuerConfig {
pub tails_file: Option<String>,
}

fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPreview> {
fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPreviewV1> {
trace!(
"Issuer::_build_credential_preview >>> credential_json: {:?}",
secret!(credential_json)
Expand Down Expand Up @@ -115,7 +118,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
_ => {}
};

Ok(CredentialPreview::new(attributes))
Ok(CredentialPreviewV1::new(attributes))
}

impl Issuer {
Expand All @@ -127,7 +130,7 @@ impl Issuer {

pub fn create_from_proposal(
source_id: &str,
credential_proposal: &ProposeCredential,
credential_proposal: &ProposeCredentialV1,
) -> VcxResult<Issuer> {
trace!(
"Issuer::create_from_proposal >>> source_id: {:?}, credential_proposal: {:?}",
Expand Down Expand Up @@ -159,7 +162,7 @@ impl Issuer {
Ok(())
}

pub fn get_credential_offer(&self) -> VcxResult<OfferCredential> {
pub fn get_credential_offer(&self) -> VcxResult<OfferCredentialV1> {
self.issuer_sm.get_credential_offer_msg()
}

Expand All @@ -168,12 +171,12 @@ impl Issuer {
Ok(offer.into())
}

pub fn process_credential_request(&mut self, request: RequestCredential) -> VcxResult<()> {
pub fn process_credential_request(&mut self, request: RequestCredentialV1) -> VcxResult<()> {
self.issuer_sm = self.issuer_sm.clone().receive_request(request)?;
Ok(())
}

pub fn process_credential_ack(&mut self, ack: AckCredential) -> VcxResult<()> {
pub fn process_credential_ack(&mut self, ack: AckCredentialV1) -> VcxResult<()> {
self.issuer_sm = self.issuer_sm.clone().receive_ack(ack)?;
Ok(())
}
Expand All @@ -183,7 +186,7 @@ impl Issuer {
Ok(())
}

pub fn get_msg_issue_credential(&mut self) -> VcxResult<IssueCredential> {
pub fn get_msg_issue_credential(&mut self) -> VcxResult<IssueCredentialV1> {
self.issuer_sm.clone().get_msg_issue_credential()
}

Expand Down Expand Up @@ -253,7 +256,7 @@ impl Issuer {
self.issuer_sm.thread_id()
}

pub fn get_proposal(&self) -> VcxResult<ProposeCredential> {
pub fn get_proposal(&self) -> VcxResult<ProposeCredentialV1> {
self.issuer_sm.get_proposal()
}

Expand All @@ -269,17 +272,17 @@ impl Issuer {
self.issuer_sm.is_revoked(ledger).await
}

pub async fn receive_proposal(&mut self, proposal: ProposeCredential) -> VcxResult<()> {
pub async fn receive_proposal(&mut self, proposal: ProposeCredentialV1) -> VcxResult<()> {
self.issuer_sm = self.issuer_sm.clone().receive_proposal(proposal)?;
Ok(())
}

pub async fn receive_request(&mut self, request: RequestCredential) -> VcxResult<()> {
pub async fn receive_request(&mut self, request: RequestCredentialV1) -> VcxResult<()> {
self.issuer_sm = self.issuer_sm.clone().receive_request(request)?;
Ok(())
}

pub async fn receive_ack(&mut self, ack: AckCredential) -> VcxResult<()> {
pub async fn receive_ack(&mut self, ack: AckCredentialV1) -> VcxResult<()> {
self.issuer_sm = self.issuer_sm.clone().receive_ack(ack)?;
Ok(())
}
Expand All @@ -299,23 +302,25 @@ impl Issuer {
// 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 {
AriesMessage::CredentialIssuance(CredentialIssuance::ProposeCredential(proposal)) => {
self.issuer_sm.clone().receive_proposal(proposal)?
}
AriesMessage::CredentialIssuance(CredentialIssuance::RequestCredential(request)) => {
self.issuer_sm.clone().receive_request(request)?
}
AriesMessage::CredentialIssuance(CredentialIssuance::Ack(ack)) => {
self.issuer_sm.clone().receive_ack(ack)?
}
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::ProposeCredential(proposal),
)) => self.issuer_sm.clone().receive_proposal(proposal)?,
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::RequestCredential(request),
)) => self.issuer_sm.clone().receive_request(request)?,
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::Ack(ack),
)) => self.issuer_sm.clone().receive_ack(ack)?,
AriesMessage::ReportProblem(report) => {
self.issuer_sm.clone().receive_problem_report(report)?
}
AriesMessage::Notification(Notification::ProblemReport(report)) => self
.issuer_sm
.clone()
.receive_problem_report(report.into())?,
AriesMessage::CredentialIssuance(CredentialIssuance::ProblemReport(report)) => self
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::ProblemReport(report),
)) => self
.issuer_sm
.clone()
.receive_problem_report(report.into())?,
Expand Down
17 changes: 10 additions & 7 deletions aries_vcx/src/handlers/issuance/mediated_holder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashMap;

use messages::{
msg_fields::protocols::{cred_issuance::CredentialIssuance, notification::Notification},
msg_fields::protocols::{
cred_issuance::{v1::CredentialIssuanceV1, CredentialIssuance},
notification::Notification,
},
AriesMessage,
};

Expand All @@ -22,8 +25,8 @@ pub fn holder_find_message_to_handle(
for (uid, message) in messages {
match sm.get_state() {
HolderState::ProposalSet => {
if let AriesMessage::CredentialIssuance(CredentialIssuance::OfferCredential(
offer,
if let AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::OfferCredential(offer),
)) = &message
{
if matches_opt_thread_id!(offer, sm.get_thread_id().unwrap().as_str()) {
Expand All @@ -32,15 +35,15 @@ pub fn holder_find_message_to_handle(
}
}
HolderState::RequestSet => match &message {
AriesMessage::CredentialIssuance(CredentialIssuance::IssueCredential(
credential,
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::IssueCredential(credential),
)) => {
if matches_thread_id!(credential, sm.get_thread_id().unwrap().as_str()) {
return Some((uid, message));
}
}
AriesMessage::CredentialIssuance(CredentialIssuance::ProblemReport(
problem_report,
AriesMessage::CredentialIssuance(CredentialIssuance::V1(
CredentialIssuanceV1::ProblemReport(problem_report),
)) => {
if matches_opt_thread_id!(problem_report, sm.get_thread_id().unwrap().as_str())
{
Expand Down
Loading

0 comments on commit ed39a52

Please sign in to comment.