Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mark identity wallet ids #83

Merged
merged 2 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion token-core/tcx-migration/src/migration.rs
Expand Up @@ -59,7 +59,7 @@ impl OldMetadata {
self.source
.clone()
.map_or((Source::Mnemonic, None), |source| match source.as_str() {
"RECOVER_IDENTITY" => (Source::Mnemonic, None),
"RECOVERED_IDENTITY" => (Source::Mnemonic, None),
"NEW_IDENTITY" => (Source::NewMnemonic, None),
"KEYSTORE" => (Source::KeystoreV3, Some(vec!["ETHEREUM".to_string()])),
"PRIVATE" => (Source::Private, Some(vec!["ETHEREUM".to_string()])),
Expand Down
9 changes: 9 additions & 0 deletions token-core/tcx-proto/src/params.proto
Expand Up @@ -277,4 +277,13 @@ message MigrateKeystoreParam {

message BackupResult {
string original = 1;
}

message MarkIdentityWalletsParam {
repeated string ids = 1;
string source = 2;
}

message ReadKeystoreMnemonicPathResult {
string path = 1;
}
14 changes: 14 additions & 0 deletions token-core/tcx/src/api.rs
Expand Up @@ -704,6 +704,20 @@ pub struct BackupResult {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MarkIdentityWalletsParam {
#[prost(string, repeated, tag = "1")]
pub ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, tag = "2")]
pub source: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadKeystoreMnemonicPathResult {
#[prost(string, tag = "1")]
pub path: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct VerifyDerivedKeyParam {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
Expand Down
16 changes: 15 additions & 1 deletion token-core/tcx/src/handler.rs
Expand Up @@ -70,7 +70,9 @@ use tcx_primitive::TypedDeterministicPublicKey;
use tcx_tezos::{encode_tezos_private_key, parse_tezos_private_key};

use crate::macros::{impl_to_key, use_chains};
use crate::migration::remove_old_keystore_by_id;
use crate::migration::{
read_all_identity_wallet_ids, remove_all_identity_wallets, remove_old_keystore_by_id,
};

use_chains!(
tcx_btc_kin::bitcoin,
Expand Down Expand Up @@ -727,12 +729,24 @@ pub(crate) fn delete_keystore(data: &[u8]) -> Result<Vec<u8>> {
delete_keystore_file(&param.id)?;
map.remove(&param.id);

// Used to delete all duplicated mnemonic keystore
if let Some(file_ids) = remove_old_keystore_by_id(&param.id.clone()) {
for file_id in file_ids {
map.remove(&file_id);
}
}

// Used to delete all identity keystore if is deleting identity wallet
if let Some(all_identity_wallets) = read_all_identity_wallet_ids() {
if all_identity_wallets.wallet_ids.contains(&param.id) {
if let Some(file_ids) = remove_all_identity_wallets() {
for file_id in file_ids {
map.remove(&file_id);
}
}
}
}

let rsp = GeneralResult {
is_success: true,
error: "".to_owned(),
Expand Down
7 changes: 7 additions & 0 deletions token-core/tcx/src/lib.rs
Expand Up @@ -7,6 +7,7 @@ use std::os::raw::c_char;

use anyhow::anyhow;
use handler::{backup, sign_bls_to_execution_change};
use migration::{mark_identity_wallets, read_legacy_keystore_mnemonic_path};
use prost::Message;

pub mod api;
Expand Down Expand Up @@ -78,6 +79,9 @@ pub unsafe extern "C" fn call_tcx_api(hex_str: *const c_char) -> *const c_char {
let ret = scan_legacy_keystores()?;
encode_message(ret)
}),
"read_keystore_mnemonic_path" => {
landingpad(|| read_legacy_keystore_mnemonic_path(&action.param.unwrap().value))
}
"create_keystore" => landingpad(|| create_keystore(&action.param.unwrap().value)),
"import_mnemonic" => landingpad(|| import_mnemonic(&action.param.unwrap().value)),
"export_mnemonic" => landingpad(|| export_mnemonic(&action.param.unwrap().value)),
Expand Down Expand Up @@ -122,6 +126,9 @@ pub unsafe extern "C" fn call_tcx_api(hex_str: *const c_char) -> *const c_char {
"eth_batch_personal_sign" => {
landingpad(|| eth_batch_personal_sign(&action.param.unwrap().value))
}
"mark_identity_wallets" => {
landingpad(|| mark_identity_wallets(&action.param.unwrap().value))
}
_ => landingpad(|| Err(anyhow!("unsupported_method"))),
};
match reply {
Expand Down