Skip to content

Commit

Permalink
Add Protobuf definitions from cosmos.crypto.* (#149)
Browse files Browse the repository at this point in the history
* add crypto proto

* Add changelog entry

---------

Co-authored-by: Davirain <[email protected]>
  • Loading branch information
romac and DaviRain-Su authored Sep 28, 2023
1 parent cd8d423 commit 049639a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/149-crypto.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add Protobuf definitions from `cosmos.crypto.*`
([\#149](https://github.com/cosmos/ibc-proto-rs/pull/149))
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ pub mod cosmos {
pub mod v1beta1 {
include_proto!("cosmos.crypto.multisig.v1beta1.rs");
}
include_proto!("cosmos.crypto.multisig.rs");
}
pub mod ed25519 {
include_proto!("cosmos.crypto.ed25519.rs");
}
pub mod secp256k1 {
include_proto!("cosmos.crypto.secp256k1.rs");
}
pub mod secp256r1 {
include_proto!("cosmos.crypto.secp256r1.rs");
}
pub mod keyring {
pub mod v1 {
include_proto!("cosmos.crypto.keyring.v1.rs");
}
}
pub mod hd {
pub mod v1 {
include_proto!("cosmos.crypto.hd.v1.rs");
}
}
}
pub mod tx {
Expand Down
19 changes: 19 additions & 0 deletions src/prost/cosmos.crypto.ed25519.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// PubKey is an ed25519 public key for handling Tendermint keys in SDK.
/// It's needed for Any serialization and SDK compatibility.
/// It must not be used in a non Tendermint key context because it doesn't implement
/// ADR-28. Nevertheless, you will like to use ed25519 in app user level
/// then you must create a new proto message and follow ADR-28 for Address construction.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PubKey {
#[prost(bytes = "vec", tag = "1")]
pub key: ::prost::alloc::vec::Vec<u8>,
}
/// Deprecated: PrivKey defines a ed25519 private key.
/// NOTE: ed25519 keys must not be used in SDK apps except in a tendermint validator context.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PrivKey {
#[prost(bytes = "vec", tag = "1")]
pub key: ::prost::alloc::vec::Vec<u8>,
}
21 changes: 21 additions & 0 deletions src/prost/cosmos.crypto.hd.v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// BIP44Params is used as path field in ledger item in Record.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Bip44Params {
/// purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation
#[prost(uint32, tag = "1")]
pub purpose: u32,
/// coin_type is a constant that improves privacy
#[prost(uint32, tag = "2")]
pub coin_type: u32,
/// account splits the key space into independent user identities
#[prost(uint32, tag = "3")]
pub account: u32,
/// change is a constant used for public derivation. Constant 0 is used for external chain and constant 1 for internal
/// chain.
#[prost(bool, tag = "4")]
pub change: bool,
/// address_index is used as child index in BIP32 derivation
#[prost(uint32, tag = "5")]
pub address_index: u32,
}
61 changes: 61 additions & 0 deletions src/prost/cosmos.crypto.keyring.v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/// Record is used for representing a key in the keyring.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Record {
/// name represents a name of Record
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// pub_key represents a public key in any format
#[prost(message, optional, tag = "2")]
pub pub_key: ::core::option::Option<
super::super::super::super::google::protobuf::Any,
>,
/// Record contains one of the following items
#[prost(oneof = "record::Item", tags = "3, 4, 5, 6")]
pub item: ::core::option::Option<record::Item>,
}
/// Nested message and enum types in `Record`.
pub mod record {
/// Item is a keyring item stored in a keyring backend.
/// Local item
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Local {
#[prost(message, optional, tag = "1")]
pub priv_key: ::core::option::Option<
super::super::super::super::super::google::protobuf::Any,
>,
}
/// Ledger item
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Ledger {
#[prost(message, optional, tag = "1")]
pub path: ::core::option::Option<super::super::super::hd::v1::Bip44Params>,
}
/// Multi item
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Multi {}
/// Offline item
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Offline {}
/// Record contains one of the following items
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Item {
/// local stores the private key locally.
#[prost(message, tag = "3")]
Local(Local),
/// ledger stores the information about a Ledger key.
#[prost(message, tag = "4")]
Ledger(Ledger),
/// Multi does not store any other information.
#[prost(message, tag = "5")]
Multi(Multi),
/// Offline does not store any other information.
#[prost(message, tag = "6")]
Offline(Offline),
}
}
13 changes: 13 additions & 0 deletions src/prost/cosmos.crypto.multisig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// LegacyAminoPubKey specifies a public key type
/// which nests multiple public keys and a threshold,
/// it uses legacy amino address rules.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LegacyAminoPubKey {
#[prost(uint32, tag = "1")]
pub threshold: u32,
#[prost(message, repeated, tag = "2")]
pub public_keys: ::prost::alloc::vec::Vec<
super::super::super::google::protobuf::Any,
>,
}
18 changes: 18 additions & 0 deletions src/prost/cosmos.crypto.secp256k1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// PubKey defines a secp256k1 public key
/// Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte
/// if the y-coordinate is the lexicographically largest of the two associated with
/// the x-coordinate. Otherwise the first byte is a 0x03.
/// This prefix is followed with the x-coordinate.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PubKey {
#[prost(bytes = "vec", tag = "1")]
pub key: ::prost::alloc::vec::Vec<u8>,
}
/// PrivKey defines a secp256k1 private key.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PrivKey {
#[prost(bytes = "vec", tag = "1")]
pub key: ::prost::alloc::vec::Vec<u8>,
}
17 changes: 17 additions & 0 deletions src/prost/cosmos.crypto.secp256r1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// PubKey defines a secp256r1 ECDSA public key.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PubKey {
/// Point on secp256r1 curve in a compressed representation as specified in section
/// 4.3.6 of ANSI X9.62: <https://webstore.ansi.org/standards/ascx9/ansix9621998>
#[prost(bytes = "vec", tag = "1")]
pub key: ::prost::alloc::vec::Vec<u8>,
}
/// PrivKey defines a secp256r1 ECDSA private key.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PrivKey {
/// secret number serialized using big-endian encoding
#[prost(bytes = "vec", tag = "1")]
pub secret: ::prost::alloc::vec::Vec<u8>,
}
Binary file modified src/prost/proto_descriptor.bin
Binary file not shown.
1 change: 1 addition & 0 deletions tools/proto-compiler/src/cmd/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl CompileCmd {
format!("{}/cosmos/gov", sdk_dir.display()),
format!("{}/cosmos/tx", sdk_dir.display()),
format!("{}/cosmos/base", sdk_dir.display()),
format!("{}/cosmos/crypto", sdk_dir.display()),
format!("{}/cosmos/bank", sdk_dir.display()),
format!("{}/cosmos/staking", sdk_dir.display()),
format!("{}/cosmos/upgrade", sdk_dir.display()),
Expand Down

0 comments on commit 049639a

Please sign in to comment.