ppad-bolt3-0.0.1: Bitcoin transaction formats per BOLT #3
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Lightning.Protocol.BOLT3

Description

Bitcoin transaction formats for the Lightning Network, per BOLT #3.

Overview

This library implements the transaction and script formats defined in BOLT #3, including:

  • Commitment transactions with to_local, to_remote, anchor, and HTLC outputs
  • HTLC-timeout and HTLC-success second-stage transactions
  • Closing transactions (legacy and option_simple_close)
  • Per-commitment key derivation and secret storage
  • Transaction serialization and parsing
  • Stateless validation

Quick Start

import Lightning.Protocol.BOLT3

-- Build a commitment transaction
let ctx = CommitmentContext { ... }
    tx = build_commitment_tx ctx

-- Serialize for signing
let bytes = encode_tx tx

-- Validate the transaction
case validate_commitment_tx dustLimit features tx of
  Right () -> putStrLn Valid
  Left err -> print err

Modules

Synopsis

Types

Monetary amounts

newtype Satoshi Source #

Amount in satoshis.

Constructors

Satoshi 

Fields

Instances

Instances details
Generic Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Satoshi 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Satoshi = D1 ('MetaData "Satoshi" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Satoshi" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSatoshi") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

Methods

from :: Satoshi -> Rep Satoshi x #

to :: Rep Satoshi x -> Satoshi #

Num Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Satoshi -> Satoshi -> Bool #

(/=) :: Satoshi -> Satoshi -> Bool #

Ord Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Satoshi = D1 ('MetaData "Satoshi" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Satoshi" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSatoshi") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

newtype MilliSatoshi Source #

Amount in millisatoshis.

Constructors

MilliSatoshi 

Instances

Instances details
Generic MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep MilliSatoshi 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep MilliSatoshi = D1 ('MetaData "MilliSatoshi" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "MilliSatoshi" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMilliSatoshi") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Num MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep MilliSatoshi = D1 ('MetaData "MilliSatoshi" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "MilliSatoshi" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMilliSatoshi") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

msat_to_sat :: MilliSatoshi -> Satoshi Source #

Convert millisatoshis to satoshis (rounds down).

sat_to_msat :: Satoshi -> MilliSatoshi Source #

Convert satoshis to millisatoshis.

Keys and points

newtype Pubkey Source #

Compressed public key (33 bytes).

Constructors

Pubkey 

Fields

Instances

Instances details
Generic Pubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Pubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Pubkey = D1 ('MetaData "Pubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Pubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: Pubkey -> Rep Pubkey x #

to :: Rep Pubkey x -> Pubkey #

Show Pubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Pubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Pubkey -> Pubkey -> Bool #

(/=) :: Pubkey -> Pubkey -> Bool #

Ord Pubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Pubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Pubkey = D1 ('MetaData "Pubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Pubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

pubkey :: ByteString -> Maybe Pubkey Source #

Parse a 33-byte compressed public key.

Returns Nothing if the input is not exactly 33 bytes.

>>> pubkey (BS.replicate 33 0x02)
Just (Pubkey ...)
>>> pubkey (BS.replicate 32 0x02)
Nothing

newtype Seckey Source #

Secret key (32 bytes).

Constructors

Seckey 

Fields

Instances

Instances details
Generic Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Seckey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Seckey = D1 ('MetaData "Seckey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Seckey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSeckey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: Seckey -> Rep Seckey x #

to :: Rep Seckey x -> Seckey #

Show Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Seckey -> Seckey -> Bool #

(/=) :: Seckey -> Seckey -> Bool #

type Rep Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Seckey = D1 ('MetaData "Seckey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Seckey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSeckey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

seckey :: ByteString -> Maybe Seckey Source #

Parse a 32-byte secret key.

Returns Nothing if the input is not exactly 32 bytes.

newtype Point Source #

Elliptic curve point (33-byte compressed form).

Constructors

Point 

Fields

Instances

Instances details
Generic Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Point 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Point = D1 ('MetaData "Point" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: Point -> Rep Point x #

to :: Rep Point x -> Point #

Show Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

showsPrec :: Int -> Point -> ShowS #

show :: Point -> String #

showList :: [Point] -> ShowS #

Eq Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Point -> Point -> Bool #

(/=) :: Point -> Point -> Bool #

Ord Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

compare :: Point -> Point -> Ordering #

(<) :: Point -> Point -> Bool #

(<=) :: Point -> Point -> Bool #

(>) :: Point -> Point -> Bool #

(>=) :: Point -> Point -> Bool #

max :: Point -> Point -> Point #

min :: Point -> Point -> Point #

type Rep Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Point = D1 ('MetaData "Point" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

point :: ByteString -> Maybe Point Source #

Parse a 33-byte elliptic curve point.

Returns Nothing if the input is not exactly 33 bytes.

Hashes

newtype PaymentHash Source #

Payment hash (32 bytes, SHA256 of preimage).

Constructors

PaymentHash 

Instances

Instances details
Generic PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep PaymentHash 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentHash = D1 ('MetaData "PaymentHash" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentHash = D1 ('MetaData "PaymentHash" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

payment_hash :: ByteString -> Maybe PaymentHash Source #

Parse a 32-byte payment hash.

Returns Nothing if the input is not exactly 32 bytes.

newtype PaymentPreimage Source #

Payment preimage (32 bytes).

Instances

Instances details
Generic PaymentPreimage Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep PaymentPreimage 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentPreimage = D1 ('MetaData "PaymentPreimage" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentPreimage" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentPreimage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show PaymentPreimage Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq PaymentPreimage Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentPreimage Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentPreimage = D1 ('MetaData "PaymentPreimage" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentPreimage" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentPreimage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

payment_preimage :: ByteString -> Maybe PaymentPreimage Source #

Parse a 32-byte payment preimage.

Returns Nothing if the input is not exactly 32 bytes.

Transaction primitives

newtype TxId Source #

Transaction ID (32 bytes, little-endian hash).

Constructors

TxId 

Fields

Instances

Instances details
Generic TxId Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep TxId 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep TxId = D1 ('MetaData "TxId" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "TxId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unTxId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: TxId -> Rep TxId x #

to :: Rep TxId x -> TxId #

Show TxId Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

showsPrec :: Int -> TxId -> ShowS #

show :: TxId -> String #

showList :: [TxId] -> ShowS #

Eq TxId Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: TxId -> TxId -> Bool #

(/=) :: TxId -> TxId -> Bool #

Ord TxId Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

compare :: TxId -> TxId -> Ordering #

(<) :: TxId -> TxId -> Bool #

(<=) :: TxId -> TxId -> Bool #

(>) :: TxId -> TxId -> Bool #

(>=) :: TxId -> TxId -> Bool #

max :: TxId -> TxId -> TxId #

min :: TxId -> TxId -> TxId #

type Rep TxId Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep TxId = D1 ('MetaData "TxId" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "TxId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unTxId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

txid :: ByteString -> Maybe TxId Source #

Parse a 32-byte transaction ID.

Returns Nothing if the input is not exactly 32 bytes.

data Outpoint Source #

Transaction outpoint (txid + output index).

Constructors

Outpoint 

Instances

Instances details
Generic Outpoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Outpoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Outpoint = D1 ('MetaData "Outpoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "Outpoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "outpoint_txid") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "outpoint_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))

Methods

from :: Outpoint -> Rep Outpoint x #

to :: Rep Outpoint x -> Outpoint #

Show Outpoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Outpoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord Outpoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Outpoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Outpoint = D1 ('MetaData "Outpoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "Outpoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "outpoint_txid") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "outpoint_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))

newtype Sequence Source #

Transaction input sequence number.

Constructors

Sequence 

Fields

Instances

Instances details
Generic Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Sequence 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Sequence = D1 ('MetaData "Sequence" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Sequence" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSequence") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Methods

from :: Sequence -> Rep Sequence x #

to :: Rep Sequence x -> Sequence #

Num Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Sequence = D1 ('MetaData "Sequence" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Sequence" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSequence") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

newtype Locktime Source #

Transaction locktime.

Constructors

Locktime 

Fields

Instances

Instances details
Generic Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Locktime 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Locktime = D1 ('MetaData "Locktime" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Locktime" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocktime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Methods

from :: Locktime -> Rep Locktime x #

to :: Rep Locktime x -> Locktime #

Num Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Locktime = D1 ('MetaData "Locktime" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Locktime" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocktime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Channel parameters

newtype CommitmentNumber Source #

48-bit commitment number.

Instances

Instances details
Generic CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep CommitmentNumber 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentNumber = D1 ('MetaData "CommitmentNumber" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "CommitmentNumber" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCommitmentNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Num CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentNumber = D1 ('MetaData "CommitmentNumber" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "CommitmentNumber" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCommitmentNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

commitment_number :: Word64 -> Maybe CommitmentNumber Source #

Parse a 48-bit commitment number.

Returns Nothing if the value exceeds 2^48 - 1.

newtype ToSelfDelay Source #

CSV delay for to_local outputs.

Constructors

ToSelfDelay 

Instances

Instances details
Generic ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep ToSelfDelay 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ToSelfDelay = D1 ('MetaData "ToSelfDelay" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "ToSelfDelay" 'PrefixI 'True) (S1 ('MetaSel ('Just "unToSelfDelay") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))
Num ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ToSelfDelay = D1 ('MetaData "ToSelfDelay" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "ToSelfDelay" 'PrefixI 'True) (S1 ('MetaSel ('Just "unToSelfDelay") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))

newtype CltvExpiry Source #

CLTV expiry for HTLCs.

Constructors

CltvExpiry 

Fields

Instances

Instances details
Generic CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep CltvExpiry 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CltvExpiry = D1 ('MetaData "CltvExpiry" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "CltvExpiry" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCltvExpiry") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))
Num CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CltvExpiry = D1 ('MetaData "CltvExpiry" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "CltvExpiry" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCltvExpiry") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

newtype DustLimit Source #

Dust limit threshold.

Constructors

DustLimit 

Fields

Instances

Instances details
Generic DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep DustLimit 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DustLimit = D1 ('MetaData "DustLimit" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "DustLimit" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDustLimit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Satoshi)))
Show DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DustLimit = D1 ('MetaData "DustLimit" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "DustLimit" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDustLimit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Satoshi)))

newtype FeeratePerKw Source #

Fee rate in satoshis per 1000 weight units.

Constructors

FeeratePerKw 

Instances

Instances details
Generic FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep FeeratePerKw 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FeeratePerKw = D1 ('MetaData "FeeratePerKw" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "FeeratePerKw" 'PrefixI 'True) (S1 ('MetaSel ('Just "unFeeratePerKw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))
Num FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Show FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FeeratePerKw = D1 ('MetaData "FeeratePerKw" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "FeeratePerKw" 'PrefixI 'True) (S1 ('MetaSel ('Just "unFeeratePerKw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

HTLC types

data HTLC Source #

HTLC output details.

NOTE: No Ord instance is provided. BOLT #3 requires output ordering by amount then scriptPubKey, but scriptPubKey depends on derived keys which are not available here. Use sort_outputs in Tx module for proper BIP69 output ordering.

Instances

Instances details
Generic HTLC Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep HTLC 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HTLC = D1 ('MetaData "HTLC" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLC" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htlc_direction") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLCDirection) :*: S1 ('MetaSel ('Just "htlc_amount_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "htlc_payment_hash") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 PaymentHash) :*: S1 ('MetaSel ('Just "htlc_cltv_expiry") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry))))

Methods

from :: HTLC -> Rep HTLC x #

to :: Rep HTLC x -> HTLC #

Show HTLC Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

showsPrec :: Int -> HTLC -> ShowS #

show :: HTLC -> String #

showList :: [HTLC] -> ShowS #

Eq HTLC Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: HTLC -> HTLC -> Bool #

(/=) :: HTLC -> HTLC -> Bool #

type Rep HTLC Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HTLC = D1 ('MetaData "HTLC" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLC" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htlc_direction") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLCDirection) :*: S1 ('MetaSel ('Just "htlc_amount_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "htlc_payment_hash") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 PaymentHash) :*: S1 ('MetaSel ('Just "htlc_cltv_expiry") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry))))

data HTLCDirection Source #

Direction of an HTLC from the commitment tx owner's perspective.

Constructors

HTLCOffered

We offered this HTLC (outgoing)

HTLCReceived

We received this HTLC (incoming)

Instances

Instances details
Generic HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep HTLCDirection 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HTLCDirection = D1 ('MetaData "HTLCDirection" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCOffered" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "HTLCReceived" 'PrefixI 'False) (U1 :: Type -> Type))
Show HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HTLCDirection = D1 ('MetaData "HTLCDirection" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCOffered" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "HTLCReceived" 'PrefixI 'False) (U1 :: Type -> Type))

Basepoints

data Basepoints Source #

Collection of all basepoints for one party.

Instances

Instances details
Generic Basepoints Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Basepoints 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Basepoints = D1 ('MetaData "Basepoints" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "Basepoints" 'PrefixI 'True) ((S1 ('MetaSel ('Just "bp_revocation") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationBasepoint) :*: S1 ('MetaSel ('Just "bp_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint)) :*: (S1 ('MetaSel ('Just "bp_delayed_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DelayedPaymentBasepoint) :*: S1 ('MetaSel ('Just "bp_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HtlcBasepoint))))
Show Basepoints Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Basepoints Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Basepoints Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Basepoints = D1 ('MetaData "Basepoints" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "Basepoints" 'PrefixI 'True) ((S1 ('MetaSel ('Just "bp_revocation") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationBasepoint) :*: S1 ('MetaSel ('Just "bp_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint)) :*: (S1 ('MetaSel ('Just "bp_delayed_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DelayedPaymentBasepoint) :*: S1 ('MetaSel ('Just "bp_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HtlcBasepoint))))

newtype PerCommitmentPoint Source #

Per-commitment point (used to derive keys).

Instances

Instances details
Generic PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep PerCommitmentPoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentPoint = D1 ('MetaData "PerCommitmentPoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PerCommitmentPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPerCommitmentPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
Show PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentPoint = D1 ('MetaData "PerCommitmentPoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PerCommitmentPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPerCommitmentPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype PerCommitmentSecret Source #

Per-commitment secret (32 bytes).

Instances

Instances details
Generic PerCommitmentSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep PerCommitmentSecret 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentSecret = D1 ('MetaData "PerCommitmentSecret" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PerCommitmentSecret" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPerCommitmentSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show PerCommitmentSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq PerCommitmentSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentSecret Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PerCommitmentSecret = D1 ('MetaData "PerCommitmentSecret" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PerCommitmentSecret" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPerCommitmentSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

per_commitment_secret :: ByteString -> Maybe PerCommitmentSecret Source #

Parse a 32-byte per-commitment secret.

Returns Nothing if the input is not exactly 32 bytes.

newtype RevocationBasepoint Source #

Revocation basepoint.

Instances

Instances details
Generic RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep RevocationBasepoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationBasepoint = D1 ('MetaData "RevocationBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RevocationBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRevocationBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
Show RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationBasepoint = D1 ('MetaData "RevocationBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RevocationBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRevocationBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype PaymentBasepoint Source #

Payment basepoint.

Constructors

PaymentBasepoint 

Instances

Instances details
Generic PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep PaymentBasepoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentBasepoint = D1 ('MetaData "PaymentBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
Show PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep PaymentBasepoint = D1 ('MetaData "PaymentBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "PaymentBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPaymentBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype DelayedPaymentBasepoint Source #

Delayed payment basepoint.

Instances

Instances details
Generic DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep DelayedPaymentBasepoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DelayedPaymentBasepoint = D1 ('MetaData "DelayedPaymentBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "DelayedPaymentBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDelayedPaymentBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
Show DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep DelayedPaymentBasepoint = D1 ('MetaData "DelayedPaymentBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "DelayedPaymentBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unDelayedPaymentBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype HtlcBasepoint Source #

HTLC basepoint.

Constructors

HtlcBasepoint 

Instances

Instances details
Generic HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep HtlcBasepoint 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HtlcBasepoint = D1 ('MetaData "HtlcBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "HtlcBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unHtlcBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
Show HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep HtlcBasepoint = D1 ('MetaData "HtlcBasepoint" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "HtlcBasepoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unHtlcBasepoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

Derived keys

newtype LocalPubkey Source #

Local pubkey (derived from payment_basepoint + per_commitment_point).

Constructors

LocalPubkey 

Instances

Instances details
Generic LocalPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep LocalPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalPubkey = D1 ('MetaData "LocalPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show LocalPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq LocalPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord LocalPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalPubkey = D1 ('MetaData "LocalPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype RemotePubkey Source #

Remote pubkey (simply the remote's payment_basepoint).

Constructors

RemotePubkey 

Instances

Instances details
Generic RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep RemotePubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemotePubkey = D1 ('MetaData "RemotePubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemotePubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemotePubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemotePubkey = D1 ('MetaData "RemotePubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemotePubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemotePubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype LocalDelayedPubkey Source #

Local delayed pubkey.

Instances

Instances details
Generic LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep LocalDelayedPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalDelayedPubkey = D1 ('MetaData "LocalDelayedPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalDelayedPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalDelayedPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalDelayedPubkey = D1 ('MetaData "LocalDelayedPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalDelayedPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalDelayedPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype RemoteDelayedPubkey Source #

Remote delayed pubkey.

Instances

Instances details
Generic RemoteDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep RemoteDelayedPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteDelayedPubkey = D1 ('MetaData "RemoteDelayedPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemoteDelayedPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemoteDelayedPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show RemoteDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq RemoteDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord RemoteDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteDelayedPubkey = D1 ('MetaData "RemoteDelayedPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemoteDelayedPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemoteDelayedPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype LocalHtlcPubkey Source #

Local HTLC pubkey.

Constructors

LocalHtlcPubkey 

Instances

Instances details
Generic LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep LocalHtlcPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalHtlcPubkey = D1 ('MetaData "LocalHtlcPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalHtlcPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalHtlcPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep LocalHtlcPubkey = D1 ('MetaData "LocalHtlcPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "LocalHtlcPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLocalHtlcPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype RemoteHtlcPubkey Source #

Remote HTLC pubkey.

Instances

Instances details
Generic RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep RemoteHtlcPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteHtlcPubkey = D1 ('MetaData "RemoteHtlcPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemoteHtlcPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemoteHtlcPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RemoteHtlcPubkey = D1 ('MetaData "RemoteHtlcPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RemoteHtlcPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRemoteHtlcPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype RevocationPubkey Source #

Revocation pubkey (derived from revocation_basepoint + per_commitment).

Instances

Instances details
Generic RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep RevocationPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationPubkey = D1 ('MetaData "RevocationPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RevocationPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRevocationPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep RevocationPubkey = D1 ('MetaData "RevocationPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "RevocationPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRevocationPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

newtype FundingPubkey Source #

Funding pubkey (used in 2-of-2 multisig).

Constructors

FundingPubkey 

Instances

Instances details
Generic FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep FundingPubkey 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FundingPubkey = D1 ('MetaData "FundingPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "FundingPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unFundingPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))
Show FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep FundingPubkey = D1 ('MetaData "FundingPubkey" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "FundingPubkey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unFundingPubkey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pubkey)))

Script and witness

newtype Script Source #

Bitcoin script (serialized).

Constructors

Script 

Fields

Instances

Instances details
Generic Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Script 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Script = D1 ('MetaData "Script" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Script" 'PrefixI 'True) (S1 ('MetaSel ('Just "unScript") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Methods

from :: Script -> Rep Script x #

to :: Rep Script x -> Script #

Show Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Script -> Script -> Bool #

(/=) :: Script -> Script -> Bool #

Ord Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Script = D1 ('MetaData "Script" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Script" 'PrefixI 'True) (S1 ('MetaSel ('Just "unScript") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

newtype Witness Source #

Transaction witness stack.

Constructors

Witness 

Fields

Instances

Instances details
Generic Witness Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep Witness 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Witness = D1 ('MetaData "Witness" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Witness" 'PrefixI 'True) (S1 ('MetaSel ('Just "unWitness") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ByteString])))

Methods

from :: Witness -> Rep Witness x #

to :: Rep Witness x -> Witness #

Show Witness Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq Witness Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

(==) :: Witness -> Witness -> Bool #

(/=) :: Witness -> Witness -> Bool #

Ord Witness Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Witness Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep Witness = D1 ('MetaData "Witness" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'True) (C1 ('MetaCons "Witness" 'PrefixI 'True) (S1 ('MetaSel ('Just "unWitness") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ByteString])))

Channel features

data ChannelFeatures Source #

Channel feature flags relevant to BOLT #3.

Constructors

ChannelFeatures 

Instances

Instances details
Generic ChannelFeatures Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep ChannelFeatures 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ChannelFeatures = D1 ('MetaData "ChannelFeatures" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ChannelFeatures" 'PrefixI 'True) (S1 ('MetaSel ('Just "cf_option_anchors") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))
Show ChannelFeatures Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq ChannelFeatures Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ChannelFeatures Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep ChannelFeatures = D1 ('MetaData "ChannelFeatures" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ChannelFeatures" 'PrefixI 'True) (S1 ('MetaSel ('Just "cf_option_anchors") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))

has_anchors :: ChannelFeatures -> Bool Source #

Check if option_anchors is enabled.

Constants

commitment_weight_no_anchors :: Word64 Source #

Base commitment tx weight without option_anchors.

commitment_weight_anchors :: Word64 Source #

Base commitment tx weight with option_anchors.

htlc_timeout_weight_no_anchors :: Word64 Source #

HTLC-timeout tx weight without option_anchors.

htlc_timeout_weight_anchors :: Word64 Source #

HTLC-timeout tx weight with option_anchors.

htlc_success_weight_no_anchors :: Word64 Source #

HTLC-success tx weight without option_anchors.

htlc_success_weight_anchors :: Word64 Source #

HTLC-success tx weight with option_anchors.

htlc_output_weight :: Word64 Source #

Weight added per HTLC output in commitment tx.

dust_p2pkh :: Satoshi Source #

P2PKH dust threshold (546 satoshis).

dust_p2sh :: Satoshi Source #

P2SH dust threshold (540 satoshis).

dust_p2wpkh :: Satoshi Source #

P2WPKH dust threshold (294 satoshis).

dust_p2wsh :: Satoshi Source #

P2WSH dust threshold (330 satoshis).

anchor_output_value :: Satoshi Source #

Fixed anchor output value (330 satoshis).

Key derivation

derive_per_commitment_point :: PerCommitmentSecret -> Maybe PerCommitmentPoint Source #

Derive the per-commitment point from a per-commitment secret.

per_commitment_point = per_commitment_secret * G
>>> let secret = PerCommitmentSecret (BS.replicate 32 0x01)
>>> derive_per_commitment_point secret
Just (PerCommitmentPoint ...)

derive_pubkey Source #

Arguments

:: Point

basepoint

-> PerCommitmentPoint

per_commitment_point

-> Maybe Pubkey 

Derive a pubkey from a basepoint and per-commitment point.

pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G

This is the general derivation formula used for localpubkey, local_htlcpubkey, remote_htlcpubkey, local_delayedpubkey, and remote_delayedpubkey.

>>> derive_pubkey basepoint per_commitment_point
Just (Pubkey ...)

derive_localpubkey :: PaymentBasepoint -> PerCommitmentPoint -> Maybe LocalPubkey Source #

Derive localpubkey from payment_basepoint and per_commitment_point.

>>> derive_localpubkey payment_basepoint per_commitment_point
Just (LocalPubkey ...)

derive_local_htlcpubkey :: HtlcBasepoint -> PerCommitmentPoint -> Maybe LocalHtlcPubkey Source #

Derive local_htlcpubkey from htlc_basepoint and per_commitment_point.

>>> derive_local_htlcpubkey htlc_basepoint per_commitment_point
Just (LocalHtlcPubkey ...)

derive_remote_htlcpubkey :: HtlcBasepoint -> PerCommitmentPoint -> Maybe RemoteHtlcPubkey Source #

Derive remote_htlcpubkey from htlc_basepoint and per_commitment_point.

>>> derive_remote_htlcpubkey htlc_basepoint per_commitment_point
Just (RemoteHtlcPubkey ...)

derive_local_delayedpubkey :: DelayedPaymentBasepoint -> PerCommitmentPoint -> Maybe LocalDelayedPubkey Source #

Derive local_delayedpubkey from delayed_payment_basepoint and per_commitment_point.

>>> derive_local_delayedpubkey delayed_payment_basepoint per_commitment_point
Just (LocalDelayedPubkey ...)

derive_remote_delayedpubkey :: DelayedPaymentBasepoint -> PerCommitmentPoint -> Maybe RemoteDelayedPubkey Source #

Derive remote_delayedpubkey from delayed_payment_basepoint and per_commitment_point.

>>> derive_remote_delayedpubkey delayed_payment_basepoint pcp
Just (RemoteDelayedPubkey ...)

derive_revocationpubkey :: RevocationBasepoint -> PerCommitmentPoint -> Maybe RevocationPubkey Source #

Derive revocationpubkey from revocation_basepoint and per_commitment_point.

revocationpubkey = revocation_basepoint
                     * SHA256(revocation_basepoint || per_commitment_point)
                 + per_commitment_point
                     * SHA256(per_commitment_point || revocation_basepoint)
>>> derive_revocationpubkey revocation_basepoint per_commitment_point
Just (RevocationPubkey ...)

Secret generation

generate_from_seed Source #

Arguments

:: ByteString

seed (32 bytes)

-> Word64

index I (max 2^48 - 1)

-> ByteString

per-commitment secret (32 bytes)

Generate the I'th per-commitment secret from a seed.

Implements the generate_from_seed algorithm from BOLT #3:

generate_from_seed(seed, I):
    P = seed
    for B in 47 down to 0:
        if B set in I:
            flip(B) in P
            P = SHA256(P)
    return P
>>> generate_from_seed seed 281474976710655
<32-byte secret>

derive_secret Source #

Arguments

:: ByteString

base secret

-> Int

bits (number of trailing bits to process)

-> Word64

target index I

-> ByteString

derived secret

Derive a secret from a base secret.

This is a generalization of generate_from_seed used for efficient secret storage. Given a base secret whose index has bits..47 the same as target index I, derive the I'th secret.

derive_secret(base, bits, I):
    P = base
    for B in bits - 1 down to 0:
        if B set in I:
            flip(B) in P
            P = SHA256(P)
    return P

Secret storage

data SecretStore Source #

Compact storage for per-commitment secrets.

Stores up to 49 (value, index) pairs, allowing efficient derivation of any previously-received secret. This is possible because for a given secret on a 2^X boundary, all secrets up to the next 2^X boundary can be derived from it.

Instances

Instances details
Generic SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Associated Types

type Rep SecretStore 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Show SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Eq SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

type Rep SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

empty_store :: SecretStore Source #

Empty secret store.

insert_secret Source #

Arguments

:: ByteString

secret (32 bytes)

-> Word64

index

-> SecretStore

current store

-> Maybe SecretStore 

Insert a secret into the store, validating against existing secrets.

Returns Nothing if the secret doesn't derive correctly from known secrets (indicating the secrets weren't generated from the same seed).

>>> insert_secret secret 281474976710655 empty_store
Just (SecretStore ...)

derive_old_secret Source #

Arguments

:: Word64

target index

-> SecretStore

store

-> Maybe ByteString 

Derive a previously-received secret from the store.

Iterates over known secrets to find one whose index is a prefix of the target index, then derives the target secret from it.

>>> derive_old_secret 281474976710654 store
Just <32-byte secret>

Commitment number

obscured_commitment_number Source #

Arguments

:: PaymentBasepoint

opener's payment_basepoint

-> PaymentBasepoint

accepter's payment_basepoint

-> CommitmentNumber

commitment number (48-bit)

-> Word64

obscured commitment number

Calculate the obscured commitment number.

The 48-bit commitment number is obscured by XOR with the lower 48 bits of SHA256(payment_basepoint from open_channel || payment_basepoint from accept_channel).

>>> obscured_commitment_number local_payment_bp remote_payment_bp cn
<obscured value>

Scripts

Funding output

funding_script :: FundingPubkey -> FundingPubkey -> Script Source #

Funding output witness script (2-of-2 multisig).

Script: 2 pubkey1 pubkey2 2 OP_CHECKMULTISIG

Where pubkey1 is lexicographically lesser.

>>> funding_script pk1 pk2
Script "R!<pk_lesser>!<pk_greater>R\xae"

funding_witness :: ByteString -> ByteString -> Witness Source #

Witness for spending funding output.

Witness: 0 sig1 sig2

Signatures ordered to match pubkey order in script.

>>> funding_witness sig1 sig2
Witness ["", sig1, sig2]

to_local output

to_local_script :: RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script Source #

to_local witness script (revocable with CSV delay).

Script:

OP_IF
    revocationpubkey
OP_ELSE
    to_self_delay
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    local_delayedpubkey
OP_ENDIF
OP_CHECKSIG
>>> to_local_script revpk delay localpk
Script "c!<revpk>g<delay>\xb2u!<localpk>h\xac"

to_local_witness_spend :: ByteString -> Witness Source #

Witness for delayed spend of to_local output.

Input nSequence must be set to to_self_delay.

Witness: local_delayedsig <>

>>> to_local_witness_spend sig
Witness [sig, ""]

to_local_witness_revoke :: ByteString -> Witness Source #

Witness for revocation spend of to_local output.

Witness: revocation_sig 1

>>> to_local_witness_revoke sig
Witness [sig, "\x01"]

to_remote output

to_remote_script :: RemotePubkey -> ChannelFeatures -> Script Source #

to_remote witness script.

With option_anchors:

remotepubkey OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY

Without option_anchors: P2WPKH (just the pubkey hash).

>>> to_remote_script pk (ChannelFeatures True)
Script "!<pk>\xadQ\xb2"

to_remote_witness :: ByteString -> RemotePubkey -> ChannelFeatures -> Witness Source #

Witness for spending to_remote output.

With option_anchors (P2WSH), input nSequence must be 1. Witness: remote_sig (witness script appended by caller)

Without option_anchors (P2WPKH): Witness: remote_sig remotepubkey

>>> to_remote_witness sig pk (ChannelFeatures False)
Witness [sig, pk]

Anchor outputs

anchor_script :: FundingPubkey -> Script Source #

Anchor output witness script.

Script:

funding_pubkey OP_CHECKSIG OP_IFDUP
OP_NOTIF
    OP_16 OP_CHECKSEQUENCEVERIFY
OP_ENDIF
>>> anchor_script fundpk
Script "!<fundpk>\xac\x73d`\xb2h"

anchor_witness_owner :: ByteString -> Witness Source #

Witness for owner to spend anchor output.

Witness: sig

>>> anchor_witness_owner sig
Witness [sig]

anchor_witness_anyone :: Witness Source #

Witness for anyone to sweep anchor output after 16 blocks.

Witness: <>

>>> anchor_witness_anyone
Witness [""]

Offered HTLC

offered_htlc_script :: RevocationPubkey -> RemoteHtlcPubkey -> LocalHtlcPubkey -> PaymentHash -> ChannelFeatures -> Script Source #

Offered HTLC witness script.

Without option_anchors:

OP_DUP OP_HASH160 RIPEMD160(SHA256(revocationpubkey)) OP_EQUAL
OP_IF
    OP_CHECKSIG
OP_ELSE
    remote_htlcpubkey OP_SWAP OP_SIZE 32 OP_EQUAL
    OP_NOTIF
        OP_DROP 2 OP_SWAP local_htlcpubkey 2 OP_CHECKMULTISIG
    OP_ELSE
        OP_HASH160 RIPEMD160(payment_hash) OP_EQUALVERIFY
        OP_CHECKSIG
    OP_ENDIF
OP_ENDIF

With option_anchors, adds 1 OP_CHECKSEQUENCEVERIFY OP_DROP before final OP_ENDIF.

offered_htlc_witness_preimage :: ByteString -> PaymentPreimage -> Witness Source #

Witness for remote node to claim offered HTLC with preimage.

With option_anchors, input nSequence must be 1.

Witness: remotehtlcsig payment_preimage

>>> offered_htlc_witness_preimage sig preimage
Witness [sig, preimage]

offered_htlc_witness_revoke :: ByteString -> Pubkey -> Witness Source #

Witness for revocation spend of offered HTLC.

Witness: revocation_sig revocationpubkey

>>> offered_htlc_witness_revoke sig revpk
Witness [sig, revpk]

Received HTLC

received_htlc_script :: RevocationPubkey -> RemoteHtlcPubkey -> LocalHtlcPubkey -> PaymentHash -> CltvExpiry -> ChannelFeatures -> Script Source #

Received HTLC witness script.

Without option_anchors:

OP_DUP OP_HASH160 RIPEMD160(SHA256(revocationpubkey)) OP_EQUAL
OP_IF
    OP_CHECKSIG
OP_ELSE
    remote_htlcpubkey OP_SWAP OP_SIZE 32 OP_EQUAL
    OP_IF
        OP_HASH160 RIPEMD160(payment_hash) OP_EQUALVERIFY
        2 OP_SWAP local_htlcpubkey 2 OP_CHECKMULTISIG
    OP_ELSE
        OP_DROP cltv_expiry OP_CHECKLOCKTIMEVERIFY OP_DROP
        OP_CHECKSIG
    OP_ENDIF
OP_ENDIF

With option_anchors, adds 1 OP_CHECKSEQUENCEVERIFY OP_DROP before final OP_ENDIF.

received_htlc_witness_timeout :: ByteString -> Witness Source #

Witness for remote node to timeout received HTLC.

With option_anchors, input nSequence must be 1.

Witness: remotehtlcsig <>

>>> received_htlc_witness_timeout sig
Witness [sig, ""]

received_htlc_witness_revoke :: ByteString -> Pubkey -> Witness Source #

Witness for revocation spend of received HTLC.

Witness: revocation_sig revocationpubkey

>>> received_htlc_witness_revoke sig revpk
Witness [sig, revpk]

HTLC output (same as to_local)

htlc_output_script :: RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script Source #

HTLC output witness script (same structure as to_local).

Used for HTLC-timeout and HTLC-success transaction outputs.

Script:

OP_IF
    revocationpubkey
OP_ELSE
    to_self_delay
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    local_delayedpubkey
OP_ENDIF
OP_CHECKSIG

htlc_output_witness_spend :: ByteString -> Witness Source #

Witness for delayed spend of HTLC output.

Input nSequence must be set to to_self_delay.

Witness: local_delayedsig 0

htlc_output_witness_revoke :: ByteString -> Witness Source #

Witness for revocation spend of HTLC output.

Witness: revocationsig 1

P2WSH helpers

to_p2wsh :: Script -> Script Source #

Convert a witness script to P2WSH scriptPubKey.

P2WSH format: OP_0 32-byte-hash

>>> to_p2wsh some_witness_script
Script "\x00\x20<32-byte-hash>"

witness_script_hash :: Script -> ByteString Source #

Compute SHA256 hash of a witness script.

>>> witness_script_hash (Script "some_script")
<32-byte SHA256 hash>

Transaction assembly

Commitment transactions

data CommitmentTx Source #

A commitment transaction.

Instances

Instances details
Generic CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx = D1 ('MetaData "CommitmentTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "ctx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))
Show CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx = D1 ('MetaData "CommitmentTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "ctx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data CommitmentContext Source #

Context for building a commitment transaction.

Instances

Instances details
Generic CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext = D1 ('MetaData "CommitmentContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentNumber) :*: S1 ('MetaSel ('Just "cc_local_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint))) :*: (S1 ('MetaSel ('Just "cc_remote_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint) :*: (S1 ('MetaSel ('Just "cc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "cc_htlcs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [HTLC]) :*: S1 ('MetaSel ('Just "cc_keys") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys))))))
Show CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext = D1 ('MetaData "CommitmentContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentNumber) :*: S1 ('MetaSel ('Just "cc_local_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint))) :*: (S1 ('MetaSel ('Just "cc_remote_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint) :*: (S1 ('MetaSel ('Just "cc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "cc_htlcs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [HTLC]) :*: S1 ('MetaSel ('Just "cc_keys") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys))))))

data CommitmentKeys Source #

Derived keys needed for commitment transaction outputs.

Instances

Instances details
Generic CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentKeys 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentKeys" 'PrefixI 'True) (((S1 ('MetaSel ('Just "ck_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "ck_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)) :*: (S1 ('MetaSel ('Just "ck_local_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalHtlcPubkey) :*: S1 ('MetaSel ('Just "ck_remote_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemoteHtlcPubkey))) :*: ((S1 ('MetaSel ('Just "ck_local_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalPubkey) :*: S1 ('MetaSel ('Just "ck_remote_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemotePubkey)) :*: (S1 ('MetaSel ('Just "ck_local_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey) :*: S1 ('MetaSel ('Just "ck_remote_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))
Show CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentKeys" 'PrefixI 'True) (((S1 ('MetaSel ('Just "ck_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "ck_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)) :*: (S1 ('MetaSel ('Just "ck_local_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalHtlcPubkey) :*: S1 ('MetaSel ('Just "ck_remote_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemoteHtlcPubkey))) :*: ((S1 ('MetaSel ('Just "ck_local_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalPubkey) :*: S1 ('MetaSel ('Just "ck_remote_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemotePubkey)) :*: (S1 ('MetaSel ('Just "ck_local_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey) :*: S1 ('MetaSel ('Just "ck_remote_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))

build_commitment_tx :: CommitmentContext -> CommitmentTx Source #

Build a commitment transaction.

Follows the algorithm from BOLT #3:

  1. Initialize input and locktime with obscured commitment number
  2. Calculate which HTLCs are trimmed
  3. Calculate base fee and subtract from funder
  4. Add untrimmed HTLC outputs
  5. Add to_local output if above dust
  6. Add to_remote output if above dust
  7. Add anchor outputs if option_anchors
  8. Sort outputs per BIP69+CLTV

HTLC transactions

data HTLCTx Source #

An HTLC transaction (timeout or success).

Instances

Instances details
Generic HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep HTLCTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCTx = D1 ('MetaData "HTLCTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "htx_output_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

Methods

from :: HTLCTx -> Rep HTLCTx x #

to :: Rep HTLCTx x -> HTLCTx #

Show HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

(==) :: HTLCTx -> HTLCTx -> Bool #

(/=) :: HTLCTx -> HTLCTx -> Bool #

type Rep HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCTx = D1 ('MetaData "HTLCTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "htx_output_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data HTLCContext Source #

Context for building HTLC transactions.

Instances

Instances details
Generic HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep HTLCContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext = D1 ('MetaData "HTLCContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hc_commitment_txid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "hc_output_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :*: (S1 ('MetaSel ('Just "hc_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: S1 ('MetaSel ('Just "hc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures)) :*: (S1 ('MetaSel ('Just "hc_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "hc_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))))
Show HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext = D1 ('MetaData "HTLCContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hc_commitment_txid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "hc_output_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :*: (S1 ('MetaSel ('Just "hc_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: S1 ('MetaSel ('Just "hc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures)) :*: (S1 ('MetaSel ('Just "hc_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "hc_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))))

build_htlc_timeout_tx :: HTLCContext -> HTLCTx Source #

Build an HTLC-timeout transaction.

  • locktime: cltv_expiry
  • sequence: 0 (or 1 with option_anchors)
  • output: to_local style script with revocation and delayed paths

build_htlc_success_tx :: HTLCContext -> HTLCTx Source #

Build an HTLC-success transaction.

  • locktime: 0
  • sequence: 0 (or 1 with option_anchors)
  • output: to_local style script with revocation and delayed paths

Closing transactions

data ClosingTx Source #

A closing transaction.

Instances

Instances details
Generic ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx = D1 ('MetaData "ClosingTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "cltx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "cltx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "cltx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))
Show ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx = D1 ('MetaData "ClosingTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "cltx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "cltx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "cltx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data ClosingContext Source #

Context for building closing transactions.

Instances

Instances details
Generic ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext = D1 ('MetaData "ClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: S1 ('MetaSel ('Just "clc_local_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_remote_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "clc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))) :*: ((S1 ('MetaSel ('Just "clc_local_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: (S1 ('MetaSel ('Just "clc_remote_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: S1 ('MetaSel ('Just "clc_fee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :*: (S1 ('MetaSel ('Just "clc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "clc_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))))))
Show ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext = D1 ('MetaData "ClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: S1 ('MetaSel ('Just "clc_local_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_remote_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "clc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))) :*: ((S1 ('MetaSel ('Just "clc_local_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: (S1 ('MetaSel ('Just "clc_remote_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: S1 ('MetaSel ('Just "clc_fee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :*: (S1 ('MetaSel ('Just "clc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "clc_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))))))

build_closing_tx :: ClosingContext -> ClosingTx Source #

Build a closing transaction (option_simple_close).

  • locktime: from closing_complete message
  • sequence: 0xFFFFFFFD
  • outputs: sorted per BIP69

build_legacy_closing_tx :: ClosingContext -> ClosingTx Source #

Build a legacy closing transaction (closing_signed).

  • locktime: 0
  • sequence: 0xFFFFFFFF
  • outputs: sorted per BIP69

Transaction outputs

data TxOutput Source #

A transaction output with value, script, and type information.

Instances

Instances details
Generic TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep TxOutput 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput = D1 ('MetaData "TxOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "TxOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "txout_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "txout_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "txout_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))

Methods

from :: TxOutput -> Rep TxOutput x #

to :: Rep TxOutput x -> TxOutput #

Show TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput = D1 ('MetaData "TxOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "TxOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "txout_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "txout_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "txout_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))

data OutputType Source #

Type of output in a commitment transaction.

Instances

Instances details
Generic OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep OutputType 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType = D1 ('MetaData "OutputType" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "OutputToLocal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputToRemote" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OutputLocalAnchor" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "OutputRemoteAnchor" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputOfferedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)) :+: C1 ('MetaCons "OutputReceivedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)))))
Show OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType = D1 ('MetaData "OutputType" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "OutputToLocal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputToRemote" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OutputLocalAnchor" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "OutputRemoteAnchor" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputOfferedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)) :+: C1 ('MetaCons "OutputReceivedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)))))

Fee calculation

commitment_fee :: FeeratePerKw -> ChannelFeatures -> Word64 -> Satoshi Source #

Calculate the base commitment transaction fee.

fee = feerate_per_kw * weight / 1000

where weight = base_weight + 172 * num_htlcs

commitment_weight :: ChannelFeatures -> Word64 -> Word64 Source #

Calculate commitment transaction weight.

weight = base + 172 * num_htlcs

htlc_timeout_fee :: FeeratePerKw -> ChannelFeatures -> Satoshi Source #

Calculate HTLC-timeout transaction fee.

With option_anchors, fee is 0 (CPFP). Otherwise, fee = feerate_per_kw * 663 / 1000

htlc_success_fee :: FeeratePerKw -> ChannelFeatures -> Satoshi Source #

Calculate HTLC-success transaction fee.

With option_anchors, fee is 0 (CPFP). Otherwise, fee = feerate_per_kw * 703 / 1000

Trimming

htlc_trim_threshold :: DustLimit -> FeeratePerKw -> ChannelFeatures -> HTLCDirection -> Satoshi Source #

Calculate the trim threshold for an HTLC.

An HTLC is trimmed if: amount < dust_limit + htlc_tx_fee

is_trimmed :: DustLimit -> FeeratePerKw -> ChannelFeatures -> HTLC -> Bool Source #

Check if an HTLC should be trimmed.

An HTLC is trimmed if its amount minus the HTLC tx fee is below the dust limit.

trimmed_htlcs :: DustLimit -> FeeratePerKw -> ChannelFeatures -> [HTLC] -> [HTLC] Source #

Filter HTLCs that are trimmed.

untrimmed_htlcs :: DustLimit -> FeeratePerKw -> ChannelFeatures -> [HTLC] -> [HTLC] Source #

Filter HTLCs that are not trimmed.

Output ordering

sort_outputs :: [TxOutput] -> [TxOutput] Source #

Sort outputs per BOLT #3 ordering.

Outputs are sorted by: 1. Value (smallest first) 2. ScriptPubKey (lexicographic) 3. CLTV expiry (for HTLCs)

Serialization

encode_tx :: CommitmentTx -> ByteString Source #

Encode a commitment transaction (SegWit format with witness).

SegWit format:

  • version (4 bytes LE)
  • marker (0x00)
  • flag (0x01)
  • input count (varint)
  • inputs
  • output count (varint)
  • outputs
  • witness data
  • locktime (4 bytes LE)

Note: The witness is empty (just count=0) since the commitment tx spending the funding output requires external signatures.

encode_htlc_tx :: HTLCTx -> ByteString Source #

Encode an HTLC transaction (SegWit format with witness).

HTLC transactions have a single input (the commitment tx HTLC output) and a single output (the to_local-style delayed output).

encode_closing_tx :: ClosingTx -> ByteString Source #

Encode a closing transaction (SegWit format with witness).

Closing transactions have a single input (the funding output) and one or two outputs (to_local and/or to_remote).

encode_tx_for_signing :: CommitmentTx -> ByteString Source #

Encode a commitment transaction for signing (stripped format).

The stripped format omits the SegWit marker, flag, and witness data. This is the format used to compute the sighash for signing.

Format:

  • version (4 bytes LE)
  • input count (varint)
  • inputs
  • output count (varint)
  • outputs
  • locktime (4 bytes LE)

encode_varint :: Word64 -> ByteString Source #

Encode a value as a Bitcoin varint (CompactSize).

Encoding scheme:

  • 0-252: 1 byte
  • 253-65535: 0xFD followed by 2 bytes LE
  • 65536-4294967295: 0xFE followed by 4 bytes LE
  • larger: 0xFF followed by 8 bytes LE
>>> encode_varint 100
"\x64"
>>> encode_varint 1000
"\xFD\xE8\x03"

encode_le32 :: Word32 -> ByteString Source #

Encode a 32-bit value in little-endian format.

>>> encode_le32 0x12345678
"\x78\x56\x34\x12"

encode_le64 :: Word64 -> ByteString Source #

Encode a 64-bit value in little-endian format.

>>> encode_le64 0x123456789ABCDEF0
"\xF0\xDE\xBC\x9A\x78\x56\x34\x12"

encode_outpoint :: Outpoint -> ByteString Source #

Encode an outpoint (txid + output index).

Format: 32 bytes txid (already LE in TxId) + 4 bytes output index LE

>>> encode_outpoint (Outpoint txid 0)
<32-byte txid><4-byte index>

encode_output :: TxOutput -> ByteString Source #

Encode a transaction output.

Format: 8 bytes value LE + varint scriptPubKey length + scriptPubKey

>>> encode_output (TxOutput (Satoshi 100000) script OutputToLocal)
<8-byte value><varint length><scriptPubKey>

encode_witness :: Witness -> ByteString Source #

Encode a witness stack.

Format: varint item count + (varint length + data) for each item

>>> encode_witness (Witness [sig, pubkey])
<varint 2><varint sigLen><sig><varint pkLen><pubkey>

encode_funding_witness Source #

Arguments

:: ByteString

Signature for pubkey1 (lexicographically lesser)

-> ByteString

Signature for pubkey2 (lexicographically greater)

-> Script

The funding witness script

-> ByteString 

Encode a funding witness (2-of-2 multisig).

The witness stack is: 0 sig1 sig2 witnessScript

Signatures must be ordered to match pubkey order in the funding script.

>>> encode_funding_witness sig1 sig2 fundingScript
<witness with 4 items: empty, sig1, sig2, script>

Parsing

data DecodeError Source #

Errors that can occur during transaction decoding.

Constructors

InsufficientBytes !Int !Int

Expected bytes, actual bytes available

InvalidMarker !Word8

Invalid SegWit marker byte (expected 0x00)

InvalidFlag !Word8

Invalid SegWit flag byte (expected 0x01)

InvalidVarint

Malformed varint encoding

EmptyInput

No bytes to decode

Instances

Instances details
Generic DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Associated Types

type Rep DecodeError 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "InsufficientBytes" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "InvalidMarker" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word8))) :+: (C1 ('MetaCons "InvalidFlag" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word8)) :+: (C1 ('MetaCons "InvalidVarint" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EmptyInput" 'PrefixI 'False) (U1 :: Type -> Type))))
Show DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Eq DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "InsufficientBytes" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "InvalidMarker" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word8))) :+: (C1 ('MetaCons "InvalidFlag" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word8)) :+: (C1 ('MetaCons "InvalidVarint" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EmptyInput" 'PrefixI 'False) (U1 :: Type -> Type))))

data RawTx Source #

A raw transaction as parsed from bytes.

Supports both legacy and SegWit transaction formats.

Constructors

RawTx 

Fields

Instances

Instances details
Generic RawTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Associated Types

type Rep RawTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawTx = D1 ('MetaData "RawTx" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "rtx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "rtx_inputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [RawInput])) :*: (S1 ('MetaSel ('Just "rtx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [RawOutput]) :*: (S1 ('MetaSel ('Just "rtx_witness") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [[ByteString]]) :*: S1 ('MetaSel ('Just "rtx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime)))))

Methods

from :: RawTx -> Rep RawTx x #

to :: Rep RawTx x -> RawTx #

Show RawTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Methods

showsPrec :: Int -> RawTx -> ShowS #

show :: RawTx -> String #

showList :: [RawTx] -> ShowS #

Eq RawTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Methods

(==) :: RawTx -> RawTx -> Bool #

(/=) :: RawTx -> RawTx -> Bool #

type Rep RawTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawTx = D1 ('MetaData "RawTx" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "rtx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "rtx_inputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [RawInput])) :*: (S1 ('MetaSel ('Just "rtx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [RawOutput]) :*: (S1 ('MetaSel ('Just "rtx_witness") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [[ByteString]]) :*: S1 ('MetaSel ('Just "rtx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime)))))

data RawInput Source #

A raw transaction input as parsed from bytes.

Instances

Instances details
Generic RawInput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Associated Types

type Rep RawInput 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawInput = D1 ('MetaData "RawInput" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawInput" 'PrefixI 'True) (S1 ('MetaSel ('Just "ri_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "ri_script_sig") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "ri_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence))))

Methods

from :: RawInput -> Rep RawInput x #

to :: Rep RawInput x -> RawInput #

Show RawInput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Eq RawInput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawInput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawInput = D1 ('MetaData "RawInput" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawInput" 'PrefixI 'True) (S1 ('MetaSel ('Just "ri_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "ri_script_sig") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "ri_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence))))

data RawOutput Source #

A raw transaction output as parsed from bytes.

Constructors

RawOutput 

Fields

Instances

Instances details
Generic RawOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Associated Types

type Rep RawOutput 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawOutput = D1 ('MetaData "RawOutput" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "ro_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "ro_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))
Show RawOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

Eq RawOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Decode

type Rep RawOutput = D1 ('MetaData "RawOutput" "Lightning.Protocol.BOLT3.Decode" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "RawOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "ro_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "ro_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))

decode_tx :: ByteString -> Either DecodeError RawTx Source #

Decode a raw Bitcoin transaction from bytes.

Handles both legacy and SegWit transaction formats.

SegWit format: * version (4 bytes LE) * marker (0x00) + flag (0x01) * input count (varint) * inputs: outpoint (32+4), scriptSig length (varint), scriptSig, sequence * output count (varint) * outputs: value (8 LE), scriptPubKey length (varint), scriptPubKey * witness data (for each input) * locktime (4 bytes LE)

>>> decode_tx rawTxBytes
Right (RawTx {...})

decode_varint :: ByteString -> Either DecodeError (Word64, ByteString) Source #

Decode a Bitcoin varint (CompactSize).

Encoding: * 0x00-0xFC: 1 byte * 0xFD: 2 bytes little-endian follow * 0xFE: 4 bytes little-endian follow * 0xFF: 8 bytes little-endian follow

>>> decode_varint (BS.pack [0x01])
Right (1, "")
>>> decode_varint (BS.pack [0xfd, 0x00, 0x01])
Right (256, "")

decode_le32 :: ByteString -> Either DecodeError (Word32, ByteString) Source #

Decode a little-endian 32-bit integer.

>>> decode_le32 (BS.pack [0x01, 0x00, 0x00, 0x00])
Right (1, "")

decode_le64 :: ByteString -> Either DecodeError (Word64, ByteString) Source #

Decode a little-endian 64-bit integer.

>>> decode_le64 (BS.pack [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
Right (1, "")

decode_outpoint :: ByteString -> Either DecodeError (Outpoint, ByteString) Source #

Decode a transaction outpoint (txid + output index).

Format: 32 bytes txid (little-endian) + 4 bytes index (little-endian)

>>> let txid = BS.replicate 32 0
>>> let idx = BS.pack [0x01, 0x00, 0x00, 0x00]
>>> decode_outpoint (txid <> idx)
Right (Outpoint {outpoint_txid = ..., outpoint_index = 1}, "")

decode_output :: ByteString -> Either DecodeError (RawOutput, ByteString) Source #

Decode a transaction output (value + scriptPubKey).

Format: 8 bytes value (little-endian) + varint script length + script

decode_witness :: ByteString -> Either DecodeError (Witness, ByteString) Source #

Decode a witness stack for one input.

Format: varint num_items + (varint length + data) for each item

Validation

data ValidationError Source #

Errors that can occur during validation.

Constructors

InvalidVersion !Word32 !Word32

Expected version, actual version

InvalidLocktime !Word32

Invalid locktime format

InvalidSequence !Word32

Invalid sequence format

InvalidOutputOrdering

Outputs not in BIP69+CLTV order

DustLimitViolation !Int !Satoshi !Satoshi

Output index, actual value, dust limit

MissingAnchorOutput

Expected anchor output not present

InvalidAnchorValue !Satoshi

Anchor value not 330 satoshis

InvalidFee !Satoshi !Satoshi

Expected fee, actual fee

InvalidHTLCLocktime !Word32 !Word32

Expected locktime, actual locktime

InvalidHTLCSequence !Word32 !Word32

Expected sequence, actual sequence

NoOutputs

Transaction has no outputs

TooManyOutputs !Int

More outputs than expected

Instances

Instances details
Generic ValidationError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Validate

Associated Types

type Rep ValidationError 
Instance details

Defined in Lightning.Protocol.BOLT3.Validate

type Rep ValidationError = D1 ('MetaData "ValidationError" "Lightning.Protocol.BOLT3.Validate" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (((C1 ('MetaCons "InvalidVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "InvalidLocktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: C1 ('MetaCons "InvalidSequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))) :+: (C1 ('MetaCons "InvalidOutputOrdering" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DustLimitViolation" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :+: C1 ('MetaCons "MissingAnchorOutput" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "InvalidAnchorValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :+: (C1 ('MetaCons "InvalidFee" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :+: C1 ('MetaCons "InvalidHTLCLocktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))) :+: (C1 ('MetaCons "InvalidHTLCSequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "NoOutputs" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TooManyOutputs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int))))))
Show ValidationError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Validate

Eq ValidationError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Validate

type Rep ValidationError Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Validate

type Rep ValidationError = D1 ('MetaData "ValidationError" "Lightning.Protocol.BOLT3.Validate" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (((C1 ('MetaCons "InvalidVersion" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "InvalidLocktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: C1 ('MetaCons "InvalidSequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))) :+: (C1 ('MetaCons "InvalidOutputOrdering" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DustLimitViolation" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :+: C1 ('MetaCons "MissingAnchorOutput" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "InvalidAnchorValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :+: (C1 ('MetaCons "InvalidFee" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :+: C1 ('MetaCons "InvalidHTLCLocktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)))) :+: (C1 ('MetaCons "InvalidHTLCSequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :+: (C1 ('MetaCons "NoOutputs" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TooManyOutputs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int))))))

validate_commitment_tx :: DustLimit -> ChannelFeatures -> CommitmentTx -> Either ValidationError () Source #

Validate a commitment transaction.

Checks:

  • Version is 2
  • Locktime format (upper 8 bits = 0x20)
  • Sequence format (upper 8 bits = 0x80)
  • Output ordering per BIP69+CLTV
  • Dust limit compliance
  • Anchor outputs if option_anchors

validate_commitment_locktime :: Locktime -> Either ValidationError () Source #

Validate commitment transaction locktime format.

Upper 8 bits must be 0x20.

validate_commitment_sequence :: Sequence -> Either ValidationError () Source #

Validate commitment transaction sequence format.

Upper 8 bits must be 0x80.

validate_htlc_tx :: HTLCTx -> Either ValidationError () Source #

Validate an HTLC transaction (timeout or success).

Checks:

  • Version is 2
  • Single output

validate_htlc_timeout_tx :: ChannelFeatures -> CltvExpiry -> HTLCTx -> Either ValidationError () Source #

Validate an HTLC-timeout transaction.

Checks:

  • Base HTLC validation
  • Locktime equals HTLC cltv_expiry
  • Sequence is 0 (or 1 with option_anchors)

validate_htlc_success_tx :: ChannelFeatures -> HTLCTx -> Either ValidationError () Source #

Validate an HTLC-success transaction.

Checks:

  • Base HTLC validation
  • Locktime is 0
  • Sequence is 0 (or 1 with option_anchors)

validate_closing_tx :: ClosingTx -> Either ValidationError () Source #

Validate a closing transaction (option_simple_close).

Checks:

  • Version is 2
  • Sequence is 0xFFFFFFFD
  • At least one output
  • Output ordering per BIP69

validate_legacy_closing_tx :: ClosingTx -> Either ValidationError () Source #

Validate a legacy closing transaction (closing_signed).

Checks:

  • Version is 2
  • Locktime is 0
  • Sequence is 0xFFFFFFFF
  • At least one output
  • Output ordering per BIP69

validate_output_ordering :: [TxOutput] -> Either ValidationError () Source #

Validate output ordering per BIP69+CLTV.

Outputs must be sorted by: 1. Value (smallest first) 2. ScriptPubKey (lexicographic) 3. CLTV expiry (for HTLC outputs)

validate_dust_limits :: DustLimit -> [TxOutput] -> Either ValidationError () Source #

Validate that no output violates dust limits.

validate_anchor_outputs :: [TxOutput] -> Either ValidationError () Source #

Validate anchor outputs are present and correctly valued.

validate_commitment_fee Source #

Arguments

:: FeeratePerKw 
-> ChannelFeatures 
-> Word64

Number of untrimmed HTLCs

-> Satoshi

Actual fee

-> Either ValidationError () 

Validate commitment transaction fee.

Checks that the fee matches the expected calculation.

validate_htlc_fee Source #

Arguments

:: FeeratePerKw 
-> ChannelFeatures 
-> HTLCDirection 
-> Satoshi

Actual fee

-> Either ValidationError () 

Validate HTLC transaction fee.