Skip to content

Commit cbfff99

Browse files
authored
Merge pull request #2229 from TheBlueMatt/2023-04-115-bindings-upstream-2
Trivial Bindings Updates
2 parents d4fc1a7 + 53c48c1 commit cbfff99

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

lightning-invoice/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ pub enum TaggedField {
455455
pub struct Sha256(/// This is not exported to bindings users as the native hash types are not currently mapped
456456
pub sha256::Hash);
457457

458+
impl Sha256 {
459+
/// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
460+
/// single sha256 hash.
461+
#[cfg(c_bindings)]
462+
pub fn from_bytes(bytes: &[u8; 32]) -> Self {
463+
Self(sha256::Hash::from_slice(bytes).expect("from_slice only fails if len is not 32"))
464+
}
465+
}
466+
458467
/// Description string
459468
///
460469
/// # Invariants

lightning/src/offers/invoice.rs

+12
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ pub(super) const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice", "
134134
///
135135
/// See [module-level documentation] for usage.
136136
///
137+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
138+
///
137139
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
138140
/// [`Refund`]: crate::offers::refund::Refund
139141
/// [module-level documentation]: self
@@ -145,12 +147,18 @@ pub struct InvoiceBuilder<'a, S: SigningPubkeyStrategy> {
145147
}
146148

147149
/// Indicates how [`Invoice::signing_pubkey`] was set.
150+
///
151+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
148152
pub trait SigningPubkeyStrategy {}
149153

150154
/// [`Invoice::signing_pubkey`] was explicitly set.
155+
///
156+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
151157
pub struct ExplicitSigningPubkey {}
152158

153159
/// [`Invoice::signing_pubkey`] was derived.
160+
///
161+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
154162
pub struct DerivedSigningPubkey {}
155163

156164
impl SigningPubkeyStrategy for ExplicitSigningPubkey {}
@@ -369,6 +377,8 @@ impl<'a> UnsignedInvoice<'a> {
369377
}
370378

