Skip to content

Commit e648ebc

Browse files
committed
Remove secp256k1 dependency.
1 parent 4594c1e commit e648ebc

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

lightning-invoice/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ std = ["bech32/std"]
2222
[dependencies]
2323
bech32 = { version = "0.9.1", default-features = false }
2424
lightning-types = { version = "0.1", path = "../lightning-types", default-features = false }
25-
secp256k1 = { version = "0.29.0", default-features = false, features = ["recovery", "alloc"] }
2625
serde = { version = "1.0.118", optional = true }
27-
bitcoin = { version = "0.32.2", default-features = false }
26+
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
2827

2928
[dev-dependencies]
3029
serde_json = { version = "1"}

lightning-invoice/src/de.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::prelude::*;
1717
use lightning_types::payment::PaymentSecret;
1818
use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop};
1919

20-
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
21-
use secp256k1::PublicKey;
20+
use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
21+
use bitcoin::secp256k1::PublicKey;
2222

2323
use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, Bolt11InvoiceSignature, PositiveTimestamp,
2424
Bolt11SemanticError, PrivateRoute, Bolt11ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawBolt11Invoice,
@@ -698,7 +698,7 @@ macro_rules! from_error {
698698
}
699699
}
700700

701-
from_error!(Bolt11ParseError::MalformedSignature, secp256k1::Error);
701+
from_error!(Bolt11ParseError::MalformedSignature, bitcoin::secp256k1::Error);
702702
from_error!(Bolt11ParseError::ParseAmountError, ParseIntError);
703703
from_error!(Bolt11ParseError::DescriptionDecodeError, str::Utf8Error);
704704

