Add function to sign an expiration date

This commit is contained in:
aniampio
2023-11-21 11:23:45 +00:00
parent bb35e67106
commit 78f01dbe9a
6 changed files with 67 additions and 6 deletions
@@ -0,0 +1,3 @@
pub const ATTRIBUTES_LEN: usize = 3; // number of attributes encoded in a single zk-nym credential
pub const VALIDITY_PERIOD: u64 = 30;
pub const TYPE_EXP: [u8; 32] = *b"ZKNYMEXPIRATIONDATE4llCBMEypAxr3";
@@ -26,6 +26,7 @@ mod scheme;
mod tests;
mod traits;
mod utils;
mod constants;
pub type Attribute = Scalar;
@@ -0,0 +1,60 @@
use crate::scheme::setup::Parameters;
use crate::scheme::keygen::{SecretKeyAuth, VerificationKeyAuth};
use crate::constants;
use crate::utils::hash_g1;
use bls12_381::{Scalar, G1Projective};
#[derive(Debug, PartialEq, Clone)]
pub struct ExpirationDateSignature{
pub(crate) h : G1Projective,
pub(crate) s : G1Projective,
}
pub type PartialExpirationDateSignature = ExpirationDateSignature;
// This function is execute by a single issuing authority
pub fn sign_expiration_date(params: &Parameters, sk_auth: SecretKeyAuth, expiration_date: u64) -> Vec<PartialExpirationDateSignature>{
// Initialize a vector to collect exp_sign values
let mut exp_signs: Vec<PartialExpirationDateSignature> = Vec::new();
for l in 0..constants::VALIDITY_PERIOD {
let m0: u64 = expiration_date;
let m1: u64 = expiration_date - constants::VALIDITY_PERIOD + l;
let m2 = constants::TYPE_EXP;
// Convert u64 values to bytes
let m0_bytes: [u8; 8] = m0.to_le_bytes();
let m1_bytes: [u8; 8] = m1.to_le_bytes();
let mut concatenated_attributes = Vec::new();
concatenated_attributes.extend_from_slice(&m0_bytes);
concatenated_attributes.extend_from_slice(&m1_bytes);
concatenated_attributes.extend_from_slice(&m2);
// Compute the hash
let h = hash_g1(concatenated_attributes);
// Compute s = x + y[0]*m0 + y[1]*m1 + y[2]*m2
let mut s_exponent = sk_auth.x;
// Perform scalar-point multiplications and accumulate the result
s_exponent += &sk_auth.ys[0] * Scalar::from(m0);
s_exponent += &sk_auth.ys[1] * Scalar::from(m1);
s_exponent += &sk_auth.ys[2] * Scalar::from_bytes(&m2).unwrap();
// Create the signature on the expiration date
let exp_sign = PartialExpirationDateSignature {
h,
s: h * s_exponent,
};
// Collect the exp_sign value into the vector
exp_signs.push(exp_sign);
}
exp_signs
}
// pub fn aggregate_expiration_signatures(params: &Parameters, vk_auth: &VerificationKeyAuth, expiration_date: u64, indices: Option<&[u64]>, )
@@ -405,7 +405,7 @@ pub fn ttp_keygen(
// generate polynomials
let v = Polynomial::new_random(params, threshold - 1);
let ws = (0..attributes)
let ws = (0..attributes+1)
.map(|_| Polynomial::new_random(params, threshold - 1))
.collect::<Vec<_>>();
@@ -20,6 +20,7 @@ pub mod identify;
pub mod keygen;
pub mod setup;
pub mod withdrawal;
pub mod expiration_date_signatures;
#[derive(Debug, Clone, PartialEq)]
pub struct PartialWallet {
@@ -6,8 +6,8 @@ use rand::thread_rng;
use crate::error::{CompactEcashError, Result};
use crate::utils::{hash_g1, Signature};
use crate::constants::ATTRIBUTES_LEN;
const ATTRIBUTES_LEN: usize = 3;
pub struct GroupParameters {
/// Generator of the G1 group
@@ -51,10 +51,6 @@ impl GroupParameters {
&self.gammas
}
// pub(crate) fn gamma1(&self) -> &G1Projective {
// &self.gammas[0]
// }
pub(crate) fn gamma_idx(&self, i: usize) -> Option<&G1Projective>{
self.gammas.get(i)
}