-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: snip-12 typed data parsing and hashing
- Loading branch information
1 parent
de3fec7
commit 73cdb6b
Showing
16 changed files
with
3,046 additions
and
18 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
use starknet::{core::types::TypedData, macros::felt}; | ||
|
||
fn main() { | ||
let raw = r#"{ | ||
"types": { | ||
"StarknetDomain": [ | ||
{ "name": "name", "type": "shortstring" }, | ||
{ "name": "version", "type": "shortstring" }, | ||
{ "name": "chainId", "type": "shortstring" }, | ||
{ "name": "revision", "type": "shortstring" } | ||
], | ||
"Example Message": [ | ||
{ "name": "Name", "type": "string" }, | ||
{ "name": "Some Array", "type": "u128*" }, | ||
{ "name": "Some Object", "type": "My Object" } | ||
], | ||
"My Object": [ | ||
{ "name": "Some Selector", "type": "selector" }, | ||
{ "name": "Some Contract Address", "type": "ContractAddress" } | ||
] | ||
}, | ||
"primaryType": "Example Message", | ||
"domain": { | ||
"name": "Starknet Example", | ||
"version": "1", | ||
"chainId": "SN_MAIN", | ||
"revision": "1" | ||
}, | ||
"message": { | ||
"Name": "some name", | ||
"Some Array": [1, 2, 3, 4], | ||
"Some Object": { | ||
"Some Selector": "transfer", | ||
"Some Contract Address": "0x0123" | ||
} | ||
} | ||
}"#; | ||
|
||
let typed_data = serde_json::from_str::<TypedData>(raw).unwrap(); | ||
println!("SNIP-12 revision: {}", typed_data.revision()); | ||
|
||
let message_hash = typed_data.message_hash(felt!("0x1234")).unwrap(); | ||
println!("SNIP-12 hash: {:#064x}", message_hash); | ||
} |
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
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
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
Oops, something went wrong.