Skip to content

Commit

Permalink
Merge pull request #589 from LNP-BP/taproot/key-1
Browse files Browse the repository at this point in the history
Non-API breaking introduction of Schnorr keys
  • Loading branch information
apoelstra committed Apr 29, 2021
2 parents 8231e25 + 230813b commit 4db4e60
Show file tree
Hide file tree
Showing 15 changed files with 563 additions and 510 deletions.
2 changes: 1 addition & 1 deletion examples/bip32.rs
Expand Up @@ -4,7 +4,7 @@ use std::{env, process};
use std::str::FromStr;

use bitcoin::secp256k1::Secp256k1;
use bitcoin::util::key::PrivateKey;
use bitcoin::util::ecdsa::PrivateKey;
use bitcoin::util::bip32::ExtendedPrivKey;
use bitcoin::util::bip32::ExtendedPubKey;
use bitcoin::util::bip32::DerivationPath;
Expand Down
4 changes: 2 additions & 2 deletions src/blockdata/script.rs
Expand Up @@ -37,7 +37,7 @@ use hashes::{Hash, hex};
#[cfg(feature="bitcoinconsensus")] use std::convert;
#[cfg(feature="bitcoinconsensus")] use OutPoint;

use util::key::PublicKey;
use util::ecdsa::PublicKey;

#[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
/// A Bitcoin script
Expand Down Expand Up @@ -889,7 +889,7 @@ mod test {
use hashes::hex::{FromHex, ToHex};
use consensus::encode::{deserialize, serialize};
use blockdata::opcodes;
use util::key::PublicKey;
use util::ecdsa::PublicKey;
use util::psbt::serialize::Serialize;

#[test]
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Expand Up @@ -85,10 +85,15 @@ pub use util::address::AddressType;
pub use util::amount::Amount;
pub use util::amount::Denomination;
pub use util::amount::SignedAmount;
pub use util::key::PrivateKey;
pub use util::key::PublicKey;
pub use util::merkleblock::MerkleBlock;

pub use util::ecdsa;
pub use util::schnorr;
#[deprecated(since = "0.26.1", note = "Please use `ecdsa::PrivateKey` instead")]
pub use util::ecdsa::PrivateKey;
#[deprecated(since = "0.26.1", note = "Please use `ecdsa::PublicKey` instead")]
pub use util::ecdsa::PublicKey;

#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;

#[cfg(all(test, feature = "unstable"))]
Expand Down
14 changes: 7 additions & 7 deletions src/util/address.rs
Expand Up @@ -21,13 +21,13 @@
//!
//! use bitcoin::network::constants::Network;
//! use bitcoin::util::address::Address;
//! use bitcoin::util::key;
//! use bitcoin::util::ecdsa;
//! use bitcoin::secp256k1::Secp256k1;
//! use bitcoin::secp256k1::rand::thread_rng;
//!
//! // Generate random key pair
//! let s = Secp256k1::new();
//! let public_key = key::PublicKey {
//! let public_key = ecdsa::PublicKey {
//! compressed: true,
//! key: s.generate_keypair(&mut thread_rng()).1,
//! };
Expand All @@ -46,7 +46,7 @@ use hash_types::{PubkeyHash, WPubkeyHash, ScriptHash, WScriptHash};
use blockdata::script;
use network::constants::Network;
use util::base58;
use util::key;
use util::ecdsa;

/// Address error.
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -220,7 +220,7 @@ impl Address {
/// Creates a pay to (compressed) public key hash address from a public key
/// This is the preferred non-witness type address
#[inline]
pub fn p2pkh(pk: &key::PublicKey, network: Network) -> Address {
pub fn p2pkh(pk: &ecdsa::PublicKey, network: Network) -> Address {
let mut hash_engine = PubkeyHash::engine();
pk.write_into(&mut hash_engine).expect("engines don't error");

Expand All @@ -244,7 +244,7 @@ impl Address {
/// This is the native segwit address type for an output redeemable with a single signature
///
/// Will only return an Error when an uncompressed public key is provided.
pub fn p2wpkh(pk: &key::PublicKey, network: Network) -> Result<Address, Error> {
pub fn p2wpkh(pk: &ecdsa::PublicKey, network: Network) -> Result<Address, Error> {
if !pk.compressed {
return Err(Error::UncompressedPubkey);
}
Expand All @@ -265,7 +265,7 @@ impl Address {
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients
///
/// Will only return an Error when an uncompressed public key is provided.
pub fn p2shwpkh(pk: &key::PublicKey, network: Network) -> Result<Address, Error> {
pub fn p2shwpkh(pk: &ecdsa::PublicKey, network: Network) -> Result<Address, Error> {
if !pk.compressed {
return Err(Error::UncompressedPubkey);
}
Expand Down Expand Up @@ -500,7 +500,7 @@ mod tests {

use blockdata::script::Script;
use network::constants::Network::{Bitcoin, Testnet};
use util::key::PublicKey;
use util::ecdsa::PublicKey;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/util/bip143.rs
Expand Up @@ -274,7 +274,7 @@ mod tests {
use consensus::encode::deserialize;
use network::constants::Network;
use util::address::Address;
use util::key::PublicKey;
use util::ecdsa::PublicKey;
use hashes::hex::FromHex;

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/util/bip32.rs
Expand Up @@ -26,8 +26,8 @@ use hashes::{sha512, Hash, HashEngine, Hmac, HmacEngine};
use secp256k1::{self, Secp256k1};

use network::constants::Network;
use util::{base58, endian};
use util::key::{self, PublicKey, PrivateKey};
use util::{base58, endian, key};
use util::ecdsa::{PublicKey, PrivateKey};

/// A chain code
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down

0 comments on commit 4db4e60

Please sign in to comment.