pub struct OnionErrorPacket {
pub packet_data: Vec<u8>,
}Expand description
Onion error packet to return errors to the origin node.
The nodes must store the shared secrets to forward OnionPacket locally and reuse them to obfuscate
the error packet. See the section “Returning Errors” in the specification for details.
§Example
use secp256k1::{PublicKey, SecretKey, Secp256k1};
use std::str::FromStr;
use fiber_sphinx::{OnionErrorPacket, OnionPacket, OnionSharedSecretIter};
let secp = Secp256k1::new();
let hops_path = vec![
PublicKey::from_str("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").expect("valid public key"),
PublicKey::from_str("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").expect("valid public key"),
PublicKey::from_str("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").expect("valid public key"),
];
let session_key = SecretKey::from_slice(&[0x41; 32]).expect("32 bytes, within curve order");
let hops_ss = OnionSharedSecretIter::new(hops_path.iter(), session_key, &secp).collect::<Vec<_>>();
// The node 0324653...0ab1c generates the error
let shared_secret = hops_ss[1];
let error_packet = OnionErrorPacket::create(&shared_secret, b"error message".to_vec());Fields§
§packet_data: Vec<u8>Encrypted error-returning packet data.
Implementations§
Source§impl OnionErrorPacket
impl OnionErrorPacket
Sourcepub fn create(shared_secret: &[u8; 32], payload: Vec<u8>) -> Self
pub fn create(shared_secret: &[u8; 32], payload: Vec<u8>) -> Self
Creates an onion error packet using the erring node shared secret.
The erring node should store the shared secrets to forward the onion packet locally and reuse them to obfuscate the error packet.
The shared secret can be obtained via OnionPacket::shared_secret.
Sourcepub fn concat(hmac: [u8; 32], payload: Vec<u8>) -> Self
pub fn concat(hmac: [u8; 32], payload: Vec<u8>) -> Self
Concatenates HMAC and the payload without encryption.
Sourcepub fn xor_cipher_stream(self, shared_secret: &[u8; 32]) -> Self
pub fn xor_cipher_stream(self, shared_secret: &[u8; 32]) -> Self
Encrypts or decrypts the packet data with the chacha20 stream.
Apply XOR on the packet data with the keystream generated by the chacha20 stream cipher.
Sourcepub fn parse<F, T>(
self,
hops_path: Vec<PublicKey>,
session_key: SecretKey,
parse_payload: F,
) -> Option<(T, usize)>
pub fn parse<F, T>( self, hops_path: Vec<PublicKey>, session_key: SecretKey, parse_payload: F, ) -> Option<(T, usize)>
Decrypts the packet data and parses the error message.
This method is for the origin node to decrypts the packet data node by node and try to parse the message.
hops_path: The public keys for each hop. These are yi in the specification.session_key: The ephemeral secret key for the onion packet. It must be generated securely using a random process. This is x in the specification.parse_payload: A function to parse the error payload from the decrypted packet data. It should returnSome(T)if the given buffer starts with a valid error payload, otherwiseNone.
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.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Converts the onion packet into a byte vector.
pub fn from_bytes(bytes: Vec<u8>) -> Self
Trait Implementations§
Source§impl Clone for OnionErrorPacket
impl Clone for OnionErrorPacket
Source§fn clone(&self) -> OnionErrorPacket
fn clone(&self) -> OnionErrorPacket
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more