Skip to content

Commit

Permalink
feat(keyring): introduce gring (#3619)
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop authored Feb 1, 2024
1 parent fd2be4b commit 7d119cf
Show file tree
Hide file tree
Showing 17 changed files with 1,309 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ toml_edit = "0.21.0" # crat
scale-decode = "0.9.0" # gsdk
directories = "5.0.1" # utils/key-finder
num-traits = { version = "0.2", default-features = false } # gear-core
blake2 = "0.10.6" # gring

# TODO: remove after wasmer bug is fixed:
# `misaligned pointer dereference: address must be a multiple of 0x8 but is...`
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ test-gear: # Crates except gclient, gcli, gsdk are excluded to significantly dec
--exclude gear-authorship \
--exclude pallet-gear-staking-rewards \
--exclude gear-wasm-gen \
--exclude demo-stack-allocations
--exclude demo-stack-allocations \
--exclude gring

.PHONY: test-gear-release
test-gear-release:
Expand Down
3 changes: 2 additions & 1 deletion utils/crates-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub const STACKED_DEPENDENCIES: [&str; 13] = [
/// Packages need to be published.
///
/// NOTE: DO NOT change the order of this array.
pub const PACKAGES: [&str; 6] = [
pub const PACKAGES: [&str; 7] = [
"gring",
"gear-wasm-builder",
"gstd",
"gtest",
Expand Down
39 changes: 39 additions & 0 deletions utils/gring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "gring"
description = "Substrate keystore implementation"
keywords = [ "substrate", "gear", "keystore" ]
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[[bin]]
name = "gring"
path = "src/bin/gring.rs"
required-features = ["cli"]

[dependencies]
anyhow.workspace = true
blake2.workspace = true
bs58 = { workspace = true, features = ["alloc"] }
base64.workspace = true
nacl.workspace = true
once_cell.workspace = true
rand = { workspace = true, features = ["std", "std_rng"] }
schnorrkel.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tracing.workspace = true

# Feature CLI
clap = { workspace = true, features = ["derive"], optional = true }
colored = { workspace = true, optional = true }
dirs = { workspace = true, optional = true }
hex = { workspace = true, features = ["std"], optional = true }
tracing-subscriber = { workspace = true, features = ["env-filter"], optional = true }

[features]
default = ["cli"]
cli = ["clap", "colored", "dirs", "hex", "tracing-subscriber"]
7 changes: 7 additions & 0 deletions utils/gring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# keyring

This crate implements a sr25519 keyring which is synced from [the keystore implementation in polkadot-js][keystore-format].

## Keystore

[keystore-format]: https://github.com/polkadot-js/common/blob/6971012f4af62f453ba25d83d0ebbfd12eaf5709/packages/util-crypto/src/json/encryptFormat.ts#L9
14 changes: 14 additions & 0 deletions utils/gring/res/pair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"encoded": "X/sAaS3pNejnqvbHk0lne8tcXXmTu2gPQgXvtbf3azgAgAAAAQAAAAgAAABxGGfnP+9PCbP7Gp0+7jxxl8twTthzIq4pLfC0m6NvA8hk557A4dkDapszVKhlyDhTvnQQE2WwhqzkfDwvq0XtFl9PDW6ShvVM/lSVLkZTF6QGnTzRZ2dwT7+X5v+gjFIJftI5z3vLFg7NM+NXy7kxU039iooVTxYDqzCnMSjXMBtnY2cqNedlGUcrbDGE0lNdWqu3MWT9J27kmysC",
"encoding": {
"content": ["pkcs8", "sr25519"],
"type": ["scrypt", "xsalsa20-poly1305"],
"version": "3"
},
"address": "5Hax9tpSjfiX1nYrqhFf8F3sLiaa2ZfPv2VeDQzPBLzKNjRq",
"meta": {
"genesisHash": "",
"name": "GEAR",
"whenCreated": 1659544420591
}
}
55 changes: 55 additions & 0 deletions utils/gring/src/bin/gring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of Gear.
//
// Copyright (C) 2024 Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use anyhow::Result;
use clap::{CommandFactory, Parser};
use gring::cmd::Command;
use tracing_subscriber::filter::EnvFilter;

/// Gear keyring.
#[derive(Parser)]
pub struct Opt {
/// The verbosity level.
#[arg(global = true, short, long, action = clap::ArgAction::Count)]
pub verbose: u8,

/// Sub commands.
#[command(subcommand)]
pub command: Command,
}

impl Opt {
/// Run the CLI with logger.
pub fn start() -> Result<()> {
let app = Self::parse();
let name = Self::command().get_name().to_string();
let env = EnvFilter::try_from_default_env().unwrap_or(EnvFilter::new(match app.verbose {
0 => format!("{name}=info"),
1 => format!("{name}=debug"),
2 => "debug".into(),
_ => "trace".into(),
}));

tracing_subscriber::fmt().with_env_filter(env).init();
app.command.run()
}
}

fn main() -> anyhow::Result<()> {
Opt::start()
}
Loading

0 comments on commit 7d119cf

Please sign in to comment.