ppad-bolt3-0.1.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 and script formats for the Lightning Network, per BOLT #3 (commitment, HTLC and closing transactions, their output scripts and witnesses, per-commitment key derivation, and per-commitment secret generation and storage).

Amounts, points, hashes and per-commitment secrets are the types of ppad-bolt1's Lightning.Protocol.BOLT1; transactions convert to ppad-tx's Bitcoin.Prim.Tx for txids, sighashes and serialization. The option_static_remotekey and option_anchors commitment formats are supported (CommitmentFormat).

Synopsis

Commitment transactions

data CommitmentContext Source #

The parameters of a commitment transaction, from the point of view of its owner (the "local" party, whose outputs are delayed).

Constructors

CommitmentContext 

Fields

Instances

Instances details
NFData CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: CommitmentContext -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'SourceUnpack '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") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_format") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentFormat) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'SourceUnpack '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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'SourceUnpack '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") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_format") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentFormat) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'SourceUnpack '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 CommitmentFormat Source #

The commitment format a channel uses, as fixed by its channel_type.

Constructors

StaticRemotekey

option_static_remotekey without anchors: to_remote is P2WPKH and HTLC transactions pay their own fees.

Anchors

option_anchors: two anchor outputs, a CSV-locked to_remote, and zero-fee HTLC transactions.

Instances

Instances details
NFData CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: CommitmentFormat -> () #

Generic CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep CommitmentFormat 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentFormat = D1 ('MetaData "CommitmentFormat" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "StaticRemotekey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Anchors" 'PrefixI 'False) (U1 :: Type -> Type))
Show CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentFormat Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep CommitmentFormat = D1 ('MetaData "CommitmentFormat" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "StaticRemotekey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Anchors" 'PrefixI 'False) (U1 :: Type -> Type))

data CommitmentTx Source #

An unsigned commitment transaction.

Constructors

CommitmentTx 

Fields

Instances

Instances details
NFData CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: CommitmentTx -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty CommitmentOutput)) :*: 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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty CommitmentOutput)) :*: S1 ('MetaSel ('Just "ctx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data CommitmentOutput Source #

A commitment transaction output.

Constructors

CommitmentOutput 

Fields

Instances

Instances details
NFData CommitmentOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: CommitmentOutput -> () #

Generic CommitmentOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentOutput 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentOutput = D1 ('MetaData "CommitmentOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "co_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "co_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "co_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))
Show CommitmentOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentOutput = D1 ('MetaData "CommitmentOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CommitmentOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "co_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "co_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "co_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))

data OutputType Source #

What a commitment transaction output pays.

Constructors

OutputToLocal 
OutputToRemote 
OutputLocalAnchor 
OutputRemoteAnchor 
OutputHTLC !HTLC

an offered or received HTLC (per its htlc_direction)

Instances

Instances details
NFData OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: OutputType -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" '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 "OutputHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC)))))
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.1.1-xuvWUaIZwC11qDxWpk94k" '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 "OutputHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC)))))

build_commitment_tx :: CommitmentContext -> Maybe CommitmentTx Source #

Build a commitment transaction, per BOLT #3's "Commitment Transaction Construction":

  • the locktime and input sequence encode the obscured commitment number (the payment basepoints are ordered by cc_is_funder);
  • HTLCs whose amount, less the HTLC transaction fee, is below the dust limit are trimmed;
  • the base fee (and under Anchors, both anchors) are taken from the funder's output, which is left at zero if it can't cover them;
  • to_local and to_remote outputs below the dust limit are omitted, and under Anchors each party's anchor is added if its output, or any HTLC output, exists;
  • outputs are sorted by value, scriptPubKey and CLTV expiry.

Fails if the transaction would have no outputs.

HTLCs

data HTLC Source #

An HTLC committed to a commitment transaction.

Instances

Instances details
NFData HTLC Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: HTLC -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" '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") 'NoSourceUnpackedness '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.1.1-xuvWUaIZwC11qDxWpk94k" '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") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentHash) :*: S1 ('MetaSel ('Just "htlc_cltv_expiry") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry))))

data HTLCDirection Source #

The direction of an HTLC, from the commitment owner's point of view.

Constructors

HTLCOffered

offered by the owner

HTLCReceived

received by the owner

Instances

Instances details
NFData HTLCDirection Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: HTLCDirection -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" '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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "HTLCOffered" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "HTLCReceived" 'PrefixI 'False) (U1 :: Type -> Type))

