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

gg18 #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

gg18 #18

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
1 change: 1 addition & 0 deletions gotham-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ git = "https://github.com/KZen-networks/zk-paillier"

[dependencies.kms]
git = "https://github.com/KZen-networks/kms"
branch = "gg18_support"

[dependencies.multi-party-ecdsa]
git = "https://github.com/KZen-networks/multi-party-ecdsa"
Expand Down
2 changes: 1 addition & 1 deletion gotham-client/Settings.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
endpoint = "http://localhost:8000"
endpoint = "http://localhost:8003"
50 changes: 49 additions & 1 deletion gotham-client/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ subcommands:
- verbose:
short: v
help: Sets the level of verbosity
- create-wallet-legacy:
about: Create an MPC wallet
version: "1.0"
args:
- verbose:
short: vl
help: Sets the level of verbosity
- wallet:
about: Operation on wallet
version: "1.0"
Expand Down Expand Up @@ -54,4 +61,45 @@ subcommands:
short: a
required: true
value_name: amount
help: Amount in BTC
help: Amount in BTC

- wallet-legacy:
about: Operation on wallet
version: "1.0"
args:
- new-address-legacy:
short: a
help: Generate a new address legacy
- get-balance-legacy:
short: b
help: Total balance legacy
- list-unspent-legacy:
short: u
help: List unspent transactions (tx hash) legacy
- backup-legacy:
short: s
help: Private share backup legacy
- verify-legacy:
short: c
help: Backup verification legacy
- restore-legacy:
short: r
help: Private share recovery legacy
- rotate-legacy:
short: o
help: Private shares rotation legacy
subcommands:
- send-legacy:
about: Send a transaction
version: "1.0"
args:
- to:
short: t
required: true
value_name: to
help: Receipient
- amount:
short: a
required: true
value_name: amount
help: Amount in BTC
111 changes: 96 additions & 15 deletions gotham-client/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use super::ecdsa::{keygen, sign};
use curv::BigInt;
use kms::ecdsa::two_party::MasterKey2;
use multi_party_ecdsa::protocols::two_party_ecdsa::lindell_2017::party_one;
use super::ecdsa::{keygen, keygen_legacy, sign};
use curv::elliptic::curves::traits::ECScalar;
use curv::{BigInt, FE};

use kms::ecdsa::two_party_gg18::MasterKey1;
use kms::ecdsa::two_party_lindell17::MasterKey2;
use reqwest;
use serde_json;

// iOS bindings
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2018::party_i::Signature;
use std::ffi::{CStr, CString};
use std::os::raw::c_char;

Expand All @@ -27,27 +30,49 @@ impl ClientShim {
}
}

#[derive(Serialize, Deserialize)]
pub struct PrivateShareGG {
pub id: String,
pub master_key: MasterKey1,
}

#[derive(Serialize, Deserialize)]
pub struct PrivateShare {
pub id: String,
pub master_key: MasterKey2,
}

pub fn get_master_key_new(client_shim: &ClientShim) -> PrivateShareGG {
keygen::get_master_key_new("".to_string(), FE::zero(), &client_shim)
}

pub fn get_master_key(client_shim: &ClientShim) -> PrivateShare {
keygen::get_master_key(&client_shim)
keygen_legacy::get_master_key(&client_shim)
}

// sign using Lindell keys with GG signature scheme
pub fn sign(
client_shim: &ClientShim,
message: BigInt,
mk: &MasterKey2,
x_pos: BigInt,
y_pos: BigInt,
id: &String,
) -> party_one::SignatureRecid {
) -> Signature {
sign::sign(&client_shim, message, mk, x_pos, y_pos, id)
}

pub fn sign_gg(
client_shim: &ClientShim,
message: BigInt,
mk: &MasterKey1,
x_pos: BigInt,
y_pos: BigInt,
id: &String,
) -> Signature {
sign::sign_gg(&client_shim, message, mk, x_pos, y_pos, id)
}

#[no_mangle]
pub extern "C" fn get_client_master_key(
c_endpoint: *const c_char,
Expand All @@ -67,7 +92,8 @@ pub extern "C" fn get_client_master_key(

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

let private_share: PrivateShare = keygen::get_master_key(&client_shim);
let private_share: PrivateShareGG =
keygen::get_master_key_new("".to_string(), FE::zero(), &client_shim);

let private_share_json = match serde_json::to_string(&private_share) {
Ok(share) => share,
Expand Down Expand Up @@ -131,14 +157,69 @@ 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,
Err(_) => panic!("Error while signing to endpoint {}", endpoint),
};

CString::new(signature_json.to_owned()).unwrap().into_raw()
}

#[no_mangle]
pub extern "C" fn sign_message_gg(
c_endpoint: *const c_char,
c_auth_token: *const c_char,
c_message_le_hex: *const c_char,
c_master_key_json: *const c_char,
c_x_pos: i32,
c_y_pos: i32,
c_id: *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 raw auth_token"),
};

let raw_message_hex = unsafe { CStr::from_ptr(c_message_le_hex) };
let message_hex = match raw_message_hex.to_str() {
Ok(s) => s,
Err(_) => panic!("Error while decoding raw message_hex"),
};

let raw_master_key_json = unsafe { CStr::from_ptr(c_master_key_json) };
let master_key_json = match raw_master_key_json.to_str() {
Ok(s) => s,
Err(_) => panic!("Error while decoding raw master_key_json"),
};

let raw_id = unsafe { CStr::from_ptr(c_id) };
let id = match raw_id.to_str() {
Ok(s) => s,
Err(_) => panic!("Error while decoding raw id"),
};

let x: BigInt = BigInt::from(c_x_pos);;

let y: BigInt = BigInt::from(c_y_pos);

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

let mk: MasterKey1 = serde_json::from_str(master_key_json).unwrap();

let mk_child: MasterKey1 = mk.get_child(vec![x.clone(), y.clone()]);

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

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

let signature_json = match serde_json::to_string(&sig) {
Ok(share) => share,
Expand Down
Loading