@frak-labs/core-sdk 0.0.7 → 0.0.8

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