Skip to content

Commit 2a4ecbf

Browse files
committed
Merge 10a8e36 into merged_master (Elements PR ElementsProject#1428)
2 parents bb87c99 + 10a8e36 commit 2a4ecbf

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
@@ -32,7 +32,20 @@
3232
#include <script/descriptor.h> // getwalletpakinfo
3333
#include <rpc/util.h> // IsBlindDestination
3434

35+
namespace {
36+
static secp256k1_context *secp256k1_ctx;
3537

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

3750
using interfaces::FoundBlock;
3851

@@ -2000,6 +2013,7 @@ RPCHelpMan getwalletpakinfo()
20002013
{
20012014
{RPCResult::Type::STR, "bip32_counter", "next index to be used by the wallet for `sendtomainchain`"},
20022015
{RPCResult::Type::STR, "bitcoin_descriptor", "Bitcoin script descriptor loaded in the wallet for pegouts"},
2016+
{RPCResult::Type::STR, "pakentry", "PAK entry to be used at network initialization time in the form of: `pak=<bitcoin_pak>:<liquid_pak>`"},
20032017
{RPCResult::Type::STR_HEX, "liquid_pak", "pubkey corresponding to the Liquid PAK loaded in the wallet for pegouts"},
20042018
{RPCResult::Type::STR, "liquid_pak_address", "corresponding address for `liquid_pak`. Useful for `dumpprivkey` for wallet backup or transfer"},
20052019
{RPCResult::Type::ARR_FIXED, "address_lookahead", "the three next Bitcoin addresses the wallet will use for `sendtomainchain` based on the internal counter",
@@ -2032,6 +2046,28 @@ RPCHelpMan getwalletpakinfo()
20322046
const auto& desc = Parse(desc_str, provider, error);
20332047

20342048
ret.pushKV("bitcoin_descriptor", desc_str);
2049+
{
2050+
CPubKey masterpub = pwallet->offline_xpub.pubkey;
2051+
secp256k1_pubkey masterpub_secp;
2052+
int secp256k1_ret = secp256k1_ec_pubkey_parse(secp256k1_ctx, &masterpub_secp, masterpub.begin(), masterpub.size());
2053+
if (secp256k1_ret != 1) {
2054+
throw JSONRPCError(RPC_WALLET_ERROR, "bitcoin_descriptor could not be parsed.");
2055+
}
2056+
2057+
2058+
// Negate the pubkey
2059+
secp256k1_ret = secp256k1_ec_pubkey_negate(secp256k1_ctx, &masterpub_secp);
2060+
2061+
std::vector<unsigned char> negatedpubkeybytes;
2062+
negatedpubkeybytes.resize(33);
2063+
size_t len = 33;
2064+
secp256k1_ret = secp256k1_ec_pubkey_serialize(secp256k1_ctx, &negatedpubkeybytes[0], &len, &masterpub_secp, SECP256K1_EC_COMPRESSED);
2065+
CHECK_NONFATAL(secp256k1_ret == 1);
2066+
CHECK_NONFATAL(len == 33);
2067+
CHECK_NONFATAL(negatedpubkeybytes.size() == 33);
2068+
2069+
ret.pushKV("pakentry", "pak=" + HexStr(negatedpubkeybytes) + ":" + HexStr(pwallet->online_key));
2070+
}
20352071
ret.pushKV("liquid_pak", HexStr(pwallet->online_key));
20362072
ret.pushKV("liquid_pak_address", EncodeDestination(PKHash(pwallet->online_key)));
20372073

test/functional/feature_pak.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def run_test(self):
5151
init_results += [ self.nodes[i].initpegoutwallet(xpub) ]
5252
info_results += [ self.nodes[i].getwalletpakinfo() ]
5353
assert_equal(init_results[i]["address_lookahead"], info_results[i]["address_lookahead"])
54+
assert_equal(init_results[i]["pakentry"], info_results[i]["pakentry"])
5455
assert_equal(init_results[i]["liquid_pak"], info_results[i]["liquid_pak"])
5556
assert_equal(init_results[i]["liquid_pak_address"], info_results[i]["liquid_pak_address"])
5657
assert_equal(info_results[i]["bitcoin_descriptor"], xpub_desc)

0 commit comments

Comments
 (0)