371379
/// Signs the invoice using the given function.
380+
///
381+
/// This is not exported to bindings users as functions aren't currently mapped.
372382
pub fn sign<F, E>(self, sign: F) -> Result<Invoice, SignError<E>>
373383
where
374384
F: FnOnce(&Message) -> Result<Signature, E>
@@ -405,6 +415,8 @@ impl<'a> UnsignedInvoice<'a> {
405415
/// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
406416
/// directly after scanning a refund. It includes all the information needed to pay a recipient.
407417
///
418+
/// This is not exported to bindings users as its name conflicts with the BOLT 11 Invoice type.
419+
///
408420
/// [`Offer`]: crate::offers::offer::Offer
409421
/// [`Refund`]: crate::offers::refund::Refund
410422
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest

lightning/src/offers/invoice_request.rs

+18
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Invreq ~~~~~";
8484
///
8585
/// See [module-level documentation] for usage.
8686
///
87+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
88+
///
8789
/// [module-level documentation]: self
8890
pub struct InvoiceRequestBuilder<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> {
8991
offer: &'a Offer,
@@ -94,12 +96,18 @@ pub struct InvoiceRequestBuilder<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signi
9496
}
9597

9698
/// Indicates how [`InvoiceRequest::payer_id`] will be set.
99+
///
100+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
97101
pub trait PayerIdStrategy {}
98102

99103
/// [`InvoiceRequest::payer_id`] will be explicitly set.
104+
///
105+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
100106
pub struct ExplicitPayerId {}
101107

102108
/// [`InvoiceRequest::payer_id`] will be derived.
109+
///
110+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
103111
pub struct DerivedPayerId {}
104112

105113
impl PayerIdStrategy for ExplicitPayerId {}
@@ -340,6 +348,8 @@ pub struct UnsignedInvoiceRequest<'a> {
340348

341349
impl<'a> UnsignedInvoiceRequest<'a> {
342350
/// Signs the invoice request using the given function.
351+
///
352+
/// This is not exported to bindings users as functions are not yet mapped.
343353
pub fn sign<F, E>(self, sign: F) -> Result<InvoiceRequest, SignError<E>>
344354
where
345355
F: FnOnce(&Message) -> Result<Signature, E>
@@ -465,6 +475,8 @@ impl InvoiceRequest {
465475
/// See [`InvoiceRequest::respond_with_no_std`] for further details where the aforementioned
466476
/// creation time is used for the `created_at` parameter.
467477
///
478+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
479+
///
468480
/// [`Duration`]: core::time::Duration
469481
#[cfg(feature = "std")]
470482
pub fn respond_with(
@@ -493,6 +505,8 @@ impl InvoiceRequest {
493505
///
494506
/// Errors if the request contains unknown required features.
495507
///
508+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
509+
///
496510
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
497511
pub fn respond_with_no_std(
498512
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
@@ -511,6 +525,8 @@ impl InvoiceRequest {
511525
///
512526
/// See [`InvoiceRequest::respond_with`] for further details.
513527
///
528+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
529+
///
514530
/// [`Invoice`]: crate::offers::invoice::Invoice
515531
#[cfg(feature = "std")]
516532
pub fn verify_and_respond_using_derived_keys<T: secp256k1::Signing>(
@@ -532,6 +548,8 @@ impl InvoiceRequest {
532548
///
533549
/// See [`InvoiceRequest::respond_with_no_std`] for further details.
534550
///
551+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
552+
///
535553
/// [`Invoice`]: crate::offers::invoice::Invoice
536554
pub fn verify_and_respond_using_derived_keys_no_std<T: secp256k1::Signing>(
537555
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,

lightning/src/offers/offer.rs

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Offer ~~~~~~";
9898
///
9999
/// See [module-level documentation] for usage.
100100
///
101+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
102+
///
101103
/// [module-level documentation]: self
102104
pub struct OfferBuilder<'a, M: MetadataStrategy, T: secp256k1::Signing> {
103105
offer: OfferContents,
@@ -106,12 +108,18 @@ pub struct OfferBuilder<'a, M: MetadataStrategy, T: secp256k1::Signing> {
106108
}
107109

108110
/// Indicates how [`Offer::metadata`] may be set.
111+
///
112+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
109113
pub trait MetadataStrategy {}
110114

111115
/// [`Offer::metadata`] may be explicitly set or left empty.
116+
///
117+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
112118
pub struct ExplicitMetadata {}
113119

114120
/// [`Offer::metadata`] will be derived.
121+
///
122+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
115123
pub struct DerivedMetadata {}
116124

117125
impl MetadataStrategy for ExplicitMetadata {}
@@ -448,6 +456,8 @@ impl Offer {
448456
///
449457
/// Useful to protect the sender's privacy.
450458
///
459+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
460+
///
451461
/// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
452462
/// [`InvoiceRequest::metadata`]: crate::offers::invoice_request::InvoiceRequest::metadata
453463
/// [`Invoice::verify`]: crate::offers::invoice::Invoice::verify
@@ -470,6 +480,8 @@ impl Offer {
470480
///
471481
/// Useful for recurring payments using the same `payer_id` with different invoices.
472482
///
483+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
484+
///
473485
/// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
474486
pub fn request_invoice_deriving_metadata<ES: Deref>(
475487
&self, payer_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES
@@ -496,6 +508,8 @@ impl Offer {
496508
///
497509
/// Errors if the offer contains unknown required features.
498510
///
511+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
512+
///
499513
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
500514
pub fn request_invoice(
501515
&self, metadata: Vec<u8>, payer_id: PublicKey

lightning/src/offers/parse.rs

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ impl<T: SeekReadable> TryFrom<Vec<u8>> for ParsedMessage<T> {
116116
}
117117

118118
/// Error when parsing a bech32 encoded message using [`str::parse`].
119+
///
120+
/// This is not exported to bindings users as its name conflicts with the BOLT 11 ParseError type.
119121
#[derive(Debug, PartialEq)]
120122
pub enum ParseError {
121123
/// The bech32 encoding does not conform to the BOLT 12 requirements for continuing messages
@@ -135,6 +137,8 @@ pub enum ParseError {
135137
}
136138

137139
/// Error when interpreting a TLV stream as a specific type.
140+
///
141+
/// This is not exported to bindings users as its name conflicts with the BOLT 11 SemanticError type.
138142
#[derive(Debug, PartialEq)]
139143
pub enum SemanticError {
140144
/// The current [`std::time::SystemTime`] is past the offer or invoice's expiration.

lightning/src/offers/refund.rs

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Refund ~~~~~";
105105
///
106106
/// See [module-level documentation] for usage.
107107
///
108+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
109+
///
108110
/// [module-level documentation]: self
109111
pub struct RefundBuilder<'a, T: secp256k1::Signing> {
110112
refund: RefundContents,
@@ -387,6 +389,8 @@ impl Refund {
387389
/// See [`Refund::respond_with_no_std`] for further details where the aforementioned creation
388390
/// time is used for the `created_at` parameter.
389391
///
392+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
393+
///
390394
/// [`Duration`]: core::time::Duration
391395
#[cfg(feature = "std")]
392396
pub fn respond_with(
@@ -419,6 +423,8 @@ impl Refund {
419423
///
420424
/// Errors if the request contains unknown required features.
421425
///
426+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
427+
///
422428
/// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
423429
pub fn respond_with_no_std(
424430
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
@@ -436,6 +442,8 @@ impl Refund {
436442
///
437443
/// See [`Refund::respond_with`] for further details.
438444
///
445+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
446+
///
439447
/// [`Invoice`]: crate::offers::invoice::Invoice
440448
#[cfg(feature = "std")]
441449
pub fn respond_using_derived_keys<ES: Deref>(
@@ -459,6 +467,8 @@ impl Refund {
459467
///
460468
/// See [`Refund::respond_with_no_std`] for further details.
461469
///
470+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
471+
///
462472
/// [`Invoice`]: crate::offers::invoice::Invoice
463473
pub fn respond_using_derived_keys_no_std<ES: Deref>(
464474
&self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,

0 commit comments

Comments
 (0)