Skip to content

Commit b81832e

Browse files
explicitly test mixed link secrets with w3c verifier
Signed-off-by: Andrew Whitehead <[email protected]>
1 parent a20ab4e commit b81832e

File tree

3 files changed

+78
-31
lines changed

3 files changed

+78
-31
lines changed

src/services/w3c/prover.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ pub fn create_presentation(
170170
let credential_values: CredentialValues = credential.credential_subject.encode()?;
171171
let proof = credential.get_credential_signature_proof()?;
172172

173+
let proof_link_secret = present.link_secret.unwrap_or(link_secret);
173174
proof_builder.add_sub_proof(
174175
&credential_values,
175176
&proof.signature,
176-
link_secret,
177+
proof_link_secret,
177178
present,
178179
&proof.schema_id,
179180
&proof.cred_def_id,

tests/anoncreds_demos.rs

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anoncreds::data_types::w3c::VerifiableCredentialSpecVersion;
22
use anoncreds::data_types::w3c::credential_attributes::CredentialAttributeValue;
3-
use anoncreds::verifier;
3+
use anoncreds::{verifier, w3c};
44
use rstest::rstest;
55
use serde_json::json;
66
use std::collections::{BTreeSet, HashMap};
@@ -728,7 +728,12 @@ fn anoncreds_demo_proof_does_not_verify_with_wrong_attr_and_predicates(
728728
}
729729

730730
#[rstest]
731-
fn anoncreds_demo_proof_does_not_verify_with_multiple_link_secrets() {
731+
#[case(CredentialFormat::Legacy, PresentationFormat::Legacy)]
732+
#[case(CredentialFormat::W3C, PresentationFormat::W3C)]
733+
fn anoncreds_demo_proof_does_not_verify_with_multiple_link_secrets(
734+
#[case] credential_format: CredentialFormat,
735+
#[case] presentation_format: PresentationFormat,
736+
) {
732737
// Create pseudo ledger and wallets
733738

734739
use anoncreds::{prover, types::PresentCredentials};
@@ -755,7 +760,7 @@ fn anoncreds_demo_proof_does_not_verify_with_multiple_link_secrets() {
755760
// Issuer creates a credential
756761
let cred_values = fixtures::credential_values(GVT_CRED);
757762
let issue_cred = issuer_wallet.create_credential(
758-
&CredentialFormat::Legacy,
763+
&credential_format,
759764
&gvt_cred_def_id,
760765
&cred_offer,
761766
&cred_request,
@@ -783,7 +788,7 @@ fn anoncreds_demo_proof_does_not_verify_with_multiple_link_secrets() {
783788
// Issuer creates a credential
784789
let cred_values = fixtures::credential_values(GVT_CRED);
785790
let issue_cred = issuer_wallet.create_credential(
786-
&CredentialFormat::Legacy,
791+
&credential_format,
787792
&gvt_cred_def_id,
788793
&cred_offer,
789794
&cred_request,
@@ -841,31 +846,60 @@ fn anoncreds_demo_proof_does_not_verify_with_multiple_link_secrets() {
841846
}],
842847
}];
843848

844-
// Prover creates presentation with two different link secrets
845-
let mut presented = PresentCredentials::default();
846-
prover_wallet_1.prepare_credentials_to_present(
847-
&mut presented,
848-
&prover_wallet_1.credentials,
849-
&present_credentials_1,
850-
);
851-
prover_wallet_2.prepare_credentials_to_present(
852-
&mut presented,
853-
&prover_wallet_2.credentials,
854-
&present_credentials_2,
855-
);
856-
857849
// Prover creates presentation
858-
let presentation = prover::create_presentation(
859-
&pres_request,
860-
presented,
861-
None,
862-
// This link secret value is superseded by the ones assigned to each credential in 'presented'
863-
&prover_wallet_1.link_secret,
864-
&schemas,
865-
&cred_defs,
866-
)
867-
.expect("Error creating presentation");
868-
let presentation = Presentations::Legacy(presentation);
850+
let presentation = match presentation_format {
851+
PresentationFormat::Legacy => {
852+
// Prover creates presentation with two different link secrets
853+
let mut presented = PresentCredentials::default();
854+
prover_wallet_1.prepare_credentials_to_present(
855+
&mut presented,
856+
&prover_wallet_1.credentials,
857+
&present_credentials_1,
858+
);
859+
prover_wallet_2.prepare_credentials_to_present(
860+
&mut presented,
861+
&prover_wallet_2.credentials,
862+
&present_credentials_2,
863+
);
864+
prover::create_presentation(
865+
&pres_request,
866+
presented,
867+
None,
868+
// This link secret value is superseded by the ones assigned to each credential in 'presented'
869+
&prover_wallet_1.link_secret,
870+
&schemas,
871+
&cred_defs,
872+
)
873+
.expect("Error creating presentation")
874+
.into()
875+
}
876+
PresentationFormat::W3C => {
877+
// Prover creates presentation with two different link secrets
878+
let mut presented = PresentCredentials::default();
879+
prover_wallet_1.prepare_credentials_to_present(
880+
&mut presented,
881+
&prover_wallet_1.w3c_credentials,
882+
&present_credentials_1,
883+
);
884+
prover_wallet_2.prepare_credentials_to_present(
885+
&mut presented,
886+
&prover_wallet_2.w3c_credentials,
887+
&present_credentials_2,
888+
);
889+
890+
w3c::prover::create_presentation(
891+
&pres_request,
892+
presented,
893+
// This link secret value is superseded by the ones assigned to each credential in 'presented'
894+
&prover_wallet_1.link_secret,
895+
&schemas,
896+
&cred_defs,
897+
None,
898+
)
899+
.expect("Error creating presentation")
900+
.into()
901+
}
902+
};
869903

870904
let valid = verifier_wallet.verify_presentation(
871905
&presentation,

tests/utils/mock.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ pub enum Presentations {
6565
W3C(W3CPresentation),
6666
}
6767

68+
impl From<Presentation> for Presentations {
69+
fn from(value: Presentation) -> Self {
70+
Presentations::Legacy(value)
71+
}
72+
}
73+
74+
impl From<W3CPresentation> for Presentations {
75+
fn from(value: W3CPresentation) -> Self {
76+
Presentations::W3C(value)
77+
}
78+
}
79+
6880
impl Credentials {
6981
pub fn legacy(&self) -> &Credential {
7082
match self {
@@ -940,7 +952,7 @@ impl<'a> ProverWallet<'a> {
940952
cred_defs,
941953
)
942954
.expect("Error creating presentation");
943-
Presentations::Legacy(presentation)
955+
presentation.into()
944956
}
945957
PresentationFormat::W3C => {
946958
let mut present = PresentCredentials::default();
@@ -958,7 +970,7 @@ impl<'a> ProverWallet<'a> {
958970
version,
959971
)
960972
.expect("Error creating presentation");
961-
Presentations::W3C(presentation)
973+
presentation.into()
962974
}
963975
}
964976
}

0 commit comments

Comments
 (0)