Skip to content

Commit

Permalink
fix: rename master secret to link secret
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>
  • Loading branch information
berendsliedrecht committed Mar 20, 2023
1 parent 742e2d2 commit 0d7cfa2
Show file tree
Hide file tree
Showing 40 changed files with 435 additions and 435 deletions.
6 changes: 6 additions & 0 deletions include/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Generate the header file:
```sh
cbindgen --config include/cbindgen.toml --crate anoncreds --output include/libanoncreds.h
```

Copy to React Native:

```sh
cp include/libanoncreds.h wrappers/javascript/anoncreds-react-native/cpp/include/
```
10 changes: 5 additions & 5 deletions include/libanoncreds.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ ErrorCode anoncreds_create_credential_offer(FfiStr schema_id,
ErrorCode anoncreds_create_credential_request(FfiStr entropy,
FfiStr prover_did,
ObjectHandle cred_def,
ObjectHandle master_secret,
FfiStr master_secret_id,
ObjectHandle link_secret,
FfiStr link_secret_id,
ObjectHandle cred_offer,
ObjectHandle *cred_req_p,
ObjectHandle *cred_req_meta_p);

ErrorCode anoncreds_create_master_secret(ObjectHandle *master_secret_p);
ErrorCode anoncreds_create_link_secret(ObjectHandle *link_secret_p);

ErrorCode anoncreds_create_or_update_revocation_state(ObjectHandle rev_reg_def,
ObjectHandle rev_status_list,
Expand All @@ -306,7 +306,7 @@ ErrorCode anoncreds_create_presentation(ObjectHandle pres_req,
struct FfiList_FfiCredentialProve credentials_prove,
FfiStrList self_attest_names,
FfiStrList self_attest_values,
ObjectHandle master_secret,
ObjectHandle link_secret,
struct FfiList_ObjectHandle schemas,
FfiStrList schema_ids,
struct FfiList_ObjectHandle cred_defs,
Expand Down Expand Up @@ -354,7 +354,7 @@ ErrorCode anoncreds_object_get_type_name(ObjectHandle handle, const char **resul

ErrorCode anoncreds_process_credential(ObjectHandle cred,
ObjectHandle cred_req_metadata,
ObjectHandle master_secret,
ObjectHandle link_secret,
ObjectHandle cred_def,
ObjectHandle rev_reg_def,
ObjectHandle *cred_p);
Expand Down
80 changes: 41 additions & 39 deletions src/data_types/cred_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ pub struct CredentialRequest {
#[serde(skip_serializing_if = "Option::is_none")]
prover_did: Option<String>,
cred_def_id: CredentialDefinitionId,
pub blinded_ms: ursa::cl::BlindedCredentialSecrets,
pub blinded_ms_correctness_proof: ursa::cl::BlindedCredentialSecretsCorrectnessProof,
#[serde(rename = "blinded_ms")]
pub blinded_ls: ursa::cl::BlindedCredentialSecrets,
#[serde(rename = "blinded_ms_correctness_proof")]
pub blinded_ls_correctness_proof: ursa::cl::BlindedCredentialSecretsCorrectnessProof,
pub nonce: Nonce,
}

Expand Down Expand Up @@ -55,16 +57,16 @@ impl CredentialRequest {
entropy: Option<&str>,
prover_did: Option<&str>,
cred_def_id: CredentialDefinitionId,
blinded_ms: ursa::cl::BlindedCredentialSecrets,
blinded_ms_correctness_proof: ursa::cl::BlindedCredentialSecretsCorrectnessProof,
blinded_ls: ursa::cl::BlindedCredentialSecrets,
blinded_ls_correctness_proof: ursa::cl::BlindedCredentialSecretsCorrectnessProof,
nonce: Nonce,
) -> Result<Self> {
let s = Self {
entropy: entropy.map(|e| e.to_owned()),
prover_did: prover_did.map(|p| p.to_owned()),
cred_def_id,
blinded_ms,
blinded_ms_correctness_proof,
blinded_ls,
blinded_ls_correctness_proof,
nonce,
};
s.validate()?;
Expand All @@ -82,9 +84,9 @@ impl CredentialRequest {

#[derive(Debug, Deserialize, Serialize)]
pub struct CredentialRequestMetadata {
pub master_secret_blinding_data: ursa::cl::CredentialSecretsBlindingFactors,
pub link_secret_blinding_data: ursa::cl::CredentialSecretsBlindingFactors,
pub nonce: Nonce,
pub master_secret_name: String,
pub link_secret_name: String,
}

impl Validatable for CredentialRequestMetadata {}
Expand All @@ -95,7 +97,7 @@ mod cred_req_tests {
data_types::{
cred_def::{CredentialDefinition, CredentialKeyCorrectnessProof, SignatureType},
cred_offer::CredentialOffer,
master_secret::MasterSecret,
link_secret::LinkSecret,
schema::AttributeNames,
},
issuer::{create_credential_definition, create_credential_offer, create_schema},
Expand All @@ -112,7 +114,7 @@ mod cred_req_tests {

const ENTROPY: Option<&str> = Some("entropy");
const PROVER_DID: Option<&str> = Some(LEGACY_DID_IDENTIFIER);
const MASTER_SERCET_ID: &str = "master:secret:id";
const LINK_SERCET_ID: &str = "link:secret:id";

fn cred_def() -> Result<(CredentialDefinition, CredentialKeyCorrectnessProof)> {
let credential_definition_issuer_id = "sample:id";
Expand All @@ -133,8 +135,8 @@ mod cred_req_tests {
Ok((cred_def.0, cred_def.2))
}

fn master_secret() -> MasterSecret {
MasterSecret::new().unwrap()
fn link_secret() -> LinkSecret {
LinkSecret::new().unwrap()
}

fn credential_offer(
Expand All @@ -155,15 +157,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_valid_input() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, false)?;

let res = create_credential_request(
ENTROPY,
None,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -175,15 +177,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_valid_input_legacy() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
PROVER_DID,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -195,15 +197,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_invalid_new_identifiers_and_prover_did() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, false)?;

let res = create_credential_request(
None,
PROVER_DID,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -215,15 +217,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_invalid_prover_did_and_entropy() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
ENTROPY,
PROVER_DID,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -235,15 +237,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_invalid_prover_did() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
ENTROPY,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -255,15 +257,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_with_no_entropy_or_prover_did() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
None,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
);

Expand All @@ -275,15 +277,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_json_contains_entropy() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, false)?;

let res = create_credential_request(
ENTROPY,
None,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
)
.unwrap();
Expand All @@ -298,15 +300,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_json_contains_prover_did_with_legacy_identifiers() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
PROVER_DID,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
)
.unwrap();
Expand All @@ -321,15 +323,15 @@ mod cred_req_tests {
#[test]
fn create_credential_request_json_contains_entropy_with_legacy_identifiers() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let master_secret = master_secret();
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, false)?;

let res = create_credential_request(
ENTROPY,
None,
&cred_def,
&master_secret,
MASTER_SERCET_ID,
&link_secret,
LINK_SERCET_ID,
&credential_offer,
)
.unwrap();
Expand Down
56 changes: 56 additions & 0 deletions src/data_types/link_secret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::fmt;

use crate::error::ConversionError;
use serde::{Deserialize, Serialize};
use ursa::cl::{prover::Prover as UrsaProver, MasterSecret};

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

impl LinkSecret {
#[inline]
pub fn new() -> Result<Self, ConversionError> {
let value = UrsaProver::new_master_secret().map_err(|err| {
ConversionError::from_msg(format!("Error creating link secret: {err}"))
})?;
Ok(Self { value })
}

pub fn try_clone(&self) -> Result<Self, ConversionError> {
Ok(Self {
value: self.value.try_clone().map_err(|e| e.to_string())?,
})
}
}

impl fmt::Debug for LinkSecret {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("LinkSecret")
.field(if cfg!(test) { &self.value } else { &"<hidden>" })
.finish()
}
}


#[cfg(test)]
mod link_secret_tests {
use super::*;

#[test]
fn should_create_new_link_secret() {
let link_secret = LinkSecret::new();
assert!(link_secret.is_ok())
}

#[test]
fn should_clone_link_secret() {
let link_secret = LinkSecret::new().expect("Unable to create link secret");
let link_secret_value = link_secret.value.value().expect("Unable to extract value from link secret");
let cloned_link_secret = link_secret.try_clone().expect("Unable to clone link secret");
let cloned_link_secret_value = cloned_link_secret.value.value().expect("Unable to extract value from cloned link secret");

assert_eq!(link_secret_value, cloned_link_secret_value);
}
}
34 changes: 0 additions & 34 deletions src/data_types/master_secret.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/data_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub mod cred_request;
/// Credentials
pub mod credential;

/// Identity master secret
pub mod master_secret;
/// Identity link secret
pub mod link_secret;

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

0 comments on commit 0d7cfa2

Please sign in to comment.