forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.guard.ts
638 lines (583 loc) · 21.9 KB
/
index.guard.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
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
/*
* Generated type guards for "index.ts".
* WARNING: Do not manually change this file.
*/
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferObjectTransaction, MergeCoinTransaction, SplitCoinTransaction, MoveCallTransaction, TxnDataSerializer, SignaturePubkeyPair, Signer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, TransferObject, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, MergeCoinResponse, SplitCoinResponse, TransactionResponse } from "./index";
import { BN } from "bn.js";
import { Base64DataBuffer } from "./serialization/base64";
import { PublicKey } from "./cryptography/publickey";
export function isEd25519KeypairData(obj: any, _argumentName?: string): obj is Ed25519KeypairData {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
obj.publicKey instanceof Uint8Array &&
obj.secretKey instanceof Uint8Array
)
}
export function isKeypair(obj: any, _argumentName?: string): obj is Keypair {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
typeof obj.getPublicKey === "function" &&
typeof obj.signData === "function"
)
}
export function isPublicKeyInitData(obj: any, _argumentName?: string): obj is PublicKeyInitData {
return (
(isTransactionDigest(obj) as boolean ||
isSequenceNumber(obj) as boolean ||
obj instanceof Buffer ||
obj instanceof Uint8Array ||
Array.isArray(obj) &&
obj.every((e: any) =>
isSequenceNumber(e) as boolean
) ||
isPublicKeyData(obj) as boolean)
)
}
export function isPublicKeyData(obj: any, _argumentName?: string): obj is PublicKeyData {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
obj._bn instanceof BN
)
}
export function isTransferObjectTransaction(obj: any, _argumentName?: string): obj is TransferObjectTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.objectId) as boolean &&
(typeof obj.gasPayment === "undefined" ||
isTransactionDigest(obj.gasPayment) as boolean) &&
isSequenceNumber(obj.gasBudget) as boolean &&
isTransactionDigest(obj.recipient) as boolean
)
}
export function isMergeCoinTransaction(obj: any, _argumentName?: string): obj is MergeCoinTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.primaryCoin) as boolean &&
isTransactionDigest(obj.coinToMerge) as boolean &&
(typeof obj.gasPayment === "undefined" ||
isTransactionDigest(obj.gasPayment) as boolean) &&
isSequenceNumber(obj.gasBudget) as boolean
)
}
export function isSplitCoinTransaction(obj: any, _argumentName?: string): obj is SplitCoinTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.coinObjectId) as boolean &&
Array.isArray(obj.splitAmounts) &&
obj.splitAmounts.every((e: any) =>
isSequenceNumber(e) as boolean
) &&
(typeof obj.gasPayment === "undefined" ||
isTransactionDigest(obj.gasPayment) as boolean) &&
isSequenceNumber(obj.gasBudget) as boolean
)
}
export function isMoveCallTransaction(obj: any, _argumentName?: string): obj is MoveCallTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.packageObjectId) as boolean &&
isTransactionDigest(obj.module) as boolean &&
isTransactionDigest(obj.function) as boolean &&
Array.isArray(obj.typeArguments) &&
obj.typeArguments.every((e: any) =>
isTransactionDigest(e) as boolean
) &&
Array.isArray(obj.arguments) &&
obj.arguments.every((e: any) =>
isSuiJsonValue(e) as boolean
) &&
(typeof obj.gasPayment === "undefined" ||
isTransactionDigest(obj.gasPayment) as boolean) &&
isSequenceNumber(obj.gasBudget) as boolean
)
}
export function isTxnDataSerializer(obj: any, _argumentName?: string): obj is TxnDataSerializer {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
typeof obj.newTransferObject === "function" &&
typeof obj.newMoveCall === "function" &&
typeof obj.newMergeCoin === "function" &&
typeof obj.newSplitCoin === "function"
)
}
export function isSignaturePubkeyPair(obj: any, _argumentName?: string): obj is SignaturePubkeyPair {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
obj.signature instanceof Base64DataBuffer &&
obj.pubKey instanceof PublicKey
)
}
export function isSigner(obj: any, _argumentName?: string): obj is Signer {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
typeof obj.getAddress === "function" &&
typeof obj.signData === "function"
)
}
export function isTransactionDigest(obj: any, _argumentName?: string): obj is TransactionDigest {
return (
typeof obj === "string"
)
}
export function isSuiAddress(obj: any, _argumentName?: string): obj is SuiAddress {
return (
typeof obj === "string"
)
}
export function isObjectOwner(obj: any, _argumentName?: string): obj is ObjectOwner {
return (
((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.AddressOwner) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.ObjectOwner) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.SingleOwner) as boolean ||
obj === "Shared" ||
obj === "Immutable")
)
}
export function isSuiObjectRef(obj: any, _argumentName?: string): obj is SuiObjectRef {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.digest) as boolean &&
isTransactionDigest(obj.objectId) as boolean &&
isSequenceNumber(obj.version) as boolean
)
}
export function isSuiObjectInfo(obj: any, _argumentName?: string): obj is SuiObjectInfo {
return (
isSuiObjectRef(obj) as boolean &&
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.type) as boolean &&
isObjectOwner(obj.owner) as boolean &&
isTransactionDigest(obj.previousTransaction) as boolean
)
}
export function isObjectContentFields(obj: any, _argumentName?: string): obj is ObjectContentFields {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Object.entries<any>(obj)
.every(([key, _value]) => (isTransactionDigest(key) as boolean))
)
}
export function isMovePackageContent(obj: any, _argumentName?: string): obj is MovePackageContent {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Object.entries<any>(obj)
.every(([key, value]) => (isTransactionDigest(value) as boolean &&
isTransactionDigest(key) as boolean))
)
}
export function isSuiData(obj: any, _argumentName?: string): obj is SuiData {
return (
((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isObjectType(obj.dataType) as boolean &&
isSuiMoveObject(obj) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isObjectType(obj.dataType) as boolean &&
isSuiMovePackage(obj) as boolean)
)
}
export function isSuiMoveObject(obj: any, _argumentName?: string): obj is SuiMoveObject {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.type) as boolean &&
isObjectContentFields(obj.fields) as boolean
)
}
export function isSuiMovePackage(obj: any, _argumentName?: string): obj is SuiMovePackage {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isMovePackageContent(obj.disassembled) as boolean
)
}
export function isSuiObject(obj: any, _argumentName?: string): obj is SuiObject {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSuiData(obj.data) as boolean &&
isObjectOwner(obj.owner) as boolean &&
isTransactionDigest(obj.previousTransaction) as boolean &&
isSequenceNumber(obj.storageRebate) as boolean &&
isSuiObjectRef(obj.reference) as boolean
)
}
export function isObjectStatus(obj: any, _argumentName?: string): obj is ObjectStatus {
return (
(obj === "Exists" ||
obj === "NotExists" ||
obj === "Deleted")
)
}
export function isObjectType(obj: any, _argumentName?: string): obj is ObjectType {
return (
(obj === "moveObject" ||
obj === "package")
)
}
export function isGetOwnedObjectsResponse(obj: any, _argumentName?: string): obj is GetOwnedObjectsResponse {
return (
Array.isArray(obj) &&
obj.every((e: any) =>
isSuiObjectInfo(e) as boolean
)
)
}
export function isGetObjectDataResponse(obj: any, _argumentName?: string): obj is GetObjectDataResponse {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isObjectStatus(obj.status) as boolean &&
(isTransactionDigest(obj.details) as boolean ||
isSuiObjectRef(obj.details) as boolean ||
isSuiObject(obj.details) as boolean)
)
}
export function isObjectDigest(obj: any, _argumentName?: string): obj is ObjectDigest {
return (
typeof obj === "string"
)
}
export function isObjectId(obj: any, _argumentName?: string): obj is ObjectId {
return (
typeof obj === "string"
)
}
export function isSequenceNumber(obj: any, _argumentName?: string): obj is SequenceNumber {
return (
typeof obj === "number"
)
}
export function isTransferObject(obj: any, _argumentName?: string): obj is TransferObject {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.recipient) as boolean &&
isSuiObjectRef(obj.objectRef) as boolean
)
}
export function isRawAuthoritySignInfo(obj: any, _argumentName?: string): obj is RawAuthoritySignInfo {
return (
Array.isArray(obj) &&
isTransactionDigest(obj[0]) as boolean &&
isTransactionDigest(obj[1]) as boolean
)
}
export function isTransactionKindName(obj: any, _argumentName?: string): obj is TransactionKindName {
return (
(obj === "TransferObject" ||
obj === "Publish" ||
obj === "Call")
)
}
export function isSuiTransactionKind(obj: any, _argumentName?: string): obj is SuiTransactionKind {
return (
((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransferObject(obj.TransferObject) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSuiMovePackage(obj.Publish) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isMoveCall(obj.Call) as boolean)
)
}
export function isTransactionData(obj: any, _argumentName?: string): obj is TransactionData {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Array.isArray(obj.transactions) &&
obj.transactions.every((e: any) =>
isSuiTransactionKind(e) as boolean
) &&
isTransactionDigest(obj.sender) as boolean &&
isSuiObjectRef(obj.gasPayment) as boolean &&
isSequenceNumber(obj.gasBudget) as boolean
)
}
export function isEpochId(obj: any, _argumentName?: string): obj is EpochId {
return (
typeof obj === "number"
)
}
export function isAuthorityQuorumSignInfo(obj: any, _argumentName?: string): obj is AuthorityQuorumSignInfo {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSequenceNumber(obj.epoch) as boolean &&
Array.isArray(obj.signatures) &&
obj.signatures.every((e: any) =>
isRawAuthoritySignInfo(e) as boolean
)
)
}
export function isCertifiedTransaction(obj: any, _argumentName?: string): obj is CertifiedTransaction {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.transactionDigest) as boolean &&
isTransactionData(obj.data) as boolean &&
isTransactionDigest(obj.txSignature) as boolean &&
isAuthorityQuorumSignInfo(obj.authSignInfo) as boolean
)
}
export function isGasCostSummary(obj: any, _argumentName?: string): obj is GasCostSummary {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSequenceNumber(obj.computationCost) as boolean &&
isSequenceNumber(obj.storageCost) as boolean &&
isSequenceNumber(obj.storageRebate) as boolean
)
}
export function isExecutionStatusType(obj: any, _argumentName?: string): obj is ExecutionStatusType {
return (
(obj === "success" ||
obj === "failure")
)
}
export function isExecutionStatus(obj: any, _argumentName?: string): obj is ExecutionStatus {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isExecutionStatusType(obj.status) as boolean &&
(typeof obj.error === "undefined" ||
isTransactionDigest(obj.error) as boolean)
)
}
export function isOwnedObjectRef(obj: any, _argumentName?: string): obj is OwnedObjectRef {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isObjectOwner(obj.owner) as boolean &&
isSuiObjectRef(obj.reference) as boolean
)
}
export function isTransactionEffects(obj: any, _argumentName?: string): obj is TransactionEffects {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isExecutionStatus(obj.status) as boolean &&
isGasCostSummary(obj.gasUsed) as boolean &&
(typeof obj.sharedObjects === "undefined" ||
Array.isArray(obj.sharedObjects) &&
obj.sharedObjects.every((e: any) =>
isSuiObjectRef(e) as boolean
)) &&
isTransactionDigest(obj.transactionDigest) as boolean &&
(typeof obj.created === "undefined" ||
Array.isArray(obj.created) &&
obj.created.every((e: any) =>
isOwnedObjectRef(e) as boolean
)) &&
(typeof obj.mutated === "undefined" ||
Array.isArray(obj.mutated) &&
obj.mutated.every((e: any) =>
isOwnedObjectRef(e) as boolean
)) &&
(typeof obj.unwrapped === "undefined" ||
Array.isArray(obj.unwrapped) &&
obj.unwrapped.every((e: any) =>
isOwnedObjectRef(e) as boolean
)) &&
(typeof obj.deleted === "undefined" ||
Array.isArray(obj.deleted) &&
obj.deleted.every((e: any) =>
isSuiObjectRef(e) as boolean
)) &&
(typeof obj.wrapped === "undefined" ||
Array.isArray(obj.wrapped) &&
obj.wrapped.every((e: any) =>
isSuiObjectRef(e) as boolean
)) &&
isOwnedObjectRef(obj.gasObject) as boolean &&
(typeof obj.events === "undefined" ||
Array.isArray(obj.events)) &&
(typeof obj.dependencies === "undefined" ||
Array.isArray(obj.dependencies) &&
obj.dependencies.every((e: any) =>
isTransactionDigest(e) as boolean
))
)
}
export function isTransactionEffectsResponse(obj: any, _argumentName?: string): obj is TransactionEffectsResponse {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isCertifiedTransaction(obj.certificate) as boolean &&
isTransactionEffects(obj.effects) as boolean
)
}
export function isGatewayTxSeqNumber(obj: any, _argumentName?: string): obj is GatewayTxSeqNumber {
return (
typeof obj === "number"
)
}
export function isGetTxnDigestsResponse(obj: any, _argumentName?: string): obj is GetTxnDigestsResponse {
return (
Array.isArray(obj) &&
obj.every((e: any) =>
Array.isArray(e) &&
isSequenceNumber(e[0]) as boolean &&
isTransactionDigest(e[1]) as boolean
)
)
}
export function isMoveCall(obj: any, _argumentName?: string): obj is MoveCall {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSuiObjectRef(obj.package) as boolean &&
isTransactionDigest(obj.module) as boolean &&
isTransactionDigest(obj.function) as boolean &&
(typeof obj.typeArguments === "undefined" ||
Array.isArray(obj.typeArguments) &&
obj.typeArguments.every((e: any) =>
isTransactionDigest(e) as boolean
)) &&
(typeof obj.arguments === "undefined" ||
Array.isArray(obj.arguments) &&
obj.arguments.every((e: any) =>
isSuiJsonValue(e) as boolean
))
)
}
export function isSuiJsonValue(obj: any, _argumentName?: string): obj is SuiJsonValue {
return (
(isTransactionDigest(obj) as boolean ||
isSequenceNumber(obj) as boolean ||
obj === false ||
obj === true ||
Array.isArray(obj) &&
obj.every((e: any) =>
(isTransactionDigest(e) as boolean ||
isSequenceNumber(e) as boolean ||
e === false ||
e === true)
))
)
}
export function isEmptySignInfo(obj: any, _argumentName?: string): obj is EmptySignInfo {
return (
typeof obj === "object"
)
}
export function isAuthorityName(obj: any, _argumentName?: string): obj is AuthorityName {
return (
typeof obj === "string"
)
}
export function isAuthoritySignature(obj: any, _argumentName?: string): obj is AuthoritySignature {
return (
typeof obj === "string"
)
}
export function isTransactionBytes(obj: any, _argumentName?: string): obj is TransactionBytes {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.txBytes) as boolean &&
isSuiObjectRef(obj.gas) as boolean
)
}
export function isMergeCoinResponse(obj: any, _argumentName?: string): obj is MergeCoinResponse {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isCertifiedTransaction(obj.certificate) as boolean &&
isSuiObject(obj.updatedCoin) as boolean &&
isSuiObject(obj.updatedGas) as boolean
)
}
export function isSplitCoinResponse(obj: any, _argumentName?: string): obj is SplitCoinResponse {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isCertifiedTransaction(obj.certificate) as boolean &&
isSuiObject(obj.updatedCoin) as boolean &&
Array.isArray(obj.newCoins) &&
obj.newCoins.every((e: any) =>
isSuiObject(e) as boolean
) &&
isSuiObject(obj.updatedGas) as boolean
)
}
export function isTransactionResponse(obj: any, _argumentName?: string): obj is TransactionResponse {
return (
((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionEffectsResponse(obj.EffectResponse) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSplitCoinResponse(obj.SplitCoinResponse) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isMergeCoinResponse(obj.MergeCoinResponse) as boolean)
)
}