| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Lightning.Protocol.BOLT4.Codec
Description
Serialization and deserialization for BOLT4 types.
Synopsis
- encodeBigSize :: Word64 -> ByteString
- decodeBigSize :: ByteString -> Maybe (Word64, ByteString)
- bigSizeLen :: Word64 -> Int
- encodeTlv :: TlvRecord -> ByteString
- decodeTlv :: ByteString -> Maybe (TlvRecord, ByteString)
- decodeTlvStream :: ByteString -> Maybe [TlvRecord]
- encodeTlvStream :: [TlvRecord] -> ByteString
- encodeOnionPacket :: OnionPacket -> ByteString
- decodeOnionPacket :: ByteString -> Maybe OnionPacket
- encodeHopPayload :: HopPayload -> ByteString
- decodeHopPayload :: ByteString -> Maybe HopPayload
- encodeShortChannelId :: ShortChannelId -> ByteString
- decodeShortChannelId :: ByteString -> Maybe ShortChannelId
- encodeFailureMessage :: FailureMessage -> ByteString
- decodeFailureMessage :: ByteString -> Maybe FailureMessage
- toStrict :: Builder -> ByteString
- word16BE :: ByteString -> Word16
- word32BE :: ByteString -> Word32
- encodeWord64TU :: Word64 -> ByteString
- decodeWord64TU :: ByteString -> Maybe Word64
- encodeWord32TU :: Word32 -> ByteString
- decodeWord32TU :: ByteString -> Maybe Word32
BigSize encoding
encodeBigSize :: Word64 -> ByteString Source #
Encode integer as BigSize.
- 0-0xFC: 1 byte
- 0xFD-0xFFFF: 0xFD ++ 2 bytes BE
- 0x10000-0xFFFFFFFF: 0xFE ++ 4 bytes BE
- larger: 0xFF ++ 8 bytes BE
decodeBigSize :: ByteString -> Maybe (Word64, ByteString) Source #
Decode BigSize, returning (value, remaining bytes).
bigSizeLen :: Word64 -> Int Source #
Get encoded size of a BigSize value without encoding.
TLV encoding
encodeTlv :: TlvRecord -> ByteString Source #
Encode a TLV record.
decodeTlv :: ByteString -> Maybe (TlvRecord, ByteString) Source #
Decode a single TLV record.
decodeTlvStream :: ByteString -> Maybe [TlvRecord] Source #
Decode a TLV stream (sequence of records). Validates strictly increasing type order.
encodeTlvStream :: [TlvRecord] -> ByteString Source #
Encode a TLV stream from records. Records must be sorted by type, no duplicates.
Packet serialization
encodeOnionPacket :: OnionPacket -> ByteString Source #
Serialize OnionPacket to 1366 bytes.
decodeOnionPacket :: ByteString -> Maybe OnionPacket Source #
Parse OnionPacket from 1366 bytes.
encodeHopPayload :: HopPayload -> ByteString Source #
Encode HopPayload to bytes (without length prefix).
decodeHopPayload :: ByteString -> Maybe HopPayload Source #
Decode HopPayload from bytes.
ShortChannelId
encodeShortChannelId :: ShortChannelId -> ByteString Source #
Encode ShortChannelId to 8 bytes. Format: 3 bytes block || 3 bytes tx || 2 bytes output (all BE)
decodeShortChannelId :: ByteString -> Maybe ShortChannelId Source #
Decode ShortChannelId from 8 bytes.
Failure messages
encodeFailureMessage :: FailureMessage -> ByteString Source #
Encode failure message.
decodeFailureMessage :: ByteString -> Maybe FailureMessage Source #
Decode failure message.
Internal helpers (for Blinding)
toStrict :: Builder -> ByteString Source #
Convert Builder to strict ByteString.
word16BE :: ByteString -> Word16 Source #
Decode big-endian Word16.
word32BE :: ByteString -> Word32 Source #
Decode big-endian Word32.
encodeWord64TU :: Word64 -> ByteString Source #
Encode Word64 as truncated unsigned (minimal bytes).
decodeWord64TU :: ByteString -> Maybe Word64 Source #
Decode truncated unsigned to Word64.
encodeWord32TU :: Word32 -> ByteString Source #
Encode Word32 as truncated unsigned.
decodeWord32TU :: ByteString -> Maybe Word32 Source #
Decode truncated unsigned to Word32.