Skip to content

Commit

Permalink
Bug: Change type of pbst partial sig from secp key to bitcoin key
Browse files Browse the repository at this point in the history
This changes the type of secp signature from secp256k1::Signature to
bitcoin::PublicKey. Psbt allows storing signatures for both compressed
as well as uncompressed keys. This bug was introduced in rust-bitcoin#591 while
trying to change the type of BIP32 keys from bitcoin::PublicKey to
secp256k1::PublicKey.
  • Loading branch information
sanket1729 committed Feb 17, 2022
1 parent 0c5b695 commit 69c6eb6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/util/psbt/map/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use util::psbt::map::Map;
use util::psbt::raw;
use util::psbt::serialize::Deserialize;
use util::psbt::{Error, error};
use util::key::PublicKey;

use util::taproot::{ControlBlock, LeafVersion, TapLeafHash, TapBranchHash};
use util::sighash;
Expand Down Expand Up @@ -89,7 +90,7 @@ pub struct Input {
pub witness_utxo: Option<TxOut>,
/// 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<secp256k1::PublicKey, EcdsaSig>,
pub partial_sigs: BTreeMap<PublicKey, EcdsaSig>,
/// The sighash type to be used for this input. Signatures for this input
/// must use the sighash type.
pub sighash_type: Option<PsbtSigHashType>,
Expand Down Expand Up @@ -209,7 +210,7 @@ impl Input {
}
PSBT_IN_PARTIAL_SIG => {
impl_psbt_insert_pair! {
self.partial_sigs <= <raw_key: secp256k1::PublicKey>|<raw_value: EcdsaSig>
self.partial_sigs <= <raw_key: PublicKey>|<raw_value: EcdsaSig>
}
}
PSBT_IN_SIGHASH_TYPE => {
Expand Down
16 changes: 16 additions & 0 deletions src/util/psbt/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use util::ecdsa::{EcdsaSig, EcdsaSigError};
use util::psbt;
use util::taproot::{TapBranchHash, TapLeafHash, ControlBlock, LeafVersion};
use schnorr;
use util::key::PublicKey;

use super::map::{TapTree, PsbtSigHashType};

Expand Down Expand Up @@ -75,6 +76,21 @@ impl Deserialize for Script {
}
}

impl Serialize for PublicKey {
fn serialize(&self) -> Vec<u8> {
let mut buf = Vec::new();
self.write_into(&mut buf).expect("vecs don't error");
buf
}
}

impl Deserialize for PublicKey {
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
PublicKey::from_slice(bytes)
.map_err(|_| encode::Error::ParseFailed("invalid public key"))
}
}

impl Serialize for secp256k1::PublicKey {
fn serialize(&self) -> Vec<u8> {
self.serialize().to_vec()
Expand Down

0 comments on commit 69c6eb6

Please sign in to comment.