openethereum/util/EIP-712
Patrick Tescher 79aeb95272 Make EIP712Domain Fields Optional (#11103)
According to
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#definition-
of-domainseparator “Protocol designers only need to include the fields
that make sense for their signing domain.”
2019-10-03 22:20:20 +02:00
..
src Make EIP712Domain Fields Optional (#11103) 2019-10-03 22:20:20 +02:00
Cargo.toml EIP-712: bump version in prep for publishing (#11106) 2019-10-03 19:34:06 +02:00
README.md Move EIP-712 crate back to parity-ethereum (#10106) 2018-12-28 17:36:55 +08:00

EIP-712 Crates.io Released API docs

Example

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 for details.