1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
From ccddf3be96fd08d1eccbb58a7e8f8c98d07b07f2 Mon Sep 17 00:00:00 2001
From: Konstantin Ullrich <konstantinullrich12@gmail.com>
Date: Wed, 11 Oct 2023 16:47:59 +0200
Subject: [PATCH 11/14] Add recoverDeterministicWalletFromSpendKey
This function is used by Cake Wallet to enable polyseed (dart implementation)
support.
Sourced from the following commit:
https://github.com/cake-tech/monero/commit/cb6fb5ab218878702ed151c0e3d5d68eb2732788
Co-authored-by: Godwin Asuquo <godilite@gmail.com>
---
src/wallet/api/wallet.cpp | 29 +++++++++++++++++++++++++++++
src/wallet/api/wallet.h | 4 ++++
src/wallet/api/wallet2_api.h | 19 +++++++++++++++++++
src/wallet/api/wallet_manager.cpp | 16 ++++++++++++++++
src/wallet/api/wallet_manager.h | 7 +++++++
5 files changed, 75 insertions(+)
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 6bb3a21..5734aff 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -824,6 +824,35 @@ bool WalletImpl::recover(const std::string &path, const std::string &password, c
return status() == Status_Ok;
}
+bool WalletImpl::recoverDeterministicWalletFromSpendKey(const std::string &path, const std::string &password, const std::string &language, const std::string &spendkey_string)
+{
+ clearStatus();
+ m_errorString.clear();
+
+ m_recoveringFromSeed = true;
+ m_recoveringFromDevice = false;
+
+ // parse spend key
+ crypto::secret_key spendkey;
+ if (!spendkey_string.empty()) {
+ cryptonote::blobdata spendkey_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(spendkey_string, spendkey_data) || spendkey_data.size() != sizeof(crypto::secret_key))
+ {
+ setStatusError(tr("failed to parse secret spend key"));
+ return false;
+ }
+ spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
+ }
+
+ try {
+ m_wallet->generate(path, password, spendkey, true, false);
+ setSeedLanguage(language);
+ } catch (const std::exception &e) {
+ setStatusCritical(e.what());
+ }
+ return status() == Status_Ok;
+}
+
bool WalletImpl::close(bool store)
{
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index a82f270..9e1fbb4 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -77,6 +77,10 @@ public:
const std::string &address_string,
const std::string &viewkey_string,
const std::string &spendkey_string = "");
+ bool recoverDeterministicWalletFromSpendKey(const std::string &path,
+ const std::string &password,
+ const std::string &language,
+ const std::string &spendkey_string);
bool recoverFromDevice(const std::string &path,
const std::string &password,
const std::string &device_name);
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index f421fdc..c8d6bb1 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -1323,6 +1323,25 @@ struct WalletManager
return createWalletFromKeys(path, password, language, testnet ? TESTNET : MAINNET, restoreHeight, addressString, viewKeyString, spendKeyString);
}
+ /*!
+ * \brief recover deterministic wallet from spend key.
+ * \param path Name of wallet file to be created
+ * \param password Password of wallet file
+ * \param language language
+ * \param nettype Network type
+ * \param restoreHeight restore from start height
+ * \param spendKeyString spend key
+ * \param kdf_rounds Number of rounds for key derivation function
+ * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
+ */
+ virtual Wallet * createDeterministicWalletFromSpendKey(const std::string &path,
+ const std::string &password,
+ const std::string &language,
+ NetworkType nettype,
+ uint64_t restoreHeight,
+ const std::string &spendKeyString,
+ uint64_t kdf_rounds = 1) = 0;
+
/*!
* \deprecated this method creates a wallet WITHOUT a passphrase, use createWalletFromKeys(..., password, ...) instead
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index da2056d..c200f52 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -127,6 +127,22 @@ Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path,
return wallet;
}
+Wallet *WalletManagerImpl::createDeterministicWalletFromSpendKey(const std::string &path,
+ const std::string &password,
+ const std::string &language,
+ NetworkType nettype,
+ uint64_t restoreHeight,
+ const std::string &spendkey_string,
+ uint64_t kdf_rounds)
+{
+ WalletImpl * wallet = new WalletImpl(nettype, kdf_rounds);
+ if(restoreHeight > 0){
+ wallet->setRefreshFromBlockHeight(restoreHeight);
+ }
+ wallet->recoverDeterministicWalletFromSpendKey(path, password, language, spendkey_string);
+ return wallet;
+}
+
Wallet *WalletManagerImpl::createWalletFromDevice(const std::string &path,
const std::string &password,
NetworkType nettype,
diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h
index 28fcd36..be3ff81 100644
--- a/src/wallet/api/wallet_manager.h
+++ b/src/wallet/api/wallet_manager.h
@@ -67,6 +67,13 @@ public:
const std::string &addressString,
const std::string &viewKeyString,
const std::string &spendKeyString = "") override;
+ virtual Wallet * createDeterministicWalletFromSpendKey(const std::string &path,
+ const std::string &password,
+ const std::string &language,
+ NetworkType nettype,
+ uint64_t restoreHeight,
+ const std::string &spendkey_string,
+ uint64_t kdf_rounds) override;
virtual Wallet * createWalletFromDevice(const std::string &path,
const std::string &password,
NetworkType nettype,
--
2.39.5 (Apple Git-154)
|