ppad-bolt1-0.0.1: Base protocol per BOLT #1
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Lightning.Protocol.BOLT1

Description

Base protocol for the Lightning Network, per BOLT #1.

Synopsis

Message types

data Message Source #

All BOLT #1 messages.

Instances

Instances details
NFData Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Message -> () #

Generic Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

from :: Message -> Rep Message x #

to :: Rep Message x -> Message #

Show Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

data MsgType Source #

BOLT #1 message type codes.

Instances

Instances details
NFData MsgType Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: MsgType -> () #

Generic MsgType Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep MsgType 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep MsgType = D1 ('MetaData "MsgType" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (((C1 ('MetaCons "MsgInit" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgError" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MsgPing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgPong" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MsgWarning" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgPeerStorage" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MsgPeerStorageRet" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgUnknown" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)))))

Methods

from :: MsgType -> Rep MsgType x #

to :: Rep MsgType x -> MsgType #

Show MsgType Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq MsgType Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep MsgType Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep MsgType = D1 ('MetaData "MsgType" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (((C1 ('MetaCons "MsgInit" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgError" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MsgPing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgPong" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MsgWarning" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgPeerStorage" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MsgPeerStorageRet" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MsgUnknown" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)))))

msgTypeWord :: MsgType -> Word16 Source #

Get the numeric type code for a message type.

Channel identifiers

data ChannelId Source #

A 32-byte channel identifier.

Use channelId to construct, which validates the length. Use allChannels for connection-level errors (all-zeros channel ID).

Instances

Instances details
NFData ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: ChannelId -> () #

