@frak-labs/core-sdk 0.0.9 → 0.0.11
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.
- package/cdn/bundle.js +5 -5
- package/cdn/bundle.js.LICENSE.txt +1 -10
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +135 -58
- package/dist/actions.d.ts +135 -58
- package/dist/actions.js +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +172 -46
- package/dist/index.d.ts +172 -46
- package/dist/index.js +2 -2
- package/dist/interactions.cjs +1 -1
- package/package.json +6 -8
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,20 @@ import type { Prettify } from 'viem/chains';
|
|
|
4
4
|
import type { RpcSchema } from 'viem';
|
|
5
5
|
import type { SiweMessage } from 'viem/siwe';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Decode a base64url encoded string
|
|
9
|
+
* @param value The value to decode
|
|
10
|
+
* @returns The decoded value
|
|
11
|
+
*/
|
|
12
|
+
export declare function base64urlDecode(value: string): Uint8Array;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Encode a buffer to a base64url encoded string
|
|
16
|
+
* @param buffer The buffer to encode
|
|
17
|
+
* @returns The encoded string
|
|
18
|
+
*/
|
|
19
|
+
export declare function base64urlEncode(buffer: Uint8Array): string;
|
|
20
|
+
|
|
7
21
|
/**
|
|
8
22
|
* Base props for the iframe
|
|
9
23
|
* @ignore
|
|
@@ -11,6 +25,7 @@ import type { SiweMessage } from 'viem/siwe';
|
|
|
11
25
|
export declare const baseIframeProps: {
|
|
12
26
|
id: string;
|
|
13
27
|
name: string;
|
|
28
|
+
title: string;
|
|
14
29
|
allow: string;
|
|
15
30
|
style: {
|
|
16
31
|
width: string;
|
|
@@ -27,7 +42,7 @@ export declare const baseIframeProps: {
|
|
|
27
42
|
* Event related to the iframe lifecycle
|
|
28
43
|
* @ignore
|
|
29
44
|
*/
|
|
30
|
-
export declare type ClientLifecycleEvent = CustomCssEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
|
|
45
|
+
export declare type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
|
|
31
46
|
|
|
32
47
|
/** @ignore */
|
|
33
48
|
export declare class ClientNotFound extends FrakRpcError {
|
|
@@ -46,17 +61,21 @@ declare function compress(context?: Partial<FrakContext>): string | undefined;
|
|
|
46
61
|
* -> The encoded should contain a HashProtectedData once decoded
|
|
47
62
|
* @ignore
|
|
48
63
|
*/
|
|
49
|
-
export declare type CompressedData =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
export declare type CompressedData = Uint8Array;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Compress json data
|
|
68
|
+
* @param data
|
|
69
|
+
* @ignore
|
|
70
|
+
*/
|
|
71
|
+
export declare function compressJson(data: unknown): Uint8Array;
|
|
53
72
|
|
|
54
73
|
/**
|
|
55
74
|
* Compress json data
|
|
56
75
|
* @param data
|
|
57
76
|
* @ignore
|
|
58
77
|
*/
|
|
59
|
-
export declare function
|
|
78
|
+
export declare function compressJsonToB64(data: unknown): string;
|
|
60
79
|
|
|
61
80
|
/**
|
|
62
81
|
* Create the Frak iframe
|
|
@@ -92,6 +111,7 @@ export declare function createIFrameFrakClient({ config, iframe, }: {
|
|
|
92
111
|
|
|
93
112
|
/**
|
|
94
113
|
* All the currencies available
|
|
114
|
+
* @category Config
|
|
95
115
|
*/
|
|
96
116
|
export declare type Currency = "eur" | "usd" | "gbp";
|
|
97
117
|
|
|
@@ -102,6 +122,13 @@ declare type CustomCssEvent = {
|
|
|
102
122
|
};
|
|
103
123
|
};
|
|
104
124
|
|
|
125
|
+
declare type CustomI18nEvent = {
|
|
126
|
+
clientLifecycle: "modal-i18n";
|
|
127
|
+
data: {
|
|
128
|
+
i18n: I18nConfig;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
105
132
|
/** @ignore */
|
|
106
133
|
export declare class DebugInfoGatherer {
|
|
107
134
|
private config?;
|
|
@@ -139,14 +166,21 @@ declare function decompress(context?: string): FrakContext | undefined;
|
|
|
139
166
|
* @param compressedData The params to encode
|
|
140
167
|
* @ignore
|
|
141
168
|
*/
|
|
142
|
-
export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData):
|
|
169
|
+
export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData): HashProtectedData<T>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Decompress json data
|
|
173
|
+
* @param data
|
|
174
|
+
* @ignore
|
|
175
|
+
*/
|
|
176
|
+
export declare function decompressJson<T>(data: Uint8Array): T | null;
|
|
143
177
|
|
|
144
178
|
/**
|
|
145
179
|
* Decompress json data
|
|
146
180
|
* @param data
|
|
147
181
|
* @ignore
|
|
148
182
|
*/
|
|
149
|
-
export declare function
|
|
183
|
+
export declare function decompressJsonFromB64<T>(data: string): T | null;
|
|
150
184
|
|
|
151
185
|
/**
|
|
152
186
|
* Simple deferred promise wrapper
|
|
@@ -163,31 +197,31 @@ export declare class Deferred<T> {
|
|
|
163
197
|
}
|
|
164
198
|
|
|
165
199
|
/**
|
|
166
|
-
* The params used to display the
|
|
200
|
+
* The params used to display the embedded wallet
|
|
167
201
|
*
|
|
168
|
-
* @group
|
|
202
|
+
* @group Embedded wallet
|
|
169
203
|
*/
|
|
170
204
|
export declare type DisplayEmbededWalletParamsType = {
|
|
171
205
|
/**
|
|
172
|
-
* The
|
|
206
|
+
* The embedded view to display once the user is logged in
|
|
173
207
|
*/
|
|
174
208
|
loggedIn?: LoggedInEmbededView;
|
|
175
209
|
/**
|
|
176
|
-
* The
|
|
210
|
+
* The embedded view to display once the user is logged out
|
|
177
211
|
*/
|
|
178
212
|
loggedOut?: LoggedOutEmbededView;
|
|
179
213
|
/**
|
|
180
|
-
* Some metadata to
|
|
214
|
+
* Some metadata to customize the embedded view
|
|
181
215
|
*/
|
|
182
216
|
metadata?: {
|
|
183
217
|
/**
|
|
184
|
-
* The logo to display on the
|
|
218
|
+
* The logo to display on the embedded wallet
|
|
185
219
|
* If undefined, will default to no logo displayed
|
|
186
220
|
*/
|
|
187
221
|
logo?: string;
|
|
188
222
|
/**
|
|
189
223
|
* Link to the homepage of the calling website
|
|
190
|
-
* If
|
|
224
|
+
* If undefined, will default to the domain of the calling website
|
|
191
225
|
*/
|
|
192
226
|
homepageLink?: string;
|
|
193
227
|
/**
|
|
@@ -198,6 +232,10 @@ export declare type DisplayEmbededWalletParamsType = {
|
|
|
198
232
|
* The position of the component
|
|
199
233
|
*/
|
|
200
234
|
position?: "left" | "right";
|
|
235
|
+
/**
|
|
236
|
+
* Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
|
|
237
|
+
*/
|
|
238
|
+
i18n?: I18nConfig;
|
|
201
239
|
};
|
|
202
240
|
};
|
|
203
241
|
|
|
@@ -219,9 +257,9 @@ declare type DoBackupEvent = {
|
|
|
219
257
|
};
|
|
220
258
|
|
|
221
259
|
/**
|
|
222
|
-
* The different type of action we can have on the
|
|
260
|
+
* The different type of action we can have on the embedded view (once the user is logged in)
|
|
223
261
|
*
|
|
224
|
-
* @group
|
|
262
|
+
* @group Embedded wallet
|
|
225
263
|
*/
|
|
226
264
|
export declare type EmbededViewAction = {
|
|
227
265
|
key: "sharing";
|
|
@@ -231,11 +269,13 @@ export declare type EmbededViewAction = {
|
|
|
231
269
|
options?: {
|
|
232
270
|
/**
|
|
233
271
|
* The title that will be displayed on the system popup once the system sharing window is open
|
|
272
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
234
273
|
*/
|
|
235
274
|
popupTitle?: string;
|
|
236
275
|
/**
|
|
237
276
|
* The text that will be shared alongside the link.
|
|
238
277
|
* Can contain the variable {LINK} to specify where the link is placed, otherwise it will be added at the end
|
|
278
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
239
279
|
*/
|
|
240
280
|
text?: string;
|
|
241
281
|
/**
|
|
@@ -280,7 +320,13 @@ export declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TPa
|
|
|
280
320
|
export declare type FinalActionType = {
|
|
281
321
|
key: "sharing";
|
|
282
322
|
options?: {
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
325
|
+
*/
|
|
283
326
|
popupTitle?: string;
|
|
327
|
+
/**
|
|
328
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
329
|
+
*/
|
|
284
330
|
text?: string;
|
|
285
331
|
link?: string;
|
|
286
332
|
};
|
|
@@ -319,6 +365,8 @@ export declare type FrakClient = {
|
|
|
319
365
|
* The current Frak Context
|
|
320
366
|
*
|
|
321
367
|
* For now, only contain a referrer address.
|
|
368
|
+
*
|
|
369
|
+
* @ignore
|
|
322
370
|
*/
|
|
323
371
|
export declare type FrakContext = {
|
|
324
372
|
r: Address;
|
|
@@ -347,7 +395,8 @@ export declare class FrakRpcError<T = undefined> extends Error {
|
|
|
347
395
|
}
|
|
348
396
|
|
|
349
397
|
/**
|
|
350
|
-
* Configuration for the
|
|
398
|
+
* Configuration for the Frak Wallet SDK
|
|
399
|
+
* @category Config
|
|
351
400
|
*/
|
|
352
401
|
export declare type FrakWalletSdkConfig = {
|
|
353
402
|
/**
|
|
@@ -363,20 +412,37 @@ export declare type FrakWalletSdkConfig = {
|
|
|
363
412
|
* Your application name (will be displayed in a few modals and in SSO)
|
|
364
413
|
*/
|
|
365
414
|
name: string;
|
|
366
|
-
/**
|
|
367
|
-
* Custom CSS styles to apply to the modals and components
|
|
368
|
-
*/
|
|
369
|
-
css?: string;
|
|
370
415
|
/**
|
|
371
416
|
* Language to display in the modal
|
|
372
417
|
* If undefined, will default to the browser language
|
|
373
418
|
*/
|
|
374
|
-
lang?:
|
|
419
|
+
lang?: Language;
|
|
375
420
|
/**
|
|
376
421
|
* The currency to display in the modal
|
|
377
422
|
* @defaultValue `"eur"`
|
|
378
423
|
*/
|
|
379
424
|
currency?: Currency;
|
|
425
|
+
/**
|
|
426
|
+
* The logo URL that will be displayed in a few components
|
|
427
|
+
*/
|
|
428
|
+
logoUrl?: string;
|
|
429
|
+
/**
|
|
430
|
+
* The homepage link that could be displayed in a few components
|
|
431
|
+
*/
|
|
432
|
+
homepageLink?: string;
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Some customization for the modal
|
|
436
|
+
*/
|
|
437
|
+
customizations?: {
|
|
438
|
+
/**
|
|
439
|
+
* Custom CSS styles to apply to the modals and components
|
|
440
|
+
*/
|
|
441
|
+
css?: `${string}.css`;
|
|
442
|
+
/**
|
|
443
|
+
* Custom i18n configuration for the modal
|
|
444
|
+
*/
|
|
445
|
+
i18n?: I18nConfig;
|
|
380
446
|
};
|
|
381
447
|
/**
|
|
382
448
|
* The domain name of your application
|
|
@@ -491,7 +557,7 @@ declare type HandshakeResponse = {
|
|
|
491
557
|
* @param data The params to encode
|
|
492
558
|
* @ignore
|
|
493
559
|
*/
|
|
494
|
-
export declare function hashAndCompressData<T>(data: T):
|
|
560
|
+
export declare function hashAndCompressData<T>(data: T): CompressedData;
|
|
495
561
|
|
|
496
562
|
/**
|
|
497
563
|
* The encoded data to send to a client / received by a client
|
|
@@ -505,6 +571,41 @@ declare type HearbeatEvent = {
|
|
|
505
571
|
clientLifecycle: "heartbeat";
|
|
506
572
|
};
|
|
507
573
|
|
|
574
|
+
/**
|
|
575
|
+
* Custom i18n configuration for the modal
|
|
576
|
+
* See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
|
|
577
|
+
*
|
|
578
|
+
* Available variables
|
|
579
|
+
* - `{{ productName }}` : The name of your website (`metadata.name`)
|
|
580
|
+
* - `{{ productOrigin }}` : The origin url of your website
|
|
581
|
+
* - `{{ estimatedReward }}` : The estimated reward for the user (based on the specific `targetInteraction` you can specify, or the max referrer reward if no target interaction is specified)
|
|
582
|
+
*
|
|
583
|
+
* Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
|
|
584
|
+
* - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
|
|
585
|
+
* - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* // Multi language config
|
|
590
|
+
* const multiI18n = {
|
|
591
|
+
* fr: {
|
|
592
|
+
* "sdk.modal.title": "Titre de modal",
|
|
593
|
+
* "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
|
|
594
|
+
* },
|
|
595
|
+
* en: "https://example.com/en.json"
|
|
596
|
+
* }
|
|
597
|
+
*
|
|
598
|
+
* // Single language config
|
|
599
|
+
* const singleI18n = {
|
|
600
|
+
* "sdk.modal.title": "Modal title",
|
|
601
|
+
* "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
|
|
602
|
+
* }
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* @category Config
|
|
606
|
+
*/
|
|
607
|
+
export declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
|
|
608
|
+
|
|
508
609
|
/**
|
|
509
610
|
* Represent an iframe event
|
|
510
611
|
*/
|
|
@@ -525,10 +626,7 @@ export declare type IFrameLifecycleEvent = {
|
|
|
525
626
|
export declare type IFrameRpcEvent = {
|
|
526
627
|
id: string;
|
|
527
628
|
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
528
|
-
data:
|
|
529
|
-
compressed: string;
|
|
530
|
-
compressedHash: string;
|
|
531
|
-
};
|
|
629
|
+
data: CompressedData;
|
|
532
630
|
};
|
|
533
631
|
|
|
534
632
|
/**
|
|
@@ -581,7 +679,8 @@ export declare type IFrameRpcSchema = [
|
|
|
581
679
|
Method: "frak_displayModal";
|
|
582
680
|
Parameters: [
|
|
583
681
|
requests: ModalRpcStepsInput,
|
|
584
|
-
metadata:
|
|
682
|
+
metadata: ModalRpcMetadata | undefined,
|
|
683
|
+
configMetadata: FrakWalletSdkConfig["metadata"]
|
|
585
684
|
];
|
|
586
685
|
ReturnType: ModalRpcStepsResultType;
|
|
587
686
|
},
|
|
@@ -622,12 +721,12 @@ export declare type IFrameRpcSchema = [
|
|
|
622
721
|
ReturnType: GetProductInformationReturnType;
|
|
623
722
|
},
|
|
624
723
|
/**
|
|
625
|
-
* Method to show the
|
|
724
|
+
* Method to show the embedded wallet, with potential customization
|
|
626
725
|
*/
|
|
627
726
|
{
|
|
628
727
|
Method: "frak_displayEmbededWallet";
|
|
629
728
|
Parameters: [
|
|
630
|
-
DisplayEmbededWalletParamsType,
|
|
729
|
+
request: DisplayEmbededWalletParamsType,
|
|
631
730
|
metadata: FrakWalletSdkConfig["metadata"]
|
|
632
731
|
];
|
|
633
732
|
ReturnType: undefined;
|
|
@@ -703,6 +802,12 @@ export declare type InteractionTypesKey = {
|
|
|
703
802
|
*/
|
|
704
803
|
export declare type KeyProvider<DataType> = (value: DataType) => string[];
|
|
705
804
|
|
|
805
|
+
/**
|
|
806
|
+
* All the languages available
|
|
807
|
+
* @category Config
|
|
808
|
+
*/
|
|
809
|
+
export declare type Language = "fr" | "en";
|
|
810
|
+
|
|
706
811
|
/**
|
|
707
812
|
* Type used for a listening request
|
|
708
813
|
* @inline
|
|
@@ -725,13 +830,21 @@ export declare const locales: {
|
|
|
725
830
|
export declare type LocalesKey = keyof typeof locales;
|
|
726
831
|
|
|
727
832
|
/**
|
|
728
|
-
*
|
|
833
|
+
* A localized i18n config
|
|
834
|
+
* @category Config
|
|
835
|
+
*/
|
|
836
|
+
export declare type LocalizedI18nConfig = `${string}.css` | {
|
|
837
|
+
[key: string]: string;
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Some configuration options for the embedded view
|
|
729
842
|
*
|
|
730
|
-
* @group
|
|
843
|
+
* @group Embedded wallet
|
|
731
844
|
*/
|
|
732
845
|
export declare type LoggedInEmbededView = {
|
|
733
846
|
/**
|
|
734
|
-
* The main action to display on the logged in
|
|
847
|
+
* The main action to display on the logged in embedded view
|
|
735
848
|
* If none specified, the user will see his wallet with the activation button
|
|
736
849
|
*/
|
|
737
850
|
action?: EmbededViewAction;
|
|
@@ -739,26 +852,28 @@ export declare type LoggedInEmbededView = {
|
|
|
739
852
|
|
|
740
853
|
/**
|
|
741
854
|
* The view when a user is logged out
|
|
742
|
-
* @group
|
|
855
|
+
* @group Embedded wallet
|
|
743
856
|
*/
|
|
744
857
|
export declare type LoggedOutEmbededView = {
|
|
745
858
|
/**
|
|
746
|
-
* Metadata option when displaying the
|
|
859
|
+
* Metadata option when displaying the embedded view
|
|
747
860
|
*/
|
|
748
861
|
metadata?: {
|
|
749
862
|
/**
|
|
750
863
|
* The main CTA for the logged out view
|
|
751
864
|
* - can include some variable, available ones are:
|
|
752
|
-
* - {REWARD} -> The maximum reward a user can receive when
|
|
865
|
+
* - {REWARD} -> The maximum reward a user can receive when interacting on your website
|
|
753
866
|
* - can be formatted in markdown
|
|
754
867
|
*
|
|
755
|
-
* If not
|
|
868
|
+
* If not set, it will default to a internationalized message
|
|
869
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
756
870
|
*/
|
|
757
871
|
text?: string;
|
|
758
872
|
/**
|
|
759
873
|
* The text that will be displayed on the login button
|
|
760
874
|
*
|
|
761
|
-
* If not set, it will default to a
|
|
875
|
+
* If not set, it will default to a internationalized message
|
|
876
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
762
877
|
*/
|
|
763
878
|
buttonText?: string;
|
|
764
879
|
};
|
|
@@ -785,7 +900,7 @@ declare type LoginWithoutSso = {
|
|
|
785
900
|
/** @inline */
|
|
786
901
|
declare type LoginWithSso = {
|
|
787
902
|
allowSso: true;
|
|
788
|
-
ssoMetadata
|
|
903
|
+
ssoMetadata?: SsoMetadata;
|
|
789
904
|
};
|
|
790
905
|
|
|
791
906
|
/**
|
|
@@ -798,10 +913,16 @@ export declare type ModalRpcMetadata = {
|
|
|
798
913
|
title?: string;
|
|
799
914
|
icon?: string;
|
|
800
915
|
};
|
|
801
|
-
context?: string;
|
|
802
916
|
targetInteraction?: FullInteractionTypesKey;
|
|
917
|
+
/**
|
|
918
|
+
* Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
|
|
919
|
+
*/
|
|
920
|
+
i18n?: I18nConfig;
|
|
803
921
|
} & ({
|
|
804
922
|
isDismissible: true;
|
|
923
|
+
/**
|
|
924
|
+
* @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
|
|
925
|
+
*/
|
|
805
926
|
dismissActionTxt?: string;
|
|
806
927
|
} | {
|
|
807
928
|
isDismissible?: false;
|
|
@@ -835,29 +956,34 @@ export declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalSt
|
|
|
835
956
|
};
|
|
836
957
|
|
|
837
958
|
/**
|
|
838
|
-
* Metadata that can be used to
|
|
959
|
+
* Metadata that can be used to customize a modal step
|
|
839
960
|
* @group Modal Display
|
|
961
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
840
962
|
*/
|
|
841
963
|
export declare type ModalStepMetadata = {
|
|
842
964
|
metadata?: {
|
|
843
965
|
/**
|
|
844
966
|
* Custom title for the step
|
|
845
|
-
* If none provided, it will use an
|
|
967
|
+
* If none provided, it will use an internationalized text
|
|
968
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
846
969
|
*/
|
|
847
970
|
title?: string;
|
|
848
971
|
/**
|
|
849
972
|
* Custom description for the step
|
|
850
|
-
* If none provided, it will use an
|
|
973
|
+
* If none provided, it will use an internationalized text
|
|
974
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
851
975
|
*/
|
|
852
976
|
description?: string;
|
|
853
977
|
/**
|
|
854
978
|
* Custom text for the primary action of the step
|
|
855
|
-
* If none provided, it will use an
|
|
979
|
+
* If none provided, it will use an internationalized text
|
|
980
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
856
981
|
*/
|
|
857
982
|
primaryActionText?: string;
|
|
858
983
|
/**
|
|
859
984
|
* Custom text for the secondary action of the step
|
|
860
|
-
* If none provided, it will use an
|
|
985
|
+
* If none provided, it will use an internationalized text
|
|
986
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
861
987
|
*/
|
|
862
988
|
secondaryActionText?: string;
|
|
863
989
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as e from"
|
|
1
|
+
import*as e from"@jsonjoy.com/json-pack/lib/cbor";import*as t from"viem";class n extends Error{code;data;constructor(e,t,n){super(t),this.code=e,this.data=n}}class r extends n{constructor(e){super(a.internalError,e)}}class o extends n{constructor(){super(a.clientNotConnected,"Client not found")}}let a={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006};class i{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}}function s(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function c(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(0===t?0:4-t),"=")),e=>e.charCodeAt(0))}let l=new e.CborEncoder;function d(e){let t={...e,validationHash:p(e)};return l.encode(t)}function u(e){return l.encode(e)}function f(e){return s(u(e))}function p(e){return(0,t.sha256)(l.encode(e))}let h=new e.CborDecoder;function m(e){if(!e.length)throw new n(a.corruptedResponse,"Missing compressed data");let t=g(e);if(!t)throw new n(a.corruptedResponse,"Invalid compressed data");if(!t?.validationHash)throw new n(a.corruptedResponse,"Missing validation hash");let{validationHash:r,...o}=t;if(p(o)!==t.validationHash)throw new n(a.corruptedResponse,"Invalid data validation hash");return t}function g(e){try{return h.decode(e)}catch(t){return console.error("Invalid compressed data",{e:t,data:e}),null}}function w(e){return g(c(e))}let y="nexus-wallet-backup";class b{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e){this.lastResponse={event:e.data,origin:e.origin,timestamp:Date.now()}}setLastRequest(e,t){this.lastRequest={event:e,target:t,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch(e){return console.warn("Failed to encode debug data",e),btoa("Failed to encode data")}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute("loading"),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?+("complete"===this.iframe.contentDocument.readyState):-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let t=this.getIframeStatus(),r=this.getNavigatorInfo(),o="Unknown";return e instanceof n?o=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?o=e.message:"string"==typeof e&&(o=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):"no-config",navigatorInfo:r?this.base64Encode(r):"no-navigator",iframeStatus:t?this.base64Encode(t):"not-iframe",lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):"No Frak request logged",lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):"No Frak response logged",clientStatus:this.isSetupDone?"setup":"not-setup",error:o}}static empty(){return new b}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
2
2
|
Debug Information:
|
|
3
3
|
-----------------
|
|
4
4
|
Timestamp: ${t.timestamp}
|
|
@@ -10,4 +10,4 @@ import*as e from"async-lz-string";import*as t from"js-sha256";import*as n from"v
|
|
|
10
10
|
Last Response: ${t.lastResponse}
|
|
11
11
|
Client Status: ${t.clientStatus}
|
|
12
12
|
Error: ${t.error}
|
|
13
|
-
`.trim()}}
|
|
13
|
+
`.trim()}}let v={id:"frak-wallet",name:"frak-wallet",title:"Frak Wallet",allow:"publickey-credentials-get *; clipboard-write; web-share *",style:{width:"0",height:"0",border:"0",position:"absolute",zIndex:2000001,top:"-1000px",left:"-1000px"}};function C({walletBaseUrl:e,config:t}){let n=document.querySelector("#frak-wallet");n&&n.remove();let r=document.createElement("iframe");return r.id=v.id,r.name=v.name,r.allow=v.allow,r.style.zIndex=v.style.zIndex.toString(),R({iframe:r,isVisible:!1}),document.body.appendChild(r),new Promise(n=>{r?.addEventListener("load",()=>n(r)),r.src=`${t?.walletUrl??e??"https://wallet.frak.id"}/listener`})}function R({iframe:e,isVisible:t}){if(!t){e.style.width="0",e.style.height="0",e.style.border="0",e.style.position="fixed",e.style.top="-1000px",e.style.left="-1000px";return}e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.pointerEvents="auto"}function S({config:e,iframe:t}){let o=function(){let e=new Map;return{createChannel:t=>{let n=Math.random().toString(36).substring(7);return e.set(n,t),n},getRpcResolver:t=>e.get(t),removeChannel:t=>e.delete(t),destroy:()=>e.clear()}}(),s=function({iframe:e}){let t=new i;return{handleEvent:async n=>{switch(n.iframeLifecycle){case"connected":t.resolve(!0);break;case"do-backup":n.data.backup?localStorage.setItem(y,n.data.backup):localStorage.removeItem(y);break;case"remove-backup":localStorage.removeItem(y);break;case"show":case"hide":R({iframe:e,isVisible:"show"===n.iframeLifecycle});break;case"handshake":e.contentWindow?.postMessage({clientLifecycle:"handshake-response",data:{token:n.data.token,currentUrl:window.location.href}},"*")}},isConnected:t.promise}}({iframe:t}),c=new b(e,t),l=function({frakWalletUrl:e,iframe:t,channelManager:r,iframeLifecycleManager:o,debugInfo:i}){if("undefined"==typeof window)throw new n(a.configError,"iframe client should be used in the browser");if(!t.contentWindow)throw new n(a.configError,"The iframe does not have a product window");let s=t.contentWindow;async function c(t){if(!t.origin)return;try{if(new URL(t.origin).origin.toLowerCase()!==new URL(e).origin.toLowerCase())return}catch(e){console.log("Unable to check frak msg origin",e);return}if("object"!=typeof t.data)return;if(i.setLastResponse(t),"iframeLifecycle"in t.data){await o.handleEvent(t.data);return}if("clientLifecycle"in t.data){console.error("Client lifecycle event received on the client side, dismissing it");return}let n=t.data.id,a=r.getRpcResolver(n);a&&a(t.data)}return window.addEventListener("message",c),{sendEvent:function(t){s.postMessage(t,{targetOrigin:e}),i.setLastRequest(t,e)},cleanup:function(){window.removeEventListener("message",c)}}}({frakWalletUrl:e?.walletUrl??"https://wallet.frak.id",iframe:t,channelManager:o,iframeLifecycleManager:s,debugInfo:c}),u=async e=>{if(!await s.isConnected)throw new n(a.clientNotConnected,"The iframe provider isn't connected yet");let t=new i,r=o.createChannel(e=>{let a=m(e.data);a.error?t.reject(new n(a.error.code,a.error.message,a.error?.data)):t.resolve(a.result),o.removeChannel(r)}),c=d(e);return l.sendEvent({id:r,topic:e.method,data:c}),t.promise},f=async(e,t)=>{if(!await s.isConnected)throw new n(a.clientNotConnected,"The iframe provider isn't connected yet");let i=o.createChannel(e=>{let n=m(e.data);if(n.result)t(n.result);else throw new r("No valid result in the response")}),c=d(e);l.sendEvent({id:i,topic:e.method,data:c})},p=function(e,t){let n,r;let o=()=>e.sendEvent({clientLifecycle:"heartbeat"});function a(){n&&clearInterval(n),r&&clearTimeout(r)}return async function(){o(),n=setInterval(o,100),r=setTimeout(()=>{a(),console.log("Heartbeat timeout: connection failed")},3e4),await t.isConnected,a()}(),a}(l,s),h=async()=>{p(),o.destroy(),l.cleanup(),t.remove()},g=E({config:e,messageHandler:l,lifecycleManager:s}).then(()=>c.updateSetupStatus(!0));return{config:e,debugInfo:c,waitForConnection:s.isConnected,waitForSetup:g,request:u,listenerRequest:f,destroy:h}}async function E({config:e,messageHandler:t,lifecycleManager:n}){async function r(){let n=e.customizations?.css;n&&t.sendEvent({clientLifecycle:"modal-css",data:{cssLink:n}})}async function o(){let n=e.customizations?.i18n;n&&t.sendEvent({clientLifecycle:"modal-i18n",data:{i18n:n}})}async function a(){if("undefined"==typeof window)return;let e=window.localStorage.getItem(y);e&&t.sendEvent({clientLifecycle:"restore-backup",data:{backup:e}})}await n.isConnected,await Promise.all([r(),o(),a()])}let k={eur:"fr-FR",usd:"en-US",gbp:"en-GB"};function x(e){return e&&e in k?e:"eur"}async function I({config:e}){let t=function(e){let t=x(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}(e),n=await C({config:t});if(!n){console.error("Failed to create iframe");return}let r=S({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error("Failed to connect to client");return}return r}function L(e){return e?`${e}Amount`:"eurAmount"}let F="fCtx";function D(e){if(e?.r)try{let n=(0,t.hexToBytes)(e.r);return s(n)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function U(e){if(e&&0!==e.length)try{let n=c(e);return{r:(0,t.bytesToHex)(n,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}function A({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(F);return t?U(t):null}function N({url:e,context:t}){if(!e)return null;let n=A({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let o=D(r);if(!o)return null;let a=new URL(e);return a.searchParams.set(F,o),a.toString()}function $(e){let t=new URL(e);return t.searchParams.delete(F),t.toString()}let q={compress:D,decompress:U,parse:A,update:N,remove:$,replaceUrl:function({url:e,context:t}){let n;if(!window.location?.href||"undefined"==typeof window){console.error("No window found, can't update context");return}let r=e??window.location.href;(n=null!==t?N({url:r,context:t}):$(r))&&window.history.replaceState(null,"",n.toString())}};function T(e){return e?k[e]??k.eur:k.eur}function j(e,t){let n=T(t),r=x(t);return e.toLocaleString(n,{style:"currency",currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}let _={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},M=Object.entries(_).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{}),P={press:{openArticle:"0xc0a24ffb",readArticle:"0xd5bd0fbe"},dapp:{proofVerifiableStorageUpdate:"0x2ab2aeef",callableVerifiableStorageUpdate:"0xa07da986"},webshop:{open:"0xb311798f"},referral:{referred:"0x010cc3b9",createLink:"0xb2c0f17c"},purchase:{started:"0xd87e90c3",completed:"0x8403aeb4",unsafeCompleted:"0x4d5b14e0"},retail:{customerMeeting:"0x74489004"}};export{o as ClientNotFound,b as DebugInfoGatherer,i as Deferred,q as FrakContextManager,n as FrakRpcError,a as RpcErrorCodes,c as base64urlDecode,s as base64urlEncode,v as baseIframeProps,u as compressJson,f as compressJsonToB64,S as createIFrameFrakClient,C as createIframe,m as decompressDataAndCheckHash,g as decompressJson,w as decompressJsonFromB64,j as formatAmount,L as getCurrencyAmountKey,x as getSupportedCurrency,T as getSupportedLocale,d as hashAndCompressData,P as interactionTypes,k as locales,_ as productTypes,M as productTypesMask,I as setupClient};
|
package/dist/interactions.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=
|
|
1
|
+
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{ReferralInteractionEncoder:()=>ReferralInteractionEncoder,PressInteractionEncoder:()=>PressInteractionEncoder,PurchaseInteractionEncoder:()=>PurchaseInteractionEncoder,RetailInteractionEncoder:()=>RetailInteractionEncoder,WebShopInteractionEncoder:()=>WebShopInteractionEncoder});let external_viem_namespaceObject=require("viem"),interactionTypes={press:{openArticle:"0xc0a24ffb",readArticle:"0xd5bd0fbe"},dapp:{proofVerifiableStorageUpdate:"0x2ab2aeef",callableVerifiableStorageUpdate:"0xa07da986"},webshop:{open:"0xb311798f"},referral:{referred:"0x010cc3b9",createLink:"0xb2c0f17c"},purchase:{started:"0xd87e90c3",completed:"0x8403aeb4",unsafeCompleted:"0x4d5b14e0"},retail:{customerMeeting:"0x74489004"}},productTypes={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},productTypesMask=Object.entries(productTypes).reduce((e,[r,t])=>(e[r]=BigInt(1)<<BigInt(t),e),{}),PressInteractionEncoder={openArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.openArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}},readArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.readArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}}},ReferralInteractionEncoder={createLink:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:interactionTypes.referral.createLink}),referred({referrer:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.referral.referred,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:r}}},PurchaseInteractionEncoder={startPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.started,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}},completedPurchase({purchaseId:e,proof:r}){let t=(0,external_viem_namespaceObject.encodeAbiParameters)([{type:"uint256"},{type:"bytes32[]"}],[BigInt(e),r]),a=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.completed,t]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:a}},unsafeCompletedPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.unsafeCompleted,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}}},WebShopInteractionEncoder={open:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.webshop),interactionData:interactionTypes.webshop.open})},RetailInteractionEncoder={customerMeeting({agencyId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.retail.customerMeeting,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.retail),interactionData:r}}};var __webpack_export_target__=exports;for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__]=__webpack_exports__[__webpack_i__];__webpack_exports__.__esModule&&Object.defineProperty(__webpack_export_target__,"__esModule",{value:!0});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.11",
|
|
15
15
|
"description": "Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -82,19 +82,17 @@
|
|
|
82
82
|
"publish": "echo 'Publishing core...'"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"viem": "^2.
|
|
85
|
+
"viem": "^2.23.14"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"
|
|
89
|
-
"js-sha256": "^0.11.0"
|
|
88
|
+
"@jsonjoy.com/json-pack": "^1.2.0"
|
|
90
89
|
},
|
|
91
90
|
"devDependencies": {
|
|
92
91
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
93
92
|
"@microsoft/api-extractor": "^7.52.1",
|
|
94
|
-
"@rslib/core": "^0.5.
|
|
95
|
-
"@types/node": "^22",
|
|
96
|
-
"
|
|
97
|
-
"typescript": "^5"
|
|
93
|
+
"@rslib/core": "^0.5.5",
|
|
94
|
+
"@types/node": "^22.13.13",
|
|
95
|
+
"typescript": "^5.8.2"
|
|
98
96
|
},
|
|
99
97
|
"browserslist": [
|
|
100
98
|
"extends @frak-labs/browserslist-config"
|