Channel parameters

data CommitmentNumber Source #

A 48-bit commitment number.

Instances

Instances details
NFData CommitmentNumber Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: CommitmentNumber -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "CommitmentNumber" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "CommitmentNumber" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

commitment_number :: Word64 -> Maybe CommitmentNumber Source #

Construct a CommitmentNumber. Fails at or above 2^48.

>>> commitment_number 42
Just (CommitmentNumber 42)
>>> commitment_number 281474976710656
Nothing

next_commitment_number :: CommitmentNumber -> Maybe CommitmentNumber Source #

The next commitment number. Fails past 2^48 - 1.

>>> commitment_number 0 >>= next_commitment_number
Just (CommitmentNumber 1)
>>> commitment_number 281474976710655 >>= next_commitment_number
Nothing

newtype ToSelfDelay Source #

The CSV delay (to_self_delay) on a commitment owner's outputs.

Constructors

ToSelfDelay Word16 

Instances

Instances details
NFData ToSelfDelay Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: ToSelfDelay -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "ToSelfDelay" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "ToSelfDelay" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))

newtype CltvExpiry Source #

An HTLC's absolute CLTV expiry.

Constructors

CltvExpiry Word32 

Instances

Instances details
NFData CltvExpiry Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: CltvExpiry -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "CltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "CltvExpiry" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

newtype DustLimit Source #

A dust_limit_satoshis threshold.

Constructors

DustLimit Satoshi 

Instances

Instances details
NFData DustLimit Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: DustLimit -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "DustLimit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "DustLimit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Satoshi)))

newtype FeeratePerKw Source #

A fee rate, in satoshis per 1000 weight units.

Constructors

FeeratePerKw Word32 

Instances

Instances details
NFData FeeratePerKw Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: FeeratePerKw -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "FeeratePerKw" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "FeeratePerKw" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

newtype Locktime Source #

A transaction locktime.

Constructors

Locktime Word32 

Instances

Instances details
NFData Locktime Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Locktime -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Locktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Methods

from :: Locktime -> Rep Locktime x #

to :: Rep Locktime x -> Locktime #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Locktime" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

newtype Sequence Source #

A transaction input's sequence number.

Constructors

Sequence Word32 

Instances

Instances details
NFData Sequence Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Sequence -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Sequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Methods

from :: Sequence -> Rep Sequence x #

to :: Rep Sequence x -> Sequence #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Sequence" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32)))

Fees and trimming

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

The base fee of a commitment transaction with a given number of untrimmed HTLC outputs:

feerate_per_kw * (724 + 172 * num_htlcs) / 1000

with a base weight of 1124 rather than 724 under Anchors.

>>> commitment_fee (FeeratePerKw 5000) StaticRemotekey 2
Satoshi 5340

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

The fee of an HTLC-timeout transaction: feerate_per_kw * 663 / 1000, or zero under Anchors.

>>> htlc_timeout_fee (FeeratePerKw 5000) StaticRemotekey
Satoshi 3315

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

The fee of an HTLC-success transaction: feerate_per_kw * 703 / 1000, or zero under Anchors.

>>> htlc_success_fee (FeeratePerKw 5000) StaticRemotekey
Satoshi 3515

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

The amount below which an HTLC in a given direction is trimmed: the dust limit plus the fee of its HTLC transaction.

>>> let Just d = fmap DustLimit (BOLT1.satoshi 546)
>>> htlc_trim_threshold d (FeeratePerKw 5000) StaticRemotekey HTLCOffered
Satoshi 3861

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

Whether an HTLC is trimmed from a commitment transaction: whether its amount, rounded down to whole satoshis, is below htlc_trim_threshold.

anchor_output_value :: Satoshi Source #

The value of each anchor output (330 satoshis).

HTLC transactions

data HTLCContext Source #

The parameters of an HTLC-success or HTLC-timeout transaction, spending an HTLC output of the owner's commitment transaction.

Instances

