add missing functionality from for cake's polyseed implementation

This commit is contained in:
Czarek Nakamoto
2024-04-22 12:49:17 +02:00
parent 90658235f6
commit 7e49b4ad69
14 changed files with 316 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
From bf347a3c80f0e0647176752867a54ae9ecedb580 Mon Sep 17 00:00:00 2001
From b9fac308d903e9dd79b95d6db73c37807e1219b7 Mon Sep 17 00:00:00 2001
From: tobtoht <tob@featherwallet.org>
Date: Tue, 12 Mar 2024 09:42:37 +0100
Subject: [PATCH 1/8] polyseed
Subject: [PATCH 01/10] polyseed
Co-authored-by: Czarek Nakamoto <cyjan@mrcyjanek.net>
---
@@ -150,7 +150,7 @@ index 5b7f69a56..1b9761d70 100644
\ No newline at end of file
diff --git a/external/polyseed b/external/polyseed
new file mode 160000
index 000000000..b7c35bb3c
index 000000000..9d4f1a032
--- /dev/null
+++ b/external/polyseed
@@ -0,0 +1 @@
@@ -468,7 +468,7 @@ index 000000000..f6253b9d7
\ No newline at end of file
diff --git a/src/polyseed/polyseed.cpp b/src/polyseed/polyseed.cpp
new file mode 100644
index 000000000..b26f37574
index 000000000..0a8852777
--- /dev/null
+++ b/src/polyseed/polyseed.cpp
@@ -0,0 +1,182 @@

View File

@@ -1,7 +1,7 @@
From 0cc1775c6a41a1768ebbe6155496f01289f903d4 Mon Sep 17 00:00:00 2001
From f1cf1d2378a5bb6313eef9a58325b03cb4ac0f85 Mon Sep 17 00:00:00 2001
From: j-berman <justinberman@protonmail.com>
Date: Thu, 13 Oct 2022 18:33:33 -0700
Subject: [PATCH 2/8] wallet: background sync with just the view key
Subject: [PATCH 02/10] wallet: background sync with just the view key
- When background syncing, the wallet wipes the spend key
from memory and processes all new transactions. The wallet saves

View File

@@ -1,7 +1,7 @@
From c325add45cf950a42fc4cc16f99bb7385c53a634 Mon Sep 17 00:00:00 2001
From c4499815188a0b8103092da07260074359a1874e Mon Sep 17 00:00:00 2001
From: tobtoht <tob@featherwallet.org>
Date: Tue, 12 Mar 2024 10:09:50 +0100
Subject: [PATCH 3/8] airgap
Subject: [PATCH 03/10] airgap
---
src/wallet/api/wallet.cpp | 23 ++++++++++++++++++++++

View File

@@ -1,7 +1,7 @@
From fb9cd4ff500a56a1f29f323fe05de4633dd560de Mon Sep 17 00:00:00 2001
From 8e069a8b7c15794b843471487c12c2c753d3afe2 Mon Sep 17 00:00:00 2001
From: tobtoht <tob@featherwallet.org>
Date: Tue, 12 Mar 2024 11:07:57 +0100
Subject: [PATCH 4/8] coin control
Subject: [PATCH 04/10] coin control
---
src/wallet/api/CMakeLists.txt | 8 +-

View File

@@ -1,7 +1,7 @@
From 6bd41f6e334fe979e2a5e874e404657ff0ef6c4f Mon Sep 17 00:00:00 2001
From a24797410dcda06617ff2a81de3129d38b69f2a2 Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Tue, 12 Mar 2024 17:59:13 +0100
Subject: [PATCH 5/8] fix build issues
Subject: [PATCH 05/10] fix build issues
---
contrib/depends/hosts/linux.mk | 8 +++----

View File

@@ -1,7 +1,7 @@
From c8dfb421082c895c45c6e4fd1437fee4b554b612 Mon Sep 17 00:00:00 2001
From bc3d91b07d77893983bbed0b165ce41e034579a7 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Thu, 28 Mar 2024 02:03:08 +0100
Subject: [PATCH 6/8] macos build fix
Subject: [PATCH 06/10] macos build fix
---
contrib/depends/hosts/darwin.mk | 2 +

