Conditional signature
This commit is contained in:
Generated
+3
-1
@@ -3987,6 +3987,8 @@ version = "0.12.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"attohttpc 0.18.0",
|
||||
"bandwidth-claim-contract",
|
||||
"bip39",
|
||||
"cfg-if 1.0.0",
|
||||
"clap 2.33.3",
|
||||
"coconut-interface",
|
||||
@@ -8247,4 +8249,4 @@ checksum = "615120c7a2431d16cf1cf979e7fc31ba7a5b5e5707b29c8a99e5dbf8a8392a33"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
]
|
||||
|
||||
@@ -196,7 +196,7 @@ fn main() {
|
||||
let bandwidth_credential_attributes = BandwidthVoucherAttributes {
|
||||
serial_number: params.random_scalar(),
|
||||
binding_number: params.random_scalar(),
|
||||
voucher_value: hash_to_scalar(1024u64.to_be_bytes()),
|
||||
voucher_value: Attribute::from(1000000u64),
|
||||
voucher_info: hash_to_scalar("BandwidthVoucher"),
|
||||
};
|
||||
tauri::Builder::default()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// event types
|
||||
pub const VOUCHER_ACQUIRED_EVENT_TYPE: &str = "coconut-acquired";
|
||||
pub const VOUCHER_ACQUIRED_EVENT_TYPE: &str = "coconut_acquired";
|
||||
|
||||
// attributes that are used in multiple places
|
||||
pub const VOUCHER_VALUE: &str = "value";
|
||||
|
||||
@@ -46,6 +46,7 @@ pub mod error;
|
||||
pub mod fee;
|
||||
pub mod traits;
|
||||
pub mod wallet;
|
||||
use cosmrs::rpc::endpoint::tx::Response as TxResponse;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NymdClient<C> {
|
||||
@@ -274,6 +275,13 @@ impl<C> NymdClient<C> {
|
||||
self.client.get_balance(address, denom).await
|
||||
}
|
||||
|
||||
pub async fn get_tx(&self, id: tx::Hash) -> Result<TxResponse, NymdError>
|
||||
where
|
||||
C: CosmWasmClient + Sync,
|
||||
{
|
||||
self.client.get_tx(id).await
|
||||
}
|
||||
|
||||
pub async fn get_total_supply(&self) -> Result<Vec<Coin>, NymdError>
|
||||
where
|
||||
C: CosmWasmClient + Sync,
|
||||
|
||||
@@ -15,6 +15,7 @@ rust-version = "1.56"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bip39 = "1.0.1"
|
||||
clap = "2.33.0"
|
||||
dirs = "3.0"
|
||||
dotenv = "0.15.0"
|
||||
@@ -47,6 +48,7 @@ config = { path = "../common/config" }
|
||||
crypto = { path="../common/crypto" }
|
||||
gateway-client = { path="../common/client-libs/gateway-client" }
|
||||
mixnet-contract-common = { path= "../common/cosmwasm-smart-contracts/mixnet-contract" }
|
||||
bandwidth-claim-contract = { path= "../common/bandwidth-claim-contract" }
|
||||
nymsphinx = { path="../common/nymsphinx" }
|
||||
topology = { path="../common/topology" }
|
||||
validator-api-requests = { path = "validator-api-requests" }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use bandwidth_claim_contract::events::{VOUCHER_ACQUIRED_EVENT_TYPE, VOUCHER_VALUE};
|
||||
use bip39::Mnemonic;
|
||||
use coconut_interface::{
|
||||
elgamal::PublicKey, Attribute, BlindSignRequest, BlindSignRequestBody, BlindedSignature,
|
||||
BlindedSignatureResponse, KeyPair, Parameters, VerificationKeyResponse,
|
||||
@@ -10,6 +12,10 @@ use getset::{CopyGetters, Getters};
|
||||
use rocket::fairing::AdHoc;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
use std::str::FromStr;
|
||||
use url::Url;
|
||||
use validator_client::nymd::tx::Hash;
|
||||
use validator_client::nymd::{AccountId, NymdClient};
|
||||
|
||||
#[derive(Getters, CopyGetters, Debug)]
|
||||
pub(crate) struct InternalSignRequest {
|
||||
@@ -69,6 +75,52 @@ pub async fn post_blind_sign(
|
||||
key_pair: &State<KeyPair>,
|
||||
) -> Json<BlindedSignatureResponse> {
|
||||
debug!("{:?}", blind_sign_request_body);
|
||||
let nymd_url = Url::from_str("http://127.0.0.1:26657").unwrap();
|
||||
let mnemonic = Mnemonic::from_str(&"have armor behind appear labor choose fire erase arrive slice mother acid second rely exhibit grief soul super record useless antique excite ocean walnut").unwrap();
|
||||
let nymd_client = NymdClient::connect_with_mnemonic(
|
||||
config::defaults::all::Network::SANDBOX,
|
||||
nymd_url.as_ref(),
|
||||
None,
|
||||
None,
|
||||
AccountId::from_str("").ok(),
|
||||
mnemonic,
|
||||
None,
|
||||
)
|
||||
.expect("Could not create nymd client");
|
||||
let response = nymd_client
|
||||
.get_tx(
|
||||
Hash::from_str("7CFAC90461CE017C9D8F987CF15FD3297A32E82B882B14A2A706F2B368355A12")
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Events: {:?}", response.tx_result.events);
|
||||
let bandwidth_str = response
|
||||
.tx_result
|
||||
.events
|
||||
.iter()
|
||||
.filter(|event| event.type_str == format!("wasm-{}", VOUCHER_ACQUIRED_EVENT_TYPE))
|
||||
.map(|event| {
|
||||
event
|
||||
.attributes
|
||||
.iter()
|
||||
.filter(|tag| tag.key.as_ref() == VOUCHER_VALUE)
|
||||
.last()
|
||||
.unwrap()
|
||||
.value
|
||||
.as_ref()
|
||||
})
|
||||
.last()
|
||||
.unwrap();
|
||||
println!("Bandwidth str: {}", bandwidth_str);
|
||||
let acuired_bandwidth = Attribute::from(u64::from_str(bandwidth_str).unwrap());
|
||||
let requested_bandwidth = blind_sign_request_body.0.public_attributes()[0];
|
||||
if acuired_bandwidth != requested_bandwidth {
|
||||
panic!(
|
||||
"Bandwidth value mismatch: {} vs {}",
|
||||
acuired_bandwidth, requested_bandwidth
|
||||
);
|
||||
}
|
||||
let internal_request = InternalSignRequest::new(
|
||||
*blind_sign_request_body.total_params(),
|
||||
blind_sign_request_body.public_attributes(),
|
||||
|
||||
Reference in New Issue
Block a user