2015-06-12 04:23:27 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_SIGNATURE_H
|
|
|
|
#define LIGHTNING_BITCOIN_SIGNATURE_H
|
2016-01-21 21:08:08 +01:00
|
|
|
#include "config.h"
|
2015-05-28 23:38:27 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2016-07-01 03:49:28 +02:00
|
|
|
#include <secp256k1.h>
|
2016-01-21 21:11:45 +01:00
|
|
|
#include <stdbool.h>
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2017-01-25 00:34:23 +01:00
|
|
|
struct sha256_double;
|
|
|
|
struct bitcoin_tx;
|
|
|
|
struct pubkey;
|
|
|
|
struct privkey;
|
|
|
|
struct bitcoin_tx_output;
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
enum sighash_type {
|
|
|
|
SIGHASH_ALL = 1,
|
|
|
|
SIGHASH_NONE = 2,
|
|
|
|
SIGHASH_SINGLE = 3,
|
|
|
|
SIGHASH_ANYONECANPAY = 0x80
|
|
|
|
};
|
|
|
|
|
2016-12-02 08:42:58 +01:00
|
|
|
void sign_hash(const struct privkey *p,
|
2015-06-04 08:16:49 +02:00
|
|
|
const struct sha256_double *h,
|
2017-01-25 00:33:42 +01:00
|
|
|
secp256k1_ecdsa_signature *s);
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2016-12-02 08:42:58 +01:00
|
|
|
bool check_signed_hash(const struct sha256_double *hash,
|
2017-01-25 00:33:42 +01:00
|
|
|
const secp256k1_ecdsa_signature *signature,
|
2016-01-21 21:11:45 +01:00
|
|
|
const struct pubkey *key);
|
|
|
|
|
2015-05-30 12:41:10 +02:00
|
|
|
/* All tx input scripts must be set to 0 len. */
|
2016-12-02 08:42:58 +01:00
|
|
|
void sign_tx_input(struct bitcoin_tx *tx,
|
2015-06-04 08:16:49 +02:00
|
|
|
unsigned int in,
|
2017-01-25 00:35:43 +01:00
|
|
|
const u8 *subscript,
|
2016-04-12 05:35:51 +02:00
|
|
|
const u8 *witness,
|
2015-06-26 04:24:07 +02:00
|
|
|
const struct privkey *privkey, const struct pubkey *pubkey,
|
2017-01-25 00:33:42 +01:00
|
|
|
secp256k1_ecdsa_signature *sig);
|
2015-05-30 12:41:10 +02:00
|
|
|
|
2015-06-09 03:26:51 +02:00
|
|
|
/* Does this sig sign the tx with this input for this pubkey. */
|
2016-12-02 08:42:58 +01:00
|
|
|
bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
|
2017-01-25 00:35:43 +01:00
|
|
|
const u8 *redeemscript,
|
2016-04-12 05:35:51 +02:00
|
|
|
const u8 *witness,
|
2015-06-09 03:26:51 +02:00
|
|
|
const struct pubkey *key,
|
2017-01-25 00:34:23 +01:00
|
|
|
const secp256k1_ecdsa_signature *sig);
|
2015-06-09 03:26:51 +02:00
|
|
|
|
2015-06-30 06:07:17 +02:00
|
|
|
/* Signature must have low S value. */
|
2017-01-25 00:33:42 +01:00
|
|
|
bool sig_valid(const secp256k1_ecdsa_signature *sig);
|
2015-06-30 06:07:17 +02:00
|
|
|
|
2015-06-26 03:51:08 +02:00
|
|
|
/* Give DER encoding of signature: returns length used (<= 72). */
|
2017-01-25 00:33:42 +01:00
|
|
|
size_t signature_to_der(u8 der[72], const secp256k1_ecdsa_signature *s);
|
2015-06-26 03:51:08 +02:00
|
|
|
|
2016-09-07 23:34:36 +02:00
|
|
|
/* Parse DER encoding into signature sig */
|
2017-01-25 00:33:42 +01:00
|
|
|
bool signature_from_der(const u8 *der, size_t len, secp256k1_ecdsa_signature *sig);
|
2016-09-07 23:34:36 +02:00
|
|
|
|
2015-06-12 04:23:27 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_SIGNATURE_H */
|