@frak-labs/core-sdk 0.0.7 → 0.0.9

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.
@@ -0,0 +1,1300 @@
1
+ import type { Address } from 'viem';
2
+ import { Hex } from 'viem';
3
+ import type { Prettify } from 'viem/chains';
4
+ import type { RpcSchema } from 'viem';
5
+ import type { SiweMessage } from 'viem/siwe';
6
+
7
+ /**
8
+ * All the currencies available
9
+ */
10
+ declare type Currency = "eur" | "usd" | "gbp";
11
+
12
+ /**
13
+ * Function used to display the Frak embeded wallet popup
14
+ * @param client - The current Frak Client
15
+ * @param params - The parameter used to customise the embeded wallet
16
+ */
17
+ export declare function displayEmbededWallet(client: FrakClient, params: DisplayEmbededWalletParamsType): Promise<void>;
18
+
19
+ /**
20
+ * The params used to display the embeded wallet
21
+ *
22
+ * @group Embeded wallet
23
+ */
24
+ declare type DisplayEmbededWalletParamsType = {
25
+ /**
26
+ * The embeded view to display once the user is logged in
27
+ */
28
+ loggedIn?: LoggedInEmbededView;
29
+ /**
30
+ * The embeded view to display once the user is logged out
31
+ */
32
+ loggedOut?: LoggedOutEmbededView;
33
+ /**
34
+ * Some metadata to customise the embeded view
35
+ */
36
+ metadata?: {
37
+ /**
38
+ * The logo to display on the embeded wallet
39
+ * If undefined, will default to no logo displayed
40
+ */
41
+ logo?: string;
42
+ /**
43
+ * Link to the homepage of the calling website
44
+ * If unedfined, will default to the domain of the calling website
45
+ */
46
+ homepageLink?: string;
47
+ /**
48
+ * The target interaction behind this modal
49
+ */
50
+ targetInteraction?: FullInteractionTypesKey;
51
+ /**
52
+ * The position of the component
53
+ */
54
+ position?: "left" | "right";
55
+ };
56
+ };
57
+
58
+ /**
59
+ * Function used to display a modal
60
+ * @param client - The current Frak Client
61
+ * @param args
62
+ * @param args.steps - The different steps of the modal
63
+ * @param args.metadata - The metadata for the modal (customisation, etc)
64
+ * @returns The result of each modal steps
65
+ *
66
+ * @description This function will display a modal to the user with the provided steps and metadata.
67
+ *
68
+ * @remarks
69
+ * - The UI of the displayed modal can be configured with the `customCss` property in the `metadata.css` field of the top-level config.
70
+ * - The `login` and `openSession` steps will be automatically skipped if the user is already logged in or has an active session. It's safe to include these steps in all cases to ensure proper user state.
71
+ * - Steps are automatically reordered in the following sequence:
72
+ * 1. `login` (if needed)
73
+ * 2. `openSession` (if needed)
74
+ * 3. All other steps in the order specified
75
+ * 4. `success` (if included, always last)
76
+ *
77
+ * @example
78
+ * Simple sharing modal with steps:
79
+ * 1. Login (Skipped if already logged in)
80
+ * 2. Open a session (Skipped if already opened)
81
+ * 3. Display a success message with sharing link option
82
+ *
83
+ * ```ts
84
+ * const results = await displayModal(frakConfig, {
85
+ * steps: {
86
+ * // Simple login with no SSO, nor customisation
87
+ * login: { allowSso: false },
88
+ * // Simple session opening, with no customisation
89
+ * openSession: {},
90
+ * // Success message
91
+ * final: {
92
+ * action: { key: "reward" },
93
+ * // Skip this step, it will be only displayed in the stepper within the modal
94
+ * autoSkip: true,
95
+ * },
96
+ * },
97
+ * });
98
+ *
99
+ * console.log("Login step - wallet", results.login.wallet);
100
+ * console.log("Open session step - start + end", {
101
+ * start: results.openSession.startTimestamp,
102
+ * end: results.openSession.endTimestamp,
103
+ * });
104
+ * ```
105
+ *
106
+ * @example
107
+ * A full modal example, with a few customisation options, with the steps:
108
+ * 1. Login (Skipped if already logged in)
109
+ * 2. Open a session (Skipped if already opened)
110
+ * 3. Authenticate via SIWE
111
+ * 4. Send a transaction
112
+ * 5. Display a success message with sharing link options
113
+ *
114
+ * ```ts
115
+ * const results = await displayModal(frakConfig, {
116
+ * steps: {
117
+ * // Login step
118
+ * login: {
119
+ * allowSso: true,
120
+ * ssoMetadata: {
121
+ * logoUrl: "https://my-app.com/logo.png",
122
+ * homepageLink: "https://my-app.com",
123
+ * },
124
+ * metadata: {
125
+ * // Modal title on desktop
126
+ * title: "Login on My-App",
127
+ * // Modal description (and yep it accept markdown)
128
+ * description: "## Please login to continue",
129
+ * // Primary button text
130
+ * primaryActionText: "Register",
131
+ * // Secondary button text
132
+ * secondaryActionText: "Login",
133
+ * },
134
+ * },
135
+ * // Simple session opening, with no customisation
136
+ * openSession: {},
137
+ * // Siwe authentication
138
+ * siweAuthenticate: {
139
+ * siwe: {
140
+ * domain: "my-app.com",
141
+ * uri: "https://my-app.com/",
142
+ * nonce: generateSiweNonce(),
143
+ * version: "1",
144
+ * },
145
+ * metadata: {
146
+ * title: "Authenticate with SIWE",
147
+ * description: "Please authenticate with SIWE to continue",
148
+ * primaryActionText: "Authenticate",
149
+ * },
150
+ * },
151
+ * // Send batched transaction
152
+ * sendTransaction: {
153
+ * tx: [
154
+ * { to: "0xdeadbeef", data: "0xdeadbeef" },
155
+ * { to: "0xdeadbeef", data: "0xdeadbeef" },
156
+ * ],
157
+ * metadata: {
158
+ * title: "Send a transaction",
159
+ * description: "Please send a transaction to continue",
160
+ * },
161
+ * },
162
+ * // Success message with sharing options
163
+ * final: {
164
+ * action: {
165
+ * key: "sharing",
166
+ * options: {
167
+ * popupTitle: "Share the app",
168
+ * text: "Discover my super app website",
169
+ * link: "https://my-app.com",
170
+ * },
171
+ * },
172
+ * dismissedMetadata: {
173
+ * title: "Dismiss",
174
+ * description: "You won't be rewarded for this sharing action",
175
+ * },
176
+ * },
177
+ * },
178
+ * metadata: {
179
+ * // Header of desktop modals
180
+ * header: {
181
+ * title: "My-App",
182
+ * icon: "https://my-app.com/logo.png",
183
+ * },
184
+ * // Context that will be present in every modal steps
185
+ * context: "My-app overkill flow",
186
+ * },
187
+ * });
188
+ * ```
189
+ */
190
+ export declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, { steps, metadata }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
191
+
192
+ /**
193
+ * Params used to display a modal
194
+ * @typeParam T - The list of modal steps we expect to have in the modal
195
+ * @group Modal Display
196
+ */
197
+ declare type DisplayModalParamsType<T extends ModalStepTypes[]> = {
198
+ steps: ModalRpcStepsInput<T>;
199
+ metadata?: ModalRpcMetadata;
200
+ };
201
+
202
+ /**
203
+ * The different type of action we can have on the embeded view (once the user is logged in)
204
+ *
205
+ * @group Embeded wallet
206
+ */
207
+ declare type EmbededViewAction = {
208
+ key: "sharing";
209
+ /**
210
+ * Some sharing options
211
+ */
212
+ options?: {
213
+ /**
214
+ * The title that will be displayed on the system popup once the system sharing window is open
215
+ */
216
+ popupTitle?: string;
217
+ /**
218
+ * The text that will be shared alongside the link.
219
+ * Can contain the variable {LINK} to specify where the link is placed, otherwise it will be added at the end
220
+ */
221
+ text?: string;
222
+ /**
223
+ * The link to be shared (will be suffixed with the Frak sharing context)
224
+ */
225
+ link?: string;
226
+ };
227
+ };
228
+
229
+ /**
230
+ * Type that extract the possible return type from a RPC Schema
231
+ * @ignore
232
+ */
233
+ declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
234
+ Method: TMethod;
235
+ }>;
236
+
237
+ /**
238
+ * Type that extract the possible parameters from a RPC Schema
239
+ * @ignore
240
+ */
241
+ declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
242
+ [K in keyof TRpcSchema]: Prettify<{
243
+ method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
244
+ } & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
245
+ params?: never;
246
+ } : {
247
+ params: TRpcSchema[K]["Parameters"];
248
+ } : never)>;
249
+ }[number];
250
+
251
+ /**
252
+ * Type that extract the possible return type from a RPC Schema
253
+ * @ignore
254
+ */
255
+ declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
256
+
257
+ /**
258
+ * The different types of final actions we can display in the final step
259
+ * @group Modal Display
260
+ */
261
+ declare type FinalActionType = {
262
+ key: "sharing";
263
+ options?: {
264
+ popupTitle?: string;
265
+ text?: string;
266
+ link?: string;
267
+ };
268
+ } | {
269
+ key: "reward";
270
+ options?: never;
271
+ };
272
+
273
+ /**
274
+ * The final modal step type, could be used to display sharing options or a success reward screen.
275
+ *
276
+ * **Input**: What type final step to display?
277
+ * **Output**: None
278
+ *
279
+ * @group Modal Display
280
+ */
281
+ declare type FinalModalStepType = GenericModalStepType<"final", {
282
+ dismissedMetadata?: ModalStepMetadata["metadata"];
283
+ action: FinalActionType;
284
+ autoSkip?: boolean;
285
+ }, object>;
286
+
287
+ /**
288
+ * Representing a Frak client, used to interact with the Frak Wallet
289
+ */
290
+ declare type FrakClient = {
291
+ config: FrakWalletSdkConfig;
292
+ debugInfo: {
293
+ formatDebugInfo: (error: Error | unknown | string) => string;
294
+ };
295
+ } & IFrameTransport;
296
+
297
+ /**
298
+ * The current Frak Context
299
+ *
300
+ * For now, only contain a referrer address.
301
+ */
302
+ declare type FrakContext = {
303
+ r: Address;
304
+ };
305
+
306
+ /**
307
+ * Configuration for the Nexus Wallet SDK
308
+ */
309
+ declare type FrakWalletSdkConfig = {
310
+ /**
311
+ * The Frak wallet url
312
+ * @defaultValue "https://wallet.frak.id"
313
+ */
314
+ walletUrl?: string;
315
+ /**
316
+ * Some metadata about your implementation of the Frak SDK
317
+ */
318
+ metadata: {
319
+ /**
320
+ * Your application name (will be displayed in a few modals and in SSO)
321
+ */
322
+ name: string;
323
+ /**
324
+ * Custom CSS styles to apply to the modals and components
325
+ */
326
+ css?: string;
327
+ /**
328
+ * Language to display in the modal
329
+ * If undefined, will default to the browser language
330
+ */
331
+ lang?: "fr" | "en";
332
+ /**
333
+ * The currency to display in the modal
334
+ * @defaultValue `"eur"`
335
+ */
336
+ currency?: Currency;
337
+ };
338
+ /**
339
+ * The domain name of your application
340
+ * @defaultValue window.location.host
341
+ */
342
+ domain?: string;
343
+ };
344
+
345
+ /**
346
+ * The keys for each interaction types (e.g. `press.openArticle`) -> category_type.interaction_type
347
+ * @inline
348
+ */
349
+ declare type FullInteractionTypesKey = {
350
+ [Category in keyof typeof interactionTypes]: `${Category & string}.${keyof (typeof interactionTypes)[Category] & string}`;
351
+ }[keyof typeof interactionTypes];
352
+
353
+ /**
354
+ * Represent a generic modal step type
355
+ * @ignore
356
+ * @inline
357
+ */
358
+ declare type GenericModalStepType<TKey, TParams, TReturns> = {
359
+ key: TKey;
360
+ params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
361
+ returns: TReturns;
362
+ };
363
+
364
+ /**
365
+ * Function used to get the current product information
366
+ * @param client - The current Frak Client
367
+ * @returns The product information in a promise
368
+ */
369
+ export declare function getProductInformation(client: FrakClient): Promise<GetProductInformationReturnType>;
370
+
371
+ /**
372
+ * Response of the `frak_getProductInformation` RPC method
373
+ * @group RPC Schema
374
+ */
375
+ declare type GetProductInformationReturnType = {
376
+ /**
377
+ * Current product id
378
+ */
379
+ id: Hex;
380
+ /**
381
+ * Some metadata
382
+ */
383
+ onChainMetadata: {
384
+ /**
385
+ * Name of the product on-chain
386
+ */
387
+ name: string;
388
+ /**
389
+ * Domain of the product on-chain
390
+ */
391
+ domain: string;
392
+ /**
393
+ * The supported product types
394
+ */
395
+ productTypes: ProductTypesKey[];
396
+ };
397
+ /**
398
+ * The max potential reward for the referrer
399
+ */
400
+ maxReferrer?: TokenAmountType;
401
+ /**
402
+ * The max potential reward for the referee
403
+ */
404
+ maxReferee?: TokenAmountType;
405
+ /**
406
+ * List of all the potentials reward arround this product
407
+ */
408
+ rewards: {
409
+ token: Address;
410
+ campaign: Address;
411
+ interactionTypeKey: FullInteractionTypesKey;
412
+ referrer: TokenAmountType;
413
+ referee: TokenAmountType;
414
+ }[];
415
+ };
416
+
417
+ /**
418
+ * RPC interface that's used for the iframe communication
419
+ *
420
+ * Define all the methods available within the iFrame RPC client
421
+ *
422
+ * @group RPC Schema
423
+ *
424
+ * @remarks
425
+ * Here is the list of methods available:
426
+ *
427
+ * ### frak_listenToWalletStatus
428
+ * - Params: None
429
+ * - Returns: {@link WalletStatusReturnType}
430
+ *
431
+ * ### frak_displayModal
432
+ * - Params: [{@link ModalRpcStepsInput}, name: string, metadata?: {@link ModalRpcMetadata}]
433
+ * - Returns: {@link ModalRpcStepsResultType}
434
+ *
435
+ * ### frak_sendInteraction
436
+ * - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
437
+ * - Returns: {@link SendInteractionReturnType}
438
+ *
439
+ * ### frak_sso
440
+ * - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
441
+ * - Returns: undefined
442
+ *
443
+ * ### frak_getProductInformation
444
+ * - Params: None
445
+ * - Returns: {@link GetProductInformationReturnType}
446
+ *
447
+ * ### frak_displayEmbededWallet
448
+ * - Params: [{@link DisplayEmbededWalletParamsType}]
449
+ * - Returns: undefined
450
+ */
451
+ declare type IFrameRpcSchema = [
452
+ /**
453
+ * Method used to listen to the wallet status
454
+ */
455
+ {
456
+ Method: "frak_listenToWalletStatus";
457
+ Parameters?: undefined;
458
+ ReturnType: WalletStatusReturnType;
459
+ },
460
+ /**
461
+ * Method to display a modal with the provided steps
462
+ */
463
+ {
464
+ Method: "frak_displayModal";
465
+ Parameters: [
466
+ requests: ModalRpcStepsInput,
467
+ metadata: FrakWalletSdkConfig["metadata"] & ModalRpcMetadata
468
+ ];
469
+ ReturnType: ModalRpcStepsResultType;
470
+ },
471
+ /**
472
+ * Method to transmit a user interaction
473
+ */
474
+ {
475
+ Method: "frak_sendInteraction";
476
+ Parameters: [
477
+ productId: Hex,
478
+ interaction: PreparedInteraction,
479
+ signature?: Hex
480
+ ];
481
+ ReturnType: SendInteractionReturnType;
482
+ },
483
+ /**
484
+ * Method to start a SSO
485
+ * todo: Should also support direct tracking via a consumeKey
486
+ */
487
+ {
488
+ Method: "frak_sso";
489
+ Parameters: [
490
+ params: OpenSsoParamsType,
491
+ name: string,
492
+ customCss?: string
493
+ ];
494
+ ReturnType: undefined;
495
+ },
496
+ /**
497
+ * Method to get current product information's
498
+ * - Is product minted?
499
+ * - Does it have running campaign?
500
+ * - Estimated reward on actions
501
+ */
502
+ {
503
+ Method: "frak_getProductInformation";
504
+ Parameters?: undefined;
505
+ ReturnType: GetProductInformationReturnType;
506
+ },
507
+ /**
508
+ * Method to show the embeded wallet, with potential customisation
509
+ */
510
+ {
511
+ Method: "frak_displayEmbededWallet";
512
+ Parameters: [
513
+ DisplayEmbededWalletParamsType,
514
+ metadata: FrakWalletSdkConfig["metadata"]
515
+ ];
516
+ ReturnType: undefined;
517
+ }
518
+ ];
519
+
520
+ /**
521
+ * IFrame transport interface
522
+ */
523
+ declare type IFrameTransport = {
524
+ /**
525
+ * Wait for the connection to be established
526
+ */
527
+ waitForConnection: Promise<boolean>;
528
+ /**
529
+ * Wait for the setup to be done
530
+ */
531
+ waitForSetup: Promise<void>;
532
+ /**
533
+ * Function used to perform a single request via the iframe transport
534
+ */
535
+ request: RequestFn<IFrameRpcSchema>;
536
+ /**
537
+ * Function used to listen to a request response via the iframe transport
538
+ */
539
+ listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
540
+ /**
541
+ * Function used to destroy the iframe transport
542
+ */
543
+ destroy: () => Promise<void>;
544
+ };
545
+
546
+ /**
547
+ * Each interactions types according to the product types
548
+ */
549
+ declare const interactionTypes: {
550
+ readonly press: {
551
+ readonly openArticle: "0xc0a24ffb";
552
+ readonly readArticle: "0xd5bd0fbe";
553
+ };
554
+ readonly dapp: {
555
+ readonly proofVerifiableStorageUpdate: "0x2ab2aeef";
556
+ readonly callableVerifiableStorageUpdate: "0xa07da986";
557
+ };
558
+ readonly webshop: {
559
+ readonly open: "0xb311798f";
560
+ };
561
+ readonly referral: {
562
+ readonly referred: "0x010cc3b9";
563
+ readonly createLink: "0xb2c0f17c";
564
+ };
565
+ readonly purchase: {
566
+ readonly started: "0xd87e90c3";
567
+ readonly completed: "0x8403aeb4";
568
+ readonly unsafeCompleted: "0x4d5b14e0";
569
+ };
570
+ readonly retail: {
571
+ readonly customerMeeting: "0x74489004";
572
+ };
573
+ };
574
+
575
+ /**
576
+ * Type used for a listening request
577
+ * @inline
578
+ */
579
+ declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
580
+
581
+ /**
582
+ * Some configuration options for the embeded view
583
+ *
584
+ * @group Embeded wallet
585
+ */
586
+ declare type LoggedInEmbededView = {
587
+ /**
588
+ * The main action to display on the logged in embeded view
589
+ * If none specified, the user will see his wallet with the activation button
590
+ */
591
+ action?: EmbededViewAction;
592
+ };
593
+
594
+ /**
595
+ * The view when a user is logged out
596
+ * @group Embeded wallet
597
+ */
598
+ declare type LoggedOutEmbededView = {
599
+ /**
600
+ * Metadata option when displaying the embeded view
601
+ */
602
+ metadata?: {
603
+ /**
604
+ * The main CTA for the logged out view
605
+ * - can include some variable, available ones are:
606
+ * - {REWARD} -> The maximum reward a user can receive when itneracting on your website
607
+ * - can be formatted in markdown
608
+ *
609
+ * If not sert, it will default to a internalised message
610
+ */
611
+ text?: string;
612
+ /**
613
+ * The text that will be displayed on the login button
614
+ *
615
+ * If not set, it will default to a internalised message
616
+ */
617
+ buttonText?: string;
618
+ };
619
+ };
620
+
621
+ /**
622
+ * The login step for a Modal
623
+ *
624
+ * **Input**: Do we allow SSO or not? Is yes then the SSO metadata
625
+ * **Output**: The logged in wallet address
626
+ *
627
+ * @group Modal Display
628
+ */
629
+ declare type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
630
+ wallet: Address;
631
+ }>;
632
+
633
+ /** @inline */
634
+ declare type LoginWithoutSso = {
635
+ allowSso?: false;
636
+ ssoMetadata?: never;
637
+ };
638
+
639
+ /** @inline */
640
+ declare type LoginWithSso = {
641
+ allowSso: true;
642
+ ssoMetadata: SsoMetadata;
643
+ };
644
+
645
+ /**
646
+ * Represent the output type of the modal builder
647
+ */
648
+ export declare type ModalBuilder = ModalStepBuilder<[
649
+ LoginModalStepType,
650
+ OpenInteractionSessionModalStepType
651
+ ]>;
652
+
653
+ /**
654
+ * Helper to craft Frak modal, and share a base initial config
655
+ * @param client - The current Frak Client
656
+ * @param args
657
+ * @param args.metadata - Common modal metadata (customisation, language etc)
658
+ * @param args.login - Login step parameters
659
+ * @param args.openSession - Open session step parameters
660
+ *
661
+ * @description This function will create a modal builder with the provided metadata, login and open session parameters.
662
+ *
663
+ * @example
664
+ * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
665
+ *
666
+ * ```js
667
+ * // Create the modal builder
668
+ * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
669
+ *
670
+ * // Configure the information to be shared via the sharing link
671
+ * const sharingConfig = {
672
+ * popupTitle: "Share this with your friends",
673
+ * text: "Discover our product!",
674
+ * link: window.location.href,
675
+ * };
676
+ *
677
+ * // Display the sharing modal
678
+ * function modalShare() {
679
+ * modalBuilder.sharing(sharingConfig).display();
680
+ * }
681
+ * ```
682
+ *
683
+ * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
684
+ * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
685
+ * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
686
+ * @see {@link displayModal} for more info about how the modal is displayed
687
+ */
688
+ export declare function modalBuilder(client: FrakClient, { metadata, login, openSession, }: {
689
+ metadata?: ModalRpcMetadata;
690
+ login?: LoginModalStepType["params"];
691
+ openSession?: OpenInteractionSessionModalStepType["params"];
692
+ }): ModalBuilder;
693
+
694
+ /**
695
+ * RPC metadata for the modal, used on top level modal configuration
696
+ * @group Modal Display
697
+ * @group RPC Schema
698
+ */
699
+ declare type ModalRpcMetadata = {
700
+ header?: {
701
+ title?: string;
702
+ icon?: string;
703
+ };
704
+ context?: string;
705
+ targetInteraction?: FullInteractionTypesKey;
706
+ } & ({
707
+ isDismissible: true;
708
+ dismissActionTxt?: string;
709
+ } | {
710
+ isDismissible?: false;
711
+ dismissActionTxt?: never;
712
+ });
713
+
714
+ /**
715
+ * Type for the RPC input of a modal
716
+ * Just the `params` type of each `ModalStepTypes`
717
+ * @typeParam T - The list of modal steps we expect to have in the modal
718
+ * @group Modal Display
719
+ * @group RPC Schema
720
+ */
721
+ declare type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
722
+ [K in T[number]["key"]]?: Extract<T[number], {
723
+ key: K;
724
+ }>["params"];
725
+ };
726
+
727
+ /**
728
+ * Type for the result of a modal request
729
+ * Just the `returns` type of each `ModalStepTypes`
730
+ * @typeParam T - The list of modal steps we expect to have in the modal
731
+ * @group Modal Display
732
+ * @group RPC Schema
733
+ */
734
+ declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
735
+ [K in T[number]["key"]]: Extract<T[number], {
736
+ key: K;
737
+ }>["returns"];
738
+ };
739
+
740
+ /**
741
+ * Represent the type of the modal step builder
742
+ */
743
+ export declare type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
744
+ /**
745
+ * The current modal params
746
+ */
747
+ params: DisplayModalParamsType<Steps>;
748
+ /**
749
+ * Add a send transaction step to the modal
750
+ */
751
+ sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
752
+ /**
753
+ * Add a final step of type reward to the modal
754
+ */
755
+ reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
756
+ /**
757
+ * Add a final step of type sharing to the modal
758
+ */
759
+ sharing: (sharingOptions?: Extract<FinalActionType, {
760
+ key: "sharing";
761
+ }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
762
+ /**
763
+ * Display the modal
764
+ * @param metadataOverride - Function returning optional metadata to override the current modal metadata
765
+ */
766
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
767
+ };
768
+
769
+ /**
770
+ * Metadata that can be used to customise a modal step
771
+ * @group Modal Display
772
+ */
773
+ declare type ModalStepMetadata = {
774
+ metadata?: {
775
+ /**
776
+ * Custom title for the step
777
+ * If none provided, it will use an internationalised text
778
+ */
779
+ title?: string;
780
+ /**
781
+ * Custom description for the step
782
+ * If none provided, it will use an internationalised text
783
+ */
784
+ description?: string;
785
+ /**
786
+ * Custom text for the primary action of the step
787
+ * If none provided, it will use an internationalised text
788
+ */
789
+ primaryActionText?: string;
790
+ /**
791
+ * Custom text for the secondary action of the step
792
+ * If none provided, it will use an internationalised text
793
+ */
794
+ secondaryActionText?: string;
795
+ };
796
+ };
797
+
798
+ /**
799
+ * Generic type of steps we will display in the modal to the end user
800
+ * @group Modal Display
801
+ */
802
+ declare type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | FinalModalStepType;
803
+
804
+ /**
805
+ * The open interaction session step for a Modal
806
+ *
807
+ * **Input**: None
808
+ * **Output**: The interactions session period (start and end timestamp)
809
+ *
810
+ * @group Modal Display
811
+ */
812
+ declare type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
813
+
814
+ /**
815
+ * Return type of the open session modal step
816
+ * @inline
817
+ * @ignore
818
+ */
819
+ declare type OpenInteractionSessionReturnType = {
820
+ startTimestamp: number;
821
+ endTimestamp: number;
822
+ };
823
+
824
+ /**
825
+ * Function used to open the SSO
826
+ * @param client - The current Frak Client
827
+ * @param args - The SSO parameters
828
+ *
829
+ * @description This function will open the SSO with the provided parameters.
830
+ *
831
+ * @example
832
+ * First we build the sso metadata
833
+ * ```ts
834
+ * // Build the metadata
835
+ * const metadata: SsoMetadata = {
836
+ * logoUrl: "https://my-app.com/logo.png",
837
+ * homepageLink: "https://my-app.com",
838
+ * };
839
+ * ```
840
+ *
841
+ * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
842
+ * :::code-group
843
+ * ```ts [Direct exit]
844
+ * // Trigger an sso opening with redirection
845
+ * await openSso(frakConfig, {
846
+ * directExit: true,
847
+ * metadata,
848
+ * });
849
+ * ```
850
+ * ```ts [Redirection]
851
+ * // Trigger an sso opening within a popup with direct exit
852
+ * await openSso(frakConfig, {
853
+ * redirectUrl: "https://my-app.com/nexus-sso",
854
+ * metadata,
855
+ * });
856
+ * ```
857
+ * :::
858
+ */
859
+ export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<void>;
860
+
861
+ /**
862
+ * Params to start a SSO
863
+ * @group RPC Schema
864
+ */
865
+ declare type OpenSsoParamsType = {
866
+ /**
867
+ * Redirect URL after the SSO (optional)
868
+ */
869
+ redirectUrl?: string;
870
+ /**
871
+ * If the SSO should directly exit after completion
872
+ * @defaultValue true
873
+ */
874
+ directExit?: boolean;
875
+ /**
876
+ * Language of the SSO page (optional)
877
+ * It will default to the current user language (or "en" if unsupported language)
878
+ */
879
+ lang?: "en" | "fr";
880
+ /**
881
+ * Custom SSO metadata
882
+ */
883
+ metadata: SsoMetadata;
884
+ };
885
+
886
+ /**
887
+ * Represent a prepared user interaction, ready to be sent on-chain via the wallet
888
+ */
889
+ declare type PreparedInteraction = {
890
+ handlerTypeDenominator: Hex;
891
+ interactionData: Hex;
892
+ };
893
+
894
+ /**
895
+ * This function handle all the heavy lifting of the referral interaction process
896
+ * 1. Check if the user has been referred or not (if not, early exit)
897
+ * 2. Then check if the user is logged in or not
898
+ * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
899
+ * 3. Check if that's not a self-referral (if yes, early exit)
900
+ * 4. Check if the user has an interaction session or not
901
+ * 4.1 If not, display a modal for the user to open a session
902
+ * 5. Push the referred interaction
903
+ * 6. Update the current url with the right data
904
+ * 7. Return the resulting referral state
905
+ *
906
+ * If any error occurs during the process, the function will catch it and return an error state
907
+ *
908
+ * @param client - The current Frak Client
909
+ * @param args
910
+ * @param args.walletStatus - The current user wallet status
911
+ * @param args.frakContext - The current frak context
912
+ * @param args.modalConfig - The modal configuration to display if the user is not logged in
913
+ * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
914
+ * @param args.options - Some options for the referral interaction
915
+ * @returns A promise with the resulting referral state
916
+ *
917
+ * @see {@link displayModal} for more details about the displayed modal
918
+ * @see {@link sendInteraction} for more details on the interaction submission part
919
+ * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
920
+ * @see {@link ModalStepTypes} for more details on each modal steps types
921
+ */
922
+ export declare function processReferral(client: FrakClient, { walletStatus, frakContext, modalConfig, productId, options, }: {
923
+ walletStatus?: WalletStatusReturnType;
924
+ frakContext?: Partial<FrakContext> | null;
925
+ modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
926
+ productId?: Hex;
927
+ options?: ProcessReferralOptions;
928
+ }): Promise<ReferralState>;
929
+
930
+ /**
931
+ * Options for the referral auto-interaction process
932
+ */
933
+ export declare type ProcessReferralOptions = {
934
+ /**
935
+ * If we want to always append the url with the frak context or not
936
+ * @defaultValue false
937
+ */
938
+ alwaysAppendUrl?: boolean;
939
+ };
940
+
941
+ /**
942
+ * List of the product types per denominator
943
+ */
944
+ declare const productTypes: {
945
+ dapp: number;
946
+ press: number;
947
+ webshop: number;
948
+ retail: number;
949
+ referral: number;
950
+ purchase: number;
951
+ };
952
+
953
+ /**
954
+ * The keys for each product types
955
+ * @inline
956
+ */
957
+ declare type ProductTypesKey = keyof typeof productTypes;
958
+
959
+ /**
960
+ * Function used to display a modal
961
+ * @param client - The current Frak Client
962
+ * @param args
963
+ * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
964
+ * @param args.modalConfig - The modal configuration to display if the user is not logged in
965
+ * @param args.options - Some options for the referral interaction
966
+ *
967
+ * @returns A promise with the resulting referral state, or undefined in case of an error
968
+ *
969
+ * @description This function will automatically handle the referral interaction process
970
+ *
971
+ * @see {@link processReferral} for more details on the automatic referral handling process
972
+ * @see {@link ModalStepTypes} for more details on each modal steps types
973
+ */
974
+ export declare function referralInteraction(client: FrakClient, { productId, modalConfig, options, }?: {
975
+ productId?: Hex;
976
+ modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
977
+ options?: ProcessReferralOptions;
978
+ }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
979
+
980
+ /**
981
+ * The different states of the referral process
982
+ * @inline
983
+ */
984
+ declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
985
+
986
+ /**
987
+ * Type used for a one shot request function
988
+ * @inline
989
+ */
990
+ declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
991
+
992
+ /**
993
+ * Function used to send an interaction
994
+ * @param client - The current Frak Client
995
+ * @param args
996
+ *
997
+ * @example
998
+ * const interaction = PressInteractionEncoder.openArticle({
999
+ * articleId: keccak256(toHex("article-slug")),
1000
+ * });
1001
+ * const { delegationId } = await sendInteraction(frakConfig, {
1002
+ * interaction,
1003
+ * });
1004
+ * console.log("Delegated interaction id", delegationId);
1005
+ */
1006
+ export declare function sendInteraction(client: FrakClient, { productId, interaction, validation }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
1007
+
1008
+ /**
1009
+ * Parameters that will be used to send an interaction to the blockchain
1010
+ * @inline
1011
+ */
1012
+ declare type SendInteractionParamsType = {
1013
+ /**
1014
+ * The product id where this interaction has been made
1015
+ * @defaultValue keccak256(toHex(window.location.host))
1016
+ */
1017
+ productId?: Hex;
1018
+ /**
1019
+ * The prepared interaction, built from an Interaction Encoder
1020
+ */
1021
+ interaction: PreparedInteraction;
1022
+ /**
1023
+ * A pre-computed interaction signature
1024
+ * If none provided, the delegated interaction validator of your product will sign it (you can manage it in the business dashboard)
1025
+ *
1026
+ * @defaultValue undefined
1027
+ */
1028
+ validation?: Hex;
1029
+ };
1030
+
1031
+ /**
1032
+ * Return type of the send interaction rpc request
1033
+ * @group RPC Schema
1034
+ */
1035
+ declare type SendInteractionReturnType = {
1036
+ /**
1037
+ * The id of the interaction in the interaction pool
1038
+ */
1039
+ delegationId: string;
1040
+ };
1041
+
1042
+ /**
1043
+ * Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
1044
+ * @param client - The current Frak Client
1045
+ * @param args - The parameters
1046
+ * @returns The hash of the transaction that was sent in a promise
1047
+ *
1048
+ * @description This function will display a modal to the user with the provided transaction and metadata.
1049
+ *
1050
+ * @example
1051
+ * const { hash } = await sendTransaction(frakConfig, {
1052
+ * tx: {
1053
+ * to: "0xdeadbeef",
1054
+ * value: toHex(100n),
1055
+ * },
1056
+ * metadata: {
1057
+ * header: {
1058
+ * title: "Sending eth",
1059
+ * },
1060
+ * context: "Send 100wei to 0xdeadbeef",
1061
+ * },
1062
+ * });
1063
+ * console.log("Transaction hash:", hash);
1064
+ */
1065
+ export declare function sendTransaction(client: FrakClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
1066
+
1067
+ /**
1068
+ * The send transaction step for a Modal
1069
+ *
1070
+ * **Input**: Either a single tx or an array of tx to be sent
1071
+ * **Output**: The hash of the tx(s) hash (in case of multiple tx, still returns a single hash because it's bundled on the wallet level)
1072
+ *
1073
+ * @group Modal Display
1074
+ */
1075
+ declare type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
1076
+ tx: SendTransactionTxType | SendTransactionTxType[];
1077
+ }, SendTransactionReturnType>;
1078
+
1079
+ /**
1080
+ * Parameters to directly show a modal used to send a transaction
1081
+ * @inline
1082
+ */
1083
+ export declare type SendTransactionParams = {
1084
+ /**
1085
+ * The transaction to be sent (either a single tx or multiple ones)
1086
+ */
1087
+ tx: SendTransactionModalStepType["params"]["tx"];
1088
+ /**
1089
+ * Custom metadata to be passed to the modal
1090
+ */
1091
+ metadata?: ModalRpcMetadata;
1092
+ };
1093
+
1094
+ /**
1095
+ * Return type of the send transaction rpc request
1096
+ * @inline
1097
+ */
1098
+ declare type SendTransactionReturnType = {
1099
+ hash: Hex;
1100
+ };
1101
+
1102
+ /**
1103
+ * Generic format representing a tx to be sent
1104
+ */
1105
+ declare type SendTransactionTxType = {
1106
+ to: Address;
1107
+ data?: Hex;
1108
+ value?: Hex;
1109
+ };
1110
+
1111
+ /**
1112
+ * Function used to launch a siwe authentication
1113
+ * @param client - The current Frak Client
1114
+ * @param args - The parameters
1115
+ * @returns The SIWE authentication result (message + signature) in a promise
1116
+ *
1117
+ * @description This function will display a modal to the user with the provided SIWE parameters and metadata.
1118
+ *
1119
+ * @example
1120
+ * import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
1121
+ * import { parseSiweMessage } from "viem/siwe";
1122
+ *
1123
+ * const { signature, message } = await siweAuthenticate(frakConfig, {
1124
+ * siwe: {
1125
+ * statement: "Sign in to My App",
1126
+ * domain: "my-app.com",
1127
+ * expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
1128
+ * },
1129
+ * metadata: {
1130
+ * header: {
1131
+ * title: "Sign in",
1132
+ * },
1133
+ * context: "Sign in to My App",
1134
+ * },
1135
+ * });
1136
+ * console.log("Parsed final message:", parseSiweMessage(message));
1137
+ * console.log("Siwe signature:", signature);
1138
+ */
1139
+ export declare function siweAuthenticate(client: FrakClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
1140
+
1141
+ /**
1142
+ * Parameter used to directly show a modal used to authenticate with SIWE
1143
+ * @inline
1144
+ */
1145
+ export declare type SiweAuthenticateModalParams = {
1146
+ /**
1147
+ * Partial SIWE params, since we can rebuild them from the SDK if they are empty
1148
+ *
1149
+ * If no parameters provider, some fields will be recomputed from the current configuration and environment.
1150
+ * - `statement` will be set to a default value
1151
+ * - `nonce` will be generated
1152
+ * - `uri` will be set to the current domain
1153
+ * - `version` will be set to "1"
1154
+ * - `domain` will be set to the current window domain
1155
+ *
1156
+ * @default {}
1157
+ */
1158
+ siwe?: Partial<SiweAuthenticationParams>;
1159
+ /**
1160
+ * Custom metadata to be passed to the modal
1161
+ */
1162
+ metadata?: ModalRpcMetadata;
1163
+ };
1164
+
1165
+ /**
1166
+ * The SIWE authentication step for a Modal
1167
+ *
1168
+ * **Input**: SIWE message parameters
1169
+ * **Output**: SIWE result (message signed and wallet signature)
1170
+ *
1171
+ * @group Modal Display
1172
+ */
1173
+ declare type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
1174
+ siwe: SiweAuthenticationParams;
1175
+ }, SiweAuthenticateReturnType>;
1176
+
1177
+ /**
1178
+ * Return type of the Siwe transaction rpc request
1179
+ * @inline
1180
+ */
1181
+ declare type SiweAuthenticateReturnType = {
1182
+ signature: Hex;
1183
+ message: string;
1184
+ };
1185
+
1186
+ /**
1187
+ * Parameters used send a SIWE rpc request
1188
+ */
1189
+ declare type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
1190
+ expirationTimeTimestamp?: number;
1191
+ notBeforeTimestamp?: number;
1192
+ };
1193
+
1194
+ /**
1195
+ * SSO Metadata
1196
+ */
1197
+ declare type SsoMetadata = {
1198
+ /**
1199
+ * URL to your client, if provided will be displayed in the SSO header
1200
+ */
1201
+ logoUrl?: string;
1202
+ /**
1203
+ * Link to your homepage, if referenced your app name will contain a link on the sso page
1204
+ */
1205
+ homepageLink?: string;
1206
+ };
1207
+
1208
+ /**
1209
+ * The type for the amount of tokens
1210
+ */
1211
+ declare type TokenAmountType = {
1212
+ amount: number;
1213
+ eurAmount: number;
1214
+ usdAmount: number;
1215
+ gbpAmount: number;
1216
+ };
1217
+
1218
+ /**
1219
+ * Function used to track the status of a purchase
1220
+ * when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
1221
+ *
1222
+ * @param args.customerId - The customer id that made the purchase (on your side)
1223
+ * @param args.orderId - The order id of the purchase (on your side)
1224
+ * @param args.token - The token of the purchase
1225
+ *
1226
+ * @description This function will send a request to the backend to listen for the purchase status.
1227
+ *
1228
+ * @example
1229
+ * async function trackPurchase(checkout) {
1230
+ * const payload = {
1231
+ * customerId: checkout.order.customer.id,
1232
+ * orderId: checkout.order.id,
1233
+ * token: checkout.token,
1234
+ * };
1235
+ *
1236
+ * await trackPurchaseStatus(payload);
1237
+ * }
1238
+ *
1239
+ * @remarks
1240
+ * - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
1241
+ * - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
1242
+ */
1243
+ export declare function trackPurchaseStatus(args: {
1244
+ customerId: string | number;
1245
+ orderId: string | number;
1246
+ token: string;
1247
+ }): Promise<void>;
1248
+
1249
+ /**
1250
+ * @ignore
1251
+ * @inline
1252
+ */
1253
+ declare type WalletConnected = {
1254
+ key: "connected";
1255
+ wallet: Address;
1256
+ interactionToken?: string;
1257
+ interactionSession?: {
1258
+ startTimestamp: number;
1259
+ endTimestamp: number;
1260
+ };
1261
+ };
1262
+
1263
+ /**
1264
+ * @ignore
1265
+ * @inline
1266
+ */
1267
+ declare type WalletNotConnected = {
1268
+ key: "not-connected";
1269
+ wallet?: never;
1270
+ interactionToken?: never;
1271
+ interactionSession?: never;
1272
+ };
1273
+
1274
+ /**
1275
+ * RPC Response for the method `frak_listenToWalletStatus`
1276
+ * @group RPC Schema
1277
+ */
1278
+ declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
1279
+
1280
+ /**
1281
+ * Function used to watch the current frak wallet status
1282
+ * @param client - The current Frak Client
1283
+ * @param callback - The callback that will receive any wallet status change
1284
+ * @returns A rpomise resolving with the initial wallet status
1285
+ *
1286
+ * @description This function will return the current wallet status, and will listen to any change in the wallet status.
1287
+ *
1288
+ * @example
1289
+ * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
1290
+ * if (status.key === "connected") {
1291
+ * console.log("Wallet connected:", status.wallet);
1292
+ * console.log("Current interaction session:", status.interactionSession);
1293
+ * } else {
1294
+ * console.log("Wallet not connected");
1295
+ * }
1296
+ * });
1297
+ */
1298
+ export declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
1299
+
1300
+ export { }