This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from tendermint/cosmos-stdtx
cosmos-stdtx.rs: amino serializer for Cosmos SDK-formatted StdTx transactions
- Loading branch information
Showing
22 changed files
with
1,754 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,16 @@ description = "Tendermint Key Management System" | |
version = "0.7.1" # Also update html_root_url in lib.rs when bumping this | ||
authors = ["Tony Arcieri <[email protected]>", "Ismail Khoffi <[email protected]>"] | ||
license = "Apache-2.0" | ||
homepage = "https://github.com/tendermint/kms/" | ||
homepage = "https://tendermint.com/" | ||
repository = "https://github.com/tendermint/kms/" | ||
readme = "README.md" | ||
categories = ["cryptography"] | ||
keywords = ["cosmos", "ed25519", "kms", "key-management", "yubihsm"] | ||
edition = "2018" | ||
|
||
[workspace] | ||
members = [".", "cosmos-stdtx"] | ||
|
||
[badges] | ||
circle-ci = { repository = "tendermint/kms" } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "cosmos-stdtx" | ||
description = "Extensible schema-driven Cosmos StdTx builder and serializer" | ||
version = "0.0.1" # Also update html_root_url in lib.rs when bumping this | ||
authors = ["Tony Arcieri <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/tendermint/kms/tree/master/cosmos-stdtx" | ||
readme = "README.md" | ||
categories = ["cryptography", "encoding"] | ||
keywords = ["crypto", "cosmos", "stdtx", "transaction", "tendermint"] | ||
edition = "2018" | ||
|
||
[badges] | ||
circle-ci = { repository = "tendermint/kms" } | ||
|
||
[dependencies] | ||
anomaly = "0.1" | ||
ecdsa = { version = "0.4", features = ["k256"] } | ||
prost-amino = "0.5" | ||
prost-amino-derive = "0.5" | ||
rust_decimal = "1.1" | ||
serde = { version = "1", features = ["serde_derive"] } | ||
serde_json = "1" | ||
sha2 = "0.8" | ||
subtle-encoding = { version = "0.5", features = ["bech32-preview"] } | ||
thiserror = "1" | ||
toml = "0.5" | ||
|
||
[dev-dependencies] | ||
signatory-secp256k1 = "0.18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# cosmos-stdtx.rs 🌌 | ||
|
||
[![Crate][crate-image]][crate-link] | ||
[![Docs][docs-image]][docs-link] | ||
[![Build Status][build-image]][build-link] | ||
[![Safety Dance][safety-image]][safety-link] | ||
[![Apache 2.0 Licensed][license-image]][license-link] | ||
![MSRV][rustc-image] | ||
|
||
Extensible schema-driven [Cosmos] [StdTx] builder and serializer. | ||
|
||
## About | ||
|
||
**cosmos-stdtx.rs** is a Rust library for composing transactions in the [StdTx] | ||
format used by several [Tendermint]-based networks. | ||
|
||
It includes support for cryptographically signing transactions and serializing | ||
them in the [Amino] encoding format. | ||
|
||
Definitions of transaction types are easily extensible, and can be defined at | ||
runtime by loading them from a TOML definition file. This allows | ||
**cosmos-stdtx.rs** to be used with any [Tendermint]-based software which | ||
uses the [StdTx] format without requiring upstream modifications. | ||
|
||
## Minimum Supported Rust Version | ||
|
||
- Rust **1.39+** | ||
|
||
## License | ||
|
||
Copyright © 2020 Tony Arcieri | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
[//]: # (badges) | ||
|
||
[crate-image]: https://img.shields.io/crates/v/cosmos-stdtx.svg | ||
[crate-link]: https://crates.io/crates/cosmos-stdtx | ||
[docs-image]: https://docs.rs/cosmos-stdtx/badge.svg | ||
[docs-link]: https://docs.rs/cosmos-stdtx/ | ||
[build-image]: https://circleci.com/gh/tendermint/kms.svg?style=shield | ||
[build-link]: https://circleci.com/gh/tendermint/kms | ||
[safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg | ||
[safety-link]: https://github.com/rust-secure-code/safety-dance/ | ||
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg | ||
[license-link]: https://github.com/tendermint/kms/blob/master/LICENSE | ||
[rustc-image]: https://img.shields.io/badge/rustc-1.39+-blue.svg | ||
|
||
[//]: # (general links) | ||
|
||
[Cosmos]: https://cosmos.network/ | ||
[StdTx]: https://godoc.org/github.com/cosmos/cosmos-sdk/x/auth/types#StdTx | ||
[Tendermint]: https://tendermint.com/ | ||
[Amino]: https://github.com/tendermint/go-amino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Address types (account or validator) | ||
use crate::error::{Error, ErrorKind}; | ||
use anomaly::ensure; | ||
use std::convert::TryInto; | ||
use subtle_encoding::bech32; | ||
|
||
/// Size of an address | ||
pub const ADDRESS_SIZE: usize = 20; | ||
|
||
/// Address type | ||
#[derive(Clone, Debug)] | ||
pub struct Address(pub [u8; ADDRESS_SIZE]); | ||
|
||
impl Address { | ||
/// Parse an address from its Bech32 form | ||
pub fn from_bech32(addr_bech32: impl AsRef<str>) -> Result<(String, Address), Error> { | ||
let (hrp, addr) = bech32::decode(addr_bech32.as_ref())?; | ||
|
||
ensure!( | ||
addr.len() == ADDRESS_SIZE, | ||
ErrorKind::Address, | ||
"invalid length for decoded address: {} (expected {})", | ||
addr.len(), | ||
ADDRESS_SIZE | ||
); | ||
|
||
Ok((hrp, Address(addr.as_slice().try_into().unwrap()))) | ||
} | ||
|
||
/// Encode this address as Bech32 | ||
pub fn to_bech32(&self, hrp: &str) -> String { | ||
bech32::encode(hrp, &self.0) | ||
} | ||
} | ||
|
||
impl AsRef<[u8]> for Address { | ||
fn as_ref(&self) -> &[u8] { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<[u8; ADDRESS_SIZE]> for Address { | ||
fn from(addr: [u8; ADDRESS_SIZE]) -> Address { | ||
Address(addr) | ||
} | ||
} | ||
|
||
impl From<Address> for [u8; ADDRESS_SIZE] { | ||
fn from(addr: Address) -> [u8; ADDRESS_SIZE] { | ||
addr.0 | ||
} | ||
} |
Oops, something went wrong.