@@ -1337,37 +1337,18 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
1337
1337
features, signing_pubkey,
1338
1338
} ;
1339
1339
1340
- match ( offer_tlv_stream. node_id , & offer_tlv_stream. paths ) {
1341
- ( Some ( expected_signing_pubkey) , _) => {
1342
- if fields. signing_pubkey != expected_signing_pubkey {
1343
- return Err ( Bolt12SemanticError :: InvalidSigningPubkey ) ;
1344
- }
1345
-
1346
- let invoice_request = InvoiceRequestContents :: try_from (
1347
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1348
- ) ?;
1349
- Ok ( InvoiceContents :: ForOffer { invoice_request, fields } )
1350
- } ,
1351
- ( None , Some ( paths) ) => {
1352
- if !paths
1353
- . iter ( )
1354
- . filter_map ( |path| path. blinded_hops . last ( ) )
1355
- . any ( |last_hop| fields. signing_pubkey == last_hop. blinded_node_id )
1356
- {
1357
- return Err ( Bolt12SemanticError :: InvalidSigningPubkey ) ;
1358
- }
1359
-
1360
- let invoice_request = InvoiceRequestContents :: try_from (
1361
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1362
- ) ?;
1363
- Ok ( InvoiceContents :: ForOffer { invoice_request, fields } )
1364
- } ,
1365
- ( None , None ) => {
1366
- let refund = RefundContents :: try_from (
1367
- ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1368
- ) ?;
1369
- Ok ( InvoiceContents :: ForRefund { refund, fields } )
1370
- } ,
1340
+ check_invoice_signing_pubkey ( & fields. signing_pubkey , & offer_tlv_stream) ?;
1341
+
1342
+ if offer_tlv_stream. node_id . is_none ( ) && offer_tlv_stream. paths . is_none ( ) {
1343
+ let refund = RefundContents :: try_from (
1344
+ ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1345
+ ) ?;
1346
+ Ok ( InvoiceContents :: ForRefund { refund, fields } )
1347
+ } else {
1348
+ let invoice_request = InvoiceRequestContents :: try_from (
1349
+ ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
1350
+ ) ?;
1351
+ Ok ( InvoiceContents :: ForOffer { invoice_request, fields } )
1371
1352
}
1372
1353
}
1373
1354
}
@@ -1388,6 +1369,29 @@ pub(super) fn construct_payment_paths(
1388
1369
}
1389
1370
}
1390
1371
1372
+ pub ( super ) fn check_invoice_signing_pubkey (
1373
+ invoice_signing_pubkey : & PublicKey , offer_tlv_stream : & OfferTlvStream
1374
+ ) -> Result < ( ) , Bolt12SemanticError > {
1375
+ match ( & offer_tlv_stream. node_id , & offer_tlv_stream. paths ) {
1376
+ ( Some ( expected_signing_pubkey) , _) => {
1377
+ if invoice_signing_pubkey != expected_signing_pubkey {
1378
+ return Err ( Bolt12SemanticError :: InvalidSigningPubkey ) ;
1379
+ }
1380
+ } ,
1381
+ ( None , Some ( paths) ) => {
1382
+ if !paths
1383
+ . iter ( )
1384
+ . filter_map ( |path| path. blinded_hops . last ( ) )
1385
+ . any ( |last_hop| invoice_signing_pubkey == & last_hop. blinded_node_id )
1386
+ {
1387
+ return Err ( Bolt12SemanticError :: InvalidSigningPubkey ) ;
1388
+ }
1389
+ } ,
1390
+ _ => { } ,
1391
+ }
1392
+ Ok ( ( ) )
1393
+ }
1394
+
1391
1395
#[ cfg( test) ]
1392
1396
mod tests {
1393
1397
use super :: { Bolt12Invoice , DEFAULT_RELATIVE_EXPIRY , FallbackAddress , FullInvoiceTlvStreamRef , InvoiceTlvStreamRef , SIGNATURE_TAG , UnsignedBolt12Invoice } ;
0 commit comments