README.md (2738B)
1 # ppad-bolt5 2 3 [](https://hackage.haskell.org/package/ppad-bolt5) 4  5 [](https://docs.ppad.tech/bolt5) 6 7 A pure Haskell implementation of [BOLT #5][bolt5] (Lightning Network 8 on-chain transaction handling), including logic for mutual close, 9 unilateral close, and revoked transaction close scenarios. 10 11 ## Usage 12 13 A sample GHCi session: 14 15 ``` 16 > :set -XOverloadedStrings 17 > 18 > import qualified Data.ByteString as BS 19 > import qualified Lightning.Protocol.BOLT3 as BOLT3 20 > import qualified Lightning.Protocol.BOLT5 as BOLT5 21 > 22 > -- fee calculation using BOLT #5 Appendix A weight constants 23 > let feerate = BOLT3.FeeratePerKw 5000 24 > BOLT5.spending_fee feerate BOLT5.to_local_penalty_input_weight 25 Satoshi 1620 26 > BOLT5.spending_fee feerate BOLT5.penalty_tx_base_weight 27 Satoshi 1070 28 > 29 > -- check if an HTLC has timed out at the current block height 30 > let htlc = BOLT3.HTLC BOLT3.HTLCOffered (BOLT3.MilliSatoshi 50000000) 31 > (BOLT3.PaymentHash (BS.replicate 32 0xAA)) 32 > (BOLT3.CltvExpiry 800000) 33 > BOLT5.htlc_timed_out 799999 htlc 34 False 35 > BOLT5.htlc_timed_out 800000 htlc 36 True 37 > 38 > -- extract a payment preimage from an offered HTLC witness 39 > let preimage = BS.replicate 32 0xBB 40 > let sig = BS.replicate 71 0xCC 41 > let wit = BOLT3.Witness [sig, preimage] 42 > BOLT5.extract_preimage_offered wit 43 Just PaymentPreimage <redacted> 44 > 45 > -- construct an unsigned spending tx for a to_local output 46 > let Just txid = BOLT3.mkTxId (BS.replicate 32 0x01) 47 > let outpoint = BOLT3.OutPoint txid 0 48 > let value = BOLT3.Satoshi 1000000 49 > let revpk = BOLT3.RevocationPubkey (BOLT3.Pubkey (BS.replicate 33 0x02)) 50 > let delay = BOLT3.ToSelfDelay 144 51 > let delayedpk = BOLT3.LocalDelayedPubkey (BOLT3.Pubkey (BS.replicate 33 0x03)) 52 > let dest = BOLT3.Script (BS.replicate 34 0x00) 53 > 54 > let stx = BOLT5.spend_to_local outpoint value revpk delay 55 > delayedpk dest feerate 56 > BOLT5.stx_sighash_type stx 57 SIGHASH_ALL 58 ``` 59 60 ## Documentation 61 62 Haddocks are hosted at [docs.ppad.tech/bolt5][hadoc]. 63 64 ## Security 65 66 This is a pre-release and makes no claims about security whatsoever. 67 68 ## Development 69 70 You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a 71 development shell with: 72 73 ``` 74 $ nix develop 75 ``` 76 77 Then do e.g.: 78 79 ``` 80 $ cabal build 81 $ cabal test 82 $ cabal bench 83 ``` 84 85 [bolt5]: https://github.com/lightning/bolts/blob/master/05-onchain.md 86 [nixos]: https://nixos.org/ 87 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html 88 [hadoc]: https://docs.ppad.tech/bolt5