3 个版本

0.1.2 2024年5月24日
0.1.1 2024年5月21日
0.1.0 2024年5月21日

#3 in #eip-712

Download history 416/week @ 2024-05-21 2/week @ 2024-05-28 12/week @ 2024-06-04 5/week @ 2024-06-11

106 每月下载

GPL-3.0 许可证

50KB
1K SLoC

EIP-712 Crates.io 发布 API 文档

https://github.com/openethereum/parity-ethereum/tree/v2.7.2-stable/util/EIP-712 分支

示例

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"
	)
}

许可证

本软件包在 GNU 通用公共许可证版本 3.0 的条款下分发。

有关详细信息,请参阅 LICENSE

依赖关系

~12MB
~223K SLoC