From 8c1013f724992164d23d7264ede0d1a7b3dad098 Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:31:48 +0100 Subject: [PATCH 1/6] Introduce index4 in HDWalletStorage methods --- src/hd_wallet_storage.rs | 28 +++++++++++++++++----------- src/lib_struct.rs | 8 ++++---- src/test_lib.rs | 4 ++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/hd_wallet_storage.rs b/src/hd_wallet_storage.rs index ae66d9a..1273db3 100644 --- a/src/hd_wallet_storage.rs +++ b/src/hd_wallet_storage.rs @@ -106,11 +106,11 @@ impl HDWalletStorage { } /// Return a child keypair - pub(crate) fn get_child_keypair(&self, index: u32) -> Result { + pub(crate) fn get_child_keypair(&self, index4: u32, index5: u32) -> Result { let wallet = self.get_cached_hdwallet_info()?; // derive - let index_4 = ChildNumber::from_normal_idx(0).unwrap(); - let index_5 = ChildNumber::from_normal_idx(index).unwrap(); + let index_4 = ChildNumber::from_normal_idx(index4).unwrap(); + let index_5 = ChildNumber::from_normal_idx(index5).unwrap(); let xpriv_5 = wallet .xpriv .derive_priv(&self.secp, &vec![index_4, index_5]) @@ -120,14 +120,18 @@ impl HDWalletStorage { } /// Return a child public key - pub(crate) fn get_child_public_key(&self, index: u32) -> Result { - let keypair = self.get_child_keypair(index)?; + pub(crate) fn get_child_public_key( + &self, + index4: u32, + index5: u32, + ) -> Result { + let keypair = self.get_child_keypair(index4, index5)?; Ok(keypair.public_key()) } /// Return a child address - pub(crate) fn get_address(&self, index: u32) -> Result { - let pubkey = self.get_child_public_key(index)?; + pub(crate) fn get_address(&self, index4: u32, index5: u32) -> Result { + let pubkey = self.get_child_public_key(index4, index5)?; let ck = bitcoin::CompressedPublicKey(pubkey); let address = Address::p2wpkh(&ck, self.network()); Ok(address) @@ -135,17 +139,19 @@ impl HDWalletStorage { pub(crate) fn verify_child_public_key_intern( &self, - index: u32, + index4: u32, + index5: u32, pubkey: &PublicKey, print_entity: &str, ) -> Result { - let keypair = self.get_child_keypair(index)?; + let keypair = self.get_child_keypair(index4, index5)?; // verify pubkey if &keypair.public_key() != pubkey { return Err(format!( - "{} mismatch, index {}, {} vs. {}", + "{} mismatch, index {}/{}, {} vs. {}", print_entity, - index, + index4, + index5, pubkey, keypair.public_key() )); diff --git a/src/lib_struct.rs b/src/lib_struct.rs index a72a8b3..d671248 100644 --- a/src/lib_struct.rs +++ b/src/lib_struct.rs @@ -68,7 +68,7 @@ impl Lib { fn get_child_keypair(&self, index: u32) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_child_keypair(index) + hd_wallet.get_child_keypair(0 /*index4*/, index) } else { Err("Library not initialized!".to_string()) } @@ -77,7 +77,7 @@ impl Lib { /// Return a child public key pub(crate) fn get_child_public_key(&self, index: u32) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_child_public_key(index) + hd_wallet.get_child_public_key(0 /*index4*/, index) } else { Err("Library not initialized!".to_string()) } @@ -86,7 +86,7 @@ impl Lib { /// Return a child address pub(crate) fn get_address(&self, index: u32) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_address(index) + hd_wallet.get_address(0 /*index4*/, index) } else { Err("Library not initialized!".to_string()) } @@ -99,7 +99,7 @@ impl Lib { print_entity: &str, ) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.verify_child_public_key_intern(index, pubkey, print_entity) + hd_wallet.verify_child_public_key_intern(0 /*index4*/, index, pubkey, print_entity) } else { Err("Library not initialized!".to_string()) } diff --git a/src/test_lib.rs b/src/test_lib.rs index bba2f8d..2c07cb1 100644 --- a/src/test_lib.rs +++ b/src/test_lib.rs @@ -79,14 +79,14 @@ fn test_verify_public_key() { ) .unwrap()); assert_eq!(verify_public_key(0, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e").err().unwrap(), - "Pubkey mismatch, index 0, 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e vs. 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32"); + "Pubkey mismatch, index 0/0, 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e vs. 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32"); assert!(verify_public_key( 3, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e" ) .unwrap()); assert_eq!(verify_public_key(3, "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32").err().unwrap(), - "Pubkey mismatch, index 3, 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32 vs. 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e"); + "Pubkey mismatch, index 0/3, 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32 vs. 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e"); } #[test] From 77c31e9cbe77d05e3bc91909e38524554faab225 Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:07:50 +0100 Subject: [PATCH 2/6] Introduce index4 in lib_struct methods --- src/lib.rs | 36 ++++++++++++++++++--------- src/lib_struct.rs | 63 ++++++++++++++++++++++++++++++----------------- src/test_lib.rs | 23 ++++++++++------- 3 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index be24610..87431f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,12 +59,18 @@ pub fn get_xpub() -> Result { } pub fn get_public_key(index: u32) -> Result { - let pubkey = global_lib().read().unwrap().get_child_public_key(index)?; + let pubkey = global_lib() + .read() + .unwrap() + .get_child_public_key(0 /*index4 TODO*/, index)?; Ok(pubkey.to_string()) } pub fn get_address(index: u32) -> Result { - let address = global_lib().read().unwrap().get_address(index)?; + let address = global_lib() + .read() + .unwrap() + .get_address(0 /*index4 TODO*/, index)?; Ok(address.to_string()) } @@ -74,7 +80,7 @@ pub fn verify_public_key(index: u32, pubkey_str: &str) -> Result { let verify_result = global_lib() .read() .unwrap() - .verify_child_public_key(index, &pubkey)?; + .verify_child_public_key(0 /*index4 TODO*/, index, &pubkey)?; Ok(verify_result) } @@ -87,10 +93,12 @@ pub fn sign_hash_ecdsa( .map_err(|e| format!("Failed to parse hash hex, {}", e.to_string()))?; let signer_pubkey = pubkey_from_hex(signer_pubkey_str) .map_err(|e| format!("Failed to parse signer pubkey {}", e))?; - let sig = global_lib() - .read() - .unwrap() - .sign_hash_ecdsa(&hash, index, &signer_pubkey)?; + let sig = global_lib().read().unwrap().sign_hash_ecdsa( + &hash, + 0, /*index4 TODO*/ + index, + &signer_pubkey, + )?; Ok(sig.to_lower_hex_string()) } @@ -110,10 +118,12 @@ pub fn sign_schnorr_with_nonce( ) -> Result { let nonce_sec_bin = <[u8; 32]>::from_hex(&nonce_sec_hex) .map_err(|e| format!("Error in nonce hex string {}", e))?; - let sig = global_lib() - .read() - .unwrap() - .sign_schnorr_with_nonce(msg, &nonce_sec_bin, index)?; + let sig = global_lib().read().unwrap().sign_schnorr_with_nonce( + msg, + &nonce_sec_bin, + 0, /*index4 TODO*/ + index, + )?; Ok(sig.to_string()) } @@ -124,7 +134,7 @@ pub fn verify_schnorr(msg: &str, signature_hex: &str, index: u32) -> Result Result { + fn get_child_keypair(&self, index4: u32, index5: u32) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_child_keypair(0 /*index4*/, index) + hd_wallet.get_child_keypair(index4, index5) } else { Err("Library not initialized!".to_string()) } } /// Return a child public key - pub(crate) fn get_child_public_key(&self, index: u32) -> Result { + pub(crate) fn get_child_public_key( + &self, + index4: u32, + index5: u32, + ) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_child_public_key(0 /*index4*/, index) + hd_wallet.get_child_public_key(index4, index5) } else { Err("Library not initialized!".to_string()) } } /// Return a child address - pub(crate) fn get_address(&self, index: u32) -> Result { + pub(crate) fn get_address(&self, index4: u32, index5: u32) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.get_address(0 /*index4*/, index) + hd_wallet.get_address(index4, index5) } else { Err("Library not initialized!".to_string()) } @@ -94,12 +98,13 @@ impl Lib { fn verify_child_public_key_intern( &self, - index: u32, + index4: u32, + index5: u32, pubkey: &PublicKey, print_entity: &str, ) -> Result { if let Some(hd_wallet) = &self.hd_wallet_storage { - hd_wallet.verify_child_public_key_intern(0 /*index4*/, index, pubkey, print_entity) + hd_wallet.verify_child_public_key_intern(index4, index5, pubkey, print_entity) } else { Err("Library not initialized!".to_string()) } @@ -108,21 +113,24 @@ impl Lib { /// Verify a child public key pub(crate) fn verify_child_public_key( &self, - index: u32, + index4: u32, + index5: u32, pubkey: &PublicKey, ) -> Result { - self.verify_child_public_key_intern(index, pubkey, "Pubkey") + self.verify_child_public_key_intern(index4, index5, pubkey, "Pubkey") } pub(crate) fn sign_hash_ecdsa( &self, hash: &[u8; 32], - index: u32, + index4: u32, + index5: u32, signer_pubkey: &PublicKey, ) -> Result, String> { - let keypair = self.get_child_keypair(index)?; + let keypair = self.get_child_keypair(index4, index5)?; // verify pubkey - let _ = self.verify_child_public_key_intern(index, signer_pubkey, "Signer pubkey")?; + let _ = + self.verify_child_public_key_intern(index4, index5, signer_pubkey, "Signer pubkey")?; sign_hash_ecdsa_with_key(&self.secp, hash, &keypair.secret_key()) } @@ -145,9 +153,10 @@ impl Lib { &self, msg: &str, nonce_sec: &[u8; 32], - index: u32, + index4: u32, + index5: u32, ) -> Result { - let kp = self.get_child_keypair(index)?; + let kp = self.get_child_keypair(index4, index5)?; sign_schnorr_with_nonce_sec(&self.secp, &kp, msg, nonce_sec) } @@ -156,9 +165,13 @@ impl Lib { &self, msg: &str, signature: &SchnorrSignature, - index: u32, + index4: u32, + index5: u32, ) -> Result { - let pubkey = self.get_child_public_key(index)?.x_only_public_key().0; + let pubkey = self + .get_child_public_key(index4, index5)? + .x_only_public_key() + .0; verify_schnorr(&self.secp, signature, &pubkey, msg) } @@ -179,17 +192,19 @@ impl Lib { num_cets: u64, digit_string_template: &str, oracle_pubkey: &PublicKey, - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey: &PublicKey, nonces: &Vec, interval_wildcards: &Vec, sighashes: &Vec<[u8; 32]>, ) -> Result, String> { // Prepare signing key - let sign_keypair = self.get_child_keypair(signing_key_index)?; + let sign_keypair = self.get_child_keypair(signing_key_index4, signing_key_index5)?; // Verify signing pubkey let _ = self.verify_child_public_key_intern( - signing_key_index, + signing_key_index4, + signing_key_index5, signing_pubkey, "Signer pubkey", )?; @@ -236,7 +251,8 @@ impl Lib { /// Create signatures on a CET when outcome signatures are available pub fn create_final_cet_sigs( &self, - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey: &PublicKey, other_pubkey: &PublicKey, num_digits: u8, @@ -246,10 +262,11 @@ impl Lib { other_adaptor_signature: &EcdsaAdaptorSignature, ) -> Result<(Vec, Vec), String> { // Prepare signing key - let sign_keypair = self.get_child_keypair(signing_key_index)?; + let sign_keypair = self.get_child_keypair(signing_key_index4, signing_key_index5)?; // verify signer pubkey let _ = self.verify_child_public_key_intern( - signing_key_index, + signing_key_index4, + signing_key_index5, signing_pubkey, "Signer pubkey", )?; diff --git a/src/test_lib.rs b/src/test_lib.rs index 2c07cb1..54c9ac6 100644 --- a/src/test_lib.rs +++ b/src/test_lib.rs @@ -96,21 +96,22 @@ fn test_sign_hash_ecdsa() { .init_with_entropy(&dummy_entropy(), DEFAULT_NETWORK) .unwrap(); - let pubkey3 = lib.get_child_public_key(3).unwrap(); + let pubkey3 = lib.get_child_public_key(0, 3).unwrap(); assert_eq!( pubkey3.to_string(), "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e" ); let hash = dummy_bytes32(7); - let sig = lib.sign_hash_ecdsa(&hash, 3, &pubkey3).unwrap(); + let sig = lib.sign_hash_ecdsa(&hash, 0, 3, &pubkey3).unwrap(); // verify_signature let verif_res = verify_ecdsa_signature(&hash, &sig, &pubkey3, true).unwrap(); assert!(verif_res); // negative test, wrong index - assert!(lib.sign_hash_ecdsa(&hash, 31, &pubkey3).is_err()); + assert!(lib.sign_hash_ecdsa(&hash, 0, 31, &pubkey3).is_err()); + assert!(lib.sign_hash_ecdsa(&hash, 1, 3, &pubkey3).is_err()); } #[test] @@ -228,7 +229,7 @@ fn test_create_cet_adaptor_sigs() { ]; let sighashes = vec![dummy_bytes32(0), dummy_bytes32(1), dummy_bytes32(2)]; let oracle_pubkey = create_dummy_pubkey(9); - let my_pubkey = lib.get_child_public_key(0).unwrap(); + let my_pubkey = lib.get_child_public_key(0, 0).unwrap(); assert_eq!( my_pubkey.to_string(), "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32" @@ -241,6 +242,7 @@ fn test_create_cet_adaptor_sigs() { "Outcome:btcusd1741474920:{digit_index}:{digit_outcome}", &oracle_pubkey, 0, + 0, &my_pubkey, &nonces, &interval_wildcards, @@ -271,7 +273,7 @@ fn test_verify_cet_adaptor_sigs() { ]; let sighashes = vec![dummy_bytes32(0), dummy_bytes32(1), dummy_bytes32(2)]; let oracle_pubkey = create_dummy_pubkey(9); - let my_pubkey = lib.get_child_public_key(0).unwrap(); + let my_pubkey = lib.get_child_public_key(0, 0).unwrap(); assert_eq!( my_pubkey.to_string(), "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32" @@ -285,6 +287,7 @@ fn test_verify_cet_adaptor_sigs() { "Outcome:btcusd1741474920:{digit_index}:{digit_outcome}", &oracle_pubkey, 0, + 0, &my_pubkey, &nonces, &interval_wildcards, @@ -320,7 +323,7 @@ fn test_create_final_cet_sigs() { // First preparation: create oracle signatures let mut lib_ora = Lib::new_empty(); let _xpub = lib_ora.init_with_entropy(&dummy_bytes32(3).to_vec(), DEFAULT_NETWORK); - let oracle_pubkey = lib_ora.get_child_public_key(0).unwrap(); + let oracle_pubkey = lib_ora.get_child_public_key(0, 0).unwrap(); assert_eq!( oracle_pubkey.to_string(), "020a5e571a47cc259d3cc0454a8b7e58bba16e01156bb72d0ce490823f51117cce" @@ -347,7 +350,7 @@ fn test_create_final_cet_sigs() { .replace("{digit_index}", &format!("{}", i)) .replace("{digit_outcome}", &format!("{}", digit_value)); let sig = lib_ora - .sign_schnorr_with_nonce(&digit_string, &nonces_sec_vec[i], 0) + .sign_schnorr_with_nonce(&digit_string, &nonces_sec_vec[i], 0, 0) .unwrap(); oracle_signatures.push(sig); } @@ -357,7 +360,7 @@ fn test_create_final_cet_sigs() { let _xpub = lib2 .init_with_entropy(&dummy_bytes32(2).to_vec(), DEFAULT_NETWORK) .unwrap(); - let other_pubkey = lib2.get_child_public_key(0).unwrap(); + let other_pubkey = lib2.get_child_public_key(0, 0).unwrap(); assert_eq!( other_pubkey.to_string(), "02142c5af97c4afd91bea47ac47e56fad2935dcacc04b3ffa69e5ff7760cbd07ed" @@ -371,6 +374,7 @@ fn test_create_final_cet_sigs() { digits_template_string, &oracle_pubkey, 0, + 0, &other_pubkey, &nonces_pub_vec, &vec![final_cet_wildcard.to_string()], // interval_wildcards @@ -386,7 +390,7 @@ fn test_create_final_cet_sigs() { let _xpub = lib1 .init_with_entropy(&dummy_bytes32(1).to_vec(), DEFAULT_NETWORK) .unwrap(); - let my_pubkey = lib1.get_child_public_key(0).unwrap(); + let my_pubkey = lib1.get_child_public_key(0, 0).unwrap(); assert_eq!( my_pubkey.to_string(), "035bcac7323e9971268213a188d8268277abcd962cdf096e68e2b58c228216f104" @@ -394,6 +398,7 @@ fn test_create_final_cet_sigs() { let final_sigs = lib1 .create_final_cet_sigs( + 0, 0, &my_pubkey, &other_pubkey, From 1947b34c7bd4c3e2ac399c2facf2653080d975ce Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:18:02 +0100 Subject: [PATCH 3/6] Introduce index4 in public methods, breaking change --- src/lib.rs | 74 +++++++++++++++++++++++++++---------------------- src/test_lib.rs | 48 ++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 47 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 87431f0..45a19e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,47 +58,44 @@ pub fn get_xpub() -> Result { Ok(xpub.to_string()) } -pub fn get_public_key(index: u32) -> Result { +pub fn get_public_key(index4: u32, index5: u32) -> Result { let pubkey = global_lib() .read() .unwrap() - .get_child_public_key(0 /*index4 TODO*/, index)?; + .get_child_public_key(index4, index5)?; Ok(pubkey.to_string()) } -pub fn get_address(index: u32) -> Result { - let address = global_lib() - .read() - .unwrap() - .get_address(0 /*index4 TODO*/, index)?; +pub fn get_address(index4: u32, index5: u32) -> Result { + let address = global_lib().read().unwrap().get_address(index4, index5)?; Ok(address.to_string()) } -pub fn verify_public_key(index: u32, pubkey_str: &str) -> Result { +pub fn verify_public_key(index4: u32, index5: u32, pubkey_str: &str) -> Result { let pubkey = pubkey_from_hex(pubkey_str).map_err(|e| format!("Failed to parse pubkey {}", e))?; let verify_result = global_lib() .read() .unwrap() - .verify_child_public_key(0 /*index4 TODO*/, index, &pubkey)?; + .verify_child_public_key(index4, index5, &pubkey)?; Ok(verify_result) } pub fn sign_hash_ecdsa( hash_str: &str, - index: u32, + index4: u32, + index5: u32, signer_pubkey_str: &str, ) -> Result { let hash = <[u8; 32]>::from_hex(hash_str) .map_err(|e| format!("Failed to parse hash hex, {}", e.to_string()))?; let signer_pubkey = pubkey_from_hex(signer_pubkey_str) .map_err(|e| format!("Failed to parse signer pubkey {}", e))?; - let sig = global_lib().read().unwrap().sign_hash_ecdsa( - &hash, - 0, /*index4 TODO*/ - index, - &signer_pubkey, - )?; + let sig = + global_lib() + .read() + .unwrap() + .sign_hash_ecdsa(&hash, index4, index5, &signer_pubkey)?; Ok(sig.to_lower_hex_string()) } @@ -114,27 +111,33 @@ pub fn create_deterministic_nonce(event_id: &str, index: u32) -> Result<(String, pub fn sign_schnorr_with_nonce( msg: &str, nonce_sec_hex: &str, - index: u32, + index4: u32, + index5: u32, ) -> Result { let nonce_sec_bin = <[u8; 32]>::from_hex(&nonce_sec_hex) .map_err(|e| format!("Error in nonce hex string {}", e))?; let sig = global_lib().read().unwrap().sign_schnorr_with_nonce( msg, &nonce_sec_bin, - 0, /*index4 TODO*/ - index, + index4, + index5, )?; Ok(sig.to_string()) } // Schnorr signature verification -pub fn verify_schnorr(msg: &str, signature_hex: &str, index: u32) -> Result { +pub fn verify_schnorr( + msg: &str, + signature_hex: &str, + index4: u32, + index5: u32, +) -> Result { let signature = schnorr_sig_from_hex(signature_hex) .map_err(|e| format!("Error in signature hex string {}", e))?; let res = global_lib() .read() .unwrap() - .verify_schnorr(msg, &signature, 0 /*index4 TODO*/, index)?; + .verify_schnorr(msg, &signature, index4, index5)?; Ok(res) } @@ -173,7 +176,8 @@ pub fn create_cet_adaptor_sigs( num_cets: u64, digit_string_template: &str, oracle_pubkey_str: &str, - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey_str: &str, nonces: &str, interval_wildcards: &str, @@ -241,8 +245,8 @@ pub fn create_cet_adaptor_sigs( num_cets, digit_string_template, &oracle_pubkey, - 0, /*index4 TODO*/ - signing_key_index, + signing_key_index4, + signing_key_index5, &signing_pubkey, &nonces, &wcs, @@ -359,7 +363,8 @@ pub fn verify_cet_adaptor_sigs( } pub fn create_final_cet_sigs( - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey_str: &str, other_pubkey_str: &str, num_digits: u8, @@ -400,8 +405,8 @@ pub fn create_final_cet_sigs( EcdsaAdaptorSignature::from_slice(&other_adaptor_signature_bin) .map_err(|e| format!("Failed to parse other adaptor sig {}", e))?; let (sig1, sig2) = global_lib().read().unwrap().create_final_cet_sigs( - 0, /*index4 TODO*/ - signing_key_index, + signing_key_index4, + signing_key_index5, &signing_pubkey, &other_pubkey, num_digits, @@ -450,8 +455,8 @@ pub extern "C" fn init_with_entropy_c( /// Return a child public key (specified by its index). #[no_mangle] -pub extern "C" fn get_public_key_c(index: u32) -> *mut c_char { - match get_public_key(index) { +pub extern "C" fn get_public_key_c(index4: u32, index5: u32) -> *mut c_char { + match get_public_key(index4, index5) { Ok(pubkey) => { // Return as a C string CString::new(pubkey).unwrap().into_raw() @@ -464,7 +469,8 @@ pub extern "C" fn get_public_key_c(index: u32) -> *mut c_char { #[no_mangle] pub extern "C" fn sign_hash_ecdsa_c( hash: *const c_char, - signer_index: u32, + signer_index4: u32, + signer_index5: u32, signer_pubkey: *const c_char, ) -> *mut c_char { // Convert input parameter from raw pointer to Rust string @@ -479,7 +485,7 @@ pub extern "C" fn sign_hash_ecdsa_c( .unwrap_or("Error in signer_pubkey parameter") }; - match sign_hash_ecdsa(hash_str, signer_index, signer_pubkey_str) { + match sign_hash_ecdsa(hash_str, signer_index4, signer_index5, signer_pubkey_str) { Ok(sig) => { // Return as a C string CString::new(sig).unwrap().into_raw() @@ -495,7 +501,8 @@ pub extern "C" fn create_cet_adaptor_sigs_c( num_cets: u32, digit_string_template: *const c_char, oracle_pubkey: *const c_char, - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey: *const c_char, nonces: *const c_char, interval_wildcards: *const c_char, @@ -538,7 +545,8 @@ pub extern "C" fn create_cet_adaptor_sigs_c( num_cets as u64, digit_string_template_str, oracle_pubkey_str, - signing_key_index, + signing_key_index4, + signing_key_index5, signing_pubkey_str, nonces_str, interval_wildcards_str, diff --git a/src/test_lib.rs b/src/test_lib.rs index 54c9ac6..69f3121 100644 --- a/src/test_lib.rs +++ b/src/test_lib.rs @@ -56,17 +56,23 @@ fn test_init_with_entropy_lib_mainnet() { fn test_get_public_key() { let _xpub = init_with_entropy(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); - let pubkey0 = get_public_key(0).unwrap(); + let pubkey00 = get_public_key(0, 0).unwrap(); assert_eq!( - pubkey0.to_string(), + pubkey00.to_string(), "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32" ); - let pubkey3 = get_public_key(3).unwrap(); + let pubkey03 = get_public_key(0, 3).unwrap(); assert_eq!( - pubkey3.to_string(), + pubkey03.to_string(), "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e" ); + + let pubkey10 = get_public_key(1, 0).unwrap(); + assert_eq!( + pubkey10.to_string(), + "02eb2522e05e5b4656aec2e97c85b57c2a9e2c036f4843ae4a21322fe4e6aabcaf" + ); } #[test] @@ -74,19 +80,31 @@ fn test_verify_public_key() { let _xpub = init_with_entropy(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); assert!(verify_public_key( + 0, 0, "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32" ) .unwrap()); - assert_eq!(verify_public_key(0, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e").err().unwrap(), + assert_eq!(verify_public_key(0, 0, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e").err().unwrap(), "Pubkey mismatch, index 0/0, 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e vs. 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32"); + assert!(verify_public_key( + 0, 3, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e" ) .unwrap()); - assert_eq!(verify_public_key(3, "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32").err().unwrap(), + assert_eq!(verify_public_key(0, 3, "0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32").err().unwrap(), "Pubkey mismatch, index 0/3, 0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32 vs. 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e"); + + assert!(verify_public_key( + 1, + 0, + "02eb2522e05e5b4656aec2e97c85b57c2a9e2c036f4843ae4a21322fe4e6aabcaf" + ) + .unwrap()); + assert_eq!(verify_public_key(1, 0, "03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e").err().unwrap(), + "Pubkey mismatch, index 1/0, 03b74dc470965932fc976459096526b08a0f939a95e4b72db8f9aadce18a08a72e vs. 02eb2522e05e5b4656aec2e97c85b57c2a9e2c036f4843ae4a21322fe4e6aabcaf"); } #[test] @@ -131,18 +149,18 @@ fn test_sign_schnorr_with_nonce() { let msg = "This is a message"; let nonce = "0123450000000000006897528962743076432965432697856340567500000100"; - let sig = sign_schnorr_with_nonce(msg, nonce, 0).unwrap(); + let sig = sign_schnorr_with_nonce(msg, nonce, 0, 0).unwrap(); let expected_sig = "ff4cb99e0a9be8ec7dea1e51904cf22f71717c19fc3e7dcbc8346eb28bebffbb892c4c41e05c2383efda00f5acc9c7f3622d88a90630cd62d49db598c8ce10b9"; assert_eq!(sig.len(), 128); assert_eq!(sig.to_string(), expected_sig); // sign again - let sig2 = sign_schnorr_with_nonce(msg, nonce, 0).unwrap(); + let sig2 = sign_schnorr_with_nonce(msg, nonce, 0, 0).unwrap(); assert_eq!(sig2.to_string(), expected_sig); // sign with different nonce let nonce2 = "0123450000000000006897528962743076432965432697856340567500000199"; - let sig3 = sign_schnorr_with_nonce(msg, nonce2, 0).unwrap(); + let sig3 = sign_schnorr_with_nonce(msg, nonce2, 0, 0).unwrap(); assert_eq!(sig3.to_string(), "4578740620e7a2c56eabea07c835dba35e832115930d023d0a7778652fbbf7d97a9f4a207dcb1456f1b0f57c4856085c32c79f4efce81cd276c272190aab5e3c"); } @@ -154,23 +172,25 @@ fn test_verify_schnorr() { // Constant signature let sig1 = "ff4cb99e0a9be8ec7dea1e51904cf22f71717c19fc3e7dcbc8346eb28bebffbb892c4c41e05c2383efda00f5acc9c7f3622d88a90630cd62d49db598c8ce10b9"; - let verify_res = verify_schnorr(msg, &sig1, 0).unwrap(); + let verify_res = verify_schnorr(msg, &sig1, 0, 0).unwrap(); assert_eq!(verify_res, true); // Signature created here let nonce = "0123450000000000006897528962743076432965432697856340567500000100"; - let sig = sign_schnorr_with_nonce(msg, nonce, 0).unwrap(); + let sig = sign_schnorr_with_nonce(msg, nonce, 0, 0).unwrap(); - let verify_res = verify_schnorr(msg, &sig, 0).unwrap(); + let verify_res = verify_schnorr(msg, &sig, 0, 0).unwrap(); assert_eq!(verify_res, true); // Verify with different key index - let verify_res = verify_schnorr(msg, &sig, 1).unwrap(); + let verify_res = verify_schnorr(msg, &sig, 0, 1).unwrap(); + assert_eq!(verify_res, false); + let verify_res = verify_schnorr(msg, &sig, 1, 0).unwrap(); assert_eq!(verify_res, false); // Verify with a different message let msg2 = "This is ANOTHER message"; - let verify_res = verify_schnorr(msg2, &sig, 0).unwrap(); + let verify_res = verify_schnorr(msg2, &sig, 0, 0).unwrap(); assert_eq!(verify_res, false); } From 59eec67b4df8255b916fd781c46e81176e281b8f Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:23:27 +0100 Subject: [PATCH 4/6] Bump v to 1.9, breaking --- Cargo.toml | 2 +- lib-py/Cargo.toml | 4 ++-- samples/rust/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f819d5c..f9fdfa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dlccryptlib" -version = "1.0.0" +version = "1.9.0" edition = "2021" description = "Library for working with DLC's with adaptor signatures (Discrete Log Contracts), by Cadena Bitcoin" license = "MIT" diff --git a/lib-py/Cargo.toml b/lib-py/Cargo.toml index efa8ef6..eb39a97 100644 --- a/lib-py/Cargo.toml +++ b/lib-py/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dlccryptlib-py" -version = "1.0.0" +version = "1.9.0" edition = "2021" description = "Python-wrapped library for working with DLC's with adaptor signatures (Discrete Log Contracts), by Cadena Bitcoin" license = "MIT" @@ -9,6 +9,6 @@ license = "MIT" name = "dlccryptlib_py" [dependencies] -#dlccryptlib = "1.0.0" +#dlccryptlib = "1.9.0" dlccryptlib = { path = "../" } pyo3 = { version = "0.23.1" } diff --git a/samples/rust/Cargo.toml b/samples/rust/Cargo.toml index ba57182..58e2c96 100644 --- a/samples/rust/Cargo.toml +++ b/samples/rust/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "rust" -version = "0.1.0" +version = "1.9.0" edition = "2021" [dependencies] -#dlccryptlib = "1.0.0" +#dlccryptlib = "1.9.0" dlccryptlib = { path = "../../" } From f9bb99c8fe8a17fdc8b0bf7f3991a73b893c2642 Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:30:23 +0100 Subject: [PATCH 5/6] Adapt samples --- samples/rust/src/main.rs | 4 ++-- samples/rust/src/test_lib.rs | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/samples/rust/src/main.rs b/samples/rust/src/main.rs index fb12f25..47829e2 100644 --- a/samples/rust/src/main.rs +++ b/samples/rust/src/main.rs @@ -16,10 +16,10 @@ fn main() { let xpub = dlccryptlib::init_with_entropy(entropy_hex, network).unwrap(); println!("xpub: {xpub}"); - let pubkey0 = dlccryptlib::get_public_key(0).unwrap(); + let pubkey0 = dlccryptlib::get_public_key(0, 0).unwrap(); println!("pubkey 0: {pubkey0}"); let hash = "0001020300000000000000000000000000000000000000000000000000010203"; - let sig = dlccryptlib::sign_hash_ecdsa(hash, 0, &pubkey0).unwrap(); + let sig = dlccryptlib::sign_hash_ecdsa(hash, 0, 0, &pubkey0).unwrap(); println!("signature: {sig}"); } diff --git a/samples/rust/src/test_lib.rs b/samples/rust/src/test_lib.rs index 44684c8..bc8f688 100644 --- a/samples/rust/src/test_lib.rs +++ b/samples/rust/src/test_lib.rs @@ -21,34 +21,41 @@ fn test_init_with_entropy() { fn test_get_public_key() { let _xpub = dlccryptlib::init_with_entropy(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); - let pubkey0 = dlccryptlib::get_public_key(0).unwrap(); + let pubkey00 = dlccryptlib::get_public_key(0, 0).unwrap(); assert_eq!( - pubkey0.to_string(), + pubkey00.to_string(), "031941e84b8d111e094aefc46e7181757c93a1da87c93ab519a40d9d765176e704" ); - let pubkey3 = dlccryptlib::get_public_key(3).unwrap(); + let pubkey03 = dlccryptlib::get_public_key(0, 3).unwrap(); assert_eq!( - pubkey3.to_string(), + pubkey03.to_string(), "02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128" ); + + let pubkey10 = dlccryptlib::get_public_key(1, 0).unwrap(); + assert_eq!( + pubkey10.to_string(), + "026f48799f8f6571a6b8d1f8737f4ca9f2b73aa7597ee8766120cac4cee222a603" + ); } #[test] fn test_sign_hash_ecdsa() { let _xpub = dlccryptlib::init_with_entropy(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); - let pubkey3 = dlccryptlib::get_public_key(3).unwrap(); + let pubkey3 = dlccryptlib::get_public_key(0, 3).unwrap(); assert_eq!( pubkey3.to_string(), "02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128" ); let hash = DUMMY_HASH07_STR; - let sig = dlccryptlib::sign_hash_ecdsa(&hash, 3, &pubkey3).unwrap(); + let sig = dlccryptlib::sign_hash_ecdsa(&hash, 0, 3, &pubkey3).unwrap(); assert!(sig.len() >= 140 && sig.len() <= 146); // negative test, wrong index - assert!(dlccryptlib::sign_hash_ecdsa(&hash, 31, &pubkey3).is_err()); + assert!(dlccryptlib::sign_hash_ecdsa(&hash, 0, 31, &pubkey3).is_err()); + assert!(dlccryptlib::sign_hash_ecdsa(&hash, 1, 3, &pubkey3).is_err()); } From cf13d6049fb6faa28413adb98c89bcd4c262de85 Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:40:56 +0100 Subject: [PATCH 6/6] Adapt python part (breaking) --- lib-py/src/lib.rs | 36 ++++++++++++++++++++---------------- samples/python/main.py | 4 ++-- samples/python/test_lib.py | 10 +++++----- samples/python/test_lib_c.py | 26 +++++++++++++------------- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib-py/src/lib.rs b/lib-py/src/lib.rs index 1f013e2..5fb24e5 100644 --- a/lib-py/src/lib.rs +++ b/lib-py/src/lib.rs @@ -38,26 +38,26 @@ pub fn get_xpub() -> PyResult { /// Return a child public key (specified by its index). #[pyfunction] -pub fn get_public_key(index: u32) -> PyResult { - dlccryptlib::get_public_key(index).map_err(|e| PyErr::new::(e)) +pub fn get_public_key(index4: u32, index5: u32) -> PyResult { + dlccryptlib::get_public_key(index4, index5).map_err(|e| PyErr::new::(e)) } /// Return a child address (specified by index). #[pyfunction] -pub fn get_address(index: u32) -> PyResult { - dlccryptlib::get_address(index).map_err(|e| PyErr::new::(e)) +pub fn get_address(index4: u32, index5: u32) -> PyResult { + dlccryptlib::get_address(index4, index5).map_err(|e| PyErr::new::(e)) } /// Verify a child public key. #[pyfunction] -pub fn verify_public_key(index: u32, pubkey: String) -> PyResult { - dlccryptlib::verify_public_key(index, &pubkey).map_err(|e| PyErr::new::(e)) +pub fn verify_public_key(index4: u32, index5: u32, pubkey: String) -> PyResult { + dlccryptlib::verify_public_key(index4, index5, &pubkey).map_err(|e| PyErr::new::(e)) } /// Sign a hash with a child private key (specified by index). #[pyfunction] -pub fn sign_hash_ecdsa(hash: String, signer_index: u32, signer_pubkey: String) -> PyResult { - dlccryptlib::sign_hash_ecdsa(&hash, signer_index, &signer_pubkey) +pub fn sign_hash_ecdsa(hash: String, signer_index4: u32, signer_index5: u32, signer_pubkey: String) -> PyResult { + dlccryptlib::sign_hash_ecdsa(&hash, signer_index4, signer_index5, &signer_pubkey) .map_err(|e| PyErr::new::(e)) } @@ -73,15 +73,15 @@ pub fn create_deterministic_nonce( /// Sign a message using Schnorr, with a nonce, using a child key #[pyfunction] -pub fn sign_schnorr_with_nonce(msg: String, nonce_sec_hex: String, index: u32) -> PyResult { - dlccryptlib::sign_schnorr_with_nonce(&msg, &nonce_sec_hex, index) +pub fn sign_schnorr_with_nonce(msg: String, nonce_sec_hex: String, index4: u32, index5: u32) -> PyResult { + dlccryptlib::sign_schnorr_with_nonce(&msg, &nonce_sec_hex, index4, index5) .map_err(|e| PyErr::new::(e)) } /// Verify a Schnorr signature over a message, using a child key #[pyfunction] -pub fn verify_schnorr(msg: String, signature_hex: String, index: u32) -> PyResult { - dlccryptlib::verify_schnorr(&msg, &signature_hex, index) +pub fn verify_schnorr(msg: String, signature_hex: String, index4: u32, index5: u32) -> PyResult { + dlccryptlib::verify_schnorr(&msg, &signature_hex, index4, index5) .map_err(|e| PyErr::new::(e)) } @@ -105,7 +105,8 @@ pub fn create_cet_adaptor_sigs( num_cets: u64, digit_string_template: String, oracle_pubkey: String, - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey: String, nonces: String, interval_wildcards: String, @@ -116,7 +117,8 @@ pub fn create_cet_adaptor_sigs( num_cets, &digit_string_template, &oracle_pubkey, - signing_key_index, + signing_key_index4, + signing_key_index5, &signing_pubkey, &nonces, &interval_wildcards, @@ -155,7 +157,8 @@ pub fn verify_cet_adaptor_sigs( /// Perform final signing of a CET #[pyfunction] pub fn create_final_cet_sigs( - signing_key_index: u32, + signing_key_index4: u32, + signing_key_index5: u32, signing_pubkey: String, other_pubkey: String, num_digits: u8, @@ -165,7 +168,8 @@ pub fn create_final_cet_sigs( other_adaptor_signature: String, ) -> PyResult { dlccryptlib::create_final_cet_sigs( - signing_key_index, + signing_key_index4, + signing_key_index5, &signing_pubkey, &other_pubkey, num_digits, diff --git a/samples/python/main.py b/samples/python/main.py index b6be45a..7d32575 100644 --- a/samples/python/main.py +++ b/samples/python/main.py @@ -9,11 +9,11 @@ def sample(): xpub = dlccryptlib_py.init_with_entropy(entropy_hex, network) print(f"Library initialized, xpub {xpub}") - pubkey0 = dlccryptlib_py.get_public_key(0) + pubkey0 = dlccryptlib_py.get_public_key(0, 0) print(f"pubkey 0: {pubkey0}") hash = "0001020300000000000000000000000000000000000000000000000000010203" - sig = dlccryptlib_py.sign_hash_ecdsa(hash, 0, pubkey0) + sig = dlccryptlib_py.sign_hash_ecdsa(hash, 0, 0, pubkey0) print(f"signature: {sig}") if __name__ == "__main__": diff --git a/samples/python/test_lib.py b/samples/python/test_lib.py index 30834d8..6d7470a 100644 --- a/samples/python/test_lib.py +++ b/samples/python/test_lib.py @@ -9,9 +9,9 @@ xpub = dlccryptlib_py.get_xpub() print('Xpub', xpub) -pubkey0 = dlccryptlib_py.get_public_key(0) +pubkey0 = dlccryptlib_py.get_public_key(0, 0) print('Pubkey 0', pubkey0) -address0 = dlccryptlib_py.get_address(0) +address0 = dlccryptlib_py.get_address(0, 0) print('Address 0', address0) event_id = "event001" @@ -25,11 +25,11 @@ nonce2_arr = dlccryptlib_py.create_deterministic_nonce(event_id, 2) # Sign the event id with nonce1 -sig = dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce1_sec, 0) +sig = dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce1_sec, 0, 0) print('Signature: ', sig) # Sign again (same nonce) -print('Sign again: ', dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce1_sec, 0)) +print('Sign again: ', dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce1_sec, 0, 0)) # Sign with different nonce -print('Sign with other nonce: ', dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce2_arr[0], 0)) +print('Sign with other nonce: ', dlccryptlib_py.sign_schnorr_with_nonce(event_id, nonce2_arr[0], 0, 0)) diff --git a/samples/python/test_lib_c.py b/samples/python/test_lib_c.py index a4b752c..6f8a375 100644 --- a/samples/python/test_lib_c.py +++ b/samples/python/test_lib_c.py @@ -28,11 +28,11 @@ def __init__(self): # Define Rust method signatures self.lib.init_with_entropy_c.argtypes = [c_char_p, c_char_p] self.lib.init_with_entropy_c.restype = c_char_p - self.lib.get_public_key_c.argtypes = [c_uint32] + self.lib.get_public_key_c.argtypes = [c_uint32, c_uint32] self.lib.get_public_key_c.restype = c_char_p - self.lib.sign_hash_ecdsa_c.argtypes = [c_char_p, c_uint32, c_char_p] + self.lib.sign_hash_ecdsa_c.argtypes = [c_char_p, c_uint32, c_uint32, c_char_p] self.lib.sign_hash_ecdsa_c.restype = c_char_p - self.lib.create_cet_adaptor_sigs_c.argtypes = [c_uint8, c_uint32, c_char_p, c_char_p, c_uint32, c_char_p, c_char_p, c_char_p, c_char_p] + self.lib.create_cet_adaptor_sigs_c.argtypes = [c_uint8, c_uint32, c_char_p, c_char_p, c_uint32, c_uint32, c_char_p, c_char_p, c_char_p, c_char_p] self.lib.create_cet_adaptor_sigs_c.restype = c_char_p self.lib.create_deterministic_nonce_c.argtypes = [c_char_p, c_char_p] self.lib.create_deterministic_nonce_c.restype = c_char_p @@ -43,19 +43,19 @@ def init_with_entropy(self, entropy, network): return self.lib.init_with_entropy_c(entropy.encode('utf-8'), network.encode('utf-8')).decode("utf-8") # Sign a hash with a child private key (specified by index). - def sign_hash_ecdsa(self, hash, signer_index, signer_pubkey): + def sign_hash_ecdsa(self, hash, signer_index4, signer_index5, signer_pubkey): # Call the Rust function (sign_hash_ecdsa_c) from the .so library - return self.lib.sign_hash_ecdsa_c(hash.encode('utf-8'), signer_index, signer_pubkey.encode('utf-8')).decode('utf-8') + return self.lib.sign_hash_ecdsa_c(hash.encode('utf-8'), signer_index4, signer_index5, signer_pubkey.encode('utf-8')).decode('utf-8') # Create adaptor signatures for a number of CETs - def create_cet_adaptor_sigs(self, num_digits: int, num_cets: int, digit_string_template: str, oracle_pubkey: str, signing_key_index: int, signing_pubkey: str, nonces: str, interval_wildcards: str, sighashes: str): + def create_cet_adaptor_sigs(self, num_digits: int, num_cets: int, digit_string_template: str, oracle_pubkey: str, signing_key_index4: int, signing_key_index5, signing_pubkey: str, nonces: str, interval_wildcards: str, sighashes: str): # Call the Rust function (create_cet_adaptor_sigs_c) from the .so library - return self.lib.create_cet_adaptor_sigs_c(num_digits, num_cets, digit_string_template.encode('utf-8'), oracle_pubkey.encode('utf-8'), signing_key_index, signing_pubkey.encode('utf-8'), nonces.encode('utf-8'), interval_wildcards.encode('utf-8'), sighashes.encode('utf-8')).decode('utf-8') + return self.lib.create_cet_adaptor_sigs_c(num_digits, num_cets, digit_string_template.encode('utf-8'), oracle_pubkey.encode('utf-8'), signing_key_index4, signing_key_index5, signing_pubkey.encode('utf-8'), nonces.encode('utf-8'), interval_wildcards.encode('utf-8'), sighashes.encode('utf-8')).decode('utf-8') # Return a child public key. - def get_public_key(self, index): + def get_public_key(self, index4, index5): # Call the Rust function (get_public_key_c) from the .so library - return self.lib.get_public_key_c(index).decode("utf-8") + return self.lib.get_public_key_c(index4, index5).decode("utf-8") def create_deterministic_nonce(self, event_id, index): # Call the Rust function (create_deterministic_nonce_c) from the .so library @@ -75,12 +75,12 @@ def create_deterministic_nonce(self, event_id, index): print("xpub:", xpub) assert(xpub == "tpubDCxVvuZwEu4oZypCT3pzos1MUoVJyjTHjfrhKFXNBkAEqBmkkzEb2dUgzpZmBWbd6wZnNmm3Ex2suMnEFUMmayH2a6S49R4pTnoQttGrxUm") -pubkey0 = rust_interface.get_public_key(0) -print("pubkey 0:", pubkey0) +pubkey0 = rust_interface.get_public_key(0, 0) +print("pubkey 0/0:", pubkey0) assert(pubkey0 == "031941e84b8d111e094aefc46e7181757c93a1da87c93ab519a40d9d765176e704") hash = "0001020300000000000000000000000000000000000000000000000000010203" -sig = rust_interface.sign_hash_ecdsa(hash, 0, pubkey0) +sig = rust_interface.sign_hash_ecdsa(hash, 0, 0, pubkey0) print("sig:", sig) @@ -89,7 +89,7 @@ def create_deterministic_nonce(self, event_id, index): nonces = "03bf8272fd77ac83400e8b7f1af5899ab96ce81871ca26d31fa3b80db08bdc412e 03ec14b379b5db0c5305a452ee04d4b82b5a1db90f8eddc55f1f94d5947b341ed4 0325642feb3db37b3ffa88b0754d59ad1c3116e035ee9e5557e107fd3d914fb3fb 02d597f9bd84cb925ade7efa04edf46c33a7d96cc4252647204a6961a34838d00d 03d11c778b1c4f1f7710a4b17816f02d049325220b2fb8007efd84248f08fd75dc 038fb0dbd6eb0e970c75c28ca02b614523fe59b5da000f815fcfbfcf4a4ecdd192 023f0eadc3b9c3337d31e38a9238a3c59505cc8004fa7ca6facdd3c853d824ca0d" interval_wildcards = "0000*** 0001*** 0002***" sighashes = "0001020300000000000000000000000000000000000000000000000000010200 0001020300000000000000000000000000000000000000000000000000010201 0001020300000000000000000000000000000000000000000000000000010202" -sigs = rust_interface.create_cet_adaptor_sigs(7, 3, digit_string_template, oracle_pubkey, 0, pubkey0, nonces, interval_wildcards, sighashes) +sigs = rust_interface.create_cet_adaptor_sigs(7, 3, digit_string_template, oracle_pubkey, 0, 0, pubkey0, nonces, interval_wildcards, sighashes) print("signatures:", sigs)