ppad-bolt4-0.1.1: Onion routing per BOLT #4
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Lightning.Protocol.BOLT4

Description

Onion routing for the Lightning Network, per BOLT #4 (https://github.com/lightning/bolts/blob/master/04-onion-routing.md): onion construction and processing, returning errors, and route blinding.

The examples below assume:

>>> :set -XOverloadedStrings
>>> import qualified Data.ByteString as BS
>>> import qualified Lightning.Protocol.BOLT1 as BOLT1
>>> import Lightning.Protocol.BOLT4

Construct a two-hop onion:

>>> let Just session = secret_key (BS.replicate 32 0x41)
>>> let Just alice = secret_key (BS.replicate 32 0x42)
>>> let Just bob = secret_key (BS.replicate 32 0x43)
>>> let Just scid = BOLT1.short_channel_id 800000 1 0
>>> let Just amt = BOLT1.milli_satoshi 100000
>>> :{
let alice_payload = empty_hop_payload {
        hp_amt_to_forward      = Just amt
      , hp_outgoing_cltv_value = Just 800040
      , hp_short_channel_id    = Just scid
      }
    bob_payload = empty_hop_payload {
        hp_amt_to_forward      = Just amt
      , hp_outgoing_cltv_value = Just 800000
      }
    route = [ Hop (public_key alice) alice_payload
            , Hop (public_key bob) bob_payload ]
    payment_hash = BS.replicate 32 0xff
:}
>>> let Right (onion, secrets) = construct session route payment_hash

Process it at each hop:

>>> let Right (Forward fwd) = process alice onion payment_hash Nothing
>>> hp_short_channel_id (fwd_payload fwd) == Just scid
True
>>> let next = fwd_next_packet fwd
>>> let Right (Receive rcv) = process bob next payment_hash Nothing
>>> hp_outgoing_cltv_value (rcv_payload rcv)
Just 800000

Fail at the final hop, wrap the error at the first, and attribute it at the origin:

>>> let tlvs = BOLT1.empty_tlv_stream
>>> let failure = FailureMessage TemporaryNodeFailure tlvs
>>> let Right err = construct_error (rcv_shared_secret rcv) failure
>>> let returned = wrap_error (fwd_shared_secret fwd) err
>>> unwrap_error secrets returned == Attributed 1 failure
True
Synopsis

Keys

data SecretKey Source #

A secp256k1 secret key: a session key, a node's private key, or the seed of a blinded path.

This is secret material: its Show instance is redacted and it has no Eq instance.

Instances

Instances details
NFData SecretKey Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Prim

Methods

rnf :: SecretKey -> () #

Show SecretKey Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Prim

secret_key :: ByteString -> Maybe SecretKey Source #

Construct a SecretKey from exactly 32 big-endian bytes encoding an integer in [1, n - 1], where n is the secp256k1 group order.

>>> secret_key (BS.replicate 32 0x41)
Just (SecretKey <redacted>)
>>> secret_key (BS.replicate 32 0x00)
Nothing
>>> secret_key (BS.replicate 31 0x41)
Nothing

public_key :: SecretKey -> Point Source #

The public key of a SecretKey.

>>> let Just sk = secret_key (BS.replicate 32 0x41)
>>> BS.length (BOLT1.un_point (public_key sk))
33

data SharedSecret Source #

A 32-byte shared secret, established between the origin of an onion and one of its hops.

This is secret material: its Show instance is redacted and its Eq instance runs in constant time.

Instances

Instances details
NFData SharedSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Prim

Methods

rnf :: SharedSecret -> () #

Show SharedSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Prim

Eq SharedSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Prim

shared_secret :: ByteString -> Maybe SharedSecret Source #

Construct a SharedSecret from exactly 32 bytes (e.g. to restore one that was stored with un_shared_secret).

>>> let Just ss = shared_secret (BS.replicate 32 0x01)
>>> BS.length (un_shared_secret ss)
32
>>> shared_secret "too short"
Nothing

Onion packets

data OnionPacket Source #

An onion packet (onion_packet): 1366 bytes on the wire.

Constructors

OnionPacket 

Fields

Instances

Instances details
NFData OnionPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: OnionPacket -> () #

