From 29bf49228652f7c6b4418cfde965e810e1cd09ba Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 11:58:56 +0100 Subject: [PATCH 01/10] add dummy device for ledger --- .../0016-add-dummy-device-for-ledger.patch | 196 +++--------------- 1 file changed, 28 insertions(+), 168 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index dddb4b19..e42f3ffb 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -1,21 +1,21 @@ From 77f328ba6befb9b964f764a27f8a03b71bf9095d Mon Sep 17 00:00:00 2001 -From: Czarek Nakamoto -Date: Wed, 26 Jun 2024 15:04:38 +0200 +From: Konstantin Ullrich +Date: Fri, 22 Nov 2024 11:43:18 +0100 Subject: [PATCH 16/16] add dummy device for ledger --- CMakeLists.txt | 6 +- src/device/CMakeLists.txt | 6 +- - src/device/device.cpp | 10 ++- - src/device/device.hpp | 12 +-- - src/device/device_io_dummy.cpp | 133 +++++++++++++++++++++++++++++++++ - src/device/device_io_dummy.hpp | 74 ++++++++++++++++++ + src/device/device.cpp | 10 ++-- + src/device/device.hpp | 12 +--- + src/device/device_io_dummy.cpp | 100 +++++++++++++++++++++++++++++++++ + src/device/device_io_dummy.hpp | 74 ++++++++++++++++++++++++ src/device/device_ledger.cpp | 6 +- - src/device/device_ledger.hpp | 7 +- - src/wallet/api/wallet.cpp | 94 +++++++++++++++++++++++ - src/wallet/api/wallet.h | 18 +++++ - src/wallet/api/wallet2_api.h | 12 +++ - 11 files changed, 357 insertions(+), 21 deletions(-) + src/device/device_ledger.hpp | 7 ++- + src/wallet/api/wallet.cpp | 13 +++++ + src/wallet/api/wallet.h | 2 + + src/wallet/api/wallet2_api.h | 3 + + 11 files changed, 218 insertions(+), 21 deletions(-) create mode 100644 src/device/device_io_dummy.cpp create mode 100644 src/device/device_io_dummy.hpp @@ -130,10 +130,10 @@ index 392703a24..ffd419779 100644 diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp new file mode 100644 -index 000000000..fb082694e +index 000000000..a5cbcb328 --- /dev/null +++ b/src/device/device_io_dummy.cpp -@@ -0,0 +1,133 @@ +@@ -0,0 +1,100 @@ +// Copyright (c) 2017-2022, The Monero Project +// +// All rights reserved. @@ -181,13 +181,7 @@ index 000000000..fb082694e +#include "device_ledger.hpp" + + -+bool hw::io::device_io_dummy::stateIsConnected = false; -+unsigned char* hw::io::device_io_dummy::sendToDevice = {}; -+size_t hw::io::device_io_dummy::sendToDeviceLength = 0; -+unsigned char* hw::io::device_io_dummy::receivedFromDevice = {}; -+size_t hw::io::device_io_dummy::receivedFromDeviceLength = 0; -+bool hw::io::device_io_dummy::waitsForDeviceSend = false; -+bool hw::io::device_io_dummy::waitsForDeviceReceive = false; ++int (*hw::io::device_io_dummy::sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); + +namespace hw { + namespace io { @@ -225,32 +219,8 @@ index 000000000..fb082694e + } + + int device_io_dummy::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) { -+ MDEBUG("exchange(): locking mutex"); -+ boost::unique_lock lock(mutex); -+ sendToDevice = command; -+ sendToDeviceLength = cmd_len; -+ waitsForDeviceSend = true; -+ waitsForDeviceReceive = true; -+ MDEBUG("exchange(): waitsForDeviceSend"); -+ // NOTE: waitsForDeviceSend should be changed by external code -+ while (waitsForDeviceSend) { -+ usleep(1000); -+ MDEBUG("exchange(): waitsForDeviceSend (still)"); -+ } -+ -+ MDEBUG("exchange(): waitsForDeviceReceive"); -+ while (waitsForDeviceReceive) { -+ usleep(1000); -+ MDEBUG("exchange(): waitsForDeviceReceive (still)"); -+ } -+ -+ if (receivedFromDeviceLength > max_resp_len) { -+ MDEBUG("exchange(): receivedFromDeviceLength ("<mode = NONE; this->has_view_key = false; this->tx_in_progress = false; -@@ -532,7 +532,9 @@ namespace hw { +@@ -533,7 +533,9 @@ namespace hw { bool device_ledger::connect(void) { this->disconnect(); @@ -414,7 +380,7 @@ index 03058c4f1..506f27c4a 100644 unsigned char buffer_send[BUFFER_SEND_SIZE]; unsigned int length_recv; diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 8bdd75a5a..09f91c5e2 100644 +index a307d35a7..6f1f9714e 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -49,6 +49,9 @@ @@ -427,154 +393,48 @@ index 8bdd75a5a..09f91c5e2 100644 using namespace std; using namespace cryptonote; -@@ -3299,4 +3302,95 @@ uint64_t WalletImpl::getBytesSent() +@@ -3298,4 +3301,14 @@ uint64_t WalletImpl::getBytesSent() return m_wallet->get_bytes_sent(); } -+ +// HIDAPI_DUMMY -+bool WalletImpl::getStateIsConnected() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return false; -+ #else -+ return hw::io::device_io_dummy::stateIsConnected; -+ #endif -+} -+ -+unsigned char* WalletImpl::getSendToDevice() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return {}; -+ #else -+ return hw::io::device_io_dummy::sendToDevice; -+ #endif -+} -+ -+size_t WalletImpl::getSendToDeviceLength() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return -1; -+ #else -+ return hw::io::device_io_dummy::sendToDeviceLength; -+ #endif -+} -+ -+unsigned char* WalletImpl::getReceivedFromDevice() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return {}; -+ #else -+ return hw::io::device_io_dummy::receivedFromDevice; -+ #endif -+} -+ -+size_t WalletImpl::getReceivedFromDeviceLength() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return -1; -+ #else -+ return hw::io::device_io_dummy::receivedFromDeviceLength; -+ #endif -+} -+ -+bool WalletImpl::getWaitsForDeviceSend() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return false; -+ #else -+ return hw::io::device_io_dummy::receivedFromDeviceLength; -+ #endif -+} -+ -+bool WalletImpl::getWaitsForDeviceReceive() { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return false; -+ #else -+ return hw::io::device_io_dummy::waitsForDeviceReceive; -+ #endif -+} -+ -+void WalletImpl::setDeviceReceivedData(unsigned char* data, size_t len) { ++void WalletImpl::setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) { + #ifndef HIDAPI_DUMMY + setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); + return; + #else -+ hw::io::device_io_dummy::receivedFromDevice = static_cast(malloc(len)); -+ hw::io::device_io_dummy::receivedFromDeviceLength = len; -+ memset(hw::io::device_io_dummy::receivedFromDevice, 0, len); -+ memcpy(hw::io::device_io_dummy::receivedFromDevice, data, len); -+ hw::io::device_io_dummy::waitsForDeviceReceive = false; -+ #endif -+} -+ -+void WalletImpl::setDeviceSendData(unsigned char* data, size_t len) { -+ #ifndef HIDAPI_DUMMY -+ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); -+ return; -+ #else -+ hw::io::device_io_dummy::sendToDevice = static_cast(malloc(len)); -+ hw::io::device_io_dummy::sendToDeviceLength = len; -+ memset(hw::io::device_io_dummy::sendToDevice, 0, len); -+ memcpy(hw::io::device_io_dummy::sendToDevice, data, len); -+ hw::io::device_io_dummy::waitsForDeviceSend = false; ++ hw::io::device_io_dummy::sendToLedgerDevice = sendToLedgerDevice; + #endif +} + } // namespace diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index febc93119..9e1fbb40b 100644 +index febc93119..58c55bb52 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h -@@ -321,6 +321,24 @@ private: +@@ -321,6 +321,8 @@ private: // cache connection status to avoid unnecessary RPC calls mutable std::atomic m_is_connected; boost::optional m_daemon_login{}; + -+ bool getStateIsConnected(); -+ -+ unsigned char *getSendToDevice(); -+ -+ size_t getSendToDeviceLength(); -+ -+ unsigned char *getReceivedFromDevice(); -+ -+ size_t getReceivedFromDeviceLength(); -+ -+ bool getWaitsForDeviceSend(); -+ -+ bool getWaitsForDeviceReceive(); -+ -+ void setDeviceReceivedData(unsigned char *data, size_t len); -+ -+ void setDeviceSendData(unsigned char *data, size_t len); ++ void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); }; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 2bbb32c8b..c8d6bb179 100644 +index 2bbb32c8b..a5f5c52d4 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h -@@ -1204,6 +1204,18 @@ struct Wallet +@@ -1204,6 +1204,9 @@ struct Wallet //! get bytes sent virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY -+ virtual bool getStateIsConnected() = 0; -+ virtual unsigned char* getSendToDevice() = 0; -+ virtual size_t getSendToDeviceLength() = 0; -+ virtual unsigned char* getReceivedFromDevice() = 0; -+ virtual size_t getReceivedFromDeviceLength() = 0; -+ virtual bool getWaitsForDeviceSend() = 0; -+ virtual bool getWaitsForDeviceReceive() = 0; -+ -+ virtual void setDeviceReceivedData(unsigned char* data, size_t len) = 0; -+ virtual void setDeviceSendData(unsigned char* data, size_t len) = 0; ++ virtual setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len) = 0; }; /** -- -2.45.1.windows.1 +2.47.0 From 208c24479ec0ceca2b7c38034f23b164bf1672e5 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 12:16:50 +0100 Subject: [PATCH 02/10] add better dummy device for ledger --- impls/monero.dart/lib/monero.dart | 77 +------- .../monero.dart/lib/src/checksum_monero.dart | 4 +- .../lib/src/generated_bindings_monero.g.dart | 176 ++++-------------- impls/monero.ts/checksum_monero.ts | 4 +- .../src/main/cpp/monero_checksum.h | 4 +- .../src/main/cpp/wallet2_api_c.cpp | 44 +---- .../src/main/cpp/wallet2_api_c.h | 10 +- 7 files changed, 50 insertions(+), 269 deletions(-) diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart index 7b6eac31..5acc4318 100644 --- a/impls/monero.dart/lib/monero.dart +++ b/impls/monero.dart/lib/monero.dart @@ -3279,76 +3279,17 @@ int MONERO_Wallet_getBytesSent(wallet ptr) { return getBytesSent; } -bool Wallet_getStateIsConnected(wallet ptr) { - debugStart?.call('MONERO_Wallet_getStateIsConnected'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getStateIsConnected(ptr); - debugEnd?.call('MONERO_Wallet_getStateIsConnected'); - return ret; -} - -Pointer Wallet_getSendToDevice(wallet ptr) { - debugStart?.call('MONERO_Wallet_getSendToDevice'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDevice(ptr); - debugEnd?.call('MONERO_Wallet_getSendToDevice'); - return ret; -} - -int Wallet_getSendToDeviceLength(wallet ptr) { - debugStart?.call('MONERO_Wallet_getSendToDeviceLength'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDeviceLength(ptr); - debugEnd?.call('MONERO_Wallet_getSendToDeviceLength'); - return ret; -} - -Pointer Wallet_getReceivedFromDevice(wallet ptr) { - debugStart?.call('MONERO_Wallet_getReceivedFromDevice'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDevice(ptr); - debugEnd?.call('MONERO_Wallet_getReceivedFromDevice'); - return ret; -} - -int Wallet_getReceivedFromDeviceLength(wallet ptr) { - debugStart?.call('MONERO_Wallet_getReceivedFromDeviceLength'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(ptr); - debugEnd?.call('MONERO_Wallet_getReceivedFromDeviceLength'); - return ret; -} - -bool Wallet_getWaitsForDeviceSend(wallet ptr) { - debugStart?.call('MONERO_Wallet_getWaitsForDeviceSend'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(ptr); - debugEnd?.call('MONERO_Wallet_getWaitsForDeviceSend'); - return ret; -} - -bool Wallet_getWaitsForDeviceReceive(wallet ptr) { - debugStart?.call('MONERO_Wallet_getWaitsForDeviceReceive'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(ptr); - debugEnd?.call('MONERO_Wallet_getWaitsForDeviceReceive'); - return ret; -} - -void Wallet_setDeviceReceivedData( - wallet ptr, Pointer data, int len) { - debugStart?.call('MONERO_Wallet_setDeviceReceivedData'); - lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceReceivedData(ptr, data, len); - debugEnd?.call('MONERO_Wallet_setDeviceReceivedData'); - return ret; -} +typedef LedgerExchangeFunction = Pointer< + NativeFunction< + Int Function(Pointer command, UnsignedInt cmd_len, + Pointer response, UnsignedInt max_resp_len)>>; -void Wallet_setDeviceSendData(wallet ptr, Pointer data, int len) { - debugStart?.call('MONERO_Wallet_setDeviceSendData'); +void Wallet_setLedgerExchange( + wallet ptr, LedgerExchangeFunction sendToLedgerDevice) { + debugStart?.call('MONERO_Wallet_setLedgerExchange'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceSendData(ptr, data, len); - debugEnd?.call('MONERO_Wallet_setDeviceSendData'); + final ret = lib!.MONERO_Wallet_setLedgerExchange(ptr, sendToLedgerDevice); + debugEnd?.call('MONERO_Wallet_setLedgerExchange'); return ret; } diff --git a/impls/monero.dart/lib/src/checksum_monero.dart b/impls/monero.dart/lib/src/checksum_monero.dart index 10925332..f3f28843 100644 --- a/impls/monero.dart/lib/src/checksum_monero.dart +++ b/impls/monero.dart/lib/src/checksum_monero.dart @@ -1,4 +1,4 @@ // ignore_for_file: constant_identifier_names -const String wallet2_api_c_h_sha256 = "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b"; -const String wallet2_api_c_cpp_sha256 = "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; +const String wallet2_api_c_h_sha256 = "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de"; +const String wallet2_api_c_cpp_sha256 = "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; const String wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522"; diff --git a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart index cd2124bc..48a59a68 100644 --- a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart +++ b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart @@ -4384,158 +4384,46 @@ class MoneroC { late final _MONERO_Wallet_getBytesSent = _MONERO_Wallet_getBytesSentPtr .asFunction)>(); - bool MONERO_Wallet_getStateIsConnected( + void MONERO_Wallet_setLedgerExchange( ffi.Pointer wallet_ptr, + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer command, + ffi.UnsignedInt cmd_len, + ffi.Pointer response, + ffi.UnsignedInt max_resp_len)>> + sendToLedgerDevice, ) { - return _MONERO_Wallet_getStateIsConnected( + return _MONERO_Wallet_setLedgerExchange( wallet_ptr, + sendToLedgerDevice, ); } - late final _MONERO_Wallet_getStateIsConnectedPtr = - _lookup)>>( - 'MONERO_Wallet_getStateIsConnected'); - late final _MONERO_Wallet_getStateIsConnected = - _MONERO_Wallet_getStateIsConnectedPtr.asFunction< - bool Function(ffi.Pointer)>(); - - ffi.Pointer MONERO_Wallet_getSendToDevice( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getSendToDevice( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getSendToDevicePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('MONERO_Wallet_getSendToDevice'); - late final _MONERO_Wallet_getSendToDevice = - _MONERO_Wallet_getSendToDevicePtr.asFunction< - ffi.Pointer Function(ffi.Pointer)>(); - - int MONERO_Wallet_getSendToDeviceLength( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getSendToDeviceLength( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getSendToDeviceLengthPtr = - _lookup)>>( - 'MONERO_Wallet_getSendToDeviceLength'); - late final _MONERO_Wallet_getSendToDeviceLength = - _MONERO_Wallet_getSendToDeviceLengthPtr.asFunction< - int Function(ffi.Pointer)>(); - - ffi.Pointer MONERO_Wallet_getReceivedFromDevice( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getReceivedFromDevice( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getReceivedFromDevicePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('MONERO_Wallet_getReceivedFromDevice'); - late final _MONERO_Wallet_getReceivedFromDevice = - _MONERO_Wallet_getReceivedFromDevicePtr.asFunction< - ffi.Pointer Function(ffi.Pointer)>(); - - int MONERO_Wallet_getReceivedFromDeviceLength( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getReceivedFromDeviceLength( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getReceivedFromDeviceLengthPtr = - _lookup)>>( - 'MONERO_Wallet_getReceivedFromDeviceLength'); - late final _MONERO_Wallet_getReceivedFromDeviceLength = - _MONERO_Wallet_getReceivedFromDeviceLengthPtr.asFunction< - int Function(ffi.Pointer)>(); - - bool MONERO_Wallet_getWaitsForDeviceSend( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getWaitsForDeviceSend( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getWaitsForDeviceSendPtr = - _lookup)>>( - 'MONERO_Wallet_getWaitsForDeviceSend'); - late final _MONERO_Wallet_getWaitsForDeviceSend = - _MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction< - bool Function(ffi.Pointer)>(); - - bool MONERO_Wallet_getWaitsForDeviceReceive( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getWaitsForDeviceReceive( - wallet_ptr, - ); - } - - late final _MONERO_Wallet_getWaitsForDeviceReceivePtr = - _lookup)>>( - 'MONERO_Wallet_getWaitsForDeviceReceive'); - late final _MONERO_Wallet_getWaitsForDeviceReceive = - _MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction< - bool Function(ffi.Pointer)>(); - - void MONERO_Wallet_setDeviceReceivedData( - ffi.Pointer wallet_ptr, - ffi.Pointer data, - int len, - ) { - return _MONERO_Wallet_setDeviceReceivedData( - wallet_ptr, - data, - len, - ); - } - - late final _MONERO_Wallet_setDeviceReceivedDataPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Size)>>('MONERO_Wallet_setDeviceReceivedData'); - late final _MONERO_Wallet_setDeviceReceivedData = - _MONERO_Wallet_setDeviceReceivedDataPtr.asFunction< + late final _MONERO_Wallet_setLedgerExchangePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer command, + ffi.UnsignedInt cmd_len, + ffi.Pointer response, + ffi.UnsignedInt max_resp_len)>>)>>( + 'MONERO_Wallet_setLedgerExchange'); + late final _MONERO_Wallet_setLedgerExchange = + _MONERO_Wallet_setLedgerExchangePtr.asFunction< void Function( - ffi.Pointer, ffi.Pointer, int)>(); - - void MONERO_Wallet_setDeviceSendData( - ffi.Pointer wallet_ptr, - ffi.Pointer data, - int len, - ) { - return _MONERO_Wallet_setDeviceSendData( - wallet_ptr, - data, - len, - ); - } - - late final _MONERO_Wallet_setDeviceSendDataPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( ffi.Pointer, - ffi.Pointer, - ffi.Size)>>('MONERO_Wallet_setDeviceSendData'); - late final _MONERO_Wallet_setDeviceSendData = - _MONERO_Wallet_setDeviceSendDataPtr.asFunction< - void Function( - ffi.Pointer, ffi.Pointer, int)>(); + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer command, + ffi.UnsignedInt cmd_len, + ffi.Pointer response, + ffi.UnsignedInt max_resp_len)>>)>(); ffi.Pointer MONERO_WalletManager_createWallet( ffi.Pointer wm_ptr, diff --git a/impls/monero.ts/checksum_monero.ts b/impls/monero.ts/checksum_monero.ts index b8e57cbf..7a322dde 100644 --- a/impls/monero.ts/checksum_monero.ts +++ b/impls/monero.ts/checksum_monero.ts @@ -1,5 +1,5 @@ export const moneroChecksum = { - wallet2_api_c_h_sha256: "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b", - wallet2_api_c_cpp_sha256: "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd", + wallet2_api_c_h_sha256: "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de", + wallet2_api_c_cpp_sha256: "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd", wallet2_api_c_exp_sha256: "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522", } diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h index 4d3d39f1..ffd5517d 100644 --- a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h +++ b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h @@ -1,6 +1,6 @@ #ifndef MONEROC_CHECKSUMS #define MONEROC_CHECKSUMS -const char * MONERO_wallet2_api_c_h_sha256 = "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b"; -const char * MONERO_wallet2_api_c_cpp_sha256 = "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; +const char * MONERO_wallet2_api_c_h_sha256 = "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de"; +const char * MONERO_wallet2_api_c_cpp_sha256 = "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; const char * MONERO_wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522"; #endif diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index 0cc2f9f2..f44e46a4 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -1607,49 +1607,9 @@ uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr) { return wallet->getBytesSent(); } -bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr) { +void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) { Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getStateIsConnected(); -} - -unsigned char* MONERO_Wallet_getSendToDevice(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getSendToDevice(); -} - -size_t MONERO_Wallet_getSendToDeviceLength(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getSendToDeviceLength(); -} - -unsigned char* MONERO_Wallet_getReceivedFromDevice(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getReceivedFromDevice(); -} - -size_t MONERO_Wallet_getReceivedFromDeviceLength(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getReceivedFromDeviceLength(); -} - -bool MONERO_Wallet_getWaitsForDeviceSend(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getWaitsForDeviceSend(); -} - -bool MONERO_Wallet_getWaitsForDeviceReceive(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getWaitsForDeviceReceive(); -} - -void MONERO_Wallet_setDeviceReceivedData(void* wallet_ptr, unsigned char* data, size_t len) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->setDeviceReceivedData(data, len); -} - -void MONERO_Wallet_setDeviceSendData(void* wallet_ptr, unsigned char* data, size_t len) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->setDeviceSendData(data, len); + return wallet->setLedgerExchange(sendToLedgerDevice); } void* MONERO_WalletManager_createWallet(void* wm_ptr, const char* path, const char* password, const char* language, int networkType) { diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h index 143da407..80a72c50 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -834,15 +834,7 @@ extern ADDAPI uint64_t MONERO_Wallet_getBytesReceived(void* wallet_ptr); // virtual uint64_t getBytesSent() = 0; extern ADDAPI uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr); // HIDAPI_DUMMY -extern ADDAPI bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr); -extern ADDAPI unsigned char* MONERO_Wallet_getSendToDevice(void* wallet_ptr); -extern ADDAPI size_t MONERO_Wallet_getSendToDeviceLength(void* wallet_ptr); -extern ADDAPI unsigned char* MONERO_Wallet_getReceivedFromDevice(void* wallet_ptr); -extern ADDAPI size_t MONERO_Wallet_getReceivedFromDeviceLength(void* wallet_ptr); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceSend(void* wallet_ptr); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceReceive(void* wallet_ptr); -extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(void* wallet_ptr, unsigned char* data, size_t len); -extern ADDAPI void MONERO_Wallet_setDeviceSendData(void* wallet_ptr, unsigned char* data, size_t len); +extern ADDAPI void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)); // }; // struct WalletManager From 9a0f3cd97fb1792a689518f8d6f44faa49f19510 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 13:50:47 +0100 Subject: [PATCH 03/10] add better dummy device for ledger --- .../0016-add-dummy-device-for-ledger.patch | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index e42f3ffb..efe492ba 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -9,13 +9,13 @@ Subject: [PATCH 16/16] add dummy device for ledger src/device/device.cpp | 10 ++-- src/device/device.hpp | 12 +--- src/device/device_io_dummy.cpp | 100 +++++++++++++++++++++++++++++++++ - src/device/device_io_dummy.hpp | 74 ++++++++++++++++++++++++ + src/device/device_io_dummy.hpp | 68 ++++++++++++++++++++++ src/device/device_ledger.cpp | 6 +- src/device/device_ledger.hpp | 7 ++- src/wallet/api/wallet.cpp | 13 +++++ src/wallet/api/wallet.h | 2 + src/wallet/api/wallet2_api.h | 3 + - 11 files changed, 218 insertions(+), 21 deletions(-) + 11 files changed, 212 insertions(+), 21 deletions(-) create mode 100644 src/device/device_io_dummy.cpp create mode 100644 src/device/device_io_dummy.hpp @@ -236,10 +236,10 @@ index 000000000..a5cbcb328 +#endif // HAVE_HIDAPI diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp new file mode 100644 -index 000000000..a1733616d +index 000000000..77c0a7cb1 --- /dev/null +++ b/src/device/device_io_dummy.hpp -@@ -0,0 +1,74 @@ +@@ -0,0 +1,68 @@ +// Copyright (c) 2017-2022, The Monero Project +// +// All rights reserved. @@ -288,13 +288,7 @@ index 000000000..a1733616d + boost::mutex mutex; + + public: -+ static bool stateIsConnected; -+ static unsigned char* sendToDevice; -+ static size_t sendToDeviceLength; -+ static unsigned char* receivedFromDevice; -+ static size_t receivedFromDeviceLength; -+ static bool waitsForDeviceSend; -+ static bool waitsForDeviceReceive; ++ static static int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); + + device_io_dummy() = default; + device_io_dummy(int a, int b, int c, int d); From 17985f12a306c95c5865fded492c8dea59e6ce36 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 14:01:31 +0100 Subject: [PATCH 04/10] add better dummy device for ledger --- patches/monero/0016-add-dummy-device-for-ledger.patch | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index efe492ba..d11f135c 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -403,7 +403,7 @@ index a307d35a7..6f1f9714e 100644 + } // namespace diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index febc93119..58c55bb52 100644 +index febc93119..bfe2eb34f 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -321,6 +321,8 @@ private: @@ -411,12 +411,12 @@ index febc93119..58c55bb52 100644 mutable std::atomic m_is_connected; boost::optional m_daemon_login{}; + -+ void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); ++ void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)); }; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 2bbb32c8b..a5f5c52d4 100644 +index 2bbb32c8b..29ff39553 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -1204,6 +1204,9 @@ struct Wallet @@ -425,7 +425,7 @@ index 2bbb32c8b..a5f5c52d4 100644 virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY -+ virtual setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len) = 0; ++ virtual setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) = 0; }; /** From d0675e7e31e9655decaea283858187d95a855348 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 14:26:46 +0100 Subject: [PATCH 05/10] add better dummy device for ledger --- .../0016-add-dummy-device-for-ledger.patch | 208 +----------------- 1 file changed, 12 insertions(+), 196 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index d11f135c..11b5a3c8 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -4,20 +4,16 @@ Date: Fri, 22 Nov 2024 11:43:18 +0100 Subject: [PATCH 16/16] add dummy device for ledger --- - CMakeLists.txt | 6 +- - src/device/CMakeLists.txt | 6 +- - src/device/device.cpp | 10 ++-- - src/device/device.hpp | 12 +--- - src/device/device_io_dummy.cpp | 100 +++++++++++++++++++++++++++++++++ - src/device/device_io_dummy.hpp | 68 ++++++++++++++++++++++ - src/device/device_ledger.cpp | 6 +- - src/device/device_ledger.hpp | 7 ++- - src/wallet/api/wallet.cpp | 13 +++++ - src/wallet/api/wallet.h | 2 + - src/wallet/api/wallet2_api.h | 3 + - 11 files changed, 212 insertions(+), 21 deletions(-) - create mode 100644 src/device/device_io_dummy.cpp - create mode 100644 src/device/device_io_dummy.hpp + CMakeLists.txt | 6 +++++- + src/device/CMakeLists.txt | 6 ++++-- + src/device/device.cpp | 10 ++++++---- + src/device/device.hpp | 12 +----------- + src/device/device_ledger.cpp | 6 ++++-- + src/device/device_ledger.hpp | 7 ++++++- + src/wallet/api/wallet.cpp | 13 +++++++++++++ + src/wallet/api/wallet.h | 2 ++ + src/wallet/api/wallet2_api.h | 3 +++ + 9 files changed, 44 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6028c0961..e7fa90abb 100644 @@ -128,186 +124,6 @@ index 392703a24..ffd419779 100644 #define WITH_DEVICE_LEDGER #endif -diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp -new file mode 100644 -index 000000000..a5cbcb328 ---- /dev/null -+++ b/src/device/device_io_dummy.cpp -@@ -0,0 +1,100 @@ -+// Copyright (c) 2017-2022, The Monero Project -+// -+// All rights reserved. -+// -+// Redistribution and use in source and binary forms, with or without modification, are -+// permitted provided that the following conditions are met: -+// -+// 1. Redistributions of source code must retain the above copyright notice, this list of -+// conditions and the following disclaimer. -+// -+// 2. Redistributions in binary form must reproduce the above copyright notice, this list -+// of conditions and the following disclaimer in the documentation and/or other -+// materials provided with the distribution. -+// -+// 3. Neither the name of the copyright holder nor the names of its contributors may be -+// used to endorse or promote products derived from this software without specific -+// prior written permission. -+// -+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -+// -+ -+// device_io_dummy -+// Main goal of device_io_dummy is to emulate a hw::io::device_io without the need to actually -+// connect a device. -+// Many operating systems do not support giving raw USB access to a process (android), or don't -+// support that at all (hi iOS), therefore other means of connection can be used, either USB -+// abstraction provided by the OS (monerujo), or BLE (also monerujo). -+// Monerujo implementation is written in Java, which makes it a nice fit for iOS, but makes the -+// code extremely unportable, so for this reason the code in here is written in CPP. -+// Data transport is made available in wallet2_api.h, so wallet developers can easily plug their -+// own USB/BLE/other transport layer. -+ -+#ifdef HIDAPI_DUMMY -+#include -+#include "log.hpp" -+#include "device_io_dummy.hpp" -+#include "device_ledger.hpp" -+ -+ -+int (*hw::io::device_io_dummy::sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); -+ -+namespace hw { -+ namespace io { -+ -+#undef MONERO_DEFAULT_LOG_CATEGORY -+#define MONERO_DEFAULT_LOG_CATEGORY "device.io_dummy" -+ device_io_dummy::device_io_dummy(int a, int b, int c, int d) { -+ MDEBUG("device_io_dummy(a: " << a << ", b: " << b << ", c: " << c << ", d: " << d <<")"); -+ } -+ -+ void device_io_dummy::init() { -+ MDEBUG("init()"); -+ } -+ -+ void device_io_dummy::connect(void *params) { -+ MDEBUG("connect(" << params << ")"); -+ stateIsConnected = true; -+ } -+ -+ void device_io_dummy::connect(const std::vector& known_devices) { -+ MDEBUG("connect(["); -+ for (const auto &item: known_devices) { -+ MDEBUG("{ interface_number: " << item.interface_number); -+ MDEBUG(" pid : " << item.pid); -+ MDEBUG(" usage_page : " << item.usage_page); -+ MDEBUG(" vid : " << item.vid << " },"); -+ } -+ MDEBUG("])"); -+ stateIsConnected = true; -+ } -+ -+ bool device_io_dummy::connected() const { -+ MDEBUG("connected()"); -+ return stateIsConnected; -+ } -+ -+ int device_io_dummy::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) { -+ size_t receivedFromDeviceLength = sendToLedgerDevice(command, cmd_len, response, max_resp_len); -+ -+ return receivedFromDeviceLength; -+ } -+ -+ void device_io_dummy::disconnect() { -+ MDEBUG("disconnect()"); -+ } -+ -+ void device_io_dummy::release() { -+ MDEBUG("release()"); -+ } -+ } -+} -+#endif // HAVE_HIDAPI -diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp -new file mode 100644 -index 000000000..77c0a7cb1 ---- /dev/null -+++ b/src/device/device_io_dummy.hpp -@@ -0,0 +1,68 @@ -+// Copyright (c) 2017-2022, The Monero Project -+// -+// All rights reserved. -+// -+// Redistribution and use in source and binary forms, with or without modification, are -+// permitted provided that the following conditions are met: -+// -+// 1. Redistributions of source code must retain the above copyright notice, this list of -+// conditions and the following disclaimer. -+// -+// 2. Redistributions in binary form must reproduce the above copyright notice, this list -+// of conditions and the following disclaimer in the documentation and/or other -+// materials provided with the distribution. -+// -+// 3. Neither the name of the copyright holder nor the names of its contributors may be -+// used to endorse or promote products derived from this software without specific -+// prior written permission. -+// -+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -+// -+#ifdef HIDAPI_DUMMY -+ -+#pragma once -+ -+#include "device_io.hpp" -+#include "device_io_hid.hpp" -+ -+namespace hw { -+ namespace io { -+ struct hid_conn_params { -+ unsigned int vid; -+ unsigned int pid; -+ int interface_number; -+ unsigned short usage_page; -+ }; -+ class device_io_dummy : device_io { -+ private: -+ boost::mutex mutex; -+ -+ public: -+ static static int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); -+ -+ device_io_dummy() = default; -+ device_io_dummy(int a, int b, int c, int d); -+ ~device_io_dummy() = default; -+ -+ void init(); -+ void release(); -+ -+ void connect(void *parms); -+ void connect(const std::vector& known_devices); -+ void disconnect(); -+ bool connected() const; -+ -+ int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); -+ }; -+ }; -+}; -+ -+#endif // HAVE_HIDAPI diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index bb5b6f497..d405b86f2 100644 --- a/src/device/device_ledger.cpp @@ -416,7 +232,7 @@ index febc93119..bfe2eb34f 100644 diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 2bbb32c8b..29ff39553 100644 +index 2bbb32c8b..bc1f733aa 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -1204,6 +1204,9 @@ struct Wallet @@ -425,7 +241,7 @@ index 2bbb32c8b..29ff39553 100644 virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY -+ virtual setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) = 0; ++ virtual void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) = 0; }; /** From d3414339efa5d36d925cd228ffb9e792481cb8ad Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 14:36:55 +0100 Subject: [PATCH 06/10] add dummy device for ledger --- .../0016-add-dummy-device-for-ledger.patch | 204 +++++++++++++++++- 1 file changed, 194 insertions(+), 10 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index 11b5a3c8..2fd6b52b 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -4,16 +4,20 @@ Date: Fri, 22 Nov 2024 11:43:18 +0100 Subject: [PATCH 16/16] add dummy device for ledger --- - CMakeLists.txt | 6 +++++- - src/device/CMakeLists.txt | 6 ++++-- - src/device/device.cpp | 10 ++++++---- - src/device/device.hpp | 12 +----------- - src/device/device_ledger.cpp | 6 ++++-- - src/device/device_ledger.hpp | 7 ++++++- - src/wallet/api/wallet.cpp | 13 +++++++++++++ - src/wallet/api/wallet.h | 2 ++ - src/wallet/api/wallet2_api.h | 3 +++ - 9 files changed, 44 insertions(+), 21 deletions(-) + CMakeLists.txt | 6 +- + src/device/CMakeLists.txt | 6 +- + src/device/device.cpp | 10 ++-- + src/device/device.hpp | 12 +--- + src/device/device_io_dummy.cpp | 100 +++++++++++++++++++++++++++++++++ + src/device/device_io_dummy.hpp | 68 ++++++++++++++++++++++ + src/device/device_ledger.cpp | 6 +- + src/device/device_ledger.hpp | 7 ++- + src/wallet/api/wallet.cpp | 13 +++++ + src/wallet/api/wallet.h | 2 + + src/wallet/api/wallet2_api.h | 3 + + 11 files changed, 212 insertions(+), 21 deletions(-) + create mode 100644 src/device/device_io_dummy.cpp + create mode 100644 src/device/device_io_dummy.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6028c0961..e7fa90abb 100644 @@ -124,6 +128,186 @@ index 392703a24..ffd419779 100644 #define WITH_DEVICE_LEDGER #endif +diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp +new file mode 100644 +index 000000000..a5cbcb328 +--- /dev/null ++++ b/src/device/device_io_dummy.cpp +@@ -0,0 +1,100 @@ ++// Copyright (c) 2017-2022, The Monero Project ++// ++// All rights reserved. ++// ++// Redistribution and use in source and binary forms, with or without modification, are ++// permitted provided that the following conditions are met: ++// ++// 1. Redistributions of source code must retain the above copyright notice, this list of ++// conditions and the following disclaimer. ++// ++// 2. Redistributions in binary form must reproduce the above copyright notice, this list ++// of conditions and the following disclaimer in the documentation and/or other ++// materials provided with the distribution. ++// ++// 3. Neither the name of the copyright holder nor the names of its contributors may be ++// used to endorse or promote products derived from this software without specific ++// prior written permission. ++// ++// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY ++// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ++// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ++// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ++// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ++// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ++// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF ++// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++// ++ ++// device_io_dummy ++// Main goal of device_io_dummy is to emulate a hw::io::device_io without the need to actually ++// connect a device. ++// Many operating systems do not support giving raw USB access to a process (android), or don't ++// support that at all (hi iOS), therefore other means of connection can be used, either USB ++// abstraction provided by the OS (monerujo), or BLE (also monerujo). ++// Monerujo implementation is written in Java, which makes it a nice fit for iOS, but makes the ++// code extremely unportable, so for this reason the code in here is written in CPP. ++// Data transport is made available in wallet2_api.h, so wallet developers can easily plug their ++// own USB/BLE/other transport layer. ++ ++#ifdef HIDAPI_DUMMY ++#include ++#include "log.hpp" ++#include "device_io_dummy.hpp" ++#include "device_ledger.hpp" ++ ++ ++int (*hw::io::device_io_dummy::sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); ++ ++namespace hw { ++ namespace io { ++ ++#undef MONERO_DEFAULT_LOG_CATEGORY ++#define MONERO_DEFAULT_LOG_CATEGORY "device.io_dummy" ++ device_io_dummy::device_io_dummy(int a, int b, int c, int d) { ++ MDEBUG("device_io_dummy(a: " << a << ", b: " << b << ", c: " << c << ", d: " << d <<")"); ++ } ++ ++ void device_io_dummy::init() { ++ MDEBUG("init()"); ++ } ++ ++ void device_io_dummy::connect(void *params) { ++ MDEBUG("connect(" << params << ")"); ++ stateIsConnected = true; ++ } ++ ++ void device_io_dummy::connect(const std::vector& known_devices) { ++ MDEBUG("connect(["); ++ for (const auto &item: known_devices) { ++ MDEBUG("{ interface_number: " << item.interface_number); ++ MDEBUG(" pid : " << item.pid); ++ MDEBUG(" usage_page : " << item.usage_page); ++ MDEBUG(" vid : " << item.vid << " },"); ++ } ++ MDEBUG("])"); ++ stateIsConnected = true; ++ } ++ ++ bool device_io_dummy::connected() const { ++ MDEBUG("connected()"); ++ return stateIsConnected; ++ } ++ ++ int device_io_dummy::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) { ++ size_t receivedFromDeviceLength = sendToLedgerDevice(command, cmd_len, response, max_resp_len); ++ ++ return receivedFromDeviceLength; ++ } ++ ++ void device_io_dummy::disconnect() { ++ MDEBUG("disconnect()"); ++ } ++ ++ void device_io_dummy::release() { ++ MDEBUG("release()"); ++ } ++ } ++} ++#endif // HAVE_HIDAPI +diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp +new file mode 100644 +index 000000000..77c0a7cb1 +--- /dev/null ++++ b/src/device/device_io_dummy.hpp +@@ -0,0 +1,68 @@ ++// Copyright (c) 2017-2022, The Monero Project ++// ++// All rights reserved. ++// ++// Redistribution and use in source and binary forms, with or without modification, are ++// permitted provided that the following conditions are met: ++// ++// 1. Redistributions of source code must retain the above copyright notice, this list of ++// conditions and the following disclaimer. ++// ++// 2. Redistributions in binary form must reproduce the above copyright notice, this list ++// of conditions and the following disclaimer in the documentation and/or other ++// materials provided with the distribution. ++// ++// 3. Neither the name of the copyright holder nor the names of its contributors may be ++// used to endorse or promote products derived from this software without specific ++// prior written permission. ++// ++// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY ++// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ++// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ++// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ++// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ++// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ++// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF ++// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++// ++#ifdef HIDAPI_DUMMY ++ ++#pragma once ++ ++#include "device_io.hpp" ++#include "device_io_hid.hpp" ++ ++namespace hw { ++ namespace io { ++ struct hid_conn_params { ++ unsigned int vid; ++ unsigned int pid; ++ int interface_number; ++ unsigned short usage_page; ++ }; ++ class device_io_dummy : device_io { ++ private: ++ boost::mutex mutex; ++ ++ public: ++ static static int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); ++ ++ device_io_dummy() = default; ++ device_io_dummy(int a, int b, int c, int d); ++ ~device_io_dummy() = default; ++ ++ void init(); ++ void release(); ++ ++ void connect(void *parms); ++ void connect(const std::vector& known_devices); ++ void disconnect(); ++ bool connected() const; ++ ++ int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); ++ }; ++ }; ++}; ++ ++#endif // HAVE_HIDAPI diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index bb5b6f497..d405b86f2 100644 --- a/src/device/device_ledger.cpp From 510510f035a927fe8bbb1dddf822c5cb003c47ad Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 15:30:56 +0100 Subject: [PATCH 07/10] Add Ledger Stuff --- impls/monero.dart/lib/monero.dart | 36 +++++++++++++++---- .../monero_libwallet2_api_c.exp | 10 +----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart index 5acc4318..643bcb98 100644 --- a/impls/monero.dart/lib/monero.dart +++ b/impls/monero.dart/lib/monero.dart @@ -72,7 +72,9 @@ library; // ignore_for_file: non_constant_identifier_names, camel_case_types import 'dart:ffi'; +import 'dart:ffi' as ffi; import 'dart:io'; +import 'dart:typed_data'; import 'package:ffi/ffi.dart'; import 'package:monero/src/generated_bindings_monero.g.dart'; @@ -3279,16 +3281,38 @@ int MONERO_Wallet_getBytesSent(wallet ptr) { return getBytesSent; } -typedef LedgerExchangeFunction = Pointer< - NativeFunction< - Int Function(Pointer command, UnsignedInt cmd_len, - Pointer response, UnsignedInt max_resp_len)>>; +// Ledger Stuff + +typedef LedgerExchangeFunctionNative = Int Function( + Pointer command, + UnsignedInt cmd_len, + Pointer response, + UnsignedInt max_resp_len); void Wallet_setLedgerExchange( - wallet ptr, LedgerExchangeFunction sendToLedgerDevice) { + wallet ptr, Uint8List Function(Uint8List, int) sendToLedgerDevice) { debugStart?.call('MONERO_Wallet_setLedgerExchange'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setLedgerExchange(ptr, sendToLedgerDevice); + + int sendToLedgerDeviceWrapper(Pointer command, int cmd_len, + Pointer response, int max_resp_len) { + final command_ = command.cast().asTypedList(cmd_len); + + final res = sendToLedgerDevice(command_, max_resp_len); + + calloc.free(command); + + for (var i = 0; i < res.length; i++) { + response.cast().asTypedList(res.length)[i] = res[i]; + } + + return res.length; + } + + final sendToLedgerDevice_ = + Pointer.fromFunction( + sendToLedgerDeviceWrapper, 0); + final ret = lib!.MONERO_Wallet_setLedgerExchange(ptr, sendToLedgerDevice_); debugEnd?.call('MONERO_Wallet_setLedgerExchange'); return ret; } diff --git a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp index 3b2931c1..8419a8ee 100644 --- a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp +++ b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp @@ -254,15 +254,7 @@ _MONERO_Wallet_deviceShowAddress _MONERO_Wallet_reconnectDevice _MONERO_Wallet_getBytesReceived _MONERO_Wallet_getBytesSent -_MONERO_Wallet_getStateIsConnected -_MONERO_Wallet_getSendToDevice -_MONERO_Wallet_getSendToDeviceLength -_MONERO_Wallet_getReceivedFromDevice -_MONERO_Wallet_getReceivedFromDeviceLength -_MONERO_Wallet_getWaitsForDeviceSend -_MONERO_Wallet_getWaitsForDeviceReceive -_MONERO_Wallet_setDeviceReceivedData -_MONERO_Wallet_setDeviceSendData +_MONERO_Wallet_setLedgerExchange _MONERO_WalletManager_createWallet _MONERO_WalletManager_openWallet _MONERO_WalletManager_recoveryWallet From 1cccda90358e43ae8f45f9010bfb38f5e38606e5 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 15:38:55 +0100 Subject: [PATCH 08/10] add dummy device for ledger --- .../0016-add-dummy-device-for-ledger.patch | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/patches/monero/0016-add-dummy-device-for-ledger.patch b/patches/monero/0016-add-dummy-device-for-ledger.patch index 2fd6b52b..d8544e9d 100644 --- a/patches/monero/0016-add-dummy-device-for-ledger.patch +++ b/patches/monero/0016-add-dummy-device-for-ledger.patch @@ -9,13 +9,13 @@ Subject: [PATCH 16/16] add dummy device for ledger src/device/device.cpp | 10 ++-- src/device/device.hpp | 12 +--- src/device/device_io_dummy.cpp | 100 +++++++++++++++++++++++++++++++++ - src/device/device_io_dummy.hpp | 68 ++++++++++++++++++++++ + src/device/device_io_dummy.hpp | 69 +++++++++++++++++++++++ src/device/device_ledger.cpp | 6 +- src/device/device_ledger.hpp | 7 ++- - src/wallet/api/wallet.cpp | 13 +++++ - src/wallet/api/wallet.h | 2 + - src/wallet/api/wallet2_api.h | 3 + - 11 files changed, 212 insertions(+), 21 deletions(-) + src/wallet/api/wallet.cpp | 22 ++++++++ + src/wallet/api/wallet.h | 3 + + src/wallet/api/wallet2_api.h | 4 ++ + 11 files changed, 224 insertions(+), 21 deletions(-) create mode 100644 src/device/device_io_dummy.cpp create mode 100644 src/device/device_io_dummy.hpp @@ -130,7 +130,7 @@ index 392703a24..ffd419779 100644 diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp new file mode 100644 -index 000000000..a5cbcb328 +index 000000000..c95de70cc --- /dev/null +++ b/src/device/device_io_dummy.cpp @@ -0,0 +1,100 @@ @@ -180,7 +180,7 @@ index 000000000..a5cbcb328 +#include "device_io_dummy.hpp" +#include "device_ledger.hpp" + -+ ++bool hw::io::device_io_dummy::stateIsConnected = false; +int (*hw::io::device_io_dummy::sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); + +namespace hw { @@ -236,10 +236,10 @@ index 000000000..a5cbcb328 +#endif // HAVE_HIDAPI diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp new file mode 100644 -index 000000000..77c0a7cb1 +index 000000000..266702f28 --- /dev/null +++ b/src/device/device_io_dummy.hpp -@@ -0,0 +1,68 @@ +@@ -0,0 +1,69 @@ +// Copyright (c) 2017-2022, The Monero Project +// +// All rights reserved. @@ -288,7 +288,8 @@ index 000000000..77c0a7cb1 + boost::mutex mutex; + + public: -+ static static int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); ++ static bool stateIsConnected; ++ static int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len); + + device_io_dummy() = default; + device_io_dummy(int a, int b, int c, int d); @@ -374,7 +375,7 @@ index 03058c4f1..506f27c4a 100644 unsigned char buffer_send[BUFFER_SEND_SIZE]; unsigned int length_recv; diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index a307d35a7..6f1f9714e 100644 +index a307d35a7..df2b1d7a4 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -49,6 +49,9 @@ @@ -387,11 +388,20 @@ index a307d35a7..6f1f9714e 100644 using namespace std; using namespace cryptonote; -@@ -3298,4 +3301,14 @@ uint64_t WalletImpl::getBytesSent() +@@ -3298,4 +3301,23 @@ uint64_t WalletImpl::getBytesSent() return m_wallet->get_bytes_sent(); } +// HIDAPI_DUMMY ++bool WalletImpl::getStateIsConnected() { ++ #ifndef HIDAPI_DUMMY ++ setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); ++ return false; ++ #else ++ return hw::io::device_io_dummy::stateIsConnected; ++ #endif ++} ++ +void WalletImpl::setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) { + #ifndef HIDAPI_DUMMY + setStatusError("MONERO compiled with -DHIDAPI_DUMMY"); @@ -403,28 +413,30 @@ index a307d35a7..6f1f9714e 100644 + } // namespace diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index febc93119..bfe2eb34f 100644 +index febc93119..f821bf475 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h -@@ -321,6 +321,8 @@ private: +@@ -321,6 +321,9 @@ private: // cache connection status to avoid unnecessary RPC calls mutable std::atomic m_is_connected; boost::optional m_daemon_login{}; + ++ bool getStateIsConnected(); + void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)); }; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 2bbb32c8b..bc1f733aa 100644 +index 2bbb32c8b..ca7cfaeb2 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h -@@ -1204,6 +1204,9 @@ struct Wallet +@@ -1204,6 +1204,10 @@ struct Wallet //! get bytes sent virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY ++ virtual bool getStateIsConnected() = 0; + virtual void setLedgerExchange(int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) = 0; }; From ca89b74eb585fbf9436c4e8a9c58371f41eb22b4 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 15:45:45 +0100 Subject: [PATCH 09/10] Revert some stuff --- impls/monero.dart/lib/src/checksum_monero.dart | 6 +++--- impls/monero.ts/checksum_monero.ts | 6 +++--- monero_libwallet2_api_c/monero_libwallet2_api_c.exp | 1 + monero_libwallet2_api_c/src/main/cpp/monero_checksum.h | 6 +++--- monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp | 5 +++++ monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h | 1 + 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/impls/monero.dart/lib/src/checksum_monero.dart b/impls/monero.dart/lib/src/checksum_monero.dart index f3f28843..71d497b5 100644 --- a/impls/monero.dart/lib/src/checksum_monero.dart +++ b/impls/monero.dart/lib/src/checksum_monero.dart @@ -1,4 +1,4 @@ // ignore_for_file: constant_identifier_names -const String wallet2_api_c_h_sha256 = "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de"; -const String wallet2_api_c_cpp_sha256 = "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; -const String wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522"; +const String wallet2_api_c_h_sha256 = "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7"; +const String wallet2_api_c_cpp_sha256 = "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; +const String wallet2_api_c_exp_sha256 = "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce"; diff --git a/impls/monero.ts/checksum_monero.ts b/impls/monero.ts/checksum_monero.ts index 7a322dde..7e8abf9e 100644 --- a/impls/monero.ts/checksum_monero.ts +++ b/impls/monero.ts/checksum_monero.ts @@ -1,5 +1,5 @@ export const moneroChecksum = { - wallet2_api_c_h_sha256: "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de", - wallet2_api_c_cpp_sha256: "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd", - wallet2_api_c_exp_sha256: "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522", + wallet2_api_c_h_sha256: "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7", + wallet2_api_c_cpp_sha256: "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd", + wallet2_api_c_exp_sha256: "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce", } diff --git a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp index 8419a8ee..da921167 100644 --- a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp +++ b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp @@ -254,6 +254,7 @@ _MONERO_Wallet_deviceShowAddress _MONERO_Wallet_reconnectDevice _MONERO_Wallet_getBytesReceived _MONERO_Wallet_getBytesSent +_MONERO_Wallet_getStateIsConnected _MONERO_Wallet_setLedgerExchange _MONERO_WalletManager_createWallet _MONERO_WalletManager_openWallet diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h index ffd5517d..a58b6705 100644 --- a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h +++ b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h @@ -1,6 +1,6 @@ #ifndef MONEROC_CHECKSUMS #define MONEROC_CHECKSUMS -const char * MONERO_wallet2_api_c_h_sha256 = "87ec362cdf9b3e6403d899c11e7ae39d932a8098c3ebb360723b537bded2d8de"; -const char * MONERO_wallet2_api_c_cpp_sha256 = "32cc5fbbdb89e77f33619b7f3d942cfac4202f3a3838605a396aed3882d668b5-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; -const char * MONERO_wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522"; +const char * MONERO_wallet2_api_c_h_sha256 = "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7"; +const char * MONERO_wallet2_api_c_cpp_sha256 = "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd"; +const char * MONERO_wallet2_api_c_exp_sha256 = "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce"; #endif diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index f44e46a4..6cdd349e 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -1607,6 +1607,11 @@ uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr) { return wallet->getBytesSent(); } +bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr) { + Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); + return wallet->getStateIsConnected(); +} + void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) { Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); return wallet->setLedgerExchange(sendToLedgerDevice); diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h index 80a72c50..b2af9d8b 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -834,6 +834,7 @@ extern ADDAPI uint64_t MONERO_Wallet_getBytesReceived(void* wallet_ptr); // virtual uint64_t getBytesSent() = 0; extern ADDAPI uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr); // HIDAPI_DUMMY +extern ADDAPI bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr); extern ADDAPI void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)); // }; From 6834738bf6878a1a82cb7686957798ce48443212 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 22 Nov 2024 15:53:17 +0100 Subject: [PATCH 10/10] Revert some stuff --- impls/monero.dart/lib/monero.dart | 8 ++++++++ .../lib/src/generated_bindings_monero.g.dart | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart index 643bcb98..76f03912 100644 --- a/impls/monero.dart/lib/monero.dart +++ b/impls/monero.dart/lib/monero.dart @@ -3283,6 +3283,14 @@ int MONERO_Wallet_getBytesSent(wallet ptr) { // Ledger Stuff +bool Wallet_getStateIsConnected(wallet ptr) { + debugStart?.call('MONERO_Wallet_getStateIsConnected'); + lib ??= MoneroC(DynamicLibrary.open(libPath)); + final ret = lib!.MONERO_Wallet_getStateIsConnected(ptr); + debugEnd?.call('MONERO_Wallet_getStateIsConnected'); + return ret; +} + typedef LedgerExchangeFunctionNative = Int Function( Pointer command, UnsignedInt cmd_len, diff --git a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart index 48a59a68..019b140c 100644 --- a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart +++ b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart @@ -4384,6 +4384,21 @@ class MoneroC { late final _MONERO_Wallet_getBytesSent = _MONERO_Wallet_getBytesSentPtr .asFunction)>(); + bool MONERO_Wallet_getStateIsConnected( + ffi.Pointer wallet_ptr, + ) { + return _MONERO_Wallet_getStateIsConnected( + wallet_ptr, + ); + } + + late final _MONERO_Wallet_getStateIsConnectedPtr = + _lookup)>>( + 'MONERO_Wallet_getStateIsConnected'); + late final _MONERO_Wallet_getStateIsConnected = + _MONERO_Wallet_getStateIsConnectedPtr.asFunction< + bool Function(ffi.Pointer)>(); + void MONERO_Wallet_setLedgerExchange( ffi.Pointer wallet_ptr, ffi.Pointer<