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"
|
2017-06-14 10:29:10 +02:00
|
|
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
|
|
|
#include <ccan/crypto/sha256/sha256.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-12-02 08:42:58 +01:00
|
|
|
bool pubkey_from_hexstr(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) */
|
2016-12-02 08:42:58 +01:00
|
|
|
char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key);
|
2016-07-01 03:49:28 +02:00
|
|
|
|
2017-01-25 00:32:43 +01:00
|
|
|
/* Convenience wrapper for a raw secp256k1_pubkey */
|
|
|
|
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);
|
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Pubkey from privkey */
|
2016-12-02 08:42:58 +01:00
|
|
|
bool pubkey_from_privkey(const struct privkey *privkey,
|
2016-07-01 03:57:57 +02:00
|
|
|
struct pubkey *key);
|
2015-06-02 04:23:59 +02:00
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Pubkey from DER encoding. */
|
2016-12-02 08:42:58 +01:00
|
|
|
bool pubkey_from_der(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. */
|
2016-12-02 08:42:58 +01:00
|
|
|
void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key);
|
2016-07-01 03:49:28 +02:00
|
|
|
|
2015-09-30 03:24:54 +02:00
|
|
|
/* Are these keys equal? */
|
|
|
|
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b);
|
2016-12-12 13:12:58 +01:00
|
|
|
|
|
|
|
/* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */
|
|
|
|
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b);
|
2017-06-14 10:29:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* pubkey_to_hash160 - Get the hash for p2pkh payments for a given pubkey
|
|
|
|
*/
|
|
|
|
void pubkey_to_hash160(const struct pubkey *pk, struct ripemd160 *hash);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_PUBKEY_H */
|