forked from Keeper-Wallet/waveskeeper-types
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobals.d.ts
656 lines (577 loc) · 17.1 KB
/
globals.d.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
// Type definitions for WavesKeeper
// Project: WavesKeeper
/*~ This template shows how to write a global plugin. */
interface Window {
TurtleShell: TurtleShell.TTurtleShellApi;
}
declare var TurtleShell: TurtleShell.TTurtleShellApi;
declare namespace TurtleShell {
type TTurtleShellApi = {
/**
* This is a method for obtaining a signature of authorization data while verifying Waves' user.
* @param data
*/
auth(data: IAuthData): Promise<IAuthResponse>;
/**
* If a website is trusted, Waves Keeper public data are returned.
*/
publicState(): Promise<IPublicStateResponse>;
/**
* Waves Keeper's method for cancelling an order to the matcher.
* It works identically to signCancelOrder, but also tries to send data to the matcher.
* @param data
*/
signAndPublishCancelOrder(data: TSignCancelOrderDataPublish): Promise<string>;
/**
* Waves Keeper's method for creating an order to the matcher is identical to signOrder
* but it also tries to send data to the matcher.
* @param data
*/
signAndPublishOrder(data: TSignOrderData): Promise<string>;
/**
* This is similar to "signTransaction", but it also broadcasts a transaction to the blockchain.
* @param data
*/
signAndPublishTransaction(data: TSignTransactionData): Promise<string>;
/**
* Waves Keeper's method for signing cancellation of an order to the matcher.
* @param data
*/
signCancelOrder(data: TSignCancelOrderData): Promise<string>;
/**
* Waves Keeper's method for signing an order to the matcher.
* @param data
*/
signOrder(data: TSignOrderData): Promise<string>;
/**
* A method for signing transactions in Waves' network.
* @param data
*/
signTransaction(data: TSignTransactionData): Promise<string>;
/**
* Waves Keeper's method for signing typified data, for signing requests on various services.
* @param data
*/
signRequest(data: TSignRequestData): Promise<string>;
/**
* A package transaction signature. Sometimes several transactions need to be simultaneously signed,
* and for users' convenience, up to seven transactions at ones could be signed.
* Only certain types of transactions are permitted:
* issue, transfer, reissue, burn, create alias, mass transfer, data
* @param tx
* @param name
*/
signTransactionPackage(tx: TSignTransactionPackageData, name?: string): Promise<Array<string>>;
/**
* Waves Keeper's method for signing custom data. Can be used for different services
* Adds prefix to data to make it impossible to sign transaction data in this method
* Signs byteArray. Prefix = [255, 255, 255, 1]
* @param data
*/
signCustomData(data: TSignCustomDataParamsV1): Promise<TSignCustomDataResponseV1>
/**
* Waves Keeper's method for signing custom data. Can be used for different services
* Adds prefix to data to make it impossible to sign transaction data in this method
* Signs typed data array. Prefix = [255, 255, 255, 2]
* @param data
*/
signCustomData(data: TSignCustomDataParamsV2): Promise<TSignCustomDataResponseV2>
/**
* Send message to keeper.
* You can send message only 1 time in 30 sec for trusted sites with send permission
* @param data
*/
notification(data: INotificationData): Promise<any>;
/**
* You can encrypt string messages to account in Waves network.
* You need have recipient publicKey.
* @param stringToEncrypt
* String to encrypt
* @param publicKey
* Public key in base58 string
* @param prefix
* Prefix is secret app string need for encoding
*/
encryptMessage(stringToEncrypt: string, publicKey: string, prefix: string): Promise<string>;
/**
* You can decrypt string messages from account in Waves network to you.
* You need have sender publicKey and encrypted message.
* @param stringToDecrypt
* String to decrypt
* @param publicKey
* Public key in base58 string
* @param prefix
* Prefix is secret app string need for encoding
*/
decryptMessage(stringToDecrypt: string, publicKey: string, prefix: string): Promise<string>;
/**
* Allows subscribing to Waves Keeper events.
* If a website is not trusted, events won't show.
* @param event
* Supports events:
* update – subscribe to updates of the state
* @param cb
*/
on(event: 'update', cb: (state: IPublicStateResponse) => any): object;
/**
* On initialize window.TurtleShell has no api methods.
* You can use TurtleShell.initialPromise for waiting end initializing api
*/
initialPromise : Promise<any>;
}
type TTypedData = TBinaryData | TBooleanData | TIntegerData | TStringData
type TBinaryData = { type: 'binary', key: string, value: string}
type TBooleanData = { type: 'boolean', key: string, value: boolean}
type TIntegerData = { type: 'integer', key: string, value: number}
type TStringData = { type: 'string', key: string, value: string}
type TSignCustomDataParamsV1 = {
version: 1
/**
* base64 encoded byteArray
*/
binary: string
}
type TSignCustomDataResponseV1 = TSignCustomDataParamsV1 & { signature: string, publicKey: string}
type TSignCustomDataParamsV2 = {
version: 2
data: TTypedData[]
}
type TSignCustomDataResponseV2 = TSignCustomDataParamsV2 & { signature: string, publicKey: string}
interface IAuthData {
/**
* a string line with any data (required field)
*/
data: string;
/**
* name of the service (optional field)
*/
name?: string;
/**
* a websites' full URL for redirect (optional field)
*/
referrer?: string;
/**
* path to the logo relative to the referrer or origin of the website (optional field)
*/
icon?: string;
/**
* relative path to the website's Auth API (optional field)
*/
successPath?: string;
}
interface IAuthResponse {
/**
* an address in Waves network
*/
address: string;
/**
* a host that requested a signature
*/
host: string;
/**
* a prefix participating in the signature
*/
prefix: string;
/**
* the user's public key
*/
publicKey: string;
/**
* signature
*/
signature: string;
/**
* API version
*/
version: number;
/**
* the name of an application that requested a signature
*/
name: string;
}
interface IPublicStateResponse {
/**
* boolean keeper initialized
*/
initialized: boolean;
/**
* boolean keeper in wait mode
*/
locked: boolean;
/**
* current account, if the user allowed access to the website, or null
*/
account: TPublicStateAccount | null;
/**
* current Waves network, node and matcher addresses
*/
network: TPublicStateNetwork,
/**
* signature request statuses
*/
messages: Array<TPublicStateMessage>,
/**
* available transaction versions for each type
*/
txVersion: Record<number, Array<number>>;
}
type TPublicStateNetwork = {
code: string;
server: string;
matcher: string;
}
type TPublicStateAccount = {
name: string;
publicKey: string;
address: string;
networkCode: string;
network: string;
balance: TAccountBalance;
type: string;
}
type TAccountBalance = {
available: string;
leasedOut: string;
network: string;
}
type TPublicStateMessage = {
id: string;
status: string;
}
interface ICancelOrderData {
/**
* order ID
*/
id: string;
/**
* sender's public key in base58
*/
senderPublicKey?: string;
}
type TSignCancelOrderData = ISignData<1003, ICancelOrderData>;
// @ts-ignore
type TSignCancelOrderDataPublish = ISignData<1003,string,string, ICancelOrderData>;
interface ISignOrderDataBody {
/**
* MoneyLike - amount
*/
amount: TMoney;
/**
* MoneyLike - price
*/
price: TMoney;
/**
* 'sell'/'buy' – order type
*/
orderType: 'sell' | 'buy';
/**
* MoneyLike - fee (0.003 WAVES minimum)
*/
matcherFee: TMoney;
/**
* the public key of the exchange service
*/
matcherPublicKey: string;
/**
* the order's expiration time
*/
expiration: string | number;
/**
* current time
*/
timestamp?: string | number;
/**
* public key in base58
*/
senderPublicKey?: string;
}
type TSignOrderData = ISignData<1002, ISignOrderDataBody>;
interface ISignRequestBody {
timestamp: number | string;
/**
* public key in base58
*/
senderPublicKey?: string;
}
type TSignRequestData = ISignData<1001 | 1004, ISignRequestBody>;
type TSignTransactionData =
TIssueTxData |
TTransferTxData |
TReissueTxData |
TBurnTxData |
TLeaseTxData |
TLeaseCancelTxData |
TCreateAliasTxData |
TMassTransferTxData |
TDataTxData |
TSetScriptTxData |
TSponsoredFeeTxData |
TSetAssetScriptTxData |
TScriptInvocationTxData |
TUpdateAssetInfoTxData;
interface ISignData<TYPE extends number, BODY> {
type: TYPE;
data: BODY;
}
interface ITransactionBase {
/**
* MoneyLike - fee
*/
fee?: TMoney;
/**
* sender's public key in base58
*/
senderPublicKey?: string;
/**
* time in ms
*/
timestamp?: number | string;
}
interface IIssueTx extends ITransactionBase {
/**
* [4, 16] string – token name
*/
name: string;
/**
* [0, 1000] string – token description
*/
description: string,
/**
* [0 - (JLM)] number/string - quantity
*/
quantity: number | string;
/**
* [0 - 8] number - precision
*/
precision: number;
/**
* can reissue token
*/
reissuable: boolean;
/**
* smart asset
*/
script?: string;
}
type TIssueTxData = ISignData<3, IIssueTx>;
interface ITransferTx extends ITransactionBase {
/**
* MoneyLike - amount
*/
amount: TMoney;
/**
* recipient's address or alias
*/
recipient: string;
/**
* [,140 bytes] string or byte Array – additional info in text (optional field)
*/
attachment?: string | Uint8Array | Array<number>;
}
type TTransferTxData = ISignData<4, ITransferTx>;
interface IReissueTx extends ITransactionBase {
/**
* asset ID
*/
assetId: string;
/**
* [0 - (JLM)] number/string/MoneyLike - quantity
*/
quantity: number | string | TMoney;
/**
* deny reissue
*/
reissuable: boolean;
}
type TReissueTxData = ISignData<5, IReissueTx>;
interface IBurnTx extends ITransactionBase {
/**
* asset ID
*/
assetId: string;
/**
* [0 - (JLM)] number/string/MoneyLike - quantity,
*/
amount: number | string | TMoney;
}
type TBurnTxData = ISignData<6, IBurnTx>;
interface ILeaseTx extends ITransactionBase {
/**
* recipient's address or alias
*/
recipient: string;
/**
* [0 - (JLM)] number/string/MoneyLike - quantity
*/
amount: number | string | TMoney;
}
type TLeaseTxData = ISignData<8, ILeaseTx>;
interface ILeaseCancelTx extends ITransactionBase {
/**
* leasing transaction ID
*/
leaseId: string;
}
type TLeaseCancelTxData = ISignData<9, ILeaseCancelTx>;
interface ICreateAliasTx extends ITransactionBase {
/**
* [4, 30] string - alias
*/
alias: string;
}
type TCreateAliasTxData = ISignData<10, ICreateAliasTx>;
interface IMassTransferTx extends ITransactionBase {
/**
* moneyLike – total to be sent
* instead of calculating the amount you may insert { assetId: "ID of the asset to be sent", coins: 0},
*/
totalAmount: TMoney;
/**
* a mass of objects
*/
transfers: Array<ITransfer>;
/**
* [,140 bytes в base58] string – additional info (optional field)
*/
attachment?: string;
}
interface ITransfer {
/**
* address/alias
*/
recipient: string;
/**
* amount
*/
amount: number | string | TMoney;
}
type TMassTransferTxData = ISignData<11, IMassTransferTx>;
interface IDataTx extends ITransactionBase {
/**
* mass of objects
*/
data: Array<TData>;
}
type TData = TCallArgs & {key: string};
type TDataTxData = ISignData<12, IDataTx>;
interface ISetScriptTx extends ITransactionBase {
/**
* script
* https://docs.wavesplatform.com/en/#section-5e6520b97a7ead921d7fb6bce7292ce0
*/
script: string | null;
}
type TSetScriptTxData = ISignData<13, ISetScriptTx>;
interface ISponsoredFeeTx extends ITransactionBase {
/**
* MoneyLike – fee price in the asset
*/
minSponsoredAssetFee: TMoney;
}
type TSponsoredFeeTxData = ISignData<14, ISponsoredFeeTx>;
interface ISetAssetScriptTx extends ITransactionBase {
/**
* asset ID
*/
assetId: string;
/**
* script
* https://docs.wavesplatform.com/en/#section-5e6520b97a7ead921d7fb6bce7292ce0
*/
script: string;
}
type TSetAssetScriptTxData = ISignData<15, ISetAssetScriptTx>;
interface IScriptInvocationTx extends ITransactionBase {
/**
* address script account
*/
dApp: string;
/**
* array MoneyLike (at now can use only 1 payment)
*/
payment?: Array<TMoney>;
call?: ICall;
}
interface ICall {
/**
* function name
*/
function: string;
/**
* array
*/
args: Array<TCallArgs>;
}
type TCallArgs = TCallArgsInteger | TCallArgsBoolean | TCallArgsBinary | TCallArgsString;
type TCallArgsInteger = {
type: 'integer';
value: number | string;
}
type TCallArgsBoolean = {
type: 'boolean';
value: boolean;
}
type TCallArgsBinary = {
type: 'binary';
/**
* base64
*/
value: string;
}
type TCallArgsString = {
type: 'string';
value: string;
}
type TScriptInvocationTxData = ISignData<16, IScriptInvocationTx>;
interface IUpdateAssetInfoTx extends ITransactionBase {
/**
* [4, 16] string – token name
*/
name: string;
/**
* [0, 1000] string – token description
*/
description: string,
}
type TUpdateAssetInfoTxData = ISignData<17, IUpdateAssetInfoTx>;
type TSignTransactionPackageData = Array<
TIssueTxData |
TTransferTxData |
TReissueTxData |
TBurnTxData |
TLeaseTxData |
TLeaseCancelTxData |
TCreateAliasTxData |
TMassTransferTxData |
TDataTxData |
TSetScriptTxData |
TSponsoredFeeTxData |
TSetAssetScriptTxData |
TScriptInvocationTxData>;
interface INotificationData {
/**
* string (20 chars max)
*/
title: string;
/**
* string (250 chars max)
*/
message?: string;
}
interface IMoneyTokens {
assetId: string;
tokens: number | string;
}
interface IMoneyCoins {
assetId: string;
coins: number | string;
}
interface IMoneyAmount {
assetId: string;
/**
* coins alias
*/
amount: number | string;
}
type TMoney = IMoneyTokens | IMoneyCoins | IMoneyAmount;
}