Move EIP-712 crate back to parity-ethereum (#10106)

* move eip-712 crate back to parity-ethereum

* changed license, updated documentation url
This commit is contained in:
Seun LanLege 2018-12-28 10:36:55 +01:00 committed by Wei Tang
parent ff0095ac5e
commit 912e5599d9
12 changed files with 88 additions and 31 deletions

4
Cargo.lock generated
View File

@ -549,7 +549,7 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "eip712"
name = "eip-712"
version = "0.1.0"
dependencies = [
"ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2509,7 +2509,7 @@ version = "1.12.0"
dependencies = [
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eip712 0.1.0",
"eip-712 0.1.0",
"ethash 1.12.0",
"ethcore 1.12.0",
"ethcore-io 1.12.0",

View File

@ -58,7 +58,7 @@ parity-updater = { path = "../updater" }
parity-version = { path = "../util/version" }
patricia-trie = "0.3.0"
rlp = { version = "0.3.0", features = ["ethereum"] }
eip712 = { path = "../util/EIP-712" }
eip-712 = { path = "../util/EIP-712" }
stats = { path = "../util/stats" }
vm = { path = "../ethcore/vm" }

View File

@ -62,7 +62,7 @@ extern crate parity_runtime;
extern crate parity_updater as updater;
extern crate parity_version as version;
extern crate patricia_trie as trie;
extern crate eip712;
extern crate eip_712;
extern crate rlp;
extern crate stats;
extern crate vm;

View File

@ -16,7 +16,7 @@
//! EIP-191 compliant decoding + hashing
use v1::types::{EIP191Version, Bytes, PresignedTransaction};
use eip712::{hash_structured_data, EIP712};
use eip_712::{hash_structured_data, EIP712};
use serde_json::{Value, from_value};
use v1::helpers::errors;
use jsonrpc_core::Error;

View File

@ -39,7 +39,7 @@ use v1::types::{
EIP191Version,
};
use v1::metadata::Metadata;
use eip712::{EIP712, hash_structured_data};
use eip_712::{EIP712, hash_structured_data};
use jsonrpc_core::types::Value;
/// Account management (personal) rpc implementation.

View File

@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Personal rpc interface.
use eip712::EIP712;
use eip_712::EIP712;
use jsonrpc_core::types::Value;
use jsonrpc_core::{BoxFuture, Result};
use v1::types::{Bytes, U128, H160, H256, H520, TransactionRequest, RichRawTransaction as RpcRichRawTransaction, EIP191Version};

View File

@ -1,7 +1,14 @@
[package]
name = "eip712"
name = "eip-712"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/parity-ethereum"
documentation = "https://docs.rs/eip-712"
readme = "README.md"
description = "eip-712 encoding"
keywords = ["eip-712", "eip712", "eip"]
license = "GPL-3.0"
edition = "2018"
[dependencies]
serde_derive = "1.0"

62
util/EIP-712/README.md Normal file
View File

@ -0,0 +1,62 @@
# EIP-712 ![Crates.io](https://img.shields.io/crates/d/EIP-712.svg) [![Released API docs](https://docs.rs/EIP-712/badge.svg)](https://docs.rs/EIP-712)
## Example
```rust
use eip_712::{EIP712, hash_structured_data};
use serde_json::from_str;
use rustc_hex::ToHex;
fn main() {
let json = r#"{
"primaryType": "Mail",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": "0x1",
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
"contents": "Hello, Bob!"
},
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"Person": [
{ "name": "name", "type": "string" },
{ "name": "wallet", "type": "address" }
],
"Mail": [
{ "name": "from", "type": "Person" },
{ "name": "to", "type": "Person" },
{ "name": "contents", "type": "string" }
]
}
}"#;
let typed_data = from_str::<EIP712>(json).unwrap();
assert_eq!(
hash_structured_data(typed_data).unwrap().to_hex::<String>(),
"be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2"
)
}
```
## License
This crate is distributed under the terms of GNU GENERAL PUBLIC LICENSE version 3.0.
See [LICENSE](../../LICENSE) for details.

View File

@ -21,6 +21,7 @@ use ethereum_types::{U256, H256, Address};
use regex::Regex;
use validator::Validate;
use validator::ValidationErrors;
use lazy_static::lazy_static;
pub(crate) type MessageTypes = HashMap<String, Vec<FieldType>>;

View File

@ -23,9 +23,9 @@ use std::str::FromStr;
use itertools::Itertools;
use indexmap::IndexSet;
use serde_json::to_value;
use parser::{Parser, Type};
use error::{Result, ErrorKind, serde_error};
use eip712::{EIP712, MessageTypes};
use crate::parser::{Parser, Type};
use crate::error::{Result, ErrorKind, serde_error};
use crate::eip712::{EIP712, MessageTypes};
use rustc_hex::FromHex;
use validator::Validate;
use std::collections::HashSet;
@ -162,7 +162,7 @@ fn encode_data(
check_hex(&string)?;
let mut bytes = (&string[2..])
let bytes = (&string[2..])
.from_hex::<Vec<u8>>()
.map_err(|err| ErrorKind::HexParseError(format!("{}", err)))?;

View File

@ -156,26 +156,13 @@
//! }
//! ```
#![warn(missing_docs, unused_extern_crates)]
#![warn(missing_docs)]
extern crate serde_json;
extern crate ethabi;
extern crate ethereum_types;
extern crate keccak_hash;
extern crate itertools;
extern crate failure;
extern crate indexmap;
extern crate lunarity_lexer;
extern crate toolshed;
extern crate regex;
extern crate validator;
#[macro_use]
extern crate validator_derive;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate lazy_static;
extern crate rustc_hex;
mod eip712;
mod error;
@ -183,8 +170,8 @@ mod parser;
mod encode;
/// the EIP-712 encoding function
pub use encode::hash_structured_data;
pub use crate::encode::hash_structured_data;
/// encoding Error types
pub use error::{ErrorKind, Error};
pub use crate::error::{ErrorKind, Error};
/// EIP712 struct
pub use eip712::EIP712;
pub use crate::eip712::EIP712;

View File

@ -16,7 +16,7 @@
//! Solidity type-name parsing
use lunarity_lexer::{Lexer, Token};
use error::*;
use crate::error::*;
use toolshed::Arena;
use std::{fmt, result};