Skip to content

Commit

Permalink
Fix wrong documentation for get_extended_pubkey; renamed to get_exten…
Browse files Browse the repository at this point in the history
…ded_pubkey_from_client
  • Loading branch information
bigspider committed Nov 21, 2024
1 parent 745743e commit 850ce3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
12 changes: 9 additions & 3 deletions src/handler/lib/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ execute_processor(policy_parser_state_t *state, policy_parser_processor_t proc,

// convenience function, split from get_derived_pubkey only to improve stack usage
// returns -1 on error, 0 if the returned key info has no wildcard (**), 1 if it has the wildcard
__attribute__((noinline, warn_unused_result)) int get_extended_pubkey(
__attribute__((noinline, warn_unused_result)) int get_extended_pubkey_from_client(
dispatcher_context_t *dispatcher_context,
const wallet_derivation_info_t *wdi,
int key_index,
Expand Down Expand Up @@ -464,7 +464,10 @@ __attribute__((warn_unused_result)) static int get_derived_pubkey(
serialized_extended_pubkey_t ext_pubkey;

if (key_expr->type == KEY_EXPRESSION_NORMAL) {
if (0 > get_extended_pubkey(dispatcher_context, wdi, key_expr->k.key_index, &ext_pubkey)) {
if (0 > get_extended_pubkey_from_client(dispatcher_context,
wdi,
key_expr->k.key_index,
&ext_pubkey)) {
return -1;
}
} else if (key_expr->type == KEY_EXPRESSION_MUSIG) {
Expand All @@ -473,7 +476,10 @@ __attribute__((warn_unused_result)) static int get_derived_pubkey(
plain_pk_t keys[MAX_PUBKEYS_PER_MUSIG];
for (int i = 0; i < musig_info->n; i++) {
// we use ext_pubkey as a temporary variable; will overwrite later
if (0 > get_extended_pubkey(dispatcher_context, wdi, key_indexes[i], &ext_pubkey)) {
if (0 > get_extended_pubkey_from_client(dispatcher_context,
wdi,
key_indexes[i],
&ext_pubkey)) {
return -1;
}
memcpy(keys[i], ext_pubkey.compressed_pubkey, sizeof(ext_pubkey.compressed_pubkey));
Expand Down
11 changes: 3 additions & 8 deletions src/handler/lib/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,18 @@ typedef struct {
} wallet_derivation_info_t;

/**
* Computes the a derived compressed pubkey for one of the key of the wallet policy,
* for a given change/address_index combination.
*
* This function computes the extended public key (xpub) based on the provided
* BIP32 derivation path. It supports both standard BIP32 derivation and
* the derivation of Musig (multi-signature) keys.
* Requests and parses the serialized extended public key from the client.
*
* @param[in] dispatcher_context Pointer to the dispatcher content
* @param[in] wdi Pointer to a `wallet_derivation_info_t` struct with the details of the
* necessary details of the wallet policy, and the desired change/address_index pair.
* necessary details of the wallet policy. The change/addr_index pairs are not
* @param[in] key_index Index of the pubkey in the vector of keys of the wallet policy.
* @param[out] out Pointer to a `serialized_extended_pubkey_t` that will contain the requested
* extended pubkey.
*
* @return -1 on error, 0 if the returned key info has no wildcard (**), 1 if it has the wildcard.
*/
__attribute__((warn_unused_result)) int get_extended_pubkey(
__attribute__((warn_unused_result)) int get_extended_pubkey_from_client(
dispatcher_context_t *dispatcher_context,
const wallet_derivation_info_t *wdi,
int key_index,
Expand Down
2 changes: 1 addition & 1 deletion src/handler/sign_psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ static bool compute_musig_per_input_info(dispatcher_context_t *dc,
LEDGER_ASSERT(musig_info->n <= MAX_PUBKEYS_PER_MUSIG, "Too many keys in musig key expression");
for (int i = 0; i < musig_info->n; i++) {
// we use ext_pubkey as a temporary variable; will overwrite later
if (0 > get_extended_pubkey(dc, &wdi, key_indexes[i], &ext_pubkey)) {
if (0 > get_extended_pubkey_from_client(dc, &wdi, key_indexes[i], &ext_pubkey)) {
return -1;
}
memcpy(out->keys[i], ext_pubkey.compressed_pubkey, sizeof(ext_pubkey.compressed_pubkey));
Expand Down

0 comments on commit 850ce3f

Please sign in to comment.