1- from starknet_py .net .client_models import OutsideExecution
2-
31from starknet_py .constants import SNIP9InterfaceVersion
4-
2+ from starknet_py . net . client_models import OutsideExecution
53from starknet_py .net .schemas .common import Revision
64from starknet_py .utils import typed_data as td
75
108 SNIP9InterfaceVersion .V2 : Revision .V1 ,
119}
1210
11+
1312def outside_execution_to_typed_data (
1413 outside_execution : OutsideExecution ,
1514 snip9_version : SNIP9InterfaceVersion ,
16- chain_id : int
15+ chain_id : int ,
1716) -> td .TypedData :
1817 """
1918 SNIP-12 Typed Data for OutsideExecution implementation. For revision V0 and V1.
@@ -22,92 +21,98 @@ def outside_execution_to_typed_data(
2221 revision = SNIP9_INTERFACE_ID_TO_SNIP12_REVISION [snip9_version ]
2322
2423 if revision == Revision .V0 :
25- return td .TypedData .from_dict ({
26- 'types' : {
27- 'StarkNetDomain' : [
28- {'name' : 'name' , 'type' : 'felt' },
29- {'name' : 'version' , 'type' : 'felt' },
30- {'name' : 'chainId' , 'type' : 'felt' },
24+ return td .TypedData .from_dict (
25+ {
26+ "types" : {
27+ "StarkNetDomain" : [
28+ {"name" : "name" , "type" : "felt" },
29+ {"name" : "version" , "type" : "felt" },
30+ {"name" : "chainId" , "type" : "felt" },
31+ ],
32+ "OutsideExecution" : [
33+ {"name" : "caller" , "type" : "felt" },
34+ {"name" : "nonce" , "type" : "felt" },
35+ {"name" : "execute_after" , "type" : "felt" },
36+ {"name" : "execute_before" , "type" : "felt" },
37+ {"name" : "calls_len" , "type" : "felt" },
38+ {"name" : "calls" , "type" : "OutsideCall*" },
39+ ],
40+ "OutsideCall" : [
41+ {"name" : "to" , "type" : "felt" },
42+ {"name" : "selector" , "type" : "felt" },
43+ {"name" : "calldata_len" , "type" : "felt" },
44+ {"name" : "calldata" , "type" : "felt*" },
45+ ],
46+ },
47+ "primaryType" : "OutsideExecution" ,
48+ "domain" : {
49+ "name" : "Account.execute_from_outside" ,
50+ "version" : "1" ,
51+ "chainId" : str (chain_id ),
52+ "revision" : Revision .V0 ,
53+ },
54+ "message" : {
55+ "caller" : outside_execution .caller ,
56+ "nonce" : outside_execution .nonce ,
57+ "execute_after" : outside_execution .execute_after ,
58+ "execute_before" : outside_execution .execute_before ,
59+ "calls_len" : len (outside_execution .calls ),
60+ "calls" : [
61+ {
62+ "to" : call .to_addr ,
63+ "selector" : call .selector ,
64+ "calldata_len" : len (call .calldata ),
65+ "calldata" : call .calldata ,
66+ }
67+ for call in outside_execution .calls
68+ ],
69+ },
70+ }
71+ )
72+
73+ # revision == Revision.V1
74+ return td .TypedData .from_dict (
75+ {
76+ "types" : {
77+ "StarknetDomain" : [
78+ {"name" : "name" , "type" : "shortstring" },
79+ {"name" : "version" , "type" : "shortstring" },
80+ {"name" : "chainId" , "type" : "shortstring" },
81+ {"name" : "revision" , "type" : "shortstring" },
3182 ],
32- 'OutsideExecution' : [
33- {'name' : 'caller' , 'type' : 'felt' },
34- {'name' : 'nonce' , 'type' : 'felt' },
35- {'name' : 'execute_after' , 'type' : 'felt' },
36- {'name' : 'execute_before' , 'type' : 'felt' },
37- {'name' : 'calls_len' , 'type' : 'felt' },
38- {'name' : 'calls' , 'type' : 'OutsideCall*' },
83+ "OutsideExecution" : [
84+ {"name" : "Caller" , "type" : "ContractAddress" },
85+ {"name" : "Nonce" , "type" : "felt" },
86+ {"name" : "Execute After" , "type" : "u128" },
87+ {"name" : "Execute Before" , "type" : "u128" },
88+ {"name" : "Calls" , "type" : "Call*" },
3989 ],
40- 'OutsideCall' : [
41- { 'name' : 'to' , 'type' : 'felt' },
42- { 'name' : 'selector' , 'type' : 'felt' },
43- { 'name' : 'calldata_len' , 'type' : 'felt' },
44- { 'name' : 'calldata' , 'type' : 'felt*' },
90+ "Call" : [
91+ {"name" : "To" , "type" : "ContractAddress" },
92+ {"name" : "Selector" , "type" : "selector" },
93+ {"name" : "Calldata" , "type" : "felt*" },
4594 ],
4695 },
47- ' primaryType' : ' OutsideExecution' ,
48- ' domain' : {
49- ' name' : ' Account.execute_from_outside' ,
50- ' version' : '1' ,
51- ' chainId' : str (chain_id ),
52- ' revision' : Revision .V0 ,
96+ " primaryType" : " OutsideExecution" ,
97+ " domain" : {
98+ " name" : " Account.execute_from_outside" ,
99+ " version" : "2" ,
100+ " chainId" : str (chain_id ),
101+ " revision" : Revision .V1 ,
53102 },
54- 'message' : {
55- 'caller' : outside_execution .caller ,
56- 'nonce' : outside_execution .nonce ,
57- 'execute_after' : outside_execution .execute_after ,
58- 'execute_before' : outside_execution .execute_before ,
59- 'calls_len' : len (outside_execution .calls ),
60- 'calls' : [
103+ "message" : {
104+ "Caller" : outside_execution .caller ,
105+ "Nonce" : outside_execution .nonce ,
106+ "Execute After" : outside_execution .execute_after ,
107+ "Execute Before" : outside_execution .execute_before ,
108+ "Calls" : [
61109 {
62- 'to' : call .to_addr ,
63- 'selector' : call .selector ,
64- 'calldata_len' : len ( call .calldata ) ,
65- 'calldata' : call . calldata ,
66- } for call in outside_execution .calls
110+ "To" : call .to_addr ,
111+ "Selector" : call .selector ,
112+ "Calldata" : call .calldata ,
113+ }
114+ for call in outside_execution .calls
67115 ],
68116 },
69- })
70-
71- # revision == Revision.V1
72- return td .TypedData .from_dict ({
73- 'types' : {
74- 'StarknetDomain' : [
75- {'name' : 'name' , 'type' : 'shortstring' },
76- {'name' : 'version' , 'type' : 'shortstring' },
77- {'name' : 'chainId' , 'type' : 'shortstring' },
78- {'name' : 'revision' , 'type' : 'shortstring' },
79- ],
80- 'OutsideExecution' : [
81- {'name' : 'Caller' , 'type' : 'ContractAddress' },
82- {'name' : 'Nonce' , 'type' : 'felt' },
83- {'name' : 'Execute After' , 'type' : 'u128' },
84- {'name' : 'Execute Before' , 'type' : 'u128' },
85- {'name' : 'Calls' , 'type' : 'Call*' },
86- ],
87- 'Call' : [
88- { 'name' : 'To' , 'type' : 'ContractAddress' },
89- { 'name' : 'Selector' , 'type' : 'selector' },
90- { 'name' : 'Calldata' , 'type' : 'felt*' },
91- ],
92- },
93- 'primaryType' : 'OutsideExecution' ,
94- 'domain' : {
95- 'name' : 'Account.execute_from_outside' ,
96- 'version' : '2' ,
97- 'chainId' : str (chain_id ),
98- 'revision' : Revision .V1 ,
99- },
100- 'message' : {
101- 'Caller' : outside_execution .caller ,
102- 'Nonce' : outside_execution .nonce ,
103- 'Execute After' : outside_execution .execute_after ,
104- 'Execute Before' : outside_execution .execute_before ,
105- 'Calls' : [
106- {
107- 'To' : call .to_addr ,
108- 'Selector' : call .selector ,
109- 'Calldata' : call .calldata ,
110- } for call in outside_execution .calls
111- ],
112- },
113- })
117+ }
118+ )
0 commit comments