README.md (3396B)
1 # ppad-bolt2 2 3 [](https://hackage.haskell.org/package/ppad-bolt2) 4  5 [](https://docs.ppad.tech/bolt2) 6 7 Haskell implementation of BOLT #2 (Lightning Network peer protocol), 8 including message types and codecs for channel establishment, normal 9 operation, and channel close. 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.BOLT2 as BOLT2 20 > import Lightning.Protocol.BOLT1 (TlvStream(..)) 21 > 22 > -- construct an open_channel message 23 > let Just cid = BOLT2.channelId (BS.replicate 32 0x00) 24 > let Just ch = BOLT2.chainHash (BS.replicate 32 0x01) 25 > let Just pk = BOLT2.point (BS.cons 0x02 (BS.replicate 32 0xff)) 26 > 27 > let msg = BOLT2.OpenChannel 28 > { BOLT2.openChannelChainHash = ch 29 > , BOLT2.openChannelTempChannelId = cid 30 > , BOLT2.openChannelFundingSatoshis = BOLT2.Satoshis 1000000 31 > , BOLT2.openChannelPushMsat = BOLT2.MilliSatoshis 0 32 > , BOLT2.openChannelDustLimitSatoshis = BOLT2.Satoshis 546 33 > , BOLT2.openChannelMaxHtlcValueInFlight = BOLT2.MilliSatoshis 100000000 34 > , BOLT2.openChannelChannelReserveSat = BOLT2.Satoshis 10000 35 > , BOLT2.openChannelHtlcMinimumMsat = BOLT2.MilliSatoshis 1000 36 > , BOLT2.openChannelFeeratePerKw = 2500 37 > , BOLT2.openChannelToSelfDelay = 144 38 > , BOLT2.openChannelMaxAcceptedHtlcs = 483 39 > , BOLT2.openChannelFundingPubkey = pk 40 > , BOLT2.openChannelRevocationBasepoint = pk 41 > , BOLT2.openChannelPaymentBasepoint = pk 42 > , BOLT2.openChannelDelayedPaymentBase = pk 43 > , BOLT2.openChannelHtlcBasepoint = pk 44 > , BOLT2.openChannelFirstPerCommitPoint = pk 45 > , BOLT2.openChannelChannelFlags = 0x01 46 > , BOLT2.openChannelTlvs = TlvStream [] 47 > } 48 > 49 > -- encode and decode 50 > let encoded = BOLT2.encodeOpenChannel msg 51 > BS.length encoded 52 319 53 > BOLT2.decodeOpenChannel encoded 54 Right (OpenChannel {..}, "") 55 ``` 56 57 ## Message Types 58 59 Supported BOLT #2 messages: 60 61 - Channel establishment v1: `open_channel`, `accept_channel`, 62 `funding_created`, `funding_signed`, `channel_ready` 63 - Channel establishment v2: `open_channel2`, `accept_channel2`, 64 `tx_add_input`, `tx_add_output`, `tx_remove_input`, `tx_remove_output`, 65 `tx_complete`, `tx_signatures`, `tx_init_rbf`, `tx_ack_rbf`, `tx_abort` 66 - Channel close: `stfu`, `shutdown`, `closing_signed`, `closing_complete`, 67 `closing_sig` 68 - Normal operation: `update_add_htlc`, `update_fulfill_htlc`, 69 `update_fail_htlc`, `update_fail_malformed_htlc`, `commitment_signed`, 70 `revoke_and_ack`, `update_fee` 71 - Reestablishment: `channel_reestablish` 72 73 ## Documentation 74 75 Haddocks are hosted at [docs.ppad.tech/bolt2][hadoc]. 76 77 ## Security 78 79 This is a pre-release version of the library and makes no guarantees about 80 security whatsoever. 81 82 ## Development 83 84 You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a 85 development shell with: 86 87 ``` 88 $ nix develop 89 ``` 90 91 Then do e.g.: 92 93 ``` 94 $ cabal build 95 $ cabal test 96 $ cabal bench 97 ``` 98 99 [nixos]: https://nixos.org/ 100 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html 101 [hadoc]: https://docs.ppad.tech/bolt2