shared-libraries.md
1 Shared Libraries 2 ================ 3 4 ## bitcoinconsensus 5 ***This library is deprecated and will be removed in v28*** 6 7 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. 8 9 ### API 10 11 The interface is defined in the C header `bitcoinconsensus.h` located in `src/script/bitcoinconsensus.h`. 12 13 #### Version 14 15 `bitcoinconsensus_version` returns an `unsigned int` with the API version *(currently `2`)*. 16 17 #### Script Validation 18 19 `bitcoinconsensus_verify_script`, `bitcoinconsensus_verify_script_with_amount` and `bitcoinconsensus_verify_script_with_spent_outputs` return an `int` with the status of the verification. It will be `1` if the input script correctly spends the previous output `scriptPubKey`. 20 21 ##### Parameters 22 ###### bitcoinconsensus_verify_script 23 - `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. 24 - `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. 25 - `const unsigned char *txTo` - The transaction with the input that is spending the previous output. 26 - `unsigned int txToLen` - The number of bytes for the `txTo`. 27 - `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. 28 - `unsigned int flags` - The script validation flags *(see below)*. 29 - `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. 30 31 ###### bitcoinconsensus_verify_script_with_amount 32 - `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. 33 - `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. 34 - `int64_t amount` - The amount spent in the input 35 - `const unsigned char *txTo` - The transaction with the input that is spending the previous output. 36 - `unsigned int txToLen` - The number of bytes for the `txTo`. 37 - `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. 38 - `unsigned int flags` - The script validation flags *(see below)*. 39 - `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. 40 41 ###### bitcoinconsensus_verify_script_with_spent_outputs 42 - `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. 43 - `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. 44 - `int64_t amount` - The amount spent in the input 45 - `const unsigned char *txTo` - The transaction with the input that is spending the previous output. 46 - `unsigned int txToLen` - The number of bytes for the `txTo`. 47 - `UTXO *spentOutputs` - Previous outputs spent in the transaction. `UTXO` is a struct composed by `const unsigned char *scriptPubKey`, `unsigned int scriptPubKeySize` (the number of bytes for the `scriptPubKey`) and `unsigned int value`. 48 - `unsigned int spentOutputsLen` - The number of bytes for the `spentOutputs`. 49 - `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. 50 - `unsigned int flags` - The script validation flags *(see below)*. 51 - `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. 52 53 ##### Script Flags 54 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE` 55 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` - Evaluate P2SH ([BIP16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki)) subscripts 56 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG` - Enforce strict DER ([BIP66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki)) compliance 57 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY` - Enforce NULLDUMMY ([BIP147](https://github.com/bitcoin/bips/blob/master/bip-0147.mediawiki)) 58 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY` - Enable CHECKLOCKTIMEVERIFY ([BIP65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)) 59 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY` - Enable CHECKSEQUENCEVERIFY ([BIP112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki)) 60 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS` - Enable WITNESS ([BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)) 61 - `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT` - Enable TAPROOT ([BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki), [BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki), [BIP342](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki)) 62 63 ##### Errors 64 - `bitcoinconsensus_ERR_OK` - No errors with input parameters *(see the return value of `bitcoinconsensus_verify_script` for the verification status)* 65 - `bitcoinconsensus_ERR_TX_INDEX` - An invalid index for `txTo` 66 - `bitcoinconsensus_ERR_TX_SIZE_MISMATCH` - `txToLen` did not match with the size of `txTo` 67 - `bitcoinconsensus_ERR_DESERIALIZE` - An error deserializing `txTo` 68 - `bitcoinconsensus_ERR_AMOUNT_REQUIRED` - Input amount is required if WITNESS is used 69 - `bitcoinconsensus_ERR_INVALID_FLAGS` - Script verification `flags` are invalid (i.e. not part of the libconsensus interface) 70 - `bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED` - Spent outputs are required if TAPROOT is used 71 - `bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH` - Spent outputs size doesn't match tx inputs size 72 73 ### Example Implementations 74 - [NBitcoin](https://github.com/MetacoSA/NBitcoin/blob/5e1055cd7c4186dee4227c344af8892aea54faec/NBitcoin/Script.cs#L979-#L1031) (.NET Bindings) 75 - [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus) (Node.js Bindings) 76 - [java-libbitcoinconsensus](https://github.com/dexX7/java-libbitcoinconsensus) (Java Bindings) 77 - [bitcoinconsensus-php](https://github.com/Bit-Wasp/bitcoinconsensus-php) (PHP Bindings) 78 - [rust-bitcoinconsensus](https://github.com/rust-bitcoin/rust-bitcoinconsensus) (Rust Bindings)