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