1- import { getMessageHash , getStructHash } from '../../src/utils/typedData' ;
1+ import { encodeType , getMessageHash , getStructHash , getTypeHash } from '../../src/utils/typedData' ;
22
33const typedDataExample = {
44 types : {
@@ -19,7 +19,7 @@ const typedDataExample = {
1919 } ,
2020 primaryType : 'Mail' ,
2121 domain : {
22- name : 'Ether Mail' ,
22+ name : 'StarkNet Mail' ,
2323 version : '1' ,
2424 chainId : 1 ,
2525 } ,
@@ -37,16 +37,36 @@ const typedDataExample = {
3737} ;
3838
3939describe ( 'typedData' , ( ) => {
40+ test ( 'should get right type encoding' , ( ) => {
41+ const typeEncoding = encodeType ( typedDataExample , 'Mail' ) ;
42+ expect ( typeEncoding ) . toMatchInlineSnapshot (
43+ `"Mail(from:Person,to:Person,contents:felt)Person(name:felt,wallet:felt)"`
44+ ) ;
45+ } ) ;
46+ test ( 'should get right type hash' , ( ) => {
47+ const typeHashDomain = getTypeHash ( typedDataExample , 'StarkNetDomain' ) ;
48+ expect ( typeHashDomain ) . toMatchInlineSnapshot (
49+ `"0x1bfc207425a47a5dfa1a50a4f5241203f50624ca5fdf5e18755765416b8e288"`
50+ ) ;
51+ const typeHashPerson = getTypeHash ( typedDataExample , 'Person' ) ;
52+ expect ( typeHashPerson ) . toMatchInlineSnapshot (
53+ `"0x2896dbe4b96a67110f454c01e5336edc5bbc3635537efd690f122f4809cc855"`
54+ ) ;
55+ const typeHashMail = getTypeHash ( typedDataExample , 'Mail' ) ;
56+ expect ( typeHashMail ) . toMatchInlineSnapshot (
57+ `"0x13d89452df9512bf750f539ba3001b945576243288137ddb6c788457d4b2f79"`
58+ ) ;
59+ } ) ;
4060 test ( 'should get right hash for StarkNetDomain' , ( ) => {
4161 const hash = getStructHash ( typedDataExample , 'StarkNetDomain' , typedDataExample . domain as any ) ;
4262 expect ( hash ) . toMatchInlineSnapshot (
43- `"0x3a53775bb506be3f4f84619cd2d063a9408ba2b2e7fe134b82b04a62783eef9 "`
63+ `"0x54833b121883a3e3aebff48ec08a962f5742e5f7b973469c1f8f4f55d470b07 "`
4464 ) ;
4565 } ) ;
4666 test ( 'should get right hash for entire message' , ( ) => {
4767 const hash = getMessageHash ( typedDataExample , '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' ) ;
4868 expect ( hash ) . toMatchInlineSnapshot (
49- `"0x214aad847084997443f3bace488411e46dfff96dce13f0356107d0fc12b1219 "`
69+ `"0x6fcff244f63e38b9d88b9e3378d44757710d1b244282b435cb472053c8d78d0 "`
5070 ) ;
5171 } ) ;
5272} ) ;
0 commit comments