Browse Source

type_to_string: add secp256k1_pubkey

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
a25e2816e9
  1. 12
      bitcoin/pubkey.c
  2. 3
      bitcoin/pubkey.h
  3. 2
      type_to_string.h

12
bitcoin/pubkey.c

@ -62,6 +62,18 @@ char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key)
return tal_hexstr(ctx, der, sizeof(der));
}
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key)
{
unsigned char der[PUBKEY_DER_LEN];
size_t outlen = sizeof(der);
if (!secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &outlen, key,
SECP256K1_EC_COMPRESSED))
abort();
assert(outlen == sizeof(der));
return tal_hexstr(ctx, der, sizeof(der));
}
REGISTER_TYPE_TO_STRING(secp256k1_pubkey, secp256k1_pubkey_to_hexstr);
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b)
{
return structeq(&a->pubkey, &b->pubkey);

3
bitcoin/pubkey.h

@ -20,6 +20,9 @@ bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key);
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key);
/* Convenience wrapper for a raw secp256k1_pubkey */
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);
/* Pubkey from privkey */
bool pubkey_from_privkey(const struct privkey *privkey,
struct pubkey *key);

2
type_to_string.h

@ -3,6 +3,7 @@
#include "config.h"
#include "utils.h"
#include <ccan/autodata/autodata.h>
#include <secp256k1.h>
/* This must match the type_to_string_ cases. */
union printable_types {
@ -17,6 +18,7 @@ union printable_types {
const struct channel_state *channel_state;
const struct channel_oneside *channel_oneside;
const struct netaddr *netaddr;
const secp256k1_pubkey *secp256k1_pubkey;
const char *charp_;
};

Loading…
Cancel
Save