2015-06-12 04:23:27 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_PUBKEY_H
|
|
|
|
#define LIGHTNING_BITCOIN_PUBKEY_H
|
2016-01-21 21:08:08 +01:00
|
|
|
#include "config.h"
|
2015-06-02 04:23:59 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
2016-07-01 03:49:28 +02:00
|
|
|
#include <secp256k1.h>
|
2015-09-30 03:24:54 +02:00
|
|
|
|
|
|
|
struct privkey;
|
2015-06-02 04:23:59 +02:00
|
|
|
|
2016-07-01 03:49:28 +02:00
|
|
|
#define PUBKEY_DER_LEN 33
|
|
|
|
|
2015-06-02 04:23:59 +02:00
|
|
|
struct pubkey {
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Unpacked pubkey (as used by libsecp256k1 internally) */
|
|
|
|
secp256k1_pubkey pubkey;
|
2015-06-02 04:23:59 +02:00
|
|
|
};
|
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
|
2016-01-21 21:11:47 +01:00
|
|
|
bool pubkey_from_hexstr(secp256k1_context *secpctx,
|
|
|
|
const char *derstr, size_t derlen, struct pubkey *key);
|
2015-09-30 03:24:54 +02:00
|
|
|
|
2016-07-01 03:49:28 +02:00
|
|
|
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
|
|
|
|
char *pubkey_to_hexstr(const tal_t *ctx, secp256k1_context *secpctx,
|
|
|
|
const struct pubkey *key);
|
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Pubkey from privkey */
|
2016-01-21 21:11:47 +01:00
|
|
|
bool pubkey_from_privkey(secp256k1_context *secpctx,
|
|
|
|
const struct privkey *privkey,
|
2015-09-30 03:24:54 +02:00
|
|
|
struct pubkey *key,
|
|
|
|
unsigned int compressed_flags);
|
2015-06-02 04:23:59 +02:00
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Pubkey from DER encoding. */
|
2016-01-21 21:11:47 +01:00
|
|
|
bool pubkey_from_der(secp256k1_context *secpctx,
|
|
|
|
const u8 *der, size_t len, struct pubkey *key);
|
2015-06-05 04:54:58 +02:00
|
|
|
|
2016-07-01 03:49:28 +02:00
|
|
|
/* Pubkey to DER encoding: must be valid pubkey. */
|
|
|
|
void pubkey_to_der(secp256k1_context *secpctx, u8 der[PUBKEY_DER_LEN],
|
|
|
|
const struct pubkey *key);
|
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Are these keys equal? */
|
|
|
|
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b);
|
2015-06-02 04:23:59 +02:00
|
|
|
#endif /* LIGHTNING_PUBKEY_H */
|