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

Support for 2P-EDDSA #30

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
25 changes: 21 additions & 4 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,8 +24,9 @@ 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"
Expand All @@ -34,19 +38,32 @@ features = ["rand", "serde"]

[dependencies.zk-paillier]
git = "https://github.com/KZen-networks/zk-paillier"
branch = "feature/libra-support-fix"

[dependencies.kms]
git = "https://github.com/KZen-networks/kms"
git = "https://github.com/KZen-networks/kms-secp256k1"
branch = "feature/libra-support-fix"

[dependencies.multi-party-ecdsa]
git = "https://github.com/KZen-networks/multi-party-ecdsa"
branch = "feature/libra-support-fix"

[dependencies.multi-party-ed25519]
git = "https://github.com/KZen-networks/multi-party-eddsa"
branch = "feature/libra-support-fix"

[dependencies.multi-party-schnorr]
git = "https://github.com/KZen-networks/multi-party-schnorr"
branch = "feature/libra-support-fix"

[dependencies.curv]
git = "https://github.com/KZen-networks/curv"
branch = "feature/libra-support-fix"
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"
branch = "feature/libra-support-fix"
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