-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcl.d.ts
1382 lines (1300 loc) · 47.8 KB
/
fcl.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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable @typescript-eslint/no-explicit-any */
// Type definitions for @onflow/fcl 1.3.0
// Project: https://github.com/onflow/fcl-js
declare module "@onflow/fcl" {
export namespace InteractionTemplateUtils {
function generateDependencyPin(opts: object): string;
function generateDependencyPinAtLatestSealedBlock(
opts: Record<string, unknown>
): string;
function generateTemplateId(opts: Record<string, unknown>): string;
function verifyInteractionTemplateAudit(
opts: Record<string, unknown>
): string;
function deriveCadenceByNetwork(opts: Record<string, unknown>): string;
}
// CONFIGURATION
export type Environment = "local" | "canarynet" | "testnet" | "mainnet";
/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#common-configuration-keys}
* @see {@link https://docs.onflow.org/fcl/reference/configure-fcl/}
*/
export interface ConfigurationOptions {
/**
* API URL for the Flow Blockchain Access Node you want to be communicating
* with. See all available access node endpoints
* [here]{@link https://docs.onflow.org/access-api/#flow-access-node-endpoints}.
*/
"accessNode.api": string;
/**
* Used in conjunction with stored interactions.
*/
env?: Environment;
/**
* Points FCL at the Wallet or Wallet Discovery mechanism.
*/
"discovery.wallet": string;
/**
* ALPHA - Endpoint for alternative configurable Wallet Discovery mechanism.
* Read more on
* [discovery]{@link https://docs.onflow.org/fcl/reference/api/#discovery}.
*/
"discovery.authn.endpoint"?: string;
/**
* Your applications title, can be requested by wallets and other services.
*/
"app.detail.title"?: string;
/**
* Url for your applications icon, can be requested by wallets and other
* services.
*/
"app.detail.icon"?: string;
}
export interface Configuration {
subscribe: any;
/**
* Set a configuration value.
*
* @param key - The key of the value to set. Must be one of the options for
* the configuration at initialization.
* @param value - The value to set.
*/
put(key: keyof ConfigurationOptions, value: string): Configuration;
/**
* Set a configuration value.
*
* @param key - The key of the value to set. May start with `'0x'`.
* Configuration keys that start with `'0x'` will be replaced in FCL scripts
* and transactions, this allows you to write your script or transaction
* Cadence code once and not have to change it when you point your
* application at a difference instance of the Flow Blockchain.
* @param value - The value to set.
*/
put(key: string, value: string | number): Configuration;
/**
* Get a configuration value.
*
* @param key - The key of the value to get.
* @param fallback - An optional fallback value to return in case the value
* was not set.
*/
get(
key: string,
fallback?: string | number
): Promise<string | number | undefined>;
}
/**
* FCL has a mechanism that lets you configure various aspects of FCL. The
* main idea here (from an FCL perspective) should be that when you move from
* one instance of the Flow Blockchain to another (Local Emulator to Testnet
* to Mainnet) the only thing you should need to change (once again from an
* FCL perspective) is your configuration.
*
* ```typescript
* import * as fcl from "@onflow/fcl"
*
* const configuration = fcl.config({
* "accessNode.api": "https://access-testnet.onflow.org",
* "discovery.wallet": "https://fcl-discovery.onflow.org/testnet/authn",
* "0xProfile": "0xba1132bc08f82fe2"
* });
*
* configuration.put('foo', 'bar');
* configuration.get('foo').then(console.log); // ↵ "bar"
* ```
*
* @param options - The initial configuration values.
*/
export function config(options?: ConfigurationOptions): Configuration;
// WALLET INTERACTIONS
/**
* @see {@link https://github.com/onflow/fcl-discovery/blob/master/data/services.json}
*/
export interface WalletService {
f_type: "Service";
f_vsn: string;
type: "authn";
method: string;
uid: string;
endpoint: string;
provider: {
address: Address;
name: string;
icon: string;
description: string;
color: string;
supportEmail: string;
website: string;
};
}
export interface AuthenticateOptions {
service: WalletService;
}
export function withPrefix(addr: string): string;
export function sansPrefix(addr: string): string;
/**
* Calling this method will authenticate the current user via any wallet that supports FCL.
* Once called, FCL will initiate communication with the configured `discovery.wallet`
* endpoint which lets the user select a wallet to authenticate with.
* Once the wallet provider has authenticated the user, FCL will set the values on the
* [current user object]{@link CurrentUserObject} for future use and authorization.
*
* @param options `authenticate` can also take a service returned from {@link discovery}
*
* @see {@link https://docs.onflow.org/fcl/reference/api/#authenticate}
*/
export function authenticate(options?: AuthenticateOptions): void;
// Ref: https://docs.onflow.org/fcl/reference/api/#unauthenticate
/**
* Logs out the current user and sets the values on the [current user object]{@link CurrentUserObject} to null.
*/
export function unauthenticate(): void;
/**
* A **convenience method** that calls {@link unauthenticate} and then {@link authenticate} for the current user.
* @see {@link https://docs.onflow.org/fcl/reference/api/#reauthenticate}
*/
export function reauthenticate(): void;
/**
* A **convenience method** that calls and is equivalent to {@link authenticate}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#signup}
*/
export function signUp(): void;
/**
* A **convenience method** that calls and is equivalent to {@link authenticate}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#login}
*/
export function logIn(): void;
/**
* A **convenience method** that produces the needed authorization details for the
* current user to submit transactions to Flow. It defines a signing function that
* connects to a user's wallet provider to produce signatures to submit transactions.
* @see {@link https://docs.onflow.org/fcl/reference/api/#authz}
*/
export function authz(): AuthorizationObject;
/**
* Holds the [current user]{@link CurrentUserObject}, if set, and offers a set of
* functions to manage the authentication and authorization of the user.
*/
export function currentUser(): CurrentUserObject;
export namespace currentUser {
/**
* @param callback The callback will be called with the [current user]{@link CurrentUserObject}
* as the first argument when the current user is set or removed.
*/
function subscribe(callback: (user: CurrentUserObject) => void): void;
/**
* Returns the [current user object]{@link CurrentUserObject}.
* This is the same object that is set and available on {@link subscribe}.
*/
function snapshot(): CurrentUserObject;
/**
* Equivalent to {@link fcl.authenticate}.
* @param options `authenticate` can also take a service returned from {@link fcl.discovery}
*/
function authenticate(options?: AuthenticateOptions): void;
/**
* Equivalent to {@link fcl.unauthenticate}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#currentuserunauthenticate}
*/
function unauthenticate(): void;
/**
* Equivalent to {@link fcl.authz}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#currentuserauthorization}
*/
function authorization(): void;
/**
* A method to use allowing the user to personally sign data via FCL Compatible Wallets/Services.
* @param message A hexadecimal string to be signed
* @see {@link https://docs.onflow.org/fcl/reference/api/#currentusersignusermessage}
*/
function signUserMessage(message: string): Promise<CompositeSignature[]>;
}
/**
* @see {@link https://github.com/onflow/fcl-js/blob/master/packages/fcl/src/wallet-provider-spec/draft-v2.md#compositesignature}
*/
export interface CompositeSignature {
f_type: string;
f_vsn: string;
addr: Address;
keyId: number;
signature: string;
}
/**
* Discovery abstracts away code so that developers don't have to deal with the
* discovery of Flow compatible wallets, integration, or authentication.
* Using `discovery` from FCL allows dapps to list and authenticate with
* wallets while having full control over the UI.
* Common use cases for this are login or registration pages.
* (Alternatively, if you don't need control over your UI you can
* continue to use the `discovery.wallet` config value documented
* in the Quickstart for the simplest configuration.)
* @see {@link https://docs.onflow.org/fcl/reference/api/#discovery-1}
*/
export namespace discovery {
/**
* By default, limited functionality services, like Ledger,
* require apps to opt-in in order to display to users.
* This is so users don't authenticate only to later find out
* certain services cannot complete certain actions.
* To enable specific limited functionality services in an application,
* use the `discovery.authn.include` property in your configuration
* with a value of an array of services you'd like your app to
* opt-in to displaying for users.
* @see {@link https://docs.onflow.org/fcl/reference/api/#authn}
*/
namespace authn {
/**
* Return a list of `authn` services.
* @see {@link https://docs.onflow.org/fcl/reference/api/#discoveryauthnsnapshot}
*/
function snapshot(): Promise<WalletService[]>;
/**
* @param callback The callback sent to `subscribe` will be called with a list of `authn` services.
* @see {@link https://docs.onflow.org/fcl/reference/api/#discoveryauthnsubscribecallback}
*/
// TODO: check syntax of param in https://github.com/onflow/fcl-js or with FCL dev team
function subscribe(
callback: (res: { results: WalletService[] }) => void
): void;
}
}
// ON-CHAIN INTERACTIONS
export interface QueryOptions {
/**
* A valid cadence script.
*/
cadence: string;
/**
* Any arguments to the script if needed should be supplied via
* a function that returns an array of arguments.
*/
args?: ArgumentFunction;
/**
* Compute (Gas) limit for query. Read the documentation about
* computation cost for information about how computation cost is calculated on Flow.
*/
limit?: number;
}
/**
* Allows you to submit scripts to query the blockchain.
* @param options Pass in the following as a single object with the following keys.
* All keys are optional unless otherwise stated.
* @see {@link https://docs.onflow.org/fcl/reference/api/#query}
*/
export function query(options: QueryOptions): Promise<any>;
export interface MutateOptions {
/**
* A valid cadence transaction.
*/
cadence: string;
/**
* Any arguments to the script if needed should be supplied via a function that returns an array of arguments.
*/
args?: ArgumentFunction;
/**
* Compute (Gas) limit for query. Read the documentation about computation
* cost for information about how computation cost is calculated on Flow.
*/
limit?: number;
/**
* The authorization function that returns a valid {@link AuthorizationObject} for the proposer role.
*/
proposer?: AuthorizationFunction;
}
/**
* Allows you to submit transactions to the blockchain to potentially mutate the state.
* ⚠️When being used in the browser, `fcl.mutate` uses the built-in `fcl.authz` function
* to produce the authorization (signatures) for the current user.
* When calling this method from Node.js, you will need to supply your own custom authorization function.
* @param options
* @returns The transaction ID.
* @see {@link https://docs.onflow.org/fcl/reference/api/#mutate}
*/
export function mutate(options: MutateOptions): Promise<string>;
export interface CompositeSignatures {
f_type: string;
f_vsn: string;
addr: Address;
keyId: string;
signature: string;
}
/**
* A method allowing applications to cryptographically verify the ownership of a
* Flow account by verifying a message was signed by a user's private key/s.
* This is typically used with the response from `currentUser.signUserMessage`.
* @param message A hexadecimal string
* @param compositeSignatures An Array of CompositeSignatures
* @return true if verifed
* @see {@link https://docs.onflow.org/fcl/reference/api/#verifyusersignatures}
*/
export function verifyUserSignatures(
message: string,
compositeSignatures: CompositeSignatures[]
): Promise<boolean>;
/**
* Sends arbitrary scripts, transactions, and requests to Flow.
* This method consumes an array of builders that are to be resolved and sent.
* The builders required to be included in the array depend on the interaction that is being built.
* @param builders
* @returns An object containing the data returned from the chain.
* Should always be decoded with `fcl.decode()` to get back appropriate JSON keys and values.
* @see {@link https://docs.onflow.org/fcl/reference/api/#send}
*/
export function send(builders: Builders[]): Promise<ResponseObject>;
/**
* Decodes the response from `fcl.send()` into the appropriate JSON
* representation of any values returned from Cadence code.
* @param response Should be the response returned from `fcl.send([...])`
* @returns A JSON representation of the raw string response depending on the cadence code executed.
* The return value can be a single value and type or an object with multiple types.
* @see {@link https://docs.onflow.org/fcl/reference/api/#decode}
*/
export function decode(response: ResponseObject): any;
/**
* A builder function that returns the interaction to get an account by address.
* ⚠️Consider using the pre-built interaction {@link account} if you do not need to pair with any other builders.
* @param address Address of the user account with or without a prefix (both formats are supported).
* @returns A JSON representation of a user account.
* @see {@link https://docs.onflow.org/fcl/reference/api/#getaccount}
*/
export function getAccount(address: Address): AccountObject;
/**
* A builder function that returns the interaction to get the latest block.
* 📣 Use with {@link atBlockId} and {@link atBlockHeight} when building
* the interaction to get information for older blocks.
* ⚠️Consider using the pre-built interaction {@link latestBlock}
* if you do not need to pair with any other builders.
* @param isSealed If the latest block should be sealed or not.
* @returns The latest block if not used with any other builders.
* @see {@link https://docs.onflow.org/fcl/reference/api/#getblock}
*/
export function getBlock(isSealed?: boolean): BlockObject;
/**
* A builder function that returns a partial interaction to a block at a specific height.
* ⚠️Use with other interactions like {@link getBlock} to get a full interaction at the specified block height.
* @param blockHeight The height of the block to execute the interaction at.
* @returns A partial interaction to be paired with another interaction such as {@link getBlock} or {@link getAccount}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#atblockheight}
*/
export function atBlockHeight(blockHeight: number): Partial<Interaction>;
/**
* A builder function that returns a partial interaction to a block at a specific block ID.
* ⚠️Use with other interactions like {@link getBlock} to get a full interaction at the specified block block ID.
* @param blockId The ID of the block to execute the interaction at.
* @returns A partial interaction to be paired with another interaction such as {@link getBlock} or {@link getAccount}.
* @see {@link https://docs.onflow.org/fcl/reference/api/#atblockid}
*/
export function atBlockId(blockId: string): Partial<Interaction>;
/**
* A builder function that returns the interaction to get a block header.
* 📣 Use with {@link atBlockId} and {@link atBlockHeight} when building
* the interaction to get information for older blocks.
* @returns The latest block header if not used with any other builders.
* @see {@link https://docs.onflow.org/fcl/reference/api/#getblockheader}
*/
export function getBlockHeader(): BlockHeaderObject;
/**
* A builder function that returns all instances of a particular event (by name) within a height range.
* ⚠️The block range provided must be from the current spork.
* ⚠️The block range provided must be 250 blocks or lower per request.
* @param eventName The name of the event.
* @param fromBlockHeight The height of the block to start looking for events (inclusive).
* @param toBlockHeight The height of the block to stop looking for events (inclusive).
* @returns An array of events that matched the eventName.
* @see {@link https://docs.onflow.org/fcl/reference/api/#geteventsatblockheightrange}
*/
export function getEventsAtBlockHeightRange(
eventName: EventName,
fromBlockHeight: number,
toBlockHeight: number
): EventObject[];
/**
* A builder function that returns all instances of a particular event (by name)
* within a set of blocks, specified by block ids.
* ⚠️The block range provided must be from the current spork.
* @param eventName The name of the event.
* @param blockIds The ids of the blocks to scan for events.
* @returns An array of events that matched the eventName.
* @see {@link https://docs.onflow.org/fcl/reference/api/#geteventsatblockids}
*/
export function getEventsAtBlockIds(
eventName: EventName,
blockIds: string[]
): EventObject[];
/**
* A builder function that returns all a collection containing a list of transaction ids by its collection id.
* ⚠️The block range provided must be from the current spork.
* All events emitted during past sporks is current unavailable.
* @param collectionID The id of the collection.
* @returns An object with the id and a list of transactions within the requested collection.
*/
export function getCollection(collectionID: string): CollectionObject;
/**
* A builder function that returns the status of transaction.
* ⚠️The transactionID provided must be from the current spork.
* 📣 Consider [subscribing to the transaction from fcl.tx(id)]{@link tx} instead of calling this method directly.
* @param transactionId The transactionID returned when submitting a transaction. Example: 9dda5f281897389b99f103a1c6b180eec9dac870de846449a302103ce38453f3
* @see {@link https://docs.onflow.org/fcl/reference/api/#gettransactionstatus}
*/
export function getTransactionStatus(
transactionId: string
): TransactionObject & {
/**
* The status as as descriptive text (e.g. "FINALIZED").
*/
statusString: string;
};
/**
* A builder function that returns a {@link TransactionObject} once decoded.
* ⚠️The transactionID provided must be from the current spork.
* 📣 Consider using {@link tx} instead of calling this method directly.
* @param transactionId The transactionID returned when submitting a transaction. Example: 9dda5f281897389b99f103a1c6b180eec9dac870de846449a302103ce38453f3
* @see {@link https://docs.onflow.org/fcl/reference/api/#gettransaction}
*/
export function getTransaction(transactionId: string): TransactionObject;
/**
* A utility builder to be used with `fcl.args[...]` to create FCL supported arguments for interactions.
* @param value Any value that you are looking to pass to other builders.
* @param type A type supported by Flow.
* @returns Holds the value and type passed in.
* @see {@link https://docs.onflow.org/fcl/reference/api/#arg}
*/
export function arg(value: any, type: FType): ArgumentObject;
/**
* A utility builder to be used with other builders to pass in arguments with a value and supported type.
* @param args An array of arguments that you are looking to pass to other builders.
* @returns An interaction that contains the arguments and types passed in. This alone is a partial and incomplete interaction.
* @see {@link https://docs.onflow.org/fcl/reference/api/#args}
*/
export function args(args: ArgumentObject[]): Partial<Interaction>;
/**
* A template builder to use a Cadence script for an interaction.
* 📣 Use with {@link args} to pass in arguments dynamically.
* @param CODE Should be valid Cadence script.
* @returns An interaction containing the code passed in.
* @see {@link https://docs.onflow.org/fcl/reference/api/#script}
*/
export function script(CODE: string): Interaction;
/**
* A template builder to use a Cadence transaction for an interaction.
* ⚠️Must be used with {@link payer}, {@link proposer}, {@link authorizations}
* to produce a valid interaction before sending to the chain.
* 📣 Use with {@link args} to pass in arguments dynamically.
* @param CODE Should be valid a Cadence transaction.
* @returns An partial interaction containing the code passed in.
* Further builders are required to complete the interaction - see warning.
* @see {@link https://docs.onflow.org/fcl/reference/api/#transaction}
*/
export function transaction(CODE: string): Partial<Interaction>;
/**
* A pre-built interaction that returns the details of an account from their public address.
* @param address Address of the user account with or without a prefix (both formats are supported).
* @see {@link https://docs.onflow.org/fcl/reference/api/#transaction}
*/
export function account(address: Address): Promise<AccountObject>;
/**
* A pre-built interaction that returns the latest block (optionally sealed or not), by id, or by height.
* @param sealed If the latest block should be sealed or not.
* @param id ID of block to get.
* @param height Height of block to get.
* @returns A JSON representation of a block.
* @see {@link https://docs.onflow.org/fcl/reference/api/#block}
*/
export function block(options?: {
sealed?: boolean;
id?: string;
height?: number;
}): Promise<BlockObject>;
/**
* A utility function that lets you set the transaction to get subsequent
* status updates (via polling) and the finalized result once available.
* The poll rate is set at 2500ms and will update at that interval until
* transaction is sealed.
*
* @param transactionId A valid transaction id.
* @see {@link https://docs.onflow.org/fcl/reference/api/#tx}
*/
export function tx(transactionId: string): {
/**
* Returns the current state of the transaction.
*/
// TODO: check return type in https://github.com/onflow/fcl-js or with FCL dev team
snapshot(): TransactionObject;
/**
* Calls the callback passed in with the new transaction on a status change.
*/
subscribe(callback: (tx: TransactionObject) => void): void;
/**
* Provides the transaction once status 2 is returned.
*/
onceFinalized(): Promise<TransactionObject>;
/**
* Provides the transaction once status 3 is returned.
*/
onceExecuted(): Promise<TransactionObject>;
/**
* Provides the transaction once status 4 is returned.
*/
onceSealed(): Promise<TransactionObject>;
};
/**
* A utility function that lets you set the transaction to get subsequent status
* updates (via polling) and the finalized result once available.
* ⚠️The poll rate is set at 10000ms and will update at that interval for getting new events.
* @param eventName A valid event name.
* @see {@link https://docs.onflow.org/fcl/reference/api/#events}
*/
export function events(eventName: string): {
/**
* Calls the callback passed in with the new event.
*/
subscribe(callback: (tx: EventObject) => void): void;
};
// TYPES, INTERFACES, AND DEFINITIONS
// TODO: How to better leverage TypeScript to say that Builders us the union of all builder methods:
// getAccount, getBlock, atBlockHeight, atBlockId, getBlockHeader, getEventsAtBlockHeightRange, getEventsAtBlockIds,
// getCollection, getTransactionStatus, getTransaction, arg, script, transaction, account, block
/**
* Builders are modular functions that can be coupled together with `fcl.send([...builders])``
* to create an {@link Interaction}. The builders needed to create an interaction
* depend on the script or transaction that is being sent.
* @see {@link https://docs.onflow.org/fcl/reference/api/#builders-1}
*/
export type Builders = any;
// TODO: Double check with FCL dev team if Interaction needs to be added from https://github.com/onflow/fcl-js/blob/master/packages/sdk/src/interaction/interaction.js#L66
/**
* An interaction is an object containing the information to perform an action on chain.
* This object is populated through builders and converted into the approriate access node API call.
* A 'partial' interaction is an interaction object that does not have sufficient
* information to the intended on-chain action. Multiple partial interactions (through builders)
* can be coupled to create a complete interaction.
* @see {@link https://docs.onflow.org/fcl/reference/api/#interaction}
* @see {@link https://github.com/onflow/fcl-js/blob/master/packages/sdk/src/interaction/interaction.js#L66}
*/
export type Interaction = object;
/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#currentuserobject}
*/
export interface CurrentUserObject {
[x: string]: any;
/**
* The public address of the current user
*/
addr: Address | undefined;
/**
* Allows wallets to specify a content identifier for user metadata.
*/
cid: string | undefined;
/**
* Allows wallets to specify a time-frame for a valid session.
*/
expiresAt: number | undefined;
/**
* A type identifier used internally by FCL.
*/
f_type: string;
/**
* FCL protocol version.
*/
f_vsn: string;
/**
* If the user is logged in.
*/
loggedIn: boolean | null | undefined;
/**
* A list of trusted services that express ways of interacting with the current user's identity,
* including means to further discovery, authentication, authorization, or other kinds of interactions.
*/
services: object[];
}
/**
* An authorization function must produce the information of the user that is going
* to sign and a signing function to use the information to produce a signature.
*
* 📣 By default FCL exposes `fcl.authz` that produces the authorization object
* for the current user (given they are signed in and only on the browser).
* Replace this with your own function that conforms to this interface to
* use it wherever an authorization object is needed.
* @see {@link https://docs.onflow.org/fcl/reference/api/#authorizationobject}
*/
export interface AuthorizationObject {
/**
* The address of the authorizer
*/
addr: Address;
/**
* A function that allows FCL to sign using the authorization details and produce a valid signature.
*/
signingFunction: SigningFunction;
/**
* The index of the key to use during authorization. (Multiple keys on an account is possible).
*/
keyId: number;
/**
* A number that is incremented per transaction using they keyId.
*/
sequenceNum: number;
}
/**
* An object that contains all the information needed for FCL to sign a message with the user's signature.
* @see {@link https://docs.onflow.org/fcl/reference/api/#signableobject}
*/
export interface SignableObject {
/**
* The address of the authorizer
*/
addr: Address;
/**
* The index of the key to use during authorization. (Multiple keys on an account is possible).
*/
keyId: number;
/**
* A {@link SigningFunction} that can produce a valid signature for a user from a message.
*/
signature: SigningFunction;
}
/**
* The JSON representation of an account on the Flow blockchain.
* @see {@link https://docs.onflow.org/fcl/reference/api/#accountobject}
*/
export interface AccountObject {
/**
* The address of the account
*/
address: Address;
/**
* The FLOW balance of the account in 10*6.
*/
balance: number;
/**
* The code of any Cadence contracts stored in the account.
*/
code: string;
/**
* An object with keys as the contract name deployed and the value as the the cadence string.
*/
contracts: Contract;
/**
* Any contracts deployed to this account.
*/
keys: KeyObject[];
}
/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#address}
*/
export type Address = string;
/**
* An argument object created by `fcl.arg(value,type)`
* @see {@link https://docs.onflow.org/fcl/reference/api/#argumentobject}
*/
export interface ArgumentObject {
/**
* Any value to be used as an argument to a builder.
*/
value: any;
/**
* Any of the supported types on Flow.
*/
xform: FType;
}
/**
* An function that takes the `fcl.arg` function and fcl types `t`
* and returns an array of `fcl.arg(value,type)`.
* @see {@link https://docs.onflow.org/fcl/reference/api/#argumentfunction}
*/
export type ArgumentFunction = (
arg: (value: any, xform: FType) => ArgumentObject,
t: FType
) => ArgumentObject[];
/**
* An authorization function must produce the information of the user that
* is going to sign and a signing function to use the information to produce a signature.
* 📣 By default FCL exposes `fcl.authz` that produces the authorization object
* for the current user (given they are signed in and only on the browser).
* Replace this with your own function that conforms to this interface
* to use it wherever an authorization object is needed.
* @param account The account of the user that is going to sign.
* @returns The object that contains all the information needed by FCL to authorize a user's transaction.
* @see {@link https://docs.onflow.org/fcl/reference/api/#authorization-function}
*/
export type AuthorizationFunction = (
account: AccountObject
) => Promise<AuthorizationObject>;
/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#payload}
*/
export interface SigningPayload {
/**
* The encoded string which needs to be used to produce the signature.
*/
message: string;
/**
* The encoded string which needs to be used to produce the signature.
*/
addr: Address;
/**
* The encoded string which needs to be used to produce the signature.
*/
keyId: string;
/**
* The encoded string which needs to be used to produce the signature.
*/
roles: string;
/**
* The raw transactions information, can be used to create the message
* for additional safety and lack of trust in the supplied message.
*/
voucher: object;
}
/**
* Consumes a payload and produces a signature for a transaction.
* @see {@link https://docs.onflow.org/fcl/reference/api/#signing-function}
*/
export type SigningFunction = (
options: SigningPayload
) => Promise<SignableObject>;
/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#transactionrolesobject}
*/
export interface TransactionRolesObject {
/**
* A Boolean representing if this signature to be produced for a proposer.
*/
proposer: boolean;
/**
* A Boolean representing if this signature to be produced for an authorizer.
*/
authorizer: boolean;
/**
* A Boolean representing if this signature to be produced for a payer.
*/
payer: boolean;
}
/**
* A event name in Flow must follow the format `A.{AccountAddress}.{ContractName}.{EventName}`
* eg. `A.ba1132bc08f82fe2.Debug.Log`
* @see {@link https://docs.onflow.org/fcl/reference/api/#eventname}
*/
export type EventName = string;
/**
* A formatted string that is a valid cadence contract.
* @see {@link https://docs.onflow.org/fcl/reference/api/#contract}
*/
export type Contract = string;
/**
* @see {@link https://github.com/onflow/fcl-js/blob/9cf62bfaabb02444e6daa24b1ee10faeed40f732/packages/util-encode-key/src/index.js#L4}
*/
export enum Curve {
ECDSA_P256 = 2,
ECDSA_secp256k1 = 3,
}
/**
* @see {@link https://github.com/onflow/fcl-js/blob/9cf62bfaabb02444e6daa24b1ee10faeed40f732/packages/util-encode-key/src/index.js#L9}
*/
export enum Hash {
SHA2_256 = 1,
SHA3_256 = 3,
}
/**
* This is the JSON representation of a key on the Flow blockchain.
* @see {@link https://docs.onflow.org/fcl/reference/api/#keyobject}
*/
export interface KeyObject {
/**
* The address of the account
*/
index: number;
publicKey: string;
/**
* An index referring to one of ECDSA_P256 or ECDSA_secp256k1
*/
signAlgo: Curve;
/**
* An index referring to one of SHA2_256 or SHA3_256
*/
hashAlgo: Hash;
signAlgoString: string;
hashAlgoString: string;
/**
* A number between 1 and 1000 indicating the relative weight to other keys on the account.
*/
weight: number;
/**
* This number is incremented for every transaction signed using this key.
*/
sequenceNumber: number;
/**
* If this key has been disabled for use.
*/
revoked: boolean;
}
// TODO: Double check with FCL dev team where I can find types for SealedBlockObject (they are absent from docs https://docs.onflow.org/fcl/reference/api/#blockobject)
export type SealedBlockObject = object;
/**
* The JSON representation of a key on the Flow blockchain.
* @see {@link https://docs.onflow.org/fcl/reference/api/#blockobject}
*/
export type BlockObject = BlockHeaderObject & {
/**
* Contains the ids of collections included in the block.
*/
collectionGuarantees: CollectionGuaranteeObject[];
/**
* The details of which nodes executed and sealed the blocks.
*/
blockSeals: SealedBlockObject[];
/**
* All signatures.
*/
signatures: number[];
};
/**
* The subset of the {@link BlockObject} containing only the header values of a block.
* @see {@link https://docs.onflow.org/fcl/reference/api/#blockheaderobject}
*/
export interface BlockHeaderObject {
/**
* The id of the block.
*/
id: string;
/**
* The id of the parent block.
*/
parentId: string;
/**
* The height of the block.
*/
height: number;
/**
* Contains time related fields.
*/
timestamp: object;
}
/**
* A collection that has been included in a block.
* @see {@link https://docs.onflow.org/fcl/reference/api/#collectionguaranteeobject}
*/
export interface CollectionGuaranteeObject {
/**
* The id of the block.
*/
collectionId: string;
/**
* All signatures.
*/
signatures: SignableObject[];
}
/**
* A collection is a list of transactions that are contained in the same block.
* @see {@link https://docs.onflow.org/fcl/reference/api/#collectionobject}
*/
export interface CollectionObject {
/**
* The id of the collection.
*/
id: string;
/**
* The ids of the transactions included in the collection.
*/
transactionIds: string[];
}
interface Signature {
/**
* Sequence number of the key used to perform this signature
*/
sequenceNumber: string;
/**
* ID of the key in the account used to perform this signature
*/
keyId: number;
/**
* The signature
*/
signature: string;
}
/**
* The format of all responses in FCL returned from `fcl.send(...)`.
* For full details on the values and descriptions of the keys, view here.
* @see {@link https://docs.onflow.org/fcl/reference/api/#responseobject}
* @see {@link https://github.com/onflow/fcl-js/tree/master/packages/sdk/src/response#internal-properties}
*/
export interface ResponseObject {
/**
* A marker that represents the type of the response. See {@link Interaction} for information on the possible tag values.