From b7eab542df8e5be2cdc2180dba2dfedc66f07a14 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Thu, 25 Apr 2024 10:07:36 +0200 Subject: wownero-seed support --- .../src/main/cpp/wallet2_api_c.cpp | 40 +++++++++++++++++++++- .../src/main/cpp/wallet2_api_c.h | 4 +++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'wownero_libwallet2_api_c/src') diff --git a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index 097c321..fbc2332 100644 --- a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -5,7 +5,7 @@ #include #include #include "../../../../wownero/src/wallet/api/wallet2_api.h" - +#include "../../../../external/wownero-seed/include/wownero_seed/wownero_seed.hpp" #ifdef __cplusplus extern "C" @@ -1862,6 +1862,44 @@ uint64_t WOWNERO_cw_WalletListener_height(void* cw_walletListener_ptr) { return listener->cw_isNeedToRefresh(); }; +// 14-word polyseed compat +// wow was really quick to implement polyseed support (aka wownero-seed), which +// results in this maintenance burden we have to go through. +// +// Code is borrowed from +// https://github.com/cypherstack/flutter_libmonero/blob/2c684cedba6c3d9353c7ea748cadb5a246008027/cw_wownero/ios/Classes/wownero_api.cpp#L240 +// this code slightly goes against the way of being simple +void* WOWNERO_deprecated_restore14WordSeed(char *path, char *password, char *language, int32_t networkType, char *error) { + Monero::NetworkType _networkType = static_cast(networkType); + Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager(); + + // 14 word seeds /* + time_t time = std::time(nullptr); + wownero_seed wow_seed(time, "wownero"); + + std::stringstream seed_stream; + seed_stream << wow_seed; + std::string seed = seed_stream.str(); + + std::stringstream key_stream; + key_stream << wow_seed.key(); + std::string spendKey = key_stream.str(); + + uint64_t restoreHeight = wow_seed.blockheight(); + + Monero::Wallet *wallet = walletManager->createDeterministicWalletFromSpendKey( + std::string(path), + std::string(password), + std::string(language), + static_cast(_networkType), + (uint64_t)restoreHeight, + spendKey, + 1); + wallet->setCacheAttribute("cake.seed", seed); + return reinterpret_cast(wallet); +} + + #ifdef __cplusplus } #endif diff --git a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h index d95ec69..1482910 100644 --- a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h +++ b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -1004,6 +1004,10 @@ extern ADDAPI bool WOWNERO_cw_WalletListener_isNewTransactionExist(void* cw_wall extern ADDAPI void WOWNERO_cw_WalletListener_resetIsNewTransactionExist(void* cw_walletListener_ptr); extern ADDAPI uint64_t WOWNERO_cw_WalletListener_height(void* cw_walletListener_ptr); +// legacy + +extern ADDAPI void* WOWNERO_deprecated_restore14WordSeed(char *path, char *password, char *language, int32_t networkType, char *error); + #ifdef __cplusplus } #endif \ No newline at end of file -- cgit v1.2.3