2021-12-23 20:57:33 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include <bitcoin/tx.h>
|
|
|
|
#include <common/psbt_keypath.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <wally_bip32.h>
|
|
|
|
|
2023-07-10 21:59:41 +02:00
|
|
|
void psbt_output_set_keypath(u32 index, const struct ext_key *ext, bool is_taproot, struct wally_psbt_output *output) {
|
2021-12-23 20:57:33 +01:00
|
|
|
u8 fingerprint[BIP32_KEY_FINGERPRINT_LEN];
|
|
|
|
if (bip32_key_get_fingerprint(
|
|
|
|
(struct ext_key *) ext, fingerprint, sizeof(fingerprint)) != WALLY_OK)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
u32 path[1];
|
|
|
|
path[0] = index;
|
|
|
|
|
2023-07-10 21:59:41 +02:00
|
|
|
if (is_taproot) {
|
|
|
|
if (wally_psbt_output_taproot_keypath_add(output,
|
|
|
|
ext->pub_key + 1, sizeof(ext->pub_key) - 1,
|
|
|
|
NULL, 0,
|
|
|
|
fingerprint, sizeof(fingerprint),
|
|
|
|
path, 1) != WALLY_OK)
|
|
|
|
abort();
|
|
|
|
} else {
|
|
|
|
if (wally_psbt_output_keypath_add(output,
|
|
|
|
ext->pub_key, sizeof(ext->pub_key),
|
|
|
|
fingerprint, sizeof(fingerprint),
|
|
|
|
path, 1) != WALLY_OK)
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2021-12-23 20:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void psbt_add_keypath_to_last_output(struct bitcoin_tx *tx,
|
|
|
|
u32 key_index,
|
2023-07-10 21:59:41 +02:00
|
|
|
const struct ext_key *ext,
|
|
|
|
bool is_taproot) {
|
2021-12-23 20:57:33 +01:00
|
|
|
size_t outndx = tx->psbt->num_outputs - 1;
|
|
|
|
|
|
|
|
tal_wally_start();
|
2023-07-10 21:59:41 +02:00
|
|
|
psbt_output_set_keypath(key_index, ext, is_taproot, &tx->psbt->outputs[outndx]);
|
2021-12-23 20:57:33 +01:00
|
|
|
tal_wally_end(tx->psbt);
|
|
|
|
}
|