Skip to content

Commit

Permalink
type_to_string: add privkey.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 2, 2017
1 parent d97e348 commit 25a37fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion bitcoin/privkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
struct privkey {
u8 secret[32];
};

#endif /* LIGHTNING_BITCOIN_PRIVKEY_H */
10 changes: 10 additions & 0 deletions bitcoin/pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 1 addition & 0 deletions type_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};

Expand Down

0 comments on commit 25a37fa

Please sign in to comment.