diff --git a/nym-wallet/src-tauri/src/main.rs b/nym-wallet/src-tauri/src/main.rs index 15f03fc481..cda784a8b7 100644 --- a/nym-wallet/src-tauri/src/main.rs +++ b/nym-wallet/src-tauri/src/main.rs @@ -169,6 +169,10 @@ fn main() { simulate::mixnet::simulate_claim_operator_reward, signatures::sign::sign, signatures::sign::verify, + signatures::ed25519_signing_payload::generate_mixnode_bonding_msg_payload, + signatures::ed25519_signing_payload::vesting_generate_mixnode_bonding_msg_payload, + signatures::ed25519_signing_payload::generate_gateway_bonding_msg_payload, + signatures::ed25519_signing_payload::vesting_generate_gateway_bonding_msg_payload, help::log::help_log_toggle_window, ]) .menu(Menu::os_default(&context.package_info().name).add_default_app_submenus()) diff --git a/nym-wallet/src-tauri/src/operations/signatures/ed25519_signing_payload.rs b/nym-wallet/src-tauri/src/operations/signatures/ed25519_signing_payload.rs new file mode 100644 index 0000000000..b3e2c779cf --- /dev/null +++ b/nym-wallet/src-tauri/src/operations/signatures/ed25519_signing_payload.rs @@ -0,0 +1,100 @@ +// Copyright 2023 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 + +use crate::error::BackendError; +use crate::operations::helpers::{ + create_gateway_bonding_sign_payload, create_mixnode_bonding_sign_payload, +}; +use crate::state::WalletState; +use nym_mixnet_contract_common::{Gateway, MixNode}; +use nym_types::currency::DecCoin; +use nym_types::mixnode::MixNodeCostParams; + +async fn mixnode_bonding_msg_payload( + mixnode: MixNode, + cost_params: MixNodeCostParams, + pledge: DecCoin, + vesting: bool, + state: tauri::State<'_, WalletState>, +) -> Result { + let guard = state.read().await; + let reg = guard.registered_coins()?; + let pledge_base = guard.attempt_convert_to_base_coin(pledge.clone())?; + let cost_params = cost_params.try_convert_to_mixnet_contract_cost_params(reg)?; + log::info!( + ">>> Bond mixnode bonding signature: identity_key = {}, pledge_display = {}, pledge_base = {}, vesting = {vesting}", + mixnode.identity_key, + pledge, + pledge_base, + ); + + let client = guard.current_client()?; + + // TODO: decide on exact structure here. Json? base58? some hash? + // to be determined + let msg = + create_mixnode_bonding_sign_payload(client, mixnode, cost_params, pledge_base, vesting) + .await?; + Ok(msg.to_string()?) +} + +async fn gateway_bonding_msg_payload( + gateway: Gateway, + pledge: DecCoin, + vesting: bool, + state: tauri::State<'_, WalletState>, +) -> Result { + let guard = state.read().await; + let pledge_base = guard.attempt_convert_to_base_coin(pledge.clone())?; + log::info!( + ">>> Bond gateway bonding signature: identity_key = {}, pledge_display = {}, pledge_base = {}, vesting = {vesting}", + gateway.identity_key, + pledge, + pledge_base, + ); + + let client = guard.current_client()?; + + // TODO: decide on exact structure here. Json? base58? some hash? + // to be determined + let msg = create_gateway_bonding_sign_payload(client, gateway, pledge_base, vesting).await?; + Ok(msg.to_string()?) +} + +#[tauri::command] +pub async fn generate_mixnode_bonding_msg_payload( + mixnode: MixNode, + cost_params: MixNodeCostParams, + pledge: DecCoin, + state: tauri::State<'_, WalletState>, +) -> Result { + mixnode_bonding_msg_payload(mixnode, cost_params, pledge, false, state).await +} + +#[tauri::command] +pub async fn vesting_generate_mixnode_bonding_msg_payload( + mixnode: MixNode, + cost_params: MixNodeCostParams, + pledge: DecCoin, + state: tauri::State<'_, WalletState>, +) -> Result { + mixnode_bonding_msg_payload(mixnode, cost_params, pledge, true, state).await +} + +#[tauri::command] +pub async fn generate_gateway_bonding_msg_payload( + gateway: Gateway, + pledge: DecCoin, + state: tauri::State<'_, WalletState>, +) -> Result { + gateway_bonding_msg_payload(gateway, pledge, false, state).await +} + +#[tauri::command] +pub async fn vesting_generate_gateway_bonding_msg_payload( + gateway: Gateway, + pledge: DecCoin, + state: tauri::State<'_, WalletState>, +) -> Result { + gateway_bonding_msg_payload(gateway, pledge, true, state).await +} diff --git a/nym-wallet/src-tauri/src/operations/signatures/mod.rs b/nym-wallet/src-tauri/src/operations/signatures/mod.rs index 66ccbc9eb6..5b98a61130 100644 --- a/nym-wallet/src-tauri/src/operations/signatures/mod.rs +++ b/nym-wallet/src-tauri/src/operations/signatures/mod.rs @@ -1 +1,2 @@ +pub mod ed25519_signing_payload; pub mod sign;