From 07a86afb549fc36d8fde0e57ae5c18f30867425b Mon Sep 17 00:00:00 2001 From: Simon Wicky Date: Fri, 1 Dec 2023 15:48:47 +0100 Subject: [PATCH] generate ecash key on client upgrade --- Cargo.lock | 1 + clients/native/Cargo.toml | 1 + clients/native/src/commands/mod.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 9166f751c9..aff1431482 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6317,6 +6317,7 @@ dependencies = [ "nym-client-core", "nym-client-websocket-requests", "nym-coconut-interface", + "nym-compact-ecash", "nym-config", "nym-credential-storage", "nym-credentials", diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index 03827720ba..450b4940f9 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -38,6 +38,7 @@ nym-bandwidth-controller = { path = "../../common/bandwidth-controller" } nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] } nym-client-core = { path = "../../common/client-core", features = ["fs-surb-storage", "cli"] } nym-coconut-interface = { path = "../../common/coconut-interface" } +nym-compact-ecash = { path = "../../common/nym_offline_compact_ecash" } nym-config = { path = "../../common/config" } nym-credential-storage = { path = "../../common/credential-storage" } nym-credentials = { path = "../../common/credentials" } diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index 3ebe929b16..a96f570e16 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -18,6 +18,7 @@ use nym_client_core::client::base_client::storage::gateway_details::{ use nym_client_core::client::key_manager::persistence::OnDiskKeys; use nym_client_core::config::GatewayEndpointConfig; use nym_client_core::error::ClientCoreError; +use nym_compact_ecash::{generate_keypair_user, setup::GroupParameters}; use nym_config::OptionalSet; use std::error::Error; use std::net::IpAddr; @@ -121,6 +122,28 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config { ) } +fn init_ecash_keypair(config: &Config) -> Result<(), ClientError> { + let kp = generate_keypair_user(&GroupParameters::new().unwrap()); + nym_pemstore::store_keypair( + &kp, + &nym_pemstore::KeyPairPath::new( + config + .storage_paths + .common_paths + .keys + .private_ecash_key_file + .clone(), + config + .storage_paths + .common_paths + .keys + .public_ecash_key_file + .clone(), + ), + )?; + Ok(()) +} + fn persist_gateway_details( config: &Config, details: GatewayEndpointConfig, @@ -159,6 +182,7 @@ fn try_upgrade_v1_1_13_config(id: &str) -> Result { let updated_step2: ConfigV1_1_20_2 = updated_step1.into(); let (updated, gateway_config) = updated_step2.upgrade()?; persist_gateway_details(&updated, gateway_config)?; + init_ecash_keypair(&updated)?; //SW does that belong here? updated.save_to_default_location()?; Ok(true) @@ -179,6 +203,7 @@ fn try_upgrade_v1_1_20_config(id: &str) -> Result { let updated_step1: ConfigV1_1_20_2 = old_config.into(); let (updated, gateway_config) = updated_step1.upgrade()?; persist_gateway_details(&updated, gateway_config)?; + init_ecash_keypair(&updated)?; //SW does that belong here? updated.save_to_default_location()?; Ok(true) @@ -196,6 +221,7 @@ fn try_upgrade_v1_1_20_2_config(id: &str) -> Result { let (updated, gateway_config) = old_config.upgrade()?; persist_gateway_details(&updated, gateway_config)?; + init_ecash_keypair(&updated)?; //SW does that belong here? updated.save_to_default_location()?; Ok(true)