From 8e62984a28768c80c0a2fce08f522d632653ecbe Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 18 Jan 2024 17:22:47 -0600 Subject: [PATCH 01/35] add apple docs --- docs/building.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index e7128df2e..915f9c7d4 100644 --- a/docs/building.md +++ b/docs/building.md @@ -9,7 +9,7 @@ Here you will find instructions on how to install the necessary tools for buildi - 100 GB of storage ## Linux host -The following instructions are for building and running on a Linux host. Alternatively, see the [Windows](#Windows host) section. +The following instructions are for building and running on a Linux host. Alternatively, see the [Mac](#mac-host) and/or [Windows](#windows-host) section. ### Android Studio Install Android Studio. Follow instructions here [https://developer.android.com/studio/install#linux](https://developer.android.com/studio/install#linux) or install via snap: @@ -44,6 +44,7 @@ Install [Rust](https://www.rust-lang.org/tools/install) with command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.bashrc rustup install 1.67.1 +rustup install 1.72.0 rustup default 1.67.1 ``` @@ -129,6 +130,44 @@ flutter pub get flutter run linux ``` +## Mac host + +### Dependencies +XCode, Homebrew and several homebrew packages, Rust, and Flutter are required for Mac development with the Flutter SDK. Multiple IDEs may work, but Android Studio is recommended. + +Download and install Xcode at https://developer.apple.com/xcode/, register your device (Mac or iPhone), and enable developer mode for your device as applicable. + +Download and install [Homebrew](https://brew.sh/). The following command can install it via script: +``` +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +``` + +After installing Homebrew, install the following packages: +``` +brew install cocoapods git cmake autoconf fontconfig libpng lz4 pkg-config automake freetype libssh2 lzo procs berkeley-db gdbm libtool m4 rtmpdump brotli gettext libunistring make rustup-init ca-certificates git-gui libx11 openldap tcl-tk cairo glib libxau openssl@1.1 unbound cbindgen gmp libxcb openssl@3 unzip cmake libevent libxdmcp pcre2 xorgproto coreutils libidn2 libxext perl xz curl libnghttp2 libxrender pixman zstd +``` + +Download and install [Rust](https://www.rust-lang.org/tools/install). [Rustup](https://rustup.rs/) is recommended for Rust setup. Use `rustc` to confirm successful installation. Install toolchains 1.67.1 and 1.72.0 and `cbindgen` and `cargo-lipo` too. You will also have to add the platform targets `aarch64-apple-ios` and/or `aarch64-apple-darwin`. You can use the command(s): +``` +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source ~/.bashrc +rustup install 1.67.1 +rustup install 1.72.0 +rustup default 1.67.1 +cargo install cbindgen cargo-lipo +rustup target add aarch64-apple-ios aarch64-apple-darwin +``` + +Download and install [Flutter](https://docs.flutter.dev/get-started/install). Versions 3.16.8 and 3.10.6 should both work. Use `flutter doctor` to confirm successful installation. + +Download [Android Studio](https://developer.android.com/studio). VS Code may work as an alternative, but this is not recommended. + +### Building libraries + +### Install Flutter on Mac host +Install Flutter 3.10.3 on your Mac host by following these instructions: https://docs.flutter.dev/get-started/install/macos. Run `flutter doctor` in PowerShell to confirm its installation. + + ## Windows host ### Visual Studio Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++" workload, including all of its default components. From cd425d50c417d8e8683dd6bc9c6cbdd71d4a4756 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 18 Jan 2024 17:48:53 -0600 Subject: [PATCH 02/35] add xcode commandline tools note --- docs/building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index 915f9c7d4..c7fc198c4 100644 --- a/docs/building.md +++ b/docs/building.md @@ -135,7 +135,7 @@ flutter run linux ### Dependencies XCode, Homebrew and several homebrew packages, Rust, and Flutter are required for Mac development with the Flutter SDK. Multiple IDEs may work, but Android Studio is recommended. -Download and install Xcode at https://developer.apple.com/xcode/, register your device (Mac or iPhone), and enable developer mode for your device as applicable. +Download and install Xcode at https://developer.apple.com/xcode/, register your device (Mac or iPhone), and enable developer mode for your device as applicable. After installing XCode, make sure commandline tools are installed with `xcode-select --install`. Download and install [Homebrew](https://brew.sh/). The following command can install it via script: ``` From 00bc8d02f9a5d9bd408982e83d3c4b32b54564e7 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 18 Jan 2024 17:52:52 -0600 Subject: [PATCH 03/35] small final docs corrections for the day --- docs/building.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index c7fc198c4..977f08161 100644 --- a/docs/building.md +++ b/docs/building.md @@ -147,7 +147,7 @@ After installing Homebrew, install the following packages: brew install cocoapods git cmake autoconf fontconfig libpng lz4 pkg-config automake freetype libssh2 lzo procs berkeley-db gdbm libtool m4 rtmpdump brotli gettext libunistring make rustup-init ca-certificates git-gui libx11 openldap tcl-tk cairo glib libxau openssl@1.1 unbound cbindgen gmp libxcb openssl@3 unzip cmake libevent libxdmcp pcre2 xorgproto coreutils libidn2 libxext perl xz curl libnghttp2 libxrender pixman zstd ``` -Download and install [Rust](https://www.rust-lang.org/tools/install). [Rustup](https://rustup.rs/) is recommended for Rust setup. Use `rustc` to confirm successful installation. Install toolchains 1.67.1 and 1.72.0 and `cbindgen` and `cargo-lipo` too. You will also have to add the platform targets `aarch64-apple-ios` and/or `aarch64-apple-darwin`. You can use the command(s): +Download and install [Rust](https://www.rust-lang.org/tools/install). [Rustup](https://rustup.rs/) is recommended for Rust setup. Use `rustc` to confirm successful installation. Install toolchains 1.67.1 and 1.72.0 and `cbindgen` and `cargo-lipo` too. You will also have to add the platform target(s) `aarch64-apple-ios` and/or `aarch64-apple-darwin`. You can use the command(s): ``` curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.bashrc @@ -163,10 +163,10 @@ Download and install [Flutter](https://docs.flutter.dev/get-started/install). V Download [Android Studio](https://developer.android.com/studio). VS Code may work as an alternative, but this is not recommended. ### Building libraries +TODO ### Install Flutter on Mac host -Install Flutter 3.10.3 on your Mac host by following these instructions: https://docs.flutter.dev/get-started/install/macos. Run `flutter doctor` in PowerShell to confirm its installation. - +Install Flutter 3.16.8 on your Mac host by following these instructions: https://docs.flutter.dev/get-started/install/macos. Run `flutter doctor` in a terminal to confirm its installation. ## Windows host ### Visual Studio From d2841121202128d4300054d28a175e104675d1cb Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 7 Mar 2024 21:20:59 -0600 Subject: [PATCH 04/35] Windows (and Rust in general) docs updates --- docs/building.md | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/building.md b/docs/building.md index e7128df2e..cf02f5219 100644 --- a/docs/building.md +++ b/docs/building.md @@ -9,7 +9,7 @@ Here you will find instructions on how to install the necessary tools for buildi - 100 GB of storage ## Linux host -The following instructions are for building and running on a Linux host. Alternatively, see the [Windows](#Windows host) section. +The following instructions are for building and running on a Linux host. Alternatively, see the [Windows](#Windows-host) section. ### Android Studio Install Android Studio. Follow instructions here [https://developer.android.com/studio/install#linux](https://developer.android.com/studio/install#linux) or install via snap: @@ -29,6 +29,8 @@ Then in `File > Settings > Plugins`, install the **Flutter** and **Dart** plugin Make a Pixel 4 (API 30) x86_64 emulator with 2GB of storage space for emulation +### Build dependencies + Install basic dependencies ``` sudo apt-get install libssl-dev curl unzip automake build-essential file pkg-config git python libtool libtinfo5 cmake libgit2-dev clang libncurses5-dev libncursesw5-dev zlib1g-dev llvm python3-distutils @@ -43,19 +45,22 @@ Install [Rust](https://www.rust-lang.org/tools/install) with command: ``` curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.bashrc -rustup install 1.67.1 +rustup install 1.72.0 # For tor. +rustup install 1.67.1 # For flutter_libepiccash. rustup default 1.67.1 ``` Install the additional components for Rust: ``` -cargo install cargo-ndk --version 2.12.7 +cargo install cargo-ndk --version 2.12.7 --locked ``` + Android specific dependencies: ``` sudo apt-get install libc6-dev-i386 rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android ``` + Linux desktop specific dependencies: ``` sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev meson python3-pip libgirepository1.0-dev valac xsltproc docbook-xsl @@ -67,9 +72,11 @@ After installing the prerequisites listed above, download the code and init the git clone https://github.com/cypherstack/stack_wallet.git cd stack_wallet git submodule update --init --recursive - ``` +### Remove system packages (may be needed for building flutter_libmonero) +[`flutter_libmonero`](https://github.com/cypherstack/flutter_libmonero) may have issues building due to conflicts with system packages: if so, follow this section. + Remove pre-installed system libraries for the following packages built by cryptography plugins in the crypto_plugins folder: `boost iconv libjson-dev libsecret openssl sodium unbound zmq`. You can use ``` sudo apt list --installed | grep boost @@ -134,12 +141,7 @@ flutter run linux Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++" workload, including all of its default components. ### Building libraries in WSL2 -Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. You will also need to install Rust and MXE dependencies on the WSL2 Ubuntu 20.04 host: - - [Install Rust](https://rustup.rs/) - ```sh - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - ``` - - Install MXE by running `stack_wallet/scripts/windows/deps.sh` +Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. You will also need to install MXE on the WSL2 Ubuntu 20.04 host by running `stack_wallet/scripts/windows/deps.sh` ```sh ./stack_wallet/scripts/windows/deps.sh ``` @@ -158,10 +160,23 @@ Copy the resulting `dll`s to their respective positions on the Windows host: --> -### Install Flutter on Windows host +### Flutter Install Flutter 3.10.3 on your Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows or by running `scripts/windows/deps.ps1`. You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1`. Run `flutter doctor` in PowerShell to confirm its installation. -### Dependencies +### Rust +Install [Rust](https://www.rust-lang.org/tools/install) via `rustup`. Make sure it works and install the following versions: +``` +rustup install 1.72.0 # For tor. +rustup install 1.67.1 # For flutter_libepiccash. +rustup default 1.67.1 +``` + +Also install `cargo-ndk`: +``` +cargo install cargo-ndk --version 2.12.7 --locked +``` + +### Windows SDK and Developer Mode Install the Windows SDK: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ You may need to install the [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/), which can be installed [by Visual Studio](https://stackoverflow.com/a/73923899) (`Tools > Get Tools and Features... > Modify > Individual Components > Windows 10 SDK`). Enable Developer Mode for symlink support, From 05080ea80ac551cab7e35b6c96ca19a60e1f6a60 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 7 Mar 2024 21:38:17 -0600 Subject: [PATCH 05/35] add coinlib, VS, gtk, and flutter 3.16.0 notes --- docs/building.md | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/building.md b/docs/building.md index cf02f5219..7685abdbf 100644 --- a/docs/building.md +++ b/docs/building.md @@ -119,6 +119,12 @@ cd scripts/windows ./build_all.sh ``` +### Build coinlib +Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be built from within the root `stack_wallet` folder on a... + - Linux host for Linux targets: `dart run coinlib:build_linux`, or + - Linux host for Windows targets: `dart run coinlib:build_windows_crosscompile` + + ### Running #### Android Plug in your android device or use the emulator available via Android Studio and then run the following commands: @@ -138,13 +144,20 @@ flutter run linux ## Windows host ### Visual Studio -Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++" workload, including all of its default components. +Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++" and "Linux development with C++" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version. ### Building libraries in WSL2 -Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. You will also need to install MXE on the WSL2 Ubuntu 20.04 host by running `stack_wallet/scripts/windows/deps.sh` - ```sh - ./stack_wallet/scripts/windows/deps.sh - ``` +Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. + +Install the following libraries: +``` +sudo apt-get install libgtk2.0-dev +``` + +You will also need to install MXE on the WSL2 Ubuntu 20.04 host and can do so by running `stack_wallet/scripts/windows/deps.sh`: +``` +./stack_wallet/scripts/windows/deps.sh +``` The WSL2 host may optionally be navigated to the `stack_wallet` repository on the Windows host in order to build the plugins in-place and skip the next section in which you copy the `dll`s from WSL2 to Windows. Then build windows `dll` libraries by running the following script on the WSL2 Ubuntu 20.04 host: @@ -161,10 +174,10 @@ Copy the resulting `dll`s to their respective positions on the Windows host: ### Flutter -Install Flutter 3.10.3 on your Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows or by running `scripts/windows/deps.ps1`. You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1`. Run `flutter doctor` in PowerShell to confirm its installation. +Install Flutter 3.16.0 on the Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows or by running `scripts/windows/deps.ps1`. You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1` (you may need to open a new terminal). Run `flutter doctor` in PowerShell to confirm its installation. ### Rust -Install [Rust](https://www.rust-lang.org/tools/install) via `rustup`. Make sure it works and install the following versions: +Install [Rust](https://www.rust-lang.org/tools/install) on the Windows host (not in WSL2). Download the installer from [rustup.rs](https://rustup.rs), make sure it works on the commandline (you may need to open a new terminal), and install the following versions: ``` rustup install 1.72.0 # For tor. rustup install 1.67.1 # For flutter_libepiccash. @@ -192,6 +205,11 @@ winget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 or [download the package](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.210806.1) and [manually install it](https://github.com/Baseflow/flutter-permission-handler/issues/1025#issuecomment-1518576722) by placing it in `flutter/bin` with [nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe) and installing by running `nuget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1` in the root `stack_wallet` folder. +### Build coinlib +Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be run from within the root `stack_wallet` folder on a... + - Windows host: `dart run coinlib:build_windows` + - WSL2 host: `dart run coinlib:build_wsl` + ### Run prebuild script Certain test wallet parameter and API key template files must be created in order to run Stack Wallet. These can be created by script as in @@ -201,7 +219,7 @@ cd scripts // when finished go back to the root directory cd .. ``` -or manually by creating the files referenced in that script with the specified content. +or manually by creating the files referenced in that script with the specified content. ### Running From 0b4d5db02165e1f9f4bdebc2627252431365d1b6 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 7 Mar 2024 22:31:32 -0600 Subject: [PATCH 06/35] add coinlib section and general rearrangement --- docs/building.md | 71 ++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/docs/building.md b/docs/building.md index 7685abdbf..0af3882ae 100644 --- a/docs/building.md +++ b/docs/building.md @@ -9,7 +9,7 @@ Here you will find instructions on how to install the necessary tools for buildi - 100 GB of storage ## Linux host -The following instructions are for building and running on a Linux host. Alternatively, see the [Windows](#Windows-host) section. +The following instructions are for building and running on a Linux host. This entire section (except for the Android Studio section) needs to be completed in WSL if building on a Windows host. ### Android Studio Install Android Studio. Follow instructions here [https://developer.android.com/studio/install#linux](https://developer.android.com/studio/install#linux) or install via snap: @@ -27,7 +27,12 @@ Use `Tools > SDK Manager` to install: Then in `File > Settings > Plugins`, install the **Flutter** and **Dart** plugins and restart the IDE. In `File > Settings > Languages & Frameworks > Flutter > Editor`, enable auto format on save to match the project's code style. If you have problems with the Dart SDK, make sure to run `flutter` in a terminal to download it (use `source ~/.bashrc` to update your environment variables if you're still using the same terminal from which you ran `setup.sh`). Run `flutter doctor` to install any missing dependencies and review and agree to any license agreements. -Make a Pixel 4 (API 30) x86_64 emulator with 2GB of storage space for emulation +Make a Pixel 4 (API 30) x86_64 emulator with 2GB of storage space for emulation. + +The following *may* be needed for Android studio: +``` +sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 +``` ### Build dependencies @@ -36,11 +41,6 @@ Install basic dependencies sudo apt-get install libssl-dev curl unzip automake build-essential file pkg-config git python libtool libtinfo5 cmake libgit2-dev clang libncurses5-dev libncursesw5-dev zlib1g-dev llvm python3-distutils ``` -The following *may* be needed for Android studio: -``` -sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 -``` - Install [Rust](https://www.rust-lang.org/tools/install) with command: ``` curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh @@ -74,18 +74,24 @@ cd stack_wallet git submodule update --init --recursive ``` -### Remove system packages (may be needed for building flutter_libmonero) -[`flutter_libmonero`](https://github.com/cypherstack/flutter_libmonero) may have issues building due to conflicts with system packages: if so, follow this section. +Build the secure storage dependencies in order to target Linux (not needed for Windows or other platforms): +``` +cd scripts/linux +./build_secure_storage_deps.sh +// when finished go back to the root directory +cd ../.. +``` + +### Build coinlib +Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be built from within the root `stack_wallet` folder on a... + - Linux host for Linux targets: `dart run coinlib:build_linux`, or + - Linux host for Windows targets: `dart run coinlib:build_windows_crosscompile` + - Windows host: `dart run coinlib:build_windows` + - WSL2 host: `dart run coinlib:build_wsl` + + +For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom options if the first attempts doesn't succeed! -Remove pre-installed system libraries for the following packages built by cryptography plugins in the crypto_plugins folder: `boost iconv libjson-dev libsecret openssl sodium unbound zmq`. You can use -``` -sudo apt list --installed | grep boost -``` -for example to find which pre-installed packages you may need to remove with `sudo apt remove`. Be careful, as some packages (especially boost) are linked to GNOME (GUI) packages: when in doubt, remove `-dev` packages first like with -``` -sudo apt-get remove '^libboost.*-dev.*' -``` - ### Run prebuild script @@ -112,19 +118,25 @@ cd scripts/linux ./build_all.sh ``` +##### Remove system packages (may be needed for building flutter_libmonero) +[`flutter_libmonero`](https://github.com/cypherstack/flutter_libmonero) may have issues building due to conflicts with system packages: if so, follow this section. + +Remove pre-installed system libraries for the following packages built by cryptography plugins in the crypto_plugins folder: `boost iconv libjson-dev libsecret openssl sodium unbound zmq`. You can use +``` +sudo apt list --installed | grep boost +``` +for example to find which pre-installed packages you may need to remove with `sudo apt remove`. Be careful, as some packages (especially boost) are linked to GNOME (GUI) packages: when in doubt, remove `-dev` packages first like with +``` +sudo apt-get remove '^libboost.*-dev.*' +``` + + #### Building plugins for Windows ``` cd scripts/windows ./deps.sh ./build_all.sh ``` - -### Build coinlib -Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be built from within the root `stack_wallet` folder on a... - - Linux host for Linux targets: `dart run coinlib:build_linux`, or - - Linux host for Windows targets: `dart run coinlib:build_windows_crosscompile` - - ### Running #### Android Plug in your android device or use the emulator available via Android Studio and then run the following commands: @@ -144,7 +156,7 @@ flutter run linux ## Windows host ### Visual Studio -Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++" and "Linux development with C++" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version. +Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++", "Linux development with C++", and "Visual C++ build tools" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version. ### Building libraries in WSL2 Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. @@ -205,14 +217,9 @@ winget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 or [download the package](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.210806.1) and [manually install it](https://github.com/Baseflow/flutter-permission-handler/issues/1025#issuecomment-1518576722) by placing it in `flutter/bin` with [nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe) and installing by running `nuget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1` in the root `stack_wallet` folder. -### Build coinlib -Coinlib's native secp256k1 library must be built prior to running Stack Wallet. It can be run from within the root `stack_wallet` folder on a... - - Windows host: `dart run coinlib:build_windows` - - WSL2 host: `dart run coinlib:build_wsl` - ### Run prebuild script -Certain test wallet parameter and API key template files must be created in order to run Stack Wallet. These can be created by script as in +Certain test wallet parameter and API key template files must be created in order to run Stack Wallet on Windows. These can be created by script as in ``` cd scripts ./prebuild.ps1 From ed42dba9cc6eda3745898cd969b9fc74a032c75e Mon Sep 17 00:00:00 2001 From: likho Date: Fri, 8 Mar 2024 19:31:34 +0200 Subject: [PATCH 07/35] Update address to match epicbox config --- lib/wallets/wallet/impl/epiccash_wallet.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/wallets/wallet/impl/epiccash_wallet.dart b/lib/wallets/wallet/impl/epiccash_wallet.dart index 8228ab7c8..015faa00c 100644 --- a/lib/wallets/wallet/impl/epiccash_wallet.dart +++ b/lib/wallets/wallet/impl/epiccash_wallet.dart @@ -317,6 +317,7 @@ class EpiccashWallet extends Bip39Wallet { Future
_generateAndStoreReceivingAddressForIndex( int index, ) async { + Address? address = await getCurrentReceivingAddress(); EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig(); @@ -325,6 +326,7 @@ class EpiccashWallet extends Bip39Wallet { //Check if the address is the same as the current epicbox domain //Since we're only using one epicbpox now this doesn't apply but will be // useful in the future + final encodedConfig = jsonEncode(epicboxConfig); if (splitted[1] != epicboxConfig.host) { //Update the address address = await thisWalletAddress(index, epicboxConfig); @@ -332,6 +334,13 @@ class EpiccashWallet extends Bip39Wallet { } else { address = await thisWalletAddress(index, epicboxConfig); } + + if (info.cachedReceivingAddress != address.value) { + await info.updateReceivingAddress( + newAddress: address.value, + isar: mainDB.isar, + ); + } return address; } @@ -360,7 +369,6 @@ class EpiccashWallet extends Bip39Wallet { subType: AddressSubType.receiving, publicKey: [], // ?? ); - await mainDB.updateOrPutAddresses([address]); return address; } From e6fc739192942cf86e37d7f85474640efd0e902e Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 8 Mar 2024 14:25:49 -0600 Subject: [PATCH 08/35] add docker/podman note for coinlib --- docs/building.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index 0af3882ae..e3d0cebaf 100644 --- a/docs/building.md +++ b/docs/building.md @@ -90,7 +90,9 @@ Coinlib's native secp256k1 library must be built prior to running Stack Wallet. - WSL2 host: `dart run coinlib:build_wsl` -For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom options if the first attempts doesn't succeed! +To build coinlib on Linux, you will need `docker` (see [installation instructions](https://docs.docker.com/engine/install/ubuntu/)) or [`podman`](https://podman.io/docs/installation) (`sudo apt-get -y install podman`) + +For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom options if the first attempt doesn't succeed! ### Run prebuild script From 6f98abddf78108aa6f976936753fc0410637bfd1 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sat, 9 Mar 2024 06:12:10 -0800 Subject: [PATCH 09/35] nit that android studio is not necessarily needed in wsl --- docs/building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index e3d0cebaf..9f220f759 100644 --- a/docs/building.md +++ b/docs/building.md @@ -161,7 +161,7 @@ flutter run linux Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++", "Linux development with C++", and "Visual C++ build tools" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version. ### Building libraries in WSL2 -Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. +Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. The Android Studio section may be skipped in WSL (it's only needed on the Windows host). Install the following libraries: ``` From 114ec4cd1011fe58081b0d36bd632be66a503181 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sat, 9 Mar 2024 15:43:50 -0800 Subject: [PATCH 10/35] expand upon flutter installation method --- docs/building.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index 9f220f759..b4385220a 100644 --- a/docs/building.md +++ b/docs/building.md @@ -34,6 +34,15 @@ The following *may* be needed for Android studio: sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 ``` +### Flutter + +Flutter and the Dart SDK should have been set up by Android studio, but if running `flutter` doesn't work (try `flutter doctor`, too), follow the [guide to install Flutter on any of their supported platforms](https://docs.flutter.dev/get-started/install) or: + - `git clone https://github.com/flutter/flutter` somewhere it can live (`/var`, `/opt`, `~`) + - `git checkout 3.16.0` after navigating into the `flutter` directory, and + - add `flutter/bin` to your PATH (on Ubuntu, add `PATH=$PATH:path/to/flutter/bin` to `~/.profile`). + +Run `flutter doctor` to install any missing dependencies and review and agree to any license agreements. + ### Build dependencies Install basic dependencies @@ -188,7 +197,11 @@ Copy the resulting `dll`s to their respective positions on the Windows host: ### Flutter -Install Flutter 3.16.0 on the Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows or by running `scripts/windows/deps.ps1`. You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1` (you may need to open a new terminal). Run `flutter doctor` in PowerShell to confirm its installation. +Install Flutter 3.16.0 on the Windows host (not in WSL2) by following [Flutter's Windows install guide](https://docs.flutter.dev/get-started/install/windows), by running `scripts/windows/deps.ps1`, or by + - `git clone https://github.com/flutter/flutter` somewhere it can live (`C:`, **avoid** anywhere in `C:/Users/`), + - `git checkout 3.16.0` (after navigating into the `flutter` folder), + - and adding `flutter/bin` to your PATH environmen variable (search "environment variables" in the Start menu) +You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1` (you may need to open a new terminal). Run `flutter doctor` in PowerShell to confirm its installation. ### Rust Install [Rust](https://www.rust-lang.org/tools/install) on the Windows host (not in WSL2). Download the installer from [rustup.rs](https://rustup.rs), make sure it works on the commandline (you may need to open a new terminal), and install the following versions: From 557d3fd07d44a4e129fde9bc7e98bb0924087f32 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sat, 9 Mar 2024 17:55:27 -0600 Subject: [PATCH 11/35] android nit --- docs/building.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/building.md b/docs/building.md index b4385220a..5bd2016e7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -20,10 +20,11 @@ sudo snap install android-studio --classic ``` Use `Tools > SDK Manager` to install: - - `SDK Tools > Android SDK (API 30)` - - `SDK Tools > NDK` - `SDK Tools > Android SDK command line tools` - `SDK Tools > CMake` +and for Android builds, + - `SDK Tools > Android SDK (API 30)` + - `SDK Tools > NDK` Then in `File > Settings > Plugins`, install the **Flutter** and **Dart** plugins and restart the IDE. In `File > Settings > Languages & Frameworks > Flutter > Editor`, enable auto format on save to match the project's code style. If you have problems with the Dart SDK, make sure to run `flutter` in a terminal to download it (use `source ~/.bashrc` to update your environment variables if you're still using the same terminal from which you ran `setup.sh`). Run `flutter doctor` to install any missing dependencies and review and agree to any license agreements. From 35019bdab3841969ccd05090004334c4498c7fe8 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 3 Apr 2024 12:07:16 -0500 Subject: [PATCH 12/35] finish mac host section --- docs/building.md | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/building.md b/docs/building.md index c6473127e..2caed60d3 100644 --- a/docs/building.md +++ b/docs/building.md @@ -185,6 +185,7 @@ After installing Homebrew, install the following packages: ``` brew install cocoapods git cmake autoconf fontconfig libpng lz4 pkg-config automake freetype libssh2 lzo procs berkeley-db gdbm libtool m4 rtmpdump brotli gettext libunistring make rustup-init ca-certificates git-gui libx11 openldap tcl-tk cairo glib libxau openssl@1.1 unbound cbindgen gmp libxcb openssl@3 unzip cmake libevent libxdmcp pcre2 xorgproto coreutils libidn2 libxext perl xz curl libnghttp2 libxrender pixman zstd ``` + Download and install [Rust](https://www.rust-lang.org/tools/install). [Rustup](https://rustup.rs/) is recommended for Rust setup. Use `rustc` to confirm successful installation. Install toolchains 1.67.1 and 1.72.0 and `cbindgen` and `cargo-lipo` too. You will also have to add the platform target(s) `aarch64-apple-ios` and/or `aarch64-apple-darwin`. You can use the command(s): ``` @@ -201,17 +202,42 @@ Download and install [Flutter](https://docs.flutter.dev/get-started/install). V Download [Android Studio](https://developer.android.com/studio). VS Code may work as an alternative, but this is not recommended. -### Building libraries -TODO +### Flutter +Install [Flutter](https://docs.flutter.dev/get-started/install) 3.16.8 on your Mac host by following [these instructions](https://docs.flutter.dev/get-started/install/macos). Run `flutter doctor` in a terminal to confirm its installation. -### Install Flutter on Mac host -Install Flutter 3.16.8 on your Mac host by following these instructions: https://docs.flutter.dev/get-started/install/macos. Run `flutter doctor` in a terminal to confirm its installation. +### Build plugins +#### Building plugins for iOS +``` +cd scripts/ios +./build_all.sh +``` + +#### Building plugins for macOS +``` +cd scripts/macos +./build_all.sh +``` + +### Running +#### iOS +Plug in your iOS device or use an emulato and then run the following commands: +``` +flutter pub get +flutter run ios +``` + +#### macOS +Run the following commands or launch via Android Studio: +``` +flutter pub get +flutter run macos +``` ## Windows host ### Visual Studio Visual Studio is required for Windows development with the Flutter SDK. Download it at https://visualstudio.microsoft.com/downloads/ and install the "Desktop development with C++", "Linux development with C++", and "Visual C++ build tools" workloads. You may also need the Windows 10, 11, and/or Universal SDK workloads depending on your Windows version. -### Building libraries in WSL2 +### Build plugins in WSL2 Set up Ubuntu 20.04 in WSL2. Follow the entire Linux host section in the WSL2 Ubuntu 20.04 host to get set up to build. The Android Studio section may be skipped in WSL (it's only needed on the Windows host). Install the following libraries: From 4cefed89d28f4049cbfae522a926ea098cb0b54d Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 3 Apr 2024 12:17:17 -0500 Subject: [PATCH 13/35] mention prebuild.sh for apple, too --- docs/building.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index 2caed60d3..b3effad4c 100644 --- a/docs/building.md +++ b/docs/building.md @@ -106,7 +106,6 @@ To build coinlib on Linux, you will need `docker` (see [installation instruction For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom options if the first attempt doesn't succeed! - ### Run prebuild script Certain test wallet parameter and API key template files must be created in order to run Stack Wallet. These can be created by script as in @@ -218,6 +217,17 @@ cd scripts/macos ./build_all.sh ``` +### Run prebuild script + +Certain test wallet parameter and API key template files must be created in order to run Stack Wallet. These can be created by script as in +``` +cd scripts +./prebuild.sh +// when finished go back to the root directory +cd .. +``` +or manually by creating the files referenced in that script with the specified content. + ### Running #### iOS Plug in your iOS device or use an emulato and then run the following commands: From 115ae7cb73d2da604830ea3150a5ea3df867b7cb Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 3 Apr 2024 12:25:01 -0500 Subject: [PATCH 14/35] macos/ios nit --- docs/building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index b3effad4c..c4301bfae 100644 --- a/docs/building.md +++ b/docs/building.md @@ -4,7 +4,7 @@ Here you will find instructions on how to install the necessary tools for buildi ## Prerequisites -- The only OS supported for building Android and Linux desktop is Ubuntu 20.04. Windows build are completed using Ubuntu 20.04 on WSL2. Advanced users may also be able to build on other Debian-based distributions like Linux Mint. +- The only OS supported for building Android and Linux desktop is Ubuntu 20.04. Windows builds require using Ubuntu 20.04 on WSL2. macOS builds for itself and iOS. Advanced users may also be able to build on other Debian-based distributions like Linux Mint. - Android setup ([Android Studio](https://developer.android.com/studio) and subsequent dependencies) - 100 GB of storage From 32c253674d699ca45a370b5fec876b51900af437 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 4 Apr 2024 13:02:43 -0500 Subject: [PATCH 15/35] remove cargo-ndk mention for windows over-agressive copying and pasting with insufficient review --- docs/building.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index c4301bfae..b6dbec820 100644 --- a/docs/building.md +++ b/docs/building.md @@ -285,15 +285,16 @@ You may still have to add `C:\development\flutter\bin` to PATH before proceeding Install [Rust](https://www.rust-lang.org/tools/install) on the Windows host (not in WSL2). Download the installer from [rustup.rs](https://rustup.rs), make sure it works on the commandline (you may need to open a new terminal), and install the following versions: ``` rustup install 1.72.0 # For frostdart and tor. -rustup install 1.73.0 # For cargo-ndk. rustup install 1.67.1 # For flutter_libepiccash. rustup default 1.67.1 ``` - -Also install `cargo-ndk`: + ### Windows SDK and Developer Mode Install the Windows SDK: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ You may need to install the [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/), which can be installed [by Visual Studio](https://stackoverflow.com/a/73923899) (`Tools > Get Tools and Features... > Modify > Individual Components > Windows 10 SDK`). From 9826dbb0b19a6a38dc74589a1ededf601b7db15a Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 4 Apr 2024 13:20:28 -0500 Subject: [PATCH 16/35] clarification of deps script role in flutter\bin's path for PATH --- docs/building.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index b6dbec820..f6e529b37 100644 --- a/docs/building.md +++ b/docs/building.md @@ -277,9 +277,9 @@ Copy the resulting `dll`s to their respective positions on the Windows host: ### Flutter Install Flutter 3.16.0 on the Windows host (not in WSL2) by following [Flutter's Windows install guide](https://docs.flutter.dev/get-started/install/windows), by running `scripts/windows/deps.ps1`, or by - `git clone https://github.com/flutter/flutter` somewhere it can live (`C:`, **avoid** anywhere in `C:/Users/`), - - `git checkout 3.16.0` (after navigating into the `flutter` folder), - - and adding `flutter/bin` to your PATH environmen variable (search "environment variables" in the Start menu) -You may still have to add `C:\development\flutter\bin` to PATH before proceeding, even if you ran `deps.ps1` (you may need to open a new terminal). Run `flutter doctor` in PowerShell to confirm its installation. + - `git checkout 3.16.9` (after navigating into the `flutter` folder), + - adding `flutter\bin`'s full absolute path to your PATH environment variable (search "environment variables" in the Start menu. If you ran `deps.ps1`, use `C:\development\flutter\bin`. You may also need to open a new terminal), + - and running `flutter doctor` in PowerShell to confirm its installation. You may need to resolve any issues which `flutter doctor` might raise. ### Rust Install [Rust](https://www.rust-lang.org/tools/install) on the Windows host (not in WSL2). Download the installer from [rustup.rs](https://rustup.rs), make sure it works on the commandline (you may need to open a new terminal), and install the following versions: From 70afa6fbb3807321c8ee08722e50933021fa7628 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 4 Apr 2024 14:08:28 -0500 Subject: [PATCH 17/35] make kvm performance note --- docs/building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/building.md b/docs/building.md index f6e529b37..46e57b1cf 100644 --- a/docs/building.md +++ b/docs/building.md @@ -159,7 +159,7 @@ flutter pub get flutter run android ``` -Note on Emulators: Only x86_64 emulators are supported, x86 emulators will not work +Note on Emulators: Only x86_64 emulators are supported, x86 emulators will not work. You should [configure KVM](https://help.ubuntu.com/community/KVM/Installation) for much better performance. #### Linux Run the following commands or launch via Android Studio: From d574bb5b45bcf1fc52c765c7be6518e74956d37b Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sun, 7 Apr 2024 20:11:45 -0500 Subject: [PATCH 18/35] Remove duplicate instruction and clatify that Android Studio is not required on macOS --- docs/building.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index 46e57b1cf..af128caf4 100644 --- a/docs/building.md +++ b/docs/building.md @@ -197,9 +197,7 @@ cargo install cbindgen cargo-lipo rustup target add aarch64-apple-ios aarch64-apple-darwin ``` -Download and install [Flutter](https://docs.flutter.dev/get-started/install). Versions 3.16.8 and 3.10.6 should both work. Use `flutter doctor` to confirm successful installation. - -Download [Android Studio](https://developer.android.com/studio). VS Code may work as an alternative, but this is not recommended. +Optionally download [Android Studio](https://developer.android.com/studio) as an IDE and activate its Dart and Flutter plugins. VS Code may work as an alternative, but this is not recommended. ### Flutter Install [Flutter](https://docs.flutter.dev/get-started/install) 3.16.8 on your Mac host by following [these instructions](https://docs.flutter.dev/get-started/install/macos). Run `flutter doctor` in a terminal to confirm its installation. From 34cf1f971583fb1e86b492843274f3c3cd150657 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 10 Apr 2024 23:53:20 -0500 Subject: [PATCH 19/35] Document required brew formulae: boost, libsodium, zmq/zeromq --- docs/building.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/building.md b/docs/building.md index af128caf4..52d663841 100644 --- a/docs/building.md +++ b/docs/building.md @@ -182,9 +182,14 @@ Download and install [Homebrew](https://brew.sh/). The following command can in After installing Homebrew, install the following packages: ``` -brew install cocoapods git cmake autoconf fontconfig libpng lz4 pkg-config automake freetype libssh2 lzo procs berkeley-db gdbm libtool m4 rtmpdump brotli gettext libunistring make rustup-init ca-certificates git-gui libx11 openldap tcl-tk cairo glib libxau openssl@1.1 unbound cbindgen gmp libxcb openssl@3 unzip cmake libevent libxdmcp pcre2 xorgproto coreutils libidn2 libxext perl xz curl libnghttp2 libxrender pixman zstd +brew install autoconf automake boost berkeley-db ca-certificates cbindgen cmake cmake cocoapods curl git libssh2 make openssl@1.1 openssl@3 perl pkg-config rustup-init sodium unbound unzip xz zmq ``` - + +The following brew formula *may* be needed: +``` +brew install brotli cairo coreutils gdbm gettext glib gmp libevent libidn2 libnghttp2 libtool libunistring libx11 libxau libxcb libxdmcp libxext libxrender lzo m4 openldap pcre2 pixman procs rtmpdump tcl-tk xorgproto zstd +``` + Download and install [Rust](https://www.rust-lang.org/tools/install). [Rustup](https://rustup.rs/) is recommended for Rust setup. Use `rustc` to confirm successful installation. Install toolchains 1.67.1 and 1.72.0 and `cbindgen` and `cargo-lipo` too. You will also have to add the platform target(s) `aarch64-apple-ios` and/or `aarch64-apple-darwin`. You can use the command(s): ``` From f3ef245fd7f842022d431621cce7b435a676822c Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 24 Apr 2024 16:21:25 -0500 Subject: [PATCH 20/35] pass proxy to StellarSdk as appropriate --- lib/wallets/wallet/impl/stellar_wallet.dart | 20 +++++++++++++++++++- pubspec.lock | 13 +++++++------ pubspec.yaml | 5 ++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/wallets/wallet/impl/stellar_wallet.dart b/lib/wallets/wallet/impl/stellar_wallet.dart index d078dd98e..edea60fe5 100644 --- a/lib/wallets/wallet/impl/stellar_wallet.dart +++ b/lib/wallets/wallet/impl/stellar_wallet.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:isar/isar.dart'; +import 'package:socks5_proxy/socks.dart'; import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'; @@ -9,6 +11,7 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart' import 'package:stackwallet/models/isar/models/blockchain_data/v2/output_v2.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; @@ -43,6 +46,7 @@ class StellarWallet extends Bip39Wallet { // ============== Private ==================================================== stellar.StellarSDK? _stellarSdk; + HttpClient? _httpClient; Future _getBaseFee() async { final fees = await stellarSdk.feeStats.execute(); @@ -51,7 +55,21 @@ class StellarWallet extends Bip39Wallet { void _updateSdk() { final currentNode = getCurrentNode(); - _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}"); + + // TODO [prio=med]: refactor out and call before requests in case Tor is enabled/disabled, listen to prefs change, or similar. + if (prefs.useTor) { + final ({InternetAddress host, int port}) proxyInfo = + TorService.sharedInstance.getProxyInfo(); + + _httpClient = HttpClient(); + SocksTCPClient.assignToHttpClient( + _httpClient!, [ProxySettings(proxyInfo.host, proxyInfo.port)]); + } else { + _httpClient = null; + } + + _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}", + httpClient: _httpClient); } Future _accountExists(String accountId) async { diff --git a/pubspec.lock b/pubspec.lock index 4e4d39cb7..afd26b39f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1659,10 +1659,11 @@ packages: stellar_flutter_sdk: dependency: "direct main" description: - name: stellar_flutter_sdk - sha256: "4c55b1b6dfbde7f89bba59a422754280715fa3b5726cff5e7eeaed454d2c4b89" - url: "https://pub.dev" - source: hosted + path: "." + ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 + resolved-ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 + url: "https://github.com/cypherstack/stellar_flutter_sdk.git" + source: git version: "1.5.3" stream_channel: dependency: "direct main" @@ -2109,5 +2110,5 @@ packages: source: hosted version: "1.0.0" sdks: - dart: ">=3.3.0 <4.0.0" - flutter: ">=3.16.0" + dart: ">=3.3.3 <4.0.0" + flutter: ">=3.19.5" diff --git a/pubspec.yaml b/pubspec.yaml index 16db28f97..2c432f6e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -156,7 +156,10 @@ dependencies: desktop_drop: ^0.4.1 nanodart: ^2.0.0 basic_utils: ^5.5.4 - stellar_flutter_sdk: ^1.5.3 + stellar_flutter_sdk: # ^1.5.3 + git: # TODO Revert to official package once Tor support is merged upstream. + url: https://github.com/cypherstack/stellar_flutter_sdk.git + ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 # tor-backport branch (based on 1.5.3). socks_socket: git: url: https://github.com/cypherstack/socks_socket.git From fe531ba19127d8bb9dd46d7ead79dc40acb2bce6 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 24 Apr 2024 16:35:00 -0500 Subject: [PATCH 21/35] point solana package to master on cypherstack/espresso-cash-public --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 723f2aae2..b299c3d71 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -180,7 +180,7 @@ dependencies: solana: git: # TODO [prio=low]: Revert to official package once Tor support is merged upstream. url: https://github.com/cypherstack/espresso-cash-public.git - ref: 0ada1f775c2a2c815de640424270a229f5e91e2f + ref: a83e375678eb22fe544dc125d29bbec0fb833882 path: packages/solana dev_dependencies: From 083f38ffe1791e24320b8cac90721a70eecbbe63 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 10:52:14 -0500 Subject: [PATCH 22/35] Remove unused socks_socket package So the nonexistence of github.com:cypherstack/socks_socket doesn't interfere with `pub get`s --- pubspec.lock | 6 +++--- pubspec.yaml | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 25ba923a0..765f09bb1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1574,7 +1574,7 @@ packages: source: hosted version: "1.0.4" socks_socket: - dependency: "direct main" + dependency: transitive description: path: "." ref: master @@ -1586,8 +1586,8 @@ packages: dependency: "direct main" description: path: "packages/solana" - ref: "0ada1f775c2a2c815de640424270a229f5e91e2f" - resolved-ref: "0ada1f775c2a2c815de640424270a229f5e91e2f" + ref: a83e375678eb22fe544dc125d29bbec0fb833882 + resolved-ref: a83e375678eb22fe544dc125d29bbec0fb833882 url: "https://github.com/cypherstack/espresso-cash-public.git" source: git version: "0.30.4" diff --git a/pubspec.yaml b/pubspec.yaml index 723f2aae2..df55b3fb9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -157,10 +157,6 @@ dependencies: nanodart: ^2.0.0 basic_utils: ^5.5.4 stellar_flutter_sdk: ^1.5.3 - socks_socket: - git: - url: https://github.com/cypherstack/socks_socket.git - ref: master bip340: ^0.2.0 # tezart: ^2.0.5 tezart: From 414760cc54ec085915fcccd79591fba55cfab827 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 13:57:39 -0500 Subject: [PATCH 23/35] pubspec todo nit --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2c432f6e0..832b24fdd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -157,7 +157,7 @@ dependencies: nanodart: ^2.0.0 basic_utils: ^5.5.4 stellar_flutter_sdk: # ^1.5.3 - git: # TODO Revert to official package once Tor support is merged upstream. + git: # TODO [prio=low]: Revert to official package once Tor support is merged upstream. url: https://github.com/cypherstack/stellar_flutter_sdk.git ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 # tor-backport branch (based on 1.5.3). socks_socket: From e4d8a4af3651e437b676a2462d323be6012866f1 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 14:00:44 -0500 Subject: [PATCH 24/35] solana has tor support --- lib/wallets/crypto_currency/coins/solana.dart | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/wallets/crypto_currency/coins/solana.dart b/lib/wallets/crypto_currency/coins/solana.dart index 632e0f977..193e48541 100644 --- a/lib/wallets/crypto_currency/coins/solana.dart +++ b/lib/wallets/crypto_currency/coins/solana.dart @@ -1,9 +1,9 @@ import 'package:solana/solana.dart'; import 'package:stackwallet/models/node_model.dart'; +import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart'; -import 'package:stackwallet/utilities/default_nodes.dart'; class Solana extends Bip39Currency { Solana(super.network) { @@ -20,7 +20,8 @@ class Solana extends Bip39Currency { switch (network) { case CryptoCurrencyNetwork.main: return NodeModel( - host: "https://api.mainnet-beta.solana.com/", // TODO: Change this to stack wallet one + host: + "https://api.mainnet-beta.solana.com/", // TODO: Change this to stack wallet one port: 443, name: DefaultNodes.defaultName, id: DefaultNodes.buildId(Coin.solana), @@ -38,11 +39,15 @@ class Solana extends Bip39Currency { @override int get minConfirms => 21; + @override + bool get torSupport => true; + @override bool validateAddress(String address) { - return isPointOnEd25519Curve(Ed25519HDPublicKey.fromBase58(address).toByteArray()); + return isPointOnEd25519Curve( + Ed25519HDPublicKey.fromBase58(address).toByteArray()); } @override String get genesisHash => throw UnimplementedError(); -} \ No newline at end of file +} From 4f55765a53258d218f0efa47fcc2412f62faf2d1 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 14:01:28 -0500 Subject: [PATCH 25/35] stellar has tor support --- lib/wallets/crypto_currency/coins/stellar.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/wallets/crypto_currency/coins/stellar.dart b/lib/wallets/crypto_currency/coins/stellar.dart index aa5f9ce4d..e9a7e605b 100644 --- a/lib/wallets/crypto_currency/coins/stellar.dart +++ b/lib/wallets/crypto_currency/coins/stellar.dart @@ -19,6 +19,9 @@ class Stellar extends Bip39Currency { @override int get minConfirms => 1; + @override + bool get torSupport => true; + @override String get genesisHash => throw UnimplementedError( "Not used for stellar", From 9e26913fc4d107a5651a80f484f56150ef4778b1 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 14:03:28 -0500 Subject: [PATCH 26/35] tezos has tor support --- lib/wallets/crypto_currency/coins/tezos.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/wallets/crypto_currency/coins/tezos.dart b/lib/wallets/crypto_currency/coins/tezos.dart index ef0937da6..efb982867 100644 --- a/lib/wallets/crypto_currency/coins/tezos.dart +++ b/lib/wallets/crypto_currency/coins/tezos.dart @@ -70,6 +70,9 @@ class Tezos extends Bip39Currency { @override int get minConfirms => 1; + @override + bool get torSupport => true; + @override bool validateAddress(String address) { return RegExp(r"^tz[1-9A-HJ-NP-Za-km-z]{34}$").hasMatch(address); From 81fd642735614f9a608d8721bc27e7b9940a443e Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 14:57:42 -0500 Subject: [PATCH 27/35] do not show multiple warnings when entering wallet remove WIP/original TorWarningDialog --- lib/widgets/wallet_card.dart | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/lib/widgets/wallet_card.dart b/lib/widgets/wallet_card.dart index 31a29fb68..bc1c80aa4 100644 --- a/lib/widgets/wallet_card.dart +++ b/lib/widgets/wallet_card.dart @@ -30,7 +30,6 @@ import 'package:stackwallet/wallets/wallet/wallet.dart'; import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/cw_based_interface.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; -import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/dialogs/basic_dialog.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; @@ -95,37 +94,6 @@ class SimpleWalletCard extends ConsumerWidget { final wallet = ref.read(pWallets).getWallet(walletId); - // If Tor enabled, show a warning if opening a wallet incompatible with Tor. - if (ref.read(prefsChangeNotifierProvider).useTor) { - if (!wallet.cryptoCurrency.torSupport) { - final shouldContinue = await showDialog( - context: context, - builder: (context) => BasicDialog( - title: "Warning! Tor not supported.", - message: "Stacky is not compatible with Tor." - "\n\nBy using it, you will leak your IP address. Are you sure you " - "want to continue?", - // A PrimaryButton widget: - leftButton: PrimaryButton( - label: "Cancel", - onPressed: () { - Navigator.of(context).pop(false); - }, - ), - rightButton: SecondaryButton( - label: "Continue", - onPressed: () { - Navigator.of(context).pop(true); - }, - ), - )) ?? - false; - if (!shouldContinue) { - return; - } - } - } - if (context.mounted) { final Future loadFuture; if (wallet is CwBasedInterface) { From 01de393521f3eed4c6143e6c901312fc745d6f84 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 25 Apr 2024 15:35:04 -0500 Subject: [PATCH 28/35] fetch paynym bot image over Tor hard to test, as I cannot claim/generate nor detect a previously-claimed/generated nym over Tor due to ``` flutter: Log: [Info][2024-04-25 20:28:22.609Z]: HTTP.post() rethrew: Exception: Command handling failed. With error: serverError flutter: #0 SocksSocket._handleCommandResponse (package:socks5_proxy/src/client/socks_client.dart:196:7) flutter: flutter: #1 SocksSocket.initialize (package:socks5_proxy/src/client/socks_client.dart:74:22) flutter: flutter: #2 SocksTCPClient.connect (package:socks5_proxy/src/client/socks_tcp_client.dart:70:20) flutter: flutter: #3 SocksTCPClient.assignToHttpClientWithSecureOptions. (package:socks5_proxy/src/client/socks_tcp_client.dart:46:40) flutter: flutter: #4 _ConnectionTarget.connect. (dart:_http/http_impl.dart:2490:32) flutter: flutter: #5 _HttpClient._openUrl. (dart:_http/http_impl.dart:2787:15) flutter: flutter: #6 HTTP.post (package:stackwallet/networking/http.dart:85:41) flutter: flutter: #7 PaynymIsApi._post (package:stackwallet/utilities/paynym_is_api.dart:54:22) flutter: flutter: #8 PaynymIsApi.nym (package:stackwallet/utilities/paynym_is_api.dart:267:22) flutter: flutter: #9 Wallet.refresh (package:stackwallet/wallets/wallet/wallet.dart:511:21) flutter: ``` --- lib/pages/paynym/subwidgets/paynym_bot.dart | 43 ++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/pages/paynym/subwidgets/paynym_bot.dart b/lib/pages/paynym/subwidgets/paynym_bot.dart index d8f645da3..082f7034e 100644 --- a/lib/pages/paynym/subwidgets/paynym_bot.dart +++ b/lib/pages/paynym/subwidgets/paynym_bot.dart @@ -8,8 +8,12 @@ * */ +import 'dart:typed_data'; + import 'package:flutter/material.dart'; -import 'package:stackwallet/widgets/loading_indicator.dart'; +import 'package:stackwallet/networking/http.dart'; +import 'package:stackwallet/services/tor_service.dart'; +import 'package:stackwallet/utilities/prefs.dart'; class PayNymBot extends StatelessWidget { const PayNymBot({ @@ -28,16 +32,37 @@ class PayNymBot extends StatelessWidget { child: SizedBox( width: size, height: size, - child: Image.network( - "https://paynym.is/$paymentCodeString/avatar", - loadingBuilder: (context, child, loadingProgress) => - loadingProgress == null - ? child - : const Center( - child: LoadingIndicator(), - ), + child: FutureBuilder( + future: _fetchImage(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return Image.memory(snapshot.data!); + } else if (snapshot.hasError) { + return const Center(child: Icon(Icons.error)); + } else { + return const Center(); // TODO [prio=low]: Make better loading indicator. + } + }, ), ), ); } + + Future _fetchImage() async { + final HTTP client = HTTP(); + final Uri uri = Uri.parse("https://paynym.is/$paymentCodeString/avatar"); + + final response = await client.get( + url: uri, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null, + ); + + if (response.code == 200) { + return Uint8List.fromList(response.bodyBytes); + } else { + throw Exception('Failed to load image'); + } + } } From bf3667da85dea8f464c80eb6abe7f384dbbcc732 Mon Sep 17 00:00:00 2001 From: dethe <76167420+detherminal@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:19:09 +0300 Subject: [PATCH 29/35] solana fee estimation fixes --- lib/wallets/wallet/impl/solana_wallet.dart | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/wallets/wallet/impl/solana_wallet.dart b/lib/wallets/wallet/impl/solana_wallet.dart index c9343ddfc..7a4aab388 100644 --- a/lib/wallets/wallet/impl/solana_wallet.dart +++ b/lib/wallets/wallet/impl/solana_wallet.dart @@ -18,7 +18,6 @@ import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/wallets/crypto_currency/coins/solana.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; @@ -66,10 +65,8 @@ class SolanaWallet extends Bip39Wallet { recipientAccount: pubKey, lamports: transferAmount.raw.toInt(), ), - ]).compile( - recentBlockhash: latestBlockhash!.value.blockhash, - feePayer: pubKey, - ); + ComputeBudgetInstruction.setComputeUnitPrice(microLamports: 6000), + ]).compile(recentBlockhash: latestBlockhash!.value.blockhash, feePayer: (await _getKeyPair()).publicKey); return await _rpcClient?.getFeeForMessage( base64Encode(compiledMessage.toByteArray().toList()), @@ -118,19 +115,10 @@ class SolanaWallet extends Bip39Wallet { throw Exception("Insufficient available balance"); } - int feeAmount; - final currentFees = await fees; - switch (txData.feeRateType) { - case FeeRateType.fast: - feeAmount = currentFees.fast; - break; - case FeeRateType.slow: - feeAmount = currentFees.slow; - break; - case FeeRateType.average: - default: - feeAmount = currentFees.medium; - break; + final feeAmount = await _getEstimatedNetworkFee(sendAmount); + if (feeAmount == null) { + throw Exception( + "Failed to get fees, please check your node connection."); } // Rent exemption of Solana From 87a96b9b09335b64d983736c8aa501b8f8dbf0e8 Mon Sep 17 00:00:00 2001 From: dethe <76167420+detherminal@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:18:54 +0300 Subject: [PATCH 30/35] sol: fee set fix and sent to self fix --- lib/wallets/wallet/impl/solana_wallet.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/wallets/wallet/impl/solana_wallet.dart b/lib/wallets/wallet/impl/solana_wallet.dart index 7a4aab388..e7d93ed0f 100644 --- a/lib/wallets/wallet/impl/solana_wallet.dart +++ b/lib/wallets/wallet/impl/solana_wallet.dart @@ -64,8 +64,7 @@ class SolanaWallet extends Bip39Wallet { fundingAccount: pubKey, recipientAccount: pubKey, lamports: transferAmount.raw.toInt(), - ), - ComputeBudgetInstruction.setComputeUnitPrice(microLamports: 6000), + ) ]).compile(recentBlockhash: latestBlockhash!.value.blockhash, feePayer: (await _getKeyPair()).publicKey); return await _rpcClient?.getFeeForMessage( @@ -167,7 +166,12 @@ class SolanaWallet extends Bip39Wallet { recipientAccount: recipientPubKey, lamports: txData.amount!.raw.toInt()), ComputeBudgetInstruction.setComputeUnitPrice( - microLamports: txData.fee!.raw.toInt()), + microLamports: txData.fee!.raw.toInt() - 5000), + // 5000 lamports is the base fee for a transaction. This instruction adds the necessary fee on top of base fee if it is needed. + ComputeBudgetInstruction.setComputeUnitLimit(units: 1000000), + // 1000000 is the multiplication number to turn the compute unit price of microLamports to lamports. + // These instructions also help the user to not pay more than the shown fee. + // See: https://solanacookbook.com/references/basic-transactions.html#how-to-change-compute-budget-fee-priority-for-a-transaction ], ); @@ -367,7 +371,7 @@ class SolanaWallet extends Bip39Wallet { for (final tx in transactionsList!) { final senderAddress = (tx.transaction as ParsedTransaction).message.accountKeys[0].pubkey; - final receiverAddress = + var receiverAddress = (tx.transaction as ParsedTransaction).message.accountKeys[1].pubkey; var txType = isar.TransactionType.unknown; final txAmount = Amount( @@ -376,9 +380,10 @@ class SolanaWallet extends Bip39Wallet { fractionDigits: cryptoCurrency.fractionDigits, ); - if ((senderAddress == (await _getKeyPair()).address) && - (receiverAddress == (await _getKeyPair()).address)) { + if ((senderAddress == (await _getKeyPair()).address) && (receiverAddress == "11111111111111111111111111111111")) { + // The account that is only 1's are System Program accounts which means there is no receiver except the sender, see: https://explorer.solana.com/address/11111111111111111111111111111111 txType = isar.TransactionType.sentToSelf; + receiverAddress = senderAddress; } else if (senderAddress == (await _getKeyPair()).address) { txType = isar.TransactionType.outgoing; } else if (receiverAddress == (await _getKeyPair()).address) { From 1101b8c9326a23249228c1c8b99b79fd326ea37e Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 May 2024 09:33:59 -0600 Subject: [PATCH 31/35] clean up sol --- lib/wallets/crypto_currency/coins/solana.dart | 18 +++- lib/wallets/wallet/impl/solana_wallet.dart | 97 +++++++++++-------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/lib/wallets/crypto_currency/coins/solana.dart b/lib/wallets/crypto_currency/coins/solana.dart index 632e0f977..0307d6bde 100644 --- a/lib/wallets/crypto_currency/coins/solana.dart +++ b/lib/wallets/crypto_currency/coins/solana.dart @@ -1,9 +1,9 @@ import 'package:solana/solana.dart'; import 'package:stackwallet/models/node_model.dart'; +import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart'; -import 'package:stackwallet/utilities/default_nodes.dart'; class Solana extends Bip39Currency { Solana(super.network) { @@ -20,7 +20,8 @@ class Solana extends Bip39Currency { switch (network) { case CryptoCurrencyNetwork.main: return NodeModel( - host: "https://api.mainnet-beta.solana.com/", // TODO: Change this to stack wallet one + host: + "https://api.mainnet-beta.solana.com/", // TODO: Change this to stack wallet one port: 443, name: DefaultNodes.defaultName, id: DefaultNodes.buildId(Coin.solana), @@ -40,9 +41,18 @@ class Solana extends Bip39Currency { @override bool validateAddress(String address) { - return isPointOnEd25519Curve(Ed25519HDPublicKey.fromBase58(address).toByteArray()); + return isPointOnEd25519Curve( + Ed25519HDPublicKey.fromBase58(address).toByteArray()); } @override String get genesisHash => throw UnimplementedError(); -} \ No newline at end of file + + @override + bool operator ==(Object other) { + return other is Solana && other.network == network; + } + + @override + int get hashCode => Object.hash(Solana, network); +} diff --git a/lib/wallets/wallet/impl/solana_wallet.dart b/lib/wallets/wallet/impl/solana_wallet.dart index e7d93ed0f..d2f3582c9 100644 --- a/lib/wallets/wallet/impl/solana_wallet.dart +++ b/lib/wallets/wallet/impl/solana_wallet.dart @@ -28,24 +28,30 @@ import 'package:tuple/tuple.dart'; class SolanaWallet extends Bip39Wallet { SolanaWallet(CryptoCurrencyNetwork network) : super(Solana(network)); + static const String _addressDerivationPath = "m/44'/501'/0'/0'"; + NodeModel? _solNode; RpcClient? _rpcClient; // The Solana RpcClient. Future _getKeyPair() async { - return Ed25519HDKeyPair.fromMnemonic(await getMnemonic(), - account: 0, change: 0); + return Ed25519HDKeyPair.fromMnemonic( + await getMnemonic(), + account: 0, + change: 0, + ); } - Future
_getCurrentAddress() async { + Future
_generateAddress() async { final addressStruct = Address( - walletId: walletId, - value: (await _getKeyPair()).address, - publicKey: List.empty(), - derivationIndex: 0, - derivationPath: DerivationPath()..value = "m/44'/501'/0'/0'", - type: cryptoCurrency.coin.primaryAddressType, - subType: AddressSubType.unknown); + walletId: walletId, + value: (await _getKeyPair()).address, + publicKey: List.empty(), + derivationIndex: 0, + derivationPath: DerivationPath()..value = _addressDerivationPath, + type: cryptoCurrency.coin.primaryAddressType, + subType: AddressSubType.receiving, + ); return addressStruct; } @@ -65,7 +71,10 @@ class SolanaWallet extends Bip39Wallet { recipientAccount: pubKey, lamports: transferAmount.raw.toInt(), ) - ]).compile(recentBlockhash: latestBlockhash!.value.blockhash, feePayer: (await _getKeyPair()).publicKey); + ]).compile( + recentBlockhash: latestBlockhash!.value.blockhash, + feePayer: pubKey, + ); return await _rpcClient?.getFeeForMessage( base64Encode(compiledMessage.toByteArray().toList()), @@ -79,18 +88,13 @@ class SolanaWallet extends Bip39Wallet { @override Future checkSaveInitialReceivingAddress() async { try { - final address = (await _getKeyPair()).address; + Address? address = await getCurrentReceivingAddress(); - await mainDB.updateOrPutAddresses([ - Address( - walletId: walletId, - value: address, - publicKey: List.empty(), - derivationIndex: 0, - derivationPath: DerivationPath()..value = "m/44'/501'/0'/0'", - type: cryptoCurrency.coin.primaryAddressType, - subType: AddressSubType.unknown) - ]); + if (address == null) { + address = await _generateAddress(); + + await mainDB.updateOrPutAddresses([address]); + } } catch (e, s) { Logging.instance.log( "$runtimeType checkSaveInitialReceivingAddress() failed: $e\n$s", @@ -120,9 +124,10 @@ class SolanaWallet extends Bip39Wallet { "Failed to get fees, please check your node connection."); } + final address = await getCurrentReceivingAddress(); + // Rent exemption of Solana - final accInfo = - await _rpcClient?.getAccountInfo((await _getKeyPair()).address); + final accInfo = await _rpcClient?.getAccountInfo(address!.value); final int minimumRent = await _rpcClient?.getMinimumBalanceForRentExemption( accInfo!.value!.data.toString().length) ?? @@ -132,7 +137,9 @@ class SolanaWallet extends Bip39Wallet { txData.amount!.raw.toInt() - feeAmount)) { throw Exception( - "Insufficient remaining balance for rent exemption, minimum rent: ${minimumRent / pow(10, cryptoCurrency.fractionDigits)}"); + "Insufficient remaining balance for rent exemption, minimum rent: " + "${minimumRent / pow(10, cryptoCurrency.fractionDigits)}", + ); } return txData.copyWith( @@ -255,7 +262,7 @@ class SolanaWallet extends Bip39Wallet { @override Future recover({required bool isRescan}) async { await refreshMutex.protect(() async { - final addressStruct = await _getCurrentAddress(); + final addressStruct = await _generateAddress(); await mainDB.updateOrPutAddresses([addressStruct]); @@ -277,13 +284,13 @@ class SolanaWallet extends Bip39Wallet { @override Future updateBalance() async { try { + final address = await getCurrentReceivingAddress(); _checkClient(); - final balance = await _rpcClient?.getBalance(info.cachedReceivingAddress); + final balance = await _rpcClient?.getBalance(address!.value); // Rent exemption of Solana - final accInfo = - await _rpcClient?.getAccountInfo((await _getKeyPair()).address); + final accInfo = await _rpcClient?.getAccountInfo(address!.value); // TODO [prio=low]: handle null account info. final int minimumRent = await _rpcClient?.getMinimumBalanceForRentExemption( @@ -366,6 +373,8 @@ class SolanaWallet extends Bip39Wallet { final txsList = List>.empty(growable: true); + final myAddress = (await getCurrentReceivingAddress())!; + // TODO [prio=low]: Revisit null assertion below. for (final tx in transactionsList!) { @@ -380,13 +389,16 @@ class SolanaWallet extends Bip39Wallet { fractionDigits: cryptoCurrency.fractionDigits, ); - if ((senderAddress == (await _getKeyPair()).address) && (receiverAddress == "11111111111111111111111111111111")) { - // The account that is only 1's are System Program accounts which means there is no receiver except the sender, see: https://explorer.solana.com/address/11111111111111111111111111111111 + if ((senderAddress == myAddress.value) && + (receiverAddress == "11111111111111111111111111111111")) { + // The account that is only 1's are System Program accounts which + // means there is no receiver except the sender, + // see: https://explorer.solana.com/address/11111111111111111111111111111111 txType = isar.TransactionType.sentToSelf; receiverAddress = senderAddress; - } else if (senderAddress == (await _getKeyPair()).address) { + } else if (senderAddress == myAddress.value) { txType = isar.TransactionType.outgoing; - } else if (receiverAddress == (await _getKeyPair()).address) { + } else if (receiverAddress == myAddress.value) { txType = isar.TransactionType.incoming; } @@ -411,15 +423,16 @@ class SolanaWallet extends Bip39Wallet { ); final txAddress = Address( - walletId: walletId, - value: receiverAddress, - publicKey: List.empty(), - derivationIndex: 0, - derivationPath: DerivationPath()..value = "m/44'/501'/0'/0'", - type: AddressType.solana, - subType: txType == isar.TransactionType.outgoing - ? AddressSubType.unknown - : AddressSubType.receiving); + walletId: walletId, + value: receiverAddress, + publicKey: List.empty(), + derivationIndex: 0, + derivationPath: DerivationPath()..value = _addressDerivationPath, + type: AddressType.solana, + subType: txType == isar.TransactionType.outgoing + ? AddressSubType.unknown + : AddressSubType.receiving, + ); txsList.add(Tuple2(transaction, txAddress)); } From 1c47b1e4c95a27b0cf134aadc03ff7ee572df644 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 3 May 2024 16:56:13 -0500 Subject: [PATCH 32/35] Update building.md --- docs/building.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/building.md b/docs/building.md index 603452e55..d7a357076 100644 --- a/docs/building.md +++ b/docs/building.md @@ -103,11 +103,11 @@ Coinlib's native secp256k1 library must be built prior to running Stack Wallet. - Linux host for Windows targets: `dart run coinlib:build_windows_crosscompile` - Windows host: `dart run coinlib:build_windows` - WSL2 host: `dart run coinlib:build_wsl` - + - macOS host: `dart run coinlib:build_macos` To build coinlib on Linux, you will need `docker` (see [installation instructions](https://docs.docker.com/engine/install/ubuntu/)) or [`podman`](https://podman.io/docs/installation) (`sudo apt-get -y install podman`) -For Windows targets, you can use a `secp256k1.dll` produced by any of the three bottom options if the first attempt doesn't succeed! +For Windows targets, you can use a `secp256k1.dll` produced by any of the three middle options if the first attempt doesn't succeed! ### Run prebuild script @@ -280,6 +280,8 @@ Copy the resulting `dll`s to their respective positions on the Windows host: --> +Frostdart will be built by the Windows host later. + ### Install Flutter on Windows host Install Flutter 3.19.5 on your Windows host (not in WSL2) by following these instructions: https://docs.flutter.dev/get-started/install/windows/desktop?tab=download#install-the-flutter-sdk. You can also clone https://github.com/flutter/flutter, check out the `3.19.5` tag, and add its `flutter/bin` folder to your PATH. Run `flutter doctor` in PowerShell to confirm its installation. @@ -316,15 +318,23 @@ or [download the package](https://www.nuget.org/packages/Microsoft.Windows.CppWi ### Run prebuild script -Certain test wallet parameter and API key template files must be created in order to run Stack Wallet on Windows. These can be created by script as in +Certain test wallet parameter and API key template files must be created in order to run Stack Wallet on Windows. These can be created by script using PowerShell on the Windows host as in ``` cd scripts ./prebuild.ps1 -// when finished go back to the root directory -cd .. +cd .. // When finished go back to the root directory. ``` or manually by creating the files referenced in that script with the specified content. +### Build frostdart + +In PowerShell on the Windows host, navigate to the `stack_wallet` folder: +``` +cd crypto_plugins/frostdart +./build_all.bat +cd .. // When finished go back to the root directory. +``` + ### Running Run the following commands: From bcb39c39065d04c3907855e1139358732b3c184c Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 May 2024 15:42:21 -0600 Subject: [PATCH 33/35] no need for class wide htt client property, and close the client before assigning a new one --- lib/wallets/wallet/impl/stellar_wallet.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/wallets/wallet/impl/stellar_wallet.dart b/lib/wallets/wallet/impl/stellar_wallet.dart index edea60fe5..a2ad93083 100644 --- a/lib/wallets/wallet/impl/stellar_wallet.dart +++ b/lib/wallets/wallet/impl/stellar_wallet.dart @@ -46,7 +46,6 @@ class StellarWallet extends Bip39Wallet { // ============== Private ==================================================== stellar.StellarSDK? _stellarSdk; - HttpClient? _httpClient; Future _getBaseFee() async { final fees = await stellarSdk.feeStats.execute(); @@ -55,6 +54,7 @@ class StellarWallet extends Bip39Wallet { void _updateSdk() { final currentNode = getCurrentNode(); + HttpClient? _httpClient; // TODO [prio=med]: refactor out and call before requests in case Tor is enabled/disabled, listen to prefs change, or similar. if (prefs.useTor) { @@ -63,13 +63,21 @@ class StellarWallet extends Bip39Wallet { _httpClient = HttpClient(); SocksTCPClient.assignToHttpClient( - _httpClient!, [ProxySettings(proxyInfo.host, proxyInfo.port)]); - } else { - _httpClient = null; + _httpClient, + [ + ProxySettings( + proxyInfo.host, + proxyInfo.port, + ), + ], + ); } - _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}", - httpClient: _httpClient); + _stellarSdk?.httpClient.close(); + _stellarSdk = stellar.StellarSDK( + "${currentNode.host}:${currentNode.port}", + httpClient: _httpClient, + ); } Future _accountExists(String accountId) async { From 8c082f3ed43d51cd66319fb3e6bb42d7a7044c1e Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 May 2024 18:04:57 -0600 Subject: [PATCH 34/35] untested stellar tor listener --- lib/wallets/wallet/impl/stellar_wallet.dart | 118 +++++++++++++++----- 1 file changed, 90 insertions(+), 28 deletions(-) diff --git a/lib/wallets/wallet/impl/stellar_wallet.dart b/lib/wallets/wallet/impl/stellar_wallet.dart index a2ad93083..657fd7676 100644 --- a/lib/wallets/wallet/impl/stellar_wallet.dart +++ b/lib/wallets/wallet/impl/stellar_wallet.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:isar/isar.dart'; +import 'package:mutex/mutex.dart'; import 'package:socks5_proxy/socks.dart'; import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; @@ -11,6 +12,9 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart' import 'package:stackwallet/models/isar/models/blockchain_data/v2/output_v2.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart'; +import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart'; +import 'package:stackwallet/services/event_bus/events/global/tor_status_changed_event.dart'; +import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; @@ -23,11 +27,47 @@ import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart' as stellar; class StellarWallet extends Bip39Wallet { - StellarWallet(CryptoCurrencyNetwork network) : super(Stellar(network)); + StellarWallet(CryptoCurrencyNetwork network) : super(Stellar(network)) { + final bus = GlobalEventBus.instance; - stellar.StellarSDK get stellarSdk { - if (_stellarSdk == null) { - _updateSdk(); + // Listen for tor status changes. + _torStatusListener = bus.on().listen( + (event) async { + switch (event.newStatus) { + case TorConnectionStatus.connecting: + if (!_torConnectingLock.isLocked) { + await _torConnectingLock.acquire(); + } + _requireMutex = true; + break; + + case TorConnectionStatus.connected: + case TorConnectionStatus.disconnected: + if (_torConnectingLock.isLocked) { + _torConnectingLock.release(); + } + _requireMutex = false; + break; + } + }, + ); + + // Listen for tor preference changes. + _torPreferenceListener = bus.on().listen( + (event) async { + _stellarSdk?.httpClient.close(); + _stellarSdk = null; + }, + ); + } + + Future get stellarSdk async { + if (_requireMutex) { + await _torConnectingLock.protect(() async { + _stellarSdk ??= _getFreshSdk(); + }); + } else { + _stellarSdk ??= _getFreshSdk(); } return _stellarSdk!; } @@ -44,19 +84,32 @@ class StellarWallet extends Bip39Wallet { } // ============== Private ==================================================== + // add finalizer to cancel stream subscription when all references to an + // instance of this becomes inaccessible + final _ = Finalizer( + (p0) { + p0._torPreferenceListener?.cancel(); + p0._torStatusListener?.cancel(); + }, + ); + + StreamSubscription? _torStatusListener; + StreamSubscription? _torPreferenceListener; + + final Mutex _torConnectingLock = Mutex(); + bool _requireMutex = false; stellar.StellarSDK? _stellarSdk; Future _getBaseFee() async { - final fees = await stellarSdk.feeStats.execute(); + final fees = await (await stellarSdk).feeStats.execute(); return int.parse(fees.lastLedgerBaseFee); } - void _updateSdk() { + stellar.StellarSDK _getFreshSdk() { final currentNode = getCurrentNode(); HttpClient? _httpClient; - // TODO [prio=med]: refactor out and call before requests in case Tor is enabled/disabled, listen to prefs change, or similar. if (prefs.useTor) { final ({InternetAddress host, int port}) proxyInfo = TorService.sharedInstance.getProxyInfo(); @@ -73,8 +126,7 @@ class StellarWallet extends Bip39Wallet { ); } - _stellarSdk?.httpClient.close(); - _stellarSdk = stellar.StellarSDK( + return stellar.StellarSDK( "${currentNode.host}:${currentNode.port}", httpClient: _httpClient, ); @@ -84,7 +136,8 @@ class StellarWallet extends Bip39Wallet { bool exists = false; try { - final receiverAccount = await stellarSdk.accounts.account(accountId); + final receiverAccount = + await (await stellarSdk).accounts.account(accountId); if (receiverAccount.accountId != "") { exists = true; } @@ -191,7 +244,8 @@ class StellarWallet extends Bip39Wallet { @override Future confirmSend({required TxData txData}) async { final senderKeyPair = await _getSenderKeyPair(index: 0); - final sender = await stellarSdk.accounts.account(senderKeyPair.accountId); + final sender = + await (await stellarSdk).accounts.account(senderKeyPair.accountId); final address = txData.recipients!.first.address; final amountToSend = txData.recipients!.first.amount; @@ -229,7 +283,7 @@ class StellarWallet extends Bip39Wallet { transaction.sign(senderKeyPair, stellarNetwork); try { - final response = await stellarSdk.submitTransaction(transaction); + final response = await (await stellarSdk).submitTransaction(transaction); if (!response.success) { throw Exception("${response.extras?.resultCodes?.transactionResultCode}" " ::: ${response.extras?.resultCodes?.operationsResultCodes}"); @@ -256,7 +310,7 @@ class StellarWallet extends Bip39Wallet { @override Future get fees async { - int fee = await _getBaseFee(); + final int fee = await _getBaseFee(); return FeeObject( numberOfBlocksFast: 1, numberOfBlocksAverage: 1, @@ -294,7 +348,8 @@ class StellarWallet extends Bip39Wallet { stellar.AccountResponse accountResponse; try { - accountResponse = await stellarSdk.accounts + accountResponse = await (await stellarSdk) + .accounts .account((await getCurrentReceivingAddress())!.value) .onError((error, stackTrace) => throw error!); } catch (e) { @@ -315,7 +370,7 @@ class StellarWallet extends Bip39Wallet { } } - for (stellar.Balance balance in accountResponse.balances) { + for (final stellar.Balance balance in accountResponse.balances) { switch (balance.assetType) { case stellar.Asset.TYPE_NATIVE: final swBalance = Balance( @@ -352,7 +407,8 @@ class StellarWallet extends Bip39Wallet { @override Future updateChainHeight() async { try { - final height = await stellarSdk.ledgers + final height = await (await stellarSdk) + .ledgers .order(stellar.RequestBuilderOrder.DESC) .limit(1) .execute() @@ -370,7 +426,8 @@ class StellarWallet extends Bip39Wallet { @override Future updateNode() async { - _updateSdk(); + _stellarSdk?.httpClient.close(); + _stellarSdk = _getFreshSdk(); } @override @@ -378,10 +435,11 @@ class StellarWallet extends Bip39Wallet { try { final myAddress = (await getCurrentReceivingAddress())!; - List transactionList = []; + final List transactionList = []; stellar.Page payments; try { - payments = await stellarSdk.payments + payments = await (await stellarSdk) + .payments .forAccount(myAddress.value) .order(stellar.RequestBuilderOrder.DESC) .execute(); @@ -401,7 +459,7 @@ class StellarWallet extends Bip39Wallet { rethrow; } } - for (stellar.OperationResponse response in payments.records!) { + for (final stellar.OperationResponse response in payments.records!) { // PaymentOperationResponse por; if (response is stellar.PaymentOperationResponse) { final por = response; @@ -431,7 +489,8 @@ class StellarWallet extends Bip39Wallet { final List outputs = []; final List inputs = []; - OutputV2 output = OutputV2.isarCantDoRequiredInDefaultConstructor( + final OutputV2 output = + OutputV2.isarCantDoRequiredInDefaultConstructor( scriptPubKeyHex: "00", valueStringSats: amount.raw.toString(), addresses: [ @@ -439,7 +498,7 @@ class StellarWallet extends Bip39Wallet { ], walletOwns: addressTo == myAddress.value, ); - InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor( + final InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor( scriptSigHex: null, scriptSigAsm: null, sequence: null, @@ -459,8 +518,9 @@ class StellarWallet extends Bip39Wallet { int height = 0; //Query the transaction linked to the payment, // por.transaction returns a null sometimes - stellar.TransactionResponse tx = - await stellarSdk.transactions.transaction(por.transactionHash!); + final stellar.TransactionResponse tx = await (await stellarSdk) + .transactions + .transaction(por.transactionHash!); if (tx.hash.isNotEmpty) { fee = tx.feeCharged!; @@ -511,7 +571,8 @@ class StellarWallet extends Bip39Wallet { final List outputs = []; final List inputs = []; - OutputV2 output = OutputV2.isarCantDoRequiredInDefaultConstructor( + final OutputV2 output = + OutputV2.isarCantDoRequiredInDefaultConstructor( scriptPubKeyHex: "00", valueStringSats: amount.raw.toString(), addresses: [ @@ -520,7 +581,7 @@ class StellarWallet extends Bip39Wallet { ], walletOwns: caor.sourceAccount! == myAddress.value, ); - InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor( + final InputV2 input = InputV2.isarCantDoRequiredInDefaultConstructor( scriptSigHex: null, scriptSigAsm: null, sequence: null, @@ -541,8 +602,9 @@ class StellarWallet extends Bip39Wallet { int fee = 0; int height = 0; - final tx = - await stellarSdk.transactions.transaction(caor.transactionHash!); + final tx = await (await stellarSdk) + .transactions + .transaction(caor.transactionHash!); if (tx.hash.isNotEmpty) { fee = tx.feeCharged!; height = tx.ledger; From 6b6e2097127f725445ef011eb784411f2de6ad99 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 3 May 2024 19:24:38 -0500 Subject: [PATCH 35/35] revert to official package with tor support merged --- pubspec.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index fb5a9f31c..86531ddad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -156,10 +156,7 @@ dependencies: desktop_drop: ^0.4.1 nanodart: ^2.0.0 basic_utils: ^5.5.4 - stellar_flutter_sdk: # ^1.5.3 - git: # TODO [prio=low]: Revert to official package once Tor support is merged upstream. - url: https://github.com/cypherstack/stellar_flutter_sdk.git - ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 # tor-backport branch (based on 1.5.3). + stellar_flutter_sdk: ^1.7.8 bip340: ^0.2.0 # tezart: ^2.0.5 tezart: