tx

Minimal transaction primitives (docs.ppad.tech/tx).
git clone git://git.ppad.tech/tx.git
Log | Files | Refs | README | LICENSE

README.md (2235B)


      1 # ppad-tx
      2 
      3 [![](https://img.shields.io/hackage/v/ppad-tx?color=blue)](https://hackage.haskell.org/package/ppad-tx)
      4 ![](https://img.shields.io/badge/license-MIT-brightgreen)
      5 [![](https://img.shields.io/badge/haddock-tx-lightblue)](https://docs.ppad.tech/tx)
      6 
      7 Minimal Bitcoin transaction primitives, including raw transaction
      8 types, serialisation to/from bytes, txid computation, and sighash
      9 calculation (legacy and BIP143 segwit).
     10 
     11 ## Usage
     12 
     13 A sample GHCi session:
     14 
     15 ```
     16   > :set -XOverloadedStrings
     17   > import qualified Data.ByteString as BS
     18   > import qualified Data.ByteString.Base16 as B16
     19   > import Bitcoin.Prim.Tx
     20   > import Bitcoin.Prim.Tx.Sighash
     21   >
     22   > -- parse a raw transaction from hex
     23   > let raw = "0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000"
     24   > let Just tx = from_base16 raw
     25   >
     26   > -- compute the txid
     27   > let TxId tid = txid tx
     28   > B16.encode (BS.reverse tid)
     29   "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"
     30   >
     31   > -- round-trip serialisation
     32   > from_bytes (to_bytes tx) == Just tx
     33   True
     34   >
     35   > -- compute a legacy sighash
     36   > let scriptPubKey = BS.pack [0x76, 0xa9, 0x14]
     37   > let hash = sighash_legacy tx 0 scriptPubKey SIGHASH_ALL
     38   > BS.length hash
     39   32
     40 ```
     41 
     42 ## Documentation
     43 
     44 Haddocks are hosted at [docs.ppad.tech/tx][hadoc].
     45 
     46 ## Security
     47 
     48 This is a pre-release library that, at present, claims no security
     49 properties whatsoever.
     50 
     51 ## Development
     52 
     53 You'll require [Nix][nixos] with [flake][flake] support enabled.
     54 Enter a development shell with:
     55 
     56 ```
     57 $ nix develop
     58 ```
     59 
     60 Then do e.g.:
     61 
     62 ```
     63 $ cabal build
     64 $ cabal test
     65 $ cabal bench
     66 ```
     67 
     68 [nixos]: https://nixos.org/
     69 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html
     70 [hadoc]: https://docs.ppad.tech/tx