From a6e8f581dbfad3f5b63e13fc17dd6cf79d38e00c Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 12 Apr 2021 14:09:02 +0200 Subject: [PATCH] PSBT BIP32 keys moved to Secp256k1 from bitcoin ECDSA Fourth step in implementation of Schnorr key support after #588. While PSBT BIP174 does not specify whether uncompressed keys are supported in BIP32-related fields, from BIP32 it follows that it is impossible to use uncompressed keys within the extended keys. This PR fixes this situation and is a companion to BIP174 PR clarifying key serialization: https://github.com/bitcoin/bips/pull/1100 --- src/blockdata/script.rs | 4 ++-- src/util/psbt/map/input.rs | 14 +++++++------- src/util/psbt/map/output.rs | 8 ++++---- src/util/psbt/mod.rs | 16 +++------------- src/util/psbt/serialize.rs | 12 +++++------- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 5a62cab0..4a946747 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -1038,10 +1038,10 @@ mod test { let pubkey = PublicKey::from_str("0234e6a79c5359c613762d537e0e19d86c77c1666d8c9ab050f23acd198e97f93e").unwrap(); assert!(Script::new_p2pk(&pubkey).is_p2pk()); - let pubkey_hash = PubkeyHash::hash(&pubkey.serialize()); + let pubkey_hash = PubkeyHash::hash(&pubkey.key.serialize()); assert!(Script::new_p2pkh(&pubkey_hash).is_p2pkh()); - let wpubkey_hash = WPubkeyHash::hash(&pubkey.serialize()); + let wpubkey_hash = WPubkeyHash::hash(&pubkey.key.serialize()); assert!(Script::new_v0_wpkh(&wpubkey_hash).is_v0_p2wpkh()); let script = Builder::new().push_opcode(opcodes::all::OP_NUMEQUAL) diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index 926bf899..52ef22ab 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -16,13 +16,13 @@ use prelude::*; use ::{EcdsaSig, io}; +use secp256k1; use blockdata::script::Script; use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut}; use consensus::encode; +use hashes::{self, hash160, ripemd160, sha256, sha256d}; use secp256k1::XOnlyPublicKey; use util::bip32::KeySource; -use hashes::{self, hash160, ripemd160, sha256, sha256d}; -use util::ecdsa::PublicKey; use util::psbt; use util::psbt::map::Map; use util::psbt::raw; @@ -88,7 +88,7 @@ pub struct Input { pub witness_utxo: Option, /// A map from public keys to their corresponding signature as would be /// pushed to the stack from a scriptSig or witness for a non-taproot inputs. - pub partial_sigs: BTreeMap, + pub partial_sigs: BTreeMap, /// The sighash type to be used for this input. Signatures for this input /// must use the sighash type. pub sighash_type: Option, @@ -99,7 +99,7 @@ pub struct Input { /// A map from public keys needed to sign this input to their corresponding /// master key fingerprints and derivation paths. #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] - pub bip32_derivation: BTreeMap, + pub bip32_derivation: BTreeMap, /// The finalized, fully-constructed scriptSig with signatures and any other /// scripts necessary for this input to pass validation. pub final_script_sig: Option