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

Lightning.Protocol.BOLT4.Types

Description

Core data types for BOLT4 onion routing.

Synopsis

Packet types

data OnionPacket Source #

Complete onion packet (1366 bytes).

Constructors

OnionPacket 

Fields

Instances

Instances details
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "OnionPacket" 'PrefixI 'True) ((S1 ('MetaSel ('Just "opVersion") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8) :*: S1 ('MetaSel ('Just "opEphemeralKey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :*: (S1 ('MetaSel ('Just "opHopPayloads") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "opHmac") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "OnionPacket" 'PrefixI 'True) ((S1 ('MetaSel ('Just "opVersion") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word8) :*: S1 ('MetaSel ('Just "opEphemeralKey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)) :*: (S1 ('MetaSel ('Just "opHopPayloads") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "opHmac") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))

data HopPayload Source #

Parsed hop payload after decryption.

Constructors

HopPayload 

Fields

Instances

Instances details
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "HopPayload" 'PrefixI 'True) ((S1 ('MetaSel ('Just "hpAmtToForward") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word64)) :*: (S1 ('MetaSel ('Just "hpOutgoingCltv") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word32)) :*: S1 ('MetaSel ('Just "hpShortChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId)))) :*: ((S1 ('MetaSel ('Just "hpPaymentData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentData)) :*: S1 ('MetaSel ('Just "hpEncryptedData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString))) :*: (S1 ('MetaSel ('Just "hpCurrentPathKey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "hpUnknownTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TlvRecord])))))
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "HopPayload" 'PrefixI 'True) ((S1 ('MetaSel ('Just "hpAmtToForward") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word64)) :*: (S1 ('MetaSel ('Just "hpOutgoingCltv") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Word32)) :*: S1 ('MetaSel ('Just "hpShortChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ShortChannelId)))) :*: ((S1 ('MetaSel ('Just "hpPaymentData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe PaymentData)) :*: S1 ('MetaSel ('Just "hpEncryptedData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString))) :*: (S1 ('MetaSel ('Just "hpCurrentPathKey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "hpUnknownTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TlvRecord])))))

newtype ShortChannelId Source #

A short channel identifier (8 bytes packed as Word64).

Encodes block height (3 bytes), transaction index (3 bytes), and output index (2 bytes).

Constructors

ShortChannelId Word64 

Instances

Instances details
NFData ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: ShortChannelId -> () #

Generic ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ShortChannelId = D1 ('MetaData "ShortChannelId" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-9kk6j4MaRHW2ecFq1ls24D" 'True) (C1 ('MetaCons "ShortChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Show ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ShortChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ShortChannelId = D1 ('MetaData "ShortChannelId" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-9kk6j4MaRHW2ecFq1ls24D" 'True) (C1 ('MetaCons "ShortChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

shortChannelId Source #

Arguments

:: Word32

Block height (24 bits max)

-> Word32

Transaction index (24 bits max)

-> Word16

Output index

-> Maybe ShortChannelId 

Construct a ShortChannelId from components.

Returns Nothing if block height or tx index exceed 24 bits.

scidBlockHeight :: ShortChannelId -> Word32 Source #

Extract the block height from a ShortChannelId.

scidTxIndex :: ShortChannelId -> Word32 Source #

Extract the transaction index from a ShortChannelId.

scidOutputIndex :: ShortChannelId -> Word16 Source #

Extract the output index from a ShortChannelId.

scidWord64 :: ShortChannelId -> Word64 Source #

Extract the packed Word64 from a ShortChannelId.

data PaymentData Source #

Payment data for final hop (TLV type 8).

Constructors

PaymentData 

Instances

Instances details
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "PaymentData" 'PrefixI 'True) (S1 ('MetaSel ('Just "pdPaymentSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "pdTotalMsat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64)))
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "PaymentData" 'PrefixI 'True) (S1 ('MetaSel ('Just "pdPaymentSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "pdTotalMsat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64)))

data TlvRecord Source #

Generic TLV record for unknown/extension types.

Constructors

TlvRecord 

Instances

Instances details
Generic TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep TlvRecord 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep TlvRecord = D1 ('MetaData "TlvRecord" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "TlvRecord" 'PrefixI 'True) (S1 ('MetaSel ('Just "tlvType") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64) :*: S1 ('MetaSel ('Just "tlvValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))
Show TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep TlvRecord = D1 ('MetaData "TlvRecord" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "TlvRecord" 'PrefixI 'True) (S1 ('MetaSel ('Just "tlvType") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64) :*: S1 ('MetaSel ('Just "tlvValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Error types

data FailureMessage Source #

Failure message from intermediate or final node.

Constructors

FailureMessage 

Instances

Instances details
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "FailureMessage" 'PrefixI 'True) (S1 ('MetaSel ('Just "fmCode") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FailureCode) :*: (S1 ('MetaSel ('Just "fmData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "fmTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TlvRecord]))))
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.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "FailureMessage" 'PrefixI 'True) (S1 ('MetaSel ('Just "fmCode") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FailureCode) :*: (S1 ('MetaSel ('Just "fmData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "fmTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TlvRecord]))))

