radix-clis 1.4.0

A collection of CLIs for developing, building and testing Scrypto code, from the Radix DLT project.
use crate::resim::*;
use clap::Parser;
use colored::*;
use radix_common::prelude::*;
use rand::Rng;

/// Generate a key pair
#[derive(Parser, Debug)]
pub struct GenerateKeyPair {}

impl GenerateKeyPair {
    pub fn run<O: std::io::Write>(&self, out: &mut O) -> Result<(), String> {
        let secret = rand::thread_rng().gen::<[u8; 32]>();
        let private_key = Secp256k1PrivateKey::from_bytes(&secret).unwrap();
        let public_key = private_key.public_key();
        writeln!(out, "Public key: {}", public_key.to_string().green()).map_err(Error::IOError)?;
        writeln!(
            out,
            "Private key: {}",
            hex::encode(private_key.to_bytes()).green()
        )
        .map_err(Error::IOError)?;
        Ok(())
    }
}