diff options
| -rwxr-xr-x | build_single.sh | 2 | ||||
| -rw-r--r-- | builder/Dockerfile | 6 | ||||
| -rw-r--r-- | contrib/depends/Makefile | 4 | ||||
| -rwxr-xr-x | contrib/depends/gen_toolchain.cmake.sh | 2 | ||||
| -rw-r--r-- | impls/monero.dart/lib/monero.dart | 46 | ||||
| -rw-r--r-- | impls/monero.dart/lib/src/generated_bindings_monero.g.dart | 125 | ||||
| -rw-r--r-- | impls/monero.dart/lib/src/monero.dart | 44 | ||||
| -rw-r--r-- | impls/monero.dart/lib/src/wallet2.dart | 6 | ||||
| -rw-r--r-- | monero_libwallet2_api_c/monero_libwallet2_api_c.exp | 2 | ||||
| -rw-r--r-- | monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp | 40 | ||||
| -rw-r--r-- | monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h | 20 | ||||
| -rw-r--r-- | patches/monero/0021-add-dummy-device-for-Trezor.patch | 596 |
12 files changed, 771 insertions, 122 deletions
diff --git a/build_single.sh b/build_single.sh index ebc30e3..ec2d760 100755 --- a/build_single.sh +++ b/build_single.sh @@ -78,7 +78,7 @@ do EXTRA_CMAKE_FLAGS="-DCAKEWALLET=ON" fi pushd build/${HOST_ABI}_${OUTPUT_MODE} - cmake -DCMAKE_TOOLCHAIN_FILE=$PWD/../../../contrib/depends/${HOST_ABI}/share/toolchain.cmake $EXTRA_CMAKE_FLAGS -DUSE_DEVICE_TREZOR=OFF -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} -DOUTPUT_MODE=${OUTPUT_MODE} ../.. + cmake -DCMAKE_TOOLCHAIN_FILE=$PWD/../../../contrib/depends/${HOST_ABI}/share/toolchain.cmake $EXTRA_CMAKE_FLAGS -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} -DOUTPUT_MODE=${OUTPUT_MODE} ../.. make $NPROC popd popd diff --git a/builder/Dockerfile b/builder/Dockerfile index dbf893b..29dd299 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.26.0-bookworm@sha256:c7a82e9e2df2fea5d8cb62a16aa6f796d2b2ed81ccad4ddd2bc9f0d22936c3f2 AS builder_base +FROM --platform=linux/amd64 golang:1.26.0-bookworm@sha256:c7a82e9e2df2fea5d8cb62a16aa6f796d2b2ed81ccad4ddd2bc9f0d22936c3f2 AS builder_base WORKDIR /w RUN apt update \ @@ -36,9 +36,9 @@ RUN make HOST=aarch64-apple-ios && make HOST=aarch64-apple-ios BOOST_VERSION=1_8 RUN make HOST=aarch64-apple-ios-simulator && make HOST=aarch64-apple-ios-simulator BOOST_VERSION=1_83_0 && make sbs-cleanup FROM builder_base AS monero_c_base -COPY . /w +COPY .git /w/.git RUN sudo chown -R user:user /w -RUN git submodule update --init --force --recursive \ +RUN git reset --hard && git submodule update --init --force --recursive \ && ./apply_patches.sh monero \ && ./apply_patches.sh wownero \ && ./apply_patches.sh zano diff --git a/contrib/depends/Makefile b/contrib/depends/Makefile index 9b26205..b41d245 100644 --- a/contrib/depends/Makefile +++ b/contrib/depends/Makefile @@ -3,8 +3,8 @@ HOST ?= BOOST_VERSION ?= 1_90_0 -PACKAGES = native/cmake,native/python@3.14,native/git,native/_,native/make,native/cmake-toolchain,icu4c,boost@$(BOOST_VERSION),zeromq,unbound,sodium,openssl,libiconv,zlib -SIMPLYBS_HASH = a37442738bc26fbe4e526f48694746b2efed2c2b +PACKAGES = native/protobuf,native/cmake,native/python@3.14,native/git,native/_,native/make,native/cmake-toolchain,protobuf,icu4c,boost@$(BOOST_VERSION),zeromq,unbound,sodium,openssl,libiconv,zlib +SIMPLYBS_HASH = 0ea74cb120b06156ce16118f86dc5b7d23a93c46 all: simplybs $(if $(HOST),sbs-build-$(HOST),) @if [ -z "$(HOST)" ]; then \ diff --git a/contrib/depends/gen_toolchain.cmake.sh b/contrib/depends/gen_toolchain.cmake.sh index 9ed2621..8af722e 100755 --- a/contrib/depends/gen_toolchain.cmake.sh +++ b/contrib/depends/gen_toolchain.cmake.sh @@ -155,7 +155,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") SET(LLVM_ENABLE_PIC OFF) SET(LLVM_ENABLE_PIE OFF) elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") - add_definitions(-DUSE_DEVICE_TREZOR=OFF) SET(ANDROID TRUE) if(ARCHITECTURE STREQUAL "armv7a") SET(CMAKE_ANDROID_ARCH_ABI "armeabi-v7a") @@ -181,7 +180,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") SET(CMAKE_C_COMPILER @CC@) SET(CMAKE_CXX_COMPILER @CXX@) elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") - set(USE_DEVICE_TREZOR OFF) add_definitions(-DUSE_DEVICE_LEDGER=ON) SET(CMAKE_C_COMPILER @CC@) SET(CMAKE_CXX_COMPILER @CXX@) diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart index ce19d4e..44bb8a9 100644 --- a/impls/monero.dart/lib/monero.dart +++ b/impls/monero.dart/lib/monero.dart @@ -72,6 +72,7 @@ library; // ignore_for_file: non_constant_identifier_names, camel_case_types import 'dart:ffi'; +import 'dart:html_common'; import 'dart:io'; import 'package:ffi/ffi.dart'; @@ -3515,91 +3516,96 @@ int MONERO_Wallet_getBytesSent(wallet ptr) { } @Deprecated("TODO") -bool Wallet_getStateIsConnected() { +bool Wallet_getStateIsConnected(int device) { debugStart?.call('MONERO_Wallet_getStateIsConnected'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getStateIsConnected(); + final ret = lib!.MONERO_Wallet_getStateIsConnected(device); debugEnd?.call('MONERO_Wallet_getStateIsConnected'); return ret; } @Deprecated("TODO") -Pointer<UnsignedChar> Wallet_getSendToDevice() { +Pointer<UnsignedChar> Wallet_getSendToDevice(int device) { debugStart?.call('MONERO_Wallet_getSendToDevice'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDevice(); + final ret = lib!.MONERO_Wallet_getSendToDevice(device); debugEnd?.call('MONERO_Wallet_getSendToDevice'); return ret; } @Deprecated("TODO") -int Wallet_getSendToDeviceLength() { +int Wallet_getSendToDeviceLength(int device) { debugStart?.call('MONERO_Wallet_getSendToDeviceLength'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDeviceLength(); + final ret = lib!.MONERO_Wallet_getSendToDeviceLength(device); debugEnd?.call('MONERO_Wallet_getSendToDeviceLength'); return ret; } @Deprecated("TODO") -Pointer<UnsignedChar> Wallet_getReceivedFromDevice() { +Pointer<UnsignedChar> Wallet_getReceivedFromDevice(int device) { debugStart?.call('MONERO_Wallet_getReceivedFromDevice'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDevice(); + final ret = lib!.MONERO_Wallet_getReceivedFromDevice(device); debugEnd?.call('MONERO_Wallet_getReceivedFromDevice'); return ret; } @Deprecated("TODO") -int Wallet_getReceivedFromDeviceLength() { +int Wallet_getReceivedFromDeviceLength(int device) { debugStart?.call('MONERO_Wallet_getReceivedFromDeviceLength'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(); + final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(device); debugEnd?.call('MONERO_Wallet_getReceivedFromDeviceLength'); return ret; } @Deprecated("TODO") -bool Wallet_getWaitsForDeviceSend() { +bool Wallet_getWaitsForDeviceSend(int device) { debugStart?.call('MONERO_Wallet_getWaitsForDeviceSend'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(); + final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(device); debugEnd?.call('MONERO_Wallet_getWaitsForDeviceSend'); return ret; } @Deprecated("TODO") -bool Wallet_getWaitsForDeviceReceive() { +bool Wallet_getWaitsForDeviceReceive(int device) { debugStart?.call('MONERO_Wallet_getWaitsForDeviceReceive'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(); + final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(device); debugEnd?.call('MONERO_Wallet_getWaitsForDeviceReceive'); return ret; } @Deprecated("TODO") -void Wallet_setDeviceReceivedData(Pointer<UnsignedChar> data, int len) { +void Wallet_setDeviceReceivedData(int device, Pointer<UnsignedChar> data, int len) { debugStart?.call('MONERO_Wallet_setDeviceReceivedData'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceReceivedData(data, len); + final ret = lib!.MONERO_Wallet_setDeviceReceivedData(device, data, len); debugEnd?.call('MONERO_Wallet_setDeviceReceivedData'); return ret; } @Deprecated("TODO") -void Wallet_setDeviceSendData(Pointer<UnsignedChar> data, int len) { +void Wallet_setDeviceSendData(int device, Pointer<UnsignedChar> data, int len) { debugStart?.call('MONERO_Wallet_setDeviceSendData'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceSendData(data, len); + final ret = lib!.MONERO_Wallet_setDeviceSendData(device, data, len); debugEnd?.call('MONERO_Wallet_setDeviceSendData'); return ret; } -@Deprecated("TODO") +@Deprecated("Use Wallet_setDeviceCallback(1, callback) instead") void Wallet_setLedgerCallback(Pointer<NativeFunction<Void Function(Pointer<UnsignedChar>, UnsignedInt)>> callback) { + return Wallet_setDeviceCallback(1, callback); +} + +@Deprecated("TODO") +void Wallet_setDeviceCallback(int device, Pointer<NativeFunction<Void Function(Pointer<UnsignedChar>, UnsignedInt)>> callback) { debugStart?.call('MONERO_Wallet_setDeviceSendData'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setLedgerCallback(callback); + final ret = lib!.MONERO_Wallet_setDeviceCallback(device, callback); debugEnd?.call('MONERO_Wallet_setDeviceSendData'); return ret; } 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 b757806..b348f8b 100644 --- a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart +++ b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart @@ -4351,83 +4351,114 @@ class MoneroC { late final _MONERO_Wallet_getBytesSent = _MONERO_Wallet_getBytesSentPtr .asFunction<int Function(ffi.Pointer<ffi.Void>)>(); - bool MONERO_Wallet_getStateIsConnected() { - return _MONERO_Wallet_getStateIsConnected(); + bool MONERO_Wallet_getStateIsConnected( + int device, + ) { + return _MONERO_Wallet_getStateIsConnected( + device, + ); } late final _MONERO_Wallet_getStateIsConnectedPtr = - _lookup<ffi.NativeFunction<ffi.Bool Function()>>( + _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Int)>>( 'MONERO_Wallet_getStateIsConnected'); late final _MONERO_Wallet_getStateIsConnected = - _MONERO_Wallet_getStateIsConnectedPtr.asFunction<bool Function()>(); + _MONERO_Wallet_getStateIsConnectedPtr.asFunction<bool Function(int)>(); - ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getSendToDevice() { - return _MONERO_Wallet_getSendToDevice(); + ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getSendToDevice( + int device, + ) { + return _MONERO_Wallet_getSendToDevice( + device, + ); } - late final _MONERO_Wallet_getSendToDevicePtr = - _lookup<ffi.NativeFunction<ffi.Pointer<ffi.UnsignedChar> Function()>>( - 'MONERO_Wallet_getSendToDevice'); + late final _MONERO_Wallet_getSendToDevicePtr = _lookup< + ffi.NativeFunction<ffi.Pointer<ffi.UnsignedChar> Function(ffi.Int)>>( + 'MONERO_Wallet_getSendToDevice'); late final _MONERO_Wallet_getSendToDevice = _MONERO_Wallet_getSendToDevicePtr - .asFunction<ffi.Pointer<ffi.UnsignedChar> Function()>(); + .asFunction<ffi.Pointer<ffi.UnsignedChar> Function(int)>(); - int MONERO_Wallet_getSendToDeviceLength() { - return _MONERO_Wallet_getSendToDeviceLength(); + int MONERO_Wallet_getSendToDeviceLength( + int device, + ) { + return _MONERO_Wallet_getSendToDeviceLength( + device, + ); } late final _MONERO_Wallet_getSendToDeviceLengthPtr = - _lookup<ffi.NativeFunction<ffi.Size Function()>>( + _lookup<ffi.NativeFunction<ffi.Size Function(ffi.Int)>>( 'MONERO_Wallet_getSendToDeviceLength'); late final _MONERO_Wallet_getSendToDeviceLength = - _MONERO_Wallet_getSendToDeviceLengthPtr.asFunction<int Function()>(); + _MONERO_Wallet_getSendToDeviceLengthPtr.asFunction<int Function(int)>(); - ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getReceivedFromDevice() { - return _MONERO_Wallet_getReceivedFromDevice(); + ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getReceivedFromDevice( + int device, + ) { + return _MONERO_Wallet_getReceivedFromDevice( + device, + ); } - late final _MONERO_Wallet_getReceivedFromDevicePtr = - _lookup<ffi.NativeFunction<ffi.Pointer<ffi.UnsignedChar> Function()>>( - 'MONERO_Wallet_getReceivedFromDevice'); + late final _MONERO_Wallet_getReceivedFromDevicePtr = _lookup< + ffi.NativeFunction<ffi.Pointer<ffi.UnsignedChar> Function(ffi.Int)>>( + 'MONERO_Wallet_getReceivedFromDevice'); late final _MONERO_Wallet_getReceivedFromDevice = _MONERO_Wallet_getReceivedFromDevicePtr.asFunction< - ffi.Pointer<ffi.UnsignedChar> Function()>(); + ffi.Pointer<ffi.UnsignedChar> Function(int)>(); - int MONERO_Wallet_getReceivedFromDeviceLength() { - return _MONERO_Wallet_getReceivedFromDeviceLength(); + int MONERO_Wallet_getReceivedFromDeviceLength( + int device, + ) { + return _MONERO_Wallet_getReceivedFromDeviceLength( + device, + ); } late final _MONERO_Wallet_getReceivedFromDeviceLengthPtr = - _lookup<ffi.NativeFunction<ffi.Size Function()>>( + _lookup<ffi.NativeFunction<ffi.Size Function(ffi.Int)>>( 'MONERO_Wallet_getReceivedFromDeviceLength'); late final _MONERO_Wallet_getReceivedFromDeviceLength = _MONERO_Wallet_getReceivedFromDeviceLengthPtr.asFunction< - int Function()>(); + int Function(int)>(); - bool MONERO_Wallet_getWaitsForDeviceSend() { - return _MONERO_Wallet_getWaitsForDeviceSend(); + bool MONERO_Wallet_getWaitsForDeviceSend( + int device, + ) { + return _MONERO_Wallet_getWaitsForDeviceSend( + device, + ); } late final _MONERO_Wallet_getWaitsForDeviceSendPtr = - _lookup<ffi.NativeFunction<ffi.Bool Function()>>( + _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Int)>>( 'MONERO_Wallet_getWaitsForDeviceSend'); late final _MONERO_Wallet_getWaitsForDeviceSend = - _MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction<bool Function()>(); + _MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction<bool Function(int)>(); - bool MONERO_Wallet_getWaitsForDeviceReceive() { - return _MONERO_Wallet_getWaitsForDeviceReceive(); + bool MONERO_Wallet_getWaitsForDeviceReceive( + int device, + ) { + return _MONERO_Wallet_getWaitsForDeviceReceive( + device, + ); } late final _MONERO_Wallet_getWaitsForDeviceReceivePtr = - _lookup<ffi.NativeFunction<ffi.Bool Function()>>( + _lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Int)>>( 'MONERO_Wallet_getWaitsForDeviceReceive'); late final _MONERO_Wallet_getWaitsForDeviceReceive = - _MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction<bool Function()>(); + _MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction< + bool Function(int)>(); void MONERO_Wallet_setDeviceReceivedData( + int device, ffi.Pointer<ffi.UnsignedChar> data, int len, ) { return _MONERO_Wallet_setDeviceReceivedData( + device, data, len, ); @@ -4435,17 +4466,19 @@ class MoneroC { late final _MONERO_Wallet_setDeviceReceivedDataPtr = _lookup< ffi.NativeFunction< - ffi.Void Function(ffi.Pointer<ffi.UnsignedChar>, + ffi.Void Function(ffi.Int, ffi.Pointer<ffi.UnsignedChar>, ffi.Size)>>('MONERO_Wallet_setDeviceReceivedData'); late final _MONERO_Wallet_setDeviceReceivedData = _MONERO_Wallet_setDeviceReceivedDataPtr.asFunction< - void Function(ffi.Pointer<ffi.UnsignedChar>, int)>(); + void Function(int, ffi.Pointer<ffi.UnsignedChar>, int)>(); void MONERO_Wallet_setDeviceSendData( + int device, ffi.Pointer<ffi.UnsignedChar> data, int len, ) { return _MONERO_Wallet_setDeviceSendData( + device, data, len, ); @@ -4453,36 +4486,40 @@ class MoneroC { late final _MONERO_Wallet_setDeviceSendDataPtr = _lookup< ffi.NativeFunction< - ffi.Void Function(ffi.Pointer<ffi.UnsignedChar>, + ffi.Void Function(ffi.Int, ffi.Pointer<ffi.UnsignedChar>, ffi.Size)>>('MONERO_Wallet_setDeviceSendData'); late final _MONERO_Wallet_setDeviceSendData = _MONERO_Wallet_setDeviceSendDataPtr.asFunction< - void Function(ffi.Pointer<ffi.UnsignedChar>, int)>(); + void Function(int, ffi.Pointer<ffi.UnsignedChar>, int)>(); - void MONERO_Wallet_setLedgerCallback( + void MONERO_Wallet_setDeviceCallback( + int device, ffi.Pointer< ffi.NativeFunction< ffi.Void Function(ffi.Pointer<ffi.UnsignedChar> command, ffi.UnsignedInt cmd_len)>> - sendToLedgerDevice, + sendToDeviceCallback, ) { - return _MONERO_Wallet_setLedgerCallback( - sendToLedgerDevice, + return _MONERO_Wallet_setDeviceCallback( + device, + sendToDeviceCallback, ); } - late final _MONERO_Wallet_setLedgerCallbackPtr = _lookup< + late final _MONERO_Wallet_setDeviceCallbackPtr = _lookup< ffi.NativeFunction< ffi.Void Function( + ffi.Int, ffi.Pointer< ffi.NativeFunction< ffi.Void Function( ffi.Pointer<ffi.UnsignedChar> command, ffi.UnsignedInt cmd_len)>>)>>( - 'MONERO_Wallet_setLedgerCallback'); - late final _MONERO_Wallet_setLedgerCallback = - _MONERO_Wallet_setLedgerCallbackPtr.asFunction< + 'MONERO_Wallet_setDeviceCallback'); + late final _MONERO_Wallet_setDeviceCallback = + _MONERO_Wallet_setDeviceCallbackPtr.asFunction< void Function( + int, ffi.Pointer< ffi.NativeFunction< ffi.Void Function(ffi.Pointer<ffi.UnsignedChar> command, diff --git a/impls/monero.dart/lib/src/monero.dart b/impls/monero.dart/lib/src/monero.dart index e142d6b..c4dc93d 100644 --- a/impls/monero.dart/lib/src/monero.dart +++ b/impls/monero.dart/lib/src/monero.dart @@ -1,6 +1,7 @@ // ignore_for_file: deprecated_member_use_from_same_package import 'dart:ffi'; +import 'dart:html_common'; import 'package:monero/monero.dart' as monero; import 'package:monero/src/wallet2.dart'; @@ -1033,12 +1034,12 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_getPolyseed(walletPtr, passphrase: passphrase); } - static Pointer<UnsignedChar> getReceivedFromDevice() { - return monero.Wallet_getReceivedFromDevice(); + static Pointer<UnsignedChar> getReceivedFromDevice(Wallet2Device device) { + return monero.Wallet_getReceivedFromDevice(device.index); } - static int getReceivedFromDeviceLength() { - return monero.Wallet_getReceivedFromDeviceLength(); + static int getReceivedFromDeviceLength(Wallet2Device device) { + return monero.Wallet_getReceivedFromDeviceLength(device.index); } @override @@ -1051,16 +1052,16 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_getSeedLanguage(walletPtr); } - static Pointer<UnsignedChar> getSendToDevice() { - return monero.Wallet_getSendToDevice(); + static Pointer<UnsignedChar> getSendToDevice(Wallet2Device device) { + return monero.Wallet_getSendToDevice(device.index); } - static int getSendToDeviceLength() { - return monero.Wallet_getSendToDeviceLength(); + static int getSendToDeviceLength(Wallet2Device device) { + return monero.Wallet_getSendToDeviceLength(device.index); } - static bool getStateIsConnected() { - return monero.Wallet_getStateIsConnected(); + static bool getStateIsConnected(Wallet2Device device) { + return monero.Wallet_getStateIsConnected(device.index); } @override @@ -1078,12 +1079,12 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_getUserNote(walletPtr, txid: txid); } - static bool getWaitsForDeviceReceive() { - return monero.Wallet_getWaitsForDeviceReceive(); + static bool getWaitsForDeviceReceive(Wallet2Device device) { + return monero.Wallet_getWaitsForDeviceReceive(device.index); } - static bool getWaitsForDeviceSend() { - return monero.Wallet_getWaitsForDeviceSend(); + static bool getWaitsForDeviceSend(Wallet2Device device) { + return monero.Wallet_getWaitsForDeviceSend(device.index); } @override @@ -1350,16 +1351,21 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_setDevicePin(walletPtr, passphrase: passphrase); } - static void setDeviceReceivedData(Pointer<UnsignedChar> data, int len) { - monero.Wallet_setDeviceReceivedData(data, len); + static void setDeviceReceivedData(Wallet2Device device, Pointer<UnsignedChar> data, int len) { + monero.Wallet_setDeviceReceivedData(device.index, data, len); } - static void setDeviceSendData(Pointer<UnsignedChar> data, int len) { - monero.Wallet_setDeviceSendData(data, len); + static void setDeviceSendData(Wallet2Device device, Pointer<UnsignedChar> data, int len) { + monero.Wallet_setDeviceSendData(device.index, data, len); } + @Deprecated("use setDeviceCallback(Wallet2Device.ledger, callback)") static void setLedgerCallback(Pointer<NativeFunction<Void Function(Pointer<UnsignedChar>, UnsignedInt)>> callback) { - monero.Wallet_setLedgerCallback(callback); + setDeviceCallback(Wallet2Device.ledger, callback); + } + + static void setDeviceCallback(Wallet2Device device, Pointer<NativeFunction<Void Function(Pointer<UnsignedChar>, UnsignedInt)>> callback) { + monero.Wallet_setDeviceCallback(device.index, callback); } @override diff --git a/impls/monero.dart/lib/src/wallet2.dart b/impls/monero.dart/lib/src/wallet2.dart index 8c41ffa..46be758 100644 --- a/impls/monero.dart/lib/src/wallet2.dart +++ b/impls/monero.dart/lib/src/wallet2.dart @@ -403,4 +403,10 @@ abstract class Wallet2WalletManagerFactory { void setLogLevel(int level); void setLogCategories(String categories); Wallet2WalletManager getWalletManager(); +} + +enum Wallet2Device { + software, + ledger, + trezor }
\ No newline at end of file diff --git a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp index 0c59e1a..2c014c1 100644 --- a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp +++ b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp @@ -122,7 +122,7 @@ _MONERO_MultisigState_total _MONERO_DeviceProgress_progress _MONERO_DeviceProgress_indeterminate _MONERO_Wallet_seed -_MONERO_Wallet_setLedgerCallback +_MONERO_Wallet_setDeviceCallback _MONERO_Wallet_serializeCacheToJson _MONERO_Wallet_getSeedLanguage _MONERO_Wallet_setSeedLanguage diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp index b9ff95f..73a4b8b 100644 --- a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.cpp @@ -2148,63 +2148,63 @@ uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr) { DEBUG_END() } -bool MONERO_Wallet_getStateIsConnected() { +bool MONERO_Wallet_getStateIsConnected(int device) { DEBUG_START() - return Monero::Wallet::getStateIsConnected(); + return Monero::Wallet::getStateIsConnected(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -unsigned char* MONERO_Wallet_getSendToDevice() { +unsigned char* MONERO_Wallet_getSendToDevice(int device) { DEBUG_START() - return Monero::Wallet::getSendToDevice(); + return Monero::Wallet::getSendToDevice(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -size_t MONERO_Wallet_getSendToDeviceLength() { +size_t MONERO_Wallet_getSendToDeviceLength(int device) { DEBUG_START() - return Monero::Wallet::getSendToDeviceLength(); + return Monero::Wallet::getSendToDeviceLength(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -unsigned char* MONERO_Wallet_getReceivedFromDevice() { +unsigned char* MONERO_Wallet_getReceivedFromDevice(int device) { DEBUG_START() - return Monero::Wallet::getReceivedFromDevice(); + return Monero::Wallet::getReceivedFromDevice(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -size_t MONERO_Wallet_getReceivedFromDeviceLength() { +size_t MONERO_Wallet_getReceivedFromDeviceLength(int device) { DEBUG_START() - return Monero::Wallet::getReceivedFromDeviceLength(); + return Monero::Wallet::getReceivedFromDeviceLength(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -bool MONERO_Wallet_getWaitsForDeviceSend() { +bool MONERO_Wallet_getWaitsForDeviceSend(int device) { DEBUG_START() - return Monero::Wallet::getWaitsForDeviceSend(); + return Monero::Wallet::getWaitsForDeviceSend(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -bool MONERO_Wallet_getWaitsForDeviceReceive() { +bool MONERO_Wallet_getWaitsForDeviceReceive(int device) { DEBUG_START() - return Monero::Wallet::getWaitsForDeviceReceive(); + return Monero::Wallet::getWaitsForDeviceReceive(static_cast<Monero::Wallet::Device>(device)); DEBUG_END() } -void MONERO_Wallet_setDeviceReceivedData(unsigned char* data, size_t len) { +void MONERO_Wallet_setDeviceReceivedData(int device, unsigned char* data, size_t len) { DEBUG_START() - Monero::Wallet::setDeviceReceivedData(data, len); + Monero::Wallet::setDeviceReceivedData(static_cast<Monero::Wallet::Device>(device), data, len); DEBUG_END() } -void MONERO_Wallet_setDeviceSendData(unsigned char* data, size_t len) { +void MONERO_Wallet_setDeviceSendData(int device, unsigned char* data, size_t len) { DEBUG_START() - Monero::Wallet::setDeviceSendData(data, len); + Monero::Wallet::setDeviceSendData(static_cast<Monero::Wallet::Device>(device), data, len); DEBUG_END() } -void MONERO_Wallet_setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { +void MONERO_Wallet_setDeviceCallback(int device, void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)) { DEBUG_START() - Monero::Wallet::setLedgerCallback(sendToLedgerDevice); + Monero::Wallet::setDeviceCallback(static_cast<Monero::Wallet::Device>(device), sendToDeviceCallback); DEBUG_END() } diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h index 39bca89..ad9c486 100644 --- a/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h +++ b/monero_libwallet2_api_c/src/main/cpp/monero_wallet2_api_c.h @@ -837,16 +837,16 @@ 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(); -extern ADDAPI unsigned char* MONERO_Wallet_getSendToDevice(); -extern ADDAPI size_t MONERO_Wallet_getSendToDeviceLength(); -extern ADDAPI unsigned char* MONERO_Wallet_getReceivedFromDevice(); -extern ADDAPI size_t MONERO_Wallet_getReceivedFromDeviceLength(); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceSend(); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceReceive(); -extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(unsigned char* data, size_t len); -extern ADDAPI void MONERO_Wallet_setDeviceSendData(unsigned char* data, size_t len); -extern ADDAPI void MONERO_Wallet_setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); +extern ADDAPI bool MONERO_Wallet_getStateIsConnected(int device); +extern ADDAPI unsigned char* MONERO_Wallet_getSendToDevice(int device); +extern ADDAPI size_t MONERO_Wallet_getSendToDeviceLength(int device); +extern ADDAPI unsigned char* MONERO_Wallet_getReceivedFromDevice(int device); +extern ADDAPI size_t MONERO_Wallet_getReceivedFromDeviceLength(int device); +extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceSend(int device); +extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceReceive(int device); +extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(int device, unsigned char* data, size_t len); +extern ADDAPI void MONERO_Wallet_setDeviceSendData(int device, unsigned char* data, size_t len); +extern ADDAPI void MONERO_Wallet_setDeviceCallback(int device, void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)); extern ADDAPI const char* MONERO_Wallet_serializeCacheToJson(void* wallet_ptr); // }; diff --git a/patches/monero/0021-add-dummy-device-for-Trezor.patch b/patches/monero/0021-add-dummy-device-for-Trezor.patch new file mode 100644 index 0000000..9205a9f --- /dev/null +++ b/patches/monero/0021-add-dummy-device-for-Trezor.patch @@ -0,0 +1,596 @@ +From 32f25991193d88f07109ed0416ccd1cead078550 Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto <cyjan@mrcyjanek.net> +Date: Wed, 6 May 2026 13:45:34 -0400 +Subject: [PATCH] add dummy device for Trezor + +--- + src/device/device_io_dummy.cpp | 6 +- + src/device/device_io_dummy.hpp | 2 +- + src/device_trezor/trezor/transport.cpp | 178 ++++++++++++++++++++++++- + src/device_trezor/trezor/transport.hpp | 51 +++++++ + src/wallet/api/wallet.cpp | 127 ++++++++++++++---- + src/wallet/api/wallet.h | 14 +- + src/wallet/api/wallet2_api.h | 21 ++- + 7 files changed, 351 insertions(+), 48 deletions(-) + +diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp +index 74742150d..6365bb427 100644 +--- a/src/device/device_io_dummy.cpp ++++ b/src/device/device_io_dummy.cpp +@@ -138,9 +138,9 @@ namespace hw { + MDEBUG("release()"); + } + +- void device_io_dummy::setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { +- MDEBUG("setLedgerCallback()"); +- sendToLedgerDeviceCallback = sendToLedgerDevice; ++ void device_io_dummy::setDeviceCallback(void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)) { ++ MDEBUG("setDeviceCallback()"); ++ sendToLedgerDeviceCallback = sendToDeviceCallback; + } + + void device_io_dummy::setDeviceReceivedData(unsigned char* data, size_t len) { +diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp +index 87a5f109f..80b356a0b 100644 +--- a/src/device/device_io_dummy.hpp ++++ b/src/device/device_io_dummy.hpp +@@ -73,7 +73,7 @@ namespace hw { + + int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); + +- static void setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); ++ static void setDeviceCallback(void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)); + static void setDeviceReceivedData(unsigned char* data, size_t len); + }; + }; +diff --git a/src/device_trezor/trezor/transport.cpp b/src/device_trezor/trezor/transport.cpp +index 10dd82c53..5cf7e1cb8 100644 +--- a/src/device_trezor/trezor/transport.cpp ++++ b/src/device_trezor/trezor/transport.cpp +@@ -27,6 +27,7 @@ + // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + // + ++#include "exceptions.hpp" + #ifdef WITH_DEVICE_TREZOR_WEBUSB + #include <libusb.h> + #endif +@@ -1166,8 +1167,177 @@ namespace trezor{ + return o << ">"; + }; + +-#endif // WITH_DEVICE_TREZOR_WEBUSB ++#endif // WITH_DEVICE_TREZOR_WEBUSB + ++ ++std::condition_variable hw::trezor::DummyTransport::cv_send; ++std::condition_variable hw::trezor::DummyTransport::cv_receive; ++bool hw::trezor::DummyTransport::stateIsConnected = false; ++unsigned char* hw::trezor::DummyTransport::sendToDevice = {}; ++size_t hw::trezor::DummyTransport::sendToDeviceLength = 0; ++unsigned char* hw::trezor::DummyTransport::receivedFromDevice = {}; ++size_t hw::trezor::DummyTransport::receivedFromDeviceLength = 0; ++bool hw::trezor::DummyTransport::waitsForDeviceSend = false; ++bool hw::trezor::DummyTransport::waitsForDeviceReceive = false; ++void (*hw::trezor::DummyTransport::sendToTrezorDeviceCallback)(unsigned char *command, unsigned int cmd_len) = nullptr; ++std::mutex hw::trezor::DummyTransport::mutex; ++ ++const char * DummyTransport::PATH_PREFIX = "dummy:"; ++ ++DummyTransport::DummyTransport( ++ boost::optional<std::shared_ptr<Protocol>> proto ++) ++{ ++ m_proto = proto ? proto.get() : std::make_shared<ProtocolV1>(); ++} ++ ++DummyTransport::~DummyTransport(){ ++ close(); ++} ++ ++std::shared_ptr<Transport> DummyTransport::find_debug() { ++ return nullptr; ++} ++ ++void DummyTransport::require_device() const{ ++ if (!stateIsConnected){ ++ throw std::runtime_error("stateIsConnected is false"); ++ } ++} ++ ++void DummyTransport::require_connected() const{ ++ require_device(); ++} ++ ++void DummyTransport::enumerate(t_transport_vect & res) { ++ auto t = std::make_shared<DummyTransport>(); ++ res.push_back(t); ++} ++ ++std::string DummyTransport::get_path() const { ++ std::stringstream ss; ++ ss << DummyTransport::PATH_PREFIX << "dummy"; ++ return ss.str(); ++}; ++ ++void DummyTransport::open() { ++ if (sendToTrezorDeviceCallback == nullptr) { ++ throw exc::TrezorException("sendToTrezorDeviceCallback is null"); ++ } ++ stateIsConnected = true; ++ m_proto->session_begin(*this); ++} ++ ++void DummyTransport::close() { ++ stateIsConnected = false; ++}; ++ ++int DummyTransport::get_interface() const{ ++ const int INTERFACE_NORMAL = 0; ++#ifdef WITH_TREZOR_DEBUGGING ++ const int INTERFACE_DEBUG = 1; ++ return m_debug_mode ? INTERFACE_DEBUG : INTERFACE_NORMAL; ++#else ++ return INTERFACE_NORMAL; ++#endif ++} ++ ++unsigned char DummyTransport::get_endpoint() const{ ++ const unsigned char ENDPOINT_NORMAL = 1; ++#ifdef WITH_TREZOR_DEBUGGING ++ const unsigned char ENDPOINT_DEBUG = 2; ++ return m_debug_mode ? ENDPOINT_DEBUG : ENDPOINT_NORMAL; ++#else ++ return ENDPOINT_NORMAL; ++#endif ++} ++ ++void DummyTransport::write(const google::protobuf::Message &req) { ++ m_proto->write(*this, req); ++}; ++ ++void DummyTransport::read(std::shared_ptr<google::protobuf::Message> & msg, messages::MessageType * msg_type) { ++ m_proto->read(*this, msg, msg_type); ++}; ++ ++void DummyTransport::write_chunk(const void * buff, size_t size) { ++ require_connected(); ++ if (size != REPLEN){ ++ throw exc::CommunicationException("Invalid chunk size: "); ++ } ++ ++ MDEBUG("write_chunk(): locking mutex"); ++ std::unique_lock<std::mutex> lock(mutex); ++ ++ sendToDevice = const_cast<unsigned char*>(static_cast<const unsigned char*>(buff)); ++ sendToDeviceLength = size; ++ waitsForDeviceSend = true; ++ waitsForDeviceReceive = true; ++ ++ if (sendToTrezorDeviceCallback != nullptr) { ++ MDEBUG("write_chunk(): calling sendToTrezorDeviceCallback"); ++ sendToTrezorDeviceCallback( ++ const_cast<unsigned char*>(static_cast<const unsigned char*>(buff)), ++ static_cast<unsigned int>(size) ++ ); ++ } ++ ++ while (waitsForDeviceSend) { ++ cv_send.wait(lock); ++ MDEBUG("write_chunk(): waitsForDeviceSend notified"); ++ } ++} ++ ++size_t DummyTransport::read_chunk(void * buff, size_t size) { ++ require_connected(); ++ MDEBUG("read_chunk(): locking mutex"); ++ std::unique_lock<std::mutex> lock(mutex); ++ ++ while (waitsForDeviceReceive) { ++ cv_receive.wait(lock); ++ MDEBUG("read_chunk(): waitsForDeviceReceive notified"); ++ } ++ ++ if (receivedFromDeviceLength > size) { ++ MDEBUG("read_chunk(): receivedFromDeviceLength (" ++ << receivedFromDeviceLength << ") > buffer size (" << size << ")"); ++ throw exc::CommunicationException("Response chunk too large for buffer"); ++ } ++ ++ memset(buff, 0, size); ++ memcpy(buff, receivedFromDevice, receivedFromDeviceLength); ++ ++ waitsForDeviceReceive = true; ++ ++ return receivedFromDeviceLength; ++} ++ ++std::ostream& DummyTransport::dump(std::ostream& o) const { ++ o << "DummyTransport<path=" << get_path(); ++ return o << ">"; ++}; ++ ++ ++void DummyTransport::setDeviceCallback(void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)) { ++ MDEBUG("setDeviceCallback()"); ++ sendToTrezorDeviceCallback = sendToDeviceCallback; ++} ++ ++void DummyTransport::setDeviceReceivedData(unsigned char* data, size_t len) { ++ MDEBUG("setDeviceReceivedData(len: " << len << ")"); ++ std::unique_lock<std::mutex> lock(mutex); ++ ++ receivedFromDevice = static_cast<unsigned char *>(malloc(len)); ++ receivedFromDeviceLength = len; ++ memset(receivedFromDevice, 0, len); ++ memcpy(receivedFromDevice, data, len); ++ waitsForDeviceReceive = false; ++ waitsForDeviceSend = false; ++ cv_send.notify_all(); ++ cv_receive.notify_all(); ++} ++ ++ + void enumerate(t_transport_vect & res){ + BridgeTransport bt; + try{ +@@ -1193,6 +1363,12 @@ namespace trezor{ + MERROR("UdpTransport enumeration failed:" << e.what()); + } + #endif ++ hw::trezor::DummyTransport dt; ++ try{ ++ dt.enumerate(res); ++ } catch (const std::exception & e){ ++ MERROR("DummyTransport enumeration failed:" << e.what()); ++ } + } + + void sort_transports_by_env(t_transport_vect & res){ +diff --git a/src/device_trezor/trezor/transport.hpp b/src/device_trezor/trezor/transport.hpp +index 827b189fd..f1036383b 100644 +--- a/src/device_trezor/trezor/transport.hpp ++++ b/src/device_trezor/trezor/transport.hpp +@@ -302,6 +302,57 @@ namespace trezor { + + #endif + ++class DummyTransport : public Transport { ++public: ++ ++ explicit DummyTransport( ++ boost::optional<std::shared_ptr<Protocol>> proto = boost::none ++ ); ++ ++ virtual ~DummyTransport(); ++ ++ static const char * PATH_PREFIX; ++ ++ std::string get_path() const override; ++ void enumerate(t_transport_vect & res) override; ++ ++ void open() override; ++ void close() override; ++ std::shared_ptr<Transport> find_debug() override; ++ ++ void write(const google::protobuf::Message &req) override; ++ void read(std::shared_ptr<google::protobuf::Message> & msg, messages::MessageType * msg_type=nullptr) override; ++ ++ void write_chunk(const void * buff, size_t size) override; ++ size_t read_chunk(void * buff, size_t size) override; ++ ++ std::ostream& dump(std::ostream& o) const override; ++ static std::mutex mutex; ++ static void setDeviceReceivedData(unsigned char* data, size_t len); ++ static void setDeviceCallback(void (*sendToDeviceCallback)(unsigned char *command, unsigned int cmd_len)); ++ static std::condition_variable cv_send; ++ static std::condition_variable cv_receive; ++ 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 void (*sendToTrezorDeviceCallback)(unsigned char *command, unsigned int cmd_len); ++private: ++ void require_device() const; ++ void require_connected() const; ++ int get_interface() const; ++ unsigned char get_endpoint() const; ++ ++ std::shared_ptr<Protocol> m_proto; ++ ++#ifdef WITH_TREZOR_DEBUGGING ++ bool m_debug_mode; ++#endif ++}; ++ + // + // General helpers + // +diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp +index c24b4a97d..4cb37a4a6 100644 +--- a/src/wallet/api/wallet.cpp ++++ b/src/wallet/api/wallet.cpp +@@ -42,6 +42,7 @@ + + #include "mnemonics/electrum-words.h" + #include "mnemonics/english.h" ++#include "wallet2_api.h" + #include <boost/format.hpp> + #include <sstream> + #include <unordered_map> +@@ -53,6 +54,7 @@ + #include "bc-ur/src/bc-ur.hpp" + #if defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI) + #include "device/device_io_dummy.hpp" ++#include "device_trezor/trezor/transport.hpp" + #endif + + using namespace std; +@@ -3379,98 +3381,173 @@ uint64_t WalletImpl::getBytesSent() + + + // HIDAPI_DUMMY +-bool Wallet::getStateIsConnected() { ++bool Wallet::getStateIsConnected(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else +- return hw::io::device_io_dummy::stateIsConnected; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::stateIsConnected; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::stateIsConnected; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-unsigned char* Wallet::getSendToDevice() { ++unsigned char* Wallet::getSendToDevice(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return {}; + #else +- return hw::io::device_io_dummy::sendToDevice; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::sendToDevice; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::sendToDevice; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-size_t Wallet::getSendToDeviceLength() { ++size_t Wallet::getSendToDeviceLength(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return -1; + #else +- return hw::io::device_io_dummy::sendToDeviceLength; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::sendToDeviceLength; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::sendToDeviceLength; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-unsigned char* Wallet::getReceivedFromDevice() { ++unsigned char* Wallet::getReceivedFromDevice(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return {}; + #else +- return hw::io::device_io_dummy::receivedFromDevice; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::receivedFromDevice; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::receivedFromDevice; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-size_t Wallet::getReceivedFromDeviceLength() { ++size_t Wallet::getReceivedFromDeviceLength(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return -1; + #else +- return hw::io::device_io_dummy::receivedFromDeviceLength; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::receivedFromDeviceLength; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::receivedFromDeviceLength; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-bool Wallet::getWaitsForDeviceSend() { ++bool Wallet::getWaitsForDeviceSend(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else +- return hw::io::device_io_dummy::waitsForDeviceSend; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::waitsForDeviceSend; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::waitsForDeviceSend; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-bool Wallet::getWaitsForDeviceReceive() { ++bool Wallet::getWaitsForDeviceReceive(Device device) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else +- return hw::io::device_io_dummy::waitsForDeviceReceive; ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ return hw::io::device_io_dummy::waitsForDeviceReceive; ++ case Monero::Wallet::Device_Trezor: ++ return hw::trezor::DummyTransport::waitsForDeviceReceive; ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-void Wallet::setDeviceReceivedData(unsigned char* data, size_t len) { ++void Wallet::setDeviceReceivedData(Device device, unsigned char* data, size_t len) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return; + #else +- hw::io::device_io_dummy::setDeviceReceivedData(data, len); ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ hw::io::device_io_dummy::setDeviceReceivedData(data, len); ++ case Monero::Wallet::Device_Trezor: ++ hw::trezor::DummyTransport::setDeviceReceivedData(data, len); ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-void Wallet::setDeviceSendData(unsigned char* data, size_t len) { ++void Wallet::setDeviceSendData(Device device, unsigned char* data, size_t len) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return; + #else +- hw::io::device_io_dummy::sendToDevice = static_cast<unsigned char *>(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::cv_send.notify_all(); ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ hw::io::device_io_dummy::sendToDevice = static_cast<unsigned char *>(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::cv_send.notify_all(); ++ case Monero::Wallet::Device_Trezor: ++ hw::trezor::DummyTransport::sendToDevice = static_cast<unsigned char *>(malloc(len)); ++ hw::trezor::DummyTransport::sendToDeviceLength = len; ++ memset(hw::trezor::DummyTransport::sendToDevice, 0, len); ++ memcpy(hw::trezor::DummyTransport::sendToDevice, data, len); ++ hw::trezor::DummyTransport::waitsForDeviceSend = false; ++ hw::trezor::DummyTransport::cv_send.notify_all(); ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +-void Wallet::setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { ++void Wallet::setDeviceCallback(Monero::Wallet::Device device, void (*sendToDevice)(unsigned char *command, unsigned int cmd_len)) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) + MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return; + #else +- hw::io::device_io_dummy::setLedgerCallback(sendToLedgerDevice); ++ switch (device) { ++ case Monero::Wallet::Device_Ledger: ++ hw::io::device_io_dummy::setDeviceCallback(sendToDevice); ++ case Monero::Wallet::Device_Trezor: ++ hw::trezor::DummyTransport::setDeviceCallback(sendToDevice); ++ default: ++ throw std::runtime_error("unknown device type"); ++ } + #endif + } + +diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h +index 98c03b9c1..2a29c07b3 100644 +--- a/src/wallet/api/wallet.h ++++ b/src/wallet/api/wallet.h +@@ -322,19 +322,19 @@ private: + mutable std::atomic<bool> m_is_connected; + boost::optional<epee::net_utils::http::login> m_daemon_login{}; + +- bool getStateIsConnected(); ++ bool getStateIsConnected(Device device); + +- unsigned char *getSendToDevice(); ++ unsigned char *getSendToDevice(Device device); + +- size_t getSendToDeviceLength(); ++ size_t getSendToDeviceLength(Device device); + +- unsigned char *getReceivedFromDevice(); ++ unsigned char *getReceivedFromDevice(Device device); + +- size_t getReceivedFromDeviceLength(); ++ size_t getReceivedFromDeviceLength(Device device); + +- bool getWaitsForDeviceSend(); ++ bool getWaitsForDeviceSend(Device device); + +- bool getWaitsForDeviceReceive(); ++ bool getWaitsForDeviceReceive(Device device); + + virtual std::string serializeCacheToJson() const override; + }; +diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h +index 3d11929f9..61756a127 100644 +--- a/src/wallet/api/wallet2_api.h ++++ b/src/wallet/api/wallet2_api.h +@@ -1206,17 +1206,16 @@ struct Wallet + virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY +- static bool getStateIsConnected(); +- static unsigned char* getSendToDevice(); +- static size_t getSendToDeviceLength(); +- static unsigned char* getReceivedFromDevice(); +- static size_t getReceivedFromDeviceLength(); +- static bool getWaitsForDeviceSend(); +- static bool getWaitsForDeviceReceive(); +- +- static void setDeviceReceivedData(unsigned char* data, size_t len); +- static void setDeviceSendData(unsigned char* data, size_t len); +- static void setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); ++ static bool getStateIsConnected(Device device); ++ static unsigned char* getSendToDevice(Device device); ++ static size_t getSendToDeviceLength(Device device); ++ static unsigned char* getReceivedFromDevice(Device device); ++ static size_t getReceivedFromDeviceLength(Device device); ++ static bool getWaitsForDeviceSend(Device device); ++ static bool getWaitsForDeviceReceive(Device device); ++ static void setDeviceReceivedData(Device device, unsigned char* data, size_t len); ++ static void setDeviceSendData(Device device, unsigned char* data, size_t len); ++ static void setDeviceCallback(Device device, void (*sendToDevice)(unsigned char *command, unsigned int cmd_len)); + + //! serialize wallet cache to JSON + virtual std::string serializeCacheToJson() const = 0; +-- +2.50.1 (Apple Git-155) + |
