Skip to content

Commit

Permalink
v0.1.0 candidate - support for EdDSA, Schnorr & fix dependencies (Zen…
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiba authored Oct 27, 2019
1 parent d108393 commit a77e05f
Show file tree
Hide file tree
Showing 31 changed files with 1,530 additions and 504 deletions.
31 changes: 22 additions & 9 deletions gotham-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "gotham-client"
version = "0.1.0"
authors = ["gbenattar <[email protected]>"]
authors = [
"gbenattar <[email protected]>",
"Oded Leiba <[email protected]"
]
edition = "2018"

[lib]
Expand All @@ -21,32 +24,42 @@ log = "0.4"
time = "*"
clap = { version = "2.32", features = ["yaml"] }
reqwest = "0.9.5"
failure = "0.1.5"
uuid = { version = "0.7", features = ["v4"] }
electrumx_client = { git = "https://github.com/KZen-networks/rust-electrumx-client" }
electrumx_client = { git = "https://github.com/KZen-networks/rust-electrumx-client", tag = "[email protected]" }
itertools = "0.8.0"
hex = "0.3.2"
bitcoin = "0.16.0"
bitcoin = "0.20.0"
config = "0.9"

[dependencies.secp256k1]
version = "0.12"
features = ["rand", "serde"]

[dependencies.zk-paillier]
git = "https://github.com/KZen-networks/zk-paillier"
tag = "v0.2.0"

[dependencies.kms]
git = "https://github.com/KZen-networks/kms"
git = "https://github.com/KZen-networks/kms-secp256k1"
tag = "v0.1.0"

[dependencies.multi-party-ecdsa]
git = "https://github.com/KZen-networks/multi-party-ecdsa"
tag = "v0.1.0"

[dependencies.multi-party-eddsa]
git = "https://github.com/KZen-networks/multi-party-eddsa"
tag = "v0.2.1"

[dependencies.multi-party-schnorr]
git = "https://github.com/KZen-networks/multi-party-schnorr"
tag = "v0.3.0"

[dependencies.curv]
git = "https://github.com/KZen-networks/curv"
tag = "v0.2.0"
features = ["ec_secp256k1"]

[patch.crates-io]
rust-gmp = { version = "0.5.0", features = ["serde_support"], git = "https://github.com/KZen-networks/rust-gmp" }

[dependencies.centipede]
git = "https://github.com/KZen-networks/centipede"
git = "https://github.com/KZen-networks/centipede"
tag = "v0.2.0"
149 changes: 0 additions & 149 deletions gotham-client/src/api/mod.rs

This file was deleted.

69 changes: 45 additions & 24 deletions gotham-client/src/ecdsa/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ 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::types::PrivateShare;
use super::super::utilities::requests;
use super::super::ClientShim;

// iOS bindings
use std::ffi::{CStr, CString};
use std::os::raw::c_char;

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

pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {
pub fn get_master_key(client_shim: &ClientShim) -> 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();
requests::post(client_shim, &format!("{}/first", KG_PATH_PRE)).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 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();
requests::postb(client_shim, &format!("{}/{}/second", KG_PATH_PRE, id), body).unwrap();

let key_gen_second_message = MasterKey2::key_gen_second_message(
&kg_party_one_first_message,
Expand All @@ -48,23 +48,17 @@ pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {

let body = &party_two_second_message.pdl_first_message;

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

let party_one_third_message: party_one::PDLFirstMessage =
serde_json::from_str(&res_body).unwrap();
requests::postb(client_shim, &format!("{}/{}/third", KG_PATH_PRE, id), body).unwrap();

let pdl_decom_party2 = MasterKey2::key_gen_third_message(&party_two_pdl_chal);

let party_2_pdl_second_message = pdl_decom_party2;

let body = &party_2_pdl_second_message;

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

let party_one_pdl_second_message: party_one::PDLSecondMessage =
serde_json::from_str(&res_body).unwrap();
requests::postb(client_shim, &format!("{}/{}/fourth", KG_PATH_PRE, id), body).unwrap();

MasterKey2::key_gen_fourth_message(
&party_two_pdl_chal,
Expand All @@ -73,28 +67,24 @@ pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {
)
.expect("pdl error party1");

let res_body = requests::post(
let cc_party_one_first_message: Party1FirstMessage = 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(
let cc_party_one_second_message: Party1SecondMessage = 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,
Expand All @@ -121,5 +111,36 @@ pub fn get_master_key(client_shim: &api::ClientShim) -> api::PrivateShare {
let end = PreciseTime::now();
println!("(id: {}) Took: {}", id, start.to(end));

api::PrivateShare { id, master_key }
PrivateShare { id, master_key }
}

#[no_mangle]
pub extern "C" fn get_client_master_key(
c_endpoint: *const c_char,
c_auth_token: *const c_char,
) -> *mut c_char {
let raw_endpoint = unsafe { CStr::from_ptr(c_endpoint) };
let endpoint = match raw_endpoint.to_str() {
Ok(s) => s,
Err(_) => panic!("Error while decoding raw endpoint"),
};

let raw_auth_token = unsafe { CStr::from_ptr(c_auth_token) };
let auth_token = match raw_auth_token.to_str() {
Ok(s) => s,
Err(_) => panic!("Error while decoding auth token"),
};

let client_shim = ClientShim::new(endpoint.to_string(), Some(auth_token.to_string()));

let private_share: PrivateShare = get_master_key(&client_shim);

let private_share_json = match serde_json::to_string(&private_share) {
Ok(share) => share,
Err(_) => panic!("Error while performing keygen to endpoint {}", endpoint),
};

CString::new(private_share_json.to_owned())
.unwrap()
.into_raw()
}
7 changes: 7 additions & 0 deletions gotham-client/src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
pub mod keygen;
pub mod rotate;
pub mod sign;
pub mod types;
pub mod recover;

pub use keygen::get_master_key;
pub use rotate::rotate_master_key;
pub use sign::sign;
pub use types::PrivateShare;
Loading

0 comments on commit a77e05f

Please sign in to comment.