View File

@@ -1,7 +1,7 @@
From d0d86d333ea4788cc27c4c87c5ec2ec3bc1668b7 Mon Sep 17 00:00:00 2001
From 14b4c210a11e0c333087026775cf22fcccf46a40 Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Tue, 2 Apr 2024 01:13:12 +0200
Subject: [PATCH 7/8] fix `make debug-test` target
Subject: [PATCH 07/10] fix `make debug-test` target
---
src/simplewallet/simplewallet.cpp | 4 ++--

View File

@@ -1,7 +1,7 @@
From b154719d3fe7ae407de91f5c5a245998efd05997 Mon Sep 17 00:00:00 2001
From d3a704bfb62bede87d5da0261585f62f19f858c1 Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Tue, 2 Apr 2024 16:51:56 +0200
Subject: [PATCH 8/8] fix missing ___clear_cache when targetting iOS
Subject: [PATCH 08/10] fix missing ___clear_cache when targetting iOS
---
.gitmodules | 2 +-

View File

@@ -0,0 +1,153 @@
From 8db1b159445a8aaca702a8bacb9476abe3aebcf1 Mon Sep 17 00:00:00 2001
From: Konstantin Ullrich <konstantinullrich12@gmail.com>
Date: Wed, 11 Oct 2023 16:47:59 +0200
Subject: [PATCH 09/10] 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 2fe0d1d29..2411d948c 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -820,6 +820,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 4a16ca028..d0f443abc 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 8a5c4135e..a585c8212 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -1302,6 +1302,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 c79fe25d6..f88bd9e64 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 28fcd36c9..be3ff8184 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.44.0

View File

@@ -0,0 +1,68 @@
From db90a0218d581276fcede6f188cc951499095a2f Mon Sep 17 00:00:00 2001
From: M <m@cakewallet.com>
Date: Fri, 21 Apr 2023 15:43:47 -0400
Subject: [PATCH 10/10] Add hex encoding and tx key getter for
PendingTransction in wallet api.
---
src/wallet/api/pending_transaction.cpp | 16 ++++++++++++++++
src/wallet/api/pending_transaction.h | 2 ++
src/wallet/api/wallet2_api.h | 2 ++
3 files changed, 20 insertions(+)
diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp
index 70a702796..be20b478c 100644
--- a/src/wallet/api/pending_transaction.cpp
+++ b/src/wallet/api/pending_transaction.cpp
@@ -78,6 +78,22 @@ std::vector<std::string> PendingTransactionImpl::txid() const
return txid;
}
+std::vector<std::string> PendingTransactionImpl::hex() const
+{
+ std::vector<std::string> hexs;
+ for (const auto &pt: m_pending_tx)
+ hexs.push_back(epee::string_tools::buff_to_hex_nodelimer(cryptonote::tx_to_blob(pt.tx)));
+ return hexs;
+}
+
+std::vector<std::string> PendingTransactionImpl::txKey() const
+{
+ std::vector<std::string> keys;
+ for (const auto& pt: m_pending_tx)
+ keys.push_back(epee::string_tools::pod_to_hex(pt.tx_key));
+ return keys;
+}
+
bool PendingTransactionImpl::commit(const std::string &filename, bool overwrite)
{
diff --git a/src/wallet/api/pending_transaction.h b/src/wallet/api/pending_transaction.h
index 0a9779c07..2fbaa83d9 100644
--- a/src/wallet/api/pending_transaction.h
+++ b/src/wallet/api/pending_transaction.h
@@ -58,6 +58,8 @@ public:
std::string multisigSignData() override;
void signMultisigTx() override;
std::vector<std::string> signersKeys() const override;
+ std::vector<std::string> hex() const override;
+ std::vector<std::string> txKey() const override;
private:
friend class WalletImpl;
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index a585c8212..1c3a11c39 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -126,6 +126,8 @@ struct PendingTransaction
* @return vector of base58-encoded signers' public keys
*/
virtual std::vector<std::string> signersKeys() const = 0;
+ virtual std::vector<std::string> hex() const = 0;
+ virtual std::vector<std::string> txKey() const = 0;
};
/**
--
2.44.0