Improve the public API
We created the `crypto` crate as a container for cryptography modules with the idea that it may be split out into a separate crate. There is no reason for users of the lib to know about this module. Also, we have two `taproot` modules, one in `crypto` and one at the crate root, this makes for un-ergonomic usage of the lib. Improve the public API by doing: - Make the `crypto` module private (`pub(crate)`). - Re-export `crypto::taproot::Signature` (and `Error`) from `crate::taproot`
This commit is contained in:
parent
4d8ba9be31
commit
42b07586ac
|
@ -81,15 +81,12 @@ use std::str::FromStr;
|
|||
use bitcoin::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey, Fingerprint};
|
||||
use bitcoin::consensus::encode;
|
||||
use bitcoin::constants::COIN_VALUE;
|
||||
use bitcoin::crypto::taproot;
|
||||
use bitcoin::key::{TapTweak, XOnlyPublicKey};
|
||||
use bitcoin::opcodes::all::{OP_CHECKSIG, OP_CLTV, OP_DROP};
|
||||
use bitcoin::psbt::{self, Input, Output, Psbt, PsbtSighashType};
|
||||
use bitcoin::secp256k1::Secp256k1;
|
||||
use bitcoin::sighash::{self, TapSighashType, SighashCache};
|
||||
use bitcoin::taproot::{
|
||||
LeafVersion, TapLeafHash, TapSighash, TaprootBuilder, TaprootSpendInfo,
|
||||
};
|
||||
use bitcoin::sighash::{self, SighashCache, TapSighash, TapSighashType};
|
||||
use bitcoin::taproot::{self, LeafVersion, TapLeafHash, TaprootBuilder, TaprootSpendInfo};
|
||||
use bitcoin::{
|
||||
absolute, script, Address, Amount, Network, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Witness,
|
||||
};
|
||||
|
|
|
@ -589,8 +589,8 @@ impl<E> EncodeSigningDataResult<E> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin::consensus::deserialize;
|
||||
/// # use bitcoin::sighash::{LegacySighash, SighashCache};
|
||||
/// # use bitcoin::Transaction;
|
||||
/// # use bitcoin::crypto::sighash::{LegacySighash, SighashCache};
|
||||
/// # use bitcoin_hashes::{Hash, hex::FromHex};
|
||||
/// # let mut writer = LegacySighash::engine();
|
||||
/// # let input_index = 0;
|
||||
|
|
|
@ -578,7 +578,7 @@ pub type UntweakedKeyPair = KeyPair;
|
|||
/// # Examples
|
||||
/// ```
|
||||
/// # #[cfg(feature = "rand-std")] {
|
||||
/// # use bitcoin::crypto::key::{KeyPair, TweakedKeyPair, TweakedPublicKey};
|
||||
/// # use bitcoin::key::{KeyPair, TweakedKeyPair, TweakedPublicKey};
|
||||
/// # use bitcoin::secp256k1::{rand, Secp256k1};
|
||||
/// # let secp = Secp256k1::new();
|
||||
/// # let keypair = TweakedKeyPair::dangerous_assume_tweaked(KeyPair::new(&secp, &mut rand::thread_rng()));
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
pub mod ecdsa;
|
||||
pub mod key;
|
||||
pub mod sighash;
|
||||
pub mod taproot;
|
||||
// Contents re-exported in `bitcoin::taproot`.
|
||||
pub(crate) mod taproot;
|
||||
|
|
|
@ -92,7 +92,8 @@ pub mod bip158;
|
|||
pub mod bip32;
|
||||
pub mod blockdata;
|
||||
pub mod consensus;
|
||||
pub mod crypto;
|
||||
// Private until we either make this a crate or flatten it - still to be decided.
|
||||
pub(crate) mod crypto;
|
||||
pub mod error;
|
||||
pub mod hash_types;
|
||||
pub mod merkle_tree;
|
||||
|
@ -127,7 +128,7 @@ pub use crate::blockdata::witness::{self, Witness};
|
|||
pub use crate::blockdata::{constants, opcodes};
|
||||
pub use crate::consensus::encode::VarInt;
|
||||
pub use crate::crypto::key::{self, PrivateKey, PublicKey};
|
||||
pub use crate::crypto::sighash;
|
||||
pub use crate::crypto::{ecdsa, sighash};
|
||||
pub use crate::error::Error;
|
||||
pub use crate::hash_types::{Txid, Wtxid, BlockHash, PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash};
|
||||
pub use crate::merkle_tree::MerkleBlock;
|
||||
|
|
|
@ -13,12 +13,13 @@ use bitcoin_internals::write_err;
|
|||
use secp256k1::{self, Scalar, Secp256k1};
|
||||
|
||||
use crate::consensus::Encodable;
|
||||
use crate::crypto::key::{TapTweak, TweakedPublicKey, UntweakedPublicKey, XOnlyPublicKey};
|
||||
use crate::hashes::{sha256t_hash_newtype, Hash, HashEngine};
|
||||
use crate::crypto::key::{TapTweak, TweakedPublicKey, UntweakedPublicKey, XOnlyPublicKey};
|
||||
use crate::prelude::*;
|
||||
use crate::{io, Script, ScriptBuf};
|
||||
|
||||
pub use crate::crypto::sighash::{TapSighash, TapSighashTag};
|
||||
// Re-export these so downstream only has to use one `taproot` module.
|
||||
pub use crate::crypto::taproot::{Signature, Error};
|
||||
|
||||
/// The SHA-256 midstate value for the TapLeaf hash.
|
||||
const MIDSTATE_TAPLEAF: [u8; 32] = [
|
||||
|
@ -1133,6 +1134,7 @@ mod test {
|
|||
use crate::hashes::hex::FromHex;
|
||||
use crate::hashes::sha256t::Tag;
|
||||
use crate::hashes::{sha256, Hash, HashEngine};
|
||||
use crate::sighash::{TapSighash, TapSighashTag};
|
||||
use crate::{Address, Network};
|
||||
extern crate serde_json;
|
||||
|
||||
|
|
|
@ -30,16 +30,15 @@ use bitcoin::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, KeySource};
|
|||
use bitcoin::blockdata::locktime::{absolute, relative};
|
||||
use bitcoin::blockdata::witness::Witness;
|
||||
use bitcoin::consensus::encode::deserialize;
|
||||
use bitcoin::crypto::key::UntweakedPublicKey;
|
||||
use bitcoin::crypto::{ecdsa, taproot};
|
||||
use bitcoin::hashes::hex::FromHex;
|
||||
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
|
||||
use bitcoin::key::UntweakedPublicKey;
|
||||
use bitcoin::psbt::raw::{self, Key, Pair, ProprietaryKey};
|
||||
use bitcoin::psbt::{Input, Output, Psbt, PsbtSighashType};
|
||||
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
|
||||
use bitcoin::taproot::{ControlBlock, LeafVersion, TaprootBuilder, TaprootSpendInfo};
|
||||
use bitcoin::taproot::{self, ControlBlock, LeafVersion, TaprootBuilder, TaprootSpendInfo};
|
||||
use bitcoin::{
|
||||
Address, Block, Network, OutPoint, PrivateKey, PublicKey, ScriptBuf, Sequence, Target,
|
||||
ecdsa, Address, Block, Network, OutPoint, PrivateKey, PublicKey, ScriptBuf, Sequence, Target,
|
||||
Transaction, TxIn, TxOut, Txid, Work,
|
||||
};
|
||||
use secp256k1::Secp256k1;
|
||||
|
|
Loading…
Reference in New Issue