Skip to content

Commit

Permalink
feat(utils): add util to retrieve default peer ID secret keys (#3335)
Browse files Browse the repository at this point in the history
Co-authored-by: Shamil <[email protected]>
  • Loading branch information
mqxf and shamilsan authored Sep 23, 2023
1 parent 2943b74 commit 661ed02
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
41 changes: 38 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ scale-value = "^0.10" # gsdk
heck = "0.4.1" # gsdk-api-gen
etc = "0.1.16" # gcli
scale-decode = "0.7.0" # gsdk
directories = "5.0.1" # utils/key-finder

[profile.release]
panic = "unwind"
Expand Down
12 changes: 12 additions & 0 deletions utils/key-finder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "gear-key-finder"
version.workspace = true
authors.workspace = true
edition.workspace = true

[[bin]]
name = "gear-key-finder"

[dependencies]
hex = { workspace = true, features = ["alloc"] }
directories.workspace = true
41 changes: 41 additions & 0 deletions utils/key-finder/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use directories::ProjectDirs;

const VERSIONS: [&str; 7] = [
"staging_testnet",
"staging_testnet_v2",
"gear_staging_testnet_v3",
"gear_staging_testnet_v4",
"gear_staging_testnet_v5",
"gear_staging_testnet_v6",
"gear_staging_testnet_v7",
];

const PATHS: [&str; 2] = ["gear", "gear-node"];

fn main() {
let mut found = false;
for path in PATHS {
let chains_path = ProjectDirs::from("", "", path)
.unwrap()
.data_local_dir()
.join("chains");
if chains_path.is_dir() {
for version in VERSIONS {
let mut key_path = chains_path.join(version);
key_path.extend(&["network", "secret_ed25519"]);
if key_path.is_file() {
let key = std::fs::read(&key_path);
if let Ok(key) = key {
println!("Key found in \"{path}/{version}\": 0x{}", hex::encode(key));
found = true;
} else {
eprintln!("Failed to read key from {path:?}",);
}
}
}
}
}
if !found {
println!("No key file was found. Please try to run this utility with `sudo`.");
}
}

0 comments on commit 661ed02

Please sign in to comment.