c7cdd1e1b4
* add pedersen.rs and first alias type * replace ciphertexts in BlindSignRequest by commitments and adapt try_from * update BlindSignRequest.to_byte_vec * add TODO to issuance.rs * [WIP] update CmCs proof to use commitments * complete ProofCmCs construct implementation * [WIP] ProofCmCs verify * complete ProofCmCs verify implementation * complete ProofCmCs to_bytes implementation * complete ProofCmCs from_bytes implementation * WIP update ProofCmCs roundtrip tests * WIP update prepare_blind_sign * update prepare_blind_sign * WIP update blind_sign * update blind_sign * update BlindedSignature and try_from * update BlindedSignature unblind * update BlindedSignature to_bytes * move elgamal encrypto to elgamal and manage imports * add verification keys for g1 method * upadate tests to work with Pedersen commitments * unused remove pedersen.rs * update error message * fix proof_cm_cs_bytes_roundtrip test * Move generation of commitment openings into prepare blind signature function * Edits * Extende the verification key; remove validator's secret key from the unblind function * Update the unblind function throughout the whole nymcoconut repo * Fix broken tests * Run cargo clippy and fmt * Add benchmark measurements * Add more detailed printouts * Change byte printout * Update benchmarks * add public attributes as part of the commitment * update bytes order comment for ProofCmCs * check proof_cm_cs_bytes_roundtrip test and remove TODO * remove irrelevant prints in blind signature tests * remove inappropriate function to get betas_g1 * remove irrelevant prints in verification * Remove print statement and add additional checks on the verification key * Run clippy * Fix coconut call in validator-api * Update dependend packages * Update the input to the obtain partial credential function * Fix the verification key bytes calculation * Run cargo fmt on keygen.rs * Run cargo fmt for validator-api * Run cargo fmt for credentials * Replace concat with chain * Remove unneccessary mut * Run cargo fmt * fix type conversion Co-authored-by: aniampio <anna.piotrowska.15@ucl.ac.uk>
136 lines
3.6 KiB
Rust
136 lines
3.6 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use getset::{CopyGetters, Getters};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
pub use nymcoconut::*;
|
|
|
|
#[derive(Serialize, Deserialize, Getters, CopyGetters, Clone)]
|
|
pub struct Credential {
|
|
#[getset(get = "pub")]
|
|
n_params: u32,
|
|
#[getset(get = "pub")]
|
|
theta: Theta,
|
|
public_attributes: Vec<Vec<u8>>,
|
|
#[getset(get = "pub")]
|
|
signature: Signature,
|
|
}
|
|
impl Credential {
|
|
pub fn new(
|
|
n_params: u32,
|
|
theta: Theta,
|
|
public_attributes: Vec<Vec<u8>>,
|
|
signature: &Signature,
|
|
) -> Credential {
|
|
Credential {
|
|
n_params,
|
|
theta,
|
|
public_attributes,
|
|
signature: *signature,
|
|
}
|
|
}
|
|
|
|
pub fn public_attributes(&self) -> Vec<Vec<u8>> {
|
|
self.public_attributes.clone()
|
|
}
|
|
|
|
pub fn verify(&self, verification_key: &VerificationKey) -> bool {
|
|
let params = Parameters::new(self.n_params).unwrap();
|
|
let public_attributes = self
|
|
.public_attributes
|
|
.iter()
|
|
.map(hash_to_scalar)
|
|
.collect::<Vec<Attribute>>();
|
|
nymcoconut::verify_credential(¶ms, verification_key, &self.theta, &public_attributes)
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Getters, CopyGetters)]
|
|
pub struct VerifyCredentialBody {
|
|
#[getset(get = "pub")]
|
|
n_params: u32,
|
|
#[getset(get = "pub")]
|
|
theta: Theta,
|
|
public_attributes: Vec<String>,
|
|
}
|
|
|
|
impl VerifyCredentialBody {
|
|
pub fn new(
|
|
n_params: u32,
|
|
theta: &Theta,
|
|
public_attributes: &[Attribute],
|
|
) -> VerifyCredentialBody {
|
|
VerifyCredentialBody {
|
|
n_params,
|
|
theta: theta.clone(),
|
|
public_attributes: public_attributes
|
|
.iter()
|
|
.map(|attr| attr.to_bs58())
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
pub fn public_attributes(&self) -> Vec<Attribute> {
|
|
self.public_attributes
|
|
.iter()
|
|
.map(|x| Attribute::try_from_bs58(x).unwrap())
|
|
.collect()
|
|
}
|
|
}
|
|
// All strings are base58 encoded representations of structs
|
|
#[derive(Serialize, Deserialize, Debug, Getters, CopyGetters)]
|
|
pub struct BlindSignRequestBody {
|
|
#[getset(get = "pub")]
|
|
blind_sign_request: BlindSignRequest,
|
|
public_attributes: Vec<String>,
|
|
#[getset(get = "pub")]
|
|
total_params: u32,
|
|
}
|
|
|
|
impl BlindSignRequestBody {
|
|
pub fn new(
|
|
blind_sign_request: &BlindSignRequest,
|
|
public_attributes: &[Attribute],
|
|
total_params: u32,
|
|
) -> BlindSignRequestBody {
|
|
BlindSignRequestBody {
|
|
blind_sign_request: blind_sign_request.clone(),
|
|
public_attributes: public_attributes
|
|
.iter()
|
|
.map(|attr| attr.to_bs58())
|
|
.collect(),
|
|
total_params,
|
|
}
|
|
}
|
|
|
|
pub fn public_attributes(&self) -> Vec<Attribute> {
|
|
self.public_attributes
|
|
.iter()
|
|
.map(|x| Attribute::try_from_bs58(x).unwrap())
|
|
.collect()
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct BlindedSignatureResponse {
|
|
pub blinded_signature: BlindedSignature,
|
|
}
|
|
|
|
impl BlindedSignatureResponse {
|
|
pub fn new(blinded_signature: BlindedSignature) -> BlindedSignatureResponse {
|
|
BlindedSignatureResponse { blinded_signature }
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct VerificationKeyResponse {
|
|
pub key: VerificationKey,
|
|
}
|
|
|
|
impl VerificationKeyResponse {
|
|
pub fn new(key: VerificationKey) -> VerificationKeyResponse {
|
|
VerificationKeyResponse { key }
|
|
}
|
|
}
|