|
33 | 33 | #include <script/descriptor.h> // getwalletpakinfo
|
34 | 34 | #include <rpc/util.h> // IsBlindDestination
|
35 | 35 |
|
| 36 | +namespace { |
| 37 | + static secp256k1_context *secp256k1_ctx; |
36 | 38 |
|
| 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 | +} |
37 | 50 |
|
38 | 51 | using interfaces::FoundBlock;
|
39 | 52 |
|
@@ -1955,6 +1968,7 @@ RPCHelpMan getwalletpakinfo()
|
1955 | 1968 | {
|
1956 | 1969 | {RPCResult::Type::STR, "bip32_counter", "next index to be used by the wallet for `sendtomainchain`"},
|
1957 | 1970 | {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>`"}, |
1958 | 1972 | {RPCResult::Type::STR_HEX, "liquid_pak", "pubkey corresponding to the Liquid PAK loaded in the wallet for pegouts"},
|
1959 | 1973 | {RPCResult::Type::STR, "liquid_pak_address", "corresponding address for `liquid_pak`. Useful for `dumpprivkey` for wallet backup or transfer"},
|
1960 | 1974 | {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()
|
1987 | 2001 | const auto& desc = Parse(desc_str, provider, error);
|
1988 | 2002 |
|
1989 | 2003 | 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 | + } |
1990 | 2026 | ret.pushKV("liquid_pak", HexStr(pwallet->online_key));
|
1991 | 2027 | ret.pushKV("liquid_pak_address", EncodeDestination(PKHash(pwallet->online_key)));
|
1992 | 2028 |
|
|
0 commit comments