Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Nov 28, 2024
2 parents dad9929 + 9817442 commit 94abb22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fiber-sphinx"
version = "1.0.1"
version = "2.0.0"
edition = "2021"
license-file = "COPYING.md"
description = "A Rust implementation of the Sphinx mix network."
Expand Down
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ impl OnionErrorPacket {
/// - `parse_payload`: A function to parse the error payload from the decrypted packet data. It should return `Some(T)` if
/// the given buffer starts with a valid error payload, otherwise `None`.
///
/// Returns the parsed error message and the erring node public key if the HMAC is valid and the error message is successfully
/// parsed by the function `parse_payload`.
/// Returns the parsed error message and the erring node index in `hops_path` if the HMAC is valid and the error message is
/// successfully parsed by the function `parse_payload`.
pub fn parse<F, T>(
self,
hops_path: Vec<PublicKey>,
session_key: SecretKey,
parse_payload: F,
) -> Option<(T, PublicKey)>
) -> Option<(T, usize)>
where
F: Fn(&[u8]) -> Option<T>,
{
Expand All @@ -340,17 +340,15 @@ impl OnionErrorPacket {

let secp_ctx = Secp256k1::new();
let mut packet = self;
for (public_key, shared_secret) in hops_path.iter().zip(OnionSharedSecretIter::new(
hops_path.iter(),
session_key,
&secp_ctx,
)) {
for (index, shared_secret) in
OnionSharedSecretIter::new(hops_path.iter(), session_key, &secp_ctx).enumerate()
{
let ReturnKeys { ammag, um } = ReturnKeys::new(&shared_secret);
packet = packet.xor_cipher_stream_with_ammag(ammag);
if let Some(error) = parse_payload(&packet.packet_data[32..]) {
let hmac = compute_hmac(&um, &packet.packet_data[32..], None);
if hmac == packet.packet_data[..32] {
return Some((error, public_key.clone()));
return Some((error, index));
}
}
}
Expand Down Expand Up @@ -1025,9 +1023,9 @@ mod tests {
parse_lightning_error_packet_data,
);
assert!(error.is_some());
let (error, public_key) = error.unwrap();
let (error, hops_index) = error.unwrap();
assert_eq!(error, vec![0x20, 0x02]);
assert_eq!(public_key, hops_path[0]);
assert_eq!(hops_index, 0);
}

{
Expand All @@ -1043,9 +1041,9 @@ mod tests {
parse_lightning_error_packet_data,
);
assert!(error.is_some());
let (error, public_key) = error.unwrap();
let (error, hops_index) = error.unwrap();
assert_eq!(error, vec![0x20, 0x02]);
assert_eq!(public_key, hops_path[4]);
assert_eq!(hops_index, 4);
}

{
Expand Down

0 comments on commit 94abb22

Please sign in to comment.