mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
bitcoin/pubkey: add pubkey_from_secret.
Really, we should have a 'struct point' since we don't use all points as pubkeys. But this is the minimal fix to avoid type cast nastiness. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
9dd0415a15
commit
289e39a0a3
@@ -28,14 +28,18 @@ void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key)
|
|||||||
assert(outlen == PUBKEY_DER_LEN);
|
assert(outlen == PUBKEY_DER_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pubkey from privkey */
|
bool pubkey_from_secret(const struct secret *secret, struct pubkey *key)
|
||||||
|
{
|
||||||
|
if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
|
||||||
|
&key->pubkey, secret->data))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool pubkey_from_privkey(const struct privkey *privkey,
|
bool pubkey_from_privkey(const struct privkey *privkey,
|
||||||
struct pubkey *key)
|
struct pubkey *key)
|
||||||
{
|
{
|
||||||
if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
|
return pubkey_from_secret(&privkey->secret, key);
|
||||||
&key->pubkey, privkey->secret.data))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
|
bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <secp256k1.h>
|
#include <secp256k1.h>
|
||||||
|
|
||||||
struct privkey;
|
struct privkey;
|
||||||
|
struct secret;
|
||||||
|
|
||||||
#define PUBKEY_DER_LEN 33
|
#define PUBKEY_DER_LEN 33
|
||||||
|
|
||||||
@@ -28,6 +29,9 @@ char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key);
|
|||||||
/* Convenience wrapper for a raw secp256k1_pubkey */
|
/* Convenience wrapper for a raw secp256k1_pubkey */
|
||||||
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);
|
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);
|
||||||
|
|
||||||
|
/* Point from secret */
|
||||||
|
bool pubkey_from_secret(const struct secret *secret, struct pubkey *key);
|
||||||
|
|
||||||
/* Pubkey from privkey */
|
/* Pubkey from privkey */
|
||||||
bool pubkey_from_privkey(const struct privkey *privkey,
|
bool pubkey_from_privkey(const struct privkey *privkey,
|
||||||
struct pubkey *key);
|
struct pubkey *key);
|
||||||
|
|||||||
@@ -56,14 +56,6 @@ static struct secret secret_from_hex(const char *hex)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pubkey_from_secret(const struct secret *secret,
|
|
||||||
struct pubkey *key)
|
|
||||||
{
|
|
||||||
return secp256k1_ec_pubkey_create(secp256k1_ctx,
|
|
||||||
&key->pubkey,
|
|
||||||
secret->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tx_must_be_eq(const struct bitcoin_tx *a,
|
static void tx_must_be_eq(const struct bitcoin_tx *a,
|
||||||
const struct bitcoin_tx *b)
|
const struct bitcoin_tx *b)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user