From af86c798d01e0984acce3b4ed5a3936c3816fae3 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sun, 2 Jul 2023 22:42:00 -0500 Subject: [PATCH] Remove lib bitcoin dependency, update tapsigner to verify derive sig with master_pubkey --- lib/Cargo.toml | 1 - lib/src/lib.rs | 33 ++------------------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 69dcb1b..e558d09 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -10,7 +10,6 @@ ciborium = "0.2.0" serde = "1" serde_bytes = "0.11" secp256k1 = { version = "0.26.0", features = ["rand-std", "bitcoin-hashes-std", "recovery"] } -bitcoin = "0.30.0" # optional dependencies pcsc = { version = "2", optional = true } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 7dc2b36..c94b203 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -137,14 +137,8 @@ impl TapSigner { message_bytes.extend(&response.chain_code); let message = Message::from_hashed_data::(message_bytes.as_slice()); let signature = Signature::from_compact(sig.as_slice())?; - let pubkey = PublicKey::from_slice( - response - .pubkey - .clone() - .expect("derive response pubkey") - .as_slice(), - ) - .unwrap(); + let pubkey = PublicKey::from_slice(response.master_pubkey.as_slice())?; + // TODO fix verify when a derivation path is used, currently only works if no path given self.secp().verify_ecdsa(&message, &signature, &pubkey)?; self.set_card_nonce(response.card_nonce.clone()); } @@ -293,29 +287,6 @@ impl SatsCard { .expect("Failed to construct ECDSA signature from check response"); let pubkey = PublicKey::from_slice(r.master_pubkey.as_slice())?; self.secp().verify_ecdsa(&message, &signature, &pubkey)?; - - // Construct BIP-32 XPUB from master_pubkey + chain_code - - // let chain_code: [u8; 32] = r.chain_code.clone().try_into().unwrap(); - - // use bitcoin::bip32 - // let xpub = ExtendedPubKey { - // network: Network::Bitcoin, - // depth: 0, - // parent_fingerprint: Fingerprint::default(), - // child_number: ChildNumber::from_normal_idx(0).unwrap(), - // public_key: bitcoin::secp256k1::PublicKey::from_slice(r.master_pubkey.as_slice()).unwrap(), - // chain_code: ChainCode::from(chain_code), - // }; - - // The payment address the card shares (i.e., the slot's pubkey) must equal the BIP-32 derived key (m/0) constructed from that XPUB. - // &xpub. - // dbg!(&xpub.to_pub().to_string()); - // let derived_pubkey = PublicKey::from_str(&xpub.to_pub().inner.to_string())?; - // dbg!(&derived_pubkey.to_string()); - // let slot = self.read(None)?.pubkey(None); - // dbg!(&slot.to_string()); - // assert_eq!(&derived_pubkey, &slot); } resp }