Skip to content

Commit

Permalink
Merge pull request #74 from osmosis-labs/boss/keyring
Browse files Browse the repository at this point in the history
Implements keyring as signer
  • Loading branch information
iboss-ptk authored Jul 11, 2022
2 parents d975f1d + c390b1d commit 1c49173
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 15 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@

[Beaker](https://github.com/osmosis-labs/beaker) makes it easy to scaffold a new cosmwasm app, with all of the dependencies for osmosis hooked up, interactive console, and a sample front-end at the ready.


---

## Table of Contents

### Getting Started
+ [Installation](#installation)
+ [Scaffolding your new dapp project](#scaffolding-your-new-dapp-project)

- [Installation](#installation)
- [Scaffolding your new dapp project](#scaffolding-your-new-dapp-project)
- [`frontend` and `contracts`](#frontend-and-contracts)
- [`Cargo.toml`](#cargotoml)
- [`Beaker.toml`](#beakertoml)
- [`.beaker`](#beaker-1)
+ [Your first CosmWasm contract with Beaker](#your-first-cosmwasm-contract-with-beaker)
+ [Deploy contract on LocalOsmosis](#deploy-contract-on-localosmosis)
+ [Contract Upgrade](#contract-upgrade)
+ [Console](#console)
+ [Frontend](#frontend)

- [Your first CosmWasm contract with Beaker](#your-first-cosmwasm-contract-with-beaker)
- [Deploy contract on LocalOsmosis](#deploy-contract-on-localosmosis)
- [Contract Upgrade](#contract-upgrade)
- [Signers](#signers)
- [Console](#console)
- [Frontend](#frontend)

### Reference

- [Command](./docs/commands)
- [Config](./docs/config)


---

## Getting Started
Expand Down Expand Up @@ -276,6 +276,15 @@ beaker wasm upgrade counter --signer-account test1 --no-wasm-opt

You can find more information about their options [here](./docs/commands/beaker_wasm.md).

### Signers

Whenever you run command that requires signing transactions, there are 3 options you can reference your private keys:

- `--signer-account` input of this option refer to the accounts defined in the [config file](./docs/config/global.md), which is not encrypted, so it should be used only for testing
- `--signer-mnemonic` input of this option is the raw mnemonic string to construct a signer
- `--signer-private-key` input of this option is the same as `--signer-mnemonic` except it expects base64 encoded private key
- `--signer-keyring` use the OS secure store as backend to securely store your key. To manage them, you can find more information [here](./docs/commands/beaker_key.md).

### Console

After deployed, you can play with the deployed contract using:
Expand Down
14 changes: 14 additions & 0 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ Arguments:

---

### `beaker key`

Managing key backed by system's secret store

[\> `beaker key`'s subcommands](./beaker_key.md)

Arguments:

* `--help`: Print help information

* `--version`: Print version information

---

### `beaker console`

Launch interactive console for interacting with the project
Expand Down
75 changes: 75 additions & 0 deletions docs/commands/beaker_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# `beaker key`

Managing key backed by system's secret store

Arguments:

* `--help`: Print help information

* `--version`: Print version information

## Subcommands

### `beaker key set`

Create new key or update existing key

Arguments:

* `--help`: Print help information

* `--version`: Print version information

* ` <name>`Name of the key to create or update

* ` <mnemonic>`Mnemonic string to store as an entry

* `-y/--yes`: Agree to all prompts

---

### `beaker key delete`

Delete existing key

Arguments:

* `--help`: Print help information

* `--version`: Print version information

* ` <name>`Name of the key to create or update

* `-y/--yes`: Agree to all prompts

---

### `beaker key address`

Get address from keyring's stored key

Arguments:

* `--help`: Print help information

* `--version`: Print version information

* ` <name>`Name of the key to create or update

---

### `beaker key generate`

Generate new mnemonic

Arguments:

* `--help`: Print help information

* `--version`: Print version information

* ` <name>`Name of the key to create or update

* `--show`: Show mnemonic in the console if set, keep it secret otherwise

* `-y/--yes`: Agree to all prompts
10 changes: 10 additions & 0 deletions docs/commands/beaker_wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down Expand Up @@ -106,6 +108,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down Expand Up @@ -142,6 +146,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down Expand Up @@ -182,6 +188,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down Expand Up @@ -218,6 +226,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down
4 changes: 4 additions & 0 deletions docs/commands/beaker_wasm_proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down Expand Up @@ -72,6 +74,8 @@ Arguments:

* `--signer-account <signer-account>`: Specifies predefined account as a tx signer

* `--signer-keyring <signer-keyring>`: Specifies private_key as a tx signer (base64 encoded string)

* `--signer-mnemonic <signer-mnemonic>`: Specifies mnemonic as a tx signer

* `--signer-private-key <signer-private-key>`: Specifies private_key as a tx signer (base64 encoded string)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data_doc_derive = {path = "../data_doc_derive"}
derive-new = "0.5.9"
dialoguer = "0.10.1"
getset = "0.1.2"
keyring = "1.2.0"
prost = "0.10.3"
regex = "1.5.6"
serde = "1.0.137"
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use anyhow::{bail, Context as _, Result};
use clap::{AppSettings, Parser, Subcommand};
use config::Config;
use data_doc_derive::GetDataDocs;
use modules::key::entrypoint::{KeyCmd, KeyModule};
use serde::{Deserialize, Serialize};
use std::process::Command;

pub use framework::{config::GlobalConfig, Context, Module};
pub use modules::wasm::{WasmCmd, WasmConfig, WasmModule};
pub use modules::workspace::{WorkspaceCmd, WorkspaceConfig, WorkspaceModule};

use crate::modules::key::config::KeyConfig;

#[derive(Parser)]
#[clap(author, version,about, long_about = None)]
#[clap(propagate_version = true)]
Expand All @@ -35,6 +38,11 @@ pub enum Commands {
#[clap(subcommand)]
cmd: WasmCmd,
},
/// Managing key backed by system's secret store
Key {
#[clap(subcommand)]
cmd: KeyCmd,
},
/// Launch interactive console for interacting with the project
Console {
#[clap(short, long, default_value = "local")]
Expand Down Expand Up @@ -99,14 +107,16 @@ fn console(network: &str) -> Result<()> {
context!(
WasmContext, config = { wasm: WasmConfig };
WorkspaceContext, config = { workspace: WorkspaceConfig };
ConsoleContext, config = { console: ConsoleConfig }
ConsoleContext, config = { console: ConsoleConfig };
KeyContext, config = { key: KeyConfig }
);

pub fn execute(cmd: &Commands) -> Result<()> {
match cmd {
Commands::Wasm { cmd } => WasmModule::execute(WasmContext::new(), cmd),
Commands::Workspace(cmd) => WorkspaceModule::execute(WorkspaceContext::new(), cmd),
Commands::Console { network } => console(network),
Commands::Key { cmd } => KeyModule::execute(KeyContext::new(), cmd),
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/modules/key/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use data_doc_derive::GetDataDocs;
use serde::Deserialize;
use serde::Serialize;

#[derive(Serialize, Deserialize, GetDataDocs, Default)]
pub struct KeyConfig {}

pub const SERVICE: &str = "beaker";
Loading

0 comments on commit 1c49173

Please sign in to comment.