Skip to content

Instantly share code, notes, and snippets.

@mkg20001
Created February 26, 2026 20:18
Show Gist options
  • Select an option

  • Save mkg20001/30b38667e244ee2c49482543778c06c8 to your computer and use it in GitHub Desktop.

Select an option

Save mkg20001/30b38667e244ee2c49482543778c06c8 to your computer and use it in GitHub Desktop.
freenet private key to public key

freenet private key to public key

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()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment