Skip to content

Commit 10a8e36

Browse files
authored
Merge pull request #1428 from psgreco/master-showpak
wallet: Show full pak entry in getwalletpakinfo
2 parents 7ed597f + c878b25 commit 10a8e36

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,20 @@
3333
#include <script/descriptor.h> // getwalletpakinfo
3434
#include <rpc/util.h> // IsBlindDestination
3535

36+
namespace {
37+
static secp256k1_context *secp256k1_ctx;
3638

39+
class CSecp256k1Init {
40+
public:
41+
CSecp256k1Init() {
42+
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
43+
}
44+
~CSecp256k1Init() {
45+
secp256k1_context_destroy(secp256k1_ctx);
46+
}
47+
};
48+
static CSecp256k1Init instance_of_csecp256k1;
49+
}
3750

3851
using interfaces::FoundBlock;
3952

@@ -1955,6 +1968,7 @@ RPCHelpMan getwalletpakinfo()
19551968
{
19561969
{RPCResult::Type::STR, "bip32_counter", "next index to be used by the wallet for `sendtomainchain`"},
19571970
{RPCResult::Type::STR, "bitcoin_descriptor", "Bitcoin script descriptor loaded in the wallet for pegouts"},
1971+
{RPCResult::Type::STR, "pakentry", "PAK entry to be used at network initialization time in the form of: `pak=<bitcoin_pak>:<liquid_pak>`"},
19581972
{RPCResult::Type::STR_HEX, "liquid_pak", "pubkey corresponding to the Liquid PAK loaded in the wallet for pegouts"},
19591973
{RPCResult::Type::STR, "liquid_pak_address", "corresponding address for `liquid_pak`. Useful for `dumpprivkey` for wallet backup or transfer"},
19601974
{RPCResult::Type::ARR_FIXED, "address_lookahead", "the three next Bitcoin addresses the wallet will use for `sendtomainchain` based on the internal counter",
@@ -1987,6 +2001,28 @@ RPCHelpMan getwalletpakinfo()
19872001
const auto& desc = Parse(desc_str, provider, error);
19882002

19892003
ret.pushKV("bitcoin_descriptor", desc_str);
2004+
{
2005+
CPubKey masterpub = pwallet->offline_xpub.pubkey;
2006+
secp256k1_pubkey masterpub_secp;
2007+
int secp256k1_ret = secp256k1_ec_pubkey_parse(secp256k1_ctx, &masterpub_secp, masterpub.begin(), masterpub.size());
2008+
if (secp256k1_ret != 1) {
2009+
throw JSONRPCError(RPC_WALLET_ERROR, "bitcoin_descriptor could not be parsed.");
2010+
}
2011+
2012+
2013+
// Negate the pubkey
2014+
secp256k1_ret = secp256k1_ec_pubkey_negate(secp256k1_ctx, &masterpub_secp);
2015+
2016+
std::vector<unsigned char> negatedpubkeybytes;
2017+
negatedpubkeybytes.resize(33);
2018+
size_t len = 33;
2019+
secp256k1_ret = secp256k1_ec_pubkey_serialize(secp256k1_ctx, &negatedpubkeybytes[0], &len, &masterpub_secp, SECP256K1_EC_COMPRESSED);
2020+
CHECK_NONFATAL(secp256k1_ret == 1);
2021+
CHECK_NONFATAL(len == 33);
2022+
CHECK_NONFATAL(negatedpubkeybytes.size() == 33);
2023+
2024+
ret.pushKV("pakentry", "pak=" + HexStr(negatedpubkeybytes) + ":" + HexStr(pwallet->online_key));
2025+
}
19902026
ret.pushKV("liquid_pak", HexStr(pwallet->online_key));
19912027
ret.pushKV("liquid_pak_address", EncodeDestination(PKHash(pwallet->online_key)));
19922028

test/functional/feature_pak.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def run_test(self):
4747
init_results += [ self.nodes[i].initpegoutwallet(xpub) ]
4848
info_results += [ self.nodes[i].getwalletpakinfo() ]
4949
assert_equal(init_results[i]["address_lookahead"], info_results[i]["address_lookahead"])
50+
assert_equal(init_results[i]["pakentry"], info_results[i]["pakentry"])
5051
assert_equal(init_results[i]["liquid_pak"], info_results[i]["liquid_pak"])
5152
assert_equal(init_results[i]["liquid_pak_address"], info_results[i]["liquid_pak_address"])
5253
assert_equal(info_results[i]["bitcoin_descriptor"], xpub_desc)

0 commit comments

Comments
 (0)