mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
type_to_string: add secp256k1_pubkey
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
66175c7361
commit
a25e2816e9
3 changed files with 17 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue