bolt7

Routing gossip protocol, per BOLT #7 (docs.ppad.tech/bolt7).
git clone git://git.ppad.tech/bolt7.git
Log | Files | Refs | README | LICENSE

BOLT7.hs (3566B)


      1 {-# OPTIONS_HADDOCK prune #-}
      2 
      3 -- |
      4 -- Module: Lightning.Protocol.BOLT7
      5 -- Copyright: (c) 2025 Jared Tobin
      6 -- License: MIT
      7 -- Maintainer: Jared Tobin <jared@ppad.tech>
      8 --
      9 -- Routing gossip for the Lightning Network, per
     10 -- [BOLT #7](https://github.com/lightning/bolts/blob/master/07-routing-gossip.md):
     11 -- the gossip messages and queries, their signature digests and
     12 -- checksums, signature verification, and stateless validation.
     13 --
     14 -- Fundamental types (chain hashes, points, signatures, short channel
     15 -- ids, amounts, TLV streams) come from ppad-bolt1, and feature vectors
     16 -- from ppad-bolt9.
     17 --
     18 -- Decoders take a message payload, without its 2-byte type, and consume
     19 -- all of it. Every byte is kept, including unassigned flag bits,
     20 -- unknown address descriptors and unknown odd TLV records, so encoding
     21 -- a decoded message reproduces its payload exactly and its signatures
     22 -- still verify.
     23 
     24 module Lightning.Protocol.BOLT7 (
     25   -- * Messages
     26     Message(..)
     27   , message_type
     28   , ChannelAnnouncement(..)
     29   , NodeAnnouncement(..)
     30   , ChannelUpdate(..)
     31   , AnnouncementSignatures(..)
     32   , QueryShortChannelIds(..)
     33   , ReplyShortChannelIdsEnd(..)
     34   , QueryChannelRange(..)
     35   , ReplyChannelRange(..)
     36   , GossipTimestampFilter(..)
     37 
     38   -- * Encoding and decoding
     39   , encode_message
     40   , decode_message
     41   , EncodeError(..)
     42   , DecodeError(..)
     43 
     44   -- ** Payloads
     45   , encode_channel_announcement
     46   , decode_channel_announcement
     47   , encode_node_announcement
     48   , decode_node_announcement
     49   , encode_channel_update
     50   , decode_channel_update
     51   , encode_announcement_signatures
     52   , decode_announcement_signatures
     53   , encode_query_short_channel_ids
     54   , decode_query_short_channel_ids
     55   , encode_reply_short_channel_ids_end
     56   , decode_reply_short_channel_ids_end
     57   , encode_query_channel_range
     58   , decode_query_channel_range
     59   , encode_reply_channel_range
     60   , decode_reply_channel_range
     61   , encode_gossip_timestamp_filter
     62   , decode_gossip_timestamp_filter
     63 
     64   -- * Signatures and checksums
     65   , channel_announcement_hash
     66   , node_announcement_hash
     67   , channel_update_hash
     68   , verify_channel_announcement
     69   , verify_node_announcement
     70   , verify_channel_update
     71   , channel_update_checksum
     72 
     73   -- * Validation
     74   , ValidationError(..)
     75   , validate_channel_announcement
     76   , validate_node_announcement
     77   , validate_channel_update
     78   , validate_query_short_channel_ids
     79   , validate_query_channel_range
     80   , validate_reply_channel_range
     81 
     82   -- * channel_update flags
     83   , MessageFlags(..)
     84   , Forwarding(..)
     85   , message_flags
     86   , message_flags_forwarding
     87   , has_must_be_one
     88   , ChannelFlags(..)
     89   , Direction(..)
     90   , ChannelStatus(..)
     91   , channel_flags
     92   , channel_flags_direction
     93   , channel_flags_status
     94 
     95   -- * node_announcement fields
     96   , RgbColor(..)
     97   , Alias
     98   , alias
     99   , un_alias
    100 
    101   -- ** Addresses
    102   , Address(..)
    103   , usable_addresses
    104   , IPv4Addr
    105   , ipv4_addr
    106   , un_ipv4_addr
    107   , IPv6Addr
    108   , ipv6_addr
    109   , un_ipv6_addr
    110   , TorV2Addr
    111   , tor_v2_addr
    112   , un_tor_v2_addr
    113   , TorV3Addr
    114   , tor_v3_addr
    115   , un_tor_v3_addr
    116   , Hostname
    117   , hostname
    118   , un_hostname
    119   , is_ascii_hostname
    120 
    121   -- * Query fields
    122   , QueryFlags(..)
    123   , QueryFlag(..)
    124   , query_flags
    125   , has_query_flag
    126   , QueryOption(..)
    127   , QueryOptionFlag(..)
    128   , query_option
    129   , has_query_option
    130   , ChannelUpdateTimestamps(..)
    131   , ChannelUpdateChecksums(..)
    132 
    133   -- * Short channel ids
    134   , format_short_channel_id
    135   ) where
    136 
    137 import Lightning.Protocol.BOLT7.Codec
    138 import Lightning.Protocol.BOLT7.Hash
    139 import Lightning.Protocol.BOLT7.Messages
    140 import Lightning.Protocol.BOLT7.Types
    141 import Lightning.Protocol.BOLT7.Validate