@@ -147,8 +147,7 @@ pub const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice", "signatu
147
147
pub struct InvoiceBuilder < ' a , S : SigningPubkeyStrategy > {
148
148
invreq_bytes : & ' a Vec < u8 > ,
149
149
invoice : InvoiceContents ,
150
- keys : Option < KeyPair > ,
151
- signing_pubkey_strategy : core:: marker:: PhantomData < S > ,
150
+ signing_pubkey_strategy : S ,
152
151
}
153
152
154
153
/// Indicates how [`Bolt12Invoice::signing_pubkey`] was set.
@@ -164,7 +163,7 @@ pub struct ExplicitSigningPubkey {}
164
163
/// [`Bolt12Invoice::signing_pubkey`] was derived.
165
164
///
166
165
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
167
- pub struct DerivedSigningPubkey { }
166
+ pub struct DerivedSigningPubkey ( KeyPair ) ;
168
167
169
168
impl SigningPubkeyStrategy for ExplicitSigningPubkey { }
170
169
impl SigningPubkeyStrategy for DerivedSigningPubkey { }
@@ -183,7 +182,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
183
182
) ,
184
183
} ;
185
184
186
- Self :: new ( & invoice_request. bytes , contents, None )
185
+ Self :: new ( & invoice_request. bytes , contents, ExplicitSigningPubkey { } )
187
186
}
188
187
189
188
pub ( super ) fn for_refund (
@@ -198,7 +197,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
198
197
) ,
199
198
} ;
200
199
201
- Self :: new ( & refund. bytes , contents, None )
200
+ Self :: new ( & refund. bytes , contents, ExplicitSigningPubkey { } )
202
201
}
203
202
}
204
203
@@ -216,7 +215,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
216
215
) ,
217
216
} ;
218
217
219
- Self :: new ( & invoice_request. bytes , contents, Some ( keys) )
218
+ Self :: new ( & invoice_request. bytes , contents, DerivedSigningPubkey ( keys) )
220
219
}
221
220
222
221
pub ( super ) fn for_refund_using_keys (
@@ -232,7 +231,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
232
231
) ,
233
232
} ;
234
233
235
- Self :: new ( & refund. bytes , contents, Some ( keys) )
234
+ Self :: new ( & refund. bytes , contents, DerivedSigningPubkey ( keys) )
236
235
}
237
236
}
238
237
@@ -262,18 +261,13 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
262
261
}
263
262
264
263
fn new (
265
- invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents , keys : Option < KeyPair >
264
+ invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents , signing_pubkey_strategy : S
266
265
) -> Result < Self , Bolt12SemanticError > {
267
266
if contents. fields ( ) . payment_paths . is_empty ( ) {
268
267
return Err ( Bolt12SemanticError :: MissingPaths ) ;
269
268
}
270
269
271
- Ok ( Self {
272
- invreq_bytes,
273
- invoice : contents,
274
- keys,
275
- signing_pubkey_strategy : core:: marker:: PhantomData ,
276
- } )
270
+ Ok ( Self { invreq_bytes, invoice : contents, signing_pubkey_strategy } )
277
271
}
278
272
279
273
/// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
@@ -359,10 +353,11 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
359
353
}
360
354
}
361
355
362
- let InvoiceBuilder { invreq_bytes, invoice, keys, .. } = self ;
356
+ let InvoiceBuilder {
357
+ invreq_bytes, invoice, signing_pubkey_strategy : DerivedSigningPubkey ( keys)
358
+ } = self ;
363
359
let unsigned_invoice = UnsignedBolt12Invoice :: new ( invreq_bytes, invoice) ;
364
360
365
- let keys = keys. unwrap ( ) ;
366
361
let invoice = unsigned_invoice
367
362
. sign :: < _ , Infallible > (
368
363
|message| Ok ( secp_ctx. sign_schnorr_no_aux_rand ( message. as_ref ( ) . as_digest ( ) , & keys) )
0 commit comments