newtype FailureCode Source #

2-byte failure code with flag bits.

Constructors

FailureCode Word16 

Instances

Instances details
Show FailureCode Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq FailureCode Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Flag bits

pattern BADONION :: Word16 Source #

BADONION flag (0x8000): error was in parsing the onion.

pattern PERM :: Word16 Source #

PERM flag (0x4000): permanent failure, do not retry.

pattern NODE :: Word16 Source #

NODE flag (0x2000): node failure rather than channel.

pattern UPDATE :: Word16 Source #

UPDATE flag (0x1000): channel update is attached.

Common failure codes

pattern InvalidRealm :: FailureCode Source #

Invalid realm byte in onion.

pattern TemporaryNodeFailure :: FailureCode Source #

Temporary node failure.

pattern PermanentNodeFailure :: FailureCode Source #

Permanent node failure.

pattern RequiredNodeFeatureMissing :: FailureCode Source #

Required node feature missing.

pattern InvalidOnionVersion :: FailureCode Source #

Invalid onion version.

pattern InvalidOnionHmac :: FailureCode Source #

Invalid HMAC in onion.

pattern InvalidOnionKey :: FailureCode Source #

Invalid ephemeral key in onion.

pattern TemporaryChannelFailure :: FailureCode Source #

Temporary channel failure.

pattern PermanentChannelFailure :: FailureCode Source #

Permanent channel failure.

pattern AmountBelowMinimum :: FailureCode Source #

Amount below minimum for channel.

pattern FeeInsufficient :: FailureCode Source #

Fee insufficient.

pattern IncorrectCltvExpiry :: FailureCode Source #

Incorrect CLTV expiry.

pattern ExpiryTooSoon :: FailureCode Source #

Expiry too soon.

pattern IncorrectOrUnknownPaymentDetails :: FailureCode Source #

Payment details incorrect or unknown.

pattern FinalIncorrectCltvExpiry :: FailureCode Source #

Final incorrect CLTV expiry.

pattern FinalIncorrectHtlcAmount :: FailureCode Source #

Final incorrect HTLC amount.

pattern ChannelDisabled :: FailureCode Source #

Channel disabled.

pattern ExpiryTooFar :: FailureCode Source #

Expiry too far.

pattern InvalidOnionPayload :: FailureCode Source #

Invalid onion payload.

pattern MppTimeout :: FailureCode Source #

MPP timeout.

Processing results

data ProcessResult Source #

Result of processing an onion packet.

Constructors

Forward !ForwardInfo

Forward to next hop

Receive !ReceiveInfo

Final destination reached

Instances

Instances details
Generic ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep ProcessResult 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessResult = D1 ('MetaData "ProcessResult" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" '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.Types

Eq ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessResult Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ProcessResult = D1 ('MetaData "ProcessResult" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" '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 #

Information for forwarding to next hop.

Constructors

ForwardInfo 

Fields

Instances

Instances details
Generic ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep ForwardInfo 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ForwardInfo = D1 ('MetaData "ForwardInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "ForwardInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "fiNextPacket") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionPacket) :*: (S1 ('MetaSel ('Just "fiPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "fiSharedSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))
Show ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ForwardInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ForwardInfo = D1 ('MetaData "ForwardInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "ForwardInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "fiNextPacket") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OnionPacket) :*: (S1 ('MetaSel ('Just "fiPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "fiSharedSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))

data ReceiveInfo Source #

Information for receiving at final destination.

Instances

Instances details
Generic ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Associated Types

type Rep ReceiveInfo 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ReceiveInfo = D1 ('MetaData "ReceiveInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "ReceiveInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "riPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "riSharedSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))
Show ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

Eq ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ReceiveInfo Source # 
Instance details

Defined in Lightning.Protocol.BOLT4.Types

type Rep ReceiveInfo = D1 ('MetaData "ReceiveInfo" "Lightning.Protocol.BOLT4.Types" "ppad-bolt4-0.0.1-JIey8hf1eNsLERYHqjRDfZ" 'False) (C1 ('MetaCons "ReceiveInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "riPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HopPayload) :*: S1 ('MetaSel ('Just "riSharedSecret") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Constants

onionPacketSize :: Int Source #

Total onion packet size (1366 bytes).

hopPayloadsSize :: Int Source #

Hop payloads section size (1300 bytes).

hmacSize :: Int Source #

HMAC size (32 bytes).

pubkeySize :: Int Source #

Compressed public key size (33 bytes).

versionByte :: Word8 Source #

Version byte for onion packets.

maxPayloadSize :: Int Source #

Maximum payload size (1300 - 32 - 1 = 1267 bytes).