diff --git a/common/credentials/src/utils.rs b/common/credentials/src/utils.rs index 36bce5f562..737b21249e 100644 --- a/common/credentials/src/utils.rs +++ b/common/credentials/src/utils.rs @@ -4,8 +4,8 @@ use url::Url; use coconut_interface::{ - aggregate_signature_shares, aggregate_verification_keys, prepare_blind_sign, - prove_bandwidth_credential, Attribute, BlindSignRequestBody, Credential, Parameters, Signature, + aggregate_signature_shares, aggregate_verification_keys, Attribute, + BlindSignRequestBody, Credential, Parameters, prepare_blind_sign, prove_bandwidth_credential, Signature, SignatureShare, VerificationKey, }; @@ -94,7 +94,7 @@ async fn obtain_partial_credential( validator_vk, private_attributes, public_attributes, - &blind_sign_request.commitment_hash, + &blind_sign_request.get_commitment_hash(), ) .unwrap()) } @@ -122,7 +122,7 @@ pub async fn obtain_aggregate_signature( &client, &validator_partial_vk.key, ) - .await?; + .await?; shares.push(SignatureShare::new(first, 0)); for (id, validator_url) in validators.iter().enumerate().skip(1) { @@ -135,7 +135,7 @@ pub async fn obtain_aggregate_signature( &client, &validator_partial_vk.key, ) - .await?; + .await?; let share = SignatureShare::new(signature, id as u64); shares.push(share) } diff --git a/common/nymcoconut/src/scheme/issuance.rs b/common/nymcoconut/src/scheme/issuance.rs index 391f7ffda2..9c26730293 100644 --- a/common/nymcoconut/src/scheme/issuance.rs +++ b/common/nymcoconut/src/scheme/issuance.rs @@ -18,16 +18,16 @@ use std::convert::TryInto; use bls12_381::{G1Affine, G1Projective, Scalar}; use group::{Curve, GroupEncoding}; +use crate::{Attribute, elgamal, ElGamalKeyPair}; use crate::elgamal::{Ciphertext, EphemeralKey}; use crate::error::{CoconutError, Result}; use crate::proofs::ProofCmCs; -use crate::scheme::setup::Parameters; use crate::scheme::BlindedSignature; use crate::scheme::SecretKey; +use crate::scheme::setup::Parameters; /// Creates a Coconut Signature under a given secret key on a set of public attributes only. #[cfg(test)] use crate::Signature; -use crate::{elgamal, Attribute, ElGamalKeyPair}; // TODO: possibly completely remove those two functions. // They only exist to have a simpler and smaller code snippets to test // basic functionalities. @@ -42,7 +42,7 @@ pub struct BlindSignRequest { // cm commitment: G1Projective, // h - pub commitment_hash: G1Projective, + commitment_hash: G1Projective, // c private_attributes_ciphertexts: Vec, // pi_s @@ -147,6 +147,10 @@ impl BlindSignRequest { ) } + pub fn get_commitment_hash(&self) -> G1Projective { + self.commitment_hash + } + // TODO: perhaps also include pi_s.len()? // to be determined once we implement serde to make sure its 1:1 compatible // with bincode @@ -338,10 +342,10 @@ pub fn sign( // x + m0 * y0 + m1 * y1 + ... mn * yn let exponent = secret_key.x + public_attributes - .iter() - .zip(secret_key.ys.iter()) - .map(|(m_i, y_i)| m_i * y_i) - .sum::(); + .iter() + .zip(secret_key.ys.iter()) + .map(|(m_i, y_i)| m_i * y_i) + .sum::(); let sig2 = h * exponent; Ok(Signature(h, sig2)) @@ -364,7 +368,7 @@ mod tests { &private_attributes, &public_attributes, ) - .unwrap(); + .unwrap(); let bytes = lambda.to_bytes(); println!("{:?}", bytes.len()); @@ -382,7 +386,7 @@ mod tests { &private_attributes, &public_attributes, ) - .unwrap(); + .unwrap(); let bytes = lambda.to_bytes(); assert_eq!( diff --git a/common/nymcoconut/src/scheme/mod.rs b/common/nymcoconut/src/scheme/mod.rs index 043bea2d5c..85fc0d2dc7 100644 --- a/common/nymcoconut/src/scheme/mod.rs +++ b/common/nymcoconut/src/scheme/mod.rs @@ -22,13 +22,13 @@ use group::Curve; pub use keygen::{SecretKey, VerificationKey}; +use crate::{Attribute, elgamal}; use crate::elgamal::Ciphertext; use crate::error::{CoconutError, Result}; use crate::scheme::setup::Parameters; use crate::scheme::verification::check_bilinear_pairing; use crate::traits::{Base58, Bytable}; use crate::utils::try_deserialize_g1_projective; -use crate::{elgamal, Attribute}; pub mod aggregation; pub mod issuance; @@ -265,16 +265,16 @@ mod tests { &lambda, &[], ) - .unwrap() - .unblind( - ¶ms, - elgamal_keypair.private_key(), - &keypair1.verification_key(), - &private_attributes, - &[], - &lambda.commitment_hash, - ) - .unwrap(); + .unwrap() + .unblind( + ¶ms, + elgamal_keypair.private_key(), + &keypair1.verification_key(), + &private_attributes, + &[], + &lambda.get_commitment_hash(), + ) + .unwrap(); let sig2 = blind_sign( &mut params, @@ -283,16 +283,16 @@ mod tests { &lambda, &[], ) - .unwrap() - .unblind( - ¶ms, - elgamal_keypair.private_key(), - &keypair2.verification_key(), - &private_attributes, - &[], - &lambda.commitment_hash, - ) - .unwrap(); + .unwrap() + .unblind( + ¶ms, + elgamal_keypair.private_key(), + &keypair2.verification_key(), + &private_attributes, + &[], + &lambda.get_commitment_hash(), + ) + .unwrap(); let theta1 = prove_bandwidth_credential( &mut params, @@ -301,7 +301,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); let theta2 = prove_bandwidth_credential( &mut params, @@ -310,7 +310,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); assert!(verify_credential( ¶ms, @@ -384,7 +384,7 @@ mod tests { &private_attributes, &public_attributes, ) - .unwrap(); + .unwrap(); let sig1 = blind_sign( &mut params, @@ -393,16 +393,16 @@ mod tests { &lambda, &public_attributes, ) - .unwrap() - .unblind( - ¶ms, - elgamal_keypair.private_key(), - &keypair1.verification_key(), - &private_attributes, - &public_attributes, - &lambda.commitment_hash, - ) - .unwrap(); + .unwrap() + .unblind( + ¶ms, + elgamal_keypair.private_key(), + &keypair1.verification_key(), + &private_attributes, + &public_attributes, + &lambda.get_commitment_hash(), + ) + .unwrap(); let sig2 = blind_sign( &mut params, @@ -411,16 +411,16 @@ mod tests { &lambda, &public_attributes, ) - .unwrap() - .unblind( - ¶ms, - elgamal_keypair.private_key(), - &keypair2.verification_key(), - &private_attributes, - &public_attributes, - &lambda.commitment_hash, - ) - .unwrap(); + .unwrap() + .unblind( + ¶ms, + elgamal_keypair.private_key(), + &keypair2.verification_key(), + &private_attributes, + &public_attributes, + &lambda.get_commitment_hash(), + ) + .unwrap(); let theta1 = prove_bandwidth_credential( &mut params, @@ -429,7 +429,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); let theta2 = prove_bandwidth_credential( &mut params, @@ -438,7 +438,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); assert!(verify_credential( ¶ms, @@ -479,7 +479,7 @@ mod tests { &private_attributes, &public_attributes, ) - .unwrap(); + .unwrap(); let sigs = keypairs .iter() @@ -491,16 +491,16 @@ mod tests { &lambda, &public_attributes, ) - .unwrap() - .unblind( - ¶ms, - elgamal_keypair.private_key(), - &keypair.verification_key(), - &private_attributes, - &public_attributes, - &lambda.commitment_hash, - ) - .unwrap() + .unwrap() + .unblind( + ¶ms, + elgamal_keypair.private_key(), + &keypair.verification_key(), + &private_attributes, + &public_attributes, + &lambda.get_commitment_hash(), + ) + .unwrap() }) .collect::>(); @@ -525,7 +525,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); assert!(verify_credential( ¶ms, @@ -547,7 +547,7 @@ mod tests { serial_number, binding_number, ) - .unwrap(); + .unwrap(); assert!(verify_credential( ¶ms, @@ -570,7 +570,7 @@ mod tests { signature.0.to_affine().to_compressed(), signature.1.to_affine().to_compressed(), ] - .concat(); + .concat(); assert_eq!(expected_bytes, bytes); assert_eq!(signature, Signature::try_from(&bytes[..]).unwrap()) } @@ -590,10 +590,10 @@ mod tests { // also make sure it is equivalent to the internal g1 compressed bytes concatenated let expected_bytes = [ blinded_sig.0.to_affine().to_compressed(), - blinded_sig.1 .0.to_affine().to_compressed(), - blinded_sig.1 .1.to_affine().to_compressed(), + blinded_sig.1.0.to_affine().to_compressed(), + blinded_sig.1.1.to_affine().to_compressed(), ] - .concat(); + .concat(); assert_eq!(expected_bytes, bytes); assert_eq!(blinded_sig, BlindedSignature::try_from(&bytes[..]).unwrap()) } diff --git a/common/nymcoconut/src/tests/e2e.rs b/common/nymcoconut/src/tests/e2e.rs index d271008aa7..bc9c7fb506 100644 --- a/common/nymcoconut/src/tests/e2e.rs +++ b/common/nymcoconut/src/tests/e2e.rs @@ -1,7 +1,7 @@ use crate::{ - aggregate_signature_shares, aggregate_verification_keys, blind_sign, elgamal_keygen, - prepare_blind_sign, prove_bandwidth_credential, setup, ttp_keygen, verify_credential, - CoconutError, Signature, SignatureShare, VerificationKey, + aggregate_signature_shares, aggregate_verification_keys, blind_sign, CoconutError, + elgamal_keygen, prepare_blind_sign, prove_bandwidth_credential, setup, Signature, + SignatureShare, ttp_keygen, VerificationKey, verify_credential, }; #[test] @@ -61,7 +61,7 @@ fn main() -> Result<(), CoconutError> { &verification_key, &private_attributes, &public_attributes, - &blind_sign_request.commitment_hash, + &blind_sign_request.get_commitment_hash(), ) .unwrap() })