Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. use std::{fs, path::PathBuf, process, str};
  2. use subtle_encoding::{base64, Identity};
  3. use signatory::{Decode, Encode, ed25519};
  4.  
  5. pub type SecretKeyEncoding = subtle_encoding::Base64;
  6.  
  7. fn import_priv_validator(json_data: &str) {
  8.  
  9. let v: serde_json::Value = serde_json::from_str(json_data).unwrap();
  10.  
  11. let s = v["priv_key"]["value"].as_str().unwrap_or_else(|| {
  12. process::exit(1);
  13. });
  14.  
  15. let key_pair = base64::decode(s).unwrap_or_else(|_| {
  16. process::exit(1);
  17. });
  18.  
  19. let seed = ed25519::Seed::from_keypair(&key_pair).unwrap_or_else(|| {
  20. process::exit(1);
  21. });
  22.  
  23. let key_encoded = seed.encode_to_string(&SecretKeyEncoding::default());
  24. println!("output secret key: {}", key_encoded.unwrap());
  25. }
  26.  
  27. fn main() {
  28. let path = PathBuf::from(r"priv_validator_key.json");
  29. let contents = fs::read_to_string(&path).unwrap_or_else(|e| {
  30. println!("couldn't import file {}: {}", &path.display(), e);
  31. process::exit(1);
  32. });
  33. println!("{}", &contents);
  34. import_priv_validator(&contents);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement