From 87d304f0175807d9839e7cc9858567d2d433489b Mon Sep 17 00:00:00 2001 From: Edyta Pawlak Date: Fri, 29 Nov 2024 17:37:27 +0100 Subject: [PATCH] fix: clear registry id while init --- src/init.rs | 2 ++ src/tel.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/init.rs b/src/init.rs index 98f294e..ff26f21 100644 --- a/src/init.rs +++ b/src/init.rs @@ -20,6 +20,7 @@ use serde::{Deserialize, Serialize}; use crate::{ keri::{setup_identifier, KeriError}, subcommands::identifier::IdentifierSubcommandError, + tel::remove_registry, utils::working_directory, CliError, }; @@ -141,6 +142,7 @@ pub async fn handle_init( let id = handle_new_id(&keys, kel_config, &db_path).await; match id { Ok(id) => { + let _ = remove_registry(&alias); // Save next keys seed let mut nsk_path = store_path.clone(); nsk_path.push("next_priv_key"); diff --git a/src/tel.rs b/src/tel.rs index 64c6264..105e2cf 100644 --- a/src/tel.rs +++ b/src/tel.rs @@ -1,4 +1,8 @@ -use std::{fs::File, io::Write, sync::Arc}; +use std::{ + fs::{self, File}, + io::Write, + sync::Arc, +}; use keri_controller::{EndRole, IdentifierPrefix, Oobi}; use keri_core::actor::prelude::SelfAddressingIdentifier; @@ -21,6 +25,19 @@ pub fn save_registry(alias: &str, registry_id: &str) -> Result<(), CliError> { Ok(()) } +pub fn remove_registry(alias: &str) -> Result<(), CliError> { + let mut store_path = working_directory()?; + store_path.push(alias); + + let mut reg_path = store_path.clone(); + reg_path.push("reg_id"); + + if fs::metadata(®_path).is_ok() { + fs::remove_file(reg_path)?; + }; + Ok(()) +} + pub async fn handle_issue(alias: &str, data: &str) -> Result<(), CliError> { let mut id = load(alias)?;