9e8f550e6d
* Add placeholder client for implementing coconut interactions * Add db for persistance * Add nymd client * Add new coconut-bandwidth contract * Call deposit function * Introduce error handling * Call the old flow of getting a signature * List available tx hashes * Add signed req in body * Save signature received * Add event generation * Checks in validator-api * Fail with error instead of panic in validator-api route * Fix contract address and small bug * Add file db for storing previous signatures * Encrypt and store data in validator-api * Decrypt the received signature * Remove tx hashes after getting credentials * Small listing changes in client * Change response so that it easier to serialize * Error message is sent to client for display * Remove already signed error and return the previous sig * Merge signature with deposit data in client * Entrypoint for getting the encrypted signature * Refactor blinding stuff so that it can be backed up * Backed up the blind sign request * Client can re-request the encrypted signature shares * Update crypto features * Fix clippy * Activate instantiate test and remove unused code * Add tx tests * Add verification key endpoint test * Voucher consistency test * Test for some errors and a race condition on blind signing * Refactor and add client trait for enabling better testing env * Test some more of blind sign * Finished testing all extract_encryption_key paths * Split into function test and endpoint test * Test for correct signature * Test for state functions * Remove print * Test blind_sign endpoint * Test for cached signature endpoint * Stricter types in voucher * Rename signature with partial_bandwidth_credential * Extra route levels * Length check and remove some unused code from coconut interface * Renamed coconut-bandwidth common crate * Renamed verification_key to identity_key * Use const instead of hardcoded values * Use type aliases for crypto algorithms * Remove unused mods, until needed * Remove unneeded unwrap * Fix some coconut issues that were blocking the wasm client build * Move from sled to existing sql database * Update tests for new db type * Fix wasm for coconut too * Remove sled from dependencies
73 lines
2.2 KiB
Rust
73 lines
2.2 KiB
Rust
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use coconut_interface::{Attribute, BlindSignRequest, Bytable, PrivateAttribute};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crypto::asymmetric::{encryption, identity};
|
|
|
|
use crate::error::{CredentialClientError, Result};
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub(crate) struct KeyPair {
|
|
pub public_key: String,
|
|
pub private_key: String,
|
|
}
|
|
|
|
impl From<identity::KeyPair> for KeyPair {
|
|
fn from(kp: identity::KeyPair) -> Self {
|
|
Self {
|
|
public_key: kp.public_key().to_base58_string(),
|
|
private_key: kp.private_key().to_base58_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<encryption::KeyPair> for KeyPair {
|
|
fn from(kp: encryption::KeyPair) -> Self {
|
|
Self {
|
|
public_key: kp.public_key().to_base58_string(),
|
|
private_key: kp.private_key().to_base58_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub(crate) struct State {
|
|
pub amount: u64,
|
|
pub tx_hash: String,
|
|
pub signing_keypair: KeyPair,
|
|
pub encryption_keypair: KeyPair,
|
|
pub blind_request_data: Option<RequestData>,
|
|
pub signature: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub(crate) struct RequestData {
|
|
pub serial_number: Vec<u8>,
|
|
pub binding_number: Vec<u8>,
|
|
pub first_attribute: Vec<u8>,
|
|
pub second_attribute: Vec<u8>,
|
|
pub blind_sign_req: Vec<u8>,
|
|
}
|
|
|
|
impl RequestData {
|
|
pub fn new(
|
|
private_attributes: Vec<PrivateAttribute>,
|
|
attributes: &[Attribute],
|
|
blind_sign_request: &BlindSignRequest,
|
|
) -> Result<Self> {
|
|
if private_attributes.len() != 2 || attributes.len() != 2 {
|
|
Err(CredentialClientError::WrongAttributeNumber)
|
|
} else {
|
|
Ok(RequestData {
|
|
serial_number: private_attributes[0].to_byte_vec(),
|
|
binding_number: private_attributes[1].to_byte_vec(),
|
|
first_attribute: attributes[0].to_byte_vec(),
|
|
second_attribute: attributes[1].to_byte_vec(),
|
|
blind_sign_req: blind_sign_request.to_bytes(),
|
|
})
|
|
}
|
|
}
|
|
}
|