Skip to content

Commit cb20590

Browse files
authored
feat: expand structured data hashing in line with SNIP-12 (#920)
* feat: expand structured data hashing in line with SNIP-12 * chore: reduce revision overlap * chore: allow hash method override for the Merkle tree class * chore: simplify enum and array handling
1 parent 418bc11 commit cb20590

14 files changed

+637
-224
lines changed
File renamed without changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"types": {
3+
"StarknetDomain": [
4+
{ "name": "name", "type": "shortstring" },
5+
{ "name": "version", "type": "shortstring" },
6+
{ "name": "chainId", "type": "shortstring" },
7+
{ "name": "revision", "type": "shortstring" }
8+
],
9+
"Example": [
10+
{ "name": "n0", "type": "felt" },
11+
{ "name": "n1", "type": "bool" },
12+
{ "name": "n2", "type": "string" },
13+
{ "name": "n3", "type": "selector" },
14+
{ "name": "n4", "type": "u128" },
15+
{ "name": "n5", "type": "ContractAddress" },
16+
{ "name": "n6", "type": "ClassHash" },
17+
{ "name": "n7", "type": "timestamp" },
18+
{ "name": "n8", "type": "shortstring" }
19+
]
20+
},
21+
"primaryType": "Example",
22+
"domain": {
23+
"name": "StarkNet Mail",
24+
"version": "1",
25+
"chainId": "1",
26+
"revision": "1"
27+
},
28+
"message": {
29+
"n0": "0x3e8",
30+
"n1": true,
31+
"n2": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
32+
"n3": "transfer",
33+
"n4": "0x3e8",
34+
"n5": "0x3e8",
35+
"n6": "0x3e8",
36+
"n7": 1000,
37+
"n8": "transfer"
38+
}
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"types": {
3+
"StarknetDomain": [
4+
{ "name": "name", "type": "shortstring" },
5+
{ "name": "version", "type": "shortstring" },
6+
{ "name": "chainId", "type": "shortstring" },
7+
{ "name": "revision", "type": "shortstring" }
8+
],
9+
"Example": [{ "name": "someEnum", "type": "enum", "contains": "MyEnum" }],
10+
"MyEnum": [
11+
{ "name": "Variant 1", "type": "()" },
12+
{ "name": "Variant 2", "type": "(u128,u128*)" },
13+
{ "name": "Variant 3", "type": "(u128)" }
14+
]
15+
},
16+
"primaryType": "Example",
17+
"domain": {
18+
"name": "StarkNet Mail",
19+
"version": "1",
20+
"chainId": "1",
21+
"revision": "1"
22+
},
23+
"message": {
24+
"someEnum": {
25+
"Variant 2": [2, [0, 1]]
26+
}
27+
}
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"types": {
3+
"StarknetDomain": [
4+
{ "name": "name", "type": "shortstring" },
5+
{ "name": "version", "type": "shortstring" },
6+
{ "name": "chainId", "type": "shortstring" },
7+
{ "name": "revision", "type": "shortstring" }
8+
],
9+
"Example": [
10+
{ "name": "n0", "type": "TokenAmount" },
11+
{ "name": "n1", "type": "NftId" }
12+
]
13+
},
14+
"primaryType": "Example",
15+
"domain": {
16+
"name": "StarkNet Mail",
17+
"version": "1",
18+
"chainId": "1",
19+
"revision": "1"
20+
},
21+
"message": {
22+
"n0": {
23+
"token_address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
24+
"amount": {
25+
"low": "0x3e8",
26+
"high": "0x0"
27+
}
28+
},
29+
"n1": {
30+
"collection_address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
31+
"token_id": {
32+
"low": "0x3e8",
33+
"high": "0x0"
34+
}
35+
}
36+
}
37+
}
File renamed without changes.
File renamed without changes.

__tests__/account.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import typedDataExample from '../__mocks__/typedDataExample.json';
1+
import typedDataExample from '../__mocks__/typedData/baseExample.json';
22
import {
33
Account,
44
Contract,

0 commit comments

Comments
 (0)