Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Move EIP-712 crate back to parity-ethereum (#10106)
Browse files Browse the repository at this point in the history
* move eip-712 crate back to parity-ethereum

* changed license, updated documentation url
  • Loading branch information
seunlanlege authored and sorpaas committed Dec 28, 2018
1 parent ff0095a commit 912e559
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
2 changes: 1 addition & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/helpers/eip191.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/traits/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 8 additions & 1 deletion util/EIP-712/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[package]
name = "eip712"
name = "eip-712"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
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"
Expand Down
62 changes: 62 additions & 0 deletions util/EIP-712/README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions util/EIP-712/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>;

Expand Down
8 changes: 4 additions & 4 deletions util/EIP-712/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))?;

Expand Down
23 changes: 5 additions & 18 deletions util/EIP-712/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,22 @@
//! }
//! ```
#![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;
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;
2 changes: 1 addition & 1 deletion util/EIP-712/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 912e559

Please sign in to comment.