| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT1
Description
Base protocol for the Lightning Network, per BOLT #1.
Synopsis
- data Message
- data MsgType
- msgTypeWord :: MsgType -> Word16
- newtype ChannelId = ChannelId ByteString
- channelId :: ByteString -> Maybe ChannelId
- unChannelId :: ChannelId -> ByteString
- allChannels :: ChannelId
- newtype Signature = Signature ByteString
- signature :: ByteString -> Maybe Signature
- unSignature :: Signature -> ByteString
- newtype Point = Point ByteString
- point :: ByteString -> Maybe Point
- unPoint :: Point -> ByteString
- newtype PaymentHash = PaymentHash ByteString
- paymentHash :: ByteString -> Maybe PaymentHash
- unPaymentHash :: PaymentHash -> ByteString
- newtype PaymentPreimage = PaymentPreimage ByteString
- paymentPreimage :: ByteString -> Maybe PaymentPreimage
- unPaymentPreimage :: PaymentPreimage -> ByteString
- newtype PerCommitmentSecret = PerCommitmentSecret ByteString
- perCommitmentSecret :: ByteString -> Maybe PerCommitmentSecret
- unPerCommitmentSecret :: PerCommitmentSecret -> ByteString
- newtype ShortChannelId = ShortChannelId Word64
- shortChannelId :: Word32 -> Word32 -> Word16 -> Maybe ShortChannelId
- scidWord64 :: ShortChannelId -> Word64
- scidBlockHeight :: ShortChannelId -> Word32
- scidTxIndex :: ShortChannelId -> Word32
- scidOutputIndex :: ShortChannelId -> Word16
- newtype Satoshi = Satoshi {}
- newtype MilliSatoshi = MilliSatoshi {}
- satToMsat :: Satoshi -> MilliSatoshi
- msatToSat :: MilliSatoshi -> Satoshi
- data Init = Init {
- initGlobalFeatures :: !ByteString
- initFeatures :: !ByteString
- initTlvs :: ![InitTlv]
- data Error = Error {}
- data Warning = Warning {}
- data Ping = Ping {}
- data Pong = Pong {}
- data PeerStorage = PeerStorage {}
- data PeerStorageRetrieval = PeerStorageRetrieval {}
- data TlvRecord = TlvRecord {
- tlvType :: !Word64
- tlvValue :: !ByteString
- data TlvStream
- tlvStream :: [TlvRecord] -> Maybe TlvStream
- unsafeTlvStream :: [TlvRecord] -> TlvStream
- data TlvError
- encodeTlvStream :: TlvStream -> ByteString
- decodeTlvStream :: ByteString -> Either TlvError TlvStream
- decodeTlvStreamWith :: (Word64 -> Bool) -> ByteString -> Either TlvError TlvStream
- decodeTlvStreamRaw :: ByteString -> Either TlvError TlvStream
- data InitTlv
- newtype ChainHash = ChainHash ByteString
- chainHash :: ByteString -> Maybe ChainHash
- unChainHash :: ChainHash -> ByteString
- data Envelope = Envelope {
- envType :: !MsgType
- envPayload :: !ByteString
- envExtension :: !(Maybe TlvStream)
- data EncodeError
- encodeMessage :: Message -> Either EncodeError ByteString
- encodeEnvelope :: Message -> Maybe TlvStream -> Either EncodeError ByteString
- data DecodeError
- decodeMessage :: MsgType -> ByteString -> Either DecodeError (Message, ByteString)
- decodeEnvelope :: ByteString -> Either DecodeError (Maybe Message, Maybe TlvStream)
- decodeEnvelopeWith :: (Word64 -> Bool) -> ByteString -> Either DecodeError (Maybe Message, Maybe TlvStream)
- encodeU16 :: Word16 -> ByteString
- encodeU32 :: Word32 -> ByteString
- encodeU64 :: Word64 -> ByteString
- encodeS8 :: Int8 -> ByteString
- encodeS16 :: Int16 -> ByteString
- encodeS32 :: Int32 -> ByteString
- encodeS64 :: Int64 -> ByteString
- encodeTu16 :: Word16 -> ByteString
- encodeTu32 :: Word32 -> ByteString
- encodeTu64 :: Word64 -> ByteString
- encodeMinSigned :: Int64 -> ByteString
- encodeBigSize :: Word64 -> ByteString
- decodeU16 :: ByteString -> Maybe (Word16, ByteString)
- decodeU32 :: ByteString -> Maybe (Word32, ByteString)
- decodeU64 :: ByteString -> Maybe (Word64, ByteString)
- decodeS8 :: ByteString -> Maybe (Int8, ByteString)
- decodeS16 :: ByteString -> Maybe (Int16, ByteString)
- decodeS32 :: ByteString -> Maybe (Int32, ByteString)
- decodeS64 :: ByteString -> Maybe (Int64, ByteString)
- decodeTu16 :: Int -> ByteString -> Maybe (Word16, ByteString)
- decodeTu32 :: Int -> ByteString -> Maybe (Word32, ByteString)
- decodeTu64 :: Int -> ByteString -> Maybe (Word64, ByteString)
- decodeMinSigned :: Int -> ByteString -> Maybe (Int64, ByteString)
- decodeBigSize :: ByteString -> Maybe (Word64, ByteString)
Message types
All BOLT #1 messages.
Constructors
| MsgInitVal !Init | |
| MsgErrorVal !Error | |
| MsgWarningVal !Warning | |
| MsgPingVal !Ping | |
| MsgPongVal !Pong | |
| MsgPeerStorageVal !PeerStorage | |
| MsgPeerStorageRetrievalVal !PeerStorageRetrieval |
Instances
BOLT #1 message type codes.
Constructors
| MsgInit | 16 |
| MsgError | 17 |
| MsgPing | 18 |
| MsgPong | 19 |
| MsgWarning | 1 |
| MsgPeerStorage | 7 |
| MsgPeerStorageRet | 9 |
| MsgUnknown !Word16 | Unknown type |
Instances
| NFData MsgType Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic MsgType Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show MsgType Source # | |||||
| Eq MsgType Source # | |||||
| type Rep MsgType Source # | |||||
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
A 32-byte channel identifier.
Constructors
| ChannelId ByteString |
Instances
| NFData ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show ChannelId Source # | |||||
| Eq ChannelId Source # | |||||
| Ord ChannelId Source # | |||||
| type Rep ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep ChannelId = D1 ('MetaData "ChannelId" "Lightning.Protocol.BOLT1.Prim" "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.
unChannelId :: ChannelId -> ByteString Source #
Extract the raw bytes from a ChannelId.
allChannels :: ChannelId Source #
The all-zeros channel ID (connection-level errors).
Signatures and keys
A 64-byte compact ECDSA signature.
Constructors
| Signature ByteString |
Instances
| NFData Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show Signature Source # | |||||
| Eq Signature Source # | |||||
| Ord Signature Source # | |||||
| type Rep Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep Signature = D1 ('MetaData "Signature" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "Signature" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
signature :: ByteString -> Maybe Signature Source #
Construct a Signature from a 64-byte ByteString.
Returns Nothing if the input is not exactly 64 bytes.
unSignature :: Signature -> ByteString Source #
Extract the raw bytes from a Signature.
A 33-byte compressed secp256k1 public key.
Constructors
| Point ByteString |
Instances
| NFData Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show Point Source # | |||||
| Eq Point Source # | |||||
| Ord Point Source # | |||||
| type Rep Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep Point = D1 ('MetaData "Point" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "Point" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
point :: ByteString -> Maybe Point Source #
Construct a Point from a 33-byte ByteString.
Returns Nothing if the input is not exactly 33 bytes.
Payment types
newtype PaymentHash Source #
A 32-byte SHA256 payment hash.
Constructors
| PaymentHash ByteString |
Instances
| NFData PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PaymentHash -> () # | |||||
| Generic PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PaymentHash -> ShowS # show :: PaymentHash -> String # showList :: [PaymentHash] -> ShowS # | |||||
| Eq PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Ord PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: PaymentHash -> PaymentHash -> Ordering # (<) :: PaymentHash -> PaymentHash -> Bool # (<=) :: PaymentHash -> PaymentHash -> Bool # (>) :: PaymentHash -> PaymentHash -> Bool # (>=) :: PaymentHash -> PaymentHash -> Bool # max :: PaymentHash -> PaymentHash -> PaymentHash # min :: PaymentHash -> PaymentHash -> PaymentHash # | |||||
| type Rep PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep PaymentHash = D1 ('MetaData "PaymentHash" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "PaymentHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
paymentHash :: ByteString -> Maybe PaymentHash Source #
Construct a PaymentHash from a 32-byte ByteString.
Returns Nothing if the input is not exactly 32 bytes.
unPaymentHash :: PaymentHash -> ByteString Source #
Extract the raw bytes from a PaymentHash.
newtype PaymentPreimage Source #
A 32-byte payment preimage.
Constructors
| PaymentPreimage ByteString |
Instances
| NFData PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PaymentPreimage -> () # | |||||
| Generic PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
Methods from :: PaymentPreimage -> Rep PaymentPreimage x # to :: Rep PaymentPreimage x -> PaymentPreimage # | |||||
| Show PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PaymentPreimage -> ShowS # show :: PaymentPreimage -> String # showList :: [PaymentPreimage] -> ShowS # | |||||
| Eq PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: PaymentPreimage -> PaymentPreimage -> Bool # (/=) :: PaymentPreimage -> PaymentPreimage -> Bool # | |||||
| Ord PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: PaymentPreimage -> PaymentPreimage -> Ordering # (<) :: PaymentPreimage -> PaymentPreimage -> Bool # (<=) :: PaymentPreimage -> PaymentPreimage -> Bool # (>) :: PaymentPreimage -> PaymentPreimage -> Bool # (>=) :: PaymentPreimage -> PaymentPreimage -> Bool # max :: PaymentPreimage -> PaymentPreimage -> PaymentPreimage # min :: PaymentPreimage -> PaymentPreimage -> PaymentPreimage # | |||||
| type Rep PaymentPreimage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep PaymentPreimage = D1 ('MetaData "PaymentPreimage" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "PaymentPreimage" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
paymentPreimage :: ByteString -> Maybe PaymentPreimage Source #
Construct a PaymentPreimage from a 32-byte ByteString.
Returns Nothing if the input is not exactly 32 bytes.
unPaymentPreimage :: PaymentPreimage -> ByteString Source #
Extract the raw bytes from a PaymentPreimage.
Per-commitment secret
newtype PerCommitmentSecret Source #
A 32-byte per-commitment secret.
Constructors
| PerCommitmentSecret ByteString |
Instances
| NFData PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PerCommitmentSecret -> () # | |||||
| Generic PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
Methods from :: PerCommitmentSecret -> Rep PerCommitmentSecret x # to :: Rep PerCommitmentSecret x -> PerCommitmentSecret # | |||||
| Show PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PerCommitmentSecret -> ShowS # show :: PerCommitmentSecret -> String # showList :: [PerCommitmentSecret] -> ShowS # | |||||
| Eq PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # (/=) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # | |||||
| Ord PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: PerCommitmentSecret -> PerCommitmentSecret -> Ordering # (<) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # (<=) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # (>) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # (>=) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # max :: PerCommitmentSecret -> PerCommitmentSecret -> PerCommitmentSecret # min :: PerCommitmentSecret -> PerCommitmentSecret -> PerCommitmentSecret # | |||||
| type Rep PerCommitmentSecret Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep PerCommitmentSecret = D1 ('MetaData "PerCommitmentSecret" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "PerCommitmentSecret" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
perCommitmentSecret :: ByteString -> Maybe PerCommitmentSecret Source #
Construct a PerCommitmentSecret from a 32-byte
ByteString.
Returns Nothing if the input is not exactly 32 bytes.
unPerCommitmentSecret :: PerCommitmentSecret -> ByteString Source #
Extract the raw bytes from a PerCommitmentSecret.
Short channel identifier
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
| NFData ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: ShortChannelId -> () # | |||||
| Generic ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
Methods from :: ShortChannelId -> Rep ShortChannelId x # to :: Rep ShortChannelId x -> ShortChannelId # | |||||
| Show ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> ShortChannelId -> ShowS # show :: ShortChannelId -> String # showList :: [ShortChannelId] -> ShowS # | |||||
| Eq ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: ShortChannelId -> ShortChannelId -> Bool # (/=) :: ShortChannelId -> ShortChannelId -> Bool # | |||||
| Ord ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: ShortChannelId -> ShortChannelId -> Ordering # (<) :: ShortChannelId -> ShortChannelId -> Bool # (<=) :: ShortChannelId -> ShortChannelId -> Bool # (>) :: ShortChannelId -> ShortChannelId -> Bool # (>=) :: ShortChannelId -> ShortChannelId -> Bool # max :: ShortChannelId -> ShortChannelId -> ShortChannelId # min :: ShortChannelId -> ShortChannelId -> ShortChannelId # | |||||
| type Rep ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep ShortChannelId = D1 ('MetaData "ShortChannelId" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "ShortChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) | |||||
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.
scidWord64 :: ShortChannelId -> Word64 Source #
Extract the packed Word64 from a ShortChannelId.
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.
Amounts
Amount in satoshis.
Instances
| NFData Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Enum Satoshi Source # | |||||
| Generic Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Num Satoshi Source # | |||||
| Integral Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Real Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods toRational :: Satoshi -> Rational # | |||||
| Show Satoshi Source # | |||||
| Eq Satoshi Source # | |||||
| Ord Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| type Rep Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
newtype MilliSatoshi Source #
Amount in millisatoshis.
Constructors
| MilliSatoshi | |
Fields | |
Instances
| NFData MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: MilliSatoshi -> () # | |||||
| Enum MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods succ :: MilliSatoshi -> MilliSatoshi # pred :: MilliSatoshi -> MilliSatoshi # toEnum :: Int -> MilliSatoshi # fromEnum :: MilliSatoshi -> Int # enumFrom :: MilliSatoshi -> [MilliSatoshi] # enumFromThen :: MilliSatoshi -> MilliSatoshi -> [MilliSatoshi] # enumFromTo :: MilliSatoshi -> MilliSatoshi -> [MilliSatoshi] # enumFromThenTo :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi -> [MilliSatoshi] # | |||||
| Generic MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Num MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods (+) :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # (-) :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # (*) :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # negate :: MilliSatoshi -> MilliSatoshi # abs :: MilliSatoshi -> MilliSatoshi # signum :: MilliSatoshi -> MilliSatoshi # fromInteger :: Integer -> MilliSatoshi # | |||||
| Integral MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods quot :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # rem :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # div :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # mod :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # quotRem :: MilliSatoshi -> MilliSatoshi -> (MilliSatoshi, MilliSatoshi) # divMod :: MilliSatoshi -> MilliSatoshi -> (MilliSatoshi, MilliSatoshi) # toInteger :: MilliSatoshi -> Integer # | |||||
| Real MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods toRational :: MilliSatoshi -> Rational # | |||||
| Show MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> MilliSatoshi -> ShowS # show :: MilliSatoshi -> String # showList :: [MilliSatoshi] -> ShowS # | |||||
| Eq MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Ord MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: MilliSatoshi -> MilliSatoshi -> Ordering # (<) :: MilliSatoshi -> MilliSatoshi -> Bool # (<=) :: MilliSatoshi -> MilliSatoshi -> Bool # (>) :: MilliSatoshi -> MilliSatoshi -> Bool # (>=) :: MilliSatoshi -> MilliSatoshi -> Bool # max :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # min :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # | |||||
| type Rep MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep MilliSatoshi = D1 ('MetaData "MilliSatoshi" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.0.1-3AI6PDE70OhJud7vB7rIZR" 'True) (C1 ('MetaCons "MilliSatoshi" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMilliSatoshi") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) | |||||
satToMsat :: Satoshi -> MilliSatoshi Source #
Convert Satoshi to MilliSatoshi.
msatToSat :: MilliSatoshi -> Satoshi Source #
Convert MilliSatoshi to Satoshi (rounds down).
Setup messages
The init message (type 16).
Constructors
| Init | |
Fields
| |
Instances
| NFData Init Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Init Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Init Source # | |||||
| Eq Init Source # | |||||
| type Rep Init Source # | |||||
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])))) | |||||
The error message (type 17).
Constructors
| Error | |
Fields
| |
Instances
| NFData Error Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Error Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Error Source # | |||||
| Eq Error Source # | |||||
| type Rep Error Source # | |||||
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))) | |||||
The warning message (type 1).
Constructors
| Warning | |
Fields | |
Instances
| NFData Warning Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Warning Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Warning Source # | |||||
| Eq Warning Source # | |||||
| type Rep Warning Source # | |||||
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
The ping message (type 18).
Constructors
| Ping | |
Fields
| |
Instances
| NFData Ping Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Ping Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Ping Source # | |||||
| Eq Ping Source # | |||||
| type Rep Ping Source # | |||||
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))) | |||||
The pong message (type 19).
Constructors
| Pong | |
Fields | |
Instances
| NFData Pong Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Pong Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Pong Source # | |||||
| Eq Pong Source # | |||||
| type Rep Pong Source # | |||||
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 | |
Fields | |
Instances
| NFData PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods rnf :: PeerStorage -> () # | |||||
| Generic PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods showsPrec :: Int -> PeerStorage -> ShowS # show :: PeerStorage -> String # showList :: [PeerStorage] -> ShowS # | |||||
| Eq PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| type Rep PeerStorage Source # | |||||
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).
Constructors
| PeerStorageRetrieval | |
Fields | |
Instances
| NFData PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods rnf :: PeerStorageRetrieval -> () # | |||||
| Generic PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
Methods from :: PeerStorageRetrieval -> Rep PeerStorageRetrieval x # to :: Rep PeerStorageRetrieval x -> PeerStorageRetrieval # | |||||
| Show PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods showsPrec :: Int -> PeerStorageRetrieval -> ShowS # show :: PeerStorageRetrieval -> String # showList :: [PeerStorageRetrieval] -> ShowS # | |||||
| Eq PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods (==) :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool # (/=) :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool # | |||||
| type Rep PeerStorageRetrieval Source # | |||||
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
A single TLV record.
Constructors
| TlvRecord | |
Fields
| |
Instances
| NFData TlvRecord Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvRecord Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvRecord Source # | |||||
| Eq TlvRecord Source # | |||||
| type Rep TlvRecord Source # | |||||
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))) | |||||
A TLV stream (series of TLV records).
Instances
| NFData TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvStream Source # | |||||
| Eq TlvStream Source # | |||||
| type Rep TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
unsafeTlvStream :: [TlvRecord] -> TlvStream Source #
Unsafe constructor for TlvStream that skips validation.
Use only when ordering is already guaranteed (e.g., in decode functions).
TLV decoding errors.
Constructors
| TlvNonMinimalEncoding | |
| TlvNotStrictlyIncreasing | |
| TlvLengthExceedsBounds | |
| TlvUnknownEvenType !Word64 | |
| TlvInvalidKnownType !Word64 |
Instances
| NFData TlvError Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvError Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvError Source # | |||||
| Eq TlvError Source # | |||||
| type Rep TlvError Source # | |||||
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.
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
TLV records for init message.
Constructors
| InitNetworks ![ChainHash] | Type 1: chain hashes (32 bytes each) |
| InitRemoteAddr !ByteString | Type 3: remote address |
Instances
| NFData InitTlv Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic InitTlv Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show InitTlv Source # | |||||
| Eq InitTlv Source # | |||||
| type Rep InitTlv Source # | |||||
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))) | |||||
A chain hash (32-byte hash identifying a blockchain).
Constructors
| ChainHash ByteString |
Instances
| NFData ChainHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic ChainHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show ChainHash Source # | |||||
| Eq ChainHash Source # | |||||
| Ord ChainHash Source # | |||||
| type Rep ChainHash Source # | |||||
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
A complete message envelope with type, payload, and optional extension.
Constructors
| Envelope | |
Fields
| |
Instances
| NFData Envelope Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Envelope Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Envelope Source # | |||||
| Eq Envelope Source # | |||||
| type Rep Envelope Source # | |||||
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
| NFData EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods rnf :: EncodeError -> () # | |||||
| Generic EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Associated Types
| |||||
| Show EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods showsPrec :: Int -> EncodeError -> ShowS # show :: EncodeError -> String # showList :: [EncodeError] -> ShowS # | |||||
| Eq EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec | |||||
| type Rep EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec | |||||
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.
Constructors
| DecodeInsufficientBytes | |
| DecodeInvalidLength | |
| DecodeUnknownEvenType !Word16 | |
| DecodeUnknownOddType !Word16 | |
| DecodeTlvError !TlvError | |
| DecodeInvalidChannelId | |
| DecodeInvalidExtension !TlvError |
Instances
| NFData DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods rnf :: DecodeError -> () # | |||||
| Generic DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Associated Types
| |||||
| Show DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |||||
| Eq DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec | |||||
| type Rep DecodeError Source # | |||||
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.
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.