|
| 1 | +Shared Libraries |
| 2 | +================ |
| 3 | + |
| 4 | +## bitcoinconsensus |
| 5 | + |
| 6 | +The purpose of this library is to make the verification functionality that is critical to Bitcoin's consensus available to other applications, e.g. to language bindings. |
| 7 | + |
| 8 | +### API |
| 9 | + |
| 10 | +The interface is defined in the C header `bitcoinconsensus.h` located in `src/script/bitcoinconsensus.h`. |
| 11 | + |
| 12 | +#### Version |
| 13 | + |
| 14 | +`bitcoinconsensus_version` returns an `unsigned int` with the the API version *(currently at an experimental `0`)*. |
| 15 | + |
| 16 | +#### Script Validation |
| 17 | + |
| 18 | +`bitcoinconsensus_verify_script` returns an `int` with the status of the verification. It will be `1` if the input script correctly spends the previous output `scriptPubKey`. |
| 19 | + |
| 20 | +##### Parameters |
| 21 | +- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. |
| 22 | +- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. |
| 23 | +- `const unsigned char *txTo` - The transaction with the input that is spending the previous output. |
| 24 | +- `unsigned int txToLen` - The number of bytes for the `txTo`. |
| 25 | +- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. |
| 26 | +- `unsigned int flags` - The script validation flags *(see below)*. |
| 27 | +- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. |
| 28 | + |
| 29 | +##### Script Flags |
| 30 | +- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE` |
| 31 | +- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` - Evaluate P2SH ([BIP16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki)) subscripts |
| 32 | +- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG` - Enforce strict DER ([BIP66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki)) compliance |
| 33 | + |
| 34 | +##### Errors |
| 35 | +- `bitcoinconsensus_ERR_OK` - No errors with input parameters *(see the return value of `bitcoinconsensus_verify_script` for the verification status)* |
| 36 | +- `bitcoinconsensus_ERR_TX_INDEX` - An invalid index for `txTo` |
| 37 | +- `bitcoinconsensus_ERR_TX_SIZE_MISMATCH` - `txToLen` did not match with the size of `txTo` |
| 38 | +- `bitcoinconsensus_ERR_DESERIALIZE` - An error deserializing `txTo` |
| 39 | + |
| 40 | +### Example Implementations |
| 41 | +- [NBitcoin](https://github.com/NicolasDorier/NBitcoin/blob/master/NBitcoin/Script.cs#L814) (.NET Bindings) |
| 42 | +- [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus) (Node.js Bindings) |
0 commit comments