Usage: cat ~/.local/share/freenet/secrets/transport_keypair | rust-script pubkey_from_secret.rs
You can get rust-script from cargo: cargo install rust-script
| #!/usr/bin/env rust-script | |
| //! ```cargo | |
| //! [dependencies] | |
| //! x25519-dalek = { version = "2", features = ["static_secrets"] } | |
| //! hex = "0.4" | |
| //! ``` | |
| use std::io::{self, Read}; | |
| use x25519_dalek::{PublicKey, StaticSecret}; | |
| fn main() { | |
| let mut hex_input = String::new(); | |
| io::stdin().read_to_string(&mut hex_input).expect("failed to read stdin"); | |
| let bytes: [u8; 32] = hex::decode(hex_input.trim()) | |
| .expect("invalid hex") | |
| .try_into() | |
| .expect("key must be 32 bytes"); | |
| let secret = StaticSecret::from(bytes); | |
| let public = PublicKey::from(&secret); | |
| println!("{}", hex::encode(public.as_bytes())); | |
| } |