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: migrate add network field #71

Merged
merged 2 commits into from
Mar 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions token-core/tcx-proto/src/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ message MnemonicToPublicKeyResult {

message MigrateKeystoreParam {
string id = 1;
string network = 2;
oneof key {
string password = 2;
string derivedKey = 3;
string password = 3;
string derivedKey = 4;
}
}

Expand Down
8 changes: 5 additions & 3 deletions token-core/tcx/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,19 @@ pub struct MnemonicToPublicKeyResult {
pub struct MigrateKeystoreParam {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
#[prost(oneof = "migrate_keystore_param::Key", tags = "2, 3")]
#[prost(string, tag = "2")]
pub network: ::prost::alloc::string::String,
#[prost(oneof = "migrate_keystore_param::Key", tags = "3, 4")]
pub key: ::core::option::Option<migrate_keystore_param::Key>,
}
/// Nested message and enum types in `MigrateKeystoreParam`.
pub mod migrate_keystore_param {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Key {
#[prost(string, tag = "2")]
Password(::prost::alloc::string::String),
#[prost(string, tag = "3")]
Password(::prost::alloc::string::String),
#[prost(string, tag = "4")]
DerivedKey(::prost::alloc::string::String),
}
}
Expand Down
5 changes: 3 additions & 2 deletions token-core/tcx/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ pub(crate) fn migrate_keystore(data: &[u8]) -> Result<Vec<u8>> {
let keystore;

if let Some(version) = json["version"].as_i64() {
let network = IdentityNetwork::from_str(&param.network.to_uppercase())?;
match version {
11000 | 11001 => {
let keystore_upgrade = KeystoreUpgrade::new(json);
keystore = keystore_upgrade.upgrade(&key, &IdentityNetwork::Testnet)?;
keystore = keystore_upgrade.upgrade(&key, &network)?;
}
_ => {
let legacy_keystore = LegacyKeystore::from_json_str(&json_str)?;
keystore = legacy_keystore.migrate(&key, &IdentityNetwork::Testnet)?;
keystore = legacy_keystore.migrate(&key, &network)?;
}
}
let id = param.id.clone();
Expand Down
Loading
Loading