Skip to content
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
29 changes: 27 additions & 2 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ edition = "2024"

[dependencies]
clap = { version = "4.5.54", features = ["derive"] }
ed25519-dalek = { version = "2", features = ["rand_core"] }
hex = "0.4"
rand = "0.8"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
tokio = { version = "1.49.0", features = ["full"] }
wampproto = { git = "https://github.com/xconnio/wampproto-rust.git", rev = "520130fa02343409578879959748b36f151bbc8d" }
xconn = { git = "https://github.com/xconnio/xconn-rust.git", rev = "484b2deade287937d3c3a65b6ad9d8b2ae2dd2d1" }

6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ pub enum Commands {
Subscribe,
/// Publish to a topic
Publish,
/// Generate a WAMP cryptosign ed25519 keypair
Keygen {
/// Write keypair to file. Uses 'key' and 'key.pub' by default, or specify a custom name
#[arg(short = 'O', long = "output-file", value_name = "NAME", num_args = 0..=1, default_missing_value = "key")]
output_file: Option<String>,
},
}
31 changes: 31 additions & 0 deletions src/commands/keygen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use ed25519_dalek::SigningKey;
use hex::ToHex;
use rand::rngs::OsRng;
use std::fs::File;
use std::io::Write;

pub fn handle(output_file: Option<String>) -> Result<(), Box<dyn std::error::Error>> {
let mut csprng = OsRng;
let signing_key = SigningKey::generate(&mut csprng);

let private_key_hex: String = signing_key.to_bytes().encode_hex();
let public_key_hex: String = signing_key.verifying_key().to_bytes().encode_hex();

println!("Public Key: {}", public_key_hex);
println!("Private Key: {}", private_key_hex);

if let Some(name) = output_file {
let pub_path = format!("{}.pub", name);
let priv_path = name;

let mut file = File::create(&pub_path)?;
writeln!(file, "{}", public_key_hex)?;
println!("Public key written to {}", pub_path);

let mut file = File::create(&priv_path)?;
writeln!(file, "{}", private_key_hex)?;
println!("Private key written to {}", priv_path);
}

Ok(())
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod call;
pub mod keygen;
pub mod publish;
pub mod register;
pub mod subscribe;
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use config::{CallConfig, ConnectionConfig};
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();

// Handle commands that don't require a connection first
if let Commands::Keygen { output_file } = cli.command {
return commands::keygen::handle(output_file);
}

println!("Connecting to {} in realm {}", cli.url, cli.realm);

let conn_config = ConnectionConfig::from(&cli);
Expand Down Expand Up @@ -51,6 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
commands::publish::handle(&session).await?;
session.leave().await?;
}
Commands::Keygen { .. } => unreachable!(), // Handled above
}

Ok(())
Expand Down
Loading