Instances details
NFData HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: HTLCContext -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" '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") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_format") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentFormat)) :*: (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.1.1-xuvWUaIZwC11qDxWpk94k" '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") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_format") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentFormat)) :*: (S1 ('MetaSel ('Just "hc_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "hc_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))))

data HTLCTx Source #

An unsigned HTLC-success or HTLC-timeout transaction.

Instances

Instances details
NFData HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: HTLCTx -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'SourceUnpack '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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "htx_output_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

build_htlc_tx :: HTLCContext -> Maybe HTLCTx Source #

Build the second-stage transaction for an HTLC output of the owner's commitment transaction: HTLC-timeout (locktime cltv_expiry) for an offered HTLC, and HTLC-success (locktime 0) for a received one.

The output pays the HTLC amount, less the HTLC transaction fee (zero under Anchors), to the to_local_script of the owner's keys. Fails if the fee exceeds the amount (such an HTLC is always trimmed).

Closing transactions

data ClosingTx Source #

An unsigned closing transaction.

Instances

Instances details
NFData ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: ClosingTx -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "cltx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime)) :*: (S1 ('MetaSel ('Just "cltx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty ClosingOutput))))))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "cltx_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime)) :*: (S1 ('MetaSel ('Just "cltx_input_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty ClosingOutput))))))

data ClosingOutput Source #

A closing transaction output.

Constructors

ClosingOutput 

Fields

Instances

Instances details
NFData ClosingOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: ClosingOutput -> () #

Generic ClosingOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingOutput 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutput = D1 ('MetaData "ClosingOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "clo_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "clo_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))
Show ClosingOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutput = D1 ('MetaData "ClosingOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "clo_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "clo_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))

data ClosingContext Source #

The parameters of an option_simple_close closing transaction, as given by a closing_complete message.

Instances

Instances details
NFData ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: ClosingContext -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: S1 ('MetaSel ('Just "clc_closer_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "clc_closee_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "clc_closer_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))) :*: ((S1 ('MetaSel ('Just "clc_closee_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_fee") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ClosingOutputs)))))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: S1 ('MetaSel ('Just "clc_closer_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "clc_closee_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "clc_closer_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))) :*: ((S1 ('MetaSel ('Just "clc_closee_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_fee") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_locktime") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ClosingOutputs)))))

data ClosingOutputs Source #

Which outputs an option_simple_close closing transaction has, matching the signature fields of closing_complete.

Instances

Instances details
NFData ClosingOutputs Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: ClosingOutputs -> () #

Generic ClosingOutputs Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingOutputs 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutputs = D1 ('MetaData "ClosingOutputs" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CloserOutputOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CloseeOutputOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CloserAndCloseeOutputs" 'PrefixI 'False) (U1 :: Type -> Type)))
Show ClosingOutputs Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingOutputs Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutputs Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingOutputs = D1 ('MetaData "ClosingOutputs" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "CloserOutputOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CloseeOutputOnly" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CloserAndCloseeOutputs" 'PrefixI 'False) (U1 :: Type -> Type)))

build_closing_tx :: ClosingContext -> Maybe ClosingTx Source #

Build an option_simple_close closing transaction (BOLT #3's "Closing Transaction"), for closing_complete and closing_sig.

The closer pays the fee: its output is its balance, rounded down to whole satoshis, less the fee. An output whose scriptPubKey starts with OP_RETURN has amount 0. Only the chosen outputs are included, and none is trimmed. Fails if the fee exceeds the closer's balance.

data LegacyClosingContext Source #

The parameters of a legacy closing transaction (for closing_signed), from the point of view of the node producing the signature (the "local" party).

Constructors

LegacyClosingContext 

Fields

Instances

Instances details
NFData LegacyClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

rnf :: LegacyClosingContext -> () #

Generic LegacyClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep LegacyClosingContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep LegacyClosingContext = D1 ('MetaData "LegacyClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "LegacyClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "lcc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: S1 ('MetaSel ('Just "lcc_local_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "lcc_remote_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "lcc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))) :*: ((S1 ('MetaSel ('Just "lcc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "lcc_dust_limit") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)) :*: (S1 ('MetaSel ('Just "lcc_fee") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "lcc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: S1 ('MetaSel ('Just "lcc_omit_local") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))))))
Show LegacyClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq LegacyClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep LegacyClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep LegacyClosingContext = D1 ('MetaData "LegacyClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'False) (C1 ('MetaCons "LegacyClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "lcc_funding_outpoint") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: S1 ('MetaSel ('Just "lcc_local_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "lcc_remote_msat") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "lcc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))) :*: ((S1 ('MetaSel ('Just "lcc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "lcc_dust_limit") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)) :*: (S1 ('MetaSel ('Just "lcc_fee") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "lcc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: S1 ('MetaSel ('Just "lcc_omit_local") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))))))

build_legacy_closing_tx :: LegacyClosingContext -> Maybe ClosingTx Source #

Build a legacy closing transaction (BOLT #3's "Legacy Closing Transaction"), for closing_signed.

Balances are rounded down to whole satoshis and the fee is taken from the funder's output. Outputs below the signer's dust limit are removed, as is the signer's own output if lcc_omit_local is set. Fails if the fee exceeds the funder's balance, or if no output remains.

Dust thresholds

dust_p2pkh :: Satoshi Source #

Bitcoin Core's P2PKH dust threshold (546 satoshis).

dust_p2sh :: Satoshi Source #

Bitcoin Core's P2SH dust threshold (540 satoshis).

dust_p2wpkh :: Satoshi Source #

Bitcoin Core's P2WPKH dust threshold (294 satoshis).

dust_p2wsh :: Satoshi Source #

Bitcoin Core's P2WSH dust threshold (330 satoshis).

Serialization

commitment_to_tx :: CommitmentTx -> Tx Source #

The unsigned commitment transaction as a ppad-tx Tx (with no witnesses), e.g. for computing its txid or sighashes.

htlc_to_tx :: HTLCTx -> Tx Source #

The unsigned HTLC transaction as a ppad-tx Tx.

closing_to_tx :: ClosingTx -> Tx Source #

The unsigned closing transaction as a ppad-tx Tx.

encode_commitment_tx :: CommitmentTx -> ByteString Source #

Serialize an unsigned commitment transaction, without witness data. This is the form whose double-SHA256 is the txid; it is not what segwit signatures commit to (see ppad-tx's Bitcoin.Prim.Tx.Sighash). To broadcast, attach the witness to commitment_to_tx and serialize with ppad-tx.

encode_htlc_tx :: HTLCTx -> ByteString Source #

Serialize an unsigned HTLC transaction, without witness data (cf. encode_commitment_tx).

encode_closing_tx :: ClosingTx -> ByteString Source #

Serialize an unsigned closing transaction, without witness data (cf. encode_commitment_tx).

Keys

Basepoints and per-commitment points

data Basepoints Source #

The four basepoints a party announces in open_channel or accept_channel.

Instances

Instances details
NFData Basepoints Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Basepoints -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" '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.1.1-xuvWUaIZwC11qDxWpk94k" '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 RevocationBasepoint Source #

A revocation_basepoint.

Instances

Instances details
NFData RevocationBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: RevocationBasepoint -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RevocationBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RevocationBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype PaymentBasepoint Source #

A payment_basepoint.

Constructors

PaymentBasepoint Point 

Instances

Instances details
NFData PaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: PaymentBasepoint -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "PaymentBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "PaymentBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype DelayedPaymentBasepoint Source #

A delayed_payment_basepoint.

Instances

Instances details
NFData DelayedPaymentBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: DelayedPaymentBasepoint -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "DelayedPaymentBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "DelayedPaymentBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype HtlcBasepoint Source #

An htlc_basepoint.

Constructors

HtlcBasepoint Point 

Instances

Instances details
NFData HtlcBasepoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: HtlcBasepoint -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "HtlcBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "HtlcBasepoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype PerCommitmentPoint Source #

A per-commitment point, from which a commitment's keys are derived.

Instances

Instances details
NFData PerCommitmentPoint Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: PerCommitmentPoint -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "PerCommitmentPoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "PerCommitmentPoint" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

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

Fails if the secret is not a valid secp256k1 secret key.

>>> let Just s = BOLT1.per_commitment_secret (BS.pack [31, 30 .. 0])
>>> let Just (PerCommitmentPoint p) = derive_per_commitment_point s
>>> B16.encode (BOLT1.un_point p)
"025f7117a78150fe2ef97db7cfc83bd57b2e2c0d0dd25eaf467a4a1c2a45ce1486"

derive_per_commitment_point' :: Context -> PerCommitmentSecret -> Maybe PerCommitmentPoint Source #

As derive_per_commitment_point, but uses a precomputed Context to speed up the scalar multiplication.

Public keys

data CommitmentKeys Source #

The keys a commitment transaction's scripts use.

Instances

Instances details
NFData CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Methods

rnf :: CommitmentKeys -> () #

Generic CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Associated Types

type Rep CommitmentKeys 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Keys" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" '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_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.Keys

Eq CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

type Rep CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Keys" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" '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_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)))))

derive_commitment_keys Source #

Arguments

:: Basepoints

the owner's basepoints

-> FundingPubkey

the owner's funding pubkey

-> Basepoints

the other party's basepoints

-> FundingPubkey

the other party's funding pubkey

-> PerCommitmentPoint

the owner's per-commitment point

-> Maybe CommitmentKeys 

Derive the keys for a commitment transaction from both parties' basepoints and funding pubkeys, and the commitment owner's per-commitment point.

The owner is the "local" party: its delayed and HTLC basepoints give local_delayedpubkey and local_htlcpubkey, while the other party's revocation and HTLC basepoints give revocationpubkey and remote_htlcpubkey. As every supported CommitmentFormat uses option_static_remotekey, remotepubkey is the other party's payment_basepoint.

Fails if a basepoint it derives a key from, or the per-commitment point, is not on the curve.

newtype RevocationPubkey Source #

A commitment's revocationpubkey.

Constructors

RevocationPubkey Point 

Instances

Instances details
NFData RevocationPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: RevocationPubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RevocationPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RevocationPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype LocalDelayedPubkey Source #

A commitment's local_delayedpubkey: the owner's key for its delayed outputs.

Instances

Instances details
NFData LocalDelayedPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: LocalDelayedPubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "LocalDelayedPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "LocalDelayedPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype LocalHtlcPubkey Source #

A commitment's local_htlcpubkey: the owner's HTLC key.

Constructors

LocalHtlcPubkey Point 

Instances

Instances details
NFData LocalHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: LocalHtlcPubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "LocalHtlcPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "LocalHtlcPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype RemoteHtlcPubkey Source #

A commitment's remote_htlcpubkey: the other party's HTLC key.

Constructors

RemoteHtlcPubkey Point 

Instances

Instances details
NFData RemoteHtlcPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: RemoteHtlcPubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RemoteHtlcPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RemoteHtlcPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype RemotePubkey Source #

A commitment's remotepubkey: the other party's payment_basepoint, which its to_remote output pays.

Constructors

RemotePubkey Point 

Instances

Instances details
NFData RemotePubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: RemotePubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RemotePubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "RemotePubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

newtype FundingPubkey Source #

A funding_pubkey.

Constructors

FundingPubkey Point 

Instances

Instances details
NFData FundingPubkey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: FundingPubkey -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "FundingPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))
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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "FundingPubkey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

derive_pubkey :: Point -> PerCommitmentPoint -> Maybe Point Source #

Derive a per-commitment public key from a basepoint:

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

This gives local_htlcpubkey, remote_htlcpubkey, local_delayedpubkey and the like, depending on the basepoint; derive_commitment_keys derives all of a commitment's keys at once.

Fails if the basepoint is not on the curve.

>>> let Just s = BOLT1.per_commitment_secret (BS.pack [31, 30 .. 0])
>>> let Just pcp = derive_per_commitment_point s
>>> let Just b = BOLT1.per_commitment_secret (BS.pack [0 .. 31])
>>> let Just (PerCommitmentPoint bp) = derive_per_commitment_point b
>>> fmap (B16.encode . BOLT1.un_point) (derive_pubkey bp pcp)
Just "0235f2dbfaa89b57ec7b055afe29849ef7ddfeb1cefdb9ebdc43f5494984db29e5"

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

Derive a commitment's revocationpubkey from the revocation basepoint of the party that will hold the revocation key, and the commitment owner's per-commitment point:

  revocationpubkey =
      revocation_basepoint
        * SHA256(revocation_basepoint || per_commitment_point)
    + per_commitment_point
        * SHA256(per_commitment_point || revocation_basepoint)
  

Fails if either point is not on the curve.

>>> let Just s = BOLT1.per_commitment_secret (BS.pack [31, 30 .. 0])
>>> let Just pcp = derive_per_commitment_point s
>>> let Just b = BOLT1.per_commitment_secret (BS.pack [0 .. 31])
>>> let Just (PerCommitmentPoint p) = derive_per_commitment_point b
>>> let Just r = derive_revocationpubkey (RevocationBasepoint p) pcp
>>> (\(RevocationPubkey k) -> B16.encode (BOLT1.un_point k)) r
"02916e326636d19c33f13e8c0c3a03dd157f332f3e99c317c141dd865eb01f8ff0"

Private keys

data Seckey Source #

A secp256k1 secret key: 32 bytes encoding an integer in [1, n), for n the group order.

This is secret material: its Show instance is redacted, and it has no Eq instance.

Instances

Instances details
NFData Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Seckey -> () #

Show Seckey Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

seckey :: ByteString -> Maybe Seckey Source #

Construct a Seckey from 32 big-endian bytes. Fails unless the bytes encode an integer in [1, n).

>>> fmap (BS.length . un_seckey) (seckey (BS.replicate 32 0x01))
Just 32
>>> seckey (BS.replicate 32 0x00)
Nothing
>>> seckey (BS.replicate 32 0xff)
Nothing

un_seckey :: Seckey -> ByteString Source #

The bytes of a Seckey.

derive_privkey :: Seckey -> PerCommitmentPoint -> Maybe Seckey Source #

Derive the private key for a per-commitment public key from its basepoint secret:

privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)

where basepoint = basepoint_secret * G. The result is the secret key for derive_pubkey basepoint per_commitment_point.

The arithmetic on the secret is constant-time. Fails (with negligible probability) if the result is zero.

>>> let Just s = BOLT1.per_commitment_secret (BS.pack [31, 30 .. 0])
>>> let Just pcp = derive_per_commitment_point s
>>> let Just k = seckey (BS.pack [0 .. 31])
>>> fmap (B16.encode . un_seckey) (derive_privkey k pcp)
Just "cbced912d3b21bf196a766651e436aff192362621ce317704ea2f75d87e7be0f"

derive_revocationprivkey Source #

Arguments

:: Seckey

revocation basepoint secret

-> PerCommitmentSecret

per-commitment secret

-> Maybe Seckey 

Derive a commitment's revocationprivkey from the revocation basepoint secret and the commitment's (revealed) per-commitment secret:

  revocationprivkey =
      revocation_basepoint_secret
        * SHA256(revocation_basepoint || per_commitment_point)
    + per_commitment_secret
        * SHA256(per_commitment_point || revocation_basepoint)
  

The result is the secret key for the derive_revocationpubkey of the corresponding points.

The arithmetic on the secrets is constant-time. Fails if the per-commitment secret is not a valid secret key, or (with negligible probability) if the result is zero.

>>> let Just s = BOLT1.per_commitment_secret (BS.pack [31, 30 .. 0])
>>> let Just k = seckey (BS.pack [0 .. 31])
>>> fmap (B16.encode . un_seckey) (derive_revocationprivkey k s)
Just "d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110"

Per-commitment secrets

data Seed Source #

The 32-byte seed from which a party generates its per-commitment secrets.

This is secret material: its Show instance is redacted, and it has no Eq instance.

Instances

Instances details
NFData Seed Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Seed -> () #

Show Seed Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

showsPrec :: Int -> Seed -> ShowS #

show :: Seed -> String #

showList :: [Seed] -> ShowS #

seed :: ByteString -> Maybe Seed Source #

Construct a Seed from exactly 32 bytes.

>>> fmap (BS.length . un_seed) (seed (BS.replicate 32 0xff))
Just 32
>>> seed (BS.replicate 31 0xff)
Nothing

un_seed :: Seed -> ByteString Source #

The bytes of a Seed.

data SecretIndex Source #

The 48-bit index I of a per-commitment secret. Secrets are used from index 2^48 - 1 downwards.

Instances

Instances details
NFData SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: SecretIndex -> () #

Generic SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Associated Types

type Rep SecretIndex 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep SecretIndex = D1 ('MetaData "SecretIndex" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "SecretIndex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Show SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Eq SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Ord SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep SecretIndex Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

type Rep SecretIndex = D1 ('MetaData "SecretIndex" "Lightning.Protocol.BOLT3.Types" "ppad-bolt3-0.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "SecretIndex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

secret_index :: Word64 -> Maybe SecretIndex Source #

Construct a SecretIndex. Fails at or above 2^48.

>>> secret_index 281474976710655
Just (SecretIndex 281474976710655)
>>> secret_index 281474976710656
Nothing

commitment_secret_index :: CommitmentNumber -> SecretIndex Source #

The index of the per-commitment secret for a commitment number: 2^48 - 1 - n.

>>> fmap commitment_secret_index (commitment_number 0)
Just (SecretIndex 281474976710655)

generate_from_seed :: Seed -> SecretIndex -> PerCommitmentSecret Source #

Generate the per-commitment secret with a given index from a seed, per BOLT #3's generate_from_seed.

>>> let Just s = seed (BS.replicate 32 0xff)
>>> let Just i = secret_index 281474976710655
>>> B16.encode (BOLT1.un_per_commitment_secret (generate_from_seed s i))
"7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc"

Storage

data SecretStore Source #

Compact storage for the per-commitment secrets received from a peer, per BOLT #3's "Efficient Per-commitment Secret Storage".

Holds at most 49 secrets, from which every secret received so far can be derived. This is secret material: its Show instance is redacted, and it has no Eq instance.

Instances

Instances details
NFData SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

Methods

rnf :: SecretStore -> () #

Show SecretStore Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Keys

insert_secret :: PerCommitmentSecret -> SecretIndex -> SecretStore -> Maybe SecretStore Source #

Add a newly received per-commitment secret to the store, per BOLT #3's insert_secret.

Fails if a stored secret cannot be derived from the new one, i.e. if the secrets were not generated from the same seed (or were not received in order).

>>> let Just s = seed (BS.replicate 32 0xff)
>>> let Just i = secret_index 281474976710655
>>> let secret = generate_from_seed s i
>>> let Just st = insert_secret secret i empty_secret_store
>>> fmap (== secret) (derive_old_secret i st)
Just True

derive_old_secret :: SecretIndex -> SecretStore -> Maybe PerCommitmentSecret Source #

Derive a previously received per-commitment secret from the store. Fails if the index has not been received.

secret_store :: [(SecretIndex, PerCommitmentSecret)] -> Maybe SecretStore Source #

Rebuild a SecretStore from its entries, e.g. as produced by un_secret_store.

Fails if two entries share a bucket (i.e. their indices have the same number of trailing zeros), or if an entry contradicts another from which it can be derived.

Commitment number obscuring

obscured_commitment_number Source #

Arguments

:: PaymentBasepoint

opener's payment_basepoint

-> PaymentBasepoint

accepter's payment_basepoint

-> CommitmentNumber 
-> Word64 

Obscure a commitment number, by XOR with the lower 48 bits of

SHA256(payment_basepoint from open_channel
           || payment_basepoint from accept_channel)

As XOR is an involution, applying this to an obscured number recovers the commitment number. (build_commitment_tx obscures the commitment number itself.)

>>> let pay h = fmap PaymentBasepoint (BOLT1.point =<< B16.decode h)
>>> let o1 = "034f355bdcb7cc0af728ef3cceb9615d9068"
>>> let Just o = pay (o1 <> "4bb5b2ca5f859ab0f0b704075871aa")
>>> let a1 = "032c0b7cf95324a07d05398b240174dc0c2b"
>>> let Just a = pay (a1 <> "e444d96b159aa6c7f7b1e668680991")
>>> fmap (obscured_commitment_number o a) (commitment_number 42)
Just 48035859142974

Scripts and witnesses

newtype Script Source #

A serialized Bitcoin script.

Constructors

Script ByteString 

Instances

Instances details
NFData Script Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Types

Methods

rnf :: Script -> () #

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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Script" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) '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.1.1-xuvWUaIZwC11qDxWpk94k" 'True) (C1 ('MetaCons "Script" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

to_p2wsh :: Script -> Script Source #

The P2WSH scriptPubKey for a witness script: 0 <SHA256(script)>.

Funding output

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

The funding output's witness script:

2 <pubkey1> <pubkey2> 2 OP_CHECKMULTISIG

where pubkey1 is the lexicographically lesser of the two funding pubkeys. The argument order doesn't matter.

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

The witness spending the funding output, given each party's funding pubkey and signature (DER-encoded, with sighash byte):

0 <signature_for_pubkey1> <signature_for_pubkey2> <script>

The signatures are ordered to match the pubkeys in funding_script, so the argument order doesn't matter.

to_local output

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

The to_local output's witness script:

  OP_IF
      <revocationpubkey>
  OP_ELSE
      <to_self_delay> OP_CHECKSEQUENCEVERIFY OP_DROP
      <local_delayedpubkey>
  OP_ENDIF
  OP_CHECKSIG
  

HTLC-success and HTLC-timeout transaction outputs use the same script.

to_local_witness_spend :: ByteString -> Script -> Witness Source #

The witness for the owner's delayed spend of a to_local (or HTLC transaction) output, given its witness script:

<local_delayedsig> <> <script>

The spending input's nSequence must be to_self_delay.

to_local_witness_revoke :: ByteString -> Script -> Witness Source #

The witness for the revocation spend of a to_local (or HTLC transaction) output, given its witness script:

<revocation_sig> 1 <script>

to_remote output

to_remote_witness_script :: RemotePubkey -> Script Source #

The to_remote output's witness script under Anchors:

<remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY

(Under StaticRemotekey the output is P2WPKH, with no witness script; see to_remote_script_pubkey.)

to_remote_script_pubkey :: RemotePubkey -> CommitmentFormat -> Script Source #

The to_remote output's scriptPubKey: P2WPKH to remotepubkey under StaticRemotekey, and P2WSH of to_remote_witness_script under Anchors.

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

The witness spending a to_remote output: <remote_sig> <remotepubkey> (P2WPKH) under StaticRemotekey, and <remote_sig> <script> under Anchors, where the spending input's nSequence must be 1.

Anchor outputs

anchor_script :: FundingPubkey -> Script Source #

An anchor output's witness script, for the funding pubkey of the party it belongs to:

  <funding_pubkey> OP_CHECKSIG OP_IFDUP
  OP_NOTIF
      OP_16 OP_CHECKSEQUENCEVERIFY
  OP_ENDIF
  

anchor_witness_owner :: ByteString -> FundingPubkey -> Witness Source #

The witness for an anchor's owner to spend it: <sig> <script>.

anchor_witness_anyone :: FundingPubkey -> Witness Source #

The witness for anyone to sweep an anchor, 16 blocks after the commitment transaction confirms: <> <script>.

Offered HTLC outputs

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

An offered HTLC output's witness script:

  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
  

Under Anchors, 1 OP_CHECKSEQUENCEVERIFY OP_DROP precedes the final OP_ENDIF.

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

The witness for the remote party to claim an offered HTLC output with the payment preimage, given its witness script:

<remotehtlcsig> <payment_preimage> <script>

Under Anchors the spending input's nSequence must be 1.

offered_htlc_witness_revoke :: ByteString -> RevocationPubkey -> Script -> Witness Source #

The witness for the revocation spend of an offered HTLC output, given its witness script:

<revocation_sig> <revocationpubkey> <script>

Received HTLC outputs

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

A received HTLC output's witness script:

  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
  

Under Anchors, 1 OP_CHECKSEQUENCEVERIFY OP_DROP precedes the final OP_ENDIF.

received_htlc_witness_timeout :: ByteString -> Script -> Witness Source #

The witness for the remote party to time out a received HTLC output, given its witness script:

<remotehtlcsig> <> <script>

Under Anchors the spending input's nSequence must be 1.

received_htlc_witness_revoke :: ByteString -> RevocationPubkey -> Script -> Witness Source #

The witness for the revocation spend of a received HTLC output, given its witness script:

<revocation_sig> <revocationpubkey> <script>

HTLC transaction inputs

htlc_success_witness Source #

Arguments

:: ByteString

remotehtlcsig

-> ByteString

localhtlcsig

-> PaymentPreimage 
-> Script

the received HTLC output's witness script

-> Witness 

The witness for an HTLC-success transaction's input, given both HTLC signatures, the payment preimage and the received HTLC output's witness script:

0 <remotehtlcsig> <localhtlcsig> <payment_preimage> <script>

See remote_htlc_sighash for the signatures' sighash types.

htlc_timeout_witness Source #

Arguments

:: ByteString

remotehtlcsig

-> ByteString

localhtlcsig

-> Script

the offered HTLC output's witness script

-> Witness 

The witness for an HTLC-timeout transaction's input, given both HTLC signatures and the offered HTLC output's witness script:

0 <remotehtlcsig> <localhtlcsig> <> <script>

See remote_htlc_sighash for the signatures' sighash types.

remote_htlc_sighash :: CommitmentFormat -> SighashType Source #

The sighash type of remotehtlcsig: the signature on an HTLC-success or HTLC-timeout transaction that the commitment's non-owner sends in commitment_signed.

Under Anchors it is SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, so that the owner can add inputs and outputs to pay the (otherwise zero) fee; under StaticRemotekey it is SIGHASH_ALL. The owner's own signature, localhtlcsig, always uses SIGHASH_ALL.

>>> remote_htlc_sighash Anchors
SIGHASH_SINGLE_ANYONECANPAY