Skip to content

Commit 6d1fd49

Browse files
authored
Merge pull request #32 from jamesdorfman/rust-bitcoin-0.29.2
update rust-bitcoin to v0.29.2
2 parents 53d60ef + 16c7a1d commit 6d1fd49

File tree

16 files changed

+554
-334
lines changed

16 files changed

+554
-334
lines changed

Cargo.lock

Lines changed: 428 additions & 196 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ serde_json = "1.0.34"
3131
serde_yaml = "0.8.8"
3232
hex = "0.3.2"
3333

34-
bitcoin = { version = "0.27.0", features = [ "use-serde" ] }
35-
secp256k1 = { version = "0.20.3", features = [ "recovery" ] }
34+
bitcoin = { version = "0.29.2", features = [ "serde" ] }
35+
secp256k1 = { version = "0.24.3", features = [ "recovery" ] }
3636
bip39 = { version = "1.0.1", features = [ "all-languages" ] }
3737
lightning-invoice = "0.4.0"
38-
miniscript = { version = "6.0.1", features = ["compiler"] }
38+
miniscript = { version = "9.0.0", features = ["compiler"] }
3939

4040
# For external commands
4141
jobserver = "0.1.11"

src/address.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitcoin::{Address, Network, PublicKey, Script, PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash};
1+
use bitcoin::{self, Address, Network, Script, PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash};
22
use serde::{Deserialize, Serialize};
33

44
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
@@ -36,7 +36,7 @@ pub struct Addresses {
3636
}
3737

