Skip to content

Commit 041e2b8

Browse files
committed
keystore: use xpubs instead of xprvs where possible
Functionally the same, but for clarity it is better to use xpubs where only pubkeys are involved. This will also make it easier to add xpub caching to increase performance if needed (for example, xpubs are derived anew for each BTC transaction input and change). The extra keystore_is_locked check is not needed getting a xprv/xpub already does that check.
1 parent 0608d7d commit 041e2b8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/keystore.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,11 @@ bool keystore_secp256k1_pubkey_hash160(
574574
size_t keypath_len,
575575
uint8_t* hash160_out)
576576
{
577-
if (keystore_is_locked()) {
578-
return false;
579-
}
580-
struct ext_key xprv __attribute__((__cleanup__(keystore_zero_xkey))) = {0};
581-
if (!_get_xprv_twice(keypath, keypath_len, &xprv)) {
577+
struct ext_key xpub __attribute__((__cleanup__(keystore_zero_xkey))) = {0};
578+
if (!keystore_get_xpub(keypath, keypath_len, &xpub)) {
582579
return false;
583580
}
584-
memcpy(hash160_out, xprv.hash160, sizeof(xprv.hash160));
581+
memcpy(hash160_out, xpub.hash160, sizeof(xpub.hash160));
585582
return true;
586583
}
587584

@@ -590,14 +587,11 @@ bool keystore_secp256k1_pubkey_uncompressed(
590587
size_t keypath_len,
591588
uint8_t* pubkey_out)
592589
{
593-
if (keystore_is_locked()) {
594-
return false;
595-
}
596-
struct ext_key xprv __attribute__((__cleanup__(keystore_zero_xkey))) = {0};
597-
if (!_get_xprv_twice(keypath, keypath_len, &xprv)) {
590+
struct ext_key xpub __attribute__((__cleanup__(keystore_zero_xkey))) = {0};
591+
if (!keystore_get_xpub(keypath, keypath_len, &xpub)) {
598592
return false;
599593
}
600-
return _compressed_to_uncompressed(xprv.pub_key, pubkey_out);
594+
return _compressed_to_uncompressed(xpub.pub_key, pubkey_out);
601595
}
602596

603597
bool keystore_secp256k1_nonce_commit(

0 commit comments

Comments
 (0)