ppad-bolt4-0.0.1: BOLT4 (onion routing) for Lightning Network
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Lightning.Protocol.BOLT4.Blinding

Description

Route blinding for BOLT4 onion routing.

Synopsis

Types

data BlindedPath Source #

A blinded route provided by recipient.

Constructors

BlindedPath 

Fields

Instances

Instances details
Show BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

Eq BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

data BlindedHop Source #

A single hop in a blinded path.

Constructors

BlindedHop 

Fields

Instances

Instances details
Show BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

Eq BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

data PaymentRelay Source #

Payment relay parameters (TLV 10).

Constructors

PaymentRelay 

Path creation

createBlindedPath Source #

Arguments

:: ByteString

32-byte random seed for ephemeral key

-> [(Projective, BlindedHopData)]

Nodes with their data

-> Either BlindingError BlindedPath 

Create a blinded path from a seed and list of nodes with their data.

Hop processing

processBlindedHop Source #

Arguments

:: ByteString

Node's 32-byte private key

-> Projective

E_i, current path key (blinding point)

-> ByteString

encrypted_data from onion payload

-> Either BlindingError (BlindedHopData, Projective) 

Process a blinded hop, returning decrypted data and next path key.

Key derivation (exported for testing)

deriveBlindingRho :: SharedSecret -> DerivedKey Source #

Derive rho key for encrypting hop data.

rho = HMAC-SHA256(key="rho", data=shared_secret)

deriveBlindedNodeId :: SharedSecret -> Projective -> Maybe ByteString Source #

Derive blinded node ID from shared secret and node pubkey.

B_i = HMAC256("blinded_node_id", ss_i) * N_i

nextEphemeral Source #

Arguments

:: ByteString

e_i (32-byte secret key)

-> Projective

E_i

-> SharedSecret

ss_i

-> Maybe (ByteString, Projective)

(e_{i+1}, E_{i+1})

Compute next ephemeral key pair.

e_{i+1} = SHA256(E_i || ss_i) * e_i E_{i+1} = SHA256(E_i || ss_i) * E_i

TLV encoding (exported for testing)

encodeBlindedHopData :: BlindedHopData -> ByteString Source #

Encode BlindedHopData to TLV stream.

decodeBlindedHopData :: ByteString -> Maybe BlindedHopData Source #

Decode TLV stream to BlindedHopData.

Encryption (exported for testing)

encryptHopData :: DerivedKey -> BlindedHopData -> ByteString Source #

Encrypt hop data with ChaCha20-Poly1305.

Uses rho key and 12-byte zero nonce, empty AAD.

decryptHopData :: DerivedKey -> ByteString -> Maybe BlindedHopData Source #

Decrypt hop data with ChaCha20-Poly1305.