Module onion

Module onion 

Source
Expand description

Onion encryption for privacy-preserving P2P routing.

This module provides layered encryption similar to Tor’s onion routing, where data is encrypted in multiple layers. Each intermediate node can decrypt only one layer to learn the next hop, preserving privacy.

§Example

use chie_crypto::onion::{OnionBuilder, OnionLayer};
use chie_crypto::KeyPair;

// Create routing path with 3 hops
let hop1 = KeyPair::generate();
let hop2 = KeyPair::generate();
let hop3 = KeyPair::generate();

let data = b"Secret message to route through network";

// Build onion with layers
let onion = OnionBuilder::new(data)
    .add_layer(hop1.public_key())
    .add_layer(hop2.public_key())
    .add_layer(hop3.public_key())
    .build()
    .unwrap();

// Each hop peels one layer
let (layer1, next_onion) = onion.peel_layer(&hop3).unwrap();
let (layer2, next_onion) = next_onion.unwrap().peel_layer(&hop2).unwrap();
let (layer3, final_packet) = next_onion.unwrap().peel_layer(&hop1).unwrap();

// Final packet contains the data
assert_eq!(data, final_packet.unwrap().data());

Structs§

OnionBuilder
Builder for creating multi-layer onion packets.
OnionPacket
An onion-encrypted packet with multiple layers.
OnionRoute
Multi-hop onion route for P2P communication.

Enums§

OnionError
Error types for onion encryption operations.
OnionLayer
Information about a peeled onion layer.

Functions§

create_onion
Create an onion packet with the given data and routing path.

Type Aliases§

OnionResult