@@ -726,7 +726,7 @@ impl From<crate::Bolt11SemanticError> for ParseOrSemanticError {
726726
#[cfg(test)]
727727
mod test {
728728
use crate::de::Bolt11ParseError;
729-
use secp256k1::PublicKey;
729+
use bitcoin::secp256k1::PublicKey;
730730
use bech32::u5;
731731
use bitcoin::hashes::sha256;
732732
use std::str::FromStr;
@@ -973,7 +973,7 @@ mod test {
973973
#[test]
974974
fn test_payment_secret_and_features_de_and_ser() {
975975
use lightning_types::features::Bolt11InvoiceFeatures;
976-
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
976+
use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
977977
use crate::TaggedField::*;
978978
use crate::{SiPrefix, SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart,
979979
Currency, Sha256, PositiveTimestamp};
@@ -1020,7 +1020,7 @@ mod test {
10201020
#[test]
10211021
fn test_raw_signed_invoice_deserialization() {
10221022
use crate::TaggedField::*;
1023-
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
1023+
use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
10241024
use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
10251025
PositiveTimestamp};
10261026

lightning-invoice/src/lib.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ compile_error!("at least one of the `std` or `no-std` features must be enabled")
2727

2828
extern crate bech32;
2929
extern crate lightning_types;
30-
extern crate secp256k1;
3130
extern crate alloc;
3231
#[cfg(any(test, feature = "std"))]
3332
extern crate core;
@@ -42,9 +41,9 @@ use bitcoin::{Address, Network, PubkeyHash, ScriptHash, WitnessProgram, WitnessV
4241
use bitcoin::hashes::{Hash, sha256};
4342
use lightning_types::features::Bolt11InvoiceFeatures;
4443

45-
use secp256k1::PublicKey;
46-
use secp256k1::{Message, Secp256k1};
47-
use secp256k1::ecdsa::RecoverableSignature;
44+
use bitcoin::secp256k1::PublicKey;
45+
use bitcoin::secp256k1::{Message, Secp256k1};
46+
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
4847

4948
use core::cmp::Ordering;
5049
use core::fmt::{Display, Formatter, self};
@@ -84,7 +83,7 @@ use crate::prelude::*;
8483
pub enum Bolt11ParseError {
8584
Bech32Error(bech32::Error),
8685
ParseAmountError(ParseIntError),
87-
MalformedSignature(secp256k1::Error),
86+
MalformedSignature(bitcoin::secp256k1::Error),
8887
BadPrefix,
8988
UnknownCurrency,
9089
UnknownSiPrefix,
@@ -141,15 +140,14 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
141140
/// ensures that only a semantically and syntactically correct invoice can be built using it.
142141
///
143142
/// ```
144-
/// extern crate secp256k1;
145143
/// extern crate lightning_invoice;
146144
/// extern crate bitcoin;
147145
///
148146
/// use bitcoin::hashes::Hash;
149147
/// use bitcoin::hashes::sha256;
150148
///
151-
/// use secp256k1::Secp256k1;
152-
/// use secp256k1::SecretKey;
149+
/// use bitcoin::secp256k1::Secp256k1;
150+
/// use bitcoin::secp256k1::SecretKey;
153151
///
154152
/// use lightning_types::payment::PaymentSecret;
155153
///
@@ -866,7 +864,7 @@ impl SignedRawBolt11Invoice {
866864
}
867865

868866
/// Recovers the public key used for signing the invoice from the recoverable signature.
869-
pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, secp256k1::Error> {
867+
pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, bitcoin::secp256k1::Error> {
870868
let hash = Message::from_digest(self.hash);
871869

872870
Ok(PayeePubKey(Secp256k1::new().recover_ecdsa(
@@ -1248,9 +1246,9 @@ impl Bolt11Invoice {
12481246
/// Check that the invoice is signed correctly and that key recovery works
12491247
pub fn check_signature(&self) -> Result<(), Bolt11SemanticError> {
12501248
match self.signed_invoice.recover_payee_pub_key() {
1251-
Err(secp256k1::Error::InvalidRecoveryId) =>
1249+
Err(bitcoin::secp256k1::Error::InvalidRecoveryId) =>
12521250
return Err(Bolt11SemanticError::InvalidRecoveryId),
1253-
Err(secp256k1::Error::InvalidSignature) =>
1251+
Err(bitcoin::secp256k1::Error::InvalidSignature) =>
12541252
return Err(Bolt11SemanticError::InvalidSignature),
12551253
Err(e) => panic!("no other error may occur, got {:?}", e),
12561254
Ok(_) => {},
@@ -1811,9 +1809,9 @@ mod test {
18111809
#[test]
18121810
fn test_check_signature() {
18131811
use crate::TaggedField::*;
1814-
use secp256k1::Secp256k1;
1815-
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
1816-
use secp256k1::{SecretKey, PublicKey};
1812+
use bitcoin::secp256k1::Secp256k1;
1813+
use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
1814+
use bitcoin::secp256k1::{SecretKey, PublicKey};
18171815
use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
18181816
PositiveTimestamp};
18191817

@@ -1881,8 +1879,8 @@ mod test {
18811879
fn test_check_feature_bits() {
18821880
use crate::TaggedField::*;
18831881
use lightning_types::features::Bolt11InvoiceFeatures;
1884-
use secp256k1::Secp256k1;
1885-
use secp256k1::SecretKey;
1882+
use bitcoin::secp256k1::Secp256k1;
1883+
use bitcoin::secp256k1::SecretKey;
18861884
use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
18871885
Bolt11SemanticError};
18881886

@@ -2003,7 +2001,7 @@ mod test {
20032001
use crate::*;
20042002
use lightning_types::routing::RouteHintHop;
20052003
use std::iter::FromIterator;
2006-
use secp256k1::PublicKey;
2004+
use bitcoin::secp256k1::PublicKey;
20072005

20082006
let builder = InvoiceBuilder::new(Currency::Bitcoin)
20092007
.payment_hash(sha256::Hash::from_slice(&[0;32][..]).unwrap())
@@ -2056,8 +2054,8 @@ mod test {
20562054
fn test_builder_ok() {
20572055
use crate::*;
20582056
use lightning_types::routing::RouteHintHop;
2059-
use secp256k1::Secp256k1;
2060-
use secp256k1::{SecretKey, PublicKey};
2057+
use bitcoin::secp256k1::Secp256k1;
2058+
use bitcoin::secp256k1::{SecretKey, PublicKey};
20612059
use std::time::Duration;
20622060

20632061
let secp_ctx = Secp256k1::new();
@@ -2177,8 +2175,8 @@ mod test {
21772175
#[test]
21782176
fn test_default_values() {
21792177
use crate::*;
2180-
use secp256k1::Secp256k1;
2181-
use secp256k1::SecretKey;
2178+
use bitcoin::secp256k1::Secp256k1;
2179+
use bitcoin::secp256k1::SecretKey;
21822180

21832181
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
21842182
.description("Test".into())
@@ -2203,8 +2201,8 @@ mod test {
22032201
#[test]
22042202
fn test_expiration() {
22052203
use crate::*;
2206-
use secp256k1::Secp256k1;
2207-
use secp256k1::SecretKey;
2204+
use bitcoin::secp256k1::Secp256k1;
2205+
use bitcoin::secp256k1::SecretKey;
22082206

22092207
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
22102208
.description("Test".into())

lightning-invoice/src/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl ToBase32 for PayeePubKey {
297297

298298
impl Base32Len for PayeePubKey {
299299
fn base32_len(&self) -> usize {
300-
bytes_size_to_base32_size(secp256k1::constants::PUBLIC_KEY_SIZE)
300+
bytes_size_to_base32_size(bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE)
301301
}
302302
}
303303

lightning-invoice/tests/ser_de.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
extern crate bech32;
22
extern crate lightning_invoice;
3-
extern crate secp256k1;
43

54
use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion};
65
use bitcoin::hex::FromHex;
76
use bitcoin::hashes::{sha256, Hash};
87
use lightning_invoice::*;
9-
use secp256k1::PublicKey;
10-
use secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
8+
use bitcoin::secp256k1::PublicKey;
9+
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
1110
use std::collections::HashSet;
1211
use std::time::Duration;
1312
use std::str::FromStr;

0 commit comments

Comments
 (0)