mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
ed3f0115d6
I had each side using the other side's hash secret. That's a very dumb idea, since it means you can steal from a unilateral close! A's secret applies to A's commit transaction: it needs the secret and B's final signature to steal funds, and that should never happen (since A doesn't have the B's final signature, and once A has given B the secret, they never broadcast the commit tx). This makes the update a 4 step dance, since you need the new revocation hash to make the other side's TX to sign. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
55 lines
1.6 KiB
C
55 lines
1.6 KiB
C
#ifndef LIGHTNING_SIGNATURE_H
|
|
#define LIGHTNING_SIGNATURE_H
|
|
#include <ccan/short_types/short_types.h>
|
|
#include <openssl/ecdsa.h>
|
|
#include <ccan/tal/tal.h>
|
|
#include "lightning.pb-c.h"
|
|
|
|
enum sighash_type {
|
|
SIGHASH_ALL = 1,
|
|
SIGHASH_NONE = 2,
|
|
SIGHASH_SINGLE = 3,
|
|
SIGHASH_ANYONECANPAY = 0x80
|
|
};
|
|
|
|
/* ECDSA of double SHA256. */
|
|
struct signature {
|
|
u8 r[32];
|
|
u8 s[32];
|
|
};
|
|
|
|
struct sha256_double;
|
|
struct bitcoin_tx;
|
|
struct pubkey;
|
|
struct bitcoin_tx_output;
|
|
struct bitcoin_signature;
|
|
|
|
bool sign_hash(const tal_t *ctx, EC_KEY *private_key,
|
|
const struct sha256_double *h,
|
|
struct signature *s);
|
|
|
|
/* All tx input scripts must be set to 0 len. */
|
|
bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
|
|
unsigned int in,
|
|
const u8 *subscript, size_t subscript_len,
|
|
EC_KEY *privkey, const struct pubkey *pubkey,
|
|
struct signature *sig);
|
|
|
|
/* 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);
|
|
|
|
bool check_2of2_sig(struct bitcoin_tx *tx, size_t input_num,
|
|
const u8 *redeemscript, size_t redeemscript_len,
|
|
const struct pubkey *key1, const struct pubkey *key2,
|
|
const struct bitcoin_signature *sig1,
|
|
const struct bitcoin_signature *sig2);
|
|
|
|
/* Convert to-from protobuf to internal representation. */
|
|
Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig);
|
|
bool proto_to_signature(const Signature *pb, struct signature *sig);
|
|
|
|
#endif /* LIGHTNING_SIGNATURE_H */
|