Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc fold intro round1 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions gotham-client/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,7 @@ pub extern "C" fn sign_message(

let message: BigInt = serde_json::from_str(message_hex).unwrap();

let sig = sign::sign(
&client_shim,
message,
&mk_child,
x,
y,
&id.to_string(),
);
let sig = sign::sign(&client_shim, message, &mk_child, x, y, &id.to_string());

let signature_json = match serde_json::to_string(&sig) {
Ok(share) => share,
Expand Down
82 changes: 39 additions & 43 deletions gotham-client/src/ecdsa/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,73 @@
use serde_json;
use time::PreciseTime;

use super::super::api;
use super::super::utilities::requests;
use curv::cryptographic_primitives::proofs::sigma_dlog::*;
use curv::cryptographic_primitives::twoparty::dh_key_exchange_variant_with_pok_comm::*;
use kms::chain_code::two_party as chain_code;
use kms::ecdsa::two_party::*;
use multi_party_ecdsa::protocols::two_party_ecdsa::lindell_2017::*;

use super::super::api;
use super::super::utilities::requests;

const KG_PATH_PRE: &str = "ecdsa/keygen";

#[derive(Serialize, Deserialize)]
pub struct Party2KeyGenCCFirst {
pub kg_party_two_first_message_d_log_proof: DLogProof,
pub cc_party_two_first_message_d_log_proof: DLogProof,
}
pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {
let start = PreciseTime::now();

let res_body = requests::post(client_shim, &format!("{}/first", KG_PATH_PRE)).unwrap();

let (id, kg_party_one_first_message): (String, party_one::KeyGenFirstMsg) =
serde_json::from_str(&res_body).unwrap();
let (id, kg_party_one_first_message, cc_party_one_first_message): (
String,
party_one::KeyGenFirstMsg,
Party1FirstMessage,
) = serde_json::from_str(&res_body).unwrap();

let (kg_party_two_first_message, kg_ec_key_pair_party2) = MasterKey2::key_gen_first_message();

let body = &kg_party_two_first_message.d_log_proof;
let (cc_party_two_first_message, cc_ec_key_pair2) =
chain_code::party2::ChainCode2::chain_code_first_message();

let party2_keygen_cc_first = Party2KeyGenCCFirst {
kg_party_two_first_message_d_log_proof: kg_party_two_first_message.d_log_proof,
cc_party_two_first_message_d_log_proof: cc_party_two_first_message.d_log_proof,
};
let body = &party2_keygen_cc_first;

let res_body =
requests::postb(client_shim, &format!("{}/{}/second", KG_PATH_PRE, id), body).unwrap();

let kg_party_one_second_message: party1::KeyGenParty1Message2 =
serde_json::from_str(&res_body).unwrap();
let (kg_party_one_second_message, cc_party_one_second_message): (
party1::KeyGenParty1Message2,
Party1SecondMessage,
) = serde_json::from_str(&res_body).unwrap();

let key_gen_second_message = MasterKey2::key_gen_second_message(
&kg_party_one_first_message,
&kg_party_one_second_message,
);

assert!(key_gen_second_message.is_ok());
let (party_two_second_message, party_two_paillier, party_two_pdl_chal) =
key_gen_second_message.unwrap();

let cc_party_two_second_message = chain_code::party2::ChainCode2::chain_code_second_message(
&cc_party_one_first_message,
&cc_party_one_second_message,
);

assert!(cc_party_two_second_message.is_ok());

let party2_cc = chain_code::party2::ChainCode2::compute_chain_code(
&cc_ec_key_pair2,
&cc_party_one_second_message.comm_witness.public_share,
)
.chain_code;

let body = &party_two_second_message.pdl_first_message;

let res_body =
Expand Down Expand Up @@ -73,41 +104,6 @@ pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {
)
.expect("pdl error party1");

let res_body = requests::post(
client_shim,
&format!("{}/{}/chaincode/first", KG_PATH_PRE, id),
)
.unwrap();

let cc_party_one_first_message: Party1FirstMessage = serde_json::from_str(&res_body).unwrap();

let (cc_party_two_first_message, cc_ec_key_pair2) =
chain_code::party2::ChainCode2::chain_code_first_message();

let body = &cc_party_two_first_message.d_log_proof;

let res_body = requests::postb(
client_shim,
&format!("{}/{}/chaincode/second", KG_PATH_PRE, id),
body,
)
.unwrap();

let cc_party_one_second_message: Party1SecondMessage = serde_json::from_str(&res_body).unwrap();

let cc_party_two_second_message = chain_code::party2::ChainCode2::chain_code_second_message(
&cc_party_one_first_message,
&cc_party_one_second_message,
);

assert!(cc_party_two_second_message.is_ok());

let party2_cc = chain_code::party2::ChainCode2::compute_chain_code(
&cc_ec_key_pair2,
&cc_party_one_second_message.comm_witness.public_share,
)
.chain_code;

let master_key = MasterKey2::set_master_key(
&party2_cc,
&kg_ec_key_pair_party2,
Expand Down
2 changes: 1 addition & 1 deletion gotham-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ extern crate uuid;
pub mod api;
pub mod ecdsa;
pub mod escrow;
pub mod tests;
pub mod utilities;
pub mod wallet;
pub mod tests;
52 changes: 26 additions & 26 deletions gotham-client/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Gotham-city
//
// Gotham-city
//
// Copyright 2018 by Kzen Networks (kzencorp.com)
// Gotham city is free software: you can redistribute
// it and/or modify it under the terms of the GNU General Public
Expand All @@ -20,37 +20,37 @@ mod tests {

#[test]
fn get_address_test() {
let mut w : Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
let mut w: Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
let a = w.get_new_bitcoin_address();
assert!(!a.to_string().is_empty())
}

#[test]
fn get_balance_test() {
let mut w : Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
let mut w: Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
let b = w.get_balance();
assert!(b.confirmed > 0);
}

// TODO: Find a reliable way of doing integration testing over the blockchain.
// TODO: Ideally we would like to do the whole flow of receiving and sending. PR welcome ;)
// #[test]
// fn send_test() {
// // expect the server running
// let client_shim : api::ClientShim = api::ClientShim::new(
// "http://localhost:8000".to_string(), None);
//
// let mut w : Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
// let b = w.get_balance();
// assert!(b.confirmed > 0);
//
// let available_balance = b.confirmed as f32 / 100000000 as f32;
// let to_send = 0.00000001;
// let delta_pessimistic_fees = 0.00013; // 0.5 usd - 03/14/2019
// assert!(available_balance > to_send + delta_pessimistic_fees, "You need to refund the wallet");
//
// let to_address = w.get_new_bitcoin_address(); // inner wallet tx
// let txid = w.send(to_address.to_string(), to_send, &client_shim);
// assert!(!txid.is_empty());
// }
}
// TODO: Find a reliable way of doing integration testing over the blockchain.
// TODO: Ideally we would like to do the whole flow of receiving and sending. PR welcome ;)
// #[test]
// fn send_test() {
// // expect the server running
// let client_shim : api::ClientShim = api::ClientShim::new(
// "http://localhost:8000".to_string(), None);
//
// let mut w : Wallet = Wallet::load_from(TEST_WALLET_FILENAME);
// let b = w.get_balance();
// assert!(b.confirmed > 0);
//
// let available_balance = b.confirmed as f32 / 100000000 as f32;
// let to_send = 0.00000001;
// let delta_pessimistic_fees = 0.00013; // 0.5 usd - 03/14/2019
// assert!(available_balance > to_send + delta_pessimistic_fees, "You need to refund the wallet");
//
// let to_address = w.get_new_bitcoin_address(); // inner wallet tx
// let txid = w.send(to_address.to_string(), to_send, &client_shim);
// assert!(!txid.is_empty());
// }
}
Loading