add ecash params to api
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::scheme::withdrawal::WithdrawalRequest;
|
||||
use crate::scheme::EcashCredential;
|
||||
use crate::setup::Parameters;
|
||||
use crate::traits::Bytable;
|
||||
|
||||
macro_rules! impl_clone {
|
||||
@@ -14,3 +15,4 @@ macro_rules! impl_clone {
|
||||
|
||||
impl_clone!(WithdrawalRequest);
|
||||
impl_clone!(EcashCredential);
|
||||
impl_clone!(Parameters);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::scheme::EcashCredential;
|
||||
use crate::setup::Parameters;
|
||||
use crate::traits::Base58;
|
||||
use crate::VerificationKeyAuth;
|
||||
use serde::de::Unexpected;
|
||||
@@ -49,3 +50,4 @@ macro_rules! impl_serde {
|
||||
impl_serde!(WithdrawalRequest, V1);
|
||||
impl_serde!(EcashCredential, V2);
|
||||
impl_serde!(VerificationKeyAuth, V3);
|
||||
impl_serde!(Parameters, V4);
|
||||
|
||||
@@ -6,7 +6,9 @@ use group::Curve;
|
||||
use rand::thread_rng;
|
||||
|
||||
use crate::error::{CompactEcashError, Result};
|
||||
use crate::traits::Bytable;
|
||||
use crate::utils::{hash_g1, try_deserialize_g2_projective, Signature};
|
||||
use crate::Base58;
|
||||
|
||||
const ATTRIBUTES_LEN: usize = 3;
|
||||
|
||||
@@ -210,6 +212,19 @@ impl TryFrom<&[u8]> for Parameters {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Bytable for Parameters {
|
||||
fn to_byte_vec(&self) -> Vec<u8> {
|
||||
self.to_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn try_from_byte_slice(slice: &[u8]) -> std::result::Result<Self, CompactEcashError> {
|
||||
Self::try_from(slice)
|
||||
}
|
||||
}
|
||||
|
||||
impl Base58 for Parameters {}
|
||||
|
||||
pub fn setup(ll: u64) -> Parameters {
|
||||
let grp = GroupParameters::new().unwrap();
|
||||
let x = grp.random_scalar();
|
||||
|
||||
@@ -6,6 +6,7 @@ use getset::{CopyGetters, Getters};
|
||||
use nym_compact_ecash::{
|
||||
error::CompactEcashError,
|
||||
scheme::{withdrawal::WithdrawalRequest, EcashCredential},
|
||||
setup::Parameters,
|
||||
VerificationKeyAuth,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -164,3 +165,16 @@ impl CosmosAddressResponse {
|
||||
CosmosAddressResponse { addr }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct EcashParametersResponse {
|
||||
pub params: Parameters,
|
||||
}
|
||||
|
||||
impl EcashParametersResponse {
|
||||
pub fn new(params: &Parameters) -> EcashParametersResponse {
|
||||
EcashParametersResponse {
|
||||
params: params.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ use crate::support::storage::NymApiStorage;
|
||||
use getset::{CopyGetters, Getters};
|
||||
use keypair::KeyPair;
|
||||
use nym_api_requests::coconut::{
|
||||
BlindSignRequestBody, BlindedSignatureResponse, VerifyCredentialBody, VerifyCredentialResponse,
|
||||
BlindSignRequestBody, BlindedSignatureResponse, EcashParametersResponse, VerifyCredentialBody,
|
||||
VerifyCredentialResponse,
|
||||
};
|
||||
use nym_coconut::VerificationKey;
|
||||
use nym_coconut_bandwidth_contract_common::spend_credential::{
|
||||
@@ -22,7 +23,7 @@ use nym_compact_ecash::error::CompactEcashError;
|
||||
use nym_compact_ecash::scheme::keygen::{KeyPairAuth, SecretKeyAuth};
|
||||
use nym_compact_ecash::scheme::withdrawal::WithdrawalRequest;
|
||||
use nym_compact_ecash::scheme::EcashCredential;
|
||||
use nym_compact_ecash::setup::GroupParameters;
|
||||
use nym_compact_ecash::setup::{setup, GroupParameters, Parameters};
|
||||
use nym_compact_ecash::utils::BlindedSignature;
|
||||
use nym_compact_ecash::{PublicKeyUser, VerificationKeyAuth};
|
||||
use nym_config::defaults::NYM_API_VERSION;
|
||||
@@ -54,6 +55,7 @@ pub(crate) mod tests;
|
||||
pub struct State {
|
||||
client: Arc<dyn LocalClient + Send + Sync>,
|
||||
mix_denom: String,
|
||||
ecash_params: Parameters,
|
||||
key_pair: KeyPair,
|
||||
comm_channel: Arc<dyn APICommunicationChannel + Send + Sync>,
|
||||
storage: NymApiStorage,
|
||||
@@ -78,6 +80,7 @@ impl State {
|
||||
Self {
|
||||
client,
|
||||
mix_denom,
|
||||
ecash_params: setup(100),
|
||||
key_pair,
|
||||
comm_channel,
|
||||
storage,
|
||||
@@ -193,7 +196,11 @@ impl InternalSignRequest {
|
||||
rocket.manage(state).mount(
|
||||
// this format! is so ugly...
|
||||
format!("/{}/{}/{}", NYM_API_VERSION, COCONUT_ROUTES, BANDWIDTH),
|
||||
routes![post_blind_sign, verify_bandwidth_credential],
|
||||
routes![
|
||||
post_blind_sign,
|
||||
verify_bandwidth_credential,
|
||||
ecash_parameters
|
||||
],
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -284,6 +291,11 @@ pub async fn verify_bandwidth_credential(
|
||||
Ok(Json(VerifyCredentialResponse::new(true)))
|
||||
}
|
||||
|
||||
#[get("/ecash-parameters")]
|
||||
pub async fn ecash_parameters(state: &RocketState<State>) -> Result<Json<EcashParametersResponse>> {
|
||||
Ok(Json(EcashParametersResponse::new(&state.ecash_params)))
|
||||
}
|
||||
|
||||
// #[post("/verify-bandwidth-credential", data = "<verify_credential_body>")]
|
||||
// pub async fn verify_bandwidth_credential(
|
||||
// verify_credential_body: Json<VerifyCredentialBody>,
|
||||
|
||||
Reference in New Issue
Block a user