+// Advance the blinded onion message path by one hop, so make the second hop into the new
+// introduction node.
+pub(crate) fn advance_path_by_one<NS: Deref, NL: Deref, T>(
+ path: &mut BlindedPath, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
+) -> Result<(), ()>
+where
+ NS::Target: NodeSigner,
+ NL::Target: NodeIdLookUp,
+ T: secp256k1::Signing + secp256k1::Verification,
+{
+ let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &path.blinding_point, None)?;
+ let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
+ let encrypted_control_tlvs = path.blinded_hops.remove(0).encrypted_payload;
+ let mut s = Cursor::new(&encrypted_control_tlvs);
+ let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
+ match ChaChaPolyReadAdapter::read(&mut reader, rho) {
+ Ok(ChaChaPolyReadAdapter {
+ readable: ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override })
+ }) => {
+ let next_node_id = match next_hop {
+ NextMessageHop::NodeId(pubkey) => pubkey,
+ NextMessageHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
+ Some(pubkey) => pubkey,
+ None => return Err(()),
+ },
+ };
+ let mut new_blinding_point = match next_blinding_override {
+ Some(blinding_point) => blinding_point,
+ None => {
+ onion_utils::next_hop_pubkey(secp_ctx, path.blinding_point,
+ control_tlvs_ss.as_ref()).map_err(|_| ())?
+ }
+ };
+ mem::swap(&mut path.blinding_point, &mut new_blinding_point);
+ path.introduction_node = IntroductionNode::NodeId(next_node_id);
+ Ok(())
+ },
+ _ => Err(())
+ }