64c963e36e
* Reset contract state when dkg needs rerun * Reset nym-api for rerun * Gateway updates signer APIs at runtime * Fix clippy * Add epoch id * Use IndexedMap for shares * Query with epoch id * Add Clone to client traits * Pass nyxd client instead of api data * Get the specific epoch vk * Make wasm work * Remove wasm test runs As there are no wasm tests and the target_arch macros are not compatible with the cargo test environment, we can safely remove (for now) the wasm test target runs. * Put epoch_id in storage pk * Gateway uses old keys but current verifiers * Add group contract to env * Move group msg in common * Only run DKG if part of group * Clippy test * Rename wasm_storage to wasm_mockups * Update changelog
61 lines
1.8 KiB
Rust
61 lines
1.8 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::error::GatewayClientError;
|
|
pub use client::GatewayClient;
|
|
use gateway_requests::registration::handshake::SharedKeys;
|
|
use gateway_requests::BinaryResponse;
|
|
use log::warn;
|
|
pub use packet_router::{
|
|
AcknowledgementReceiver, AcknowledgementSender, MixnetMessageReceiver, MixnetMessageSender,
|
|
};
|
|
use tungstenite::{protocol::Message, Error as WsError};
|
|
|
|
pub mod bandwidth;
|
|
pub mod client;
|
|
pub mod error;
|
|
pub mod packet_router;
|
|
pub mod socket_state;
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub mod wasm_mockups;
|
|
|
|
/// Helper method for reading from websocket stream. Helps to flatten the structure.
|
|
pub(crate) fn cleanup_socket_message(
|
|
msg: Option<Result<Message, WsError>>,
|
|
) -> Result<Message, GatewayClientError> {
|
|
match msg {
|
|
Some(msg) => msg.map_err(GatewayClientError::NetworkError),
|
|
None => Err(GatewayClientError::ConnectionAbruptlyClosed),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn cleanup_socket_messages(
|
|
msgs: Option<Vec<Result<Message, WsError>>>,
|
|
) -> Result<Vec<Message>, GatewayClientError> {
|
|
match msgs {
|
|
Some(msgs) => msgs
|
|
.into_iter()
|
|
.map(|msg| msg.map_err(GatewayClientError::NetworkError))
|
|
.collect(),
|
|
None => Err(GatewayClientError::ConnectionAbruptlyClosed),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn try_decrypt_binary_message(
|
|
bin_msg: Vec<u8>,
|
|
shared_keys: &SharedKeys,
|
|
) -> Option<Vec<u8>> {
|
|
match BinaryResponse::try_from_encrypted_tagged_bytes(bin_msg, shared_keys) {
|
|
Ok(bin_response) => match bin_response {
|
|
BinaryResponse::PushedMixMessage(plaintext) => Some(plaintext),
|
|
},
|
|
Err(err) => {
|
|
warn!(
|
|
"message received from the gateway was malformed! - {:?}",
|
|
err
|
|
);
|
|
None
|
|
}
|
|
}
|
|
}
|