@@ -15,8 +15,9 @@ pub(crate) mod utils;
15
15
16
16
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
17
17
18
- use crate :: sign:: EntropySource ;
19
18
use crate :: ln:: msgs:: DecodeError ;
19
+ use crate :: offers:: invoice:: BlindedPayInfo ;
20
+ use crate :: sign:: EntropySource ;
20
21
use crate :: util:: ser:: { Readable , Writeable , Writer } ;
21
22
22
23
use crate :: io;
@@ -75,25 +76,31 @@ impl BlindedPath {
75
76
} )
76
77
}
77
78
78
- /// Create a blinded path for a payment, to be forwarded along `path`. The last node
79
- /// in `path` will be the destination node.
79
+ /// Create a blinded path for a payment, to be forwarded along `intermediate_nodes`.
80
+ ///
81
+ /// Errors if:
82
+ /// * a provided node id is invalid
83
+ /// * [`BlindedPayInfo`] calculation results in an integer overflow
84
+ /// * any unknown features are required in the provided [`ForwardTlvs`]
80
85
///
81
- /// Errors if `path` is empty or a node id in `path` is invalid.
86
+ /// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
82
87
// TODO: make all payloads the same size with padding + add dummy hops
83
88
pub fn new_for_payment < ES : EntropySource , T : secp256k1:: Signing + secp256k1:: Verification > (
84
- intermediate_nodes : & [ ( PublicKey , payment:: ForwardTlvs ) ] , payee_node_id : PublicKey ,
85
- payee_tlvs : payment:: ReceiveTlvs , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
86
- ) -> Result < Self , ( ) > {
89
+ intermediate_nodes : & [ payment:: ForwardNode ] , payee_node_id : PublicKey ,
90
+ payee_tlvs : payment:: ReceiveTlvs , htlc_maximum_msat : u64 , entropy_source : & ES ,
91
+ secp_ctx : & Secp256k1 < T >
92
+ ) -> Result < ( BlindedPayInfo , Self ) , ( ) > {
87
93
let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
88
94
let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
89
95
90
- Ok ( BlindedPath {
91
- introduction_node_id : intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. 0 ) ,
96
+ let blinded_payinfo = payment:: compute_payinfo ( intermediate_nodes, & payee_tlvs, htlc_maximum_msat) ?;
97
+ Ok ( ( blinded_payinfo, BlindedPath {
98
+ introduction_node_id : intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. node_id ) ,
92
99
blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
93
100
blinded_hops : payment:: blinded_hops (
94
101
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, & blinding_secret
95
102
) . map_err ( |_| ( ) ) ?,
96
- } )
103
+ } ) )
97
104
}
98
105
}
99
106
0 commit comments