@proton/wrap-constants 0.0.31 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/parsers.ts DELETED
@@ -1,334 +0,0 @@
1
- import * as z from 'zod'
2
- import { WRAP_CONTRACT, WRAP_AUTH_ACTION } from './constants'
3
-
4
- export enum Status {
5
- PENDING = 'pending',
6
- SUCCESS = 'success',
7
- FAIL = 'fail',
8
- PROCESSING = 'processing'
9
- }
10
-
11
- export enum Type {
12
- RECEIVE = 'receive',
13
- SEND = 'send'
14
- }
15
-
16
- export const accountParser = z.string().regex(/^[.1-5a-z]{0,12}[.1-5a-j]?$/)
17
-
18
- export const authorizationParser = z.object({
19
- actor : accountParser,
20
- permission: z.string()
21
- })
22
- export type Authorization = z.infer<typeof authorizationParser>
23
-
24
- export const authorizationsParser = z.array(authorizationParser).min(1)
25
- export type Authorizations = z.infer<typeof authorizationsParser>
26
-
27
- export const rawTransactionParser = z.object({
28
- expiration : z.string(),
29
- ref_block_num : z.number(),
30
- ref_block_prefix : z.number(),
31
- max_net_usage_words : z.number(),
32
- max_cpu_usage_ms : z.number(),
33
- delay_sec : z.number(),
34
- context_free_actions : z.array(z.any()),
35
- transaction_extensions: z.array(z.any())
36
- })
37
-
38
- const generateAuthActionsBaseParser = z.object({
39
- account: z.literal(WRAP_CONTRACT),
40
- name: z.literal(WRAP_AUTH_ACTION),
41
- data: z.object({
42
- time: z.string(),
43
- protonAccount: z.string()
44
- }),
45
- authorization: authorizationsParser
46
- })
47
- export type GenerateAuthBaseAction = z.infer<typeof generateAuthActionsBaseParser>
48
-
49
- const generateAuthActionsWebAuthParser = z.object({
50
- account: z.literal('webauthn'),
51
- name: z.literal('exec'),
52
- authorization: authorizationsParser,
53
- data: z.object({
54
- account: accountParser,
55
- key: z.object({
56
- key: z.array(z.string().or(z.object({
57
- modulus: z.string(),
58
- exponent: z.string()
59
- }))),
60
- user_presence: z.number(),
61
- rpid: z.string()
62
- }),
63
- nonce: z.number(),
64
- permissions: authorizationsParser,
65
- signature: z.object({
66
- auth_data: z.string(),
67
- client_json: z.string(),
68
- signature: z.string()
69
- }),
70
- trx: rawTransactionParser.merge(z.object({
71
- actions: z.array(
72
- z.object({
73
- account: z.literal(WRAP_CONTRACT),
74
- name: z.literal(WRAP_AUTH_ACTION),
75
- data: z.string().or(z.object({
76
- time: z.string(),
77
- protonAccount: z.string()
78
- })),
79
- authorization: authorizationsParser
80
- })
81
- ).length(1)
82
- }))
83
- })
84
- })
85
-
86
- export const generateAuthParser = z.object({
87
- signer : authorizationParser,
88
- signatures : z.array(z.string()).length(1),
89
- transaction: rawTransactionParser.merge(z.object({
90
- actions: z.array(generateAuthActionsBaseParser.or(generateAuthActionsWebAuthParser)).length(1)
91
- }))
92
- })
93
- export type GenerateAuth = z.infer<typeof generateAuthParser>
94
-
95
- export const generateAddressBodyParser = z.object({
96
- coin: z.string(),
97
- wallet: z.string(),
98
- }).merge(generateAuthParser)
99
- export type GenerateAddressBody = z.infer<typeof generateAddressBodyParser>
100
-
101
- export const generateAddressResponse = z.object({
102
- id : z.string(), // "2448834505708930950",
103
- address: z.string(), // "0x617C03C1E2Bf81C062A4CEfbE312c070E1d86d18",
104
- coin : z.string(), // "ETH",
105
- wallet : z.string(), // "ETH",
106
- memo : z.string().optional()
107
- })
108
- export type GenerateAddressResponse = z.infer<typeof generateAddressResponse>
109
-
110
- export const depositBodyParser = z.object({
111
- id : z.string(), // "0x000010203121388fac991"
112
- type : z.nativeEnum(Type), // "receive" or "send"
113
- hash : z.string(), // "0x000010203121388fac991"
114
- coin : z.string(), // "ETH" or "XPR"
115
- wallet : z.string(), // "ETH-ROPSTEN" or "XPR-MAINNET"
116
- })
117
- export type DepositBody = z.infer<typeof depositBodyParser>
118
-
119
- const withdrawBodyBaseAction = z.object({
120
- account: accountParser,
121
- name: z.literal('transfer'),
122
- data: z.object({
123
- from: z.string().refine((val) => val !== WRAP_CONTRACT, {
124
- message: `${WRAP_CONTRACT} must be receiver`,
125
- }),
126
- to: z.literal(WRAP_CONTRACT),
127
- quantity: z.string(),
128
- memo: z.string()
129
- }),
130
- authorization: authorizationsParser
131
- })
132
- export type WithdrawBodyBaseAction = z.infer<typeof withdrawBodyBaseAction>
133
-
134
- const withdrawBodyWebAuthAction = z.object({
135
- account: z.literal('webauthn'),
136
- name: z.literal('exec'),
137
- authorization: authorizationsParser,
138
- data: z.object({
139
- account: accountParser,
140
- key: z.object({
141
- key: z.array(z.string().or(z.object({
142
- modulus: z.string(),
143
- exponent: z.string()
144
- }))),
145
- user_presence: z.number(),
146
- rpid: z.string()
147
- }),
148
- nonce: z.number(),
149
- permissions: authorizationsParser,
150
- signature: z.object({
151
- auth_data: z.string(),
152
- client_json: z.string(),
153
- signature: z.string()
154
- }),
155
- trx: rawTransactionParser.merge(z.object({
156
- actions: z.array(
157
- z.object({
158
- account: accountParser,
159
- name: z.literal('transfer'),
160
- data: z.string().or(z.object({
161
- from: z.string().refine((val) => val !== WRAP_CONTRACT, {
162
- message: `${WRAP_CONTRACT} must be receiver`,
163
- }),
164
- to: z.literal(WRAP_CONTRACT),
165
- quantity: z.string(),
166
- memo: z.string()
167
- })),
168
- authorization: authorizationsParser
169
- })
170
- ).length(1)
171
- }))
172
- })
173
- })
174
-
175
- export const withdrawBodyParser = z.object({
176
- signer : authorizationParser,
177
- signatures : z.array(z.string()).length(1),
178
- transaction: rawTransactionParser.merge(z.object({
179
- actions: z.array(withdrawBodyBaseAction.or(withdrawBodyWebAuthAction)).length(1)
180
- })),
181
- quoteId: z.string(),
182
- provider: z.string().optional()
183
- })
184
- export type WithdrawBody = z.infer<typeof withdrawBodyParser>
185
-
186
- export const withdrawMetalResponseParser = z.object({
187
- success: z.boolean(),
188
- id : z.string(),
189
- })
190
- export type WithdrawMetalResponse = z.infer<typeof withdrawMetalResponseParser>
191
-
192
- export const withdrawHistoryMetalSwapParser = z.object({
193
- id : z.string(),
194
- status : z.string(),
195
- amount : z.string(),
196
- currency : z.string(),
197
- network : z.string(),
198
- created : z.string(),
199
- withdrawalAddress: z.string(),
200
- withdrawalHash : z.string().optional()
201
- })
202
- export type WithdrawHistoryMetalSwap = z.infer<typeof withdrawHistoryMetalSwapParser>
203
-
204
- export const withdrawHistoryMetalResponseParser = z.object({
205
- swaps : z.array(withdrawHistoryMetalSwapParser),
206
- page : z.number(),
207
- pageSize : z.number(),
208
- numberOfElements: z.number(),
209
- totalPages : z.number(),
210
- totalElements : z.number()
211
- })
212
- export type WithdrawHistoryMetalResponse = z.infer<typeof withdrawHistoryMetalResponseParser>
213
-
214
- const ExtendedAssetParser = z.object({
215
- quantity: z.string(),
216
- contract: accountParser
217
- })
218
- export type ExtendedAsset = z.infer<typeof ExtendedAssetParser>
219
-
220
- export const wrapStartParser = z.object({
221
- balance : ExtendedAssetParser,
222
- id : z.string(),
223
- txid : z.string(),
224
- chain : z.string(),
225
- deposit_address: z.string(),
226
- confirmations : z.number()
227
- })
228
-
229
- export type WrapStart = z.infer<typeof wrapStartParser>
230
-
231
- export const wrapSetConfParser = z.object({
232
- wrap_hash : z.string(),
233
- confirmations: z.number()
234
- })
235
- export type WrapSetConf = z.infer<typeof wrapSetConfParser>
236
-
237
- export const wrapParser = z.object({
238
- index : z.number(),
239
- proton_account : z.string(),
240
- balance : ExtendedAssetParser,
241
- id : z.string(),
242
- txid : z.string(),
243
- chain : z.string(),
244
- deposit_address: z.string(),
245
- status : z.nativeEnum(Status),
246
- finish_txid : z.string(),
247
- wrap_hash : z.string(),
248
- confirmations : z.number(),
249
- })
250
- export type Wrap = z.infer<typeof wrapParser>
251
-
252
- export const transactionParser = z.object({
253
- id : z.string(), // "2629304740076324677"
254
- wallet : z.string(), // "ETH"
255
- value : z.number(), // 10000000000000000
256
- valueString : z.string(), // "10000000000000000"
257
- address : z.string(), // "0x0000"
258
- type : z.nativeEnum(Type), // "receive" or "send"
259
- state : z.string(), // "confirmed"
260
- confirmations : z.number(), // 1
261
- hash : z.string(), // "b4781422be95fee8fbbf720e3e0fa9705ae834474ef25f5724cdd0f5d23211ed"
262
- blockHash : z.string().optional().nullable(), // "000000000000000000089b270eb99f75107d6a9cde37ec944cb80a2998df7b43"
263
- blockHeight : z.number().optional().nullable(), // 643159
264
- })
265
- export type Transaction = z.infer<typeof transactionParser>
266
-
267
- export const addressParser = z.object({
268
- index : z.number(),
269
- account : accountParser,
270
- chain : z.string(),
271
- address : z.string(),
272
- address_hash: z.string(),
273
- })
274
- export type Address = z.infer<typeof addressParser>
275
-
276
- export const otcOrderResponseParser = z.object({
277
- success : z.boolean(),
278
- transaction_id: z.string(),
279
- errormsg : z.string().optional()
280
- })
281
- export type OtcOrderResponse = z.infer<typeof otcOrderResponseParser>
282
-
283
- export const otcQuoteBodyParser = z.object({
284
- baseAmount : z.number(),
285
- baseSymbol : z.string(),
286
- quoteSymbol: z.string()
287
- })
288
- export type OtcQuoteBody = z.infer<typeof otcQuoteBodyParser>
289
-
290
- export const otcQuoteResponseParser = z.object({
291
- success : z.boolean(),
292
- token : z.string(),
293
- qty : z.number(),
294
- errormsg: z.string().optional()
295
- })
296
- export type OtcQuoteResponse = z.infer<typeof otcQuoteResponseParser>
297
-
298
- export const rateParser = z.object({
299
- counterCurrency : z.string(),
300
- price : z.number(),
301
- priceChangePercent: z.number(),
302
- marketCap : z.number(),
303
- volume : z.number(),
304
- timestamp : z.number()
305
- })
306
- export type Rate = z.infer<typeof rateParser>
307
-
308
- export const exchangeRateParser = z.object({
309
- contract: z.string(),
310
- symbol : z.string(),
311
- rank : z.number(),
312
- rates : z.array(rateParser)
313
- })
314
- export type ExchangeRate = z.infer<typeof exchangeRateParser>
315
-
316
- export const exchangeRatesParser = z.array(exchangeRateParser)
317
- export type ExchangeRates = z.infer<typeof exchangeRatesParser>
318
-
319
- export const withdrawalFeeQuoteParser = z.object({
320
- quoteId : z.string(),
321
- estimatedFee: z.string(),
322
- currency : z.string(),
323
- network : z.string(),
324
- })
325
- export type WithdrawalFeeQuote = z.infer<typeof withdrawalFeeQuoteParser>
326
-
327
- export interface CurrencyStat {
328
- supply : string;
329
- max_supply: string;
330
- issuer : string;
331
- }
332
- export interface CurrencyStats {
333
- [key: string]: CurrencyStat;
334
- }