Generic OnionPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep OnionPacket 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionPacket = D1 ('MetaData "OnionPacket" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "OnionPacket" 'PrefixI 'True) ((S1 ('MetaSel ('Just "onion_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8) :*: S1 ('MetaSel ('Just "onion_public_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point)) :*: (S1 ('MetaSel ('Just "onion_hop_payloads") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayloads) :*: S1 ('MetaSel ('Just "onion_hmac") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Hmac32))))
Show OnionPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq OnionPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionPacket = D1 ('MetaData "OnionPacket" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "OnionPacket" 'PrefixI 'True) ((S1 ('MetaSel ('Just "onion_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8) :*: S1 ('MetaSel ('Just "onion_public_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point)) :*: (S1 ('MetaSel ('Just "onion_hop_payloads") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayloads) :*: S1 ('MetaSel ('Just "onion_hmac") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Hmac32))))

data HopPayloads Source #

The 1300-byte hop_payloads field of an onion packet.

Instances

Instances details
NFData HopPayloads Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: HopPayloads -> () #

Generic HopPayloads Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep HopPayloads 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayloads = D1 ('MetaData "HopPayloads" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "HopPayloads" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show HopPayloads Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq HopPayloads Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayloads Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayloads = D1 ('MetaData "HopPayloads" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "HopPayloads" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

hop_payloads :: ByteString -> Maybe HopPayloads Source #

Construct HopPayloads from exactly 1300 bytes.

>>> let Just hp = hop_payloads (BS.replicate 1300 0)
>>> BS.length (un_hop_payloads hp)
1300
>>> hop_payloads (BS.replicate 1299 0)
Nothing

data Hmac32 Source #

A 32-byte HMAC.

Instances

Instances details
NFData Hmac32 Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: Hmac32 -> () #

Generic Hmac32 Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep Hmac32 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep Hmac32 = D1 ('MetaData "Hmac32" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "Hmac32" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: Hmac32 -> Rep Hmac32 x #

to :: Rep Hmac32 x -> Hmac32 #

Show Hmac32 Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq Hmac32 Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

(==) :: Hmac32 -> Hmac32 -> Bool #

(/=) :: Hmac32 -> Hmac32 -> Bool #

type Rep Hmac32 Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep Hmac32 = D1 ('MetaData "Hmac32" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "Hmac32" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

hmac32 :: ByteString -> Maybe Hmac32 Source #

Construct an Hmac32 from exactly 32 bytes.

>>> fmap (BS.length . un_hmac32) (hmac32 (BS.replicate 32 0))
Just 32
>>> hmac32 "too short"
Nothing

un_hmac32 :: Hmac32 -> ByteString Source #

The bytes of an Hmac32.

encode_onion_packet :: OnionPacket -> ByteString Source #

Encode an OnionPacket (1366 bytes).

>>> let Just pk = BOLT1.point (BS.cons 0x02 (BS.replicate 32 0x01))
>>> let Just hp = hop_payloads (BS.replicate 1300 0)
>>> let Just mac = hmac32 (BS.replicate 32 0)
>>> BS.length (encode_onion_packet (OnionPacket 0 pk hp mac))
1366

decode_onion_packet :: ByteString -> Either DecodeError OnionPacket Source #

Decode an OnionPacket from exactly 1366 bytes. The public key must carry a compressed-encoding prefix; the version byte is not checked (see process).

>>> decode_onion_packet (BS.replicate 1365 0)
Left InvalidLength

Hop payloads

data HopPayload Source #

A hop's payload TLV stream.

Each known record has a typed field. hp_extra holds the remaining records: decoding fills it with the unknown odd records (unknown even records are rejected), and encoding accepts any record in it whose type isn't one of the known ones.

Constructors

HopPayload 

Fields

Instances

Instances details
NFData HopPayload Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: HopPayload -> () #

Generic HopPayload Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep HopPayload 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayload = D1 ('MetaData "HopPayload" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "HopPayload" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hp_amt_to_forward") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe MilliSatoshi)) :*: S1 ('MetaSel ('Just "hp_outgoing_cltv_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word32))) :*: (S1 ('MetaSel ('Just "hp_short_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId)) :*: S1 ('MetaSel ('Just "hp_payment_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentData)))) :*: ((S1 ('MetaSel ('Just "hp_encrypted_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "hp_current_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point))) :*: (S1 ('MetaSel ('Just "hp_payment_metadata") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: (S1 ('MetaSel ('Just "hp_total_amount_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe MilliSatoshi)) :*: S1 ('MetaSel ('Just "hp_extra") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))))))
Show HopPayload Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq HopPayload Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayload Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep HopPayload = D1 ('MetaData "HopPayload" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "HopPayload" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hp_amt_to_forward") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe MilliSatoshi)) :*: S1 ('MetaSel ('Just "hp_outgoing_cltv_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word32))) :*: (S1 ('MetaSel ('Just "hp_short_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId)) :*: S1 ('MetaSel ('Just "hp_payment_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentData)))) :*: ((S1 ('MetaSel ('Just "hp_encrypted_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "hp_current_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point))) :*: (S1 ('MetaSel ('Just "hp_payment_metadata") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: (S1 ('MetaSel ('Just "hp_total_amount_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe MilliSatoshi)) :*: S1 ('MetaSel ('Just "hp_extra") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))))))

empty_hop_payload :: HopPayload Source #

The empty HopPayload, to be updated with record syntax.

>>> let Just amt = BOLT1.milli_satoshi 1000
>>> let hp = empty_hop_payload { hp_amt_to_forward = Just amt }
>>> encode_hop_payload hp
Right "\STX\STX\ETX\232"

data PaymentData Source #

The payment_data record of a final hop's payload.

Instances

Instances details
NFData PaymentData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: PaymentData -> () #

Generic PaymentData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep PaymentData 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentData = D1 ('MetaData "PaymentData" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentData" 'PrefixI 'True) (S1 ('MetaSel ('Just "pd_payment_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentSecret) :*: S1 ('MetaSel ('Just "pd_total_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)))
Show PaymentData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq PaymentData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentData = D1 ('MetaData "PaymentData" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentData" 'PrefixI 'True) (S1 ('MetaSel ('Just "pd_payment_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentSecret) :*: S1 ('MetaSel ('Just "pd_total_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)))

data PaymentSecret Source #

A 32-byte payment secret.

Its Show instance is redacted and its Eq instance runs in constant time.

payment_secret :: ByteString -> Maybe PaymentSecret Source #

Construct a PaymentSecret from exactly 32 bytes.

>>> payment_secret (BS.replicate 32 0x01)
Just (PaymentSecret <redacted>)
>>> payment_secret (BS.replicate 16 0x01)
Nothing

encode_hop_payload :: HopPayload -> Either EncodeError ByteString Source #

Encode a HopPayload as a payload TLV stream (without its length prefix). Fails if hp_extra has a record of a known type.

>>> let hp = empty_hop_payload { hp_outgoing_cltv_value = Just 144 }
>>> encode_hop_payload hp
Right "\EOT\SOH\144"

decode_hop_payload :: ByteString -> Either DecodeError HopPayload Source #

Decode a payload TLV stream (without its length prefix). Fails on a malformed stream, an unknown even type, or a malformed known record.

>>> fmap hp_outgoing_cltv_value (decode_hop_payload "\EOT\SOH\144")
Right (Just 144)
>>> decode_hop_payload "\DC4\NUL"
Left (InvalidTlvStream (TlvUnknownEvenType 20))

Constructing onions

data Hop Source #

A hop of a route: the public key the hop's onion layer is encrypted to (its node id, or its blinded node id in a blinded route), and its payload.

Constructors

Hop 

Instances

Instances details
NFData Hop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Methods

rnf :: Hop -> () #

Generic Hop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Associated Types

type Rep Hop 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

type Rep Hop = D1 ('MetaData "Hop" "Lightning.Protocol.BOLT4.Construct" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Hop" 'PrefixI 'True) (S1 ('MetaSel ('Just "hop_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "hop_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload)))

Methods

from :: Hop -> Rep Hop x #

to :: Rep Hop x -> Hop #

Show Hop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Methods

showsPrec :: Int -> Hop -> ShowS #

show :: Hop -> String #

showList :: [Hop] -> ShowS #

Eq Hop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Methods

(==) :: Hop -> Hop -> Bool #

(/=) :: Hop -> Hop -> Bool #

type Rep Hop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

type Rep Hop = D1 ('MetaData "Hop" "Lightning.Protocol.BOLT4.Construct" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Hop" 'PrefixI 'True) (S1 ('MetaSel ('Just "hop_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "hop_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload)))

construct :: SecretKey -> [Hop] -> ByteString -> Either ConstructError (OnionPacket, [SharedSecret]) Source #

Construct an onion packet for a route, given a session key (which must be fresh and random for every onion), the route's hops from the first to the final one, and the associated data (the payment hash, for a payment).

Returns the packet and the shared secret of each hop, in route order; keep the latter to attribute returned errors with unwrap_error.

>>> let Just session = secret_key (BS.replicate 32 0x41)
>>> let Just node = secret_key (BS.replicate 32 0x42)
>>> let Just amt = BOLT1.milli_satoshi 1000
>>> :{
let payload = empty_hop_payload {
        hp_amt_to_forward      = Just amt
      , hp_outgoing_cltv_value = Just 800000
      }
    route = [Hop (public_key node) payload]
:}
>>> let Right (pkt, sss) = construct session route (BS.replicate 32 0)
>>> BS.length (encode_onion_packet pkt)
1366
>>> length sss
1

data ConstructError Source #

Why an onion packet could not be constructed.

Constructors

EmptyRoute

the route has no hops

TooManyHops

the route has more than 20 hops

InvalidHopPubKey !Int

the public key of the hop with this index is not a valid point

InvalidHopPayload !Int

the payload of the hop with this index can't be encoded, or encodes to fewer than 2 bytes

PayloadsTooLarge !Int

the hops' payloads, with their length prefixes and HMACs, take this many bytes, more than the 1300 available

Instances

Instances details
NFData ConstructError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Methods

rnf :: ConstructError -> () #

Generic ConstructError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Associated Types

type Rep ConstructError 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

type Rep ConstructError = D1 ('MetaData "ConstructError" "Lightning.Protocol.BOLT4.Construct" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((C1 ('MetaCons "EmptyRoute" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TooManyHops" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "InvalidHopPubKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "InvalidHopPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "PayloadsTooLarge" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)))))
Show ConstructError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

Eq ConstructError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

type Rep ConstructError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Construct

type Rep ConstructError = D1 ('MetaData "ConstructError" "Lightning.Protocol.BOLT4.Construct" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((C1 ('MetaCons "EmptyRoute" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TooManyHops" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "InvalidHopPubKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "InvalidHopPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "PayloadsTooLarge" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)))))

Processing onions

process :: SecretKey -> OnionPacket -> ByteString -> Maybe Point -> Either ProcessError ProcessResult Source #

Process an onion packet, given this node's private key, the packet, its associated data (the payment hash, for a payment), and the path_key received with it (in update_add_htlc), if any.

In a blinded route, the onion is encrypted to this node's blinded node id: given a path_key, the matching private key is derived from it. The encrypted_recipient_data in the payload is decrypted with the path_key, or, at the introduction node, with the payload's current_path_key; a path key without encrypted_recipient_data, or both kinds of path key, are rejected.

The payload is otherwise returned as is. The caller must apply the remaining reader requirements of BOLT #4: the presence of the fields required for forwarding or receiving, the HTLC amount and expiry checks (in a blinded route, against payment_relay and payment_constraints), allowed_features, the rule that encrypted_recipient_data hold only one of short_channel_id and next_node_id, and the rejection of replayed HMACs.

>>> let Just session = secret_key (BS.replicate 32 0x41)
>>> let Just node = secret_key (BS.replicate 32 0x42)
>>> let pl = empty_hop_payload { hp_outgoing_cltv_value = Just 144 }
>>> let ad = BS.replicate 32 0
>>> let Right (pkt, _) = construct session [Hop (public_key node) pl] ad
>>> let Right (Receive info) = process node pkt ad Nothing
>>> hp_outgoing_cltv_value (rcv_payload info)
Just 144

data ProcessResult Source #

The result of processing an onion packet.

Constructors

Forward !ForwardInfo

forward the onion to the next hop

Receive !ReceiveInfo

this node is the onion's final hop

Instances

Instances details
NFData ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Methods

rnf :: ProcessResult -> () #

Generic ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Associated Types

type Rep ProcessResult 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ProcessResult = D1 ('MetaData "ProcessResult" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Forward" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ForwardInfo)) :+: C1 ('MetaCons "Receive" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ReceiveInfo)))
Show ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Eq ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ProcessResult = D1 ('MetaData "ProcessResult" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Forward" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ForwardInfo)) :+: C1 ('MetaCons "Receive" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ReceiveInfo)))

data ForwardInfo Source #

What a forwarding node learns from an onion.

Constructors

ForwardInfo 

Fields

Instances

Instances details
NFData ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Methods

rnf :: ForwardInfo -> () #

Generic ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Associated Types

type Rep ForwardInfo 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ForwardInfo = D1 ('MetaData "ForwardInfo" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ForwardInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "fwd_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "fwd_blinded") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe BlindedInfo))) :*: (S1 ('MetaSel ('Just "fwd_next_packet") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionPacket) :*: S1 ('MetaSel ('Just "fwd_shared_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SharedSecret))))
Show ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Eq ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ForwardInfo = D1 ('MetaData "ForwardInfo" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ForwardInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "fwd_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "fwd_blinded") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe BlindedInfo))) :*: (S1 ('MetaSel ('Just "fwd_next_packet") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionPacket) :*: S1 ('MetaSel ('Just "fwd_shared_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SharedSecret))))

data ReceiveInfo Source #

What the final node learns from an onion.

Constructors

ReceiveInfo 

Fields

Instances

Instances details
NFData ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Methods

rnf :: ReceiveInfo -> () #

Generic ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Associated Types

type Rep ReceiveInfo 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ReceiveInfo = D1 ('MetaData "ReceiveInfo" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ReceiveInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "rcv_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: (S1 ('MetaSel ('Just "rcv_blinded") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe BlindedInfo)) :*: S1 ('MetaSel ('Just "rcv_shared_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SharedSecret))))
Show ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

Eq ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Process

type Rep ReceiveInfo = D1 ('MetaData "ReceiveInfo" "Lightning.Protocol.BOLT4.Process" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ReceiveInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "rcv_payload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: (S1 ('MetaSel ('Just "rcv_blinded") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe BlindedInfo)) :*: S1 ('MetaSel ('Just "rcv_shared_secret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SharedSecret))))

data BlindedInfo Source #

What a node in a blinded route learns from its encrypted_recipient_data.

Constructors

BlindedInfo 

Fields

Instances

Instances details
NFData BlindedInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: BlindedInfo -> () #

Generic BlindedInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep BlindedInfo 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedInfo = D1 ('MetaData "BlindedInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "bi_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlindedHopData) :*: S1 ('MetaSel ('Just "bi_next_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point)))
Show BlindedInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq BlindedInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedInfo = D1 ('MetaData "BlindedInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "bi_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlindedHopData) :*: S1 ('MetaSel ('Just "bi_next_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point)))

data ProcessError Source #

Why an onion packet was rejected.

Constructors

InvalidVersion !Word8

the version byte is not 0

InvalidPublicKey

the ephemeral public key is not a valid point

HmacMismatch

the packet's HMAC is wrong

InvalidPayloadLength

the payload length is malformed, below 2, or past the end of hop_payloads

InvalidPayload !DecodeError

the payload is not a valid payload TLV stream

InvalidPathKey

the path key is not a valid point

UnexpectedPathKey

a path key was given with no encrypted_recipient_data, or both a path_key and a current_path_key were given

MissingPathKey

encrypted_recipient_data was given with no path key

InvalidRecipientData

the encrypted_recipient_data doesn't decrypt to a valid encrypted_data_tlv stream

Instances

Instances details
NFData ProcessError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: ProcessError -> () #

Generic ProcessError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep ProcessError 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessError = D1 ('MetaData "ProcessError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (((C1 ('MetaCons "InvalidVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8)) :+: C1 ('MetaCons "InvalidPublicKey" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HmacMismatch" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidPayloadLength" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "InvalidPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DecodeError)) :+: C1 ('MetaCons "InvalidPathKey" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "UnexpectedPathKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "MissingPathKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidRecipientData" 'PrefixI 'False) (U1 :: Type -> Type)))))
Show ProcessError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq ProcessError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessError = D1 ('MetaData "ProcessError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (((C1 ('MetaCons "InvalidVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8)) :+: C1 ('MetaCons "InvalidPublicKey" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HmacMismatch" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidPayloadLength" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "InvalidPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DecodeError)) :+: C1 ('MetaCons "InvalidPathKey" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "UnexpectedPathKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "MissingPathKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidRecipientData" 'PrefixI 'False) (U1 :: Type -> Type)))))

Route blinding

data BlindedPath Source #

A blinded route (blinded_path), as created by a recipient.

Constructors

BlindedPath 

Fields

Instances

Instances details
NFData BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: BlindedPath -> () #

Generic BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep BlindedPath 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedPath = D1 ('MetaData "BlindedPath" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedPath" 'PrefixI 'True) (S1 ('MetaSel ('Just "bp_first_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: (S1 ('MetaSel ('Just "bp_first_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "bp_hops") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [BlindedHop]))))
Show BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedPath Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedPath = D1 ('MetaData "BlindedPath" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedPath" 'PrefixI 'True) (S1 ('MetaSel ('Just "bp_first_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: (S1 ('MetaSel ('Just "bp_first_path_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "bp_hops") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [BlindedHop]))))

data BlindedHop Source #

A hop of a blinded route (blinded_path_hop).

Constructors

BlindedHop 

Fields

Instances

Instances details
NFData BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: BlindedHop -> () #

Generic BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep BlindedHop 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHop = D1 ('MetaData "BlindedHop" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedHop" 'PrefixI 'True) (S1 ('MetaSel ('Just "bh_blinded_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "bh_encrypted_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))
Show BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHop Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHop = D1 ('MetaData "BlindedHop" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedHop" 'PrefixI 'True) (S1 ('MetaSel ('Just "bh_blinded_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Point) :*: S1 ('MetaSel ('Just "bh_encrypted_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

create_blinded_path :: SecretKey -> [(Point, BlindedHopData)] -> Either BlindingError BlindedPath Source #

Create a blinded route to oneself, given a seed for the route's ephemeral keys (which must be fresh and random for every route) and each node's id and data, from the introduction node to oneself.

>>> let Just seed = secret_key (BS.replicate 32 0x01)
>>> let Just me = secret_key (BS.replicate 32 0x45)
>>> let dat = empty_blinded_hop_data { bhd_path_id = Just "deadbeef" }
>>> let Right path = create_blinded_path seed [(public_key me, dat)]
>>> bp_first_node_id path == public_key me
True
>>> length (bp_hops path)
1

data BlindingError Source #

Why a blinded route could not be created.

Constructors

EmptyPath

the route has no hops

InvalidNodeId !Int

the node id of the hop with this index is not a valid point

InvalidHopData !Int !EncodeError

the data of the hop with this index can't be encoded

Instances

Instances details
NFData BlindingError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

Methods

rnf :: BlindingError -> () #

Generic BlindingError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

Associated Types

type Rep BlindingError 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

type Rep BlindingError = D1 ('MetaData "BlindingError" "Lightning.Protocol.BOLT4.Blinding" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "EmptyPath" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidNodeId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "InvalidHopData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 EncodeError))))
Show BlindingError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

Eq BlindingError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

type Rep BlindingError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Blinding

type Rep BlindingError = D1 ('MetaData "BlindingError" "Lightning.Protocol.BOLT4.Blinding" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "EmptyPath" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidNodeId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "InvalidHopData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 EncodeError))))

decrypt_recipient_data :: SecretKey -> Point -> ByteString -> Either ProcessError BlindedInfo Source #

Decrypt the encrypted_recipient_data received by a node in a blinded route, given the node's private key and the path key it received.

Returns the decrypted data and the path key for the next node (the data's next_path_key_override, if present). process does this for payment onions.

>>> let Just seed = secret_key (BS.replicate 32 0x01)
>>> let Just me = secret_key (BS.replicate 32 0x45)
>>> let dat = empty_blinded_hop_data { bhd_path_id = Just "deadbeef" }
>>> let Right path = create_blinded_path seed [(public_key me, dat)]
>>> let [hop] = bp_hops path
>>> let pk = bp_first_path_key path
>>> let Right info = decrypt_recipient_data me pk (bh_encrypted_data hop)
>>> bhd_path_id (bi_data info)
Just "deadbeef"

data BlindedHopData Source #

The encrypted_data_tlv stream carried, encrypted, in a hop's encrypted_recipient_data.

bhd_extra plays the same role as hp_extra in HopPayload.

Constructors

BlindedHopData 

Fields

Instances

Instances details
NFData BlindedHopData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: BlindedHopData -> () #

Generic BlindedHopData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep BlindedHopData 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHopData = D1 ('MetaData "BlindedHopData" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedHopData" 'PrefixI 'True) (((S1 ('MetaSel ('Just "bhd_padding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "bhd_short_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId))) :*: (S1 ('MetaSel ('Just "bhd_next_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point)) :*: S1 ('MetaSel ('Just "bhd_path_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)))) :*: ((S1 ('MetaSel ('Just "bhd_next_path_key_override") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point)) :*: S1 ('MetaSel ('Just "bhd_payment_relay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentRelay))) :*: (S1 ('MetaSel ('Just "bhd_payment_constraints") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentConstraints)) :*: (S1 ('MetaSel ('Just "bhd_allowed_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe FeatureVector)) :*: S1 ('MetaSel ('Just "bhd_extra") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))))))
Show BlindedHopData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq BlindedHopData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHopData Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep BlindedHopData = D1 ('MetaData "BlindedHopData" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "BlindedHopData" 'PrefixI 'True) (((S1 ('MetaSel ('Just "bhd_padding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "bhd_short_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId))) :*: (S1 ('MetaSel ('Just "bhd_next_node_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point)) :*: S1 ('MetaSel ('Just "bhd_path_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)))) :*: ((S1 ('MetaSel ('Just "bhd_next_path_key_override") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Point)) :*: S1 ('MetaSel ('Just "bhd_payment_relay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentRelay))) :*: (S1 ('MetaSel ('Just "bhd_payment_constraints") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentConstraints)) :*: (S1 ('MetaSel ('Just "bhd_allowed_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe FeatureVector)) :*: S1 ('MetaSel ('Just "bhd_extra") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))))))

empty_blinded_hop_data :: BlindedHopData Source #

The empty BlindedHopData, to be updated with record syntax.

>>> let bhd = empty_blinded_hop_data { bhd_path_id = Just "path id" }
>>> encode_blinded_hop_data bhd
Right "\ACK\apath id"

data PaymentRelay Source #

The payment_relay record of BlindedHopData.

Instances

Instances details
NFData PaymentRelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: PaymentRelay -> () #

Generic PaymentRelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep PaymentRelay 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentRelay = D1 ('MetaData "PaymentRelay" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentRelay" 'PrefixI 'True) (S1 ('MetaSel ('Just "pr_cltv_expiry_delta") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: (S1 ('MetaSel ('Just "pr_fee_proportional_millionths") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "pr_fee_base_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32))))
Show PaymentRelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq PaymentRelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentRelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentRelay = D1 ('MetaData "PaymentRelay" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentRelay" 'PrefixI 'True) (S1 ('MetaSel ('Just "pr_cltv_expiry_delta") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: (S1 ('MetaSel ('Just "pr_fee_proportional_millionths") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "pr_fee_base_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32))))

data PaymentConstraints Source #

The payment_constraints record of BlindedHopData.

Instances

Instances details
NFData PaymentConstraints Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: PaymentConstraints -> () #

Generic PaymentConstraints Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep PaymentConstraints 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentConstraints = D1 ('MetaData "PaymentConstraints" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentConstraints" 'PrefixI 'True) (S1 ('MetaSel ('Just "pc_max_cltv_expiry") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "pc_htlc_minimum_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)))
Show PaymentConstraints Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq PaymentConstraints Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentConstraints Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep PaymentConstraints = D1 ('MetaData "PaymentConstraints" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "PaymentConstraints" 'PrefixI 'True) (S1 ('MetaSel ('Just "pc_max_cltv_expiry") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "pc_htlc_minimum_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)))

encode_blinded_hop_data :: BlindedHopData -> Either EncodeError ByteString Source #

Encode BlindedHopData as an encrypted_data_tlv stream. Fails if bhd_extra has a record of a known type.

decode_blinded_hop_data :: ByteString -> Either DecodeError BlindedHopData Source #

Decode an encrypted_data_tlv stream. Fails on a malformed stream, an unknown even type, or a malformed known record.

>>> fmap bhd_path_id (decode_blinded_hop_data "\ACK\apath id")
Right (Just "path id")

Failure messages

data FailureMessage Source #

A failure message (failuremsg): a failure, followed by an optional TLV stream.

Constructors

FailureMessage 

Instances

Instances details
NFData FailureMessage Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: FailureMessage -> () #

Generic FailureMessage Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep FailureMessage 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep FailureMessage = D1 ('MetaData "FailureMessage" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "FailureMessage" 'PrefixI 'True) (S1 ('MetaSel ('Just "fm_failure") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Failure) :*: S1 ('MetaSel ('Just "fm_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream)))
Show FailureMessage Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq FailureMessage Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep FailureMessage Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep FailureMessage = D1 ('MetaData "FailureMessage" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "FailureMessage" 'PrefixI 'True) (S1 ('MetaSel ('Just "fm_failure") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Failure) :*: S1 ('MetaSel ('Just "fm_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream)))

data Failure Source #

A failure: a failure code and its data.

A channel_update field holds the raw bytes of the update; it is empty when the update is omitted.

Constructors

TemporaryNodeFailure

NODE|2

PermanentNodeFailure

PERM|NODE|2

RequiredNodeFeatureMissing

PERM|NODE|3

InvalidOnionVersion !OnionHash

BADONION|PERM|4: sha256_of_onion

InvalidOnionHmac !OnionHash

BADONION|PERM|5: sha256_of_onion

InvalidOnionKey !OnionHash

BADONION|PERM|6: sha256_of_onion

TemporaryChannelFailure !ByteString

UPDATE|7: channel_update

PermanentChannelFailure

PERM|8

RequiredChannelFeatureMissing

PERM|9

UnknownNextPeer

PERM|10

AmountBelowMinimum !MilliSatoshi !ByteString

UPDATE|11: htlc_msat, channel_update

FeeInsufficient !MilliSatoshi !ByteString

UPDATE|12: htlc_msat, channel_update

IncorrectCltvExpiry !Word32 !ByteString

UPDATE|13: cltv_expiry, channel_update

ExpiryTooSoon !ByteString

UPDATE|14: channel_update

IncorrectOrUnknownPaymentDetails !MilliSatoshi !Word32

PERM|15: htlc_msat, height

FinalIncorrectCltvExpiry !Word32

18: cltv_expiry

FinalIncorrectHtlcAmount !MilliSatoshi

19: incoming_htlc_amt

ChannelDisabled !Word16 !ByteString

UPDATE|20: disabled_flags, channel_update

ExpiryTooFar

21

InvalidOnionPayload !(Maybe (Word64, Word16))

PERM|22: the optional type and offset

MppTimeout

23

InvalidOnionBlinding !OnionHash

BADONION|PERM|24: sha256_of_onion

UnknownFailure !Word16 !ByteString

a failure code not defined above, and the bytes following it

Instances

Instances details
NFData Failure Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: Failure -> () #

Generic Failure Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep Failure 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep Failure = D1 ('MetaData "Failure" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((((C1 ('MetaCons "TemporaryNodeFailure" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PermanentNodeFailure" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "RequiredNodeFeatureMissing" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidOnionVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: C1 ('MetaCons "InvalidOnionHmac" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash))))) :+: ((C1 ('MetaCons "InvalidOnionKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: (C1 ('MetaCons "TemporaryChannelFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "PermanentChannelFailure" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "RequiredChannelFeatureMissing" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "UnknownNextPeer" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AmountBelowMinimum" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))))) :+: (((C1 ('MetaCons "FeeInsufficient" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: (C1 ('MetaCons "IncorrectCltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "ExpiryTooSoon" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))) :+: (C1 ('MetaCons "IncorrectOrUnknownPaymentDetails" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "FinalIncorrectCltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: C1 ('MetaCons "FinalIncorrectHtlcAmount" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi))))) :+: ((C1 ('MetaCons "ChannelDisabled" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: (C1 ('MetaCons "ExpiryTooFar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidOnionPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (Word64, Word16)))))) :+: (C1 ('MetaCons "MppTimeout" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidOnionBlinding" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: C1 ('MetaCons "UnknownFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))))))

Methods

from :: Failure -> Rep Failure x #

to :: Rep Failure x -> Failure #

Show Failure Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq Failure Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

(==) :: Failure -> Failure -> Bool #

(/=) :: Failure -> Failure -> Bool #

type Rep Failure Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep Failure = D1 ('MetaData "Failure" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((((C1 ('MetaCons "TemporaryNodeFailure" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PermanentNodeFailure" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "RequiredNodeFeatureMissing" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidOnionVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: C1 ('MetaCons "InvalidOnionHmac" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash))))) :+: ((C1 ('MetaCons "InvalidOnionKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: (C1 ('MetaCons "TemporaryChannelFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "PermanentChannelFailure" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "RequiredChannelFeatureMissing" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "UnknownNextPeer" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AmountBelowMinimum" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))))) :+: (((C1 ('MetaCons "FeeInsufficient" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: (C1 ('MetaCons "IncorrectCltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "ExpiryTooSoon" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))) :+: (C1 ('MetaCons "IncorrectOrUnknownPaymentDetails" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "FinalIncorrectCltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: C1 ('MetaCons "FinalIncorrectHtlcAmount" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi))))) :+: ((C1 ('MetaCons "ChannelDisabled" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :+: (C1 ('MetaCons "ExpiryTooFar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidOnionPayload" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (Word64, Word16)))))) :+: (C1 ('MetaCons "MppTimeout" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "InvalidOnionBlinding" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionHash)) :+: C1 ('MetaCons "UnknownFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))))))

data OnionHash Source #

A 32-byte sha256_of_onion.

Instances

Instances details
NFData OnionHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: OnionHash -> () #

Generic OnionHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep OnionHash 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionHash = D1 ('MetaData "OnionHash" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "OnionHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show OnionHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq OnionHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep OnionHash = D1 ('MetaData "OnionHash" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "OnionHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

onion_hash :: ByteString -> Maybe OnionHash Source #

Construct an OnionHash from exactly 32 bytes.

>>> fmap (BS.length . un_onion_hash) (onion_hash (BS.replicate 32 0))
Just 32

failure_code :: Failure -> Word16 Source #

The failure_code of a Failure.

>>> failure_code TemporaryNodeFailure
8194
>>> failure_code (UnknownFailure 0x1234 mempty)
4660

is_badonion :: Failure -> Bool Source #

Is the BADONION flag (0x8000) set: was the onion unparsable?

>>> is_badonion TemporaryNodeFailure
False

is_perm :: Failure -> Bool Source #

Is the PERM flag (0x4000) set: is the failure permanent?

>>> is_perm PermanentNodeFailure
True

is_node :: Failure -> Bool Source #

Is the NODE flag (0x2000) set: is it a node (not channel) failure?

>>> is_node TemporaryNodeFailure
True

is_update :: Failure -> Bool Source #

Is the UPDATE flag (0x1000) set: was a channel forwarding parameter violated?

>>> is_update (ExpiryTooSoon mempty)
True

encode_failure_message :: FailureMessage -> Either EncodeError ByteString Source #

Encode a FailureMessage: the failure code, its data and the TLV stream. Fails if a channel_update exceeds 65535 bytes.

>>> let tlvs = BOLT1.empty_tlv_stream
>>> encode_failure_message (FailureMessage TemporaryNodeFailure tlvs)
Right " \STX"

decode_failure_message :: ByteString -> Either DecodeError FailureMessage Source #

Decode a failure message.

Per BOLT #4, bytes following a failure's data are ignored unless they form a valid TLV stream (which, as no failure TLV types are defined, may hold only odd types). The data of an unknown failure code is every byte following it.

>>> fmap fm_failure (decode_failure_message " \STX")
Right TemporaryNodeFailure
>>> decode_failure_message "\DLE\r"
Left (InvalidFailureData 4109)

Returning errors

newtype ErrorPacket Source #

An obfuscated return packet (the reason of update_fail_htlc).

Constructors

ErrorPacket ByteString 

Instances

Instances details
NFData ErrorPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Methods

rnf :: ErrorPacket -> () #

Generic ErrorPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Associated Types

type Rep ErrorPacket 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep ErrorPacket = D1 ('MetaData "ErrorPacket" "Lightning.Protocol.BOLT4.Error" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "ErrorPacket" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show ErrorPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Eq ErrorPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep ErrorPacket Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep ErrorPacket = D1 ('MetaData "ErrorPacket" "Lightning.Protocol.BOLT4.Error" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'True) (C1 ('MetaCons "ErrorPacket" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

construct_error :: SharedSecret -> FailureMessage -> Either EncodeError ErrorPacket Source #

Construct a return packet at the failing node, given the shared secret from processing the onion and the failure.

The failure message is padded so that its length plus that of the padding is at least 256 bytes. Fails if the failure message can't be encoded, or exceeds 65535 bytes.

>>> let Just ss = shared_secret (BS.replicate 32 0x01)
>>> let fm = FailureMessage TemporaryNodeFailure BOLT1.empty_tlv_stream
>>> let Right (ErrorPacket pkt) = construct_error ss fm
>>> BS.length pkt
292

wrap_error :: SharedSecret -> ErrorPacket -> ErrorPacket Source #

Wrap a return packet from downstream at an intermediate node, given the shared secret from processing the onion.

>>> let Just ss = shared_secret (BS.replicate 32 0x01)
>>> wrap_error ss (wrap_error ss (ErrorPacket "packet"))
ErrorPacket "packet"

unwrap_error :: [SharedSecret] -> ErrorPacket -> Attribution Source #

Find the origin of a return packet at the origin node, given the shared secrets from construct, in route order.

>>> let Just ss0 = shared_secret (BS.replicate 32 0x01)
>>> let Just ss1 = shared_secret (BS.replicate 32 0x02)
>>> let fm = FailureMessage TemporaryNodeFailure BOLT1.empty_tlv_stream
>>> let Right pkt = construct_error ss1 fm
>>> unwrap_error [ss0, ss1] (wrap_error ss0 pkt) == Attributed 1 fm
True
>>> unwrap_error [ss0] (wrap_error ss0 pkt)
UnknownOrigin

data Attribution Source #

The origin of a return packet, as found by unwrap_error.

Constructors

Attributed !Int !FailureMessage

the hop with this index (from 0, in route order) returned the failure

MalformedFailure !Int

the hop with this index returned the packet, but its failure message can't be decoded

UnknownOrigin

no hop's HMAC matches

Instances

Instances details
NFData Attribution Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Methods

rnf :: Attribution -> () #

Generic Attribution Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Associated Types

type Rep Attribution 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep Attribution = D1 ('MetaData "Attribution" "Lightning.Protocol.BOLT4.Error" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Attributed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FailureMessage)) :+: (C1 ('MetaCons "MalformedFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "UnknownOrigin" 'PrefixI 'False) (U1 :: Type -> Type)))
Show Attribution Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

Eq Attribution Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep Attribution Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Error

type Rep Attribution = D1 ('MetaData "Attribution" "Lightning.Protocol.BOLT4.Error" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "Attributed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FailureMessage)) :+: (C1 ('MetaCons "MalformedFailure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "UnknownOrigin" 'PrefixI 'False) (U1 :: Type -> Type)))

Encoding errors

data DecodeError Source #

Why a decoder failed.

Constructors

InvalidLength

the input has the wrong length

InvalidPoint

a point lacks a compressed-encoding prefix

InvalidTlvStream !TlvError

the TLV stream is malformed, or has an unknown even type

InvalidTlvValue !Word64

the value of the record of this type is malformed

InvalidFailureData !Word16

the data of a failure with this code is malformed

Instances

Instances details
NFData DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: DecodeError -> () #

Generic DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep DecodeError 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((C1 ('MetaCons "InvalidLength" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidPoint" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "InvalidTlvStream" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError)) :+: (C1 ('MetaCons "InvalidTlvValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "InvalidFailureData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16)))))
Show DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) ((C1 ('MetaCons "InvalidLength" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InvalidPoint" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "InvalidTlvStream" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError)) :+: (C1 ('MetaCons "InvalidTlvValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "InvalidFailureData" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16)))))

data EncodeError Source #

Why an encoder failed.

Constructors

ConflictingTlv

an extra TLV record has the type of a known record

FieldTooLong

a length-prefixed field exceeds its maximum length

Instances

Instances details
NFData EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Methods

rnf :: EncodeError -> () #

Generic EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep EncodeError 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep EncodeError = D1 ('MetaData "EncodeError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ConflictingTlv" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FieldTooLong" 'PrefixI 'False) (U1 :: Type -> Type))
Show EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep EncodeError = D1 ('MetaData "EncodeError" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.1.1-4n7rHLsFIaS7plvDS1Lrh3" 'False) (C1 ('MetaCons "ConflictingTlv" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FieldTooLong" 'PrefixI 'False) (U1 :: Type -> Type))