Compare commits

..

17 Commits

Author SHA1 Message Date
Mark Sinclair f9b90ee62b GitHub Actions: fix up build-and-upload-binaries-ci.yml 2023-02-03 17:16:46 +00:00
farbanas f04fc452dc Merge branch 'release/v1.1.8' of github.com:nymtech/nym into release/v1.1.8 2023-01-31 14:05:53 +01:00
farbanas be90d03129 changelog cleanup 2023-01-31 14:01:25 +01:00
Bogdan-Ștefan Neacşu 0a3e42700c Fix vote soft error everywhere (#2941) 2023-01-31 14:58:47 +02:00
joeiacono2021 55d554701c Merge branch 'release/v1.1.8' of https://github.com/nymtech/nym into release/v1.1.8 2023-01-31 12:55:09 +00:00
joeiacono2021 19c4769260 Changelog Updates for RELEASE 1.1.8 on 31/01 2023-01-31 12:54:55 +00:00
farbanas 71aadc8e1b update versions for the release v1.1.8 2023-01-31 13:44:41 +01:00
Fouad 95340b5817 Feature/nym connect new UI (#2916)
* reduce window size

* use new highlight color

* use react router

* render new routes

* remove old help page

* render app routes

* update connection status UI

* remove service provider info

* remove unneeded additional step

* render title from route

* experimental warning as component

* render connection page

* nym-connect: connectivity status improvements (#2915)

* connect: keep track of connectivity state

* nym-connect: query connection state

* nym-connect: function for kicking of the health check task

* rustfmt

* nym-connect: extract out into function

* nym-connect: extract out events.rs

* add app version to menu page

* help page content and style updates

* update guide content

* use layout component on disconnect page

* handle gateway issues

* only show info modal once after connecting

* power button colors

* update stories and button colors

---------

Co-authored-by: Jon Häggblad <jon.haggblad@gmail.com>
2023-01-31 11:39:38 +00:00
Tommy Verrall 12751665bb white space 2023-01-31 09:14:56 -01:00
Tommy Verrall 01b86bcc0d updating qwerty contract addresses 2023-01-31 07:39:18 -01:00
Bogdan-Ștefan Neacşu c6ce8caaf7 Feature/fix soft multisig error (#2938) 2023-01-30 18:44:45 +02:00
Jędrzej Stuczyński 265713b9d2 Renamed 'initial_supply' to 'total_supply' in the 'circulating-supply' endpoint (#2932)
* Renamed 'initial_supply' to 'total_supply' in the 'circulating-supply' endpoint

* clippy issue messing with CI
2023-01-30 15:39:55 +00:00
Jon Häggblad c9af4721f3 wasm-utils: fix clippy 2023-01-30 10:46:11 +01:00
Pierre Dommerc 8c0ab7c697 feat(explorer): add routing score on gateway list (#2913)
* feat: adding routing score on gateway list

* feat(explorer): adding routing score on gateway list

* feat(explorer): add routing score on gateway list
2023-01-26 18:39:26 +01:00
Bogdan-Ștefan Neacșu 92b220ca4b Fix typo 2023-01-26 12:27:11 +02:00
Jędrzej Stuczyński c218cba96c Feature/default nym api (#2898)
* Setting default 'id' if not provided

* Modified 'NymConfig' to always require 'id'

* moved creation of nym-api directories away from 'override_config'

* missing optional id usage in nym-connect

* changelog

* Removed default value for '--id' argument
2023-01-25 15:49:28 +01:00
Jędrzej Stuczyński c958975fff Merge branch 'master' into release/v1.1.8 2023-01-25 13:40:20 +00:00
429 changed files with 4676 additions and 24947 deletions
Vendored
BIN
View File
Binary file not shown.
+28 -30
View File
@@ -2,33 +2,11 @@ name: Continuous integration
on:
push:
paths:
- 'clients/**'
- 'common/**'
- 'explorer-api/**'
- 'gateway/**'
- 'integrations/**'
- 'mixnode/**'
- 'sdk/rust/nym-sdk/**'
- 'service-providers/**'
- 'nym-api/**'
- 'nym-outfox/**'
- 'tools/nym-cli/**'
- 'tools/ts-rs-cli/**'
paths-ignore:
- 'explorer/**'
pull_request:
paths:
- 'clients/**'
- 'common/**'
- 'explorer-api/**'
- 'gateway/**'
- 'integrations/**'
- 'mixnode/**'
- 'sdk/rust/nym-sdk/**'
- 'service-providers/**'
- 'nym-api/**'
- 'nym-outfox/**'
- 'tools/nym-cli/**'
- 'tools/ts-rs-cli/**'
paths-ignore:
- 'explorer/**'
jobs:
build:
@@ -74,24 +52,44 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace
args: --workspace --all-features
- name: Run expensive tests
if: github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop' || github.event.pull_request.base.ref == 'master'
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace -- --ignored
args: --workspace --all-features -- --ignored
- uses: actions-rs/clippy-check@v1
name: Clippy checks
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace
args: --workspace --all-features
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --all-targets -- -D warnings
args: --workspace --all-targets --all-features -- -D warnings
# COCONUT stuff
- name: Build all binaries with coconut enabled
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --features=coconut
- name: Run all tests with coconut enabled
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --features=coconut
- name: Run clippy with coconut enabled
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --features=coconut -- -D warnings
-70
View File
@@ -1,70 +0,0 @@
name: Nym Connect for Android (rust)
on:
push:
paths:
- "nym-connect-android/src-tauri/**"
- "clients/client-core/**"
- "clients/socks5/**"
- "common/**"
- "gateway/gateway-requests/**"
- "contracts/vesting/**"
- "nym-api/nym-api-requests/**"
pull_request:
paths:
- "nym-connect-android/src-tauri/**"
- "clients/client-core/**"
- "clients/socks5/**"
- "common/**"
- "gateway/gateway-requests/**"
- "contracts/vesting/**"
- "nym-api/nym-api-requests/**"
jobs:
build:
#runs-on: [self-hosted, custom-linux]
runs-on: ubuntu-22.04
#env:
#RUSTC_WRAPPER: /home/ubuntu/.cargo/bin/sccache
#defaults:
#run:
#working-directory: nym-connect-android/src-tauri/
steps:
- name: Install Dependencies (Linux)
if: ${{ !env.ACT }}
run: |
sudo apt-get update
sudo apt-get -y install \
libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
libssl-dev \
libgtk-3-dev \
squashfs-tools \
libayatana-appindicator3-dev \
librsvg2-dev \
libsoup-3.0-dev \
libjavascriptcoregtk-4.1-dev
#continue-on-error: true
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy, rustfmt
- name: Check formatting
run: cargo fmt --manifest-path nym-connect-android/src-tauri/Cargo.toml -- --check
- name: Build all binaries
run: cargo build --manifest-path nym-connect-android/src-tauri/Cargo.toml
- name: Run all tests
run: cargo test --manifest-path nym-connect-android/src-tauri/Cargo.toml
- name: Clippy
run: cargo clippy --manifest-path nym-connect-android/src-tauri/Cargo.toml --all-targets -- -D warnings
+2 -17
View File
@@ -2,23 +2,8 @@ name: Nym Connect (rust)
on:
push:
paths:
- 'nym-connect/**'
- 'clients/client-core/**'
- 'clients/socks5/**'
- 'common/**'
- 'gateway/gateway-requests/**'
- 'contracts/vesting/**'
- 'nym-api/nym-api-requests/**'
pull_request:
paths:
- 'nym-connect/**'
- 'clients/client-core/**'
- 'clients/socks5/**'
- 'common/**'
- 'gateway/gateway-requests/**'
- 'contracts/vesting/**'
- 'nym-api/nym-api-requests/**'
paths-ignore:
- 'explorer/**'
jobs:
build:
+8 -2
View File
@@ -6,11 +6,17 @@ on:
jobs:
build:
if: ${{ startsWith(github.ref, 'refs/tags/nym-contracts-') && github.event_name == 'release' }}
runs-on: [self-hosted, custom-runner-linux]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Check the release tag starts with `nym-contracts-`
if: startsWith(github.ref, 'refs/tags/nym-contracts-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-contracts-...')
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
+3 -5
View File
@@ -2,13 +2,11 @@ name: Contracts
on:
push:
paths:
- 'contracts/**'
- 'common/**'
paths-ignore:
- 'explorer/**'
pull_request:
paths-ignore:
- 'contracts/**'
- 'common/**'
- 'explorer/**'
jobs:
matrix_prep:
-127
View File
@@ -1,127 +0,0 @@
name: NC Android APK Release
on:
workflow_dispatch:
push:
branches:
- "release/nc-android-v[0-9].[0-9].[0-9]*"
jobs:
build:
name: Build APK
runs-on: ubuntu-latest
env:
ANDROID_HOME: ${{ github.workspace }}/android-sdk
NDK_VERSION: 25.1.8937393
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/${{ env.NDK_VERSION }}
SDK_PLATFORM_VERSION: android-33
SDK_BUILDTOOLS_VERSION: 33.0.1
steps:
- name: Install Dependencies (Linux)
# https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux/#1-system-dependencies
run: |
sudo apt-get update
sudo apt-get -y install \
libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
libssl-dev \
libgtk-3-dev \
squashfs-tools \
libayatana-appindicator3-dev \
librsvg2-dev
- name: Install Java
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
- name: Install Android SDK manager
# https://developer.android.com/studio/command-line/sdkmanager
run: |
curl -sS https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip -o cmdline-tools.zip
unzip cmdline-tools.zip
mkdir -p $ANDROID_HOME/cmdline-tools/latest
mv cmdline-tools/* $ANDROID_HOME/cmdline-tools/latest
rm -rf cmdline-tools
- name: Install Android S/NDK
run: |
echo y | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
echo y | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \
"platforms;$SDK_PLATFORM_VERSION" \
"platform-tools" \
"ndk;$NDK_VERSION" \
"build-tools;$SDK_BUILDTOOLS_VERSION"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install tauri cli
run: cargo install tauri-cli --version "^2.0.0-alpha.2"
- name: Install rust android targets
run: |
rustup target add aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install yarn
run: |
npm i -g yarn
yarn --version
- name: Checkout
uses: actions/checkout@v3
- name: Build frontend code
run: |
yarn install --frozen-lockfile
yarn build
yarn workspace @nym/nym-connect-android webpack:prod
- name: Build APK
working-directory: nym-connect-android
env:
WRY_ANDROID_PACKAGE: net.nymtech.nym_connect_android
WRY_ANDROID_LIBRARY: nym_connect_android
# TODO build with release profile (--release), it will requires
# to sign the APK. For now build with debug profile to avoid that
run: cargo tauri android build --debug --apk
# TODO add the version number to APK name
- name: Rename APK artifact
run: |
mv nym-connect-android/src-tauri/gen/android/nym_connect_android/app/build/outputs/apk/universal/debug/app-universal-debug.apk \
nym-connect-debug.apk
- name: Upload APK artifact
uses: actions/upload-artifact@v3
with:
name: nc-apk-debug
path: nym-connect-debug.apk
publish:
name: Publish APK
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download binary artifact
uses: actions/download-artifact@v3
with:
name: nc-apk-debug
path: apk
# TODO add a step to upload the APK somewhere
# - name: Publish
# uses: ???
+1 -1
View File
@@ -10,7 +10,6 @@ env:
jobs:
publish-nym:
if: ${{ startsWith(github.ref, 'refs/tags/nym-explorer-api-') && (github.event_name == 'release' || github.event_name == 'workflow_dispatch') }}
strategy:
fail-fast: false
matrix:
@@ -25,6 +24,7 @@ jobs:
continue-on-error: true
- name: Check the release tag starts with `nym-explorer-api-`
if: startsWith(github.ref, 'refs/tags/nym-explorer-api-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
+36 -4
View File
@@ -77,7 +77,7 @@ jobs:
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' || matrix.os == 'ubuntu-20.04' }}
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
@@ -86,7 +86,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace -- --ignored
args: --workspace --all-features -- --ignored
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
@@ -99,14 +99,14 @@ jobs:
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace
args: --all-features
- name: Run clippy
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != 'nightly' }}
with:
command: clippy
args: --workspace --all-targets -- -D warnings
args: --workspace --all-targets --all-features -- -D warnings
- name: Reclaim some disk space
uses: actions-rs/cargo@v1
@@ -114,6 +114,38 @@ jobs:
with:
command: clean
# COCONUT stuff
- name: Build all binaries with coconut enabled
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run all tests with coconut enabled
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run clippy with coconut enabled
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != 'nightly' }}
with:
command: clippy
args: --workspace --all-targets --features=coconut -- -D warnings
# nym-wallet (the rust part)
- name: Build nym-wallet rust code
uses: actions-rs/cargo@v1
@@ -117,6 +117,38 @@ jobs:
with:
command: clean
# COCONUT stuff
- name: Build all binaries with coconut enabled
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run all tests with coconut enabled
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run clippy with coconut enabled
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != 'nightly' }}
with:
command: clippy
args: --workspace --all-targets --features=coconut -- -D warnings
# nym-wallet (the rust part)
- name: Build nym-wallet rust code
uses: actions-rs/cargo@v1
@@ -117,6 +117,38 @@ jobs:
with:
command: clean
# COCONUT stuff
- name: Build all binaries with coconut enabled
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run all tests with coconut enabled
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --features=coconut
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- name: Run clippy with coconut enabled
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != 'nightly' }}
with:
command: clippy
args: --workspace --all-targets --features=coconut -- -D warnings
# nym-wallet (the rust part)
- name: Build nym-wallet rust code
uses: actions-rs/cargo@v1
+1 -1
View File
@@ -10,7 +10,6 @@ env:
jobs:
publish-nym-cli:
if: ${{ startsWith(github.ref, 'refs/tags/nym-cli-') && (github.event_name == 'release' || github.event_name = 'workflow_dispatch') }}
strategy:
fail-fast: false
matrix:
@@ -21,6 +20,7 @@ jobs:
- uses: actions/checkout@v3
- name: Check the release tag starts with `nym-cli-`
if: startsWith(github.ref, 'refs/tags/nym-cli-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
@@ -10,7 +10,6 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
@@ -20,6 +19,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Check the release tag starts with `nym-connect-`
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-connect-...')
- name: Node v16
uses: actions/setup-node@v3
with:
@@ -10,11 +10,10 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
platform: [custom-runner-linux]
platform: [ubuntu-20.04]
runs-on: ${{ matrix.platform }}
steps:
@@ -25,12 +24,17 @@ jobs:
sudo apt-get update &&
sudo apt-get install -y webkit2gtk-4.0 libayatana-appindicator3-dev
continue-on-error: true
- name: Check the release tag starts with `nym-connect-`
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-connect-...')
- name: Node v16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
@@ -10,7 +10,6 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
@@ -28,6 +27,13 @@ jobs:
- uses: actions/checkout@v3
- name: Check the release tag starts with `nym-connect-`
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-connect-...')
- name: Import signing certificate
env:
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
+8 -4
View File
@@ -16,11 +16,10 @@ env:
jobs:
publish-nym:
if: ${{ startsWith(github.ref, 'refs/tags/nym-binaries-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
platform: [custom-runner-linux]
platform: [ubuntu-20.04]
runs-on: ${{ matrix.platform }}
steps:
@@ -29,6 +28,13 @@ jobs:
- name: Install Dependencies (Linux)
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
continue-on-error: true
- name: Check the release tag starts with `nym-binaries-`
if: startsWith(github.ref, 'refs/tags/nym-binaries-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-binaries-...')
- name: Sets env vars for tokio if set in manual dispatch inputs
run: |
@@ -51,7 +57,6 @@ jobs:
with:
name: my-artifact
path: |
target/release/explorer-api
target/release/nym-client
target/release/nym-gateway
target/release/nym-mixnode
@@ -67,7 +72,6 @@ jobs:
if: github.event_name == 'release'
with:
files: |
target/release/explorer-api
target/release/nym-client
target/release/nym-gateway
target/release/nym-mixnode
@@ -10,7 +10,6 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
@@ -20,6 +19,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Check the release tag starts with `nym-wallet-`
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-wallet-...')
- name: Node v16
uses: actions/setup-node@v3
with:
@@ -9,11 +9,10 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
platform: [custom-runner-linux]
platform: [ubuntu-20.04]
runs-on: ${{ matrix.platform }}
steps:
@@ -24,12 +23,17 @@ jobs:
sudo apt-get update &&
sudo apt-get install -y webkit2gtk-4.0
continue-on-error: true
- name: Check the release tag starts with `nym-wallet-`
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-wallet-...')
- name: Node v16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
@@ -9,7 +9,6 @@ defaults:
jobs:
publish-tauri:
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
strategy:
fail-fast: false
matrix:
@@ -27,6 +26,13 @@ jobs:
- uses: actions/checkout@v3
- name: Check the release tag starts with `nym-wallet-`
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release tag did not start with nym-wallet-...')
- name: Import signing certificate
env:
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
-1
View File
@@ -6,7 +6,6 @@ on:
- 'ts-packages/**'
- 'sdk/typescript/**'
- nym-connect
- nym-connect-android
- nym-wallet
jobs:
+4 -11
View File
@@ -2,17 +2,11 @@ name: Nym Wallet (rust)
on:
push:
paths:
- 'nym-wallet/**'
- 'common/**'
- 'contracts/vesting/**'
- 'nym-api/nym-api-requests/**'
paths-ignore:
- 'explorer/**'
pull_request:
paths:
- 'nym-wallet/**'
- 'common/**'
- 'contracts/vesting/**'
- 'nym-api/nym-api-requests/**'
paths-ignore:
- 'explorer/**'
jobs:
build:
@@ -22,7 +16,6 @@ jobs:
steps:
- name: Install Dependencies (Linux)
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev squashfs-tools
continue-on-error: true
- name: Check out repository code
uses: actions/checkout@v2
+7 -7
View File
@@ -2,13 +2,8 @@ name: Wasm Client
on:
pull_request:
paths:
- 'clients/webassembly/**'
- 'clients/client-core/**'
- 'common/**'
- 'contracts/**'
- 'gateway/gateway-requests/**'
- 'nym-api/nym-api-requests/**'
paths-ignore:
- 'explorer/**'
jobs:
wasm:
@@ -29,6 +24,11 @@ jobs:
command: build
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown
- uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --features=coconut
- uses: actions-rs/cargo@v1
with:
command: fmt
-1
View File
@@ -42,4 +42,3 @@ envs/qwerty.env
Cargo.lock
nym-connect/Cargo.lock
.parcel-cache
**/.DS_Store
+1 -11
View File
@@ -4,16 +4,6 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
# [Unreleased]
### Added
- remove coconut feature and unify builds ([#2890])
- native-client: is now capable of listening for requests on sockets different than `127.0.0.1` ([#2939]). This can be specified via `--host` flag during `init` or `run`. Alternatively a custom `host` can be set in `config.toml` file under `socket` section.
- dkg resharing mode ([#2936])
[#2890]: https://github.com/nymtech/nym/pull/2890
[#2939]: https://github.com/nymtech/nym/pull/2939
[#2936]: https://github.com/nymtech/nym/pull/2936
# [v1.1.8] (2023-01-31)
### Added
@@ -28,7 +18,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
- nym-api: an `--id` flag is now always explicitly required ([#2873])
[#2754]: https://github.com/nymtech/nym/issues/2754
[#2810]: https://github.com/nymtech/nym/issues/2810
[#2839]: https://github.com/nymtech/nym/issues/2810
[#2931]: https://github.com/nymtech/nym/issues/2931
[#1902]: https://github.com/nymtech/nym/issues/1902
[#2873]: https://github.com/nymtech/nym/issues/2873
Generated
+57 -83
View File
@@ -30,7 +30,7 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cipher 0.3.0",
"cpufeatures",
"ctr 0.8.0",
@@ -43,7 +43,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cipher 0.4.3",
"cpufeatures",
]
@@ -375,7 +375,7 @@ dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if",
"cfg-if 1.0.0",
"constant_time_eq",
"digest 0.10.6",
]
@@ -458,7 +458,6 @@ dependencies = [
name = "build-information"
version = "0.1.0"
dependencies = [
"serde",
"vergen 7.5.0",
]
@@ -501,6 +500,12 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -523,7 +528,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fc89c7c5b9e7a02dfe45cd2367bae382f9ed31c61ca8debe5f827c420a2f08"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cipher 0.4.3",
"cpufeatures",
]
@@ -702,7 +707,7 @@ dependencies = [
[[package]]
name = "client-core"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"async-trait",
"client-connections",
@@ -827,7 +832,7 @@ dependencies = [
name = "config"
version = "0.1.0"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"handlebars",
"log",
"network-defaults",
@@ -1047,7 +1052,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -1055,6 +1060,7 @@ name = "credential"
version = "0.1.0"
dependencies = [
"bip39",
"cfg-if 0.1.10",
"clap 4.1.3",
"coconut-interface",
"completions",
@@ -1175,7 +1181,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-utils",
]
@@ -1185,7 +1191,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-epoch",
"crossbeam-utils",
]
@@ -1197,7 +1203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
dependencies = [
"autocfg 1.1.0",
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-utils",
"memoffset",
"scopeguard",
@@ -1209,7 +1215,7 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"crossbeam-utils",
]
@@ -1219,7 +1225,7 @@ version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -1554,7 +1560,7 @@ version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"num_cpus",
]
@@ -1564,7 +1570,7 @@ version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"hashbrown 0.12.3",
"lock_api",
"once_cell",
@@ -1790,7 +1796,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -1892,7 +1898,7 @@ dependencies = [
[[package]]
name = "explorer-api"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"chrono",
"clap 4.1.3",
@@ -2170,7 +2176,6 @@ dependencies = [
"gateway-requests",
"getrandom 0.2.8",
"log",
"mobile-storage",
"network-defaults",
"nymsphinx",
"pemstore",
@@ -2253,7 +2258,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
@@ -2266,7 +2271,7 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
@@ -2831,7 +2836,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
@@ -2938,7 +2943,7 @@ version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"ecdsa",
"elliptic-curve",
"sec1",
@@ -3006,7 +3011,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45ba81a1f5f24396b37211478aff7fbcd605dd4544df8dbed07b9da3c2057aee"
dependencies = [
"byteorder",
"cfg-if",
"cfg-if 1.0.0",
"hex",
"hidapi",
"ledger-transport",
@@ -3105,7 +3110,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -3122,7 +3127,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"generator",
"scoped-tls",
"serde",
@@ -3276,14 +3281,6 @@ dependencies = [
"version-checker",
]
[[package]]
name = "mobile-storage"
version = "0.1.0"
dependencies = [
"async-trait",
"thiserror",
]
[[package]]
name = "multer"
version = "2.0.4"
@@ -3340,7 +3337,7 @@ dependencies = [
name = "network-defaults"
version = "0.1.0"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"dotenv",
"hex-literal",
"once_cell",
@@ -3439,14 +3436,14 @@ dependencies = [
[[package]]
name = "nym-api"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"anyhow",
"async-trait",
"bip39",
"bs58",
"build-information",
"cfg-if",
"cfg-if 1.0.0",
"clap 4.1.3",
"coconut-bandwidth-contract-common",
"coconut-dkg-common",
@@ -3537,7 +3534,7 @@ dependencies = [
[[package]]
name = "nym-cli"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"anyhow",
"base64 0.13.1",
@@ -3566,7 +3563,7 @@ dependencies = [
"base64 0.13.1",
"bip39",
"bs58",
"cfg-if",
"cfg-if 1.0.0",
"clap 4.1.3",
"coconut-bandwidth-contract-common",
"coconut-dkg-common",
@@ -3595,7 +3592,7 @@ dependencies = [
[[package]]
name = "nym-client"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"build-information",
"clap 4.1.3",
@@ -3635,7 +3632,7 @@ dependencies = [
[[package]]
name = "nym-gateway"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"anyhow",
"async-trait",
@@ -3687,7 +3684,7 @@ dependencies = [
[[package]]
name = "nym-mixnode"
version = "1.1.9"
version = "1.1.8"
dependencies = [
"anyhow",
"atty",
@@ -3732,10 +3729,9 @@ dependencies = [
[[package]]
name = "nym-network-requester"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"async-trait",
"build-information",
"clap 4.1.3",
"client-connections",
"completions",
@@ -3753,7 +3749,6 @@ dependencies = [
"rand 0.7.3",
"reqwest",
"serde",
"service-providers-common",
"socks5-requests",
"sqlx 0.6.2",
"statistics-common",
@@ -3766,7 +3761,7 @@ dependencies = [
[[package]]
name = "nym-network-statistics"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"dirs",
"log",
@@ -3823,7 +3818,7 @@ dependencies = [
[[package]]
name = "nym-socks5-client"
version = "1.1.8"
version = "1.1.7"
dependencies = [
"build-information",
"clap 4.1.3",
@@ -3842,7 +3837,6 @@ dependencies = [
"lazy_static",
"log",
"logging",
"mobile-storage",
"network-defaults",
"nymsphinx",
"ordered-buffer",
@@ -3853,7 +3847,6 @@ dependencies = [
"rand 0.7.3",
"serde",
"serde_json",
"service-providers-common",
"socks5-requests",
"tap",
"task",
@@ -4105,7 +4098,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
dependencies = [
"bitflags",
"cfg-if",
"cfg-if 1.0.0",
"foreign-types",
"libc",
"once_cell",
@@ -4208,7 +4201,7 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
@@ -4222,7 +4215,7 @@ version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec 1.10.0",
@@ -4456,7 +4449,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef234e08c11dfcb2e56f79fd70f6f2eb7f025c0ce2333e82f4f0518ecad30c6"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
@@ -5497,22 +5490,6 @@ dependencies = [
"serde",
]
[[package]]
name = "service-providers-common"
version = "0.1.0"
dependencies = [
"anyhow",
"async-trait",
"build-information",
"log",
"nym-sdk",
"nymsphinx-anonymous-replies",
"serde",
"serde_json",
"thiserror",
"tokio",
]
[[package]]
name = "sha-1"
version = "0.9.8"
@@ -5520,7 +5497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer 0.9.0",
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
@@ -5532,7 +5509,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.6",
]
@@ -5543,7 +5520,7 @@ version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.6",
]
@@ -5555,7 +5532,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer 0.9.0",
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
@@ -5567,7 +5544,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.6",
]
@@ -5694,9 +5671,6 @@ name = "socks5-requests"
version = "0.1.0"
dependencies = [
"nymsphinx-addressing",
"serde",
"serde_json",
"service-providers-common",
"thiserror",
]
@@ -6094,7 +6068,7 @@ version = "0.24.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54cb4ebf3d49308b99e6e9dc95e989e2fdbdc210e4f67c39db0bb89ba927001c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"core-foundation-sys",
"libc",
"ntapi",
@@ -6127,7 +6101,7 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"fastrand",
"libc",
"redox_syscall",
@@ -6585,7 +6559,7 @@ version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"log",
"pin-project-lite",
"tracing-attributes",
@@ -6941,7 +6915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cf88d94e969e7956d924ba70741316796177fa0c79a2c9f4ab04998d96e966e"
dependencies = [
"anyhow",
"cfg-if",
"cfg-if 1.0.0",
"chrono",
"enum-iterator 0.8.1",
"getset",
@@ -6958,7 +6932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "571b69f690c855821462709b6f41d42ceccc316fbd17b60bd06d06928cfe6a99"
dependencies = [
"anyhow",
"cfg-if",
"cfg-if 1.0.0",
"enum-iterator 1.2.0",
"getset",
"git2 0.15.0",
@@ -7053,7 +7027,7 @@ version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
@@ -7078,7 +7052,7 @@ version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
+1 -8
View File
@@ -38,7 +38,6 @@ members = [
"common/cosmwasm-smart-contracts/mixnet-contract",
"common/cosmwasm-smart-contracts/multisig-contract",
"common/cosmwasm-smart-contracts/vesting-contract",
"common/mobile-storage",
"common/credential-storage",
"common/credentials",
"common/crypto",
@@ -76,7 +75,6 @@ members = [
"integrations/bity",
"mixnode",
"sdk/rust/nym-sdk",
"service-providers/common",
"service-providers/network-requester",
"service-providers/network-statistics",
"nym-api",
@@ -97,7 +95,7 @@ default-members = [
"explorer-api",
]
exclude = ["explorer", "contracts", "clients/webassembly", "nym-wallet", "nym-connect", "nym-connect-android"]
exclude = ["explorer", "contracts", "clients/webassembly", "nym-wallet", "nym-connect"]
[workspace.package]
authors = ["Nym Technologies SA"]
@@ -106,9 +104,4 @@ homepage = "https://nymtech.net"
edition = "2021"
[workspace.dependencies]
async-trait = "0.1.63"
log = "0.4"
thiserror = "1.0.38"
serde = "1.0.152"
serde_json = "1.0.91"
tokio = "1.24.1"
+13 -6
View File
@@ -2,10 +2,10 @@ test: clippy-all cargo-test wasm fmt
test-all: test cargo-test-expensive
no-clippy: build cargo-test wasm fmt
happy: fmt clippy-happy test
clippy-all: clippy-main clippy-all-contracts clippy-all-wallet clippy-all-connect clippy-all-wasm-client
clippy-all: clippy-main clippy-coconut clippy-all-contracts clippy-all-wallet clippy-all-connect clippy-all-wasm-client
clippy-happy: clippy-happy-main clippy-happy-contracts clippy-happy-wallet clippy-happy-connect
cargo-test: test-main test-contracts test-wallet test-connect
cargo-test-expensive: test-main-expensive test-contracts-expensive test-wallet-expensive test-connect-expensive
cargo-test: test-main test-contracts test-wallet test-connect test-coconut
cargo-test-expensive: test-main-expensive test-contracts-expensive test-wallet-expensive test-connect-expensive test-coconut-expensive
build: build-contracts build-wallet build-main build-connect build-wasm-client
fmt: fmt-main fmt-contracts fmt-wallet fmt-connect fmt-wasm-client
@@ -24,6 +24,9 @@ clippy-happy-connect:
clippy-main:
cargo clippy --workspace -- -D warnings
clippy-coconut:
cargo clippy --workspace --features coconut -- -D warnings
clippy-wasm:
cargo clippy --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --workspace -- -D warnings
@@ -43,9 +46,16 @@ clippy-all-wasm-client:
test-main:
cargo test --workspace
test-coconut:
cargo test --workspace --features coconut
test-main-expensive:
cargo test --workspace -- --ignored
test-coconut-expensive:
cargo test --workspace --features coconut -- --ignored
test-contracts:
cargo test --manifest-path contracts/Cargo.toml --all-features
@@ -109,6 +119,3 @@ mixnet-opt: wasm
generate-typescript:
cd tools/ts-rs-cli && cargo run && cd ../..
yarn types:lint:fix
run-validator-tests:
cd nym-api/tests/functional_test && yarn test:qa
BIN
View File
Binary file not shown.
+1
View File
@@ -82,4 +82,5 @@ sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "sqlite", "macro
default = []
fs-surb-storage = ["sqlx"]
wasm = ["gateway-client/wasm"]
coconut = ["gateway-client/coconut", "gateway-requests/coconut"]
@@ -1,11 +0,0 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
//
use crate::{client::replies::reply_storage, config::DebugConfig};
pub fn setup_empty_reply_surb_backend(debug_config: &DebugConfig) -> reply_storage::Empty {
reply_storage::Empty {
min_surb_threshold: debug_config.minimum_reply_surb_storage_threshold,
max_surb_threshold: debug_config.maximum_reply_surb_storage_threshold,
}
}
@@ -49,8 +49,6 @@ use super::received_buffer::ReceivedBufferMessage;
#[cfg(all(not(target_arch = "wasm32"), feature = "fs-surb-storage"))]
pub mod non_wasm_helpers;
pub mod helpers;
pub struct ClientInput {
pub connection_command_sender: ConnectionCommandSender,
pub input_sender: InputMessageSender,
@@ -291,6 +289,10 @@ where
if gateway_id.is_empty() {
return Err(ClientCoreError::GatewayIdUnknown);
}
let gateway_owner = self.gateway_config.gateway_owner.clone();
if gateway_owner.is_empty() {
return Err(ClientCoreError::GatewayOwnerUnknown);
}
let gateway_address = self.gateway_config.gateway_listener.clone();
if gateway_address.is_empty() {
return Err(ClientCoreError::GatwayAddressUnknown);
@@ -310,6 +312,7 @@ where
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
shared_key,
mixnet_message_sender,
ack_sender,
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::client::replies::reply_storage::{
fs_backend, CombinedReplyStorage, ReplyStorageBackend,
self, fs_backend, CombinedReplyStorage, ReplyStorageBackend,
};
use crate::config::DebugConfig;
use crate::error::ClientCoreError;
@@ -98,3 +98,10 @@ pub async fn setup_fs_reply_surb_backend<P: AsRef<Path>>(
Ok(setup_inactive_backend(debug_config))
}
}
pub fn setup_empty_reply_surb_backend(debug_config: &DebugConfig) -> reply_storage::Empty {
reply_storage::Empty {
min_surb_threshold: debug_config.minimum_reply_surb_storage_threshold,
max_surb_threshold: debug_config.maximum_reply_surb_storage_threshold,
}
}
@@ -81,11 +81,7 @@ pub struct Config {
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
/// for more even though in theory they wouldn't need to.
maximum_reply_surb_rerequest_waiting_period: Duration,
/// Defines maximum amount of time the client is going to wait for reply surbs before
/// deciding it's never going to get them and would drop all pending messages
maximum_reply_surb_drop_waiting_period: Duration,
maximum_reply_surb_waiting_period: Duration,
/// Defines maximum amount of time given reply surb is going to be valid for.
/// This is going to be superseded by key rotation once implemented.
@@ -123,8 +119,7 @@ impl<'a> From<&'a Config> for reply_controller::Config {
cfg.minimum_reply_surb_request_size,
cfg.maximum_reply_surb_request_size,
cfg.maximum_allowed_reply_surb_request_size,
cfg.maximum_reply_surb_rerequest_waiting_period,
cfg.maximum_reply_surb_drop_waiting_period,
cfg.maximum_reply_surb_waiting_period,
cfg.maximum_reply_surb_age,
cfg.maximum_reply_key_age,
)
@@ -166,10 +161,8 @@ impl Config {
.maximum_reply_surb_request_size,
maximum_allowed_reply_surb_request_size: base_client_debug_config
.maximum_allowed_reply_surb_request_size,
maximum_reply_surb_rerequest_waiting_period: base_client_debug_config
.maximum_reply_surb_rerequest_waiting_period,
maximum_reply_surb_drop_waiting_period: base_client_debug_config
.maximum_reply_surb_drop_waiting_period,
maximum_reply_surb_waiting_period: base_client_debug_config
.maximum_reply_surb_waiting_period,
maximum_reply_surb_age: base_client_debug_config.maximum_reply_surb_age,
maximum_reply_key_age: base_client_debug_config.maximum_reply_key_age,
}
@@ -30,8 +30,7 @@ pub struct Config {
min_surb_request_size: u32,
max_surb_request_size: u32,
maximum_allowed_reply_surb_request_size: u32,
max_surb_rerequest_waiting_period: Duration,
max_surb_drop_waiting_period: Duration,
max_surb_waiting_period: Duration,
max_reply_surb_age: Duration,
max_reply_key_age: Duration,
}
@@ -41,8 +40,7 @@ impl Config {
min_surb_request_size: u32,
max_surb_request_size: u32,
maximum_allowed_reply_surb_request_size: u32,
max_surb_rerequest_waiting_period: Duration,
max_surb_drop_waiting_period: Duration,
max_surb_waiting_period: Duration,
max_reply_surb_age: Duration,
max_reply_key_age: Duration,
) -> Self {
@@ -50,8 +48,7 @@ impl Config {
min_surb_request_size,
max_surb_request_size,
maximum_allowed_reply_surb_request_size,
max_surb_rerequest_waiting_period,
max_surb_drop_waiting_period,
max_surb_waiting_period,
max_reply_surb_age,
max_reply_key_age,
}
@@ -745,13 +742,9 @@ where
let diff = now - last_received_time;
if diff > self.config.max_surb_rerequest_waiting_period {
if diff > self.config.max_surb_drop_waiting_period {
to_remove.push(*pending_reply_target)
} else {
debug!("We haven't received any surbs in {:?} from {pending_reply_target}. Going to explicitly ask for more", diff);
to_request.push(*pending_reply_target);
}
if diff > self.config.max_surb_waiting_period {
warn!("We haven't received any surbs in {:?} from {pending_reply_target}. Going to explicitly ask for more", diff);
to_request.push(*pending_reply_target);
}
}
+6 -23
View File
@@ -45,8 +45,7 @@ const DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 100;
const DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE: u32 = 500;
const DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD: Duration = Duration::from_secs(10);
const DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD: Duration = Duration::from_secs(5 * 60);
const DEFAULT_MAXIMUM_REPLY_SURB_WAITING_PERIOD: Duration = Duration::from_secs(10);
// 12 hours
const DEFAULT_MAXIMUM_REPLY_SURB_AGE: Duration = Duration::from_secs(12 * 60 * 60);
@@ -171,15 +170,10 @@ impl<T> Config<T> {
self
}
pub fn set_gateway_endpoint(&mut self, gateway_endpoint: GatewayEndpointConfig) {
pub fn with_gateway_endpoint(&mut self, gateway_endpoint: GatewayEndpointConfig) {
self.client.gateway_endpoint = gateway_endpoint;
}
pub fn with_gateway_endpoint(mut self, gateway_endpoint: GatewayEndpointConfig) -> Self {
self.client.gateway_endpoint = gateway_endpoint;
self
}
pub fn with_gateway_id<S: Into<String>>(&mut self, id: S) {
self.client.gateway_endpoint.gateway_id = id.into();
}
@@ -378,12 +372,8 @@ impl<T> Config<T> {
self.debug.maximum_allowed_reply_surb_request_size
}
pub fn get_maximum_reply_surb_rerequest_waiting_period(&self) -> Duration {
self.debug.maximum_reply_surb_rerequest_waiting_period
}
pub fn get_maximum_reply_surb_drop_waiting_period(&self) -> Duration {
self.debug.maximum_reply_surb_drop_waiting_period
pub fn get_maximum_reply_surb_waiting_period(&self) -> Duration {
self.debug.maximum_reply_surb_waiting_period
}
pub fn get_maximum_reply_surb_age(&self) -> Duration {
@@ -673,12 +663,7 @@ pub struct DebugConfig {
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
/// for more even though in theory they wouldn't need to.
#[serde(with = "humantime_serde")]
pub maximum_reply_surb_rerequest_waiting_period: Duration,
/// Defines maximum amount of time the client is going to wait for reply surbs before
/// deciding it's never going to get them and would drop all pending messages
#[serde(with = "humantime_serde")]
pub maximum_reply_surb_drop_waiting_period: Duration,
pub maximum_reply_surb_waiting_period: Duration,
/// Defines maximum amount of time given reply surb is going to be valid for.
/// This is going to be superseded by key rotation once implemented.
@@ -719,9 +704,7 @@ impl Default for DebugConfig {
minimum_reply_surb_request_size: DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE,
maximum_reply_surb_request_size: DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE,
maximum_allowed_reply_surb_request_size: DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE,
maximum_reply_surb_rerequest_waiting_period:
DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD,
maximum_reply_surb_drop_waiting_period: DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD,
maximum_reply_surb_waiting_period: DEFAULT_MAXIMUM_REPLY_SURB_WAITING_PERIOD,
maximum_reply_surb_age: DEFAULT_MAXIMUM_REPLY_SURB_AGE,
maximum_reply_key_age: DEFAULT_MAXIMUM_REPLY_KEY_AGE,
}
+1
View File
@@ -63,6 +63,7 @@ pub(super) async fn register_with_gateway(
let mut gateway_client: GatewayClient<SigningNyxdClient> = GatewayClient::new_init(
gateway.clients_address(),
gateway.identity_key,
gateway.owner.clone(),
our_identity.clone(),
timeout,
);
+3
View File
@@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
bip39 = "1.0.1"
cfg-if = "0.1"
clap = { version = "4.0", features = ["cargo", "derive"] }
rand = "0.7.3"
serde = { version = "1.0", features = ["derive"] }
@@ -24,3 +25,5 @@ network-defaults = { path = "../../common/network-defaults" }
pemstore = { path = "../../common/pemstore" }
validator-client = { path = "../../common/client-libs/validator-client", features = ["nyxd-client"] }
[features]
coconut = ["credentials/coconut"]
-6
View File
@@ -82,11 +82,6 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor
let config = Config::try_from_nym_network_details(&network_details)?;
let client = validator_client::Client::new_query(config)?;
let epoch_id = client.nyxd.get_current_epoch().await?.epoch_id;
let threshold = client
.nyxd
.get_current_epoch_threshold()
.await?
.ok_or(CredentialClientError::NoThreshold)?;
let coconut_api_clients = CoconutApiClient::all_coconut_api_clients(&client, epoch_id).await?;
let params = Parameters::new(TOTAL_ATTRIBUTES).unwrap();
@@ -103,7 +98,6 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor
&params,
&bandwidth_credential_attributes,
&coconut_api_clients,
threshold,
)
.await?;
println!("Signature: {:?}", signature.to_bs58());
-3
View File
@@ -34,7 +34,4 @@ pub enum CredentialClientError {
#[error("Could not use shared storage")]
SharedStorageError(#[from] StorageError),
#[error("Threshold not set yet")]
NoThreshold,
}
+45 -36
View File
@@ -1,47 +1,56 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
mod client;
mod commands;
mod error;
mod state;
cfg_if::cfg_if! {
if #[cfg(feature = "coconut")] {
use commands::*;
use completions::fig_generate;
use config::{DATA_DIR, DB_FILE_NAME};
use error::Result;
use network_defaults::setup_env;
mod client;
mod commands;
mod error;
mod state;
use clap::{CommandFactory, Parser};
use error::Result;
use network_defaults::setup_env;
use completions::fig_generate;
use commands::*;
use config::{DATA_DIR, DB_FILE_NAME};
#[derive(Parser)]
#[clap(author = "Nymtech", version, about)]
struct Cli {
/// Path pointing to an env file that configures the client.
#[clap(short, long)]
pub(crate) config_env_file: Option<std::path::PathBuf>,
use clap::{CommandFactory, Parser};
#[clap(subcommand)]
pub(crate) command: Command,
}
#[derive(Parser)]
#[clap(author = "Nymtech", version, about)]
struct Cli {
/// Path pointing to an env file that configures the client.
#[clap(short, long)]
pub(crate) config_env_file: Option<std::path::PathBuf>,
#[tokio::main]
async fn main() -> Result<()> {
let args = Cli::parse();
setup_env(args.config_env_file.as_ref());
let bin_name = "nym-credential-client";
match args.command {
Command::Run(r) => {
let db_path = r.client_home_directory.join(DATA_DIR).join(DB_FILE_NAME);
let shared_storage = credential_storage::initialise_storage(db_path).await;
let state = deposit(&r.nyxd_url, &r.mnemonic, r.amount).await?;
get_credential(&state, shared_storage).await?;
#[clap(subcommand)]
pub(crate) command: Command,
}
Command::Completions(c) => c.generate(&mut crate::Cli::command(), bin_name),
Command::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name),
}
Ok(())
#[tokio::main]
async fn main() -> Result<()> {
let args = Cli::parse();
setup_env(args.config_env_file.as_ref());
let bin_name = "nym-credential-client";
match args.command {
Command::Run(r) => {
let db_path = r.client_home_directory.join(DATA_DIR).join(DB_FILE_NAME);
let shared_storage = credential_storage::initialise_storage(db_path).await;
let state = deposit(&r.nyxd_url, &r.mnemonic, r.amount).await?;
get_credential(&state, shared_storage).await?;
}
Command::Completions(c) => c.generate(&mut crate::Cli::command(), bin_name),
Command::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name)
}
Ok(())
}
} else {
fn main() {
println!("Crate only designed for coconut feature");
}
}
}
+5 -2
View File
@@ -37,11 +37,11 @@ tokio-tungstenite = "0.14" # websocket
build-information = { path = "../../common/build-information" }
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
client-connections = { path = "../../common/client-connections" }
coconut-interface = { path = "../../common/coconut-interface" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
config = { path = "../../common/config" }
completions = { path = "../../common/completions" }
credential-storage = { path = "../../common/credential-storage" }
credentials = { path = "../../common/credentials" }
credentials = { path = "../../common/credentials", optional = true }
crypto = { path = "../../common/crypto" }
logging = { path = "../../common/logging"}
gateway-client = { path = "../../common/client-libs/gateway-client" }
@@ -55,5 +55,8 @@ validator-client = { path = "../../common/client-libs/validator-client", feature
version-checker = { path = "../../common/version-checker" }
websocket-requests = { path = "websocket-requests" }
[features]
coconut = ["coconut-interface", "credentials", "credentials/coconut", "gateway-requests/coconut", "gateway-client/coconut", "client-core/coconut"]
[dev-dependencies]
serde_json = "1.0" # for the "textsend" example
+4 -18
View File
@@ -2,19 +2,16 @@
// SPDX-License-Identifier: Apache-2.0
use crate::client::config::template::config_template;
use client_core::config::ClientCoreConfigTrait;
pub use client_core::config::Config as BaseConfig;
pub use client_core::config::MISSING_VALUE;
use client_core::config::{ClientCoreConfigTrait, DebugConfig};
use config::defaults::DEFAULT_WEBSOCKET_LISTENING_PORT;
use config::{NymConfig, OptionalSet};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::net::{IpAddr, Ipv4Addr};
use std::path::PathBuf;
use std::str::FromStr;
pub use client_core::config::Config as BaseConfig;
pub use client_core::config::MISSING_VALUE;
pub use client_core::config::{DebugConfig, GatewayEndpointConfig};
mod template;
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone, Copy)]
@@ -107,11 +104,6 @@ impl Config {
self
}
pub fn with_host(mut self, host: IpAddr) -> Self {
self.socket.host = host;
self
}
pub fn with_port(mut self, port: u16) -> Self {
self.socket.listening_port = port;
self
@@ -138,10 +130,6 @@ impl Config {
self.socket.socket_type
}
pub fn get_listening_ip(&self) -> IpAddr {
self.socket.host
}
pub fn get_listening_port(&self) -> u16 {
self.socket.listening_port
}
@@ -192,10 +180,9 @@ impl Config {
}
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(default, deny_unknown_fields)]
#[serde(deny_unknown_fields)]
pub struct Socket {
socket_type: SocketType,
host: IpAddr,
listening_port: u16,
}
@@ -203,7 +190,6 @@ impl Default for Socket {
fn default() -> Self {
Socket {
socket_type: SocketType::WebSocket,
host: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
listening_port: DEFAULT_WEBSOCKET_LISTENING_PORT,
}
}
@@ -93,9 +93,6 @@ socket_type = '{{ socket.socket_type }}'
# will be listening for incoming requests
listening_port = {{ socket.listening_port }}
# if applicable (for the case of 'WebSocket'), the ip address on which the client
# will be listening for incoming requests
host = '{{ socket.host }}'
##### logging configuration options #####
+10 -54
View File
@@ -11,22 +11,19 @@ use client_core::client::base_client::{
non_wasm_helpers, BaseClientBuilder, ClientInput, ClientOutput, ClientState,
};
use client_core::client::inbound_messages::InputMessage;
use client_core::client::received_buffer::{
ReceivedBufferMessage, ReceivedBufferRequestSender, ReconstructedMessagesReceiver,
};
use client_core::client::key_manager::KeyManager;
use client_core::client::received_buffer::{ReceivedBufferMessage, ReconstructedMessagesReceiver};
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use futures::channel::mpsc;
use gateway_client::bandwidth::BandwidthController;
use log::*;
use nymsphinx::addressing::clients::Recipient;
use nymsphinx::anonymous_replies::requests::AnonymousSenderTag;
use nymsphinx::receiver::ReconstructedMessage;
use task::TaskManager;
use tokio::sync::watch::error::SendError;
use validator_client::nyxd::QueryNyxdClient;
pub use client_core::client::key_manager::KeyManager;
pub use nymsphinx::addressing::clients::Recipient;
pub use nymsphinx::receiver::ReconstructedMessage;
pub mod config;
pub(crate) mod config;
pub struct SocketClient {
/// Client configuration options, including, among other things, packet sending rates,
@@ -48,13 +45,6 @@ impl SocketClient {
}
}
pub fn new_with_keys(config: Config, key_manager: KeyManager) -> Self {
SocketClient {
config,
key_manager,
}
}
async fn create_bandwidth_controller(config: &Config) -> BandwidthController<QueryNyxdClient> {
let details = network_defaults::NymNetworkDetails::new_from_env();
let mut client_config = validator_client::Config::try_from_nym_network_details(&details)
@@ -112,8 +102,7 @@ impl SocketClient {
reply_controller_sender,
);
websocket::Listener::new(config.get_listening_ip(), config.get_listening_port())
.start(websocket_handler, shutdown);
websocket::Listener::new(config.get_listening_port()).start(websocket_handler, shutdown);
}
/// blocking version of `start_socket` method. Will run forever (or until SIGINT is sent)
@@ -130,17 +119,10 @@ impl SocketClient {
return Err(ClientError::InvalidSocketMode);
}
// don't create bandwidth controller if credentials are disabled
let bandwidth_controller = if self.config.get_base().get_disabled_credentials_mode() {
None
} else {
Some(Self::create_bandwidth_controller(&self.config).await)
};
let base_builder = BaseClientBuilder::new_from_base_config(
self.config.get_base(),
self.key_manager,
bandwidth_controller,
Some(Self::create_bandwidth_controller(&self.config).await),
non_wasm_helpers::setup_fs_reply_surb_backend(
Some(self.config.get_base().get_reply_surb_database_path()),
self.config.get_debug_settings(),
@@ -174,17 +156,10 @@ impl SocketClient {
return Err(ClientError::InvalidSocketMode);
}
// don't create bandwidth controller if credentials are disabled
let bandwidth_controller = if self.config.get_base().get_disabled_credentials_mode() {
None
} else {
Some(Self::create_bandwidth_controller(&self.config).await)
};
let base_client = BaseClientBuilder::new_from_base_config(
self.config.get_base(),
self.key_manager,
bandwidth_controller,
Some(Self::create_bandwidth_controller(&self.config).await),
non_wasm_helpers::setup_fs_reply_surb_backend(
Some(self.config.get_base().get_reply_surb_database_path()),
self.config.get_debug_settings(),
@@ -192,8 +167,6 @@ impl SocketClient {
.await?,
);
let address = base_client.as_mix_recipient();
let mut started_client = base_client.start_base().await?;
let client_input = started_client.client_input.register_producer();
let client_output = started_client.client_output.register_consumer();
@@ -211,38 +184,21 @@ impl SocketClient {
Ok(DirectClient {
client_input,
_received_buffer_request_sender: client_output.received_buffer_request_sender,
reconstructed_receiver,
address,
shutdown_notifier: started_client.task_manager,
_shutdown_notifier: started_client.task_manager,
})
}
}
pub struct DirectClient {
client_input: ClientInput,
// make sure to not drop the channel
_received_buffer_request_sender: ReceivedBufferRequestSender,
reconstructed_receiver: ReconstructedMessagesReceiver,
address: Recipient,
// we need to keep reference to this guy otherwise things will start dropping
shutdown_notifier: TaskManager,
_shutdown_notifier: TaskManager,
}
impl DirectClient {
pub fn address(&self) -> &Recipient {
&self.address
}
pub fn signal_shutdown(&self) -> Result<(), SendError<()>> {
self.shutdown_notifier.signal_shutdown()
}
pub async fn wait_for_shutdown(&mut self) {
self.shutdown_notifier.wait_for_shutdown().await
}
/// EXPERIMENTAL DIRECT RUST API
/// It's untested and there are absolutely no guarantees about it (but seems to have worked
/// well enough in local tests)
+7 -9
View File
@@ -12,7 +12,6 @@ use crypto::asymmetric::identity;
use nymsphinx::addressing::clients::Recipient;
use serde::Serialize;
use std::fmt::Display;
use std::net::IpAddr;
use tap::TapFallible;
#[derive(Args, Clone)]
@@ -31,7 +30,8 @@ pub(crate) struct Init {
force_register_gateway: bool,
/// Comma separated list of rest endpoints of the nyxd validators
#[clap(long, alias = "nymd_validators", value_delimiter = ',', hide = true)]
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
/// Comma separated list of rest endpoints of the API validators
@@ -47,10 +47,6 @@ pub(crate) struct Init {
#[clap(short, long)]
port: Option<u16>,
/// Ip for the socket (if applicable) to listen for requests.
#[clap(long)]
host: Option<IpAddr>,
/// Mostly debug-related option to increase default traffic rate so that you would not need to
/// modify config post init
#[clap(long, hide = true)]
@@ -62,7 +58,8 @@ pub(crate) struct Init {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[clap(long, hide = true)]
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
/// Save a summary of the initialization to a json file
@@ -76,11 +73,12 @@ impl From<Init> for OverrideConfig {
nym_apis: init_config.nym_apis,
disable_socket: init_config.disable_socket,
port: init_config.port,
host: init_config.host,
fastmode: init_config.fastmode,
no_cover: init_config.no_cover,
#[cfg(feature = "coconut")]
nyxd_urls: init_config.nyxd_urls,
#[cfg(feature = "coconut")]
enabled_credentials_mode: init_config.enabled_credentials_mode,
}
}
@@ -147,7 +145,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> {
.await
.tap_err(|err| eprintln!("Failed to setup gateway\nError: {err}"))?;
config.get_base_mut().set_gateway_endpoint(gateway);
config.get_base_mut().with_gateway_endpoint(gateway);
config.save_to_file(None).tap_err(|_| {
log::error!("Failed to save the config file");
+23 -16
View File
@@ -9,7 +9,6 @@ use completions::{fig_generate, ArgShell};
use config::OptionalSet;
use lazy_static::lazy_static;
use std::error::Error;
use std::net::IpAddr;
pub(crate) mod init;
pub(crate) mod run;
@@ -57,10 +56,12 @@ pub(crate) struct OverrideConfig {
nym_apis: Option<Vec<url::Url>>,
disable_socket: Option<bool>,
port: Option<u16>,
host: Option<IpAddr>,
fastmode: bool,
no_cover: bool,
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
enabled_credentials_mode: Option<bool>,
}
@@ -77,29 +78,35 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
Ok(())
}
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
config
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
config = config
.with_optional(Config::with_disabled_socket, args.disable_socket)
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
.with_optional(Config::with_port, args.port)
.with_optional(Config::with_host, args.host)
.with_optional_custom_env_ext(
BaseConfig::with_custom_nym_apis,
args.nym_apis,
network_defaults::var_names::NYM_API,
config::parse_urls,
)
.with_optional_custom_env_ext(
BaseConfig::with_custom_nyxd,
args.nyxd_urls,
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_optional_ext(
BaseConfig::with_disabled_credentials,
args.enabled_credentials_mode.map(|b| !b),
)
);
#[cfg(feature = "coconut")]
{
config = config
.with_optional_custom_env_ext(
BaseConfig::with_custom_nyxd,
args.nyxd_urls,
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_optional_ext(
BaseConfig::with_disabled_credentials,
args.enabled_credentials_mode.map(|b| !b),
);
}
config
}
#[cfg(test)]
+7 -8
View File
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
use std::error::Error;
use std::net::IpAddr;
use crate::{
client::{config::Config, SocketClient},
@@ -23,7 +22,8 @@ pub(crate) struct Run {
id: String,
/// Comma separated list of rest endpoints of the nyxd validators
#[clap(long, alias = "nymd_validators", value_delimiter = ',', hide = true)]
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
/// Comma separated list of rest endpoints of the API validators
@@ -44,10 +44,6 @@ pub(crate) struct Run {
#[clap(short, long)]
port: Option<u16>,
/// Ip for the socket (if applicable) to listen for requests.
#[clap(long)]
host: Option<IpAddr>,
/// Mostly debug-related option to increase default traffic rate so that you would not need to
/// modify config post init
#[clap(long, hide = true)]
@@ -59,7 +55,8 @@ pub(crate) struct Run {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[clap(long, hide = true)]
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
}
@@ -69,10 +66,12 @@ impl From<Run> for OverrideConfig {
nym_apis: run_config.nym_apis,
disable_socket: run_config.disable_socket,
port: run_config.port,
host: run_config.host,
fastmode: run_config.fastmode,
no_cover: run_config.no_cover,
#[cfg(feature = "coconut")]
nyxd_urls: run_config.nyxd_urls,
#[cfg(feature = "coconut")]
enabled_credentials_mode: run_config.enabled_credentials_mode,
}
}
+3 -3
View File
@@ -3,7 +3,6 @@
use super::handler::HandlerBuilder;
use log::*;
use std::net::IpAddr;
use std::{net::SocketAddr, process, sync::Arc};
use tokio::io::AsyncWriteExt;
use tokio::{sync::Notify, task::JoinHandle};
@@ -25,9 +24,10 @@ pub(crate) struct Listener {
}
impl Listener {
pub(crate) fn new(host: IpAddr, port: u16) -> Self {
pub(crate) fn new(port: u16) -> Self {
Listener {
address: SocketAddr::new(host, port),
// unless we find compelling reason not to, just listen on local only
address: SocketAddr::new("127.0.0.1".parse().unwrap(), port),
state: State::AwaitingConnection,
}
}
+6 -9
View File
@@ -19,8 +19,8 @@ log = { workspace = true }
pin-project = "1.0"
pretty_env_logger = "0.4"
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
serde = { workspace = true, features = ["derive"] } # for config serialization/deserialization
serde_json = { workspace = true }
serde = { version = "1.0", features = ["derive"] } # for config serialization/deserialization
serde_json = "1.0.89"
tap = "1.0.1"
thiserror = "1.0.34"
tokio = { version = "1.24.1", features = ["rt-multi-thread", "net", "signal"] }
@@ -30,12 +30,11 @@ url = "2.2"
build-information = { path = "../../common/build-information" }
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
client-connections = { path = "../../common/client-connections" }
coconut-interface = { path = "../../common/coconut-interface" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
config = { path = "../../common/config" }
completions = { path = "../../common/completions" }
credential-storage = { path = "../../common/credential-storage", optional = true }
mobile-storage = { path = "../../common/mobile-storage", optional = true }
credentials = { path = "../../common/credentials" }
credential-storage = { path = "../../common/credential-storage" }
credentials = { path = "../../common/credentials", optional = true }
crypto = { path = "../../common/crypto" }
logging = { path = "../../common/logging"}
gateway-client = { path = "../../common/client-libs/gateway-client" }
@@ -45,7 +44,6 @@ nymsphinx = { path = "../../common/nymsphinx" }
ordered-buffer = { path = "../../common/socks5/ordered-buffer" }
pemstore = { path = "../../common/pemstore" }
proxy-helpers = { path = "../../common/socks5/proxy-helpers" }
service-providers-common = { path = "../../service-providers/common" }
socks5-requests = { path = "../../common/socks5/requests" }
task = { path = "../../common/task" }
topology = { path = "../../common/topology" }
@@ -53,6 +51,5 @@ validator-client = { path = "../../common/client-libs/validator-client", feature
version-checker = { path = "../../common/version-checker" }
[features]
default = ["credential-storage"]
coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut", "credentials/coconut", "client-core/coconut"]
eth = []
mobile = ["mobile-storage", "gateway-client/mobile"]
+8 -43
View File
@@ -1,4 +1,4 @@
// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::client::config::template::config_template;
@@ -9,8 +9,6 @@ use config::defaults::DEFAULT_SOCKS5_LISTENING_PORT;
use config::{NymConfig, OptionalSet};
use nymsphinx::addressing::clients::Recipient;
use serde::{Deserialize, Serialize};
use service_providers_common::interface::ProviderInterfaceVersion;
use socks5_requests::Socks5ProtocolVersion;
use std::fmt::Debug;
use std::path::PathBuf;
use std::str::FromStr;
@@ -20,7 +18,7 @@ mod template;
const DEFAULT_CONNECTION_START_SURBS: u32 = 20;
const DEFAULT_PER_REQUEST_SURBS: u32 = 3;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
#[serde(flatten)]
@@ -38,12 +36,10 @@ impl NymConfig for Config {
}
fn default_root_directory() -> PathBuf {
#[cfg(not(feature = "mobile"))]
let base_dir = dirs::home_dir().expect("Failed to evaluate $HOME value");
#[cfg(feature = "mobile")]
let base_dir = PathBuf::from("/tmp");
base_dir.join(".nym").join("socks5-clients")
dirs::home_dir()
.expect("Failed to evaluate $HOME value")
.join(".nym")
.join("socks5-clients")
}
fn try_default_root_directory() -> Option<PathBuf> {
@@ -92,16 +88,6 @@ impl Config {
self
}
pub fn with_provider_interface_version(mut self, version: ProviderInterfaceVersion) -> Self {
self.socks5.provider_interface_version = version;
self
}
pub fn with_socks5_protocol_version(mut self, version: Socks5ProtocolVersion) -> Self {
self.socks5.socks5_protocol_version = version;
self
}
pub fn with_anonymous_replies(mut self, anonymous_replies: bool) -> Self {
self.socks5.send_anonymously = anonymous_replies;
self
@@ -129,14 +115,6 @@ impl Config {
.expect("malformed provider address")
}
pub fn get_provider_interface_version(&self) -> ProviderInterfaceVersion {
self.socks5.provider_interface_version
}
pub fn get_socks5_protocol_version(&self) -> Socks5ProtocolVersion {
self.socks5.socks5_protocol_version
}
pub fn get_send_anonymously(&self) -> bool {
self.socks5.send_anonymously
}
@@ -198,7 +176,7 @@ impl Config {
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Socks5 {
/// The port on which the client will be listening for incoming requests
@@ -207,15 +185,6 @@ pub struct Socks5 {
/// The mix address of the provider to which all requests are going to be sent.
provider_mix_address: String,
/// The version of the 'service provider' this client is going to use in its communication with the
/// specified socks5 provider.
// if in doubt, use the legacy version as initially nobody will be using the updated binaries
#[serde(default = "ProviderInterfaceVersion::new_legacy")]
provider_interface_version: ProviderInterfaceVersion,
#[serde(default = "Socks5ProtocolVersion::new_legacy")]
socks5_protocol_version: Socks5ProtocolVersion,
/// Specifies whether this client is going to use an anonymous sender tag for communication with the service provider.
/// While this is going to hide its actual address information, it will make the actual communication
/// slower and consume nearly double the bandwidth as it will require sending reply SURBs.
@@ -230,8 +199,6 @@ impl Socks5 {
Socks5 {
listening_port: DEFAULT_SOCKS5_LISTENING_PORT,
provider_mix_address: provider_mix_address.into(),
provider_interface_version: ProviderInterfaceVersion::Legacy,
socks5_protocol_version: Socks5ProtocolVersion::Legacy,
send_anonymously: false,
}
}
@@ -242,14 +209,12 @@ impl Default for Socks5 {
Socks5 {
listening_port: DEFAULT_SOCKS5_LISTENING_PORT,
provider_mix_address: "".into(),
provider_interface_version: ProviderInterfaceVersion::Legacy,
socks5_protocol_version: Socks5ProtocolVersion::Legacy,
send_anonymously: false,
}
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Socks5Debug {
/// Number of reply SURBs attached to each `Request::Connect` message.
+7 -38
View File
@@ -8,12 +8,9 @@ use crate::socks::{
authentication::{AuthenticationMethods, Authenticator, User},
server::SphinxSocksServer,
};
#[cfg(feature = "mobile")]
use client_core::client::base_client::helpers::setup_empty_reply_surb_backend;
#[cfg(not(feature = "mobile"))]
use client_core::client::base_client::non_wasm_helpers;
use client_core::client::base_client::{BaseClientBuilder, ClientInput, ClientOutput, ClientState};
use client_core::client::base_client::{
non_wasm_helpers, BaseClientBuilder, ClientInput, ClientOutput, ClientState,
};
use client_core::client::key_manager::KeyManager;
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use futures::channel::mpsc;
@@ -57,18 +54,6 @@ impl NymClient {
}
}
pub fn new_with_keys(config: Config, key_manager: Option<KeyManager>) -> Self {
let key_manager = key_manager.unwrap_or_else(|| {
let pathfinder = ClientKeyPathfinder::new_from_config(config.get_base());
KeyManager::load_keys(&pathfinder).expect("failed to load stored keys")
});
NymClient {
config,
key_manager,
}
}
async fn create_bandwidth_controller(config: &Config) -> BandwidthController<QueryNyxdClient> {
let details = network_defaults::NymNetworkDetails::new_from_env();
let mut client_config = validator_client::Config::try_from_nym_network_details(&details)
@@ -87,15 +72,10 @@ impl NymClient {
client_config = client_config.with_urls(nyxd_url, api_url);
let client = validator_client::Client::new_query(client_config)
.expect("Could not construct query client");
#[cfg(not(feature = "mobile"))]
let storage =
credential_storage::initialise_storage(config.get_base().get_database_path()).await;
#[cfg(feature = "mobile")]
let storage = mobile_storage::PersistentStorage {};
BandwidthController::new(storage, client)
BandwidthController::new(
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
client,
)
}
fn start_socks5_listener(
@@ -132,8 +112,6 @@ impl NymClient {
self_address,
shared_lane_queue_lengths,
socks::client::Config::new(
config.get_provider_interface_version(),
config.get_socks5_protocol_version(),
config.get_send_anonymously(),
config.get_connection_start_surbs(),
config.get_per_request_surbs(),
@@ -210,7 +188,6 @@ impl NymClient {
}
pub async fn start(self) -> Result<TaskManager, Socks5ClientError> {
#[cfg(not(feature = "mobile"))]
let base_builder = BaseClientBuilder::new_from_base_config(
self.config.get_base(),
self.key_manager,
@@ -222,14 +199,6 @@ impl NymClient {
.await?,
);
#[cfg(feature = "mobile")]
let base_builder = BaseClientBuilder::<_, QueryNyxdClient>::new_from_base_config(
self.config.get_base(),
self.key_manager,
None,
setup_empty_reply_surb_backend(self.config.get_debug_settings()),
);
let self_address = base_builder.as_mix_recipient();
let mut started_client = base_builder.start_base().await?;
let client_input = started_client.client_input.register_producer();
+8 -5
View File
@@ -43,7 +43,8 @@ pub(crate) struct Init {
force_register_gateway: bool,
/// Comma separated list of rest endpoints of the nyxd validators
#[clap(long, alias = "nymd_validators", value_delimiter = ',', hide = true)]
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
/// Comma separated list of rest endpoints of the API validators
@@ -66,7 +67,8 @@ pub(crate) struct Init {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[clap(long, hide = true)]
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
/// Save a summary of the initialization to a json file
@@ -82,7 +84,10 @@ impl From<Init> for OverrideConfig {
use_anonymous_replies: init_config.use_reply_surbs,
fastmode: init_config.fastmode,
no_cover: init_config.no_cover,
#[cfg(feature = "coconut")]
nyxd_urls: init_config.nyxd_urls,
#[cfg(feature = "coconut")]
enabled_credentials_mode: init_config.enabled_credentials_mode,
}
}
@@ -153,9 +158,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> {
.await
.tap_err(|err| eprintln!("Failed to setup gateway\nError: {err}"))?;
config.get_base_mut().set_gateway_endpoint(gateway);
// TODO: ask the service provider we specified for its interface version and set it in the config
config.get_base_mut().with_gateway_endpoint(gateway);
config.save_to_file(None).tap_err(|_| {
log::error!("Failed to save the config file");
+23 -13
View File
@@ -60,7 +60,10 @@ pub(crate) struct OverrideConfig {
use_anonymous_replies: Option<bool>,
fastmode: bool,
no_cover: bool,
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
enabled_credentials_mode: Option<bool>,
}
@@ -77,8 +80,8 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
Ok(())
}
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
config
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
config = config
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
@@ -88,17 +91,24 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
args.nym_apis,
network_defaults::var_names::NYM_API,
config::parse_urls,
)
.with_optional_custom_env_ext(
BaseConfig::with_custom_nyxd,
args.nyxd_urls,
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_optional_ext(
BaseConfig::with_disabled_credentials,
args.enabled_credentials_mode.map(|b| !b),
)
);
#[cfg(feature = "coconut")]
{
config = config
.with_optional_custom_env_ext(
BaseConfig::with_custom_nyxd,
args.nyxd_urls,
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_optional_ext(
BaseConfig::with_disabled_credentials,
args.enabled_credentials_mode.map(|b| !b),
);
}
config
}
#[cfg(test)]
+7 -2
View File
@@ -43,7 +43,8 @@ pub(crate) struct Run {
gateway: Option<identity::PublicKey>,
/// Comma separated list of rest endpoints of the nyxd validators
#[clap(long, alias = "nymd_validators", value_delimiter = ',', hide = true)]
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
/// Comma separated list of rest endpoints of the Nym APIs
@@ -65,7 +66,8 @@ pub(crate) struct Run {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[clap(long, hide = true)]
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
}
@@ -77,7 +79,10 @@ impl From<Run> for OverrideConfig {
use_anonymous_replies: run_config.use_anonymous_replies,
fastmode: run_config.fastmode,
no_cover: run_config.no_cover,
#[cfg(feature = "coconut")]
nyxd_urls: run_config.nyxd_urls,
#[cfg(feature = "coconut")]
enabled_credentials_mode: run_config.enabled_credentials_mode,
}
}
+1 -10
View File
@@ -1,6 +1,6 @@
use crate::socks::types::SocksProxyError;
use client_core::error::ClientCoreError;
use socks5_requests::{ConnectionError, ConnectionId};
use socks5_requests::ConnectionId;
#[derive(thiserror::Error, Debug)]
pub enum Socks5ClientError {
@@ -28,12 +28,3 @@ pub enum Socks5ClientError {
error: String,
},
}
impl From<ConnectionError> for Socks5ClientError {
fn from(value: ConnectionError) -> Self {
Socks5ClientError::NetworkRequesterError {
connection_id: value.connection_id,
error: value.network_requester_error,
}
}
}
+30 -132
View File
@@ -16,10 +16,7 @@ use proxy_helpers::connection_controller::{
};
use proxy_helpers::proxy_runner::ProxyRunner;
use rand::RngCore;
use service_providers_common::interface::{ProviderInterfaceVersion, RequestVersion};
use socks5_requests::{
ConnectionId, RemoteAddress, Socks5ProtocolVersion, Socks5ProviderRequest, Socks5Request,
};
use socks5_requests::{ConnectionId, Message, RemoteAddress, Request};
use std::io;
use std::net::SocketAddr;
use std::pin::Pin;
@@ -131,8 +128,6 @@ impl AsyncWrite for StreamState {
#[derive(Debug, Copy, Clone)]
pub(crate) struct Config {
provider_interface_version: ProviderInterfaceVersion,
socks5_protocol_version: Socks5ProtocolVersion,
use_surbs_for_responses: bool,
connection_start_surbs: u32,
per_request_surbs: u32,
@@ -140,27 +135,16 @@ pub(crate) struct Config {
impl Config {
pub(crate) fn new(
provider_interface_version: ProviderInterfaceVersion,
socks5_protocol_version: Socks5ProtocolVersion,
use_surbs_for_responses: bool,
connection_start_surbs: u32,
per_request_surbs: u32,
) -> Self {
Self {
provider_interface_version,
socks5_protocol_version,
use_surbs_for_responses,
connection_start_surbs,
per_request_surbs,
}
}
fn request_version(&self) -> RequestVersion<Socks5Request> {
RequestVersion {
provider_interface: self.provider_interface_version,
provider_protocol: self.socks5_protocol_version,
}
}
}
/// A client connecting to the Socks proxy server, because
@@ -189,9 +173,7 @@ impl Drop for SocksClient {
// if we never managed to start a proxy, the entry will not exist in the controller
if self.started_proxy {
self.controller_sender
.unbounded_send(ControllerCommand::Remove {
connection_id: self.connection_id,
})
.unbounded_send(ControllerCommand::Remove(self.connection_id))
.unwrap();
}
}
@@ -266,26 +248,19 @@ impl SocksClient {
// Send an error back to the client
pub async fn send_error_v4(&mut self, r: ResponseCodeV4) -> Result<(), SocksProxyError> {
self.stream
.write_all(&[SOCKS4_VERSION, r as u8])
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })
self.stream.write_all(&[SOCKS4_VERSION, r as u8]).await?;
Ok(())
}
pub async fn send_error_v5(&mut self, r: ResponseCodeV5) -> Result<(), SocksProxyError> {
self.stream
.write_all(&[SOCKS5_VERSION, r as u8])
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })
self.stream.write_all(&[SOCKS5_VERSION, r as u8]).await?;
Ok(())
}
/// Shutdown the `TcpStream` to the client and end the session
pub async fn shutdown(&mut self) -> Result<(), SocksProxyError> {
info!("client is shutting down its TCP stream");
self.stream
.shutdown()
.await
.map_err(|source| SocksProxyError::SocketShutdownFailure { source })?;
self.stream.shutdown().await?;
self.shutdown_listener.mark_as_success();
Ok(())
}
@@ -293,20 +268,11 @@ impl SocksClient {
/// Initializes the new client, checking that the correct Socks version (5)
/// is in use and that the client is authenticated, then runs the request.
pub async fn run(&mut self) -> Result<(), SocksProxyError> {
debug!(
"New connection from: {}",
self.stream
.peer_addr()
.map_err(|source| SocksProxyError::PeerAddrExtractionFailure { source })?
.ip()
);
debug!("New connection from: {}", self.stream.peer_addr()?.ip());
// Read a byte from the stream and determine the version being requested
let mut header = [0u8];
self.stream
.read_exact(&mut header)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut header).await?;
self.socks_version = match SocksVersion::try_from(header[0]) {
Ok(version) => Some(version),
@@ -318,10 +284,7 @@ impl SocksClient {
if self.socks_version == Some(SocksVersion::V5) {
let mut auth = [0u8];
self.stream
.read_exact(&mut auth)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut auth).await?;
self.auth_nmethods = auth[0];
self.authenticate_socks5().await?;
}
@@ -330,15 +293,8 @@ impl SocksClient {
}
async fn send_anonymous_connect_to_mixnet(&mut self, remote_address: RemoteAddress) {
// TODO: simplify by using `request_version`
let req = Socks5Request::new_connect(
self.config.socks5_protocol_version,
self.connection_id,
remote_address,
None,
);
let msg =
Socks5ProviderRequest::new_provider_data(self.config.provider_interface_version, req);
let req = Request::new_connect(self.connection_id, remote_address, None);
let msg = Message::Request(req);
let input_message = InputMessage::new_anonymous(
self.service_provider,
@@ -353,15 +309,8 @@ impl SocksClient {
}
async fn send_connect_to_mixnet_with_return_address(&mut self, remote_address: RemoteAddress) {
// TODO: simplify by using `request_version`
let req = Socks5Request::new_connect(
self.config.socks5_protocol_version,
self.connection_id,
remote_address,
Some(self.self_address),
);
let msg =
Socks5ProviderRequest::new_provider_data(self.config.provider_interface_version, req);
let req = Request::new_connect(self.connection_id, remote_address, Some(self.self_address));
let msg = Message::Request(req);
let input_message = InputMessage::new_regular(
self.service_provider,
@@ -401,7 +350,6 @@ impl SocksClient {
let input_sender = self.input_sender.clone();
let anonymous = self.config.use_surbs_for_responses;
let per_request_surbs = self.config.per_request_surbs;
let request_version = self.config.request_version();
let recipient = self.service_provider;
let (stream, _) = ProxyRunner::new(
@@ -415,16 +363,8 @@ impl SocksClient {
self.shutdown_listener.clone(),
)
.run(move |conn_id, read_data, socket_closed| {
let provider_request = Socks5Request::new_send(
request_version.provider_protocol,
conn_id,
read_data,
socket_closed,
);
let provider_message = Socks5ProviderRequest::new_provider_data(
request_version.provider_interface,
provider_request,
);
let provider_request = Request::new_send(conn_id, read_data, socket_closed);
let provider_message = Message::Request(provider_request);
let lane = TransmissionLane::ConnectionId(conn_id);
if anonymous {
InputMessage::new_anonymous(
@@ -473,10 +413,7 @@ impl SocksClient {
self.started_proxy = true;
self.controller_sender
.unbounded_send(ControllerCommand::Insert {
connection_id: self.connection_id,
connection_sender: mix_sender,
})
.unbounded_send(ControllerCommand::Insert(self.connection_id, mix_sender))
.unwrap();
info!(
@@ -554,13 +491,7 @@ impl SocksClient {
/// into the Authenticator (where it'll be more easily testable)
/// would be a good next step.
async fn authenticate_socks5(&mut self) -> Result<(), SocksProxyError> {
debug!(
"Authenticating w/ {}",
self.stream
.peer_addr()
.map_err(|source| SocksProxyError::PeerAddrExtractionFailure { source })?
.ip()
);
debug!("Authenticating w/ {}", self.stream.peer_addr()?.ip());
// Get valid auth methods
let methods = self.get_available_methods().await?;
trace!("methods: {:?}", methods);
@@ -574,45 +505,27 @@ impl SocksClient {
response[1] = AuthenticationMethods::UserPass as u8;
debug!("Sending USER/PASS packet");
self.stream
.write_all(&response)
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })?;
self.stream.write_all(&response).await?;
let mut header = [0u8; 2];
// Read a byte from the stream and determine the version being requested
self.stream
.read_exact(&mut header)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut header).await?;
// debug!("Auth Header: [{}, {}]", header[0], header[1]);
// Username parsing
let ulen = header[1];
let mut username = vec![0; ulen as usize];
self.stream
.read_exact(&mut username)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut username).await?;
// Password Parsing
let plen = self
.stream
.read_u8()
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
let plen = self.stream.read_u8().await?;
let mut password = vec![0; plen as usize];
self.stream
.read_exact(&mut password)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut password).await?;
let username_str = String::from_utf8(username)
.map_err(|source| SocksProxyError::MalformedAuthUsername { source })?;
let password_str = String::from_utf8(password)
.map_err(|source| SocksProxyError::MalformedAuthPassword { source })?;
let username_str = String::from_utf8(username)?;
let password_str = String::from_utf8(password)?;
let user = User {
username: username_str,
@@ -623,17 +536,11 @@ impl SocksClient {
if self.authenticator.is_allowed(&user) {
debug!("Access Granted. User: {}", user.username);
let response = [1, ResponseCodeV5::Success as u8];
self.stream
.write_all(&response)
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })?;
self.stream.write_all(&response).await?;
} else {
debug!("Access Denied. User: {}", user.username);
let response = [1, ResponseCodeV5::Failure as u8];
self.stream
.write_all(&response)
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })?;
self.stream.write_all(&response).await?;
// Shutdown
self.shutdown().await?;
@@ -644,18 +551,12 @@ impl SocksClient {
// set the default auth method (no auth)
response[1] = AuthenticationMethods::NoAuth as u8;
debug!("Sending NOAUTH packet");
self.stream
.write_all(&response)
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })?;
self.stream.write_all(&response).await?;
Ok(())
} else {
warn!("Client has no suitable authentication methods!");
response[1] = AuthenticationMethods::NoMethods as u8;
self.stream
.write_all(&response)
.await
.map_err(|source| SocksProxyError::SocketWriteError { source })?;
self.stream.write_all(&response).await?;
self.shutdown().await?;
Err(ResponseCodeV5::Failure.into())
}
@@ -666,10 +567,7 @@ impl SocksClient {
let mut methods: Vec<u8> = Vec::with_capacity(self.auth_nmethods as usize);
for _ in 0..self.auth_nmethods {
let mut method = [0u8; 1];
self.stream
.read_exact(&mut method)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
self.stream.read_exact(&mut method).await?;
if self.authenticator.auth_methods.contains(&method[0]) {
methods.append(&mut method.to_vec());
}
+30 -54
View File
@@ -5,9 +5,8 @@ use log::*;
use client_core::client::received_buffer::ReconstructedMessagesReceiver;
use client_core::client::received_buffer::{ReceivedBufferMessage, ReceivedBufferRequestSender};
use nymsphinx::receiver::ReconstructedMessage;
use proxy_helpers::connection_controller::ControllerSender;
use service_providers_common::interface::{ControlResponse, ResponseContent};
use socks5_requests::{Socks5ProviderResponse, Socks5Response, Socks5ResponseContent};
use proxy_helpers::connection_controller::{ControllerCommand, ControllerSender};
use socks5_requests::Message;
use task::TaskClient;
use crate::error::Socks5ClientError;
@@ -53,39 +52,6 @@ impl MixnetResponseListener {
}
}
fn on_control_response(
&self,
control_response: ControlResponse,
) -> Result<(), Socks5ClientError> {
error!("received a control response which we don't know how to handle yet!");
error!("got: {:?}", control_response);
// I guess we'd need another channel here to forward those to where they need to go
Ok(())
}
fn on_provider_data_response(
&self,
provider_response: Socks5Response,
) -> Result<(), Socks5ClientError> {
match provider_response.content {
Socks5ResponseContent::ConnectionError(err_response) => {
error!(
"Network requester failed on connection id {} with error: {}",
err_response.connection_id, err_response.network_requester_error
);
Err(err_response.into())
}
Socks5ResponseContent::NetworkData(response) => {
self.controller_sender
.unbounded_send(response.into())
.unwrap();
Ok(())
}
}
}
fn on_message(
&self,
reconstructed_message: ReconstructedMessage,
@@ -94,28 +60,38 @@ impl MixnetResponseListener {
if reconstructed_message.sender_tag.is_some() {
warn!("this message was sent anonymously - it couldn't have come from the service provider");
}
match Socks5ProviderResponse::try_from_bytes(&raw_message) {
let response = match Message::try_from_bytes(&raw_message) {
Err(err) => {
warn!("failed to parse received response: {err}");
Ok(())
warn!("failed to parse received response - {err}");
return Ok(());
}
Ok(response) => {
// as long as the client used the same (or older) interface than the service provider,
// the response should have used exactly the same version
trace!(
"the received response was sent with {:?} interface version",
response.interface_version
Ok(Message::Request(_)) => {
warn!("unexpected request");
return Ok(());
}
Ok(Message::Response(data)) => data,
Ok(Message::NetworkRequesterResponse(r)) => {
error!(
"Network requester failed on connection id {} with error: {}",
r.connection_id, r.network_requester_error
);
match response.content {
ResponseContent::Control(control_response) => {
self.on_control_response(control_response)
}
ResponseContent::ProviderData(provider_response) => {
self.on_provider_data_response(provider_response)
}
}
return Err(Socks5ClientError::NetworkRequesterError {
connection_id: r.connection_id,
error: r.network_requester_error,
});
}
}
};
self.controller_sender
.unbounded_send(ControllerCommand::Send(
response.connection_id,
response.data,
response.is_closed,
))
.unwrap();
Ok(())
}
pub(crate) async fn run(&mut self) {
+1 -1
View File
@@ -33,7 +33,7 @@ impl TryFrom<u8> for SocksVersion {
match version {
SOCKS4_VERSION => Ok(Self::V4),
SOCKS5_VERSION => Ok(Self::V5),
_ => Err(SocksProxyError::UnsupportedProxyVersion { version }),
_ => Err(SocksProxyError::UnsupportedProxyVersion(version)),
}
}
}
+10 -39
View File
@@ -28,10 +28,7 @@ impl SocksRequest {
log::trace!("read from stream socks4");
let mut packet = [0u8; 3];
stream
.read_exact(&mut packet)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut packet).await?;
// CD (command)
let Some(command) = SocksCommand::from(packet[0] as usize) else {
@@ -46,10 +43,7 @@ impl SocksRequest {
// DSTIP
let mut ip = [0u8; 4];
stream
.read_exact(&mut ip)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut ip).await?;
// USERID
let _userid = read_until_zero(stream).await;
@@ -82,17 +76,12 @@ impl SocksRequest {
let mut packet = [0u8; 4];
// Read a byte from the stream and determine the version being requested
stream
.read_exact(&mut packet)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut packet).await?;
// VER
if packet[0] != SOCKS5_VERSION {
warn!("Unsupported version: SOCKS{}", packet[0]);
return Err(SocksProxyError::UnsupportedProxyVersion {
version: (packet[0]),
});
return Err(SocksProxyError::UnsupportedProxyVersion(packet[0]));
}
// CMD
@@ -114,41 +103,26 @@ impl SocksRequest {
let addr = match addr_type {
AddrType::Domain => {
let mut domain_length = [0u8];
stream
.read_exact(&mut domain_length)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut domain_length).await?;
let mut domain = vec![0u8; domain_length[0] as usize];
stream
.read_exact(&mut domain)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut domain).await?;
domain
}
AddrType::V4 => {
let mut addr = [0u8; 4];
stream
.read_exact(&mut addr)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut addr).await?;
addr.to_vec()
}
AddrType::V6 => {
let mut addr = [0u8; 16];
stream
.read_exact(&mut addr)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut addr).await?;
addr.to_vec()
}
};
// DST.PORT
let mut port = [0u8; 2];
stream
.read_exact(&mut port)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut port).await?;
let port = merge_u8_into_u16(port[0], port[1]);
Ok(SocksRequest {
@@ -205,10 +179,7 @@ where
let mut result = Vec::new();
let mut char = [0u8];
loop {
stream
.read_exact(&mut char)
.await
.map_err(|source| SocksProxyError::SocketReadError { source })?;
stream.read_exact(&mut char).await?;
if char[0] == 0 {
break;
}
-5
View File
@@ -86,11 +86,6 @@ impl SphinxSocksServer {
mixnet_response_listener.run().await;
});
// TODO:, if required, there should be another task here responsible for control requests.
// it should get `input_sender` to send actual requests into the mixnet
// and some channel that connects it from `MixnetResponseListener` to receive
// any control responses
loop {
tokio::select! {
Ok((stream, _remote)) = listener.accept() => {
+24 -52
View File
@@ -1,7 +1,3 @@
use socks5_requests::Socks5RequestError;
use std::string::FromUtf8Error;
use thiserror::Error;
/// SOCKS4 Response codes
#[allow(dead_code)]
pub(crate) enum ResponseCodeV4 {
@@ -12,8 +8,9 @@ pub(crate) enum ResponseCodeV4 {
}
/// Possible SOCKS5 Response Codes
#[derive(Debug, Error)]
pub enum ResponseCodeV5 {
#[allow(dead_code)]
#[derive(Debug, thiserror::Error)]
pub(crate) enum ResponseCodeV5 {
#[error("SOCKS5 Server Success")]
Success = 0x00,
#[error("SOCKS5 Server Failure")]
@@ -34,55 +31,30 @@ pub enum ResponseCodeV5 {
AddrTypeNotSupported = 0x08,
}
#[derive(Error, Debug)]
#[derive(Debug)]
pub enum SocksProxyError {
#[error("{version} of the socks protocol is not supported by this client")]
UnsupportedProxyVersion { version: u8 },
GenericError(Box<dyn std::error::Error + Send + Sync>),
UnsupportedProxyVersion(u8),
}
#[error("failed to write to the socket: {source}")]
SocketWriteError {
#[source]
source: std::io::Error,
},
impl std::fmt::Display for SocksProxyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SocksProxyError::GenericError(err) => write!(f, "GenericError - {err}"),
SocksProxyError::UnsupportedProxyVersion(version) => {
write!(f, "Unsupported proxy version {}", version)
}
}
}
}
#[error("failed to read from the socket: {source}")]
SocketReadError {
#[source]
source: std::io::Error,
},
#[error("failed to shutdown underlying socket stream: {source}")]
SocketShutdownFailure {
#[source]
source: std::io::Error,
},
#[error("failed to extract ip address of the connected peer: {source}")]
PeerAddrExtractionFailure {
#[source]
source: std::io::Error,
},
#[error("failed to authenticate user due to malformed username: {source}")]
MalformedAuthUsername {
#[source]
source: FromUtf8Error,
},
#[error("failed to authenticate user due to malformed password: {source}")]
MalformedAuthPassword {
#[source]
source: FromUtf8Error,
},
#[error(transparent)]
Socks5ResponseFailure(#[from] ResponseCodeV5),
#[error("could not complete the provider request: {source}")]
ProviderRequestFailure {
#[from]
source: Socks5RequestError,
},
impl<E> From<E> for SocksProxyError
where
E: std::error::Error + Send + Sync + 'static,
{
fn from(err: E) -> Self {
SocksProxyError::GenericError(Box::new(err))
}
}
/// DST.addr variant types
+4 -3
View File
@@ -15,6 +15,7 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
offline-test = []
coconut = ["coconut-interface", "credentials", "gateway-client/coconut"]
[dependencies]
futures = "0.3"
@@ -32,12 +33,12 @@ wasm-bindgen-futures = "0.4"
# internal
client-core = { path = "../client-core", default-features = false, features = ["wasm"] }
client-connections = { path = "../../common/client-connections" }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
credentials = { path = "../../common/credentials", optional = true }
crypto = { path = "../../common/crypto" }
nymsphinx = { path = "../../common/nymsphinx" }
topology = { path = "../../common/topology" }
gateway-client = { path = "../../common/client-libs/gateway-client", default-features = false, features = ["wasm"] }
gateway-client = { path = "../../common/client-libs/gateway-client", default-features = false, features = ["wasm", "coconut"] }
validator-client = { path = "../../common/client-libs/validator-client", default-features = false }
wasm-utils = { path = "../../common/wasm-utils" }
task = { path = "../../common/task" }
+5 -15
View File
@@ -125,11 +125,7 @@ pub struct Debug {
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
/// for more even though in theory they wouldn't need to.
pub maximum_reply_surb_rerequest_waiting_period_ms: u64,
/// Defines maximum amount of time the client is going to wait for reply surbs before
/// deciding it's never going to get them and would drop all pending messages
pub maximum_reply_surb_drop_waiting_period_ms: u64,
pub maximum_reply_surb_waiting_period_ms: u64,
/// Defines maximum amount of time given reply surb is going to be valid for.
/// This is going to be superseded by key rotation once implemented.
@@ -172,11 +168,8 @@ impl From<Debug> for ConfigDebug {
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
maximum_reply_surb_rerequest_waiting_period: Duration::from_millis(
debug.maximum_reply_surb_rerequest_waiting_period_ms,
),
maximum_reply_surb_drop_waiting_period: Duration::from_millis(
debug.maximum_reply_surb_drop_waiting_period_ms,
maximum_reply_surb_waiting_period: Duration::from_millis(
debug.maximum_reply_surb_waiting_period_ms,
),
maximum_reply_surb_age: Duration::from_millis(debug.maximum_reply_surb_age_ms),
maximum_reply_key_age: Duration::from_millis(debug.maximum_reply_key_age_ms),
@@ -207,11 +200,8 @@ impl From<ConfigDebug> for Debug {
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
maximum_reply_surb_rerequest_waiting_period_ms: debug
.maximum_reply_surb_rerequest_waiting_period
.as_millis() as u64,
maximum_reply_surb_drop_waiting_period_ms: debug
.maximum_reply_surb_drop_waiting_period
maximum_reply_surb_waiting_period_ms: debug
.maximum_reply_surb_waiting_period
.as_millis() as u64,
maximum_reply_surb_age_ms: debug.maximum_reply_surb_age.as_millis() as u64,
maximum_reply_key_age_ms: debug.maximum_reply_key_age.as_millis() as u64,
-4
View File
@@ -6,10 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { workspace = true, features = ["derive"], optional = true }
[build-dependencies]
vergen = { version = "7", default-features = false, features = ["build", "git", "rustc", "cargo"] }
[features]
default = []
-50
View File
@@ -4,7 +4,6 @@
// TODO: at a later date this crate should probably also expose `ContractBuildInformation`
// and be used by our smart contracts
#[derive(Debug)]
pub struct BinaryBuildInformation {
// VERGEN_BUILD_TIMESTAMP
/// Provides the build timestamp, for example `2021-02-23T20:14:46.558472672+00:00`.
@@ -54,19 +53,6 @@ impl BinaryBuildInformation {
}
}
pub fn to_owned(&self) -> BinaryBuildInformationOwned {
BinaryBuildInformationOwned {
build_timestamp: self.build_timestamp.to_owned(),
build_version: self.build_version.to_owned(),
commit_sha: self.commit_sha.to_owned(),
commit_timestamp: self.commit_timestamp.to_owned(),
commit_branch: self.commit_branch.to_owned(),
rustc_version: self.rustc_version.to_owned(),
rustc_channel: self.rustc_channel.to_owned(),
cargo_profile: self.cargo_profile.to_owned(),
}
}
pub fn pretty_print(&self) -> String {
format!(
r#"
@@ -98,39 +84,3 @@ impl BinaryBuildInformation {
)
}
}
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BinaryBuildInformationOwned {
// VERGEN_BUILD_TIMESTAMP
/// Provides the build timestamp, for example `2021-02-23T20:14:46.558472672+00:00`.
pub build_timestamp: String,
// VERGEN_BUILD_SEMVER
/// Provides the build version, for example `0.1.0-9-g46f83e1`.
pub build_version: String,
// VERGEN_GIT_SHA
/// Provides the hash of the commit that was used for the build, for example `46f83e112520533338245862d366f6a02cef07d4`.
pub commit_sha: String,
// VERGEN_GIT_COMMIT_TIMESTAMP
/// Provides the timestamp of the commit that was used for the build, for example `2021-02-23T08:08:02-05:00`.
pub commit_timestamp: String,
// VERGEN_GIT_BRANCH
/// Provides the name of the git branch that was used for the build, for example `master`.
pub commit_branch: String,
// VERGEN_RUSTC_SEMVER
/// Provides the rustc version that was used for the build, for example `1.52.0-nightly`.
pub rustc_version: String,
// VERGEN_RUSTC_CHANNEL
/// Provides the rustc channel that was used for the build, for example `nightly`.
pub rustc_channel: String,
// VERGEN_CARGO_PROFILE
/// Provides the cargo profile that was used for the build, for example `debug`.
pub cargo_profile: String,
}
+2 -3
View File
@@ -18,7 +18,7 @@ async-trait = { version = "0.1.51" }
tokio = { version = "1.24.1", features = ["macros"] }
# internal
coconut-interface = { path = "../../coconut-interface" }
coconut-interface = { path = "../../coconut-interface", optional = true }
credentials = { path = "../../credentials" }
crypto = { path = "../../crypto" }
gateway-requests = { path = "../../../gateway/gateway-requests" }
@@ -28,7 +28,6 @@ pemstore = { path = "../../pemstore" }
validator-client = { path = "../validator-client" }
task = { path = "../../task" }
serde = { version = "1.0", features = ["derive"]}
mobile-storage = { path = "../../mobile-storage" }
[dependencies.tungstenite]
@@ -80,5 +79,5 @@ features = ["js"]
#url = "2.1"
[features]
coconut = ["gateway-requests/coconut", "coconut-interface", "credentials/coconut"]
wasm = []
mobile = []
@@ -1,34 +1,27 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "coconut")]
use crate::error::GatewayClientError;
#[cfg(target_arch = "wasm32")]
use crate::wasm_mockups::Storage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "mobile"))]
use credential_storage::storage::Storage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "mobile")]
use mobile_storage::Storage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "mobile")]
use mobile_storage::StorageError;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", feature = "coconut"))]
use crate::wasm_mockups::StorageError;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "mobile"))]
#[cfg(all(not(target_arch = "wasm32"), feature = "coconut"))]
use credential_storage::error::StorageError;
#[cfg(target_arch = "wasm32")]
use crate::wasm_mockups::{Client, CosmWasmClient};
#[cfg(feature = "coconut")]
use std::str::FromStr;
#[cfg(not(target_arch = "wasm32"))]
use validator_client::{nyxd::CosmWasmClient, Client};
#[cfg(feature = "coconut")]
use {
coconut_interface::Base58,
credentials::coconut::{
@@ -41,13 +34,8 @@ use {
use crate::wasm_mockups::PersistentStorage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "mobile"))]
use credential_storage::PersistentStorage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "mobile")]
use mobile_storage::PersistentStorage;
#[derive(Clone)]
#[allow(dead_code)]
pub struct BandwidthController<C: Clone, St: Storage = PersistentStorage> {
@@ -67,6 +55,7 @@ where
}
}
#[cfg(feature = "coconut")]
pub async fn prepare_coconut_credential(
&self,
) -> Result<(coconut_interface::Credential, i64), GatewayClientError> {
@@ -109,6 +98,7 @@ where
))
}
#[cfg(feature = "coconut")]
pub async fn consume_credential(&self, id: i64) -> Result<(), GatewayClientError> {
Ok(self.storage.consume_coconut_credential(id).await?)
}
+26 -17
View File
@@ -9,7 +9,6 @@ pub use crate::packet_router::{
};
use crate::socket_state::{PartiallyDelegated, SocketState};
use crate::{cleanup_socket_message, try_decrypt_binary_message};
use coconut_interface::Credential;
use crypto::asymmetric::identity;
use futures::{SinkExt, StreamExt};
use gateway_requests::authentication::encrypted_address::EncryptedAddressBytes;
@@ -26,19 +25,16 @@ use std::time::Duration;
use task::TaskClient;
use tungstenite::protocol::Message;
#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(not(target_arch = "wasm32"))]
use credential_storage::PersistentStorage;
#[cfg(not(target_arch = "wasm32"))]
use tokio_tungstenite::connect_async;
#[cfg(not(target_arch = "wasm32"))]
use validator_client::nyxd::CosmWasmClient;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(feature = "mobile"))]
use credential_storage::PersistentStorage;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "mobile")]
use mobile_storage::PersistentStorage;
#[cfg(target_arch = "wasm32")]
use crate::wasm_mockups::CosmWasmClient;
#[cfg(target_arch = "wasm32")]
@@ -57,6 +53,7 @@ pub struct GatewayClient<C: Clone> {
bandwidth_remaining: i64,
gateway_address: String,
gateway_identity: identity::PublicKey,
gateway_owner: String,
local_identity: Arc<identity::KeyPair>,
shared_key: Option<Arc<SharedKeys>>,
connection: SocketState,
@@ -87,6 +84,7 @@ where
gateway_address: String,
local_identity: Arc<identity::KeyPair>,
gateway_identity: identity::PublicKey,
gateway_owner: String,
shared_key: Option<Arc<SharedKeys>>,
mixnet_message_sender: MixnetMessageSender,
ack_sender: AcknowledgementSender,
@@ -100,6 +98,7 @@ where
bandwidth_remaining: 0,
gateway_address,
gateway_identity,
gateway_owner,
local_identity,
shared_key,
connection: SocketState::NotConnected,
@@ -133,6 +132,7 @@ where
pub fn new_init(
gateway_address: String,
gateway_identity: identity::PublicKey,
gateway_owner: String,
local_identity: Arc<identity::KeyPair>,
response_timeout_duration: Duration,
) -> Self {
@@ -151,6 +151,7 @@ where
bandwidth_remaining: 0,
gateway_address,
gateway_identity,
gateway_owner,
local_identity,
shared_key: None,
connection: SocketState::NotConnected,
@@ -540,6 +541,7 @@ where
}
}
#[cfg(feature = "coconut")]
async fn claim_coconut_bandwidth(
&mut self,
credential: Credential,
@@ -589,21 +591,28 @@ where
return self.try_claim_testnet_bandwidth().await;
}
let _gateway_owner = self.gateway_owner.clone();
#[cfg(feature = "coconut")]
let (credential, credential_id) = self
.bandwidth_controller
.as_ref()
.unwrap()
.prepare_coconut_credential()
.await?;
#[cfg(not(feature = "coconut"))]
return self.try_claim_testnet_bandwidth().await;
self.claim_coconut_bandwidth(credential).await?;
self.bandwidth_controller
.as_ref()
.unwrap()
.consume_credential(credential_id)
.await?;
Ok(())
#[cfg(feature = "coconut")]
{
self.claim_coconut_bandwidth(credential).await?;
self.bandwidth_controller
.as_ref()
.unwrap()
.consume_credential(credential_id)
.await?;
Ok(())
}
}
fn estimate_required_bandwidth(&self, packets: &[MixPacket]) -> i64 {
@@ -3,13 +3,9 @@
#[cfg(target_arch = "wasm32")]
use crate::wasm_mockups::StorageError;
#[cfg(not(feature = "mobile"))]
#[cfg(not(target_arch = "wasm32"))]
use credential_storage::error::StorageError;
use gateway_requests::registration::handshake::error::HandshakeError;
#[cfg(feature = "mobile")]
#[cfg(not(target_arch = "wasm32"))]
use mobile_storage::StorageError;
use std::io;
use thiserror::Error;
use tungstenite::Error as WsError;
@@ -30,6 +26,7 @@ pub enum GatewayClientError {
#[error("There was a credential storage error - {0}")]
CredentialStorageError(#[from] StorageError),
#[cfg(feature = "coconut")]
#[error("Coconut error - {0}")]
CoconutError(#[from] coconut_interface::CoconutError),
@@ -30,7 +30,7 @@ futures = "0.3"
coconut-interface = { path = "../../coconut-interface" }
network-defaults = { path = "../../network-defaults" }
nym-api-requests = { path = "../../../nym-api/nym-api-requests" }
nym-api-requests = { path = "../../../nym-api/nym-api-requests", features = ["coconut"] }
# required for nyxd-client
# at some point it might be possible to make it wasm-compatible
@@ -8,7 +8,7 @@ use coconut_dkg_common::dealer::{
DealerDetailsResponse, PagedDealerResponse, PagedDealingsResponse,
};
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
use coconut_dkg_common::types::{Epoch, EpochId, InitialReplacementData};
use coconut_dkg_common::types::{Epoch, EpochId};
use coconut_dkg_common::verification_key::PagedVKSharesResponse;
use cosmrs::AccountId;
@@ -16,7 +16,6 @@ use cosmrs::AccountId;
pub trait DkgQueryClient {
async fn get_current_epoch(&self) -> Result<Epoch, NyxdError>;
async fn get_current_epoch_threshold(&self) -> Result<Option<u64>, NyxdError>;
async fn get_initial_dealers(&self) -> Result<Option<InitialReplacementData>, NyxdError>;
async fn get_dealer_details(
&self,
address: &AccountId,
@@ -63,14 +62,6 @@ where
.query_contract_smart(self.coconut_dkg_contract_address(), &request)
.await
}
async fn get_initial_dealers(&self) -> Result<Option<InitialReplacementData>, NyxdError> {
let request = DkgQueryMsg::GetInitialDealers {};
self.client
.query_contract_smart(self.coconut_dkg_contract_address(), &request)
.await
}
async fn get_dealer_details(
&self,
address: &AccountId,
@@ -17,21 +17,18 @@ pub trait DkgSigningClient {
&self,
bte_key: EncodedBTEPublicKeyWithProof,
announce_address: String,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError>;
async fn submit_dealing_bytes(
&self,
commitment: ContractSafeBytes,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError>;
async fn submit_verification_key_share(
&self,
share: VerificationKeyShare,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError>;
}
@@ -60,13 +57,11 @@ where
&self,
bte_key: EncodedBTEPublicKeyWithProof,
announce_address: String,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
let req = DkgExecuteMsg::RegisterDealer {
bte_key_with_proof: bte_key,
announce_address,
resharing,
};
self.client
@@ -84,13 +79,9 @@ where
async fn submit_dealing_bytes(
&self,
dealing_bytes: ContractSafeBytes,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
let req = DkgExecuteMsg::CommitDealing {
dealing_bytes,
resharing,
};
let req = DkgExecuteMsg::CommitDealing { dealing_bytes };
self.client
.execute(
@@ -107,10 +98,9 @@ where
async fn submit_verification_key_share(
&self,
share: VerificationKeyShare,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
let req = DkgExecuteMsg::CommitVerificationKeyShare { share, resharing };
let req = DkgExecuteMsg::CommitVerificationKeyShare { share };
self.client
.execute(
@@ -1,13 +1,10 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use std::str::FromStr;
use clap::Parser;
use log::{debug, info};
use coconut_bandwidth_contract_common::msg::InstantiateMsg;
use validator_client::nyxd::AccountId;
#[derive(Debug, Parser)]
pub struct Args {
@@ -15,7 +12,7 @@ pub struct Args {
pub pool_addr: String,
#[clap(long)]
pub multisig_addr: Option<AccountId>,
pub multisig_addr: Option<String>,
#[clap(long)]
pub mix_denom: Option<String>,
@@ -27,10 +24,8 @@ pub async fn generate(args: Args) {
debug!("Received arguments: {:?}", args);
let multisig_addr = args.multisig_addr.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Multisig address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting multisig address to AccountId")
std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Multisig address has to be set")
});
let mix_denom = args.mix_denom.unwrap_or_else(|| {
@@ -39,7 +34,7 @@ pub async fn generate(args: Args) {
let instantiate_msg = InstantiateMsg {
pool_addr: args.pool_addr,
multisig_addr: multisig_addr.to_string(),
multisig_addr,
mix_denom,
};
@@ -7,7 +7,6 @@ use std::str::FromStr;
use coconut_dkg_common::msg::InstantiateMsg;
use coconut_dkg_common::types::TimeConfiguration;
use validator_client::nyxd::AccountId;
#[derive(Debug, Parser)]
pub struct Args {
@@ -15,7 +14,7 @@ pub struct Args {
pub group_addr: String,
#[clap(long)]
pub multisig_addr: Option<AccountId>,
pub multisig_addr: Option<String>,
#[clap(long)]
pub public_key_submission_time_secs: Option<u64>,
@@ -45,10 +44,8 @@ pub async fn generate(args: Args) {
debug!("Received arguments: {:?}", args);
let multisig_addr = args.multisig_addr.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Multisig address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting multisig address to AccountId")
std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Multisig address has to be set")
});
let mix_denom = args.mix_denom.unwrap_or_else(|| {
@@ -89,7 +86,7 @@ pub async fn generate(args: Args) {
let instantiate_msg = InstantiateMsg {
group_addr: args.group_addr,
multisig_addr: multisig_addr.to_string(),
multisig_addr,
time_configuration: Some(time_configuration),
mix_denom,
};
@@ -6,17 +6,15 @@ use log::{debug, info};
use cosmwasm_std::Decimal;
use mixnet_contract_common::{InitialRewardingParams, InstantiateMsg, Percent};
use std::str::FromStr;
use std::time::Duration;
use validator_client::nyxd::AccountId;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub rewarding_validator_address: Option<AccountId>,
pub rewarding_validator_address: Option<String>,
#[clap(long)]
pub vesting_contract_address: Option<AccountId>,
pub vesting_contract_address: Option<String>,
#[clap(long)]
pub rewarding_denom: Option<String>,
@@ -79,17 +77,13 @@ pub async fn generate(args: Args) {
debug!("initial_rewarding_params: {:?}", initial_rewarding_params);
let rewarding_validator_address = args.rewarding_validator_address.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Rewarding validator address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting rewarding validator address to AccountId")
std::env::var(network_defaults::var_names::REWARDING_VALIDATOR_ADDRESS)
.expect("Rewarding validator address has to be set")
});
let vesting_contract_address = args.vesting_contract_address.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::VESTING_CONTRACT_ADDRESS)
.expect("Vesting contract address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting vesting contract address to AccountId")
std::env::var(network_defaults::var_names::VESTING_CONTRACT_ADDRESS)
.expect("Vesting contract address has to be set")
});
let rewarding_denom = args.rewarding_denom.unwrap_or_else(|| {
@@ -98,8 +92,8 @@ pub async fn generate(args: Args) {
});
let instantiate_msg = InstantiateMsg {
rewarding_validator_address: rewarding_validator_address.to_string(),
vesting_contract_address: vesting_contract_address.to_string(),
rewarding_validator_address,
vesting_contract_address,
rewarding_denom,
epochs_in_interval: args.epochs_in_interval,
epoch_duration: Duration::from_secs(args.epoch_duration),
@@ -1,14 +1,12 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use std::str::FromStr;
use clap::Parser;
use log::{debug, info};
use cosmwasm_std::Decimal;
use cw_utils::{Duration, Threshold};
use log::{debug, info};
use multisig_contract_common::msg::InstantiateMsg;
use validator_client::nyxd::AccountId;
#[derive(Debug, Parser)]
pub struct Args {
@@ -22,10 +20,10 @@ pub struct Args {
pub max_voting_period: u64,
#[clap(long)]
pub coconut_bandwidth_contract_address: Option<AccountId>,
pub coconut_bandwidth_contract_address: Option<String>,
#[clap(long)]
pub coconut_dkg_contract_address: Option<AccountId>,
pub coconut_dkg_contract_address: Option<String>,
}
pub async fn generate(args: Args) {
@@ -35,18 +33,13 @@ pub async fn generate(args: Args) {
let coconut_bandwidth_contract_address =
args.coconut_bandwidth_contract_address.unwrap_or_else(|| {
let address =
std::env::var(network_defaults::var_names::COCONUT_BANDWIDTH_CONTRACT_ADDRESS)
.expect("Coconut bandwidth contract address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting bandwidth contract address to AccountId")
std::env::var(network_defaults::var_names::COCONUT_BANDWIDTH_CONTRACT_ADDRESS)
.expect("Coconut bandwidth contract address has to be set")
});
let coconut_dkg_contract_address = args.coconut_dkg_contract_address.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::COCONUT_DKG_CONTRACT_ADDRESS)
.expect("Coconut DKG contract address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting DKG contract address to AccountId")
std::env::var(network_defaults::var_names::COCONUT_DKG_CONTRACT_ADDRESS)
.expect("Coconut DKG contract address has to be set")
});
let instantiate_msg = InstantiateMsg {
@@ -56,8 +49,8 @@ pub async fn generate(args: Args) {
.expect("threshold can't be converted to Decimal"),
},
max_voting_period: Duration::Time(args.max_voting_period),
coconut_bandwidth_contract_address: coconut_bandwidth_contract_address.to_string(),
coconut_dkg_contract_address: coconut_dkg_contract_address.to_string(),
coconut_bandwidth_contract_address,
coconut_dkg_contract_address,
};
debug!("instantiate_msg: {:?}", instantiate_msg);
@@ -1,18 +1,15 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use std::str::FromStr;
use clap::Parser;
use log::{debug, info};
use validator_client::nyxd::AccountId;
use vesting_contract_common::InitMsg;
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
pub mixnet_contract_address: Option<AccountId>,
pub mixnet_contract_address: Option<String>,
#[clap(long)]
pub mix_denom: Option<String>,
@@ -24,10 +21,8 @@ pub async fn generate(args: Args) {
debug!("Received arguments: {:?}", args);
let mixnet_contract_address = args.mixnet_contract_address.unwrap_or_else(|| {
let address = std::env::var(network_defaults::var_names::MIXNET_CONTRACT_ADDRESS)
.expect("Mixnet contract address has to be set");
AccountId::from_str(address.as_str())
.expect("Failed converting mixnet address to AccountId")
std::env::var(network_defaults::var_names::MIXNET_CONTRACT_ADDRESS)
.expect("Mixnet contract address has to be set")
});
let mix_denom = args.mix_denom.unwrap_or_else(|| {
@@ -35,7 +30,7 @@ pub async fn generate(args: Args) {
});
let instantiate_msg = InitMsg {
mixnet_contract_address: mixnet_contract_address.to_string(),
mixnet_contract_address,
mix_denom,
};
@@ -21,22 +21,18 @@ pub enum ExecuteMsg {
RegisterDealer {
bte_key_with_proof: EncodedBTEPublicKeyWithProof,
announce_address: String,
resharing: bool,
},
CommitDealing {
dealing_bytes: ContractSafeBytes,
resharing: bool,
},
CommitVerificationKeyShare {
share: VerificationKeyShare,
resharing: bool,
},
VerifyVerificationKeyShare {
owner: Addr,
resharing: bool,
},
SurpassedThreshold {},
@@ -49,7 +45,6 @@ pub enum ExecuteMsg {
pub enum QueryMsg {
GetCurrentEpochState {},
GetCurrentEpochThreshold {},
GetInitialDealers {},
GetDealerDetails {
dealer_address: String,
},
@@ -18,12 +18,6 @@ pub type EpochId = u64;
// 2 public attributes, 2 private attributes, 1 fixed for coconut credential
pub const TOTAL_DEALINGS: usize = 2 + 2 + 1;
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct InitialReplacementData {
pub initial_dealers: Vec<Addr>,
pub initial_height: Option<u64>,
}
#[derive(
Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd, JsonSchema,
)]
@@ -92,17 +86,15 @@ impl Epoch {
current_timestamp: Timestamp,
) -> Self {
let duration = match state {
EpochState::PublicKeySubmission { .. } => {
time_configuration.public_key_submission_time_secs
}
EpochState::DealingExchange { .. } => time_configuration.dealing_exchange_time_secs,
EpochState::VerificationKeySubmission { .. } => {
EpochState::PublicKeySubmission => time_configuration.public_key_submission_time_secs,
EpochState::DealingExchange => time_configuration.dealing_exchange_time_secs,
EpochState::VerificationKeySubmission => {
time_configuration.verification_key_submission_time_secs
}
EpochState::VerificationKeyValidation { .. } => {
EpochState::VerificationKeyValidation => {
time_configuration.verification_key_validation_time_secs
}
EpochState::VerificationKeyFinalization { .. } => {
EpochState::VerificationKeyFinalization => {
time_configuration.verification_key_finalization_time_secs
}
EpochState::InProgress => time_configuration.in_progress_time_secs,
@@ -131,36 +123,28 @@ impl Epoch {
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum EpochState {
PublicKeySubmission { resharing: bool },
DealingExchange { resharing: bool },
VerificationKeySubmission { resharing: bool },
VerificationKeyValidation { resharing: bool },
VerificationKeyFinalization { resharing: bool },
PublicKeySubmission,
DealingExchange,
VerificationKeySubmission,
VerificationKeyValidation,
VerificationKeyFinalization,
InProgress,
}
impl Default for EpochState {
fn default() -> Self {
Self::PublicKeySubmission { resharing: false }
Self::PublicKeySubmission
}
}
impl Display for EpochState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
EpochState::PublicKeySubmission { resharing } => {
write!(f, "PublicKeySubmission with resharing {resharing}")
}
EpochState::DealingExchange { resharing } => write!(f, "DealingExchange {resharing}"),
EpochState::VerificationKeySubmission { resharing } => {
write!(f, "VerificationKeySubmission with resharing {resharing}")
}
EpochState::VerificationKeyValidation { resharing } => {
write!(f, "VerificationKeyValidation with resharing {resharing}")
}
EpochState::VerificationKeyFinalization { resharing } => {
write!(f, "VerificationKeyFinalization with resharing {resharing}")
}
EpochState::PublicKeySubmission => write!(f, "PublicKeySubmission"),
EpochState::DealingExchange => write!(f, "DealingExchange"),
EpochState::VerificationKeySubmission => write!(f, "VerificationKeySubmission"),
EpochState::VerificationKeyValidation => write!(f, "VerificationKeyValidation"),
EpochState::VerificationKeyFinalization => write!(f, "VerificationKeyFinalization"),
EpochState::InProgress => write!(f, "InProgress"),
}
}
@@ -169,19 +153,11 @@ impl Display for EpochState {
impl EpochState {
pub fn next(self) -> Option<Self> {
match self {
EpochState::PublicKeySubmission { resharing } => {
Some(EpochState::DealingExchange { resharing })
}
EpochState::DealingExchange { resharing } => {
Some(EpochState::VerificationKeySubmission { resharing })
}
EpochState::VerificationKeySubmission { resharing } => {
Some(EpochState::VerificationKeyValidation { resharing })
}
EpochState::VerificationKeyValidation { resharing } => {
Some(EpochState::VerificationKeyFinalization { resharing })
}
EpochState::VerificationKeyFinalization { .. } => Some(EpochState::InProgress),
EpochState::PublicKeySubmission => Some(EpochState::DealingExchange),
EpochState::DealingExchange => Some(EpochState::VerificationKeySubmission),
EpochState::VerificationKeySubmission => Some(EpochState::VerificationKeyValidation),
EpochState::VerificationKeyValidation => Some(EpochState::VerificationKeyFinalization),
EpochState::VerificationKeyFinalization => Some(EpochState::InProgress),
EpochState::InProgress => None,
}
}
@@ -30,12 +30,11 @@ pub struct PagedVKSharesResponse {
pub fn to_cosmos_msg(
owner: Addr,
resharing: bool,
coconut_dkg_addr: String,
multisig_addr: String,
expiration_time: Timestamp,
) -> StdResult<CosmosMsg> {
let verify_vk_share_req = ExecuteMsg::VerifyVerificationKeyShare { owner, resharing };
let verify_vk_share_req = ExecuteMsg::VerifyVerificationKeyShare { owner };
let verify_vk_share_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: coconut_dkg_addr,
msg: to_binary(&verify_vk_share_req)?,
@@ -63,8 +62,7 @@ pub fn owner_from_cosmos_msgs(msgs: &[CosmosMsg]) -> Option<Addr> {
funds: _,
})) = msgs.get(0)
{
if let Ok(ExecuteMsg::VerifyVerificationKeyShare { owner, .. }) =
from_binary::<ExecuteMsg>(msg)
if let Ok(ExecuteMsg::VerifyVerificationKeyShare { owner }) = from_binary::<ExecuteMsg>(msg)
{
return Some(owner);
}
@@ -15,4 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
thiserror = "1"
[dev-dependencies]
serde_json = "1.0.0"
serde_json = "1.0.0"
[features]
coconut = ["dkg"]
@@ -1,7 +1,7 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "dkg")]
#[cfg(feature = "coconut")]
use dkg::{error::DkgError, Dealing};
use schemars::JsonSchema;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -70,14 +70,14 @@ impl<'de> Deserialize<'de> for ContractSafeBytes {
}
}
#[cfg(feature = "dkg")]
#[cfg(feature = "coconut")]
impl<'a> From<&'a Dealing> for ContractSafeBytes {
fn from(dealing: &'a Dealing) -> Self {
ContractSafeBytes(dealing.to_bytes())
}
}
#[cfg(feature = "dkg")]
#[cfg(feature = "coconut")]
impl<'a> TryFrom<&'a ContractSafeBytes> for Dealing {
type Error = DkgError;
Binary file not shown.
@@ -17,7 +17,10 @@ pub struct InitMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
pub struct MigrateMsg {
// I'm making it explicit so that we wouldn't accidentally forget about it
pub manually_verified_no_staking_addresses: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)]
pub struct VestingSpecification {
+3 -1
View File
@@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
bls12_381 = { version = "0.5", default-features = false, features = ["pairings", "alloc", "experimental"] }
cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegrant_support" }
cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegrant_support", optional = true }
thiserror = "1.0"
# I guess temporarily until we get serde support in coconut up and running
@@ -19,3 +19,5 @@ validator-client = { path = "../client-libs/validator-client" }
[dev-dependencies]
rand = "0.7.3"
[features]
coconut = ["cosmrs"]
+4 -10
View File
@@ -92,7 +92,6 @@ pub async fn obtain_aggregate_signature(
params: &Parameters,
attributes: &BandwidthVoucher,
coconut_api_clients: &[CoconutApiClient],
threshold: u64,
) -> Result<Signature, Error> {
if coconut_api_clients.is_empty() {
return Err(Error::NoValidatorsAvailable);
@@ -111,20 +110,15 @@ pub async fn obtain_aggregate_signature(
.collect();
for coconut_api_client in coconut_api_clients.iter() {
if let Ok(signature) = obtain_partial_credential(
let signature = obtain_partial_credential(
params,
attributes,
&coconut_api_client.api_client,
&coconut_api_client.verification_key,
)
.await
{
let share = SignatureShare::new(signature, coconut_api_client.node_id);
shares.push(share)
}
}
if shares.len() < threshold as usize {
return Err(Error::NotEnoughShares);
.await?;
let share = SignatureShare::new(signature, coconut_api_client.node_id);
shares.push(share)
}
let mut attributes = Vec::with_capacity(private_attributes.len() + public_attributes.len());
+2 -3
View File
@@ -1,6 +1,7 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "coconut")]
use coconut_interface::CoconutError;
use crypto::asymmetric::encryption::KeyRecoveryError;
use validator_client::ValidatorClientError;
@@ -15,6 +16,7 @@ pub enum Error {
#[error("Could not contact any validator")]
NoValidatorsAvailable,
#[cfg(feature = "coconut")]
#[error("Ran into a coconut error - {0}")]
CoconutError(#[from] CoconutError),
@@ -29,7 +31,4 @@ pub enum Error {
#[error("Could not parse the key - {0}")]
ParsePublicKey(#[from] KeyRecoveryError),
#[error("Could not gather enough signature shares")]
NotEnoughShares,
}
+4
View File
@@ -1,7 +1,11 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "coconut")]
pub mod coconut;
pub mod error;
#[cfg(not(feature = "coconut"))]
pub mod token;
#[cfg(feature = "coconut")]
pub use coconut::utils::{obtain_aggregate_signature, obtain_aggregate_verification_key};
+137
View File
@@ -0,0 +1,137 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crypto::asymmetric::identity::{PublicKey, Signature, PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH};
use crate::error::Error;
use std::convert::TryInto;
pub struct TokenCredential {
verification_key: PublicKey,
gateway_identity: PublicKey,
bandwidth: u64,
signature: Signature,
}
impl TokenCredential {
pub fn new(
verification_key: PublicKey,
gateway_identity: PublicKey,
bandwidth: u64,
signature: Signature,
) -> Self {
TokenCredential {
verification_key,
gateway_identity,
bandwidth,
signature,
}
}
pub fn verification_key(&self) -> PublicKey {
self.verification_key
}
pub fn gateway_identity(&self) -> PublicKey {
self.gateway_identity
}
pub fn bandwidth(&self) -> u64 {
self.bandwidth
}
pub fn signature_bytes(&self) -> [u8; 64] {
self.signature.to_bytes()
}
pub fn verify_signature(&self) -> bool {
let message: Vec<u8> = self
.verification_key
.to_bytes()
.iter()
.chain(self.gateway_identity.to_bytes().iter())
.copied()
.collect();
self.verification_key
.verify(&message, &self.signature)
.is_ok()
}
pub fn to_bytes(&self) -> Vec<u8> {
self.verification_key
.to_bytes()
.iter()
.chain(self.gateway_identity.to_bytes().iter())
.chain(self.bandwidth.to_be_bytes().iter())
.chain(self.signature.to_bytes().iter())
.copied()
.collect()
}
pub fn from_bytes(b: &[u8]) -> Result<Self, Error> {
if b.len() != 2 * PUBLIC_KEY_LENGTH + 8 + SIGNATURE_LENGTH {
return Err(Error::BandwidthCredentialError);
}
let verification_key = PublicKey::from_bytes(&b[..PUBLIC_KEY_LENGTH])
.map_err(|_| Error::BandwidthCredentialError)?;
let gateway_identity = PublicKey::from_bytes(&b[PUBLIC_KEY_LENGTH..2 * PUBLIC_KEY_LENGTH])
.map_err(|_| Error::BandwidthCredentialError)?;
let bandwidth = u64::from_be_bytes(
b[2 * PUBLIC_KEY_LENGTH..2 * PUBLIC_KEY_LENGTH + 8]
.try_into()
// unwrapping is safe because we know we have 8 bytes
.unwrap(),
);
let signature = Signature::from_bytes(&b[2 * PUBLIC_KEY_LENGTH + 8..])
.map_err(|_| Error::BandwidthCredentialError)?;
Ok(TokenCredential {
verification_key,
gateway_identity,
bandwidth,
signature,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn token_serde() {
// pre-generated, valid values
let verification_key = PublicKey::from_bytes(&[
103, 105, 71, 177, 149, 245, 26, 32, 73, 121, 76, 50, 94, 88, 119, 231, 91, 229, 167,
56, 39, 62, 185, 39, 83, 246, 153, 27, 17, 155, 109, 73,
])
.unwrap();
let gateway_identity = PublicKey::from_bytes(&[
37, 113, 137, 189, 157, 82, 35, 2, 187, 136, 61, 119, 98, 5, 245, 82, 46, 124, 67, 45,
165, 255, 53, 222, 185, 252, 6, 148, 128, 15, 206, 19,
])
.unwrap();
let signature = Signature::from_bytes(&[
117, 251, 162, 217, 57, 2, 50, 210, 206, 81, 236, 90, 74, 201, 69, 237, 240, 247, 214,
158, 220, 89, 235, 222, 85, 134, 73, 73, 8, 60, 25, 39, 183, 28, 83, 193, 31, 174, 25,
24, 38, 215, 205, 228, 159, 135, 35, 4, 171, 59, 100, 157, 12, 249, 77, 52, 143, 4, 32,
28, 147, 70, 182, 14,
])
.unwrap();
let credential = TokenCredential::new(verification_key, gateway_identity, 1024, signature);
let serialized_credential = credential.to_bytes();
let deserialized_credential = TokenCredential::from_bytes(&serialized_credential).unwrap();
assert_eq!(
credential.verification_key,
deserialized_credential.verification_key
);
assert_eq!(
credential.gateway_identity,
deserialized_credential.gateway_identity
);
assert_eq!(credential.bandwidth, deserialized_credential.bandwidth);
assert_eq!(
credential.signature.to_bytes(),
deserialized_credential.signature.to_bytes()
);
}
}
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
pub mod bandwidth;
-11
View File
@@ -1,11 +0,0 @@
[package]
name = "mobile-storage"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-trait = { version = "0.1.51" }
thiserror = "1.0"
-67
View File
@@ -1,67 +0,0 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use async_trait::async_trait;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StorageError {
#[error("Android is not yet supported")]
AndroidNotSupported,
#[allow(dead_code)]
#[error("Code shouldn't reach this point")]
InconsistentData,
}
#[derive(Clone)]
pub struct PersistentStorage {}
pub struct CoconutCredential {
pub id: i64,
pub voucher_value: String,
pub voucher_info: String,
pub serial_number: String,
pub binding_number: String,
pub signature: String,
pub epoch_id: String,
pub consumed: bool,
}
#[async_trait]
pub trait Storage: Send + Sync {
async fn insert_coconut_credential(
&self,
voucher_value: String,
voucher_info: String,
serial_number: String,
binding_number: String,
signature: String,
) -> Result<(), StorageError>;
async fn get_next_coconut_credential(&self) -> Result<CoconutCredential, StorageError>;
async fn consume_coconut_credential(&self, id: i64) -> Result<(), StorageError>;
}
#[async_trait]
impl Storage for PersistentStorage {
async fn insert_coconut_credential(
&self,
_voucher_value: String,
_voucher_info: String,
_serial_number: String,
_binding_number: String,
_signature: String,
) -> Result<(), StorageError> {
Err(StorageError::AndroidNotSupported)
}
async fn get_next_coconut_credential(&self) -> Result<CoconutCredential, StorageError> {
Err(StorageError::AndroidNotSupported)
}
async fn consume_coconut_credential(&self, _id: i64) -> Result<(), StorageError> {
Err(StorageError::AndroidNotSupported)
}
}
-4
View File
@@ -93,10 +93,6 @@ impl SecretKey {
Self { x, ys }
}
pub fn into_raw(&self) -> (Scalar, Vec<Scalar>) {
(self.x, self.ys.clone())
}
/// Derive verification key using this secret key.
pub fn verification_key(&self, params: &Parameters) -> VerificationKey {
let g1 = params.gen1();
@@ -12,7 +12,7 @@ bs58 = "0.4"
serde = "1.0"
thiserror = "1"
crypto = { path = "../../crypto", features = ["symmetric", "rand"] }
crypto = { path = "../../crypto" }
nymsphinx-addressing = { path = "../addressing" }
nymsphinx-params = { path = "../params" }
nymsphinx-types = { path = "../types" }
@@ -6,7 +6,7 @@ use futures::channel::mpsc;
use futures::StreamExt;
use log::*;
use ordered_buffer::{OrderedMessage, OrderedMessageBuffer, ReadContiguousData};
use socks5_requests::{ConnectionId, NetworkData, SendRequest};
use socks5_requests::ConnectionId;
use std::{
collections::{HashMap, HashSet},
time::Duration,
@@ -36,38 +36,9 @@ pub type ControllerSender = mpsc::UnboundedSender<ControllerCommand>;
pub type ControllerReceiver = mpsc::UnboundedReceiver<ControllerCommand>;
pub enum ControllerCommand {
Insert {
connection_id: ConnectionId,
connection_sender: ConnectionSender,
},
Remove {
connection_id: ConnectionId,
},
Send {
connection_id: ConnectionId,
data: Vec<u8>,
is_closed: bool,
},
}
impl From<NetworkData> for ControllerCommand {
fn from(value: NetworkData) -> Self {
ControllerCommand::Send {
connection_id: value.connection_id,
data: value.data,
is_closed: value.is_closed,
}
}
}
impl From<SendRequest> for ControllerCommand {
fn from(value: SendRequest) -> Self {
ControllerCommand::Send {
connection_id: value.conn_id,
data: value.data,
is_closed: value.local_closed,
}
}
Insert(ConnectionId, ConnectionSender),
Remove(ConnectionId),
Send(ConnectionId, Vec<u8>, bool),
}
struct ActiveConnection {
@@ -264,13 +235,13 @@ impl Controller {
loop {
tokio::select! {
command = self.receiver.next() => match command {
Some(ControllerCommand::Send{connection_id, data, is_closed}) => {
self.send_to_connection(connection_id, data, is_closed)
Some(ControllerCommand::Send(conn_id, data, is_closed)) => {
self.send_to_connection(conn_id, data, is_closed)
}
Some(ControllerCommand::Insert{connection_id, connection_sender}) => {
self.insert_connection(connection_id, connection_sender)
Some(ControllerCommand::Insert(conn_id, sender)) => {
self.insert_connection(conn_id, sender)
}
Some(ControllerCommand::Remove{ connection_id }) => self.remove_connection(connection_id),
Some(ControllerCommand::Remove(conn_id)) => self.remove_connection(conn_id),
None => {
log::trace!("SOCKS5 Controller: Stopping since channel closed");
break;
+1 -5
View File
@@ -7,9 +7,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
thiserror = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
nymsphinx-addressing = { path = "../../../common/nymsphinx/addressing" }
service-providers-common = { path = "../../../service-providers/common" }
thiserror = "1"
+7 -123
View File
@@ -1,128 +1,12 @@
// Copyright 2020-2023 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2020-2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use service_providers_common::interface;
use service_providers_common::interface::ServiceProviderMessagingError;
use thiserror::Error;
pub use request::*;
pub use response::*;
pub use version::*;
pub mod msg;
pub mod network_requester_response;
pub mod request;
pub mod response;
pub mod version;
pub type Socks5ProviderRequest = interface::Request<Socks5Request>;
pub type Socks5ProviderResponse = interface::Response<Socks5Request>;
#[derive(Debug, Error)]
pub enum Socks5RequestError {
#[error("failed to deserialize received request: {source}")]
RequestDeserialization {
#[from]
source: RequestDeserializationError,
},
#[error("failed to deserialize received response: {source}")]
ResponseDeserialization {
#[from]
source: ResponseDeserializationError,
},
#[error(transparent)]
ProviderInterfaceError(#[from] ServiceProviderMessagingError),
}
#[cfg(test)]
mod tests {
use super::*;
use service_providers_common::interface::RequestContent;
#[cfg(test)]
mod interface_backwards_compatibility {
use super::*;
use service_providers_common::interface::ProviderInterfaceVersion;
#[test]
fn old_client_vs_new_service_provider() {
let old_serialized_connect = vec![
0, 0, 2, 254, 34, 100, 192, 20, 13, 171, 0, 16, 56, 48, 46, 50, 52, 57, 46, 57, 57,
46, 49, 52, 56, 58, 56, 48, 34, 112, 17, 182, 225, 6, 174, 216, 160, 41, 72, 236,
160, 90, 156, 3, 250, 41, 243, 53, 191, 178, 218, 53, 170, 14, 185, 33, 94, 153,
25, 41, 6, 82, 169, 187, 88, 246, 211, 57, 68, 225, 228, 231, 116, 29, 119, 235,
160, 14, 156, 205, 66, 1, 75, 204, 204, 220, 14, 150, 191, 203, 174, 88, 121, 173,
83, 219, 188, 164, 194, 212, 238, 228, 4, 128, 48, 105, 224, 83, 17, 246, 233, 16,
235, 223, 68, 87, 13, 40, 34, 186, 218, 204, 126, 145,
];
let new_deserialized =
Socks5ProviderRequest::try_from_bytes(&old_serialized_connect).unwrap();
match new_deserialized.content {
RequestContent::ProviderData(req) => match req.content {
Socks5RequestContent::Connect(connect_req) => {
assert_eq!(connect_req.remote_addr, "80.249.99.148:80".to_string());
assert_eq!(connect_req.conn_id, 215647648274976171);
assert_eq!(connect_req.return_address, Some("3KRydEpanwjFhq5GAraVjRUF1Tno7w7oc4EwJYTGNo5J.RgZ7uMJHruBQqD5hC9Ghi3sqiTn6NycfM5qCfJz6yoM@9Byd9VAtyYMnbVAcqdoQxJnq76XEg2dbxbiF5Aa5Jj9J".parse().unwrap()));
}
_ => panic!("unexpected request"),
},
_ => panic!("unexpected request"),
}
let old_serialized_send = vec![
0, 1, 108, 102, 28, 19, 50, 178, 37, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 69, 84,
32, 47, 49, 77, 66, 46, 122, 105, 112, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10,
72, 111, 115, 116, 58, 32, 105, 112, 118, 52, 46, 100, 111, 119, 110, 108, 111, 97,
100, 46, 116, 104, 105, 110, 107, 98, 114, 111, 97, 100, 98, 97, 110, 100, 46, 99,
111, 109, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117,
114, 108, 47, 55, 46, 54, 56, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32,
42, 47, 42, 13, 10, 13, 10,
];
let new_deserialized =
Socks5ProviderRequest::try_from_bytes(&old_serialized_send).unwrap();
match new_deserialized.content {
RequestContent::ProviderData(req) => match req.content {
Socks5RequestContent::Send(send_req) => {
assert_eq!(send_req.conn_id, 7810961472501196273);
assert_eq!(send_req.data.len(), 111);
assert!(!send_req.local_closed);
}
_ => panic!("unexpected request"),
},
_ => panic!("unexpected request"),
}
}
#[test]
fn new_client_vs_old_service_provider() {
let return_address = "3KRydEpanwjFhq5GAraVjRUF1Tno7w7oc4EwJYTGNo5J.RgZ7uMJHruBQqD5hC9Ghi3sqiTn6NycfM5qCfJz6yoM@9Byd9VAtyYMnbVAcqdoQxJnq76XEg2dbxbiF5Aa5Jj9J".parse().unwrap();
let new_connect = Socks5ProviderRequest::new_provider_data(
ProviderInterfaceVersion::Legacy,
Socks5Request::new_connect(
Socks5ProtocolVersion::Legacy,
215647648274976171,
"80.249.99.148:80".to_string(),
Some(return_address),
),
);
let legacy_serialised = new_connect.into_bytes();
let old_serialized_connect = vec![
0, 0, 2, 254, 34, 100, 192, 20, 13, 171, 0, 16, 56, 48, 46, 50, 52, 57, 46, 57, 57,
46, 49, 52, 56, 58, 56, 48, 34, 112, 17, 182, 225, 6, 174, 216, 160, 41, 72, 236,
160, 90, 156, 3, 250, 41, 243, 53, 191, 178, 218, 53, 170, 14, 185, 33, 94, 153,
25, 41, 6, 82, 169, 187, 88, 246, 211, 57, 68, 225, 228, 231, 116, 29, 119, 235,
160, 14, 156, 205, 66, 1, 75, 204, 204, 220, 14, 150, 191, 203, 174, 88, 121, 173,
83, 219, 188, 164, 194, 212, 238, 228, 4, 128, 48, 105, 224, 83, 17, 246, 233, 16,
235, 223, 68, 87, 13, 40, 34, 186, 218, 204, 126, 145,
];
assert_eq!(legacy_serialised, old_serialized_connect);
}
}
}
pub use msg::*;
pub use network_requester_response::*;
pub use request::*;
pub use response::*;
+97
View File
@@ -0,0 +1,97 @@
// Copyright 2020-2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use thiserror::Error;
use crate::network_requester_response::{Error as NrError, NetworkRequesterResponse};
use crate::request::{Request, RequestError};
use crate::response::{Response, ResponseError};
#[derive(Debug, Error)]
pub enum MessageError {
#[error(transparent)]
Request(RequestError),
#[error("{0:?}")]
Response(ResponseError),
#[error(transparent)]
NetworkRequesterResponseError(NrError),
#[error("no data")]
NoData,
#[error("unknown message type received")]
UnknownMessageType,
}
#[derive(Debug)]
pub enum Message {
Request(Request),
Response(Response),
NetworkRequesterResponse(NetworkRequesterResponse),
}
impl Message {
const REQUEST_FLAG: u8 = 0;
const RESPONSE_FLAG: u8 = 1;
const NR_RESPONSE_FLAG: u8 = 2;
pub fn conn_id(&self) -> u64 {
match self {
Message::Request(req) => match req {
Request::Connect(c) => c.conn_id,
Request::Send(conn_id, _, _) => *conn_id,
},
Message::Response(resp) => resp.connection_id,
Message::NetworkRequesterResponse(resp) => resp.connection_id,
}
}
pub fn size(&self) -> usize {
match self {
Message::Request(req) => match req {
Request::Connect(_) => 0,
Request::Send(_, data, _) => data.len(),
},
Message::Response(resp) => resp.data.len(),
Message::NetworkRequesterResponse(_) => 0,
}
}
pub fn try_from_bytes(b: &[u8]) -> Result<Message, MessageError> {
if b.is_empty() {
return Err(MessageError::NoData);
}
if b[0] == Self::REQUEST_FLAG {
Request::try_from_bytes(&b[1..])
.map(Message::Request)
.map_err(MessageError::Request)
} else if b[0] == Self::RESPONSE_FLAG {
Response::try_from_bytes(&b[1..])
.map(Message::Response)
.map_err(MessageError::Response)
} else if b[0] == Self::NR_RESPONSE_FLAG {
NetworkRequesterResponse::try_from_bytes(&b[1..])
.map(Message::NetworkRequesterResponse)
.map_err(MessageError::NetworkRequesterResponseError)
} else {
Err(MessageError::UnknownMessageType)
}
}
pub fn into_bytes(self) -> Vec<u8> {
match self {
Self::Request(r) => std::iter::once(Self::REQUEST_FLAG)
.chain(r.into_bytes().iter().cloned())
.collect(),
Self::Response(r) => std::iter::once(Self::RESPONSE_FLAG)
.chain(r.into_bytes().iter().cloned())
.collect(),
Self::NetworkRequesterResponse(r) => std::iter::once(Self::NR_RESPONSE_FLAG)
.chain(r.into_bytes().iter().cloned())
.collect(),
}
}
}
@@ -0,0 +1,112 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::ConnectionId;
#[derive(Debug)]
pub struct NetworkRequesterResponse {
pub connection_id: ConnectionId,
pub network_requester_error: String,
}
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
#[error("no data provided")]
NoData,
#[error("not enough bytes to recover the connection id")]
ConnectionIdTooShort,
#[error("message is not utf8 encoded")]
MalformedErrorMessage(#[from] std::string::FromUtf8Error),
}
impl NetworkRequesterResponse {
pub fn new(connection_id: ConnectionId, network_requester_error: String) -> Self {
NetworkRequesterResponse {
connection_id,
network_requester_error,
}
}
pub fn try_from_bytes(b: &[u8]) -> Result<NetworkRequesterResponse, Error> {
if b.is_empty() {
return Err(Error::NoData);
}
if b.len() < 8 {
return Err(Error::ConnectionIdTooShort);
}
let mut connection_id_bytes = b.to_vec();
let network_requester_error_bytes = connection_id_bytes.split_off(8);
let connection_id = u64::from_be_bytes([
connection_id_bytes[0],
connection_id_bytes[1],
connection_id_bytes[2],
connection_id_bytes[3],
connection_id_bytes[4],
connection_id_bytes[5],
connection_id_bytes[6],
connection_id_bytes[7],
]);
let network_requester_error = String::from_utf8(network_requester_error_bytes)?;
Ok(NetworkRequesterResponse {
connection_id,
network_requester_error,
})
}
pub fn into_bytes(self) -> Vec<u8> {
self.connection_id
.to_be_bytes()
.iter()
.copied()
.chain(self.network_requester_error.into_bytes().into_iter())
.collect()
}
}
#[cfg(test)]
mod network_requester_response_serde_tests {
use super::*;
#[test]
fn simple_serde() {
let conn_id = 42;
let network_requester_error = String::from("This is a test msg");
let response = NetworkRequesterResponse::new(conn_id, network_requester_error.clone());
let bytes = response.into_bytes();
let deserialized_response = NetworkRequesterResponse::try_from_bytes(&bytes).unwrap();
assert_eq!(conn_id, deserialized_response.connection_id);
assert_eq!(
network_requester_error,
deserialized_response.network_requester_error
);
}
#[test]
fn deserialization_errors() {
let err = NetworkRequesterResponse::try_from_bytes(&[]).err().unwrap();
assert_eq!(err, Error::NoData);
let bytes: [u8; 5] = [1, 2, 3, 4, 5];
let err = NetworkRequesterResponse::try_from_bytes(&bytes)
.err()
.unwrap();
assert_eq!(err, Error::ConnectionIdTooShort);
let bytes: Vec<u8> = 42u64
.to_be_bytes()
.into_iter()
.chain([0, 159, 146, 150].into_iter())
.collect();
let err = NetworkRequesterResponse::try_from_bytes(&bytes)
.err()
.unwrap();
assert!(matches!(err, Error::MalformedErrorMessage(_)));
}
}
+55 -178
View File
@@ -1,9 +1,7 @@
// Copyright 2020-2023 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2020-2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::{Socks5ProtocolVersion, Socks5RequestError, Socks5Response};
use nymsphinx_addressing::clients::{Recipient, RecipientFormattingError};
use service_providers_common::interface::{Serializable, ServiceProviderRequest};
use std::convert::TryFrom;
use thiserror::Error;
@@ -18,19 +16,19 @@ pub enum RequestFlag {
}
impl TryFrom<u8> for RequestFlag {
type Error = RequestDeserializationError;
type Error = RequestError;
fn try_from(value: u8) -> Result<RequestFlag, RequestDeserializationError> {
fn try_from(value: u8) -> Result<RequestFlag, RequestError> {
match value {
_ if value == (RequestFlag::Connect as u8) => Ok(Self::Connect),
_ if value == (RequestFlag::Send as u8) => Ok(Self::Send),
value => Err(RequestDeserializationError::UnknownRequestFlag { value }),
_ => Err(RequestError::UnknownRequestFlag),
}
}
}
#[derive(Debug, Error)]
pub enum RequestDeserializationError {
pub enum RequestError {
#[error("not enough bytes to recover the length of the address")]
AddressLengthTooShort,
@@ -43,8 +41,8 @@ pub enum RequestDeserializationError {
#[error("no data provided")]
NoData,
#[error("{value} is not a valid request flag")]
UnknownRequestFlag { value: u8 },
#[error("request of unknown type")]
UnknownRequestFlag,
#[error("too short return address")]
ReturnAddressTooShort,
@@ -53,13 +51,13 @@ pub enum RequestDeserializationError {
MalformedReturnAddress(RecipientFormattingError),
}
impl RequestDeserializationError {
impl RequestError {
pub fn is_malformed_return(&self) -> bool {
matches!(self, RequestDeserializationError::MalformedReturnAddress(_))
matches!(self, RequestError::MalformedReturnAddress(_))
}
}
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct ConnectRequest {
// TODO: is connection_id redundant now?
pub conn_id: ConnectionId,
@@ -67,128 +65,27 @@ pub struct ConnectRequest {
pub return_address: Option<Recipient>,
}
#[derive(Debug, Clone)]
pub struct SendRequest {
pub conn_id: ConnectionId,
pub data: Vec<u8>,
pub local_closed: bool,
}
#[derive(Debug, Clone)]
pub struct Socks5Request {
pub protocol_version: Socks5ProtocolVersion,
pub content: Socks5RequestContent,
}
impl Serializable for Socks5Request {
type Error = Socks5RequestError;
// legacy requests had the format of
// 0 (Message::REQUEST_FLAG) || 0 (RequestFlag::Connect) || <data> for connect requests
// 0 (Message::REQUEST_FLAG) || 1 (RequestFlag::Send) || <data> for send requests
// the updated formats use
// 3 (Socks5ProtocolVersion) || 0 (RequestFlag::Connect) || <data> for connect requests
// 3 (Socks5ProtocolVersion) || 1 (RequestFlag::Send) || <data> for send requests
// in both cases, the actual data is serialized the same way, so the process is quite straight forward
fn into_bytes(self) -> Vec<u8> {
if let Some(version) = self.protocol_version.as_u8() {
std::iter::once(version)
.chain(self.content.into_bytes().into_iter())
.collect()
} else {
std::iter::once(Self::LEGACY_TYPE_TAG)
.chain(self.content.into_bytes())
.collect()
}
}
fn try_from_bytes(b: &[u8]) -> Result<Self, Self::Error> {
if b.is_empty() {
return Err(RequestDeserializationError::NoData.into());
}
let protocol_version = Socks5ProtocolVersion::from(b[0]);
Ok(Socks5Request {
protocol_version,
content: Socks5RequestContent::try_from_bytes(&b[1..])?,
})
}
}
impl ServiceProviderRequest for Socks5Request {
type ProtocolVersion = Socks5ProtocolVersion;
type Response = Socks5Response;
type Error = Socks5RequestError;
fn provider_specific_version(&self) -> Self::ProtocolVersion {
self.protocol_version
}
fn max_supported_version() -> Self::ProtocolVersion {
Socks5ProtocolVersion::new_current()
}
}
impl Socks5Request {
// type tag that used to be prepended to all request messages
const LEGACY_TYPE_TAG: u8 = 0x00;
pub fn new(
protocol_version: Socks5ProtocolVersion,
content: Socks5RequestContent,
) -> Socks5Request {
Socks5Request {
protocol_version,
content,
}
}
pub fn new_connect(
protocol_version: Socks5ProtocolVersion,
conn_id: ConnectionId,
remote_addr: RemoteAddress,
return_address: Option<Recipient>,
) -> Socks5Request {
Socks5Request {
protocol_version,
content: Socks5RequestContent::new_connect(conn_id, remote_addr, return_address),
}
}
pub fn new_send(
protocol_version: Socks5ProtocolVersion,
conn_id: ConnectionId,
data: Vec<u8>,
local_closed: bool,
) -> Socks5Request {
Socks5Request {
protocol_version,
content: Socks5RequestContent::new_send(conn_id, data, local_closed),
}
}
}
/// A request from a SOCKS5 client that a Nym Socks5 service provider should
/// take an action for an application using a (probably local) Nym Socks5 proxy.
#[derive(Debug, Clone)]
pub enum Socks5RequestContent {
#[derive(Debug)]
pub enum Request {
/// Start a new TCP connection to the specified `RemoteAddress` and send
/// the request data up the connection.
/// All responses produced on this `ConnectionId` should come back to the specified `Recipient`
Connect(Box<ConnectRequest>),
/// Re-use an existing TCP connection, sending more request data up it.
Send(SendRequest),
Send(ConnectionId, Vec<u8>, bool),
}
impl Socks5RequestContent {
impl Request {
/// Construct a new Request::Connect instance
pub fn new_connect(
conn_id: ConnectionId,
remote_addr: RemoteAddress,
return_address: Option<Recipient>,
) -> Socks5RequestContent {
Socks5RequestContent::Connect(Box::new(ConnectRequest {
) -> Request {
Request::Connect(Box::new(ConnectRequest {
conn_id,
remote_addr,
return_address,
@@ -196,16 +93,8 @@ impl Socks5RequestContent {
}
/// Construct a new Request::Send instance
pub fn new_send(
conn_id: ConnectionId,
data: Vec<u8>,
local_closed: bool,
) -> Socks5RequestContent {
Socks5RequestContent::Send(SendRequest {
conn_id,
data,
local_closed,
})
pub fn new_send(conn_id: ConnectionId, data: Vec<u8>, local_closed: bool) -> Request {
Request::Send(conn_id, data, local_closed)
}
/// Deserialize the request type, connection id, destination address and port,
@@ -222,23 +111,23 @@ impl Socks5RequestContent {
/// The request_flag tells us whether this is a new connection request (`new_connect`),
/// an already-established connection we should send up (`new_send`), or
/// a request to close an established connection (`new_close`).
pub fn try_from_bytes(b: &[u8]) -> Result<Socks5RequestContent, RequestDeserializationError> {
pub fn try_from_bytes(b: &[u8]) -> Result<Request, RequestError> {
// each request needs to at least contain flag and ConnectionId
if b.is_empty() {
return Err(RequestDeserializationError::NoData);
return Err(RequestError::NoData);
}
if b.len() < 9 {
return Err(RequestDeserializationError::ConnectionIdTooShort);
return Err(RequestError::ConnectionIdTooShort);
}
let conn_id = u64::from_be_bytes([b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8]]);
let connection_id = u64::from_be_bytes([b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8]]);
match RequestFlag::try_from(b[0])? {
RequestFlag::Connect => {
let connect_request_bytes = &b[9..];
// we need to be able to read at least 2 bytes that specify address length
if connect_request_bytes.len() < 2 {
return Err(RequestDeserializationError::AddressLengthTooShort);
return Err(RequestError::AddressLengthTooShort);
}
let address_length =
@@ -246,7 +135,7 @@ impl Socks5RequestContent {
as usize;
if connect_request_bytes.len() < 2 + address_length {
return Err(RequestDeserializationError::AddressTooShort);
return Err(RequestError::AddressTooShort);
}
let address_start = 2;
@@ -261,19 +150,19 @@ impl Socks5RequestContent {
None
} else {
if recipient_data_bytes.len() != Recipient::LEN {
return Err(RequestDeserializationError::ReturnAddressTooShort);
return Err(RequestError::ReturnAddressTooShort);
}
let mut return_bytes = [0u8; Recipient::LEN];
return_bytes.copy_from_slice(&recipient_data_bytes[..Recipient::LEN]);
Some(
Recipient::try_from_bytes(return_bytes)
.map_err(RequestDeserializationError::MalformedReturnAddress)?,
.map_err(RequestError::MalformedReturnAddress)?,
)
};
Ok(Socks5RequestContent::new_connect(
conn_id,
Ok(Request::new_connect(
connection_id,
remote_address,
return_address,
))
@@ -282,11 +171,7 @@ impl Socks5RequestContent {
let local_closed = b[9] != 0;
let data = b[10..].to_vec();
Ok(Socks5RequestContent::Send(SendRequest {
conn_id,
data,
local_closed,
}))
Ok(Request::Send(connection_id, data, local_closed))
}
}
}
@@ -297,7 +182,7 @@ impl Socks5RequestContent {
pub fn into_bytes(self) -> Vec<u8> {
match self {
// connect is: CONN_FLAG || CONN_ID || REMOTE_LEN || REMOTE || RETURN
Socks5RequestContent::Connect(req) => {
Request::Connect(req) => {
let remote_address_bytes = req.remote_addr.into_bytes();
let remote_address_bytes_len = remote_address_bytes.len() as u16;
@@ -312,10 +197,10 @@ impl Socks5RequestContent {
iter.collect()
}
}
Socks5RequestContent::Send(req) => std::iter::once(RequestFlag::Send as u8)
.chain(req.conn_id.to_be_bytes().into_iter())
.chain(std::iter::once(req.local_closed as u8))
.chain(req.data.into_iter())
Request::Send(conn_id, data, local_closed) => std::iter::once(RequestFlag::Send as u8)
.chain(conn_id.to_be_bytes().into_iter())
.chain(std::iter::once(local_closed as u8))
.chain(data.into_iter())
.collect(),
}
}
@@ -331,8 +216,8 @@ mod request_deserialization_tests {
#[test]
fn returns_error_when_zero_bytes() {
let request_bytes = Vec::new();
match Socks5RequestContent::try_from_bytes(&request_bytes).unwrap_err() {
RequestDeserializationError::NoData => {}
match Request::try_from_bytes(&request_bytes).unwrap_err() {
RequestError::NoData => {}
_ => unreachable!(),
}
}
@@ -340,8 +225,8 @@ mod request_deserialization_tests {
#[test]
fn returns_error_when_connection_id_too_short() {
let request_bytes = [RequestFlag::Connect as u8, 1, 2, 3, 4, 5, 6, 7].to_vec(); // 7 bytes connection id
match Socks5RequestContent::try_from_bytes(&request_bytes).unwrap_err() {
RequestDeserializationError::ConnectionIdTooShort => {}
match Request::try_from_bytes(&request_bytes).unwrap_err() {
RequestError::ConnectionIdTooShort => {}
_ => unreachable!(),
}
}
@@ -356,13 +241,13 @@ mod request_deserialization_tests {
let request_bytes1 = [RequestFlag::Connect as u8, 1, 2, 3, 4, 5, 6, 7, 8].to_vec(); // 8 bytes connection id, 0 bytes address length (2 were expected)
let request_bytes2 = [RequestFlag::Connect as u8, 1, 2, 3, 4, 5, 6, 7, 8, 0].to_vec(); // 8 bytes connection id, 1 bytes address length (2 were expected)
match Socks5RequestContent::try_from_bytes(&request_bytes1).unwrap_err() {
RequestDeserializationError::AddressLengthTooShort => {}
match Request::try_from_bytes(&request_bytes1).unwrap_err() {
RequestError::AddressLengthTooShort => {}
_ => unreachable!(),
}
match Socks5RequestContent::try_from_bytes(&request_bytes2).unwrap_err() {
RequestDeserializationError::AddressLengthTooShort => {}
match Request::try_from_bytes(&request_bytes2).unwrap_err() {
RequestError::AddressLengthTooShort => {}
_ => unreachable!(),
}
}
@@ -370,8 +255,8 @@ mod request_deserialization_tests {
#[test]
fn returns_error_when_address_too_short_for_given_address_length() {
let request_bytes = [RequestFlag::Connect as u8, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1].to_vec(); // 8 bytes connection id, 2 bytes address length, missing address
match Socks5RequestContent::try_from_bytes(&request_bytes).unwrap_err() {
RequestDeserializationError::AddressTooShort => {}
match Request::try_from_bytes(&request_bytes).unwrap_err() {
RequestError::AddressTooShort => {}
_ => unreachable!(),
}
}
@@ -410,8 +295,8 @@ mod request_deserialization_tests {
.chain(recipient_bytes.iter().take(40).cloned())
.collect();
match Socks5RequestContent::try_from_bytes(&request_bytes).unwrap_err() {
RequestDeserializationError::ReturnAddressTooShort => {}
match Request::try_from_bytes(&request_bytes).unwrap_err() {
RequestError::ReturnAddressTooShort => {}
_ => unreachable!(),
}
}
@@ -453,7 +338,7 @@ mod request_deserialization_tests {
.cloned()
.chain(recipient_bytes.into_iter())
.collect();
assert!(Socks5RequestContent::try_from_bytes(&request_bytes)
assert!(Request::try_from_bytes(&request_bytes)
.unwrap_err()
.is_malformed_return());
}
@@ -491,9 +376,9 @@ mod request_deserialization_tests {
.chain(recipient_bytes.into_iter())
.collect();
let request = Socks5RequestContent::try_from_bytes(&request_bytes).unwrap();
let request = Request::try_from_bytes(&request_bytes).unwrap();
match request {
Socks5RequestContent::Connect(req) => {
Request::Connect(req) => {
assert_eq!("foo.com".to_string(), req.remote_addr);
assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), req.conn_id);
assert_eq!(
@@ -538,9 +423,9 @@ mod request_deserialization_tests {
.chain(recipient_bytes.into_iter())
.collect();
let request = Socks5RequestContent::try_from_bytes(&request_bytes).unwrap();
let request = Request::try_from_bytes(&request_bytes).unwrap();
match request {
Socks5RequestContent::Connect(req) => {
Request::Connect(req) => {
assert_eq!("foo.com".to_string(), req.remote_addr);
assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), req.conn_id);
assert_eq!(
@@ -561,13 +446,9 @@ mod request_deserialization_tests {
fn works_when_request_is_sized_properly_even_without_data() {
// correct 8 bytes of connection_id, 1 byte of local_closed and 0 bytes request data
let request_bytes = [RequestFlag::Send as u8, 1, 2, 3, 4, 5, 6, 7, 8, 0].to_vec();
let request = Socks5RequestContent::try_from_bytes(&request_bytes).unwrap();
let request = Request::try_from_bytes(&request_bytes).unwrap();
match request {
Socks5RequestContent::Send(SendRequest {
conn_id,
data,
local_closed,
}) => {
Request::Send(conn_id, data, local_closed) => {
assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), conn_id);
assert_eq!(Vec::<u8>::new(), data);
assert!(!local_closed)
@@ -596,13 +477,9 @@ mod request_deserialization_tests {
]
.to_vec();
let request = Socks5RequestContent::try_from_bytes(&request_bytes).unwrap();
let request = Request::try_from_bytes(&request_bytes).unwrap();
match request {
Socks5RequestContent::Send(SendRequest {
conn_id,
data,
local_closed,
}) => {
Request::Send(conn_id, data, local_closed) => {
assert_eq!(u64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), conn_id);
assert_eq!(vec![255, 255, 255], data);
assert!(!local_closed)

Some files were not shown because too many files have changed in this diff Show More