-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathRequestTypes.ts
352 lines (325 loc) · 10.9 KB
/
RequestTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import type { RelayRequest } from '@opengsn/common/dist/EIP712/RelayRequest';
import type { Currency, PaymentType, RequestType, CashlinkTheme } from '../../client/PublicRequestTypes';
import type { ParsedPaymentOptions } from './paymentOptions/ParsedPaymentOptions';
import type { ParsedNimiqSpecifics, ParsedNimiqDirectPaymentOptions } from './paymentOptions/NimiqPaymentOptions';
import type { ParsedEtherSpecifics, ParsedEtherDirectPaymentOptions } from './paymentOptions/EtherPaymentOptions';
import type { ParsedBitcoinSpecifics, ParsedBitcoinDirectPaymentOptions } from './paymentOptions/BitcoinPaymentOptions';
import type { SwapAsset } from '@nimiq/fastspot-api';
import type { FiatCurrency } from '@nimiq/utils';
export interface ParsedBasicRequest {
kind: RequestType;
appName: string;
}
export interface ParsedSimpleRequest extends ParsedBasicRequest {
walletId: string;
}
export interface ParsedOnboardRequest extends ParsedBasicRequest {
disableBack: boolean;
}
export interface ParsedChooseAddressRequest extends ParsedBasicRequest {
returnBtcAddress: boolean;
returnUsdcAddress: boolean;
minBalance: number;
disableContracts: boolean;
disableLegacyAccounts: boolean;
disableBip39Accounts: boolean;
disableLedgerAccounts: boolean;
ui?: number;
}
export interface ParsedSignTransactionRequest extends ParsedBasicRequest {
// The sender object is currently only for internal use in RefundSwapLedger and can not be set in public request.
// Note that the object does not get exported to the history state in RpcApi and therefore does not survive reloads.
// However, the RefundSwapLedger handler is built in a way that it starts over on reloads to avoid the problem.
sender: Nimiq.Address | {
address: Nimiq.Address,
label?: string,
walletLabel?: string,
type?: Nimiq.Account.Type,
signerKeyId: string,
signerKeyPath: string,
};
recipient: Nimiq.Address;
recipientType: Nimiq.Account.Type;
recipientLabel?: string;
value: number;
fee: number;
data: Uint8Array;
flags: number;
validityStartHeight: number; // FIXME To be made optional when hub has its own network
}
export type ParsedProtocolSpecificsForCurrency<C extends Currency> =
C extends Currency.NIM ? ParsedNimiqSpecifics
: C extends Currency.BTC ? ParsedBitcoinSpecifics
: C extends Currency.ETH ? ParsedEtherSpecifics
: undefined;
export type AvailableParsedPaymentOptions = ParsedNimiqDirectPaymentOptions
| ParsedEtherDirectPaymentOptions
| ParsedBitcoinDirectPaymentOptions;
export type ParsedPaymentOptionsForCurrencyAndType<C extends Currency, T extends PaymentType> =
T extends PaymentType.DIRECT ?
C extends Currency.NIM ? ParsedNimiqDirectPaymentOptions
: C extends Currency.BTC ? ParsedBitcoinDirectPaymentOptions
: C extends Currency.ETH ? ParsedEtherDirectPaymentOptions
: ParsedPaymentOptions<C, T>
: ParsedPaymentOptions<C, T>;
export interface ParsedCheckoutRequest extends ParsedBasicRequest {
version: number;
shopLogoUrl?: string;
callbackUrl?: string;
csrf?: string;
time: number;
fiatCurrency?: string;
fiatAmount?: number;
paymentOptions: AvailableParsedPaymentOptions[];
isPointOfSale: boolean;
disableDisclaimer: boolean;
}
export interface ParsedSignMessageRequest extends ParsedBasicRequest {
signer?: Nimiq.Address;
message: string | Uint8Array;
}
export interface ParsedRenameRequest extends ParsedSimpleRequest {
address?: string;
}
export interface ParsedExportRequest extends ParsedSimpleRequest {
fileOnly?: boolean;
wordsOnly?: boolean;
}
export interface ParsedCreateCashlinkRequest extends ParsedBasicRequest {
senderAddress?: Nimiq.Address;
senderBalance?: number;
value?: number;
message?: string;
theme: CashlinkTheme;
fiatCurrency?: FiatCurrency;
returnLink: boolean;
skipSharing: boolean;
}
export interface ParsedManageCashlinkRequest extends ParsedBasicRequest {
cashlinkAddress: Nimiq.Address;
}
/**
* Bitcoin
*/
export interface ParsedSignBtcTransactionRequest extends ParsedSimpleRequest {
inputs: Array<{
address: string,
transactionHash: string,
outputIndex: number,
outputScript: string, // hex
witnessScript?: string, // Custom witness script for p2wsh input. hex.
value: number,
sequence?: number,
// Currently only for internal use in RefundSwapLedger. Can not be set in public request.
// Note that the keyPath gets lost on re-parsing in RequestParser and therefore does not survive reloads.
// However, the RefundSwapLedger handler is built in a way that it starts over on reloads to avoid the problem.
keyPath?: string,
}>;
output: {
address: string,
value: number,
label?: string,
};
changeOutput?: {
address: string,
value: number,
};
locktime?: number;
}
export interface ParsedAddBtcAddressesRequest extends ParsedSimpleRequest {
chain: 'internal' | 'external';
firstIndex: number;
}
/**
* Polygon
*/
export interface ParsedSignPolygonTransactionRequest extends ParsedBasicRequest, RelayRequest {
recipientLabel?: string;
approval?: {
tokenNonce: number,
};
permit?: {
tokenNonce: number,
};
amount?: number;
senderLabel?: string;
}
/**
* Swap
*/
export interface ParsedSetupSwapRequest extends ParsedSimpleRequest {
swapId: string;
fund: {
type: SwapAsset.NIM,
sender: Nimiq.Address,
value: number, // Luna
fee: number, // Luna
// extraData: Uint8Array, // HTLC data
validityStartHeight: number,
} | {
type: SwapAsset.BTC,
inputs: Array<{
address: string,
transactionHash: string,
outputIndex: number,
outputScript: string,
value: number, // Sats
sequence?: number,
}>;
output: {
// address: string, // HTLC address
value: number, // Sats
};
changeOutput?: {
address: string,
value: number, // Sats
};
locktime?: number,
// htlcScript: Uint8Array,
refundAddress: string,
} | ({
type: SwapAsset.USDC_MATIC,
permit?: {
tokenNonce: number,
},
} & RelayRequest) | {
type: SwapAsset.EUR,
value: number, // Eurocents
fee: number, // Eurocents
bankLabel?: string,
} | {
type: SwapAsset.CRC,
value: number, // CRC cents
fee: number, // CRC cents
senderLabel?: string,
};
redeem: {
type: SwapAsset.NIM,
// sender: Nimiq.Address, // HTLC address
recipient: Nimiq.Address, // My address, must be redeem address of HTLC
value: number, // Luna
fee: number, // Luna
extraData?: Uint8Array,
validityStartHeight: number,
// htlcData: Uint8Array,
} | {
type: SwapAsset.BTC,
input: {
// transactionHash: string,
// outputIndex: number,
// outputScript: string,
value: number, // Sats
// witnessScript: string,
};
output: {
address: string, // My address, must be redeem address of HTLC
value: number, // Sats
};
} | ({
type: SwapAsset.USDC_MATIC,
amount: number,
} & RelayRequest) | {
type: SwapAsset.EUR,
value: number; // Eurocents
fee: number; // Eurocents
bankLabel?: string;
settlement: {
type: 'sepa',
recipient: {
name: string,
iban: string,
bic: string,
},
} | {
type: 'mock',
};
} | {
type: SwapAsset.CRC,
value: number; // CRC cents
fee: number; // CRC cents
recipientLabel?: string;
settlement: {
type: 'sinpemovil',
phoneNumber: string,
} | {
type: 'mock',
};
};
// Data needed for display
layout: 'standard' | 'slider';
fiatCurrency: string;
fundingFiatRate: number;
redeemingFiatRate: number;
fundFees: { // In the currency that gets funded
processing: number,
redeeming: number,
};
redeemFees: { // In the currency that gets redeemed
funding: number,
processing: number,
};
serviceSwapFee: number; // Luna or Sats, depending which one gets funded
direction?: 'left-to-right' | 'right-to-left';
nimiqAddresses?: Array<{
address: string,
balance: number, // Luna
}>;
bitcoinAccount?: {
balance: number, // Sats
};
polygonAddresses?: Array<{
address: string,
usdcBalance: number, // In USDC's smallest unit
}>;
// Optional KYC info for swapping at higher limits
kyc?: {
provider: 'TEN31 Pass',
userId: string,
s3GrantToken: string,
oasisGrantToken?: string,
};
}
export interface ParsedRefundSwapRequest extends ParsedSimpleRequest {
refund: {
type: SwapAsset.NIM;
sender: Nimiq.Address; // HTLC address
recipient: Nimiq.Address; // My address, must be refund address of HTLC
value: number; // Luna
fee: number; // Luna
extraData?: Uint8Array;
validityStartHeight: number;
} | {
type: SwapAsset.BTC;
input: {
transactionHash: string,
outputIndex: number,
outputScript: string,
value: number, // Sats
witnessScript: string,
};
output: {
address: string, // My address
value: number, // Sats
};
refundAddress: string; // My address, must be refund address of HTLC
} | ({
type: SwapAsset.USDC_MATIC | SwapAsset.USDC,
amount: number,
} & RelayRequest);
}
// Discriminated Unions
export type ParsedRpcRequest = ParsedSignTransactionRequest
| ParsedCreateCashlinkRequest
| ParsedManageCashlinkRequest
| ParsedCheckoutRequest
| ParsedBasicRequest
| ParsedSimpleRequest
| ParsedOnboardRequest
| ParsedRenameRequest
| ParsedSignMessageRequest
| ParsedExportRequest
| ParsedSignBtcTransactionRequest
| ParsedAddBtcAddressesRequest
| ParsedSignPolygonTransactionRequest
| ParsedSetupSwapRequest
| ParsedRefundSwapRequest;