| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
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 scidTrue>>>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 failureTrue
Synopsis
- data SecretKey
- secret_key :: ByteString -> Maybe SecretKey
- public_key :: SecretKey -> Point
- data SharedSecret
- shared_secret :: ByteString -> Maybe SharedSecret
- un_shared_secret :: SharedSecret -> ByteString
- data OnionPacket = OnionPacket {}
- data HopPayloads
- hop_payloads :: ByteString -> Maybe HopPayloads
- un_hop_payloads :: HopPayloads -> ByteString
- data Hmac32
- hmac32 :: ByteString -> Maybe Hmac32
- un_hmac32 :: Hmac32 -> ByteString
- encode_onion_packet :: OnionPacket -> ByteString
- decode_onion_packet :: ByteString -> Either DecodeError OnionPacket
- data HopPayload = HopPayload {
- hp_amt_to_forward :: !(Maybe MilliSatoshi)
- hp_outgoing_cltv_value :: !(Maybe Word32)
- hp_short_channel_id :: !(Maybe ShortChannelId)
- hp_payment_data :: !(Maybe PaymentData)
- hp_encrypted_data :: !(Maybe ByteString)
- hp_current_path_key :: !(Maybe Point)
- hp_payment_metadata :: !(Maybe ByteString)
- hp_total_amount_msat :: !(Maybe MilliSatoshi)
- hp_extra :: !TlvStream
- empty_hop_payload :: HopPayload
- data PaymentData = PaymentData {}
- data PaymentSecret
- payment_secret :: ByteString -> Maybe PaymentSecret
- un_payment_secret :: PaymentSecret -> ByteString
- encode_hop_payload :: HopPayload -> Either EncodeError ByteString
- decode_hop_payload :: ByteString -> Either DecodeError HopPayload
- data Hop = Hop {
- hop_pubkey :: !Point
- hop_payload :: !HopPayload
- construct :: SecretKey -> [Hop] -> ByteString -> Either ConstructError (OnionPacket, [SharedSecret])
- data ConstructError
- process :: SecretKey -> OnionPacket -> ByteString -> Maybe Point -> Either ProcessError ProcessResult
- data ProcessResult
- data ForwardInfo = ForwardInfo {}
- data ReceiveInfo = ReceiveInfo {}
- data BlindedInfo = BlindedInfo {}
- data ProcessError
- data BlindedPath = BlindedPath {
- bp_first_node_id :: !Point
- bp_first_path_key :: !Point
- bp_hops :: ![BlindedHop]
- data BlindedHop = BlindedHop {}
- create_blinded_path :: SecretKey -> [(Point, BlindedHopData)] -> Either BlindingError BlindedPath
- data BlindingError
- decrypt_recipient_data :: SecretKey -> Point -> ByteString -> Either ProcessError BlindedInfo
- data BlindedHopData = BlindedHopData {
- bhd_padding :: !(Maybe ByteString)
- bhd_short_channel_id :: !(Maybe ShortChannelId)
- bhd_next_node_id :: !(Maybe Point)
- bhd_path_id :: !(Maybe ByteString)
- bhd_next_path_key_override :: !(Maybe Point)
- bhd_payment_relay :: !(Maybe PaymentRelay)
- bhd_payment_constraints :: !(Maybe PaymentConstraints)
- bhd_allowed_features :: !(Maybe FeatureVector)
- bhd_extra :: !TlvStream
- empty_blinded_hop_data :: BlindedHopData
- data PaymentRelay = PaymentRelay {}
- data PaymentConstraints = PaymentConstraints {}
- encode_blinded_hop_data :: BlindedHopData -> Either EncodeError ByteString
- decode_blinded_hop_data :: ByteString -> Either DecodeError BlindedHopData
- data FailureMessage = FailureMessage {
- fm_failure :: !Failure
- fm_tlvs :: !TlvStream
- data Failure
- = TemporaryNodeFailure
- | PermanentNodeFailure
- | RequiredNodeFeatureMissing
- | InvalidOnionVersion !OnionHash
- | InvalidOnionHmac !OnionHash
- | InvalidOnionKey !OnionHash
- | TemporaryChannelFailure !ByteString
- | PermanentChannelFailure
- | RequiredChannelFeatureMissing
- | UnknownNextPeer
- | AmountBelowMinimum !MilliSatoshi !ByteString
- | FeeInsufficient !MilliSatoshi !ByteString
- | IncorrectCltvExpiry !Word32 !ByteString
- | ExpiryTooSoon !ByteString
- | IncorrectOrUnknownPaymentDetails !MilliSatoshi !Word32
- | FinalIncorrectCltvExpiry !Word32
- | FinalIncorrectHtlcAmount !MilliSatoshi
- | ChannelDisabled !Word16 !ByteString
- | ExpiryTooFar
- | InvalidOnionPayload !(Maybe (Word64, Word16))
- | MppTimeout
- | InvalidOnionBlinding !OnionHash
- | UnknownFailure !Word16 !ByteString
- data OnionHash
- onion_hash :: ByteString -> Maybe OnionHash
- un_onion_hash :: OnionHash -> ByteString
- failure_code :: Failure -> Word16
- is_badonion :: Failure -> Bool
- is_perm :: Failure -> Bool
- is_node :: Failure -> Bool
- is_update :: Failure -> Bool
- encode_failure_message :: FailureMessage -> Either EncodeError ByteString
- decode_failure_message :: ByteString -> Either DecodeError FailureMessage
- newtype ErrorPacket = ErrorPacket ByteString
- construct_error :: SharedSecret -> FailureMessage -> Either EncodeError ErrorPacket
- wrap_error :: SharedSecret -> ErrorPacket -> ErrorPacket
- unwrap_error :: [SharedSecret] -> ErrorPacket -> Attribution
- data Attribution
- data DecodeError
- data EncodeError
Keys
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
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
un_shared_secret :: SharedSecret -> ByteString Source #
The bytes of a SharedSecret.
Onion packets
data OnionPacket Source #
An onion packet (onion_packet): 1366 bytes on the wire.
Constructors
| OnionPacket | |
Fields
| |
Instances
data HopPayloads Source #
The 1300-byte hop_payloads field of an onion packet.
Instances
| NFData HopPayloads Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: HopPayloads -> () # | |||||
| Generic HopPayloads Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show HopPayloads Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> HopPayloads -> ShowS # show :: HopPayloads -> String # showList :: [HopPayloads] -> ShowS # | |||||
| Eq HopPayloads Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep HopPayloads Source # | |||||
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
un_hop_payloads :: HopPayloads -> ByteString Source #
The bytes of HopPayloads.
A 32-byte HMAC.
Instances
| NFData Hmac32 Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| Generic Hmac32 Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show Hmac32 Source # | |||||
| Eq Hmac32 Source # | |||||
| type Rep Hmac32 Source # | |||||
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
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
| NFData HopPayload Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: HopPayload -> () # | |||||
| Generic HopPayload Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show HopPayload Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> HopPayload -> ShowS # show :: HopPayload -> String # showList :: [HopPayload] -> ShowS # | |||||
| Eq HopPayload Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep HopPayload Source # | |||||
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 hpRight "\STX\STX\ETX\232"
data PaymentData Source #
The payment_data record of a final hop's payload.
Constructors
| PaymentData | |
Fields | |
Instances
| NFData PaymentData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: PaymentData -> () # | |||||
| Generic PaymentData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show PaymentData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> PaymentData -> ShowS # show :: PaymentData -> String # showList :: [PaymentData] -> ShowS # | |||||
| Eq PaymentData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep PaymentData Source # | |||||
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 #
Instances
| NFData PaymentSecret Source # | |
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: PaymentSecret -> () # | |
| Show PaymentSecret Source # | |
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> PaymentSecret -> ShowS # show :: PaymentSecret -> String # showList :: [PaymentSecret] -> ShowS # | |
| Eq PaymentSecret Source # | |
Defined in Lightning.Protocol.BOLT4.Types Methods (==) :: PaymentSecret -> PaymentSecret -> Bool # (/=) :: PaymentSecret -> PaymentSecret -> Bool # | |
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
un_payment_secret :: PaymentSecret -> ByteString Source #
The bytes of a PaymentSecret.
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 hpRight "\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
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 | |
Fields
| |
Instances
| NFData Hop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct | |||||
| Generic Hop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct Associated Types
| |||||
| Show Hop Source # | |||||
| Eq Hop Source # | |||||
| type Rep Hop Source # | |||||
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 sss1
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
| NFData ConstructError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct Methods rnf :: ConstructError -> () # | |||||
| Generic ConstructError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct Associated Types
Methods from :: ConstructError -> Rep ConstructError x # to :: Rep ConstructError x -> ConstructError # | |||||
| Show ConstructError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct Methods showsPrec :: Int -> ConstructError -> ShowS # show :: ConstructError -> String # showList :: [ConstructError] -> ShowS # | |||||
| Eq ConstructError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Construct Methods (==) :: ConstructError -> ConstructError -> Bool # (/=) :: ConstructError -> ConstructError -> Bool # | |||||
| type Rep ConstructError Source # | |||||
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
| NFData ProcessResult Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods rnf :: ProcessResult -> () # | |||||
| Generic ProcessResult Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Associated Types
| |||||
| Show ProcessResult Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods showsPrec :: Int -> ProcessResult -> ShowS # show :: ProcessResult -> String # showList :: [ProcessResult] -> ShowS # | |||||
| Eq ProcessResult Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods (==) :: ProcessResult -> ProcessResult -> Bool # (/=) :: ProcessResult -> ProcessResult -> Bool # | |||||
| type Rep ProcessResult Source # | |||||
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
| NFData ForwardInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods rnf :: ForwardInfo -> () # | |||||
| Generic ForwardInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Associated Types
| |||||
| Show ForwardInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods showsPrec :: Int -> ForwardInfo -> ShowS # show :: ForwardInfo -> String # showList :: [ForwardInfo] -> ShowS # | |||||
| Eq ForwardInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process | |||||
| type Rep ForwardInfo Source # | |||||
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
| NFData ReceiveInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods rnf :: ReceiveInfo -> () # | |||||
| Generic ReceiveInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Associated Types
| |||||
| Show ReceiveInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process Methods showsPrec :: Int -> ReceiveInfo -> ShowS # show :: ReceiveInfo -> String # showList :: [ReceiveInfo] -> ShowS # | |||||
| Eq ReceiveInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Process | |||||
| type Rep ReceiveInfo Source # | |||||
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
| NFData BlindedInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: BlindedInfo -> () # | |||||
| Generic BlindedInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show BlindedInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> BlindedInfo -> ShowS # show :: BlindedInfo -> String # showList :: [BlindedInfo] -> ShowS # | |||||
| Eq BlindedInfo Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep BlindedInfo Source # | |||||
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
|
| InvalidPayload !DecodeError | the payload is not a valid |
| InvalidPathKey | the path key is not a valid point |
| UnexpectedPathKey | a path key was given with no |
| MissingPathKey |
|
| InvalidRecipientData | the |
Instances
| NFData ProcessError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: ProcessError -> () # | |||||
| Generic ProcessError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show ProcessError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> ProcessError -> ShowS # show :: ProcessError -> String # showList :: [ProcessError] -> ShowS # | |||||
| Eq ProcessError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep ProcessError Source # | |||||
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
| NFData BlindedPath Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: BlindedPath -> () # | |||||
| Generic BlindedPath Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show BlindedPath Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> BlindedPath -> ShowS # show :: BlindedPath -> String # showList :: [BlindedPath] -> ShowS # | |||||
| Eq BlindedPath Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep BlindedPath Source # | |||||
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
| NFData BlindedHop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: BlindedHop -> () # | |||||
| Generic BlindedHop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show BlindedHop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> BlindedHop -> ShowS # show :: BlindedHop -> String # showList :: [BlindedHop] -> ShowS # | |||||
| Eq BlindedHop Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep BlindedHop Source # | |||||
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 meTrue>>>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
| NFData BlindingError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Blinding Methods rnf :: BlindingError -> () # | |||||
| Generic BlindingError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Blinding Associated Types
| |||||
| Show BlindingError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Blinding Methods showsPrec :: Int -> BlindingError -> ShowS # show :: BlindingError -> String # showList :: [BlindingError] -> ShowS # | |||||
| Eq BlindingError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Blinding Methods (==) :: BlindingError -> BlindingError -> Bool # (/=) :: BlindingError -> BlindingError -> Bool # | |||||
| type Rep BlindingError Source # | |||||
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
| NFData BlindedHopData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: BlindedHopData -> () # | |||||
| Generic BlindedHopData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
Methods from :: BlindedHopData -> Rep BlindedHopData x # to :: Rep BlindedHopData x -> BlindedHopData # | |||||
| Show BlindedHopData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> BlindedHopData -> ShowS # show :: BlindedHopData -> String # showList :: [BlindedHopData] -> ShowS # | |||||
| Eq BlindedHopData Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods (==) :: BlindedHopData -> BlindedHopData -> Bool # (/=) :: BlindedHopData -> BlindedHopData -> Bool # | |||||
| type Rep BlindedHopData Source # | |||||
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 bhdRight "\ACK\apath id"
data PaymentRelay Source #
The payment_relay record of BlindedHopData.
Constructors
| PaymentRelay | |
Fields | |
Instances
| NFData PaymentRelay Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: PaymentRelay -> () # | |||||
| Generic PaymentRelay Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show PaymentRelay Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> PaymentRelay -> ShowS # show :: PaymentRelay -> String # showList :: [PaymentRelay] -> ShowS # | |||||
| Eq PaymentRelay Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep PaymentRelay Source # | |||||
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.
Constructors
| PaymentConstraints | |
Fields | |
Instances
| NFData PaymentConstraints Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: PaymentConstraints -> () # | |||||
| Generic PaymentConstraints Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
Methods from :: PaymentConstraints -> Rep PaymentConstraints x # to :: Rep PaymentConstraints x -> PaymentConstraints # | |||||
| Show PaymentConstraints Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> PaymentConstraints -> ShowS # show :: PaymentConstraints -> String # showList :: [PaymentConstraints] -> ShowS # | |||||
| Eq PaymentConstraints Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods (==) :: PaymentConstraints -> PaymentConstraints -> Bool # (/=) :: PaymentConstraints -> PaymentConstraints -> Bool # | |||||
| type Rep PaymentConstraints Source # | |||||
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 | |
Fields
| |
Instances
| NFData FailureMessage Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: FailureMessage -> () # | |||||
| Generic FailureMessage Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
Methods from :: FailureMessage -> Rep FailureMessage x # to :: Rep FailureMessage x -> FailureMessage # | |||||
| Show FailureMessage Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> FailureMessage -> ShowS # show :: FailureMessage -> String # showList :: [FailureMessage] -> ShowS # | |||||
| Eq FailureMessage Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods (==) :: FailureMessage -> FailureMessage -> Bool # (/=) :: FailureMessage -> FailureMessage -> Bool # | |||||
| type Rep FailureMessage Source # | |||||
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))) | |||||
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: |
| InvalidOnionHmac !OnionHash | BADONION|PERM|5: |
| InvalidOnionKey !OnionHash | BADONION|PERM|6: |
| TemporaryChannelFailure !ByteString | UPDATE|7: |
| PermanentChannelFailure | PERM|8 |
| RequiredChannelFeatureMissing | PERM|9 |
| UnknownNextPeer | PERM|10 |
| AmountBelowMinimum !MilliSatoshi !ByteString | UPDATE|11: |
| FeeInsufficient !MilliSatoshi !ByteString | UPDATE|12: |
| IncorrectCltvExpiry !Word32 !ByteString | UPDATE|13: |
| ExpiryTooSoon !ByteString | UPDATE|14: |
| IncorrectOrUnknownPaymentDetails !MilliSatoshi !Word32 | PERM|15: |
| FinalIncorrectCltvExpiry !Word32 | 18: |
| FinalIncorrectHtlcAmount !MilliSatoshi | 19: |
| ChannelDisabled !Word16 !ByteString | UPDATE|20: |
| ExpiryTooFar | 21 |
| InvalidOnionPayload !(Maybe (Word64, Word16)) | PERM|22: the optional |
| MppTimeout | 23 |
| InvalidOnionBlinding !OnionHash | BADONION|PERM|24: |
| UnknownFailure !Word16 !ByteString | a failure code not defined above, and the bytes following it |
Instances
| NFData Failure Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| Generic Failure Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show Failure Source # | |||||
| Eq Failure Source # | |||||
| type Rep Failure Source # | |||||
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))))))) | |||||
A 32-byte sha256_of_onion.
Instances
| NFData OnionHash Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| Generic OnionHash Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show OnionHash Source # | |||||
| Eq OnionHash Source # | |||||
| type Rep OnionHash Source # | |||||
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
un_onion_hash :: OnionHash -> ByteString Source #
The bytes of an OnionHash.
failure_code :: Failure -> Word16 Source #
The failure_code of a Failure.
>>>failure_code TemporaryNodeFailure8194>>>failure_code (UnknownFailure 0x1234 mempty)4660
is_badonion :: Failure -> Bool Source #
Is the BADONION flag (0x8000) set: was the onion unparsable?
>>>is_badonion TemporaryNodeFailureFalse
is_perm :: Failure -> Bool Source #
Is the PERM flag (0x4000) set: is the failure permanent?
>>>is_perm PermanentNodeFailureTrue
is_node :: Failure -> Bool Source #
Is the NODE flag (0x2000) set: is it a node (not channel) failure?
>>>is_node TemporaryNodeFailureTrue
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
| NFData ErrorPacket Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Methods rnf :: ErrorPacket -> () # | |||||
| Generic ErrorPacket Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Associated Types
| |||||
| Show ErrorPacket Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Methods showsPrec :: Int -> ErrorPacket -> ShowS # show :: ErrorPacket -> String # showList :: [ErrorPacket] -> ShowS # | |||||
| Eq ErrorPacket Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error | |||||
| type Rep ErrorPacket Source # | |||||
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 pkt292
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 fmTrue>>>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
| NFData Attribution Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Methods rnf :: Attribution -> () # | |||||
| Generic Attribution Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Associated Types
| |||||
| Show Attribution Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error Methods showsPrec :: Int -> Attribution -> ShowS # show :: Attribution -> String # showList :: [Attribution] -> ShowS # | |||||
| Eq Attribution Source # | |||||
Defined in Lightning.Protocol.BOLT4.Error | |||||
| type Rep Attribution Source # | |||||
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
| NFData DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: DecodeError -> () # | |||||
| Generic DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |||||
| Eq DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep DecodeError Source # | |||||
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
| NFData EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods rnf :: EncodeError -> () # | |||||
| Generic EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Associated Types
| |||||
| Show EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types Methods showsPrec :: Int -> EncodeError -> ShowS # show :: EncodeError -> String # showList :: [EncodeError] -> ShowS # | |||||
| Eq EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||
| type Rep EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT4.Types | |||||