Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devnet): move keygen and cosmwasm address computation into devnet-utils #1986

Merged
merged 1 commit into from
May 30, 2024
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
58 changes: 30 additions & 28 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ members = [
"light-clients/linea-light-client",

"tools/generate-rust-sol-bindings",
"tools/keygen",
"tools/devnet-utils",
"tools/parse-wasm-client-type",
"tools/tidy",

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
];
});
};
keygen = self'.packages.keygen;
devnet-utils = self'.packages.devnet-utils;
# this pr (https://github.com/numtide/treefmt/pull/250) was merged one day after v0.6.1 was cut, so in order to use the --hidden flag we need to build latest
# expression taken from here https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/treefmt/default.nix
treefmt = super.rustPlatform.buildRustPackage rec {
Expand Down
1 change: 0 additions & 1 deletion networks/devnet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

mkCosmosDevnet = import ./mkCosmosDevnet.nix {
inherit pkgs dbg;
ucliBin = pkgs.lib.getExe self'.packages.ucli;
};
lnav = inputs'.nixpkgs-lnav.legacyPackages.lnav;

Expand Down
13 changes: 6 additions & 7 deletions networks/mkCosmosDevnet.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ pkgs
, dbg
, ucliBin
, ...
}:
{ node
Expand Down Expand Up @@ -43,9 +42,9 @@ let
assert (builtins.isInt idx);
pkgs.runCommand
"${chainName}-mnemonic_${toString idx}"
{ buildInputs = [ pkgs.keygen ]; }
{ buildInputs = [ pkgs.devnet-utils ]; }
''
keygen mnemonic $(echo ${toString idx} | sha256sum - | cut -d' ' -f1) > $out
devnet-utils keygen mnemonic $(echo ${toString idx} | sha256sum - | cut -d' ' -f1) > $out

echo "validator ${toString idx} mnemonic: $(cat $out)"
'';
Expand All @@ -54,9 +53,9 @@ let
assert (builtins.isInt idx);
pkgs.runCommand
"${chainName}-node-key_${toString idx}"
{ buildInputs = [ pkgs.keygen ]; }
{ buildInputs = [ pkgs.devnet-utils ]; }
''
NODE_KEY=$(keygen key --key-type ed25519 "$(cat ${mkNodeMnemonic idx})" | tr -d '\n')
NODE_KEY=$(devnet-utils keygen key --key-type ed25519 "$(cat ${mkNodeMnemonic idx})" | tr -d '\n')

echo "validator ${toString idx} node_key: $NODE_KEY"

Expand Down Expand Up @@ -489,9 +488,9 @@ let
'';

getContractAddress = creator: checksum: salt:
pkgs.runCommand "get-contract-address" { buildInputs = [ pkgs.jq ]; } ''
pkgs.runCommand "get-contract-address" { buildInputs = [ pkgs.jq pkgs.devnet-utils ]; } ''
export HOME=$(pwd)
CANONICAL_ADDR=$(${ucliBin} \
CANONICAL_ADDR=$(devnet-utils \
compute \
instantiate2-address \
--creator "0x$(cat ${creator})" \
Expand Down
19 changes: 19 additions & 0 deletions tools/devnet-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
edition = { workspace = true }
license-file = { workspace = true }
name = "devnet-utils"
repository = { workspace = true }
version = "0.1.0"

[lints]
workspace = true

[dependencies]
base64 = { workspace = true }
bip39 = "2.0.0"
clap = { workspace = true, features = ["derive", "error-context", "help"] }
cosmwasm-std = "2.0.3"
ed25519-compact = { version = "2.1.1", default-features = false, features = ["ed25519"] }
hex = { workspace = true, features = ["std"] }
strum = { version = "0.26.1", features = ["derive"] }
unionlabs.workspace = true
92 changes: 92 additions & 0 deletions tools/devnet-utils/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use base64::{display::Base64Display, engine::general_purpose::STANDARD};
use bip39::Mnemonic;
use clap::{Parser, Subcommand};
use ed25519_compact::{KeyPair, Seed};
use unionlabs::hash::{H160, H256};

#[derive(Parser)]
#[clap(arg_required_else_help = true)]
struct App {
#[clap(subcommand)]
command: Cmd,
}

#[derive(Subcommand)]
enum Cmd {
#[clap(subcommand)]
Keygen(KeygenCmd),
#[command(subcommand)]
Compute(ComputeCmd),
}

#[derive(Subcommand)]
enum KeygenCmd {
Key {
mnemonic: Mnemonic,
#[arg(long)]
key_type: KeyType,
},
Mnemonic {
seed: String,
},
}

#[derive(Subcommand)]
pub enum ComputeCmd {
Instantiate2Address {
#[arg(long)]
creator: H160,
#[arg(long)]
checksum: H256,
#[arg(long)]
salt: String,
},
}

#[derive(strum::EnumString, Clone)]
#[strum(serialize_all = "kebab-case")]
enum KeyType {
Ed25519,
}

fn main() {
let app = App::parse();

match app.command {
Cmd::Keygen(cmd) => match cmd {
KeygenCmd::Key { mnemonic, key_type } => match key_type {
KeyType::Ed25519 => {
let key_pair =
KeyPair::from_seed(Seed::new(mnemonic.to_entropy().try_into().unwrap()));

println!("{}", Base64Display::new(&*key_pair.sk, &STANDARD));
}
},
KeygenCmd::Mnemonic { seed } => {
println!(
"{}",
Mnemonic::from_entropy(&hex::decode(seed).unwrap()).unwrap()
);
}
},
Cmd::Compute(cmd) => match cmd {
ComputeCmd::Instantiate2Address {
creator,
checksum,
salt,
} => {
println!(
"{}",
hex::encode(
&*cosmwasm_std::instantiate2_address(
&checksum.0,
&creator.0.into(),
&hex::decode(salt).unwrap(),
)
.unwrap()
)
);
}
},
}
}
17 changes: 0 additions & 17 deletions tools/keygen/Cargo.toml

This file was deleted.

Loading
Loading