pub struct OnionPacket {
pub version: u8,
pub public_key: PublicKey,
pub packet_data: Vec<u8>,
pub hmac: [u8; 32],
}Expand description
Onion packet to send encrypted message via multiple hops.
Fields§
§version: u8Version of the onion packet, currently 0
public_key: PublicKeyThe public key of the next hop. Alpha in the specification.
packet_data: Vec<u8>Encrypted packet data. Beta in the specification.
hmac: [u8; 32]HMAC of the packet data. Gamma in the specification.
Implementations§
Source§impl OnionPacket
impl OnionPacket
Sourcepub fn create<C: Signing>(
session_key: SecretKey,
hops_path: Vec<PublicKey>,
hops_data: Vec<Vec<u8>>,
assoc_data: Option<Vec<u8>>,
packet_data_len: usize,
secp_ctx: &Secp256k1<C>,
) -> Result<OnionPacket, SphinxError>
pub fn create<C: Signing>( session_key: SecretKey, hops_path: Vec<PublicKey>, hops_data: Vec<Vec<u8>>, assoc_data: Option<Vec<u8>>, packet_data_len: usize, secp_ctx: &Secp256k1<C>, ) -> Result<OnionPacket, SphinxError>
Creates the new onion packet for the first hop.
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.hops_data: The unencrypted data for each hop. Attention that the data for each hop will be concatenated with the remaining encrypted data. To extract the data, the receiver must know the data length. For example, the hops data can include its length at the beginning. These are mi in the specification.assoc_data: The associated data. It will not be included in the packet itself but will be covered by the packet’s HMAC. This allows each hop to verify that the associated data has not been tampered with. This is A in the specification.onion_packet_len: The length of the onion packet. The packet has the same size for each hop.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Converts the onion packet into a byte vector.
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Self, SphinxError>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, SphinxError>
Converts back from a byte vector.
pub fn extract_public_key_from_slice( bytes: &[u8], ) -> Result<PublicKey, SphinxError>
Derives the shared secret using the node secret key and the ephemeral public key in the onion packet.
Sourcepub fn peel<C, F>(
self,
secret_key: &SecretKey,
assoc_data: Option<&[u8]>,
secp_ctx: &Secp256k1<C>,
get_hop_data_len: F,
) -> Result<(Vec<u8>, Self), SphinxError>
pub fn peel<C, F>( self, secret_key: &SecretKey, assoc_data: Option<&[u8]>, secp_ctx: &Secp256k1<C>, get_hop_data_len: F, ) -> Result<(Vec<u8>, Self), SphinxError>
Peels the onion packet at the current hop.
secret_key: the node private key. xi in the specification.assoc_data: The associated data. It was covered by the onion packet’s HMAC. A in the specification.get_hop_data_len: Tell the hop data len given the decrypted packet data for the current hop.
Returns a tuple (m, p) where m is the hop data for the current hop, and p is remaining onion packet for the next hop.
Trait Implementations§
Source§impl Clone for OnionPacket
impl Clone for OnionPacket
Source§fn clone(&self) -> OnionPacket
fn clone(&self) -> OnionPacket
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OnionPacket
impl Debug for OnionPacket
Source§impl PartialEq for OnionPacket
impl PartialEq for OnionPacket
impl Eq for OnionPacket
impl StructuralPartialEq for OnionPacket
Auto Trait Implementations§
impl Freeze for OnionPacket
impl RefUnwindSafe for OnionPacket
impl Send for OnionPacket
impl Sync for OnionPacket
impl Unpin for OnionPacket
impl UnwindSafe for OnionPacket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more