From f8654ab120c6e64995798fc876375ce34c8bc143 Mon Sep 17 00:00:00 2001 From: "J. Ayo Akinyele" Date: Mon, 2 Dec 2019 02:24:08 -0500 Subject: [PATCH] add helper test routine for computing secp sigs --- py/libbolt.py | 26 ++++++++++++++++++++++++++ src/lib.rs | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/py/libbolt.py b/py/libbolt.py index e09e2e3..1f0176f 100644 --- a/py/libbolt.py +++ b/py/libbolt.py @@ -230,6 +230,27 @@ class Libbolt(object): return False return bool_str + def get_compact_channel_token(self, channel_token_str): + ct = self._interperate_json_string_as_dictionary(channel_token_str) + + s = ct["pk_c"] + s += ct["pk_m"] + s += ct["cl_pk_m"]["X"] + s += "".join(ct["cl_pk_m"]["Y"]) + s += ct["mpk"]["g1"] + s += ct["mpk"]["g2"] + s += "".join(ct["comParams"]["pub_bases"]) + return s + + def get_compact_signing_keys(self, cust_state_str): + cust_state_str = cust_state_str.replace("null", "None") + cust_state = self._interperate_json_string_as_dictionary(cust_state_str) + + name = cust_state.get("name") + (pk, sk) = cust_state.get("pk_c"), cust_state.get("sk_c") + return name, pk, sk + + if platform == 'darwin': prefix = 'lib' ext = 'dylib' @@ -265,6 +286,11 @@ def run_unit_test(): (channel_token, cust_state, com, com_proof) = libbolt.bidirectional_establish_customer_generate_proof(channel_token, cust_state) print("channel token len: => ", len(channel_token)) print("channel token: => ", channel_token) + #libbolt.get_compact_channel_token(channel_token) + + print("cust state: ", cust_state) + #libbolt.get_compact_signing_keys(cust_state) + print("com: ", com) cust_state_dict = json.loads(cust_state) diff --git a/src/lib.rs b/src/lib.rs index dceb526..ed151f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -648,6 +648,19 @@ pub mod wtp_utils { return cid_thesame && wpk_thesame && channel_token.cl_pk_m.verify(&channel_token.mpk, &close_msg.as_fr_vec(), &close_token); } + pub fn wtp_generate_secp_signature(seckey: &[u8; 32], msg: &[u8; 32]) -> Vec { + let secp = secp256k1::Secp256k1::signing_only(); + + let msg = secp256k1::Message::from_slice(msg).unwrap(); + let seckey = secp256k1::SecretKey::from_slice(seckey).unwrap(); + let sig = secp.sign(&msg, &seckey); + + // get serialized signature + let ser_sig = sig.serialize_der(); + + return ser_sig.to_vec(); + } + pub fn wtp_verify_secp_signature(pubkey: &secp256k1::PublicKey, hash: &Vec, sig: &secp256k1::Signature) -> bool { let secp = secp256k1::Secp256k1::verification_only(); let msg = secp256k1::Message::from_slice(hash.as_slice()).unwrap();