@@ -22,105 +22,174 @@ export const AddChainRequestParams = z.object({
22
22
name : z . string ( ) ,
23
23
} ) ;
24
24
25
- export const AccountsRequestSchema = z
26
- . function ( )
27
- . args ( z . object ( { method : z . literal ( "mina_accounts" ) } ) )
28
- . returns ( z . promise ( z . array ( PublicKeySchema ) ) ) ;
29
- export const ChainIdRequestSchema = z
30
- . function ( )
31
- . args ( z . object ( { method : z . literal ( "mina_chainId" ) } ) )
32
- . returns ( z . promise ( z . string ( ) ) ) ;
33
- export const ChainInformationRequestSchema = z
34
- . function ( )
35
- . args ( z . object ( { method : z . literal ( "mina_chainInformation" ) } ) )
36
- . returns ( z . promise ( z . object ( { url : z . string ( ) , name : z . string ( ) } ) ) ) ;
37
- export const GetBalanceRequestSchema = z
38
- . function ( )
39
- . args ( z . object ( { method : z . literal ( "mina_getBalance" ) } ) )
40
- . returns ( z . promise ( z . number ( ) ) ) ;
41
- export const SignRequestSchema = z
42
- . function ( )
43
- . args (
44
- z . object ( {
45
- method : z . literal ( "mina_sign" ) ,
46
- params : SignMessageParamsSchema ,
47
- } ) ,
48
- )
49
- . returns ( z . promise ( SignedMessageSchema ) ) ;
50
- export const SignFieldsRequestSchema = z
51
- . function ( )
52
- . args (
53
- z . object ( {
54
- method : z . literal ( "mina_signFields" ) ,
55
- params : SignFieldsParamsSchema ,
56
- } ) ,
57
- )
58
- . returns ( z . promise ( SignedFieldsSchema ) ) ;
59
- export const SignTransactionRequestSchema = z
60
- . function ( )
61
- . args (
62
- z . object ( {
63
- method : z . literal ( "mina_signTransaction" ) ,
64
- params : SignTransactionParamsSchema ,
65
- } ) ,
66
- )
67
- . returns ( z . promise ( SignedTransactionSchema ) ) ;
68
- export const SendTransactionRequestSchema = z
69
- . function ( )
70
- . args (
71
- z . object ( {
72
- method : z . literal ( "mina_sendTransaction" ) ,
73
- params : SendTransactionParamsSchema ,
74
- } ) ,
75
- )
76
- . returns ( z . promise ( TransactionReceiptSchema ) ) ;
77
- export const CreateNullifierRequestSchema = z
78
- . function ( )
79
- . args (
80
- z . object ( {
81
- method : z . literal ( "mina_createNullifier" ) ,
82
- params : CreateNullifierParamsSchema ,
83
- } ) ,
84
- )
85
- . returns ( z . promise ( NullifierSchema ) ) ;
86
- export const SwitchChainRequestSchema = z
87
- . function ( )
88
- . args (
89
- z . object ( {
90
- method : z . literal ( "mina_switchChain" ) ,
91
- params : SwitchChainRequestParams ,
92
- } ) ,
93
- )
94
- . returns ( z . promise ( z . string ( ) ) ) ;
95
- export const AddChainRequestSchema = z
96
- . function ( )
97
- . args (
98
- z . object ( {
99
- method : z . literal ( "mina_addChain" ) ,
100
- params : AddChainRequestParams ,
101
- } ) ,
102
- )
103
- . returns ( z . promise ( z . string ( ) ) ) ;
25
+ // Params
26
+ export const AccountsRequestParamsSchema = z
27
+ . object ( { method : z . literal ( "mina_accounts" ) } )
28
+ . strict ( ) ;
29
+ export const ChainIdRequestParamsSchema = z
30
+ . object ( { method : z . literal ( "mina_chainId" ) } )
31
+ . strict ( ) ;
32
+ export const ChainInformationRequestParamsSchema = z
33
+ . object ( { method : z . literal ( "mina_chainInformation" ) } )
34
+ . strict ( ) ;
35
+ export const GetBalanceRequestParamsSchema = z
36
+ . object ( { method : z . literal ( "mina_getBalance" ) } )
37
+ . strict ( ) ;
38
+ export const SignRequestParamsSchema = z
39
+ . object ( {
40
+ method : z . literal ( "mina_sign" ) ,
41
+ params : SignMessageParamsSchema ,
42
+ } )
43
+ . strict ( ) ;
44
+ export const SignFieldsRequestParamsSchema = z
45
+ . object ( {
46
+ method : z . literal ( "mina_signFields" ) ,
47
+ params : SignFieldsParamsSchema ,
48
+ } )
49
+ . strict ( ) ;
50
+ export const SignTransactionRequestParamsSchema = z
51
+ . object ( {
52
+ method : z . literal ( "mina_signTransaction" ) ,
53
+ params : SignTransactionParamsSchema ,
54
+ } )
55
+ . strict ( ) ;
56
+ export const SendTransactionRequestParamsSchema = z
57
+ . object ( {
58
+ method : z . literal ( "mina_sendTransaction" ) ,
59
+ params : SendTransactionParamsSchema ,
60
+ } )
61
+ . strict ( ) ;
62
+ export const CreateNullifierRequestParamsSchema = z
63
+ . object ( {
64
+ method : z . literal ( "mina_createNullifier" ) ,
65
+ params : CreateNullifierParamsSchema ,
66
+ } )
67
+ . strict ( ) ;
68
+ export const SwitchChainRequestParamsSchema = z . object ( {
69
+ method : z . literal ( "mina_switchChain" ) ,
70
+ params : SwitchChainRequestParams ,
71
+ } ) ;
72
+ export const AddChainRequestParamsSchema = z
73
+ . object ( {
74
+ method : z . literal ( "mina_addChain" ) ,
75
+ params : AddChainRequestParams ,
76
+ } )
77
+ . strict ( ) ;
104
78
105
- export const ProviderRequestSchema = z . union ( [
106
- AccountsRequestSchema ,
107
- ChainIdRequestSchema ,
108
- ChainInformationRequestSchema ,
109
- GetBalanceRequestSchema ,
110
- SignRequestSchema ,
111
- SignFieldsRequestSchema ,
112
- SignTransactionRequestSchema ,
113
- SendTransactionRequestSchema ,
114
- CreateNullifierRequestSchema ,
115
- SwitchChainRequestSchema ,
116
- AddChainRequestSchema ,
79
+ // Returns
80
+ export const AccountsRequestReturnSchema = z
81
+ . object ( {
82
+ method : z . literal ( "mina_accounts" ) ,
83
+ result : z . array ( PublicKeySchema ) ,
84
+ } )
85
+ . strict ( ) ;
86
+ export const ChainIdRequestReturnSchema = z
87
+ . object ( {
88
+ method : z . literal ( "mina_chainId" ) ,
89
+ result : z . string ( ) ,
90
+ } )
91
+ . strict ( ) ;
92
+ export const ChainInformationRequestReturnSchema = z
93
+ . object ( {
94
+ method : z . literal ( "mina_chainInformation" ) ,
95
+ result : z . object ( { url : z . string ( ) , name : z . string ( ) } ) . strict ( ) ,
96
+ } )
97
+ . strict ( ) ;
98
+ export const GetBalanceRequestReturnSchema = z
99
+ . object ( {
100
+ method : z . literal ( "mina_getBalance" ) ,
101
+ result : z . number ( ) ,
102
+ } )
103
+ . strict ( ) ;
104
+ export const SignRequestReturnSchema = z
105
+ . object ( {
106
+ method : z . literal ( "mina_sign" ) ,
107
+ result : SignedMessageSchema ,
108
+ } )
109
+ . strict ( ) ;
110
+ export const SignFieldsRequestReturnSchema = z
111
+ . object ( {
112
+ method : z . literal ( "mina_signFields" ) ,
113
+ result : SignedFieldsSchema ,
114
+ } )
115
+ . strict ( ) ;
116
+ export const SignTransactionRequestReturnSchema = z
117
+ . object ( {
118
+ method : z . literal ( "mina_signTransaction" ) ,
119
+ result : SignedTransactionSchema ,
120
+ } )
121
+ . strict ( ) ;
122
+ export const SendTransactionRequestReturnSchema = z
123
+ . object ( {
124
+ method : z . literal ( "mina_sendTransaction" ) ,
125
+ result : TransactionReceiptSchema ,
126
+ } )
127
+ . strict ( ) ;
128
+ export const CreateNullifierRequestReturnSchema = z
129
+ . object ( {
130
+ method : z . literal ( "mina_createNullifier" ) ,
131
+ result : NullifierSchema ,
132
+ } )
133
+ . strict ( ) ;
134
+ export const SwitchChainRequestReturnSchema = z
135
+ . object ( {
136
+ method : z . literal ( "mina_switchChain" ) ,
137
+ result : z . string ( ) ,
138
+ } )
139
+ . strict ( ) ;
140
+ export const AddChainRequestReturnSchema = z
141
+ . object ( {
142
+ method : z . literal ( "mina_addChain" ) ,
143
+ result : z . string ( ) ,
144
+ } )
145
+ . strict ( ) ;
146
+
147
+ export const RpcReturnTypes = z . discriminatedUnion ( "method" , [
148
+ AccountsRequestReturnSchema ,
149
+ ChainIdRequestReturnSchema ,
150
+ ChainInformationRequestReturnSchema ,
151
+ GetBalanceRequestReturnSchema ,
152
+ SignRequestReturnSchema ,
153
+ SignFieldsRequestReturnSchema ,
154
+ SignTransactionRequestReturnSchema ,
155
+ SendTransactionRequestReturnSchema ,
156
+ CreateNullifierRequestReturnSchema ,
157
+ SwitchChainRequestReturnSchema ,
158
+ AddChainRequestReturnSchema ,
117
159
] ) ;
118
160
161
+ export const ProviderRequestParamsSchema = z . discriminatedUnion ( "method" , [
162
+ AccountsRequestParamsSchema ,
163
+ ChainIdRequestParamsSchema ,
164
+ ChainInformationRequestParamsSchema ,
165
+ GetBalanceRequestParamsSchema ,
166
+ SignRequestParamsSchema ,
167
+ SignFieldsRequestParamsSchema ,
168
+ SignTransactionRequestParamsSchema ,
169
+ SendTransactionRequestParamsSchema ,
170
+ CreateNullifierRequestParamsSchema ,
171
+ SwitchChainRequestParamsSchema ,
172
+ AddChainRequestParamsSchema ,
173
+ ] ) ;
174
+ export const ResultSchema = z . object ( {
175
+ jsonrpc : z . literal ( "2.0" ) ,
176
+ result : z . promise ( RpcReturnTypes ) ,
177
+ } ) ;
178
+ export type ResultType < M extends string > = {
179
+ jsonrpc : "2.0" ;
180
+ result : Extract < M , z . infer < typeof RpcReturnTypes > > ;
181
+ } ;
182
+ export const ProviderRequestSchema = z
183
+ . function ( )
184
+ . args ( ProviderRequestParamsSchema )
185
+ . returns ( z . promise ( ResultSchema ) ) ;
186
+
119
187
export const ChainIdCallbackSchema = z
120
188
. function ( )
121
189
. args ( z . object ( { chainId : z . string ( ) } ) )
122
190
. returns ( z . void ( ) ) ;
123
191
192
+ // TODO: Add missing deconstruction types to listeners
124
193
export const ConnectedListenerSchema = z
125
194
. function ( )
126
195
. args ( z . literal ( "connected" ) , ChainIdCallbackSchema )
@@ -151,26 +220,36 @@ export const ProviderListenerSchema = z.union([
151
220
] ) ;
152
221
153
222
export const ProviderRpcErrorSchema = z . discriminatedUnion ( "code" , [
154
- z . object ( {
155
- code : z . literal ( 4001 ) ,
156
- message : z . literal ( "User Rejected Request" ) ,
157
- } ) ,
158
- z . object ( {
159
- code : z . literal ( 4100 ) ,
160
- message : z . literal ( "Unauthorized" ) ,
161
- } ) ,
162
- z . object ( {
163
- code : z . literal ( 4200 ) ,
164
- message : z . literal ( "Unsupported Method" ) ,
165
- } ) ,
166
- z . object ( {
167
- code : z . literal ( 4900 ) ,
168
- message : z . literal ( "Disconnected" ) ,
169
- } ) ,
170
- z . object ( {
171
- code : z . literal ( 4901 ) ,
172
- message : z . literal ( "Chain Disconnected" ) ,
173
- } ) ,
223
+ z
224
+ . object ( {
225
+ code : z . literal ( 4001 ) ,
226
+ message : z . literal ( "User Rejected Request" ) ,
227
+ } )
228
+ . strict ( ) ,
229
+ z
230
+ . object ( {
231
+ code : z . literal ( 4100 ) ,
232
+ message : z . literal ( "Unauthorized" ) ,
233
+ } )
234
+ . strict ( ) ,
235
+ z
236
+ . object ( {
237
+ code : z . literal ( 4200 ) ,
238
+ message : z . literal ( "Unsupported Method" ) ,
239
+ } )
240
+ . strict ( ) ,
241
+ z
242
+ . object ( {
243
+ code : z . literal ( 4900 ) ,
244
+ message : z . literal ( "Disconnected" ) ,
245
+ } )
246
+ . strict ( ) ,
247
+ z
248
+ . object ( {
249
+ code : z . literal ( 4901 ) ,
250
+ message : z . literal ( "Chain Disconnected" ) ,
251
+ } )
252
+ . strict ( ) ,
174
253
] ) ;
175
254
176
255
export const MinaProviderInfoSchema = z . object ( {
@@ -186,7 +265,9 @@ export const MinaProviderClientSchema = z.object({
186
265
removeListener : ProviderListenerSchema ,
187
266
} ) ;
188
267
189
- export const MinaProviderDetailSchema = z . object ( {
190
- info : MinaProviderInfoSchema ,
191
- provider : MinaProviderClientSchema ,
192
- } ) ;
268
+ export const MinaProviderDetailSchema = z
269
+ . object ( {
270
+ info : MinaProviderInfoSchema ,
271
+ provider : MinaProviderClientSchema ,
272
+ } )
273
+ . strict ( ) ;
0 commit comments