Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 4 additions & 33 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"

[[package]]
name = "bincode"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
dependencies = [
"byteorder",
"serde",
]

[[package]]
name = "bitcoin"
version = "0.32.6"
version = "0.32.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad8929a18b8e33ea6b3c09297b687baaa71fb1b97353243a3f1029fad5c59c5b"
checksum = "1e499f9fc0407f50fe98af744ab44fa67d409f76b6772e1689ec8485eb0c0f66"
dependencies = [
"base58ck",
"base64",
Expand Down Expand Up @@ -116,12 +106,6 @@ dependencies = [
"serde",
]

[[package]]
name = "byteorder"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60f0b0d4c0a382d2734228fd12b5a6b5dac185c60e938026fd31b265b94f9bd2"

[[package]]
name = "cc"
version = "1.0.28"
Expand All @@ -147,9 +131,9 @@ dependencies = [

[[package]]
name = "hex-conservative"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
checksum = "fda06d18ac606267c40c04e41b9947729bf8b9efe74bd4e82b61a5f26a510b9f"
dependencies = [
"arrayvec",
]
Expand Down Expand Up @@ -202,14 +186,10 @@ name = "psbt-v2"
version = "0.2.0"
dependencies = [
"anyhow",
"bincode",
"bitcoin",
"hex-conservative",
"miniscript",
"secp256k1",
"serde",
"serde_json",
"serde_test",
]

[[package]]
Expand Down Expand Up @@ -319,15 +299,6 @@ dependencies = [
"serde",
]

[[package]]
name = "serde_test"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "482765e11e55174e2d74a611674d09ed96712c00e0777e305a0c416dfef5fa40"
dependencies = [
"serde",
]

[[package]]
name = "syn"
version = "2.0.46"
Expand Down
30 changes: 4 additions & 26 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,11 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"

[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]

[[package]]
name = "bitcoin"
version = "0.32.7"
version = "0.32.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda569d741b895131a88ee5589a467e73e9c4718e958ac9308e4f7dc44b6945"
checksum = "1e499f9fc0407f50fe98af744ab44fa67d409f76b6772e1689ec8485eb0c0f66"
dependencies = [
"base58ck",
"base64",
Expand Down Expand Up @@ -134,9 +125,9 @@ dependencies = [

[[package]]
name = "hex-conservative"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
checksum = "fda06d18ac606267c40c04e41b9947729bf8b9efe74bd4e82b61a5f26a510b9f"
dependencies = [
"arrayvec",
]
Expand Down Expand Up @@ -198,14 +189,10 @@ name = "psbt-v2"
version = "0.2.0"
dependencies = [
"anyhow",
"bincode",
"bitcoin",
"hex-conservative",
"miniscript",
"secp256k1",
"serde",
"serde_json",
"serde_test",
]

[[package]]
Expand Down Expand Up @@ -306,15 +293,6 @@ dependencies = [
"serde",
]

[[package]]
name = "serde_test"
version = "1.0.177"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f901ee573cab6b3060453d2d5f0bae4e6d628c23c0a962ff9b5f1d7c8d4f1ed"
dependencies = [
"serde",
]

[[package]]
name = "shlex"
version = "1.3.0"
Expand Down
15 changes: 4 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,23 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["std"]
std = ["bitcoin/std", "miniscript?/std"]
rand = ["std", "bitcoin/rand-std"]
serde = ["dep:actual-serde", "bitcoin/serde"]
serde = ["dep:serde", "bitcoin/serde"]
base64 = ["bitcoin/base64"]
miniscript = ["dep:miniscript", "miniscript?/no-std"]

[dependencies]
bitcoin = { version = "0.32.6", default-features = false }
# Workaround for minimal version resolution bug in bitcoin 0.32.x series.
# bitcoin 0.32.6 depends on hex-conservative 0.2.0, which incorrectly specifies
# arrayvec = "0.7" instead of "0.7.2". Is fixed in hex-conservative 0.2.1.
hex-conservative = { version = "0.2.1", default-features = false }
bitcoin = { version = "0.32.8", default-features = false }

miniscript = { version = "12.2.0", default-features = false, optional = true }
actual-serde = { package = "serde", version = "1.0.195", default-features = false, features = ["derive", "alloc"], optional = true }
serde = { version = "1.0.195", default-features = false, features = ["derive", "alloc"], optional = true }

[dev-dependencies]
anyhow = "1.0.86"
serde_json = "1.0.68"
serde_test = "1.0.19"
bincode = "1.3.1"
secp256k1 = { version = "0.29", features = ["rand-std", "global-context"] }

[[example]]
name = "v0"
required-features = ["std"]
required-features = ["std", "rand"]

[[example]]
name = "v2"
Expand Down
8 changes: 5 additions & 3 deletions examples/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use psbt_v2::bitcoin::bip32::{DerivationPath, Fingerprint};
use psbt_v2::bitcoin::hashes::Hash as _;
use psbt_v2::bitcoin::locktime::absolute;
use psbt_v2::bitcoin::opcodes::all::OP_CHECKMULTISIG;
use psbt_v2::bitcoin::secp256k1::{self, rand, SECP256K1};
use psbt_v2::bitcoin::secp256k1::{self, rand, Secp256k1};
use psbt_v2::bitcoin::{
script, transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, PublicKey,
ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, Witness,
Expand Down Expand Up @@ -230,7 +230,8 @@ impl Entity {

let mut keys = BTreeMap::new();
keys.insert(pk, sk);
psbt.sign(&keys, SECP256K1).expect("failed to sign psbt");
let secp = Secp256k1::new();
psbt.sign(&keys, &secp).expect("failed to sign psbt");

Ok(psbt)
}
Expand All @@ -240,7 +241,8 @@ impl Entity {
///
/// In a real application these would come from actual secrets.
fn random_keys() -> (secp256k1::SecretKey, secp256k1::PublicKey) {
let secp = Secp256k1::new();
let sk = secp256k1::SecretKey::new(&mut rand::thread_rng());
let pk = sk.public_key(SECP256K1);
let pk = sk.public_key(&secp);
(sk, pk)
}
19 changes: 10 additions & 9 deletions examples/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use psbt_v2::bitcoin::bip32::{DerivationPath, KeySource, Xpriv, Xpub};
use psbt_v2::bitcoin::hashes::Hash as _;
use psbt_v2::bitcoin::locktime::absolute;
use psbt_v2::bitcoin::opcodes::all::OP_CHECKMULTISIG;
use psbt_v2::bitcoin::secp256k1::{self, SECP256K1};
use psbt_v2::bitcoin::secp256k1::{self, Secp256k1};
use psbt_v2::bitcoin::{
script, Address, Amount, CompressedPublicKey, Network, OutPoint, PublicKey, ScriptBuf,
Sequence, TxOut, Txid,
Expand Down Expand Up @@ -241,17 +241,18 @@ impl Default for Bob {
/// An entity that can take on one of the PSBT roles.
pub struct Entity {
master: Xpriv,
secp: Secp256k1<secp256k1::All>,
}

impl Entity {
/// Creates a new entity with random keys.
pub fn new(master: Xpriv) -> Self { Self { master } }
pub fn new(master: Xpriv) -> Self { Self { master, secp: Secp256k1::new() } }

/// Returns the pubkey for this entity at `derivation_path`.
fn public_key(&self, derivation_path: &str) -> anyhow::Result<bitcoin::PublicKey> {
let path = DerivationPath::from_str(derivation_path)?;
let xpriv = self.master.derive_priv(SECP256K1, &path)?;
let pk = Xpub::from_priv(SECP256K1, &xpriv);
let xpriv = self.master.derive_priv(&self.secp, &path)?;
let pk = Xpub::from_priv(&self.secp, &xpriv);
Ok(pk.to_pub().into())
}

Expand All @@ -270,20 +271,20 @@ impl Entity {
derivation_path: &str,
) -> anyhow::Result<(secp256k1::PublicKey, KeySource)> {
let path = DerivationPath::from_str(derivation_path)?;
let xpriv = self.master.derive_priv(SECP256K1, &path).expect("failed to derive xpriv");
let fingerprint = xpriv.fingerprint(SECP256K1);
let xpriv = self.master.derive_priv(&self.secp, &path).expect("failed to derive xpriv");
let fingerprint = xpriv.fingerprint(&self.secp);
let sk = xpriv.to_priv();
Ok((sk.public_key(SECP256K1).inner, (fingerprint, path)))
Ok((sk.public_key(&self.secp).inner, (fingerprint, path)))
}

/// Signs any ECDSA inputs for which we have keys.
pub fn sign_ecdsa(&self, psbt: Psbt, derivation_path: &str) -> anyhow::Result<Psbt> {
// Usually we'd have to check this was our input and provide the correct key.
let path = DerivationPath::from_str(derivation_path)?;
let xpriv = self.master.derive_priv(SECP256K1, &path)?;
let xpriv = self.master.derive_priv(&self.secp, &path)?;

let signer = Signer::new(psbt)?;
match signer.sign(&xpriv, SECP256K1) {
match signer.sign(&xpriv, &self.secp) {
Ok((psbt, _signing_keys)) => Ok(psbt),
Err(e) => panic!("signing failed: {:?}", e),
}
Expand Down
2 changes: 1 addition & 1 deletion rbmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Examples to run with specific features enabled.
# Format: "example_name:feature1 feature2"
examples = [
"v0:std",
"v0:std rand",
"v2:std",
"v2-separate-creator-constructor:std",
]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern crate alloc;

#[cfg(feature = "serde")]
#[macro_use]
extern crate actual_serde as serde;
extern crate serde;

/// Re-export of the `rust-bitcoin` crate.
pub extern crate bitcoin;
Expand Down
3 changes: 0 additions & 3 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::serialize::{Deserialize, Serialize};
/// - `<keypair> := <key> <value>`
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Pair {
/// The key of this key-value pair.
pub key: Key,
Expand Down Expand Up @@ -76,7 +75,6 @@ impl Deserialize for Pair {
/// deserializing.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Key {
/// The `keytype` of this PSBT map key (`keytype`).
pub type_value: u8,
Expand Down Expand Up @@ -138,7 +136,6 @@ pub type ProprietaryType = u8;
/// structure according to BIP 174.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct ProprietaryKey<Subtype = ProprietaryType>
where
Subtype: Copy + From<u8> + Into<u8>,
Expand Down
2 changes: 0 additions & 2 deletions src/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ pub mod btreemap_as_seq_byte_values {

/// A custom key-value pair type that serialized the bytes as hex.
#[derive(Debug, Deserialize)]
#[serde(crate = "actual_serde")]
struct OwnedPair<T>(
T,
#[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")] Vec<u8>,
);

/// A custom key-value pair type that serialized the bytes as hex.
#[derive(Debug, Serialize)]
#[serde(crate = "actual_serde")]
struct BorrowedPair<'a, T: 'static>(
&'a T,
#[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")] &'a [u8],
Expand Down
1 change: 0 additions & 1 deletion src/sighash_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::prelude::*;
/// for converting to/from [`PsbtSighashType`] from/to the desired signature hash type they need.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct PsbtSighashType {
pub(crate) inner: u32,
}
Expand Down
1 change: 0 additions & 1 deletion src/v0/bitcoin/map/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC;
/// transaction.
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Input {
/// The non-witness transaction this input spends from. Should only be
/// `Option::Some` for inputs which spend non-segwit outputs or
Expand Down
1 change: 0 additions & 1 deletion src/v0/bitcoin/map/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC;
/// transaction.
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Output {
/// The redeem script for this output.
pub redeem_script: Option<ScriptBuf>,
Expand Down
1 change: 0 additions & 1 deletion src/v0/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub use self::{
/// A Partially Signed Transaction.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Psbt {
/// The unsigned transaction, scriptSigs and witnesses for each input must be empty.
pub unsigned_tx: Transaction,
Expand Down
3 changes: 0 additions & 3 deletions src/v0/bitcoin/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::v0::bitcoin::Error;
/// A PSBT key in its raw byte form.
#[derive(Debug, PartialEq, Hash, Eq, Clone, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Key {
/// The type of this PSBT key.
pub type_value: u8,
Expand All @@ -35,7 +34,6 @@ pub struct Key {
/// `<keypair> := <key> <value>`
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Pair {
/// The key of this key-value pair.
pub key: Key,
Expand All @@ -52,7 +50,6 @@ pub type ProprietaryType = u8;
/// structure according to BIP 174.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct ProprietaryKey<Subtype = ProprietaryType>
where
Subtype: Copy + From<u8> + Into<u8>,
Expand Down
4 changes: 1 addition & 3 deletions src/v0/miniscript/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use core::mem;

use bitcoin::hashes::hash160;
use bitcoin::key::XOnlyPublicKey;
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;
use bitcoin::secp256k1::{Secp256k1};
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::sighash::Prevouts;
use bitcoin::taproot::LeafVersion;
use bitcoin::{PublicKey, Script, ScriptBuf, TxOut, Witness};
Expand Down
Loading