Skip to content

Commit

Permalink
monero_wallet_light implementation (#3)
Browse files Browse the repository at this point in the history
* Monero light wallet

* Monero light wallet

* Admin methods definition

* Admin methods implementation

* Monero Wallet Light implementation progress

* MoneroWalletLight implementation

* Deprecate monero_wallet_light_model

* Remove default parameters from implementation

* Fix compile errors #1

* Fix compile errors #2

* Fix compile errors #3

* Fix compile errors #4

* Fix compile errors - 5

* Fix compile errors - 6

* Fix compile errors woodser#7

* Fix compile errors - 8

* Fix compile errors - 9

* Fix compile errors - 10

* Remove monero_daemon_model.h

* Remove pragma once

* Restore pragma once, remove monero_utils.h from header

* uint64_t_cast implementation

* MoneroWalletLight implementation

* MoneroWalletLight implementation

* MoneroWalletLight implementation

* monero_utils::generate_key_image implementation

* Monero Wallet Light implementation

* Monero wallet light fix errors

* Monero wallet light fix errors

* Wallet monero light fix errors

* Monero light transaction copy implementation

* Fix errors

* Fix errors

* Fix erros

* Fix errors

* Fix errors

* Monero wallet light implementation

* Fix errors

* Fix static utilities

* Update CMakeLists

* get_transfers implementation

* Monero wallet light implementation

* Monero wallet light create_txs implementation

* Fix errors

* Fix errors

* Fix errors

* Fix errors

* Temporary fix

* Methods implementation

* start_syncing implementation

* Fix errors

* More info on exception

* Test

* Fix

* Reduce timeout

* Enable wallet light tests

* Fix

* Fix

* MINFO

* MINFO

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix tests

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Export outputs test

* More outputs tests

* More tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix import kye images

* Sync wallet2 too

* Fix

* Fix

* Fix

* Fix

* Fix

* Check tests

* Fix

* Fix

* Fix

* Fix

* Temp full tests

* Fix port

* Fix

* Fix

* Fix

* Custom implementation export_outputs

* Fix

* Fix

* Fix key_image_is_ours

* Fix

* Fix

* Test

* Fix

* Fix

* Fix

* Fix

* Fix

* fix

* Fix

* Fix

* Fix

* Fix

* Temp full test

* Fix

* Renable light tests

* Renable tests

* Fix tests

* change wallet test

* Relay test

* submit_txs implementation

* Enable full test

* Enable full tets

* Disable full tests

* Fix import key images

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Change  monero-project module

* Enable private spend key

* Revert "Enable private spend key"

This reverts commit 21d337e.

* Enable private spend key

* Change update submodules

* Fix

* Fix

* Fix test

* Wallet light implementation
  • Loading branch information
everoddandeven authored Mar 21, 2024
1 parent 9d09227 commit 44b31c6
Show file tree
Hide file tree
Showing 10 changed files with 4,969 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "external/monero-project"]
path = external/monero-project
url = https://github.com/woodser/monero
url = https://github.com/everoddandeven/monero
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/external/monero-project/external/boost/**",
"/usr/include/x86_64-linux-gnu/c++/11"
],
"defines": [],
"compilerPath": "/usr/bin/g++-11",
"cStandard": "c17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
83 changes: 83 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"files.associations": {
"*.ipp": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cfenv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"source_location": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}
55 changes: 55 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ project(MoneroCppLibrary)

set(BUILD_LIBRARY ON)
set(BUILD_SAMPLE OFF)
set(BUILD_LIGHT_TESTS ON)
set(BUILD_SCRATCHPAD OFF)
set(BUILD_TESTS OFF)

Expand Down Expand Up @@ -295,6 +296,7 @@ set(
src/wallet/monero_wallet_model.cpp
src/wallet/monero_wallet_keys.cpp
src/wallet/monero_wallet_full.cpp
src/wallet/monero_wallet_light.cpp
)

if (BUILD_LIBRARY)
Expand Down Expand Up @@ -349,6 +351,7 @@ endif()
src/utils/monero_utils.h
DESTINATION include/utils)
INSTALL(FILES src/wallet/monero_wallet_full.h
src/wallet/monero_wallet_light.h
src/wallet/monero_wallet.h
src/wallet/monero_wallet_keys.h
src/wallet/monero_wallet_model.h
Expand Down Expand Up @@ -409,6 +412,58 @@ if (BUILD_SAMPLE)
endif()
endif()


########################
# Build C++ sample Code
########################

if (BUILD_LIGHT_TESTS)
set(LIGHT_TEST_SRC_FILES test/monero_light_tests.cpp)

add_executable(monero_light_tests ${LIBRARY_SRC_FILES} ${LIGHT_TEST_SRC_FILES})

target_link_libraries(monero_light_tests
wallet
rpc_base
net
lmdb
easylogging
cryptonote_core
cryptonote_protocol
cryptonote_basic
cryptonote_format_utils_basic
mnemonics
ringct
ringct_basic
common
cncrypto
blockchain_db
blocks
checkpoints
device
device_trezor
multisig
version
randomx
epee
hardforks
cncrypto
${wallet_crypto}

${UNBOUND_LIBRARIES}
${Boost_LIBRARIES}
${Protobuf_LIBRARY}
${LibUSB_LIBRARIES}
${OPENSSL_LIBRARIES}
${SODIUM_LIBRARY}
${HIDAPI_LIBRARIES}
${EXTRA_LIBRARIES}
)
if (NOT WIN32)
target_link_libraries(monero_light_tests dl)
endif()
endif()

########################
# Build C++ scratchpad
########################
Expand Down
4 changes: 2 additions & 2 deletions bin/update_submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ git submodule update --init --force --recursive

# update monero-project
cd ./external/monero-project
git checkout master
git pull --ff-only origin master
git checkout light-wallet-maintenance
git pull --ff-only origin light-wallet-maintenance
cd ../../
58 changes: 58 additions & 0 deletions src/utils/monero_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,64 @@ bool monero_utils::is_valid_private_spend_key(const std::string& private_spend_k
}
}

bool monero_utils::generate_key_image(
const crypto::public_key& account_pub_spend_key,
const crypto::secret_key& account_sec_spend_key,
const crypto::secret_key& account_sec_view_key,
const crypto::public_key& tx_public_key,
uint64_t out_index,
crypto::key_image &key_image) {
key_image = {};
//
bool r = false;
//
// "Subaddresses aren't supported in mymonero/openmonero yet. Roll out the original scheme:
// compute D = a*R
// compute P = Hs(D || i)*G + B
// compute x = Hs(D || i) + b (and check if P==x*G)
// compute I = x*Hp(P)"
crypto::key_derivation derivation;
r = crypto::generate_key_derivation(tx_public_key, account_sec_view_key, derivation);
if (!r) {
//retVals.did_error = true;
//std::ostringstream ss{};
//ss << "failed to generate_key_derivation(" << tx_public_key << ", " << account_sec_view_key << ")";
//retVals.err_string = ss.str();
//
return false;
}
cryptonote::keypair in_ephemeral;
r = crypto::derive_public_key(derivation, out_index, account_pub_spend_key, in_ephemeral.pub);
if (!r) {
//retVals.did_error = true;
//std::ostringstream ss{};
//ss << "failed to derive_public_key (" << derivation << ", " << out_index << ", " << account_pub_spend_key << ")";
//retVals.err_string = ss.str();
//
return false;
}
crypto::derive_secret_key(derivation, out_index, account_sec_spend_key, in_ephemeral.sec);
crypto::public_key out_pkey_test;
r = crypto::secret_key_to_public_key(in_ephemeral.sec, out_pkey_test);
if (!r) {
//retVals.did_error = true;
//std::ostringstream ss{};
//ss << "failed to secret_key_to_public_key(" << in_ephemeral.sec << ")";
//retVals.err_string = ss.str();
//
return false;
}
if (in_ephemeral.pub != out_pkey_test) {
//retVals.did_error = true;
//retVals.err_string = "derived secret key doesn't match derived public key";
//
return false;
}
crypto::generate_key_image(in_ephemeral.pub, in_ephemeral.sec, key_image);
//
return true;
}

void monero_utils::validate_address(const std::string& address, monero_network_type network_type) {
cryptonote::address_parse_info info;
if (!get_account_address_from_str(info, static_cast<cryptonote::network_type>(network_type), address)) throw std::runtime_error("Invalid address");
Expand Down
8 changes: 8 additions & 0 deletions src/utils/monero_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ namespace monero_utils
bool is_valid_address(const std::string& address, monero_network_type network_type);
bool is_valid_private_view_key(const std::string& private_view_key);
bool is_valid_private_spend_key(const std::string& private_spend_key);
bool generate_key_image(
const crypto::public_key& account_pub_spend_key,
const crypto::secret_key& account_sec_spend_key,
const crypto::secret_key& account_sec_view_key,
const crypto::public_key& tx_public_key,
uint64_t out_index,
crypto::key_image &key_image
);
void validate_address(const std::string& address, monero_network_type network_type);
void validate_private_view_key(const std::string& private_view_key);
void validate_private_spend_key(const std::string& private_spend_key);
Expand Down
Loading

0 comments on commit 44b31c6

Please sign in to comment.