Skip to content

Commit

Permalink
Remove lib bitcoin dependency, update tapsigner to verify derive sig …
Browse files Browse the repository at this point in the history
…with master_pubkey
  • Loading branch information
notmandatory committed Jul 3, 2023
1 parent 18d3070 commit af86c79
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
33 changes: 2 additions & 31 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,8 @@ impl<T: CkTransport> TapSigner<T> {
message_bytes.extend(&response.chain_code);
let message = Message::from_hashed_data::<sha256::Hash>(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());
}
Expand Down Expand Up @@ -293,29 +287,6 @@ impl<T: CkTransport> SatsCard<T> {
.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
}
Expand Down

0 comments on commit af86c79

Please sign in to comment.