psbt/
lib.rs

1// Wallet-level libraries for bitcoin protocol by LNP/BP Association
2//
3// Written in 2020-2022 by
4//     Dr. Maxim Orlovsky <orlovsky@lnp-bp.org>
5//
6// This software is distributed without any warranty.
7//
8// You should have received a copy of the Apache-2.0 License
9// along with this software.
10// If not, see <https://opensource.org/licenses/Apache-2.0>.
11
12// Coding conventions
13#![recursion_limit = "256"]
14#![deny(dead_code, /* missing_docs, */ warnings)]
15
16//! PSBT bitcoin library, providing all PSBT functionality from [`bitcoin`]
17//! library, plus
18//! - constructor, supporting miniscript-based descriptors, input descriptors,
19//!   all sighash types, spendings from P2C, S2C-tweaked inputs ([`construct`]);
20//! - advanced signer, supporting pre-segwit, bare and nested segwit v0, taproot
21//!   key and path spendings, different forms of tweaks & commitments, all
22//!   sighash types ([`sign`]);
23//! - commitment-related features: managing tapret-, P2C and S2C-related
24//!   proprietary keys;
25//! - utility methods for fee computing, lexicographic reordering etc;
26//! - command-line utility for editing PSBT data (WIP).
27
28#[macro_use]
29extern crate amplify;
30#[cfg(feature = "serde")]
31#[macro_use]
32extern crate serde_crate as serde;
33#[macro_use]
34extern crate strict_encoding;
35#[cfg(feature = "miniscript")]
36extern crate miniscript_crate as miniscript;
37
38mod errors;
39mod global;
40mod input;
41mod output;
42pub mod p2c;
43
44#[cfg(feature = "construct")]
45pub mod construct;
46pub mod lex_order;
47mod proprietary;
48#[cfg(feature = "sign")]
49pub mod sign;
50
51pub use bitcoin::psbt::raw::ProprietaryKey;
52pub use bitcoin::psbt::{raw, serialize, Error, PsbtSighashType};
53pub use errors::{FeeError, InputMatchError, TxError, TxinError};
54pub use global::{Psbt, PsbtParseError};
55pub use input::Input;
56pub use output::Output;
57pub(crate) mod v0 {
58    pub use bitcoin::psbt::{
59        Input as InputV0, Output as OutputV0, PartiallySignedTransaction as PsbtV0,
60    };
61}
62pub use p2c::{PSBT_IN_P2C_TWEAK, PSBT_P2C_PREFIX};
63pub use proprietary::{
64    ProprietaryKeyDescriptor, ProprietaryKeyError, ProprietaryKeyLocation, ProprietaryKeyType,
65};
66
67/// Version of the PSBT (V0 stands for BIP174-defined version; V2 - for BIP370).
68#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
69#[derive(StrictEncode, StrictDecode)]
70#[strict_encoding(repr = u32)]
71#[cfg_attr(
72    feature = "serde",
73    derive(Serialize, Deserialize),
74    serde(crate = "serde_crate")
75)]
76#[repr(u32)]
77pub enum PsbtVersion {
78    /// Version defined by BIP174.
79    #[default]
80    V0 = 0x0,
81    /// Version defined by BIP370.
82    V2 = 0x2,
83}