Skip to content

Commit

Permalink
rename master secret to link secret
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Jul 11, 2023
1 parent a87baee commit 1a824e3
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 107 deletions.
12 changes: 6 additions & 6 deletions indy-credx/src/ffi/cred_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::services::{
pub extern "C" fn credx_create_credential_request(
prover_did: FfiStr,
cred_def: ObjectHandle,
master_secret: ObjectHandle,
master_secret_id: FfiStr,
link_secret: ObjectHandle,
link_secret_id: FfiStr,
cred_offer: ObjectHandle,
cred_req_p: *mut ObjectHandle,
cred_req_meta_p: *mut ObjectHandle,
Expand All @@ -27,14 +27,14 @@ pub extern "C" fn credx_create_credential_request(
.ok_or_else(|| err_msg!("Missing prover DID"))?;
DidValue::from_str(did)?
};
let master_secret_id = master_secret_id
let link_secret_id = link_secret_id
.as_opt_str()
.ok_or_else(|| err_msg!("Missing master secret ID"))?;
.ok_or_else(|| err_msg!("Missing link secret ID"))?;
let (cred_req, cred_req_metadata) = create_credential_request(
&prover_did,
cred_def.load()?.cast_ref()?,
master_secret.load()?.cast_ref()?,
master_secret_id,
link_secret.load()?.cast_ref()?,
link_secret_id,
cred_offer.load()?.cast_ref()?,
)?;
let cred_req = ObjectHandle::create(cred_req)?;
Expand Down
4 changes: 2 additions & 2 deletions indy-credx/src/ffi/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub extern "C" fn credx_encode_credential_attributes(
pub extern "C" fn credx_process_credential(
cred: ObjectHandle,
cred_req_metadata: ObjectHandle,
master_secret: ObjectHandle,
link_secret: ObjectHandle,
cred_def: ObjectHandle,
rev_reg_def: ObjectHandle,
cred_p: *mut ObjectHandle,
Expand All @@ -192,7 +192,7 @@ pub extern "C" fn credx_process_credential(
process_credential(
&mut cred,
cred_req_metadata.load()?.cast_ref()?,
master_secret.load()?.cast_ref()?,
link_secret.load()?.cast_ref()?,
cred_def.load()?.cast_ref()?,
rev_reg_def
.opt_load()?
Expand Down
16 changes: 16 additions & 0 deletions indy-credx/src/ffi/link_secret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::error::{catch_error, ErrorCode};
use super::object::ObjectHandle;
use crate::services::{prover::create_link_secret, types::LinkSecret};

#[no_mangle]
pub extern "C" fn credx_create_link_secret(link_secret_p: *mut ObjectHandle) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(link_secret_p);
let secret = ObjectHandle::create(create_link_secret()?)?;
unsafe { *link_secret_p = secret };
Ok(())
})
}

impl_indy_object!(LinkSecret, "LinkSecret");
impl_indy_object_from_json!(LinkSecret, credx_link_secret_from_json);
16 changes: 0 additions & 16 deletions indy-credx/src/ffi/master_secret.rs

This file was deleted.

2 changes: 1 addition & 1 deletion indy-credx/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod cred_def;
mod cred_offer;
mod cred_req;
mod credential;
mod master_secret;
mod link_secret;
mod pres_req;
mod presentation;
mod revocation;
Expand Down
4 changes: 2 additions & 2 deletions indy-credx/src/ffi/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub extern "C" fn credx_create_presentation(
credentials_prove: FfiList<FfiCredentialProve>,
self_attest_names: FfiStrList,
self_attest_values: FfiStrList,
master_secret: ObjectHandle,
link_secret: ObjectHandle,
schemas: FfiList<ObjectHandle>,
cred_defs: FfiList<ObjectHandle>,
presentation_p: *mut ObjectHandle,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub extern "C" fn credx_create_presentation(
pres_req.load()?.cast_ref()?,
present_creds,
self_attested,
master_secret.load()?.cast_ref()?,
link_secret.load()?.cast_ref()?,
&schemas.refs_map()?,
&cred_defs.refs_map()?,
)?;
Expand Down
10 changes: 5 additions & 5 deletions indy-credx/src/services/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use indy_data_types::anoncreds::{
};

use crate::anoncreds_clsignatures::{
hash_credential_attribute, CredentialSchema, CredentialValues as CryptoCredentialValues,
Issuer as ClIssuer, MasterSecret as CryptoMasterSecret, NonCredentialSchema, SubProofRequest,
hash_credential_attribute, CredentialSchema, CredentialValues as ClCredentialValues,
Issuer as ClIssuer, MasterSecret as ClMasterSecret, NonCredentialSchema, SubProofRequest,
Verifier as ClVerifier,
};
use crate::error::Result;
Expand Down Expand Up @@ -45,8 +45,8 @@ pub fn build_non_credential_schema() -> Result<NonCredentialSchema> {

pub fn build_credential_values(
credential_values: &HashMap<String, AttributeValues>,
master_secret: Option<&CryptoMasterSecret>,
) -> Result<CryptoCredentialValues> {
link_secret: Option<&ClMasterSecret>,
) -> Result<ClCredentialValues> {
trace!(
"build_credential_values >>> credential_values: {:?}",
credential_values
Expand All @@ -56,7 +56,7 @@ pub fn build_credential_values(
for (attr, values) in credential_values {
credential_values_builder.add_dec_known(&attr_common_view(attr), &values.encoded)?;
}
if let Some(ms) = master_secret {
if let Some(ms) = link_secret {
credential_values_builder.add_value_hidden("master_secret", &ms.value()?)?;
}

Expand Down
32 changes: 16 additions & 16 deletions indy-credx/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ use indy_utils::{Qualifiable, Validatable};

use super::tails::TailsReader;

pub fn create_master_secret() -> Result<MasterSecret> {
MasterSecret::new().map_err(err_map!(Unexpected))
pub fn create_link_secret() -> Result<LinkSecret> {
LinkSecret::new().map_err(err_map!(Unexpected))
}

pub fn create_credential_request(
prover_did: &DidValue,
cred_def: &CredentialDefinition,
master_secret: &MasterSecret,
master_secret_id: &str,
link_secret: &LinkSecret,
link_secret_id: &str,
credential_offer: &CredentialOffer,
) -> Result<(CredentialRequest, CredentialRequestMetadata)> {
trace!(
"create_credential_request >>> cred_def: {:?}, master_secret: {:?}, credential_offer: {:?}",
"create_credential_request >>> cred_def: {:?}, link_secret: {:?}, credential_offer: {:?}",
cred_def,
secret!(&master_secret),
secret!(&link_secret),
credential_offer
);

Expand All @@ -46,7 +46,7 @@ pub fn create_credential_request(
cred_def.value.revocation.as_ref(),
)?;
let mut credential_values_builder = ClIssuer::new_credential_values_builder()?;
credential_values_builder.add_value_hidden("master_secret", &master_secret.value.value()?)?;
credential_values_builder.add_value_hidden("master_secret", &link_secret.value.value()?)?;
let cred_values = credential_values_builder.finalize()?;

let nonce = new_nonce()?;
Expand All @@ -71,7 +71,7 @@ pub fn create_credential_request(
let credential_request_metadata = CredentialRequestMetadata {
master_secret_blinding_data,
nonce: nonce_copy,
master_secret_name: master_secret_id.to_string(),
master_secret_name: link_secret_id.to_string(),
};

trace!(
Expand All @@ -86,12 +86,12 @@ pub fn create_credential_request(
pub fn process_credential(
credential: &mut Credential,
cred_request_metadata: &CredentialRequestMetadata,
master_secret: &MasterSecret,
link_secret: &LinkSecret,
cred_def: &CredentialDefinition,
rev_reg_def: Option<&RevocationRegistryDefinition>,
) -> Result<()> {
trace!("process_credential >>> credential: {:?}, cred_request_metadata: {:?}, master_secret: {:?}, cred_def: {:?}, rev_reg_def: {:?}",
credential, cred_request_metadata, secret!(&master_secret), cred_def, rev_reg_def);
trace!("process_credential >>> credential: {:?}, cred_request_metadata: {:?}, link_secret: {:?}, cred_def: {:?}, rev_reg_def: {:?}",
credential, cred_request_metadata, secret!(&link_secret), cred_def, rev_reg_def);

let cred_def = match cred_def {
CredentialDefinition::CredentialDefinitionV1(cd) => cd,
Expand All @@ -101,7 +101,7 @@ pub fn process_credential(
cred_def.value.revocation.as_ref(),
)?;
let credential_values =
build_credential_values(&credential.values.0, Some(&master_secret.value))?;
build_credential_values(&credential.values.0, Some(&link_secret.value))?;
let rev_pub_key = match rev_reg_def {
Some(RevocationRegistryDefinition::RevocationRegistryDefinitionV1(def)) => {
Some(&def.value.public_keys.accum_key)
Expand Down Expand Up @@ -130,12 +130,12 @@ pub fn create_presentation(
pres_req: &PresentationRequest,
credentials: PresentCredentials,
self_attested: Option<HashMap<String, String>>,
master_secret: &MasterSecret,
link_secret: &LinkSecret,
schemas: &HashMap<SchemaId, &Schema>,
cred_defs: &HashMap<CredentialDefinitionId, &CredentialDefinition>,
) -> Result<Presentation> {
trace!("create_proof >>> credentials: {:?}, pres_req: {:?}, credentials: {:?}, self_attested: {:?}, master_secret: {:?}, schemas: {:?}, cred_defs: {:?}",
credentials, pres_req, credentials, &self_attested, secret!(&master_secret), schemas, cred_defs);
trace!("create_proof >>> credentials: {:?}, pres_req: {:?}, credentials: {:?}, self_attested: {:?}, link_secret: {:?}, schemas: {:?}, cred_defs: {:?}",
credentials, pres_req, credentials, &self_attested, secret!(&link_secret), schemas, cred_defs);

if credentials.is_empty()
&& self_attested
Expand Down Expand Up @@ -192,7 +192,7 @@ pub fn create_presentation(

let credential_schema = build_credential_schema(&schema.attr_names.0)?;
let credential_values =
build_credential_values(&credential.values.0, Some(&master_secret.value))?;
build_credential_values(&credential.values.0, Some(&link_secret.value))?;
let (req_attrs, req_predicates) = prepare_credential_for_proving(
present.requested_attributes,
present.requested_predicates,
Expand Down
2 changes: 1 addition & 1 deletion indy-credx/src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use indy_data_types::{
cred_offer::CredentialOffer,
cred_request::{CredentialRequest, CredentialRequestMetadata},
credential::{AttributeValues, Credential, CredentialValues},
master_secret::MasterSecret,
link_secret::LinkSecret,
pres_request::PresentationRequest,
presentation::Presentation,
rev_reg::{RevocationRegistry, RevocationRegistryDelta},
Expand Down
16 changes: 8 additions & 8 deletions indy-credx/tests/anoncreds_demos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn anoncreds_works_for_single_issuer_single_prover() {
// Create Issuer pseudo wallet
let mut issuer_wallet = IssuerWallet::default();

// Create Prover pseudo wallet and master secret
// Create Prover pseudo wallet and link secret
let mut prover_wallet = ProverWallet::default();

// Issuer creates Schema - would be published to the ledger
Expand Down Expand Up @@ -65,7 +65,7 @@ fn anoncreds_works_for_single_issuer_single_prover() {
let (cred_request, cred_request_metadata) = prover::create_credential_request(
&prover_wallet.did,
&*gvt_cred_def,
&prover_wallet.master_secret,
&prover_wallet.link_secret,
"default",
&cred_offer,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ fn anoncreds_works_for_single_issuer_single_prover() {
prover::process_credential(
&mut recv_cred,
&cred_request_metadata,
&prover_wallet.master_secret,
&prover_wallet.link_secret,
&*gvt_cred_def,
None,
)
Expand Down Expand Up @@ -160,7 +160,7 @@ fn anoncreds_works_for_single_issuer_single_prover() {
&pres_request,
present,
Some(self_attested),
&prover_wallet.master_secret,
&prover_wallet.link_secret,
&schemas,
&cred_defs,
)
Expand Down Expand Up @@ -220,7 +220,7 @@ fn anoncreds_works_for_single_issuer_single_prover_unrevoked() {
// Create Issuer pseudo wallet
let mut issuer_wallet = IssuerWallet::default();

// Create Prover pseudo wallet and master secret
// Create Prover pseudo wallet and link secret
let mut prover_wallet = ProverWallet::default();

// Issuer creates Schema - would be published to the ledger
Expand Down Expand Up @@ -280,7 +280,7 @@ fn anoncreds_works_for_single_issuer_single_prover_unrevoked() {
let (cred_request, cred_request_metadata) = prover::create_credential_request(
&prover_wallet.did,
&gvt_cred_def,
&prover_wallet.master_secret,
&prover_wallet.link_secret,
"default",
&cred_offer,
)
Expand Down Expand Up @@ -321,7 +321,7 @@ fn anoncreds_works_for_single_issuer_single_prover_unrevoked() {
prover::process_credential(
&mut recv_cred,
&cred_request_metadata,
&prover_wallet.master_secret,
&prover_wallet.link_secret,
&*gvt_cred_def,
Some(&rev_reg_def),
)
Expand Down Expand Up @@ -393,7 +393,7 @@ fn anoncreds_works_for_single_issuer_single_prover_unrevoked() {
&pres_request,
present,
Some(self_attested),
&prover_wallet.master_secret,
&prover_wallet.link_secret,
&schemas,
&cred_defs,
)
Expand Down
8 changes: 4 additions & 4 deletions indy-credx/tests/utils/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use indy_credx::types::{CredentialDefinitionPrivate, CredentialKeyCorrectnessPro

use indy_data_types::anoncreds::cred_def::CredentialDefinition;
use indy_data_types::anoncreds::credential::Credential;
use indy_data_types::anoncreds::master_secret::MasterSecret;
use indy_data_types::anoncreds::link_secret::LinkSecret;
use indy_utils::did::DidValue;

pub const ISSUER_DID: &'static str = "NcYxiDXkpYi6ov5FcYDi1e";
Expand Down Expand Up @@ -56,16 +56,16 @@ impl Default for IssuerWallet {
pub struct ProverWallet {
pub did: DidValue,
pub credentials: Vec<Credential>,
pub master_secret: MasterSecret,
pub link_secret: LinkSecret,
}

impl Default for ProverWallet {
fn default() -> Self {
let master_secret = MasterSecret::new().expect("Error creating prover master secret");
let link_secret = LinkSecret::new().expect("Error creating prover link secret");
Self {
did: DidValue::from(PROVER_DID.to_string()),
credentials: vec![],
master_secret,
link_secret,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::anoncreds_clsignatures::{MasterSecret as ClMasterSecret, Prover as Cl
use crate::ConversionError;

#[derive(Serialize, Deserialize)]
pub struct MasterSecret {
pub struct LinkSecret {
pub value: ClMasterSecret,
}

impl MasterSecret {
impl LinkSecret {
#[cfg(any(feature = "cl", feature = "cl_native"))]
#[inline]
pub fn new() -> Result<Self, ConversionError> {
Expand All @@ -27,9 +27,9 @@ impl MasterSecret {
}
}

impl fmt::Debug for MasterSecret {
impl fmt::Debug for LinkSecret {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("MasterSecret")
f.debug_tuple("LinkSecret")
.field(if cfg!(test) { &self.value } else { &"<hidden>" })
.finish()
}
Expand Down
4 changes: 2 additions & 2 deletions indy-data-types/src/anoncreds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub mod cred_request;
/// Credentials
pub mod credential;

/// Identity master secret
/// Identity link secret
#[cfg(any(feature = "cl", feature = "cl_native"))]
pub mod master_secret;
pub mod link_secret;

/// Nonce used in presentation requests
pub mod nonce;
Expand Down
Loading

0 comments on commit 1a824e3

Please sign in to comment.