wallets: provide placeholder functions for ui password
This commit is contained in:
@@ -81,6 +81,8 @@ pub enum BackendError {
|
||||
NoNymdValidatorConfigured,
|
||||
#[error("No validator API URL configured")]
|
||||
NoValidatorApiUrlConfigured,
|
||||
#[error("The wallet file already exists")]
|
||||
WalletFileAlreadyExists,
|
||||
}
|
||||
|
||||
impl Serialize for BackendError {
|
||||
|
||||
@@ -36,8 +36,11 @@ fn main() {
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
mixnet::account::connect_with_mnemonic,
|
||||
mixnet::account::create_new_account,
|
||||
mixnet::account::create_password,
|
||||
mixnet::account::does_password_file_exist,
|
||||
mixnet::account::get_balance,
|
||||
mixnet::account::logout,
|
||||
mixnet::account::sign_in_with_password,
|
||||
mixnet::account::switch_network,
|
||||
mixnet::account::update_validator_urls,
|
||||
mixnet::admin::get_contract_settings,
|
||||
|
||||
@@ -4,8 +4,11 @@ use crate::error::BackendError;
|
||||
use crate::network::Network;
|
||||
use crate::nymd_client;
|
||||
use crate::state::State;
|
||||
use crate::wallet_storage;
|
||||
|
||||
use bip39::{Language, Mnemonic};
|
||||
use config::defaults::COSMOS_DERIVATION_PATH;
|
||||
use cosmrs::bip32::DerivationPath;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
@@ -316,3 +319,47 @@ async fn is_validator_connection_ok(client: &Client<SigningNymdClient>) -> bool
|
||||
Err(_) | Ok(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn does_password_file_exist() -> Result<bool, BackendError> {
|
||||
println!("Checking wallet file");
|
||||
let file = wallet_storage::wallet_login_filepath()?;
|
||||
if file.is_file() {
|
||||
println!("Exists: {}", file.to_string_lossy());
|
||||
} else {
|
||||
println!("Does not exist: {}", file.to_string_lossy());
|
||||
}
|
||||
Ok(file.is_file())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_password(mnemonic: String, password: String) -> Result<(), BackendError> {
|
||||
println!("Creating password");
|
||||
if does_password_file_exist()? {
|
||||
return Err(BackendError::WalletFileAlreadyExists);
|
||||
}
|
||||
|
||||
let mnemonic = Mnemonic::from_str(&mnemonic)?;
|
||||
let hd_path: DerivationPath = COSMOS_DERIVATION_PATH.parse().unwrap();
|
||||
let password = wallet_storage::UserPassword::new(password);
|
||||
wallet_storage::store_wallet_login_information(mnemonic, hd_path, password)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn sign_in_with_password(
|
||||
password: String,
|
||||
state: tauri::State<'_, Arc<RwLock<State>>>,
|
||||
) -> Result<Account, BackendError> {
|
||||
println!("Signing in with password");
|
||||
let password = wallet_storage::UserPassword::new(password);
|
||||
let stored_accounts = wallet_storage::load_existing_wallet_login_information(&password)?;
|
||||
|
||||
// WIP: we are assuming just a single password is stored
|
||||
let stored_account = stored_accounts.into_iter().next().unwrap();
|
||||
let mnemonic = match stored_account {
|
||||
wallet_storage::account_data::StoredAccount::Mnemonic(ref mn) => mn.mnemonic().clone(),
|
||||
};
|
||||
|
||||
_connect_with_mnemonic(mnemonic, state).await
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ pub(crate) struct MnemonicAccount {
|
||||
}
|
||||
|
||||
// we only ever want to expose those getters in the test code
|
||||
#[cfg(test)]
|
||||
// WIP(JON): temporarily comment out
|
||||
//#[cfg(test)]
|
||||
impl MnemonicAccount {
|
||||
pub(crate) fn mnemonic(&self) -> &bip39::Mnemonic {
|
||||
&self.mnemonic
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub(crate) use crate::wallet_storage::password::UserPassword;
|
||||
|
||||
use crate::error::BackendError;
|
||||
use crate::wallet_storage::account_data::StoredAccount;
|
||||
use crate::wallet_storage::encryption::{encrypt_struct, EncryptedData};
|
||||
use crate::wallet_storage::password::UserPassword;
|
||||
use cosmrs::bip32::DerivationPath;
|
||||
use std::fs::{create_dir_all, OpenOptions};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub(crate) mod account_data;
|
||||
pub(crate) mod encryption;
|
||||
|
||||
mod password;
|
||||
|
||||
const STORAGE_DIR_NAME: &str = "NymWallet";
|
||||
|
||||
Reference in New Issue
Block a user