3838
impl Addresses {
39-
pub fn from_pubkey(pubkey: &PublicKey, network: Network) -> Addresses {
39+
pub fn from_pubkey(pubkey: &bitcoin::PublicKey, network: Network) -> Addresses {
4040
Addresses {
4141
p2pkh: Some(Address::p2pkh(pubkey, network)),
4242
p2wpkh: Address::p2wpkh(pubkey, network).ok(),
@@ -47,7 +47,7 @@ impl Addresses {
4747

4848
pub fn from_script(script: &Script, network: Network) -> Addresses {
4949
Addresses {
50-
p2sh: Some(Address::p2sh(&script, network)),
50+
p2sh: Address::p2sh(&script, network).ok(),
5151
p2wsh: Some(Address::p2wsh(&script, network)),
5252
p2shwsh: Some(Address::p2shwsh(&script, network)),
5353
..Default::default()

src/bin/hal/cmd/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
8585
version,
8686
program,
8787
} => {
88-
let version = version.to_u8() as usize;
88+
let version = version.to_num() as usize;
8989
info.witness_program_version = Some(version);
9090

9191
if version == 0 {
9292
if program.len() == 20 {
9393
info.type_ = Some("p2wpkh".to_owned());
94-
info.witness_pubkey_hash =
94+
info.witness_pubkey_hash =
9595
Some(WPubkeyHash::from_slice(&program).expect("size 20"));
9696
} else if program.len() == 32 {
9797
info.type_ = Some("p2wsh".to_owned());

src/bin/hal/cmd/bip32.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn exec_derive<'a>(matches: &clap::ArgMatches<'a>) {
4040
Ok(ext_priv) => {
4141
derived_xpriv = Some(ext_priv.derive_priv(&secp, &path).expect("derivation error"));
4242
master_fingerprint = ext_priv.fingerprint(&secp);
43-
bip32::ExtendedPubKey::from_private(&secp, derived_xpriv.as_ref().unwrap())
43+
bip32::ExtendedPubKey::from_priv(&secp, derived_xpriv.as_ref().unwrap())
4444
}
4545
Err(_) => {
4646
let ext_pub: bip32::ExtendedPubKey = key_str.parse().expect("invalid extended key");
@@ -61,7 +61,7 @@ fn exec_derive<'a>(matches: &clap::ArgMatches<'a>) {
6161
public_key: derived_xpub.public_key,
6262
private_key: derived_xpriv.map(|x| x.private_key),
6363
addresses: hal::address::Addresses::from_pubkey(
64-
&derived_xpub.public_key, derived_xpub.network,
64+
&bitcoin::PublicKey::new(derived_xpub.public_key), derived_xpub.network,
6565
),
6666
};
6767

@@ -84,7 +84,7 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
8484
let xpub = match bip32::ExtendedPrivKey::from_str(&key_str) {
8585
Ok(ext_priv) => {
8686
xpriv = Some(ext_priv);
87-
bip32::ExtendedPubKey::from_private(&secp, xpriv.as_ref().unwrap())
87+
bip32::ExtendedPubKey::from_priv(&secp, xpriv.as_ref().unwrap())
8888
}
8989
Err(_) => key_str.parse().expect("invalid extended key"),
9090
};
@@ -101,7 +101,7 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
101101
public_key: xpub.public_key,
102102
private_key: xpriv.map(|x| x.private_key),
103103
addresses: hal::address::Addresses::from_pubkey(
104-
&xpub.public_key, xpub.network,
104+
&bitcoin::PublicKey::new(xpub.public_key), xpub.network,
105105
),
106106
};
107107

src/bin/hal/cmd/key.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn exec_generate<'a>(matches: &clap::ArgMatches<'a>) {
4444
let privkey = bitcoin::PrivateKey {
4545
compressed: true,
4646
network: network,
47-
key: secret_key,
47+
inner: secret_key,
4848
};
4949
let pubkey = privkey.public_key(&secp);
5050

@@ -76,7 +76,7 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
7676
let pubkey = privkey.public_key(&secp256k1::Secp256k1::new());
7777

7878
hal::key::KeyInfo {
79-
raw_private_key: (&privkey.key[..]).into(),
79+
raw_private_key: (&privkey.inner[..]).into(),
8080
wif_private_key: Some(privkey),
8181
public_key: pubkey,
8282
uncompressed_public_key: {
@@ -90,7 +90,7 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
9090
let pubkey = secp256k1::PublicKey::from_secret_key(&secp256k1::Secp256k1::new(), &sk);
9191
let btc_pubkey = PublicKey {
9292
compressed: true,
93-
key: pubkey.clone(),
93+
inner: pubkey.clone(),
9494
};
9595
let network = cmd::network(matches);
9696
hal::key::KeyInfo {
@@ -99,7 +99,7 @@ fn exec_inspect<'a>(matches: &clap::ArgMatches<'a>) {
9999
public_key: btc_pubkey,
100100
uncompressed_public_key: PublicKey {
101101
compressed: false,
102-
key: pubkey,
102+
inner: pubkey,
103103
},
104104
addresses: hal::address::Addresses::from_pubkey(&btc_pubkey, network),
105105
}
@@ -132,12 +132,12 @@ fn exec_sign<'a>(matches: &clap::ArgMatches<'a>) {
132132
if let Ok(sk) = secp256k1::SecretKey::from_str(&pk) {
133133
sk
134134
} else {
135-
bitcoin::PrivateKey::from_wif(&pk).expect("invalid private key provided").key
135+
bitcoin::PrivateKey::from_wif(&pk).expect("invalid private key provided").inner
136136
}
137137
};
138138

139139
let secp = secp256k1::Secp256k1::signing_only();
140-
let signature = secp.sign(&msg, &privkey);
140+
let signature = secp.sign_ecdsa(&msg, &privkey);
141141

142142
let info = hal::key::SignatureInfo {
143143
der: signature.serialize_der().as_ref().into(),
@@ -147,14 +147,14 @@ fn exec_sign<'a>(matches: &clap::ArgMatches<'a>) {
147147
}
148148

149149
fn cmd_verify<'a>() -> clap::App<'a, 'a> {
150-
cmd::subcommand("verify", "verify signatures\n\nNOTE!! For SHA-256-d hashes, the --reverse \
150+
cmd::subcommand("verify", "verify ecdsa signatures\n\nNOTE!! For SHA-256-d hashes, the --reverse \
151151
flag must be used because Bitcoin Core reverses the hex order for those!").args(&[
152152
cmd::opt_yaml(),
153153
cmd::opt("reverse", "reverse the message"),
154154
cmd::opt("no-try-reverse", "don't try to verify for reversed message"),
155155
cmd::arg("message", "the message to be signed in hex (must be 32 bytes)").required(true),
156156
cmd::arg("pubkey", "the public key in hex").required(true),
157-
cmd::arg("signature", "the signature in hex").required(true),
157+
cmd::arg("signature", "the ecdsa signature in hex").required(true),
158158
])
159159
}
160160

@@ -171,20 +171,20 @@ fn exec_verify<'a>(matches: &clap::ArgMatches<'a>) {
171171
let hex = matches.value_of("signature").expect("no signature provided");
172172
let bytes = hex::decode(&hex).expect("invalid signature: not hex");
173173
if bytes.len() == 64 {
174-
secp256k1::Signature::from_compact(&bytes).expect("invalid signature")
174+
secp256k1::ecdsa::Signature::from_compact(&bytes).expect("invalid signature")
175175
} else {
176-
secp256k1::Signature::from_der(&bytes).expect("invalid DER signature")
176+
secp256k1::ecdsa::Signature::from_der(&bytes).expect("invalid DER signature")
177177
}
178178
};
179179

180180
let secp = secp256k1::Secp256k1::verification_only();
181-
let valid = secp.verify(&msg, &sig, &pubkey.key).is_ok();
181+
let valid = secp.verify_ecdsa(&msg, &sig, &pubkey.inner).is_ok();
182182

183183
// Perhaps the user should have passed --reverse.
184184
if !valid && !matches.is_present("no-try-reverse") {
185185
msg_bytes.reverse();
186186
let msg = secp256k1::Message::from_slice(&msg_bytes[..]).expect("invalid message to be signed");
187-
if secp.verify(&msg, &sig, &pubkey.key).is_ok() {
187+
if secp.verify_ecdsa(&msg, &sig, &pubkey.inner).is_ok() {
188188
eprintln!("Signature is valid for the reverse message.");
189189
if matches.is_present("reverse") {
190190
eprintln!("Try dropping the --reverse");

src/bin/hal/cmd/message.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn exec_sign<'a>(matches: &clap::ArgMatches<'a>) {
6060

6161
let secp = secp256k1::Secp256k1::new();
6262
let signature =
63-
secp.sign_recoverable(&secp256k1::Message::from_slice(&hash).unwrap(), &privkey.key);
63+
secp.sign_ecdsa_recoverable(&secp256k1::Message::from_slice(&hash).unwrap(), &privkey.inner);
6464

6565
let (recid, raw) = signature.serialize_compact();
6666
let mut serialized = [0u8; 65];
@@ -115,19 +115,19 @@ fn exec_verify<'a>(matches: &clap::ArgMatches<'a>) {
115115
if sig_bytes.len() != 65 {
116116
panic!("Invalid signature: length is {} instead of 65 bytes", sig_bytes.len());
117117
}
118-
let recid = secp256k1::recovery::RecoveryId::from_i32(((sig_bytes[0] - 27) & 0x03) as i32)
118+
let recid = secp256k1::ecdsa::RecoveryId::from_i32(((sig_bytes[0] - 27) & 0x03) as i32)
119119
.expect("invalid recoverable signature (invalid recid)");
120120
let compressed = ((sig_bytes[0] - 27) & 0x04) != 0;
121-
let signature = secp256k1::recovery::RecoverableSignature::from_compact(&sig_bytes[1..], recid)
121+
let signature = secp256k1::ecdsa::RecoverableSignature::from_compact(&sig_bytes[1..], recid)
122122
.expect("invalid recoverable signature");
123123

124124
let msg = util::arg_or_stdin(matches, "message");
125125
let hash = bitcoin::util::misc::signed_msg_hash(&msg);
126126

127127
let secp = secp256k1::Secp256k1::verification_only();
128128
let pubkey = PublicKey {
129-
key: secp
130-
.recover(&secp256k1::Message::from_slice(&hash).unwrap(), &signature)
129+
inner: secp
130+
.recover_ecdsa(&secp256k1::Message::from_slice(&hash).unwrap(), &signature)
131131
.expect("invalid signature"),
132132
compressed: compressed,
133133
};
@@ -188,22 +188,22 @@ fn exec_recover<'a>(matches: &clap::ArgMatches<'a>) {
188188
if sig_bytes.len() != 65 {
189189
panic!("Invalid signature: length is {} instead of 65 bytes", sig_bytes.len());
190190
}
191-
let recid = secp256k1::recovery::RecoveryId::from_i32((sig_bytes[0] - 27 & 0x03) as i32)
191+
let recid = secp256k1::ecdsa::RecoveryId::from_i32((sig_bytes[0] - 27 & 0x03) as i32)
192192
.expect("invalid recoverable signature (invalid recid)");
193193
let compressed = sig_bytes[0] & 0x04 != 0x04;
194-
let signature = secp256k1::recovery::RecoverableSignature::from_compact(&sig_bytes[1..], recid)
194+
let signature = secp256k1::ecdsa::RecoverableSignature::from_compact(&sig_bytes[1..], recid)
195195
.expect("invalid recoverable signature");
196196

197197
let msg = matches.value_of("message").expect("no message given");
198198
let hash = bitcoin::util::misc::signed_msg_hash(&msg);
199199

200200
let secp = secp256k1::Secp256k1::verification_only();
201201
let pubkey = secp
202-
.recover(&secp256k1::Message::from_slice(&hash).unwrap(), &signature)
202+
.recover_ecdsa(&secp256k1::Message::from_slice(&hash).unwrap(), &signature)
203203
.expect("invalid signature");
204204

205205
let bitcoin_key = PublicKey {
206-
key: pubkey,
206+
inner: pubkey,
207207
compressed: compressed,
208208
};
209209
let info = hal::GetInfo::get_info(&bitcoin_key, cmd::network(matches));

src/bin/hal/cmd/miniscript.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use clap;
44
use hal::miniscript::{
55
DescriptorInfo, MiniscriptInfo, MiniscriptKeyType, Miniscripts, PolicyInfo, ScriptContexts,
66
};
7-
use miniscript::descriptor::Descriptor;
87
use miniscript::miniscript::{BareCtx, Legacy, Miniscript, Segwitv0};
98
use miniscript::policy::Liftable;
10-
use miniscript::{policy, DescriptorTrait, MiniscriptKey};
9+
use miniscript::{Descriptor, policy, MiniscriptKey};
1110

1211
use cmd;
1312
use util;
@@ -49,7 +48,7 @@ fn exec_descriptor<'a>(matches: &clap::ArgMatches<'a>) {
4948
address: desc.address(network).map(|a| a.to_string()).ok(),
5049
script_pubkey: Some(desc.script_pubkey().into_bytes().into()),
5150
unsigned_script_sig: Some(desc.unsigned_script_sig().into_bytes().into()),
52-
witness_script: Some(desc.explicit_script().into_bytes().into()),
51+
witness_script: desc.explicit_script().map(|s| s.into_bytes().into()).ok(),
5352
max_satisfaction_weight: desc.max_satisfaction_weight().ok(),
5453
policy: policy::Liftable::lift(&desc).map(|pol| pol.to_string()).ok(),
5554
})
@@ -177,9 +176,15 @@ fn get_policy_info<Pk: MiniscriptKey>(
177176
) -> Result<PolicyInfo, miniscript::Error>
178177
where
179178
Pk: std::str::FromStr,
180-
Pk::Hash: std::str::FromStr,
181-
<<Pk as miniscript::MiniscriptKey>::Hash as ::std::str::FromStr>::Err: ::std::fmt::Display,
182-
<Pk as ::std::str::FromStr>::Err: ::std::fmt::Display,
179+
<Pk as std::str::FromStr>::Err: std::fmt::Display,
180+
<Pk as MiniscriptKey>::Sha256: std::str::FromStr,
181+
<Pk as MiniscriptKey>::Hash256: std::str::FromStr,
182+
<Pk as MiniscriptKey>::Ripemd160: std::str::FromStr,
183+
<Pk as MiniscriptKey>::Hash160: std::str::FromStr,
184+
<<Pk as MiniscriptKey>::Sha256 as std::str::FromStr>::Err: std::fmt::Display,
185+
<<Pk as MiniscriptKey>::Hash256 as std::str::FromStr>::Err: std::fmt::Display,
186+
<<Pk as MiniscriptKey>::Ripemd160 as std::str::FromStr>::Err: std::fmt::Display,
187+
<<Pk as MiniscriptKey>::Hash160 as std::str::FromStr>::Err: std::fmt::Display,
183188
{
184189
let concrete_pol: Option<policy::Concrete<Pk>> = policy_str.parse().ok();
185190
let policy = match concrete_pol {
@@ -193,7 +198,7 @@ where
193198
is_unsatisfiable: policy.is_unsatisfiable(),
194199
relative_timelocks: policy.relative_timelocks(),
195200
n_keys: policy.n_keys(),
196-
minimum_n_keys: policy.minimum_n_keys(),
201+
minimum_n_keys: policy.minimum_n_keys().ok_or(miniscript::Error::CouldNotSatisfy)?,
197202
sorted: policy.clone().sorted().to_string(),
198203
normalized: policy.clone().normalized().to_string(),
199204
miniscript: concrete_pol.map(|p| Miniscripts {

0 commit comments

Comments
 (0)