| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Lightning.Protocol.BOLT1.TLV
Description
TLV (Type-Length-Value) format for BOLT #1.
Synopsis
- data TlvRecord = TlvRecord {
- tlvType :: !Word64
- tlvValue :: !ByteString
- data TlvStream
- tlvStream :: [TlvRecord] -> Maybe TlvStream
- unsafeTlvStream :: [TlvRecord] -> TlvStream
- data TlvError
- encodeTlvRecord :: TlvRecord -> ByteString
- encodeTlvStream :: TlvStream -> ByteString
- decodeTlvStream :: ByteString -> Either TlvError TlvStream
- decodeTlvStreamWith :: (Word64 -> Bool) -> ByteString -> Either TlvError TlvStream
- decodeTlvStreamRaw :: ByteString -> Either TlvError TlvStream
- data InitTlv
- parseInitTlvs :: TlvStream -> Either TlvError [InitTlv]
- encodeInitTlvs :: [InitTlv] -> TlvStream
- data ChainHash
- chainHash :: ByteString -> Maybe ChainHash
- unChainHash :: ChainHash -> ByteString
TLV types
A single TLV record.
Constructors
| TlvRecord | |
Fields
| |
Instances
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))))) | |||||
TLV encoding
encodeTlvRecord :: TlvRecord -> ByteString Source #
Encode a TLV record.
encodeTlvStream :: TlvStream -> ByteString Source #
Encode a TLV stream.
TLV decoding
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 TLV types
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))) | |||||
encodeInitTlvs :: [InitTlv] -> TlvStream Source #
Encode init TLVs to a TLV stream.
Re-exports
A chain hash (32-byte hash identifying a blockchain).
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 # | |||||
| 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.