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>
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use coconut_interface::{
|
|
Attribute, BlindSignRequest, BlindSignRequestBody, BlindedSignature, BlindedSignatureResponse,
|
|
KeyPair, Parameters, VerificationKeyResponse,
|
|
};
|
|
use config::defaults::VALIDATOR_API_VERSION;
|
|
use getset::{CopyGetters, Getters};
|
|
use rocket::fairing::AdHoc;
|
|
use rocket::serde::json::Json;
|
|
use rocket::State;
|
|
|
|
#[derive(Getters, CopyGetters, Debug)]
|
|
pub(crate) struct InternalSignRequest {
|
|
// Total number of parameters to generate for
|
|
#[getset(get_copy)]
|
|
total_params: u32,
|
|
#[getset(get)]
|
|
public_attributes: Vec<Attribute>,
|
|
#[getset(get)]
|
|
blind_sign_request: BlindSignRequest,
|
|
}
|
|
|
|
impl InternalSignRequest {
|
|
pub fn new(
|
|
total_params: u32,
|
|
public_attributes: Vec<Attribute>,
|
|
blind_sign_request: BlindSignRequest,
|
|
) -> InternalSignRequest {
|
|
InternalSignRequest {
|
|
total_params,
|
|
public_attributes,
|
|
blind_sign_request,
|
|
}
|
|
}
|
|
|
|
pub fn stage(key_pair: KeyPair) -> AdHoc {
|
|
AdHoc::on_ignite("Internal Sign Request Stage", |rocket| async {
|
|
rocket.manage(key_pair).mount(
|
|
// this format! is so ugly...
|
|
format!("/{}", VALIDATOR_API_VERSION),
|
|
routes![post_blind_sign, get_verification_key],
|
|
)
|
|
})
|
|
}
|
|
}
|
|
|
|
fn blind_sign(request: InternalSignRequest, key_pair: &KeyPair) -> BlindedSignature {
|
|
let params = Parameters::new(request.total_params()).unwrap();
|
|
coconut_interface::blind_sign(
|
|
¶ms,
|
|
&key_pair.secret_key(),
|
|
request.blind_sign_request(),
|
|
request.public_attributes(),
|
|
)
|
|
.unwrap()
|
|
}
|
|
|
|
#[post("/blind-sign", data = "<blind_sign_request_body>")]
|
|
// Until we have serialization and deserialization traits we'll be using a crutch
|
|
pub async fn post_blind_sign(
|
|
blind_sign_request_body: Json<BlindSignRequestBody>,
|
|
key_pair: &State<KeyPair>,
|
|
) -> Json<BlindedSignatureResponse> {
|
|
debug!("{:?}", blind_sign_request_body);
|
|
let internal_request = InternalSignRequest::new(
|
|
*blind_sign_request_body.total_params(),
|
|
blind_sign_request_body.public_attributes(),
|
|
blind_sign_request_body.blind_sign_request().clone(),
|
|
);
|
|
let blinded_signature = blind_sign(internal_request, key_pair);
|
|
Json(BlindedSignatureResponse::new(blinded_signature))
|
|
}
|
|
|
|
#[get("/verification-key")]
|
|
pub async fn get_verification_key(key_pair: &State<KeyPair>) -> Json<VerificationKeyResponse> {
|
|
Json(VerificationKeyResponse::new(key_pair.verification_key()))
|
|
}
|