type_to_string: add privkey.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-02-02 14:35:45 +10:30
parent d97e3489a0
commit 25a37fafae
3 changed files with 11 additions and 1 deletions

View File

@ -7,5 +7,4 @@
struct privkey {
u8 secret[32];
};
#endif /* LIGHTNING_BITCOIN_PRIVKEY_H */

View File

@ -88,3 +88,13 @@ int pubkey_cmp(const struct pubkey *a, const struct pubkey *b)
pubkey_to_der(keyb, b);
return memcmp(keya, keyb, sizeof(keya));
}
static char *privkey_to_hexstr(const tal_t *ctx, const struct privkey *secret)
{
/* Bitcoin appends "01" to indicate the pubkey is compressed. */
char *str = tal_arr(ctx, char, hex_str_size(sizeof(*secret) + 1));
hex_encode(secret, sizeof(*secret), str, hex_str_size(sizeof(*secret)));
strcat(str, "01");
return str;
}
REGISTER_TYPE_TO_STRING(privkey, privkey_to_hexstr);

View File

@ -20,6 +20,7 @@ union printable_types {
const struct netaddr *netaddr;
const secp256k1_pubkey *secp256k1_pubkey;
const struct channel_id *channel_id;
const struct privkey *privkey;
const char *charp_;
};