https://github.com/ppad-tech/bolt5
On-chain transaction handling for Lightning.
https://github.com/ppad-tech/bolt5
haskell htlc lightning transactions
Last synced: about 4 hours ago
JSON representation
On-chain transaction handling for Lightning.
- Host: GitHub
- URL: https://github.com/ppad-tech/bolt5
- Owner: ppad-tech
- License: mit
- Created: 2026-04-19T03:58:58.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2026-04-20T08:28:32.000Z (about 2 months ago)
- Last Synced: 2026-04-20T09:33:03.703Z (about 2 months ago)
- Topics: haskell, htlc, lightning, transactions
- Language: Haskell
- Homepage:
- Size: 63.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# ppad-bolt5
[](https://hackage.haskell.org/package/ppad-bolt5)

[](https://docs.ppad.tech/bolt5)
A pure Haskell implementation of [BOLT #5][bolt5] (Lightning Network
on-chain transaction handling), including logic for mutual close,
unilateral close, and revoked transaction close scenarios.
## Usage
A sample GHCi session:
```
> :set -XOverloadedStrings
>
> import qualified Data.ByteString as BS
> import qualified Lightning.Protocol.BOLT3 as BOLT3
> import qualified Lightning.Protocol.BOLT5 as BOLT5
>
> -- fee calculation using BOLT #5 Appendix A weight constants
> let feerate = BOLT3.FeeratePerKw 5000
> BOLT5.spending_fee feerate BOLT5.to_local_penalty_input_weight
Satoshi 1620
> BOLT5.spending_fee feerate BOLT5.penalty_tx_base_weight
Satoshi 1070
>
> -- check if an HTLC has timed out at the current block height
> let htlc = BOLT3.HTLC BOLT3.HTLCOffered (BOLT3.MilliSatoshi 50000000)
> (BOLT3.PaymentHash (BS.replicate 32 0xAA))
> (BOLT3.CltvExpiry 800000)
> BOLT5.htlc_timed_out 799999 htlc
False
> BOLT5.htlc_timed_out 800000 htlc
True
>
> -- extract a payment preimage from an offered HTLC witness
> let preimage = BS.replicate 32 0xBB
> let sig = BS.replicate 71 0xCC
> let wit = BOLT3.Witness [sig, preimage]
> BOLT5.extract_preimage_offered wit
Just PaymentPreimage
>
> -- construct an unsigned spending tx for a to_local output
> let Just txid = BOLT3.mkTxId (BS.replicate 32 0x01)
> let outpoint = BOLT3.OutPoint txid 0
> let value = BOLT3.Satoshi 1000000
> let revpk = BOLT3.RevocationPubkey (BOLT3.Pubkey (BS.replicate 33 0x02))
> let delay = BOLT3.ToSelfDelay 144
> let delayedpk = BOLT3.LocalDelayedPubkey (BOLT3.Pubkey (BS.replicate 33 0x03))
> let dest = BOLT3.Script (BS.replicate 34 0x00)
>
> let stx = BOLT5.spend_to_local outpoint value revpk delay
> delayedpk dest feerate
> BOLT5.stx_sighash_type stx
SIGHASH_ALL
```
## Documentation
Haddocks are hosted at [docs.ppad.tech/bolt5][hadoc].
## Security
This is a pre-release and makes no claims about security whatsoever.
## Development
You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a
development shell with:
```
$ nix develop
```
Then do e.g.:
```
$ cabal build
$ cabal test
$ cabal bench
```
[bolt5]: https://github.com/lightning/bolts/blob/master/05-onchain.md
[nixos]: https://nixos.org/
[flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html
[hadoc]: https://docs.ppad.tech/bolt5