Remove coconut feature (#2890)

* Remove coconut feature

* Remove github workflow remainings

* Only run dkg if coconut enabled

* Fix typo

* Update changelog
This commit is contained in:
Bogdan-Ștefan Neacşu
2023-01-25 15:59:37 +02:00
committed by GitHub
parent 33d044dd5a
commit 8336d0612a
62 changed files with 211 additions and 846 deletions
-20
View File
@@ -95,23 +95,3 @@ jobs:
with:
command: clippy
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
-32
View File
@@ -114,38 +114,6 @@ 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,38 +117,6 @@ 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,38 +117,6 @@ 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
-5
View File
@@ -29,11 +29,6 @@ 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
+3
View File
@@ -4,15 +4,18 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
# [Unreleased]
### Added
- dkg rerun from scratch and dkg-specific epochs ([#2839])
- nym-sdk: add support for surb storage ([#2870])
- nym-sdk: enable reply-SURBs by default ([#2874])
- remove coconut feature and unify builds ([#2890])
[#2839]: https://github.com/nymtech/nym/pull/2839
[#2870]: https://github.com/nymtech/nym/pull/2870
[#2874]: https://github.com/nymtech/nym/pull/2874
[#2890]: https://github.com/nymtech/nym/pull/2890
# [v1.1.7] (2023-01-24)
Generated
+40 -47
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 1.0.0",
"cfg-if",
"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 1.0.0",
"cfg-if",
"cipher 0.4.3",
"cpufeatures",
]
@@ -375,7 +375,7 @@ dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if 1.0.0",
"cfg-if",
"constant_time_eq",
"digest 0.10.6",
]
@@ -500,12 +500,6 @@ 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"
@@ -528,7 +522,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fc89c7c5b9e7a02dfe45cd2367bae382f9ed31c61ca8debe5f827c420a2f08"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cipher 0.4.3",
"cpufeatures",
]
@@ -832,7 +826,7 @@ dependencies = [
name = "config"
version = "0.1.0"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"handlebars",
"log",
"network-defaults",
@@ -1052,7 +1046,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@@ -1060,7 +1054,6 @@ name = "credential"
version = "0.1.0"
dependencies = [
"bip39",
"cfg-if 0.1.10",
"clap 4.1.3",
"coconut-interface",
"completions",
@@ -1181,7 +1174,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
]
@@ -1191,7 +1184,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
@@ -1203,7 +1196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
dependencies = [
"autocfg 1.1.0",
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
@@ -1215,7 +1208,7 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
]
@@ -1225,7 +1218,7 @@ version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@@ -1560,7 +1553,7 @@ version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"num_cpus",
]
@@ -1570,7 +1563,7 @@ version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"hashbrown 0.12.3",
"lock_api",
"once_cell",
@@ -1796,7 +1789,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@@ -2258,7 +2251,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"js-sys",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
@@ -2271,7 +2264,7 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"js-sys",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
@@ -2836,7 +2829,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
@@ -2943,7 +2936,7 @@ version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"ecdsa",
"elliptic-curve",
"sec1",
@@ -3011,7 +3004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45ba81a1f5f24396b37211478aff7fbcd605dd4544df8dbed07b9da3c2057aee"
dependencies = [
"byteorder",
"cfg-if 1.0.0",
"cfg-if",
"hex",
"hidapi",
"ledger-transport",
@@ -3110,7 +3103,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@@ -3127,7 +3120,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"generator",
"scoped-tls",
"serde",
@@ -3336,7 +3329,7 @@ dependencies = [
name = "network-defaults"
version = "0.1.0"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"dotenv",
"hex-literal",
"once_cell",
@@ -3442,7 +3435,7 @@ dependencies = [
"bip39",
"bs58",
"build-information",
"cfg-if 1.0.0",
"cfg-if",
"clap 4.1.3",
"coconut-bandwidth-contract-common",
"coconut-dkg-common",
@@ -3562,7 +3555,7 @@ dependencies = [
"base64 0.13.1",
"bip39",
"bs58",
"cfg-if 1.0.0",
"cfg-if",
"clap 4.1.3",
"coconut-bandwidth-contract-common",
"coconut-dkg-common",
@@ -4097,7 +4090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
@@ -4200,7 +4193,7 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"instant",
"libc",
"redox_syscall",
@@ -4214,7 +4207,7 @@ version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"libc",
"redox_syscall",
"smallvec 1.10.0",
@@ -4448,7 +4441,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef234e08c11dfcb2e56f79fd70f6f2eb7f025c0ce2333e82f4f0518ecad30c6"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
@@ -5496,7 +5489,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
@@ -5508,7 +5501,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.10.6",
]
@@ -5519,7 +5512,7 @@ version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.10.6",
]
@@ -5531,7 +5524,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
@@ -5543,7 +5536,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest 0.10.6",
]
@@ -6067,7 +6060,7 @@ version = "0.24.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54cb4ebf3d49308b99e6e9dc95e989e2fdbdc210e4f67c39db0bb89ba927001c"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"core-foundation-sys",
"libc",
"ntapi",
@@ -6100,7 +6093,7 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"fastrand",
"libc",
"redox_syscall",
@@ -6558,7 +6551,7 @@ version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
@@ -6914,7 +6907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cf88d94e969e7956d924ba70741316796177fa0c79a2c9f4ab04998d96e966e"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
"cfg-if",
"chrono",
"enum-iterator 0.8.1",
"getset",
@@ -6931,7 +6924,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "571b69f690c855821462709b6f41d42ceccc316fbd17b60bd06d06928cfe6a99"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
"cfg-if",
"enum-iterator 1.2.0",
"getset",
"git2 0.15.0",
@@ -7026,7 +7019,7 @@ version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"wasm-bindgen-macro",
]
@@ -7051,7 +7044,7 @@ version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
+3 -13
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-coconut clippy-all-contracts clippy-all-wallet clippy-all-connect clippy-all-wasm-client
clippy-all: clippy-main 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 test-coconut
cargo-test-expensive: test-main-expensive test-contracts-expensive test-wallet-expensive test-connect-expensive test-coconut-expensive
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
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,9 +24,6 @@ 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
@@ -46,16 +43,9 @@ 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
-1
View File
@@ -82,5 +82,4 @@ 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"]
@@ -289,10 +289,6 @@ 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);
@@ -312,7 +308,6 @@ where
gateway_address,
self.key_manager.identity_keypair(),
gateway_identity,
gateway_owner,
shared_key,
mixnet_message_sender,
ack_sender,
-1
View File
@@ -63,7 +63,6 @@ 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,7 +7,6 @@ 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"] }
@@ -25,5 +24,3 @@ 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"]
+39 -48
View File
@@ -1,56 +1,47 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
cfg_if::cfg_if! {
if #[cfg(feature = "coconut")] {
mod client;
mod commands;
mod error;
mod state;
mod client;
mod commands;
mod error;
mod state;
use commands::*;
use completions::fig_generate;
use config::{DATA_DIR, DB_FILE_NAME};
use error::Result;
use network_defaults::setup_env;
use error::Result;
use network_defaults::setup_env;
use completions::fig_generate;
use commands::*;
use config::{DATA_DIR, DB_FILE_NAME};
use clap::{CommandFactory, Parser};
use clap::{CommandFactory, Parser};
#[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>,
#[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>,
#[clap(subcommand)]
pub(crate) command: Command,
}
#[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");
}
}
#[clap(subcommand)]
pub(crate) command: Command,
}
#[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(())
}
+2 -5
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", optional = true }
coconut-interface = { path = "../../common/coconut-interface" }
config = { path = "../../common/config" }
completions = { path = "../../common/completions" }
credential-storage = { path = "../../common/credential-storage" }
credentials = { path = "../../common/credentials", optional = true }
credentials = { path = "../../common/credentials" }
crypto = { path = "../../common/crypto" }
logging = { path = "../../common/logging"}
gateway-client = { path = "../../common/client-libs/gateway-client" }
@@ -55,8 +55,5 @@ 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
View File
@@ -30,7 +30,6 @@ pub(crate) struct Init {
force_register_gateway: bool,
/// Comma separated list of rest endpoints of the nyxd validators
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
@@ -58,7 +57,6 @@ pub(crate) struct Init {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
@@ -76,9 +74,7 @@ impl From<Init> for OverrideConfig {
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,
}
}
+13 -23
View File
@@ -58,10 +58,7 @@ pub(crate) struct OverrideConfig {
port: Option<u16>,
fastmode: bool,
no_cover: bool,
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
enabled_credentials_mode: Option<bool>,
}
@@ -78,8 +75,8 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
Ok(())
}
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
config = config
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> 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)
@@ -89,24 +86,17 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
args.nym_apis,
network_defaults::var_names::NYM_API,
config::parse_urls,
);
#[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
)
.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(test)]
-5
View File
@@ -22,7 +22,6 @@ pub(crate) struct Run {
id: String,
/// Comma separated list of rest endpoints of the nyxd validators
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
@@ -55,7 +54,6 @@ pub(crate) struct Run {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
}
@@ -68,10 +66,7 @@ impl From<Run> for OverrideConfig {
port: run_config.port,
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,
}
}
+2 -3
View File
@@ -30,11 +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", optional = true }
coconut-interface = { path = "../../common/coconut-interface" }
config = { path = "../../common/config" }
completions = { path = "../../common/completions" }
credential-storage = { path = "../../common/credential-storage" }
credentials = { path = "../../common/credentials", optional = true }
credentials = { path = "../../common/credentials" }
crypto = { path = "../../common/crypto" }
logging = { path = "../../common/logging"}
gateway-client = { path = "../../common/client-libs/gateway-client" }
@@ -51,5 +51,4 @@ validator-client = { path = "../../common/client-libs/validator-client", feature
version-checker = { path = "../../common/version-checker" }
[features]
coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut", "credentials/coconut", "client-core/coconut"]
eth = []
-5
View File
@@ -43,7 +43,6 @@ pub(crate) struct Init {
force_register_gateway: bool,
/// Comma separated list of rest endpoints of the nyxd validators
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
@@ -67,7 +66,6 @@ pub(crate) struct Init {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
@@ -84,10 +82,7 @@ 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,
}
}
+13 -23
View File
@@ -60,10 +60,7 @@ 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>,
}
@@ -80,8 +77,8 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
Ok(())
}
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
config = config
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> 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)
@@ -91,24 +88,17 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
args.nym_apis,
network_defaults::var_names::NYM_API,
config::parse_urls,
);
#[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
)
.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(test)]
-5
View File
@@ -43,7 +43,6 @@ pub(crate) struct Run {
gateway: Option<identity::PublicKey>,
/// Comma separated list of rest endpoints of the nyxd validators
#[cfg(feature = "coconut")]
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
nyxd_urls: Option<Vec<url::Url>>,
@@ -66,7 +65,6 @@ pub(crate) struct Run {
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: Option<bool>,
}
@@ -79,10 +77,7 @@ 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,
}
}
+3 -4
View File
@@ -15,7 +15,6 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
offline-test = []
coconut = ["coconut-interface", "credentials", "gateway-client/coconut"]
[dependencies]
futures = "0.3"
@@ -33,12 +32,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", optional = true }
credentials = { path = "../../common/credentials", optional = true }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
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", "coconut"] }
gateway-client = { path = "../../common/client-libs/gateway-client", default-features = false, features = ["wasm"] }
validator-client = { path = "../../common/client-libs/validator-client", default-features = false }
wasm-utils = { path = "../../common/wasm-utils" }
task = { path = "../../common/task" }
+1 -2
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", optional = true }
coconut-interface = { path = "../../coconut-interface" }
credentials = { path = "../../credentials" }
crypto = { path = "../../crypto" }
gateway-requests = { path = "../../../gateway/gateway-requests" }
@@ -79,5 +79,4 @@ features = ["js"]
#url = "2.1"
[features]
coconut = ["gateway-requests/coconut", "coconut-interface", "credentials/coconut"]
wasm = []
@@ -1,7 +1,6 @@
// 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")]
@@ -9,19 +8,17 @@ use crate::wasm_mockups::Storage;
#[cfg(not(target_arch = "wasm32"))]
use credential_storage::storage::Storage;
#[cfg(all(target_arch = "wasm32", feature = "coconut"))]
#[cfg(target_arch = "wasm32")]
use crate::wasm_mockups::StorageError;
#[cfg(all(not(target_arch = "wasm32"), feature = "coconut"))]
#[cfg(not(target_arch = "wasm32"))]
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::{
@@ -55,7 +52,6 @@ where
}
}
#[cfg(feature = "coconut")]
pub async fn prepare_coconut_credential(
&self,
) -> Result<(coconut_interface::Credential, i64), GatewayClientError> {
@@ -98,7 +94,6 @@ where
))
}
#[cfg(feature = "coconut")]
pub async fn consume_credential(&self, id: i64) -> Result<(), GatewayClientError> {
Ok(self.storage.consume_coconut_credential(id).await?)
}
@@ -9,6 +9,7 @@ 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;
@@ -25,9 +26,6 @@ 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"))]
@@ -53,7 +51,6 @@ 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,
@@ -84,7 +81,6 @@ 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,
@@ -98,7 +94,6 @@ where
bandwidth_remaining: 0,
gateway_address,
gateway_identity,
gateway_owner,
local_identity,
shared_key,
connection: SocketState::NotConnected,
@@ -132,7 +127,6 @@ 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,7 +145,6 @@ where
bandwidth_remaining: 0,
gateway_address,
gateway_identity,
gateway_owner,
local_identity,
shared_key: None,
connection: SocketState::NotConnected,
@@ -541,7 +534,6 @@ where
}
}
#[cfg(feature = "coconut")]
async fn claim_coconut_bandwidth(
&mut self,
credential: Credential,
@@ -591,28 +583,21 @@ 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;
#[cfg(feature = "coconut")]
{
self.claim_coconut_bandwidth(credential).await?;
self.bandwidth_controller
.as_ref()
.unwrap()
.consume_credential(credential_id)
.await?;
Ok(())
}
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 {
@@ -26,7 +26,6 @@ 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", features = ["coconut"] }
nym-api-requests = { path = "../../../nym-api/nym-api-requests" }
# required for nyxd-client
# at some point it might be possible to make it wasm-compatible
@@ -15,7 +15,4 @@ serde = { version = "1.0", features = ["derive"] }
thiserror = "1"
[dev-dependencies]
serde_json = "1.0.0"
[features]
coconut = ["dkg"]
serde_json = "1.0.0"
@@ -1,7 +1,7 @@
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "coconut")]
#[cfg(feature = "dkg")]
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 = "coconut")]
#[cfg(feature = "dkg")]
impl<'a> From<&'a Dealing> for ContractSafeBytes {
fn from(dealing: &'a Dealing) -> Self {
ContractSafeBytes(dealing.to_bytes())
}
}
#[cfg(feature = "coconut")]
#[cfg(feature = "dkg")]
impl<'a> TryFrom<&'a ContractSafeBytes> for Dealing {
type Error = DkgError;
+1 -3
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", optional = true }
cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegrant_support" }
thiserror = "1.0"
# I guess temporarily until we get serde support in coconut up and running
@@ -19,5 +19,3 @@ validator-client = { path = "../client-libs/validator-client" }
[dev-dependencies]
rand = "0.7.3"
[features]
coconut = ["cosmrs"]
-2
View File
@@ -1,7 +1,6 @@
// 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;
@@ -16,7 +15,6 @@ pub enum Error {
#[error("Could not contact any validator")]
NoValidatorsAvailable,
#[cfg(feature = "coconut")]
#[error("Ran into a coconut error - {0}")]
CoconutError(#[from] CoconutError),
-4
View File
@@ -1,11 +1,7 @@
// 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
@@ -1,137 +0,0 @@
// 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
@@ -1,4 +0,0 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
pub mod bandwidth;
+1 -1
View File
@@ -200,7 +200,7 @@ impl NymNetworkDetails {
#[must_use]
pub fn with_group_contract<S: Into<String>>(mut self, contract: Option<S>) -> Self {
self.contracts.multisig_contract_address = contract.map(Into::into);
self.contracts.group_contract_address = contract.map(Into::into);
self
}
+1 -8
View File
@@ -53,7 +53,7 @@ url = { version = "2.2", features = ["serde"] }
# internal
build-information = { path = "../common/build-information" }
coconut-interface = { path = "../common/coconut-interface", optional = true }
coconut-interface = { path = "../common/coconut-interface" }
credentials = { path = "../common/credentials" }
config = { path = "../common/config" }
crypto = { path = "../common/crypto" }
@@ -76,13 +76,6 @@ nym-types = { path = "../common/types" }
serde_json = "1"
atty = "0.2"
[features]
coconut = [
"coconut-interface",
"gateway-requests/coconut",
"credentials/coconut",
"nym-api-requests/coconut",
]
[build-dependencies]
tokio = { version = "1.24.1", features = ["rt-multi-thread", "macros"] }
+1 -4
View File
@@ -22,12 +22,9 @@ thiserror = "1.0"
crypto = { path = "../../common/crypto" }
pemstore = { path = "../../common/pemstore" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
[features]
coconut = ["coconut-interface", "credentials/coconut"]
[dependencies.tungstenite]
version = "0.13.0"
default-features = false
+1 -31
View File
@@ -5,6 +5,7 @@ use crate::authentication::encrypted_address::EncryptedAddressBytes;
use crate::iv::IV;
use crate::registration::handshake::SharedKeys;
use crate::{GatewayMacSize, PROTOCOL_VERSION};
use coconut_interface::Credential;
use crypto::generic_array::typenum::Unsigned;
use crypto::hmac::recompute_keyed_hmac_and_verify_tag;
use crypto::symmetric::stream_cipher;
@@ -20,11 +21,6 @@ use std::{
};
use tungstenite::protocol::Message;
#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(not(feature = "coconut"))]
use credentials::token::bandwidth::TokenCredential;
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum RegistrationHandshake {
@@ -157,7 +153,6 @@ impl ClientControlRequest {
}
}
#[cfg(feature = "coconut")]
pub fn new_enc_coconut_bandwidth_credential(
credential: &Credential,
shared_key: &SharedKeys,
@@ -172,7 +167,6 @@ impl ClientControlRequest {
}
}
#[cfg(feature = "coconut")]
pub fn try_from_enc_coconut_bandwidth_credential(
enc_credential: Vec<u8>,
shared_key: &SharedKeys,
@@ -182,30 +176,6 @@ impl ClientControlRequest {
Credential::from_bytes(&credential_bytes)
.map_err(|_| GatewayRequestsError::MalformedEncryption)
}
#[cfg(not(feature = "coconut"))]
pub fn new_enc_token_bandwidth_credential(
credential: &TokenCredential,
shared_key: &SharedKeys,
iv: IV,
) -> Self {
let enc_credential = shared_key.encrypt_and_tag(&credential.to_bytes(), Some(iv.inner()));
ClientControlRequest::BandwidthCredential {
enc_credential,
iv: iv.to_bytes(),
}
}
#[cfg(not(feature = "coconut"))]
pub fn try_from_enc_token_bandwidth_credential(
enc_credential: Vec<u8>,
shared_key: &SharedKeys,
iv: IV,
) -> Result<TokenCredential, GatewayRequestsError> {
let credential = shared_key.decrypt_tagged(&enc_credential, Some(iv.inner()))?;
TokenCredential::from_bytes(&credential)
.map_err(|_| GatewayRequestsError::MalformedEncryption)
}
}
impl From<ClientControlRequest> for Message {
-6
View File
@@ -51,7 +51,6 @@ pub struct Init {
nym_apis: Option<Vec<url::Url>>,
/// Comma separated list of endpoints of the validator
#[cfg(feature = "coconut")]
#[clap(
long,
alias = "validators",
@@ -67,7 +66,6 @@ pub struct Init {
/// Set this gateway to work only with coconut credentials; that would disallow clients to
/// bypass bandwidth credential requirement
#[cfg(feature = "coconut")]
#[clap(long)]
only_coconut_credentials: Option<bool>,
@@ -95,9 +93,7 @@ impl From<Init> for OverrideConfig {
enabled_statistics: init_config.enabled_statistics,
statistics_service_url: init_config.statistics_service_url,
#[cfg(feature = "coconut")]
nyxd_urls: init_config.nyxd_urls,
#[cfg(feature = "coconut")]
only_coconut_credentials: init_config.only_coconut_credentials,
}
}
@@ -184,9 +180,7 @@ mod tests {
mnemonic: None,
statistics_service_url: None,
enabled_statistics: None,
#[cfg(feature = "coconut")]
nyxd_urls: None,
#[cfg(feature = "coconut")]
only_coconut_credentials: None,
};
std::env::set_var(BECH32_PREFIX, "n");
+12 -21
View File
@@ -7,6 +7,7 @@ use clap::CommandFactory;
use clap::Subcommand;
use completions::{fig_generate, ArgShell};
use config::OptionalSet;
use network_defaults::var_names::NYXD;
use network_defaults::var_names::{BECH32_PREFIX, NYM_API, STATISTICS_SERVICE_DOMAIN_ADDRESS};
use std::error::Error;
use std::net::IpAddr;
@@ -56,10 +57,7 @@ pub(crate) struct OverrideConfig {
statistics_service_url: Option<url::Url>,
nym_apis: Option<Vec<url::Url>>,
mnemonic: Option<bip39::Mnemonic>,
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
only_coconut_credentials: Option<bool>,
}
@@ -119,24 +117,17 @@ pub(crate) fn override_config(
ensure_correct_bech32_prefix,
)?
.with_optional(Config::with_custom_persistent_store, args.datastore)
.with_optional(Config::with_cosmos_mnemonic, args.mnemonic);
#[cfg(feature = "coconut")]
{
use network_defaults::var_names::NYXD;
config = config
.with_optional_custom_env(
Config::with_custom_validator_nyxd,
args.nyxd_urls,
NYXD,
config::parse_urls,
)
.with_optional(
Config::with_only_coconut_credentials,
args.only_coconut_credentials,
);
}
.with_optional(Config::with_cosmos_mnemonic, args.mnemonic)
.with_optional_custom_env(
Config::with_custom_validator_nyxd,
args.nyxd_urls,
NYXD,
config::parse_urls,
)
.with_optional(
Config::with_only_coconut_credentials,
args.only_coconut_credentials,
);
Ok(config)
}
-5
View File
@@ -49,7 +49,6 @@ pub struct Run {
nym_apis: Option<Vec<url::Url>>,
/// Comma separated list of endpoints of the validator
#[cfg(feature = "coconut")]
#[clap(
long,
alias = "validators",
@@ -65,7 +64,6 @@ pub struct Run {
/// Set this gateway to work only with coconut credentials; that would disallow clients to
/// bypass bandwidth credential requirement
#[cfg(feature = "coconut")]
#[clap(long)]
only_coconut_credentials: Option<bool>,
@@ -92,10 +90,7 @@ impl From<Run> for OverrideConfig {
enabled_statistics: run_config.enabled_statistics,
statistics_service_url: run_config.statistics_service_url,
#[cfg(feature = "coconut")]
nyxd_urls: run_config.nyxd_urls,
#[cfg(feature = "coconut")]
only_coconut_credentials: run_config.only_coconut_credentials,
}
}
-4
View File
@@ -128,7 +128,6 @@ impl Config {
self
}
#[cfg(feature = "coconut")]
pub fn with_only_coconut_credentials(mut self, only_coconut_credentials: bool) -> Self {
self.gateway.only_coconut_credentials = only_coconut_credentials;
self
@@ -149,7 +148,6 @@ impl Config {
self
}
#[cfg(feature = "coconut")]
pub fn with_custom_validator_nyxd(mut self, validator_nyxd_urls: Vec<Url>) -> Self {
self.gateway.nyxd_urls = validator_nyxd_urls;
self
@@ -237,12 +235,10 @@ impl Config {
self.gateway.nym_api_urls.clone()
}
#[cfg(feature = "coconut")]
pub fn get_nyxd_urls(&self) -> Vec<Url> {
self.gateway.nyxd_urls.clone()
}
#[cfg(feature = "coconut")]
pub fn get_cosmos_mnemonic(&self) -> bip39::Mnemonic {
self.gateway.cosmos_mnemonic.clone()
}
@@ -1,10 +1,7 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(not(feature = "coconut"))]
use credentials::token::bandwidth::TokenCredential;
pub struct Bandwidth {
value: u64,
@@ -16,7 +13,6 @@ impl Bandwidth {
}
}
#[cfg(feature = "coconut")]
impl From<Credential> for Bandwidth {
fn from(credential: Credential) -> Self {
let token_value = credential.voucher_value();
@@ -26,12 +22,3 @@ impl From<Credential> for Bandwidth {
}
}
}
#[cfg(not(feature = "coconut"))]
impl From<TokenCredential> for Bandwidth {
fn from(credential: TokenCredential) -> Self {
Bandwidth {
value: credential.bandwidth(),
}
}
}
@@ -52,23 +52,18 @@ pub(crate) enum RequestHandlingError {
#[error("Nyxd Error - {0}")]
NyxdError(#[from] validator_client::nyxd::error::NyxdError),
#[cfg(feature = "coconut")]
#[error("Validator API error - {0}")]
APIError(#[from] validator_client::ValidatorClientError),
#[cfg(feature = "coconut")]
#[error("Not enough nym API endpoints provided. Needed {needed}, received {received}")]
NotEnoughNymAPIs { received: usize, needed: usize },
#[cfg(feature = "coconut")]
#[error("There was a problem with the proposal id: {reason}")]
ProposalIdError { reason: String },
#[cfg(feature = "coconut")]
#[error("Coconut interface error - {0}")]
CoconutInterfaceError(#[from] coconut_interface::error::CoconutInterfaceError),
#[cfg(feature = "coconut")]
#[error("Credential error - {0}")]
CredentialError(#[from] credentials::error::Error),
}
@@ -192,7 +187,6 @@ where
}
}
#[cfg(feature = "coconut")]
/// Tries to handle the received bandwidth request by checking correctness of the received data
/// and if successful, increases client's bandwidth by an appropriate amount.
///
@@ -200,7 +194,7 @@ where
///
/// * `enc_credential`: raw encrypted bandwidth credential to verify.
/// * `iv`: fresh iv used for the credential.
async fn handle_coconut_bandwidth(
async fn handle_bandwidth(
&mut self,
enc_credential: Vec<u8>,
iv: Vec<u8>,
@@ -263,70 +257,6 @@ where
Ok(ServerResponse::Bandwidth { available_total })
}
#[cfg(not(feature = "coconut"))]
/// Tries to handle the received bandwidth request by checking correctness of the received data
/// and if successful, increases client's bandwidth by an appropriate amount.
///
/// # Arguments
///
/// * `enc_credential`: raw encrypted bandwidth credential to verify.
/// * `iv`: fresh iv used for the credential.
async fn handle_token_bandwidth(
&mut self,
enc_credential: Vec<u8>,
iv: Vec<u8>,
) -> Result<ServerResponse, RequestHandlingError> {
let iv = IV::try_from_bytes(&iv)?;
let credential = ClientControlRequest::try_from_enc_token_bandwidth_credential(
enc_credential,
&self.client.shared_keys,
iv,
)?;
if !self
.inner
.check_local_identity(&credential.gateway_identity())
{
return Err(RequestHandlingError::InvalidBandwidthCredential(
String::from("gateway"),
));
}
if !credential.verify_signature() {
return Err(RequestHandlingError::InvalidBandwidthCredential(
String::from("gateway"),
));
}
let bandwidth = Bandwidth::from(credential);
let bandwidth_value = bandwidth.value();
if bandwidth_value > i64::MAX as u64 {
// note that this would have represented more than 1 exabyte,
// which is like 125,000 worth of hard drives so I don't think we have
// to worry about it for now...
warn!("Somehow we received bandwidth value higher than 9223372036854775807. We don't really want to deal with this now");
return Err(RequestHandlingError::UnsupportedBandwidthValue(
bandwidth_value,
));
}
self.increase_bandwidth(bandwidth_value as i64).await?;
let available_total = self.get_available_bandwidth().await?;
Ok(ServerResponse::Bandwidth { available_total })
}
async fn handle_bandwidth(
&mut self,
enc_credential: Vec<u8>,
iv: Vec<u8>,
) -> Result<ServerResponse, RequestHandlingError> {
#[cfg(feature = "coconut")]
return self.handle_coconut_bandwidth(enc_credential, iv).await;
#[cfg(not(feature = "coconut"))]
return self.handle_token_bandwidth(enc_credential, iv).await;
}
async fn handle_claim_testnet_bandwidth(
&mut self,
) -> Result<ServerResponse, RequestHandlingError> {
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
use crate::node::client_handling::active_clients::ActiveClientsStore;
#[cfg(feature = "coconut")]
use crate::node::client_handling::websocket::connection_handler::coconut::CoconutVerifier;
use crate::node::client_handling::websocket::connection_handler::{
AuthenticatedHandler, ClientDetails, InitialAuthResult, SocketStream,
@@ -75,8 +74,6 @@ pub(crate) struct FreshHandler<R, S, St> {
pub(crate) outbound_mix_sender: MixForwardingSender,
pub(crate) socket_connection: SocketStream<S>,
pub(crate) storage: St,
#[cfg(feature = "coconut")]
pub(crate) coconut_verifier: Arc<CoconutVerifier>,
}
@@ -98,7 +95,7 @@ where
local_identity: Arc<identity::KeyPair>,
storage: St,
active_clients_store: ActiveClientsStore,
#[cfg(feature = "coconut")] coconut_verifier: Arc<CoconutVerifier>,
coconut_verifier: Arc<CoconutVerifier>,
) -> Self {
FreshHandler {
rng,
@@ -108,20 +105,10 @@ where
socket_connection: SocketStream::RawTcp(conn),
local_identity,
storage,
#[cfg(feature = "coconut")]
coconut_verifier,
}
}
#[cfg(not(feature = "coconut"))]
/// Check that the local identity matches a given identity.
pub(crate) fn check_local_identity(
&self,
identity: &crypto::asymmetric::identity::PublicKey,
) -> bool {
self.local_identity.public_key().eq(identity)
}
/// Attempts to perform websocket handshake with the remote and upgrades the raw TCP socket
/// to the framed WebSocket.
pub(crate) async fn perform_websocket_handshake(&mut self) -> Result<(), WsError>
@@ -15,7 +15,6 @@ pub(crate) use self::authenticated::AuthenticatedHandler;
pub(crate) use self::fresh::FreshHandler;
mod authenticated;
#[cfg(feature = "coconut")]
pub(crate) mod coconut;
mod fresh;
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::node::client_handling::active_clients::ActiveClientsStore;
use crate::node::client_handling::websocket::connection_handler::coconut::CoconutVerifier;
use crate::node::client_handling::websocket::connection_handler::FreshHandler;
use crate::node::storage::Storage;
use crypto::asymmetric::identity;
@@ -13,15 +14,10 @@ use std::process;
use std::sync::Arc;
use tokio::task::JoinHandle;
#[cfg(feature = "coconut")]
use crate::node::client_handling::websocket::connection_handler::coconut::CoconutVerifier;
pub(crate) struct Listener {
address: SocketAddr,
local_identity: Arc<identity::KeyPair>,
only_coconut_credentials: bool,
#[cfg(feature = "coconut")]
pub(crate) coconut_verifier: Arc<CoconutVerifier>,
}
@@ -30,13 +26,12 @@ impl Listener {
address: SocketAddr,
local_identity: Arc<identity::KeyPair>,
only_coconut_credentials: bool,
#[cfg(feature = "coconut")] coconut_verifier: Arc<CoconutVerifier>,
coconut_verifier: Arc<CoconutVerifier>,
) -> Self {
Listener {
address,
local_identity,
only_coconut_credentials,
#[cfg(feature = "coconut")]
coconut_verifier,
}
}
@@ -81,7 +76,6 @@ impl Listener {
Arc::clone(&self.local_identity),
storage.clone(),
active_clients_store.clone(),
#[cfg(feature = "coconut")]
Arc::clone(&self.coconut_verifier),
);
let shutdown = shutdown.clone();
+3 -11
View File
@@ -8,6 +8,7 @@ use crate::config::Config;
use crate::error::GatewayError;
use crate::node::client_handling::active_clients::ActiveClientsStore;
use crate::node::client_handling::websocket;
use crate::node::client_handling::websocket::connection_handler::coconut::CoconutVerifier;
use crate::node::mixnet_handling::receiver::connection_handler::ConnectionHandler;
use crate::node::statistics::collector::GatewayStatisticsCollector;
use crate::node::storage::Storage;
@@ -16,6 +17,7 @@ use colored::Colorize;
use crypto::asymmetric::{encryption, identity};
use log::*;
use mixnet_client::forwarder::{MixForwardingSender, PacketForwarder};
use network_defaults::NymNetworkDetails;
use rand::seq::SliceRandom;
use rand::thread_rng;
use statistics_common::collector::StatisticsSender;
@@ -24,12 +26,6 @@ use std::net::SocketAddr;
use std::process;
use std::sync::Arc;
use task::{TaskClient, TaskManager};
#[cfg(feature = "coconut")]
use crate::node::client_handling::websocket::connection_handler::coconut::CoconutVerifier;
#[cfg(feature = "coconut")]
use network_defaults::NymNetworkDetails;
#[cfg(feature = "coconut")]
use validator_client::Client;
pub(crate) mod client_handling;
@@ -190,7 +186,7 @@ where
forwarding_channel: MixForwardingSender,
active_clients_store: ActiveClientsStore,
shutdown: TaskClient,
#[cfg(feature = "coconut")] coconut_verifier: Arc<CoconutVerifier>,
coconut_verifier: Arc<CoconutVerifier>,
) {
info!("Starting client [web]socket listener...");
@@ -203,7 +199,6 @@ where
listening_address,
Arc::clone(&self.identity_keypair),
self.config.get_only_coconut_credentials(),
#[cfg(feature = "coconut")]
coconut_verifier,
)
.start(
@@ -248,7 +243,6 @@ where
validator_client::NymApiClient::new(nym_api.clone())
}
#[cfg(feature = "coconut")]
fn random_nyxd_client(
&self,
) -> validator_client::Client<validator_client::nyxd::SigningNyxdClient> {
@@ -316,7 +310,6 @@ where
let shutdown = TaskManager::new(10);
#[cfg(feature = "coconut")]
let coconut_verifier = {
let nyxd_client = self.random_nyxd_client();
CoconutVerifier::new(nyxd_client)
@@ -348,7 +341,6 @@ where
mix_forwarding_channel,
active_clients_store,
shutdown.subscribe(),
#[cfg(feature = "coconut")]
Arc::new(coconut_verifier),
);
+10 -24
View File
@@ -16,7 +16,7 @@ rust-version = "1.56"
[dependencies]
async-trait = "0.1.52"
bs58 = {version = "0.4.0", optional = true }
bs58 = {version = "0.4.0" }
bip39 = "1"
cfg-if = "1.0"
clap = { version = "4.0", features = ["cargo", "derive"] }
@@ -67,26 +67,26 @@ schemars = { version = "0.8", features = ["preserve_order"] }
## internal
build-information = { path = "../common/build-information" }
coconut-bandwidth-contract-common = { path = "../common/cosmwasm-smart-contracts/coconut-bandwidth-contract" }
coconut-dkg-common = { path = "../common/cosmwasm-smart-contracts/coconut-dkg", optional = true }
coconut-interface = { path = "../common/coconut-interface", optional = true }
coconut-dkg-common = { path = "../common/cosmwasm-smart-contracts/coconut-dkg" }
coconut-interface = { path = "../common/coconut-interface" }
config = { path = "../common/config" }
cosmwasm-std = "1.0.0"
credential-storage = { path = "../common/credential-storage" }
credentials = { path = "../common/credentials", optional = true }
credentials = { path = "../common/credentials" }
crypto = { path = "../common/crypto" }
logging = { path = "../common/logging"}
cw3 = { version = "0.13.4", optional = true }
cw4 = { version = "0.13.4", optional = true }
dkg = { path = "../common/crypto/dkg", optional = true }
cw3 = { version = "0.13.4" }
cw4 = { version = "0.13.4" }
dkg = { path = "../common/crypto/dkg" }
gateway-client = { path = "../common/client-libs/gateway-client" }
inclusion-probability = { path = "../common/inclusion-probability" }
mixnet-contract-common = { path = "../common/cosmwasm-smart-contracts/mixnet-contract" }
vesting-contract-common = { path = "../common/cosmwasm-smart-contracts/vesting-contract" }
contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common", features = ["coconut"] }
contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common", features = ["dkg"] }
multisig-contract-common = { path = "../common/cosmwasm-smart-contracts/multisig-contract" }
nymcoconut = { path = "../common/nymcoconut", optional = true }
nymcoconut = { path = "../common/nymcoconut" }
nymsphinx = { path = "../common/nymsphinx" }
pemstore = { path = "../common/pemstore", optional = true }
pemstore = { path = "../common/pemstore" }
task = { path = "../common/task" }
topology = { path = "../common/topology" }
nym-api-requests = { path = "nym-api-requests" }
@@ -96,20 +96,6 @@ validator-client = { path = "../common/client-libs/validator-client", features =
version-checker = { path = "../common/version-checker" }
[features]
coconut = [
"coconut-interface",
"credentials",
"cw3",
"cw4",
"gateway-client/coconut",
"credentials/coconut",
"nym-api-requests/coconut",
"nymcoconut",
"coconut-dkg-common",
"dkg",
"bs58",
"pemstore",
]
no-reward = []
generate-ts = ["ts-rs"]
+1 -2
View File
@@ -14,10 +14,9 @@ schemars = { version = "0.8", features = ["preserve_order"] }
serde = { version = "1.0", features = ["derive"] }
ts-rs = { version = "6.1.2", optional = true }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
coconut-interface = { path = "../../common/coconut-interface" }
mixnet-contract-common = { path= "../../common/cosmwasm-smart-contracts/mixnet-contract" }
[features]
default = []
coconut = ["coconut-interface"]
generate-ts = ["ts-rs"]
-1
View File
@@ -4,7 +4,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(feature = "coconut")]
pub mod coconut;
pub mod models;
+13 -22
View File
@@ -15,31 +15,25 @@ use ::config::defaults::setup_env;
use anyhow::Result;
use circulating_supply_api::cache::CirculatingSupplyCache;
use clap::Parser;
use coconut::dkg::controller::DkgController;
use config::NymConfig;
use log::info;
use logging::setup_logging;
use node_status_api::NodeStatusCache;
use nym_contract_cache::cache::NymContractCache;
use rand::rngs::OsRng;
use std::error::Error;
use support::{http, nyxd};
use task::TaskManager;
#[cfg(feature = "coconut")]
use coconut::dkg::controller::DkgController;
#[cfg(feature = "coconut")]
use rand::rngs::OsRng;
mod circulating_supply_api;
mod coconut;
mod epoch_operations;
mod network_monitor;
pub(crate) mod node_status_api;
pub(crate) mod nym_contract_cache;
pub(crate) mod support;
#[cfg(feature = "coconut")]
mod coconut;
struct ShutdownHandles {
task_manager_handle: TaskManager,
rocket_handle: rocket::Shutdown,
@@ -68,9 +62,6 @@ async fn start_nym_api_tasks(
let nyxd_client = nyxd::Client::new(&config);
let mix_denom = nyxd_client.chain_details().await.mix_denom.base;
// TODO: question to @BN: why are we creating a fresh coconut keypair here every time as opposed
// to using some persistent keys?
#[cfg(feature = "coconut")]
let coconut_keypair = coconut::keypair::KeyPair::new();
// let's build our rocket!
@@ -78,7 +69,6 @@ async fn start_nym_api_tasks(
&config,
mix_denom,
nyxd_client.clone(),
#[cfg(feature = "coconut")]
coconut_keypair.clone(),
)
.await?;
@@ -120,15 +110,16 @@ async fn start_nym_api_tasks(
);
// start dkg task
#[cfg(feature = "coconut")]
DkgController::start(
&config,
nyxd_client.clone(),
coconut_keypair,
OsRng,
&shutdown,
)
.await?;
if config.get_coconut_signer_enabled() {
DkgController::start(
&config,
nyxd_client.clone(),
coconut_keypair,
OsRng,
&shutdown,
)
.await?;
}
// and then only start the uptime updater (and the monitor itself, duh)
// if the monitoring if it's enabled
@@ -380,7 +380,6 @@ impl PacketPreparer {
GatewayPackets::new(
route.gateway_clients_address(),
route.gateway_identity(),
route.gateway_owner(),
mix_packets,
)
}
@@ -453,7 +452,6 @@ impl PacketPreparer {
let recipient = self.create_packet_sender(test_route.gateway());
let gateway_identity = test_route.gateway_identity();
let gateway_address = test_route.gateway_clients_address();
let gateway_owner = test_route.gateway_owner();
// it's actually going to be a tiny bit more due to gateway testing, but it's a good enough approximation
let mut mix_packets = Vec::with_capacity(mixnodes.len() * self.per_node_test_packets);
@@ -471,9 +469,7 @@ impl PacketPreparer {
let gateway_packets = all_gateway_packets
.entry(gateway_identity.to_bytes())
.or_insert_with(|| {
GatewayPackets::empty(gateway_address, gateway_identity, gateway_owner)
});
.or_insert_with(|| GatewayPackets::empty(gateway_address, gateway_identity));
gateway_packets.push_packets(mix_packets);
// and for each gateway...
@@ -482,7 +478,6 @@ impl PacketPreparer {
let test_packet = TestPacket::from_gateway(gateway, test_route.id(), test_nonce);
let gateway_identity = gateway.identity_key;
let gateway_address = gateway.clients_address();
let gateway_owner = gateway.owner.clone();
let recipient = self.create_packet_sender(gateway);
let topology = test_route.substitute_gateway(gateway);
// produce n mix packets
@@ -495,9 +490,7 @@ impl PacketPreparer {
// or create a new one
let gateway_packets = all_gateway_packets
.entry(gateway_identity.to_bytes())
.or_insert_with(|| {
GatewayPackets::empty(gateway_address, gateway_identity, gateway_owner)
});
.or_insert_with(|| GatewayPackets::empty(gateway_address, gateway_identity));
gateway_packets.push_packets(gateway_mix_packets);
}
}
+2 -16
View File
@@ -39,9 +39,6 @@ pub(crate) struct GatewayPackets {
/// Public key of the target gateway.
pub(crate) pub_key: identity::PublicKey,
/// The address of the gateway owner.
pub(crate) gateway_owner: String,
/// All the packets that are going to get sent to the gateway.
pub(crate) packets: Vec<MixPacket>,
}
@@ -50,26 +47,19 @@ impl GatewayPackets {
pub(crate) fn new(
clients_address: String,
pub_key: identity::PublicKey,
gateway_owner: String,
packets: Vec<MixPacket>,
) -> Self {
GatewayPackets {
clients_address,
pub_key,
gateway_owner,
packets,
}
}
pub(crate) fn empty(
clients_address: String,
pub_key: identity::PublicKey,
gateway_owner: String,
) -> Self {
pub(crate) fn empty(clients_address: String, pub_key: identity::PublicKey) -> Self {
GatewayPackets {
clients_address,
pub_key,
gateway_owner,
packets: Vec::new(),
}
}
@@ -182,7 +172,6 @@ impl PacketSender {
fn new_gateway_client_handle(
address: String,
identity: identity::PublicKey,
owner: String,
fresh_gateway_client_data: &FreshGatewayClientData,
) -> (
GatewayClientHandle,
@@ -200,7 +189,6 @@ impl PacketSender {
address,
Arc::clone(&fresh_gateway_client_data.local_identity),
identity,
owner,
None,
message_sender,
ack_sender,
@@ -280,7 +268,6 @@ impl PacketSender {
async fn create_new_gateway_client_handle_and_authenticate(
address: String,
identity: identity::PublicKey,
owner: String,
fresh_gateway_client_data: &FreshGatewayClientData,
gateway_connection_timeout: Duration,
) -> Option<(
@@ -288,7 +275,7 @@ impl PacketSender {
(MixnetMessageReceiver, AcknowledgementReceiver),
)> {
let (new_client, (message_receiver, ack_receiver)) =
Self::new_gateway_client_handle(address, identity, owner, fresh_gateway_client_data);
Self::new_gateway_client_handle(address, identity, fresh_gateway_client_data);
// Put this in timeout in case the gateway has incorrectly set their ulimit and our connection
// gets stuck in their TCP queue and just hangs on our end but does not terminate
@@ -365,7 +352,6 @@ impl PacketSender {
Self::create_new_gateway_client_handle_and_authenticate(
packets.clients_address,
packets.pub_key,
packets.gateway_owner,
&fresh_gateway_client_data,
gateway_connection_timeout,
)
@@ -66,10 +66,6 @@ impl TestRoute {
self.gateway().identity_key
}
pub(crate) fn gateway_owner(&self) -> String {
self.gateway().owner.clone()
}
pub(crate) fn topology(&self) -> &NymTopology {
&self.nodes
}
+4 -14
View File
@@ -93,12 +93,10 @@ pub(crate) struct CliArgs {
pub(crate) enabled_credentials_mode: Option<bool>,
/// Announced address where coconut clients will connect.
#[cfg(feature = "coconut")]
#[clap(long)]
pub(crate) announce_address: Option<url::Url>,
/// Flag to indicate whether coconut signer authority is enabled on this API
#[cfg(feature = "coconut")]
#[clap(long, requires = "mnemonic", requires = "announce_address")]
pub(crate) enable_coconut: Option<bool>,
}
@@ -123,7 +121,6 @@ pub(crate) fn build_config(args: CliArgs) -> Result<Config> {
let config = override_config(config_from_file, args);
#[cfg(feature = "coconut")]
if !_already_initialized {
crate::coconut::dkg::controller::init_keypair(&config)?;
}
@@ -140,7 +137,7 @@ pub(crate) fn override_config(mut config: Config, args: CliArgs) -> Config {
config = config.with_id(&id);
}
config = config
config
.with_optional(Config::with_custom_nyxd_validator, args.nyxd_validator)
.with_optional_env(
Config::with_custom_mixnet_contract,
@@ -170,14 +167,7 @@ pub(crate) fn override_config(mut config: Config, args: CliArgs) -> Config {
.with_optional(
Config::with_disabled_credentials_mode,
args.enabled_credentials_mode.map(|b| !b),
);
#[cfg(feature = "coconut")]
{
config = config
.with_optional(Config::with_announce_address, args.announce_address)
.with_optional(Config::with_coconut_signer_enabled, args.enable_coconut);
}
config
)
.with_optional(Config::with_announce_address, args.announce_address)
.with_optional(Config::with_coconut_signer_enabled, args.enable_coconut)
}
-10
View File
@@ -416,7 +416,6 @@ impl Config {
self
}
#[cfg(feature = "coconut")]
pub fn with_coconut_signer_enabled(mut self, enabled: bool) -> Self {
self.coconut_signer.enabled = enabled;
self
@@ -427,7 +426,6 @@ impl Config {
self
}
#[cfg(feature = "coconut")]
pub fn with_announce_address(mut self, announce_address: Url) -> Self {
self.base.announce_address = announce_address;
self
@@ -471,7 +469,6 @@ impl Config {
self.network_monitor.enabled
}
#[cfg(feature = "coconut")]
pub fn get_coconut_signer_enabled(&self) -> bool {
self.coconut_signer.enabled
}
@@ -492,7 +489,6 @@ impl Config {
self.base.local_validator.clone()
}
#[cfg(feature = "coconut")]
pub fn get_announce_address(&self) -> Url {
self.base.announce_address.clone()
}
@@ -573,32 +569,26 @@ impl Config {
self.node_status_api.database_path.clone()
}
#[cfg(feature = "coconut")]
pub fn persistent_state_path(&self) -> PathBuf {
self.coconut_signer.dkg_persistent_state_path.clone()
}
#[cfg(feature = "coconut")]
pub fn verification_key_path(&self) -> PathBuf {
self.coconut_signer.verification_key_path.clone()
}
#[cfg(feature = "coconut")]
pub fn secret_key_path(&self) -> PathBuf {
self.coconut_signer.secret_key_path.clone()
}
#[cfg(feature = "coconut")]
pub fn decryption_key_path(&self) -> PathBuf {
self.coconut_signer.decryption_key_path.clone()
}
#[cfg(feature = "coconut")]
pub fn public_key_with_proof_path(&self) -> PathBuf {
self.coconut_signer.public_key_with_proof_path.clone()
}
#[cfg(feature = "coconut")]
pub fn get_dkg_contract_polling_rate(&self) -> Duration {
self.coconut_signer.dkg_contract_polling_rate
}
+3 -6
View File
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::circulating_supply_api::cache::CirculatingSupplyCache;
use crate::coconut::{self, comm::QueryCommunicationChannel, InternalSignRequest};
use crate::node_status_api::{self, NodeStatusCache};
use crate::nym_contract_cache::cache::NymContractCache;
use crate::support::config::Config;
@@ -14,16 +15,13 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors};
use rocket_okapi::mount_endpoints_and_merged_docs;
use rocket_okapi::swagger_ui::make_swagger_ui;
#[cfg(feature = "coconut")]
use crate::coconut::{self, comm::QueryCommunicationChannel, InternalSignRequest};
pub(crate) mod openapi;
pub(crate) async fn setup_rocket(
config: &Config,
mix_denom: String,
_nyxd_client: nyxd::Client,
#[cfg(feature = "coconut")] coconut_keypair: coconut::keypair::KeyPair,
coconut_keypair: coconut::keypair::KeyPair,
) -> anyhow::Result<Rocket<Ignite>> {
let openapi_settings = rocket_okapi::settings::OpenApiSettings::default();
let mut rocket = rocket::build();
@@ -47,13 +45,12 @@ pub(crate) async fn setup_rocket(
// This is not a very nice approach. A lazy value would be more suitable, but that's still
// a nightly feature: https://github.com/rust-lang/rust/issues/74465
let storage = if cfg!(feature = "coconut") || config.get_network_monitor_enabled() {
let storage = if config.get_coconut_signer_enabled() || config.get_network_monitor_enabled() {
Some(storage::NymApiStorage::init(config.get_node_status_api_database_path()).await?)
} else {
None
};
#[cfg(feature = "coconut")]
let rocket = if config.get_coconut_signer_enabled() {
let comm_channel = QueryCommunicationChannel::new(_nyxd_client.clone());
rocket.attach(InternalSignRequest::stage(
+17 -27
View File
@@ -1,10 +1,21 @@
// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::coconut::error::CoconutError;
use crate::epoch_operations::MixnodeToReward;
use crate::support::config::Config;
use anyhow::Result;
use async_trait::async_trait;
use coconut_bandwidth_contract_common::spend_credential::SpendCredentialResponse;
use coconut_dkg_common::{
dealer::{ContractDealing, DealerDetails, DealerDetailsResponse},
types::{EncodedBTEPublicKeyWithProof, Epoch, EpochId},
verification_key::{ContractVKShare, VerificationKeyShare},
};
use config::defaults::{ChainDetails, NymNetworkDetails, DEFAULT_NYM_API_PORT};
use contracts_common::dealings::ContractSafeBytes;
use cw3::ProposalResponse;
use cw4::MemberResponse;
use mixnet_contract_common::families::{Family, FamilyHead};
use mixnet_contract_common::mixnode::MixNodeDetails;
use mixnet_contract_common::reward_params::RewardingParams;
@@ -16,32 +27,6 @@ use std::sync::Arc;
use tokio::sync::RwLock;
use validator_client::nyxd::error::NyxdError;
use validator_client::nyxd::traits::{MixnetQueryClient, MixnetSigningClient};
use validator_client::nyxd::{
hash::{Hash, SHA256_HASH_SIZE},
AccountId, Coin, SigningNyxdClient, TendermintTime, VestingQueryClient,
};
use validator_client::ValidatorClientError;
use vesting_contract_common::AccountVestingCoins;
#[cfg(feature = "coconut")]
use crate::coconut::error::CoconutError;
#[cfg(feature = "coconut")]
use async_trait::async_trait;
#[cfg(feature = "coconut")]
use coconut_bandwidth_contract_common::spend_credential::SpendCredentialResponse;
#[cfg(feature = "coconut")]
use coconut_dkg_common::{
dealer::{ContractDealing, DealerDetails, DealerDetailsResponse},
types::{EncodedBTEPublicKeyWithProof, Epoch, EpochId},
verification_key::{ContractVKShare, VerificationKeyShare},
};
#[cfg(feature = "coconut")]
use contracts_common::dealings::ContractSafeBytes;
#[cfg(feature = "coconut")]
use cw3::ProposalResponse;
#[cfg(feature = "coconut")]
use cw4::MemberResponse;
#[cfg(feature = "coconut")]
use validator_client::nyxd::{
cosmwasm_client::types::ExecuteResult,
traits::{
@@ -50,6 +35,12 @@ use validator_client::nyxd::{
},
Fee,
};
use validator_client::nyxd::{
hash::{Hash, SHA256_HASH_SIZE},
AccountId, Coin, SigningNyxdClient, TendermintTime, VestingQueryClient,
};
use validator_client::ValidatorClientError;
use vesting_contract_common::AccountVestingCoins;
pub(crate) struct Client(pub(crate) Arc<RwLock<validator_client::Client<SigningNyxdClient>>>);
@@ -288,7 +279,6 @@ impl Client {
}
#[async_trait]
#[cfg(feature = "coconut")]
impl crate::coconut::client::Client for Client {
async fn address(&self) -> AccountId {
self.client_address().await
-2
View File
@@ -977,7 +977,6 @@ impl StorageManager {
///
/// * `tx_hash`: hash of the deposit transaction.
/// * `blinded_signature_response`: the encrypted blinded signature response.
#[cfg(feature = "coconut")]
pub(crate) async fn insert_blinded_signature_response(
&self,
tx_hash: &str,
@@ -998,7 +997,6 @@ impl StorageManager {
/// # Arguments
///
/// * `tx_hash`: transaction hash of the deposit.
#[cfg(feature = "coconut")]
pub(crate) async fn get_blinded_signature_response(
&self,
tx_hash: &str,
-2
View File
@@ -737,7 +737,6 @@ impl NymApiStorage {
.map_err(|err| err.into())
}
#[cfg(feature = "coconut")]
pub(crate) async fn get_blinded_signature_response(
&self,
tx_hash: &str,
@@ -748,7 +747,6 @@ impl NymApiStorage {
.map_err(|err| err.into())
}
#[cfg(feature = "coconut")]
pub(crate) async fn insert_blinded_signature_response(
&self,
tx_hash: &str,
-1
View File
@@ -9,7 +9,6 @@ use task::manager::TaskStatus;
use tokio::sync::RwLock;
use config_common::NymConfig;
#[cfg(not(feature = "coconut"))]
use nym_socks5::client::NymClient as Socks5NymClient;
use nym_socks5::client::{config::Config as Socks5Config, Socks5ControlMessageSender};