2015-06-12 04:23:27 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_SIGNATURE_H
|
|
|
|
#define LIGHTNING_BITCOIN_SIGNATURE_H
|
2015-05-28 23:38:27 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
2015-06-12 04:56:59 +02:00
|
|
|
#include <openssl/ecdsa.h>
|
2015-05-28 23:38:27 +02:00
|
|
|
|
|
|
|
enum sighash_type {
|
|
|
|
SIGHASH_ALL = 1,
|
|
|
|
SIGHASH_NONE = 2,
|
|
|
|
SIGHASH_SINGLE = 3,
|
|
|
|
SIGHASH_ANYONECANPAY = 0x80
|
|
|
|
};
|
|
|
|
|
2015-06-01 04:26:09 +02:00
|
|
|
/* ECDSA of double SHA256. */
|
|
|
|
struct signature {
|
|
|
|
u8 r[32];
|
|
|
|
u8 s[32];
|
|
|
|
};
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
struct sha256_double;
|
2015-05-30 12:41:10 +02:00
|
|
|
struct bitcoin_tx;
|
2015-06-02 06:10:00 +02:00
|
|
|
struct pubkey;
|
|
|
|
struct bitcoin_tx_output;
|
2015-06-04 08:16:49 +02:00
|
|
|
struct bitcoin_signature;
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2015-06-04 08:16:49 +02:00
|
|
|
bool sign_hash(const tal_t *ctx, EC_KEY *private_key,
|
|
|
|
const struct sha256_double *h,
|
|
|
|
struct signature *s);
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2015-05-30 12:41:10 +02:00
|
|
|
/* All tx input scripts must be set to 0 len. */
|
2015-06-04 08:16:49 +02:00
|
|
|
bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
|
|
|
|
unsigned int in,
|
|
|
|
const u8 *subscript, size_t subscript_len,
|
2015-06-10 13:02:43 +02:00
|
|
|
EC_KEY *privkey, const struct pubkey *pubkey,
|
|
|
|
struct 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. */
|
|
|
|
bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
|
|
|
|
const u8 *redeemscript, size_t redeemscript_len,
|
|
|
|
const struct pubkey *key,
|
|
|
|
const struct bitcoin_signature *sig);
|
|
|
|
|
2015-06-02 06:10:00 +02:00
|
|
|
bool check_2of2_sig(struct bitcoin_tx *tx, size_t input_num,
|
2015-06-04 13:36:42 +02:00
|
|
|
const u8 *redeemscript, size_t redeemscript_len,
|
2015-06-02 06:10:00 +02:00
|
|
|
const struct pubkey *key1, const struct pubkey *key2,
|
2015-06-04 08:16:49 +02:00
|
|
|
const struct bitcoin_signature *sig1,
|
|
|
|
const struct bitcoin_signature *sig2);
|
2015-06-02 06:10:00 +02:00
|
|
|
|
2015-06-26 03:51:08 +02:00
|
|
|
/* Give DER encoding of signature: returns length used (<= 72). */
|
|
|
|
size_t signature_to_der(u8 der[72], const struct signature *s);
|
|
|
|
|
2015-06-12 04:23:27 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_SIGNATURE_H */
|