diff --git a/bitcoin/pubkey.c b/bitcoin/pubkey.c index 54d2a4c4e..046371819 100644 --- a/bitcoin/pubkey.c +++ b/bitcoin/pubkey.c @@ -65,3 +65,11 @@ bool pubkey_eq(const struct pubkey *a, const struct pubkey *b) { return structeq(&a->pubkey, &b->pubkey); } + +int pubkey_cmp(const struct pubkey *a, const struct pubkey *b) +{ + u8 keya[33], keyb[33]; + pubkey_to_der(keya, a); + pubkey_to_der(keyb, b); + return memcmp(keya, keyb, sizeof(keya)); +} diff --git a/bitcoin/pubkey.h b/bitcoin/pubkey.h index 03e6748e2..6e63f2ab4 100644 --- a/bitcoin/pubkey.h +++ b/bitcoin/pubkey.h @@ -32,4 +32,7 @@ void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key); /* Are these keys equal? */ bool pubkey_eq(const struct pubkey *a, const struct pubkey *b); + +/* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */ +int pubkey_cmp(const struct pubkey *a, const struct pubkey *b); #endif /* LIGHTNING_PUBKEY_H */