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.TLV

Description

TLV (Type-Length-Value) format for BOLT #1.

Synopsis

TLV types

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)))))

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.

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 TLV types

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)))

parseInitTlvs :: TlvStream -> Either TlvError [InitTlv] Source #

Parse init TLVs from a TLV stream.

encodeInitTlvs :: [InitTlv] -> TlvStream Source #

Encode init TLVs to a TLV stream.

Re-exports

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.