Generic ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep ChannelId 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep ChannelId = D1 ('MetaData "ChannelId" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "ChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep ChannelId = D1 ('MetaData "ChannelId" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "ChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

channelId :: ByteString -> Maybe ChannelId Source #

Construct a ChannelId from a 32-byte ByteString.

Returns Nothing if the input is not exactly 32 bytes.

>>> channelId (BS.replicate 32 0x00)
Just (ChannelId "\NUL\NUL...")
>>> channelId "too short"
Nothing

allChannels :: ChannelId Source #

The all-zeros channel ID, used for connection-level errors.

Per BOLT #1, setting channel_id to all zeros means the error applies to the connection rather than a specific channel.

Setup messages

data Init Source #

The init message (type 16).

Instances

Instances details
NFData Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Init -> () #

Generic Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Init 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Init = D1 ('MetaData "Init" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Init" 'PrefixI 'True) (S1 ('MetaSel ('Just "initGlobalFeatures") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: (S1 ('MetaSel ('Just "initFeatures") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "initTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [InitTlv]))))

Methods

from :: Init -> Rep Init x #

to :: Rep Init x -> Init #

Show Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Init -> ShowS #

show :: Init -> String #

showList :: [Init] -> ShowS #

Eq Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Init = D1 ('MetaData "Init" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Init" 'PrefixI 'True) (S1 ('MetaSel ('Just "initGlobalFeatures") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: (S1 ('MetaSel ('Just "initFeatures") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "initTlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [InitTlv]))))

data Error Source #

The error message (type 17).

Constructors

Error 

Instances

Instances details
NFData Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Error -> () #

Generic Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Error 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Error = D1 ('MetaData "Error" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Error" 'PrefixI 'True) (S1 ('MetaSel ('Just "errorChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: S1 ('MetaSel ('Just "errorData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Error -> Rep Error x #

to :: Rep Error x -> Error #

Show Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Eq Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Error = D1 ('MetaData "Error" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Error" 'PrefixI 'True) (S1 ('MetaSel ('Just "errorChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: S1 ('MetaSel ('Just "errorData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

data Warning Source #

The warning message (type 1).

Instances

Instances details
NFData Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Warning -> () #

Generic Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Warning 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Warning = D1 ('MetaData "Warning" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Warning" 'PrefixI 'True) (S1 ('MetaSel ('Just "warningChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: S1 ('MetaSel ('Just "warningData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Warning -> Rep Warning x #

to :: Rep Warning x -> Warning #

Show Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Warning = D1 ('MetaData "Warning" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Warning" 'PrefixI 'True) (S1 ('MetaSel ('Just "warningChannelId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: S1 ('MetaSel ('Just "warningData") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Control messages

data Ping Source #

The ping message (type 18).

Constructors

Ping 

Instances

Instances details
NFData Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Ping -> () #

Generic Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Ping 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Ping = D1 ('MetaData "Ping" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Ping" 'PrefixI 'True) (S1 ('MetaSel ('Just "pingNumPongBytes") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Just "pingIgnored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Ping -> Rep Ping x #

to :: Rep Ping x -> Ping #

Show Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Ping -> ShowS #

show :: Ping -> String #

showList :: [Ping] -> ShowS #

Eq Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Ping = D1 ('MetaData "Ping" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Ping" 'PrefixI 'True) (S1 ('MetaSel ('Just "pingNumPongBytes") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Just "pingIgnored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

data Pong Source #

The pong message (type 19).

Constructors

Pong 

Instances

Instances details
NFData Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Pong -> () #

Generic Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Pong 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Pong = D1 ('MetaData "Pong" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Pong" 'PrefixI 'True) (S1 ('MetaSel ('Just "pongIgnored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Pong -> Rep Pong x #

to :: Rep Pong x -> Pong #

Show Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Pong -> ShowS #

show :: Pong -> String #

showList :: [Pong] -> ShowS #

Eq Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

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

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

type Rep Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Pong = D1 ('MetaData "Pong" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Pong" 'PrefixI 'True) (S1 ('MetaSel ('Just "pongIgnored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Peer storage

data PeerStorage Source #

The peer_storage message (type 7).

Constructors

PeerStorage 

Instances

Instances details
NFData PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: PeerStorage -> () #

Generic PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep PeerStorage 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorage = D1 ('MetaData "PeerStorage" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "PeerStorage" 'PrefixI 'True) (S1 ('MetaSel ('Just "peerStorageBlob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))
Show PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorage = D1 ('MetaData "PeerStorage" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "PeerStorage" 'PrefixI 'True) (S1 ('MetaSel ('Just "peerStorageBlob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

data PeerStorageRetrieval Source #

The peer_storage_retrieval message (type 9).

Instances

Instances details
NFData PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: PeerStorageRetrieval -> () #

Generic PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep PeerStorageRetrieval 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorageRetrieval = D1 ('MetaData "PeerStorageRetrieval" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "PeerStorageRetrieval" 'PrefixI 'True) (S1 ('MetaSel ('Just "peerStorageRetrievalBlob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))
Show PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorageRetrieval = D1 ('MetaData "PeerStorageRetrieval" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "PeerStorageRetrieval" 'PrefixI 'True) (S1 ('MetaSel ('Just "peerStorageRetrievalBlob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

TLV

data TlvRecord Source #

A single TLV record.

Constructors

TlvRecord 

Instances

Instances details
NFData TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvRecord -> () #

Generic TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvRecord 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvRecord = D1 ('MetaData "TlvRecord" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" '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.BOLT1.TLV

Eq TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvRecord = D1 ('MetaData "TlvRecord" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "TlvRecord" 'PrefixI 'True) (S1 ('MetaSel ('Just "tlvType") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64) :*: S1 ('MetaSel ('Just "tlvValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

data TlvStream Source #

A TLV stream (series of TLV records).

Instances

Instances details
NFData TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvStream -> () #

Generic TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvStream 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream = D1 ('MetaData "TlvStream" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "TlvStream" 'PrefixI 'True) (S1 ('MetaSel ('Just "unTlvStream") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TlvRecord])))
Show TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream = D1 ('MetaData "TlvStream" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "TlvStream" 'PrefixI 'True) (S1 ('MetaSel ('Just "unTlvStream") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TlvRecord])))

tlvStream :: [TlvRecord] -> Maybe TlvStream Source #

Smart constructor for TlvStream that validates records are strictly increasing by type.

Returns Nothing if types are not strictly increasing.

unsafeTlvStream :: [TlvRecord] -> TlvStream Source #

Unsafe constructor for TlvStream that skips validation.

Use only when ordering is already guaranteed (e.g., in decode functions).

data TlvError Source #

TLV decoding errors.

Instances

Instances details
NFData TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvError -> () #

Generic TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvError 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvError = D1 ('MetaData "TlvError" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) ((C1 ('MetaCons "TlvNonMinimalEncoding" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TlvNotStrictlyIncreasing" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TlvLengthExceedsBounds" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "TlvUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "TlvInvalidKnownType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)))))

Methods

from :: TlvError -> Rep TlvError x #

to :: Rep TlvError x -> TlvError #

Show TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvError = D1 ('MetaData "TlvError" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) ((C1 ('MetaCons "TlvNonMinimalEncoding" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TlvNotStrictlyIncreasing" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TlvLengthExceedsBounds" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "TlvUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "TlvInvalidKnownType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)))))

encodeTlvStream :: TlvStream -> ByteString Source #

Encode a TLV stream.

decodeTlvStream :: ByteString -> Either TlvError TlvStream Source #

Decode a TLV stream with BOLT #1 init_tlvs validation.

This uses the default known types for init messages (1 and 3). For other contexts, use decodeTlvStreamWith with an appropriate predicate.

decodeTlvStreamWith Source #

Arguments

:: (Word64 -> Bool)

Predicate: is this type known?

-> ByteString 
-> Either TlvError TlvStream 

Decode a TLV stream with configurable known-type predicate.

Per BOLT #1: - Types must be strictly increasing - Unknown even types cause failure - Unknown odd types are skipped

The predicate determines which types are "known" for the context.

decodeTlvStreamRaw :: ByteString -> Either TlvError TlvStream Source #

Decode a TLV stream without any known-type validation.

This decoder only enforces structural validity: - Types must be strictly increasing - Lengths must not exceed bounds

All records are returned regardless of type. Note: this does NOT enforce the BOLT #1 unknown-even-type rule. Use decodeTlvStreamWith with an appropriate predicate for spec-compliant parsing.

Init TLVs

data InitTlv Source #

TLV records for init message.

Constructors

InitNetworks ![ChainHash]

Type 1: chain hashes (32 bytes each)

InitRemoteAddr !ByteString

Type 3: remote address

Instances

Instances details
NFData InitTlv Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: InitTlv -> () #

Generic InitTlv Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep InitTlv 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep InitTlv = D1 ('MetaData "InitTlv" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "InitNetworks" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [ChainHash])) :+: C1 ('MetaCons "InitRemoteAddr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: InitTlv -> Rep InitTlv x #

to :: Rep InitTlv x -> InitTlv #

Show InitTlv Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq InitTlv Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

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

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

type Rep InitTlv Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep InitTlv = D1 ('MetaData "InitTlv" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "InitNetworks" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [ChainHash])) :+: C1 ('MetaCons "InitRemoteAddr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

data ChainHash Source #

A chain hash (32-byte hash identifying a blockchain).

Instances

Instances details
NFData ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: ChainHash -> () #

Generic ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep ChainHash 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ChainHash = D1 ('MetaData "ChainHash" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "ChainHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

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

chainHash :: ByteString -> Maybe ChainHash Source #

Construct a chain hash from a 32-byte bytestring.

Returns Nothing if the input is not exactly 32 bytes.

unChainHash :: ChainHash -> ByteString Source #

Extract the raw bytes from a chain hash.

Message envelope

data Envelope Source #

A complete message envelope with type, payload, and optional extension.

Instances

Instances details
NFData Envelope Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Envelope -> () #

Generic Envelope Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Envelope 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Envelope = D1 ('MetaData "Envelope" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Envelope" 'PrefixI 'True) (S1 ('MetaSel ('Just "envType") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MsgType) :*: (S1 ('MetaSel ('Just "envPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "envExtension") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe TlvStream)))))

Methods

from :: Envelope -> Rep Envelope x #

to :: Rep Envelope x -> Envelope #

Show Envelope Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq Envelope Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Envelope Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep Envelope = D1 ('MetaData "Envelope" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "Envelope" 'PrefixI 'True) (S1 ('MetaSel ('Just "envType") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MsgType) :*: (S1 ('MetaSel ('Just "envPayload") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "envExtension") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe TlvStream)))))

Encoding

data EncodeError Source #

Encoding errors.

Constructors

EncodeLengthOverflow

Field length exceeds u16 max (65535 bytes)

EncodeMessageTooLarge

Total message size exceeds 65535 bytes

Instances

Instances details
NFData EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Methods

rnf :: EncodeError -> () #

Generic EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Associated Types

type Rep EncodeError 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep EncodeError = D1 ('MetaData "EncodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "EncodeLengthOverflow" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EncodeMessageTooLarge" 'PrefixI 'False) (U1 :: Type -> Type))
Show EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Eq EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep EncodeError = D1 ('MetaData "EncodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) (C1 ('MetaCons "EncodeLengthOverflow" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EncodeMessageTooLarge" 'PrefixI 'False) (U1 :: Type -> Type))

encodeMessage :: Message -> Either EncodeError ByteString Source #

Encode a message to its payload bytes.

Checks that the payload does not exceed 65533 bytes (the maximum possible given the 2-byte type field and 65535-byte message limit).

encodeEnvelope :: Message -> Maybe TlvStream -> Either EncodeError ByteString Source #

Encode a message as a complete envelope (type + payload + extension).

Per BOLT #1, the total message size must not exceed 65535 bytes.

Decoding

data DecodeError Source #

Decoding errors.

Instances

Instances details
NFData DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Methods

rnf :: DecodeError -> () #

Generic DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Associated Types

type Rep DecodeError 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) ((C1 ('MetaCons "DecodeInsufficientBytes" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidLength" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)))) :+: ((C1 ('MetaCons "DecodeUnknownOddType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)) :+: C1 ('MetaCons "DecodeTlvError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError))) :+: (C1 ('MetaCons "DecodeInvalidChannelId" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeInvalidExtension" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError)))))
Show DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Eq DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'False) ((C1 ('MetaCons "DecodeInsufficientBytes" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidLength" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)))) :+: ((C1 ('MetaCons "DecodeUnknownOddType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)) :+: C1 ('MetaCons "DecodeTlvError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError))) :+: (C1 ('MetaCons "DecodeInvalidChannelId" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeInvalidExtension" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError)))))

decodeMessage :: MsgType -> ByteString -> Either DecodeError (Message, ByteString) Source #

Decode a message from its type and payload.

Returns the decoded message and any remaining bytes (for extensions). For unknown types, returns an appropriate error.

decodeEnvelope :: ByteString -> Either DecodeError (Maybe Message, Maybe TlvStream) Source #

Decode a complete envelope (type + payload + optional extension).

Per BOLT #1: - Unknown odd message types are ignored (returns Nothing for message) - Unknown even message types cause connection close (returns error) - Invalid extension TLV causes connection close (returns error)

This uses the default policy of treating all extension TLV types as unknown. Use decodeEnvelopeWith for configurable extension handling.

Returns the decoded message (if known) and any extension TLVs.

decodeEnvelopeWith Source #

Arguments

:: (Word64 -> Bool)

Predicate: is this extension TLV type known?

-> ByteString 
-> Either DecodeError (Maybe Message, Maybe TlvStream) 

Decode a complete envelope with configurable extension TLV handling.

The predicate determines which extension TLV types are "known" and should be preserved. Unknown even types cause failure; unknown odd types are skipped.

Use decodeEnvelopeWith (const False) to reject all even extension types (the default behavior of decodeEnvelope).

Use decodeEnvelopeWith (const True) to accept all extension types.

Primitive encoding

encodeU16 :: Word16 -> ByteString Source #

Encode a 16-bit unsigned integer (big-endian).

>>> encodeU16 0x0102
"\SOH\STX"

encodeU32 :: Word32 -> ByteString Source #

Encode a 32-bit unsigned integer (big-endian).

>>> encodeU32 0x01020304
"\SOH\STX\ETX\EOT"

encodeU64 :: Word64 -> ByteString Source #

Encode a 64-bit unsigned integer (big-endian).

>>> encodeU64 0x0102030405060708
"\SOH\STX\ETX\EOT\ENQ\ACK\a\b"

encodeS8 :: Int8 -> ByteString Source #

Encode an 8-bit signed integer.

>>> encodeS8 42
"*"
>>> encodeS8 (-42)
"\214"

encodeS16 :: Int16 -> ByteString Source #

Encode a 16-bit signed integer (big-endian two's complement).

>>> encodeS16 0x0102
"\SOH\STX"
>>> encodeS16 (-1)
"\255\255"

encodeS32 :: Int32 -> ByteString Source #

Encode a 32-bit signed integer (big-endian two's complement).

>>> encodeS32 0x01020304
"\SOH\STX\ETX\EOT"
>>> encodeS32 (-1)
"\255\255\255\255"

encodeS64 :: Int64 -> ByteString Source #

Encode a 64-bit signed integer (big-endian two's complement).

>>> encodeS64 0x0102030405060708
"\SOH\STX\ETX\EOT\ENQ\ACK\a\b"
>>> encodeS64 (-1)
"\255\255\255\255\255\255\255\255"

encodeTu16 :: Word16 -> ByteString Source #

Encode a truncated 16-bit unsigned integer (0-2 bytes).

Leading zeros are omitted per BOLT #1. Zero encodes to empty.

>>> encodeTu16 0
""
>>> encodeTu16 1
"\SOH"
>>> encodeTu16 256
"\SOH\NUL"

encodeTu32 :: Word32 -> ByteString Source #

Encode a truncated 32-bit unsigned integer (0-4 bytes).

Leading zeros are omitted per BOLT #1. Zero encodes to empty.

>>> encodeTu32 0
""
>>> encodeTu32 1
"\SOH"
>>> encodeTu32 0x010000
"\SOH\NUL\NUL"

encodeTu64 :: Word64 -> ByteString Source #

Encode a truncated 64-bit unsigned integer (0-8 bytes).

Leading zeros are omitted per BOLT #1. Zero encodes to empty.

>>> encodeTu64 0
""
>>> encodeTu64 1
"\SOH"
>>> encodeTu64 0x0100000000
"\SOH\NUL\NUL\NUL\NUL"

encodeMinSigned :: Int64 -> ByteString Source #

Encode a signed 64-bit integer using minimal bytes.

Uses the smallest number of bytes that can represent the value in two's complement. Per BOLT #1 Appendix D test vectors.

>>> encodeMinSigned 0
"\NUL"
>>> encodeMinSigned 127
"\DEL"
>>> encodeMinSigned 128
"\NUL\128"
>>> encodeMinSigned (-1)
"\255"
>>> encodeMinSigned (-128)
"\128"
>>> encodeMinSigned (-129)
"\255\DEL"

encodeBigSize :: Word64 -> ByteString Source #

Encode a BigSize value (variable-length unsigned integer).

>>> encodeBigSize 0
"\NUL"
>>> encodeBigSize 252
"\252"
>>> encodeBigSize 253
"\253\NUL\253"
>>> encodeBigSize 65536
"\254\NUL\SOH\NUL\NUL"

Primitive decoding

decodeU16 :: ByteString -> Maybe (Word16, ByteString) Source #

Decode a 16-bit unsigned integer (big-endian).

decodeU32 :: ByteString -> Maybe (Word32, ByteString) Source #

Decode a 32-bit unsigned integer (big-endian).

decodeU64 :: ByteString -> Maybe (Word64, ByteString) Source #

Decode a 64-bit unsigned integer (big-endian).

decodeS8 :: ByteString -> Maybe (Int8, ByteString) Source #

Decode an 8-bit signed integer.

decodeS16 :: ByteString -> Maybe (Int16, ByteString) Source #

Decode a 16-bit signed integer (big-endian two's complement).

decodeS32 :: ByteString -> Maybe (Int32, ByteString) Source #

Decode a 32-bit signed integer (big-endian two's complement).

decodeS64 :: ByteString -> Maybe (Int64, ByteString) Source #

Decode a 64-bit signed integer (big-endian two's complement).

decodeTu16 :: Int -> ByteString -> Maybe (Word16, ByteString) Source #

Decode a truncated 16-bit unsigned integer (0-2 bytes).

Returns Nothing if the encoding is non-minimal (has leading zeros).

decodeTu32 :: Int -> ByteString -> Maybe (Word32, ByteString) Source #

Decode a truncated 32-bit unsigned integer (0-4 bytes).

Returns Nothing if the encoding is non-minimal (has leading zeros).

decodeTu64 :: Int -> ByteString -> Maybe (Word64, ByteString) Source #

Decode a truncated 64-bit unsigned integer (0-8 bytes).

Returns Nothing if the encoding is non-minimal (has leading zeros).

decodeMinSigned :: Int -> ByteString -> Maybe (Int64, ByteString) Source #

Decode a minimal signed integer (1, 2, 4, or 8 bytes).

Validates that the encoding is minimal: the value could not be represented in fewer bytes. Per BOLT #1 Appendix D test vectors.

decodeBigSize :: ByteString -> Maybe (Word64, ByteString) Source #

Decode a BigSize value with minimality check.