2015-06-12 03:23:27 +01:00
|
|
|
#ifndef LIGHTNING_BITCOIN_PUBKEY_H
|
|
|
|
#define LIGHTNING_BITCOIN_PUBKEY_H
|
2016-01-21 20:08:08 +00:00
|
|
|
#include "config.h"
|
2017-06-14 09:29:10 +01:00
|
|
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
|
|
|
#include <ccan/crypto/sha256/sha256.h>
|
2015-06-02 03:23:59 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
2016-07-01 02:49:28 +01:00
|
|
|
#include <secp256k1.h>
|
2015-09-30 02:24:54 +01:00
|
|
|
|
|
|
|
struct privkey;
|
2015-06-02 03:23:59 +01:00
|
|
|
|
2016-07-01 02:49:28 +01:00
|
|
|
#define PUBKEY_DER_LEN 33
|
|
|
|
|
2015-06-02 03:23:59 +01:00
|
|
|
struct pubkey {
|
2015-09-30 02:24:54 +01:00
|
|
|
/* Unpacked pubkey (as used by libsecp256k1 internally) */
|
|
|
|
secp256k1_pubkey pubkey;
|
2015-06-02 03:23:59 +01:00
|
|
|
};
|
|
|
|
|
2015-09-30 02:24:54 +01:00
|
|
|
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
|
2016-12-02 07:42:58 +00:00
|
|
|
bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key);
|
2015-09-30 02:24:54 +01:00
|
|
|
|
2016-07-01 02:49:28 +01:00
|
|
|
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
|
2016-12-02 07:42:58 +00:00
|
|
|
char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key);
|
2016-07-01 02:49:28 +01:00
|
|
|
|
2017-01-24 23:32:43 +00:00
|
|
|
/* Convenience wrapper for a raw secp256k1_pubkey */
|
|
|
|
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);
|
|
|
|
|
2015-09-30 02:24:54 +01:00
|
|
|
/* Pubkey from privkey */
|
2016-12-02 07:42:58 +00:00
|
|
|
bool pubkey_from_privkey(const struct privkey *privkey,
|
2016-07-01 02:57:57 +01:00
|
|
|
struct pubkey *key);
|
2015-06-02 03:23:59 +01:00
|
|
|
|
2015-09-30 02:24:54 +01:00
|
|
|
/* Pubkey from DER encoding. */
|
2016-12-02 07:42:58 +00:00
|
|
|
bool pubkey_from_der(const u8 *der, size_t len, struct pubkey *key);
|
2015-06-05 03:54:58 +01:00
|
|
|
|
2016-07-01 02:49:28 +01:00
|
|
|
/* Pubkey to DER encoding: must be valid pubkey. */
|
2016-12-02 07:42:58 +00:00
|
|
|
void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key);
|
2016-07-01 02:49:28 +01:00
|
|
|
|
2015-09-30 02:24:54 +01:00
|
|
|
/* Are these keys equal? */
|
|
|
|
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b);
|
2016-12-12 12:12:58 +00: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 09:29:10 +01: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 17:06:01 +01:00
|
|
|
#endif /* LIGHTNING_BITCOIN_PUBKEY_H */
|