Skip to content

Commit 3d3147f

Browse files
committed
Rename lightning_invoice::Signature to InvoiceSignature
This prevents aliasing the global secp256k1::Signature name in C bindings and also makes it a little more explicit that the object is different from other signature types.
1 parent 2363423 commit 3d3147f

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lightning-invoice/src/de.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl FromStr for SignedRawInvoice {
264264
hrp.as_bytes(),
265265
&data[..data.len()-104]
266266
),
267-
signature: Signature::from_base32(&data[data.len()-104..])?,
267+
signature: InvoiceSignature::from_base32(&data[data.len()-104..])?,
268268
})
269269
}
270270
}
@@ -338,17 +338,17 @@ impl FromBase32 for PositiveTimestamp {
338338
}
339339
}
340340

341-
impl FromBase32 for Signature {
341+
impl FromBase32 for InvoiceSignature {
342342
type Err = ParseError;
343343
fn from_base32(signature: &[u5]) -> Result<Self, Self::Err> {
344344
if signature.len() != 104 {
345-
return Err(ParseError::InvalidSliceLength("Signature::from_base32()".into()));
345+
return Err(ParseError::InvalidSliceLength("InvoiceSignature::from_base32()".into()));
346346
}
347347
let recoverable_signature_bytes = Vec::<u8>::from_base32(signature)?;
348348
let signature = &recoverable_signature_bytes[0..64];
349349
let recovery_id = RecoveryId::from_i32(recoverable_signature_bytes[64] as i32)?;
350350

351-
Ok(Signature(RecoverableSignature::from_compact(
351+
Ok(InvoiceSignature(RecoverableSignature::from_compact(
352352
signature,
353353
recovery_id
354354
)?))
@@ -999,7 +999,7 @@ mod test {
999999
use lightning::ln::features::InvoiceFeatures;
10001000
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
10011001
use TaggedField::*;
1002-
use {SiPrefix, SignedRawInvoice, Signature, RawInvoice, RawHrp, RawDataPart,
1002+
use {SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart,
10031003
Currency, Sha256, PositiveTimestamp};
10041004

10051005
// Feature bits 9, 15, and 99 are set.
@@ -1025,7 +1025,7 @@ mod test {
10251025
hash: [0xb1, 0x96, 0x46, 0xc3, 0xbc, 0x56, 0x76, 0x1d, 0x20, 0x65, 0x6e, 0x0e, 0x32,
10261026
0xec, 0xd2, 0x69, 0x27, 0xb7, 0x62, 0x6e, 0x2a, 0x8b, 0xe6, 0x97, 0x71, 0x9f,
10271027
0xf8, 0x7e, 0x44, 0x54, 0x55, 0xb9],
1028-
signature: Signature(RecoverableSignature::from_compact(
1028+
signature: InvoiceSignature(RecoverableSignature::from_compact(
10291029
&[0xd7, 0x90, 0x4c, 0xc4, 0xb7, 0x4a, 0x22, 0x26, 0x9c, 0x68, 0xc1, 0xdf, 0x68,
10301030
0xa9, 0x6c, 0x21, 0x4d, 0x65, 0x1b, 0x93, 0x76, 0xe9, 0xf1, 0x64, 0xd3, 0x60,
10311031
0x4d, 0xa4, 0xb7, 0xde, 0xcc, 0xce, 0x0e, 0x82, 0xaa, 0xab, 0x4c, 0x85, 0xd3,
@@ -1045,7 +1045,7 @@ mod test {
10451045
fn test_raw_signed_invoice_deserialization() {
10461046
use TaggedField::*;
10471047
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
1048-
use {SignedRawInvoice, Signature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
1048+
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
10491049
PositiveTimestamp};
10501050

10511051
assert_eq!(
@@ -1078,7 +1078,7 @@ mod test {
10781078
0x7b, 0x1d, 0x85, 0x8d, 0xb1, 0xd1, 0xf7, 0xab, 0x71, 0x37, 0xdc, 0xb7,
10791079
0x83, 0x5d, 0xb2, 0xec, 0xd5, 0x18, 0xe1, 0xc9
10801080
],
1081-
signature: Signature(RecoverableSignature::from_compact(
1081+
signature: InvoiceSignature(RecoverableSignature::from_compact(
10821082
& [
10831083
0x38u8, 0xec, 0x68, 0x91, 0x34, 0x5e, 0x20, 0x41, 0x45, 0xbe, 0x8a,
10841084
0x3a, 0x99, 0xde, 0x38, 0xe9, 0x8a, 0x39, 0xd6, 0xa5, 0x69, 0x43,

lightning-invoice/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub struct SignedRawInvoice {
207207
hash: [u8; 32],
208208

209209
/// signature of the payment request
210-
signature: Signature,
210+
signature: InvoiceSignature,
211211
}
212212

213213
/// Represents an syntactically correct Invoice for a payment on the lightning network,
@@ -381,7 +381,7 @@ pub enum Fallback {
381381

382382
/// Recoverable signature
383383
#[derive(Eq, PartialEq, Debug, Clone)]
384-
pub struct Signature(pub RecoverableSignature);
384+
pub struct InvoiceSignature(pub RecoverableSignature);
385385

386386
/// Private routing information
387387
///
@@ -630,7 +630,7 @@ impl SignedRawInvoice {
630630
/// 1. raw invoice
631631
/// 2. hash of the raw invoice
632632
/// 3. signature
633-
pub fn into_parts(self) -> (RawInvoice, [u8; 32], Signature) {
633+
pub fn into_parts(self) -> (RawInvoice, [u8; 32], InvoiceSignature) {
634634
(self.raw_invoice, self.hash, self.signature)
635635
}
636636

@@ -644,8 +644,8 @@ impl SignedRawInvoice {
644644
&self.hash
645645
}
646646

647-
/// Signature for the invoice.
648-
pub fn signature(&self) -> &Signature {
647+
/// InvoiceSignature for the invoice.
648+
pub fn signature(&self) -> &InvoiceSignature {
649649
&self.signature
650650
}
651651

@@ -771,7 +771,7 @@ impl RawInvoice {
771771
Ok(SignedRawInvoice {
772772
raw_invoice: self,
773773
hash: raw_hash,
774-
signature: Signature(signature),
774+
signature: InvoiceSignature(signature),
775775
})
776776
}
777777

@@ -1192,7 +1192,7 @@ impl Deref for RouteHint {
11921192
}
11931193
}
11941194

1195-
impl Deref for Signature {
1195+
impl Deref for InvoiceSignature {
11961196
type Target = RecoverableSignature;
11971197

11981198
fn deref(&self) -> &RecoverableSignature {
@@ -1354,7 +1354,7 @@ mod test {
13541354
use secp256k1::Secp256k1;
13551355
use secp256k1::recovery::{RecoveryId, RecoverableSignature};
13561356
use secp256k1::key::{SecretKey, PublicKey};
1357-
use {SignedRawInvoice, Signature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
1357+
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
13581358
PositiveTimestamp};
13591359

13601360
let invoice = SignedRawInvoice {
@@ -1383,7 +1383,7 @@ mod test {
13831383
0x7b, 0x1d, 0x85, 0x8d, 0xb1, 0xd1, 0xf7, 0xab, 0x71, 0x37, 0xdc, 0xb7,
13841384
0x83, 0x5d, 0xb2, 0xec, 0xd5, 0x18, 0xe1, 0xc9
13851385
],
1386-
signature: Signature(RecoverableSignature::from_compact(
1386+
signature: InvoiceSignature(RecoverableSignature::from_compact(
13871387
& [
13881388
0x38u8, 0xec, 0x68, 0x91, 0x34, 0x5e, 0x20, 0x41, 0x45, 0xbe, 0x8a,
13891389
0x3a, 0x99, 0xde, 0x38, 0xe9, 0x8a, 0x39, 0xd6, 0xa5, 0x69, 0x43,

lightning-invoice/src/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl ToBase32 for TaggedField {
461461
}
462462
}
463463

464-
impl ToBase32 for Signature {
464+
impl ToBase32 for InvoiceSignature {
465465
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
466466
let mut converter = BytesToBase32::new(writer);
467467
let (recovery_id, signature) = self.0.serialize_compact();

0 commit comments

Comments
 (0)