@frak-labs/core-sdk 0.0.9 → 0.0.10
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 +171 -46
- package/dist/index.d.ts +171 -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
|
|
@@ -27,7 +41,7 @@ export declare const baseIframeProps: {
|
|
|
27
41
|
* Event related to the iframe lifecycle
|
|
28
42
|
* @ignore
|
|
29
43
|
*/
|
|
30
|
-
export declare type ClientLifecycleEvent = CustomCssEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
|
|
44
|
+
export declare type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
|
|
31
45
|
|
|
32
46
|
/** @ignore */
|
|
33
47
|
export declare class ClientNotFound extends FrakRpcError {
|
|
@@ -46,17 +60,21 @@ declare function compress(context?: Partial<FrakContext>): string | undefined;
|
|
|
46
60
|
* -> The encoded should contain a HashProtectedData once decoded
|
|
47
61
|
* @ignore
|
|
48
62
|
*/
|
|
49
|
-
export declare type CompressedData =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
export declare type CompressedData = Uint8Array;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Compress json data
|
|
67
|
+
* @param data
|
|
68
|
+
* @ignore
|
|
69
|
+
*/
|
|
70
|
+
export declare function compressJson(data: unknown): Uint8Array;
|
|
53
71
|
|
|
54
72
|
/**
|
|
55
73
|
* Compress json data
|
|
56
74
|
* @param data
|
|
57
75
|
* @ignore
|
|
58
76
|
*/
|
|
59
|
-
export declare function
|
|
77
|
+
export declare function compressJsonToB64(data: unknown): string;
|
|
60
78
|
|
|
61
79
|
/**
|
|
62
80
|
* Create the Frak iframe
|
|
@@ -92,6 +110,7 @@ export declare function createIFrameFrakClient({ config, iframe, }: {
|
|
|
92
110
|
|
|
93
111
|
/**
|
|
94
112
|
* All the currencies available
|
|
113
|
+
* @category Config
|
|
95
114
|
*/
|
|
96
115
|
export declare type Currency = "eur" | "usd" | "gbp";
|
|
97
116
|
|
|
@@ -102,6 +121,13 @@ declare type CustomCssEvent = {
|
|
|
102
121
|
};
|
|
103
122
|
};
|
|
104
123
|
|
|
124
|
+
declare type CustomI18nEvent = {
|
|
125
|
+
clientLifecycle: "modal-i18n";
|
|
126
|
+
data: {
|
|
127
|
+
i18n: I18nConfig;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
105
131
|
/** @ignore */
|
|
106
132
|
export declare class DebugInfoGatherer {
|
|
107
133
|
private config?;
|
|
@@ -139,14 +165,21 @@ declare function decompress(context?: string): FrakContext | undefined;
|
|
|
139
165
|
* @param compressedData The params to encode
|
|
140
166
|
* @ignore
|
|
141
167
|
*/
|
|
142
|
-
export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData):
|
|
168
|
+
export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData): HashProtectedData<T>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Decompress json data
|
|
172
|
+
* @param data
|
|
173
|
+
* @ignore
|
|
174
|
+
*/
|
|
175
|
+
export declare function decompressJson<T>(data: Uint8Array): T | null;
|
|
143
176
|
|
|
144
177
|
/**
|
|
145
178
|
* Decompress json data
|
|
146
179
|
* @param data
|
|
147
180
|
* @ignore
|
|
148
181
|
*/
|
|
149
|
-
export declare function
|
|
182
|
+
export declare function decompressJsonFromB64<T>(data: string): T | null;
|
|
150
183
|
|
|
151
184
|
/**
|
|
152
185
|
* Simple deferred promise wrapper
|
|
@@ -163,31 +196,31 @@ export declare class Deferred<T> {
|
|
|
163
196
|
}
|
|
164
197
|
|
|
165
198
|
/**
|
|
166
|
-
* The params used to display the
|
|
199
|
+
* The params used to display the embedded wallet
|
|
167
200
|
*
|
|
168
|
-
* @group
|
|
201
|
+
* @group Embedded wallet
|
|
169
202
|
*/
|
|
170
203
|
export declare type DisplayEmbededWalletParamsType = {
|
|
171
204
|
/**
|
|
172
|
-
* The
|
|
205
|
+
* The embedded view to display once the user is logged in
|
|
173
206
|
*/
|
|
174
207
|
loggedIn?: LoggedInEmbededView;
|
|
175
208
|
/**
|
|
176
|
-
* The
|
|
209
|
+
* The embedded view to display once the user is logged out
|
|
177
210
|
*/
|
|
178
211
|
loggedOut?: LoggedOutEmbededView;
|
|
179
212
|
/**
|
|
180
|
-
* Some metadata to
|
|
213
|
+
* Some metadata to customize the embedded view
|
|
181
214
|
*/
|
|
182
215
|
metadata?: {
|
|
183
216
|
/**
|
|
184
|
-
* The logo to display on the
|
|
217
|
+
* The logo to display on the embedded wallet
|
|
185
218
|
* If undefined, will default to no logo displayed
|
|
186
219
|
*/
|
|
187
220
|
logo?: string;
|
|
188
221
|
/**
|
|
189
222
|
* Link to the homepage of the calling website
|
|
190
|
-
* If
|
|
223
|
+
* If undefined, will default to the domain of the calling website
|
|
191
224
|
*/
|
|
192
225
|
homepageLink?: string;
|
|
193
226
|
/**
|
|
@@ -198,6 +231,10 @@ export declare type DisplayEmbededWalletParamsType = {
|
|
|
198
231
|
* The position of the component
|
|
199
232
|
*/
|
|
200
233
|
position?: "left" | "right";
|
|
234
|
+
/**
|
|
235
|
+
* Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
|
|
236
|
+
*/
|
|
237
|
+
i18n?: I18nConfig;
|
|
201
238
|
};
|
|
202
239
|
};
|
|
203
240
|
|
|
@@ -219,9 +256,9 @@ declare type DoBackupEvent = {
|
|
|
219
256
|
};
|
|
220
257
|
|
|
221
258
|
/**
|
|
222
|
-
* The different type of action we can have on the
|
|
259
|
+
* The different type of action we can have on the embedded view (once the user is logged in)
|
|
223
260
|
*
|
|
224
|
-
* @group
|
|
261
|
+
* @group Embedded wallet
|
|
225
262
|
*/
|
|
226
263
|
export declare type EmbededViewAction = {
|
|
227
264
|
key: "sharing";
|
|
@@ -231,11 +268,13 @@ export declare type EmbededViewAction = {
|
|
|
231
268
|
options?: {
|
|
232
269
|
/**
|
|
233
270
|
* The title that will be displayed on the system popup once the system sharing window is open
|
|
271
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
234
272
|
*/
|
|
235
273
|
popupTitle?: string;
|
|
236
274
|
/**
|
|
237
275
|
* The text that will be shared alongside the link.
|
|
238
276
|
* Can contain the variable {LINK} to specify where the link is placed, otherwise it will be added at the end
|
|
277
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
239
278
|
*/
|
|
240
279
|
text?: string;
|
|
241
280
|
/**
|
|
@@ -280,7 +319,13 @@ export declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TPa
|
|
|
280
319
|
export declare type FinalActionType = {
|
|
281
320
|
key: "sharing";
|
|
282
321
|
options?: {
|
|
322
|
+
/**
|
|
323
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
324
|
+
*/
|
|
283
325
|
popupTitle?: string;
|
|
326
|
+
/**
|
|
327
|
+
* @deprecated Use the top level `config.metadata.i18n` instead
|
|
328
|
+
*/
|
|
284
329
|
text?: string;
|
|
285
330
|
link?: string;
|
|
286
331
|
};
|
|
@@ -319,6 +364,8 @@ export declare type FrakClient = {
|
|
|
319
364
|
* The current Frak Context
|
|
320
365
|
*
|
|
321
366
|
* For now, only contain a referrer address.
|
|
367
|
+
*
|
|
368
|
+
* @ignore
|
|
322
369
|
*/
|
|
323
370
|
export declare type FrakContext = {
|
|
324
371
|
r: Address;
|
|
@@ -347,7 +394,8 @@ export declare class FrakRpcError<T = undefined> extends Error {
|
|
|
347
394
|
}
|
|
348
395
|
|
|
349
396
|
/**
|
|
350
|
-
* Configuration for the
|
|
397
|
+
* Configuration for the Frak Wallet SDK
|
|
398
|
+
* @category Config
|
|
351
399
|
*/
|
|
352
400
|
export declare type FrakWalletSdkConfig = {
|
|
353
401
|
/**
|
|
@@ -363,20 +411,37 @@ export declare type FrakWalletSdkConfig = {
|
|
|
363
411
|
* Your application name (will be displayed in a few modals and in SSO)
|
|
364
412
|
*/
|
|
365
413
|
name: string;
|
|
366
|
-
/**
|
|
367
|
-
* Custom CSS styles to apply to the modals and components
|
|
368
|
-
*/
|
|
369
|
-
css?: string;
|
|
370
414
|
/**
|
|
371
415
|
* Language to display in the modal
|
|
372
416
|
* If undefined, will default to the browser language
|
|
373
417
|
*/
|
|
374
|
-
lang?:
|
|
418
|
+
lang?: Language;
|
|
375
419
|
/**
|
|
376
420
|
* The currency to display in the modal
|
|
377
421
|
* @defaultValue `"eur"`
|
|
378
422
|
*/
|
|
379
423
|
currency?: Currency;
|
|
424
|
+
/**
|
|
425
|
+
* The logo URL that will be displayed in a few components
|
|
426
|
+
*/
|
|
427
|
+
logoUrl?: string;
|
|
428
|
+
/**
|
|
429
|
+
* The homepage link that could be displayed in a few components
|
|
430
|
+
*/
|
|
431
|
+
homepageLink?: string;
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Some customization for the modal
|
|
435
|
+
*/
|
|
436
|
+
customizations?: {
|
|
437
|
+
/**
|
|
438
|
+
* Custom CSS styles to apply to the modals and components
|
|
439
|
+
*/
|
|
440
|
+
css?: `${string}.css`;
|
|
441
|
+
/**
|
|
442
|
+
* Custom i18n configuration for the modal
|
|
443
|
+
*/
|
|
444
|
+
i18n?: I18nConfig;
|
|
380
445
|
};
|
|
381
446
|
/**
|
|
382
447
|
* The domain name of your application
|
|
@@ -491,7 +556,7 @@ declare type HandshakeResponse = {
|
|
|
491
556
|
* @param data The params to encode
|
|
492
557
|
* @ignore
|
|
493
558
|
*/
|
|
494
|
-
export declare function hashAndCompressData<T>(data: T):
|
|
559
|
+
export declare function hashAndCompressData<T>(data: T): CompressedData;
|
|
495
560
|
|
|
496
561
|
/**
|
|
497
562
|
* The encoded data to send to a client / received by a client
|
|
@@ -505,6 +570,41 @@ declare type HearbeatEvent = {
|
|
|
505
570
|
clientLifecycle: "heartbeat";
|
|
506
571
|
};
|
|
507
572
|
|
|
573
|
+
/**
|
|
574
|
+
* Custom i18n configuration for the modal
|
|
575
|
+
* See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
|
|
576
|
+
*
|
|
577
|
+
* Available variables
|
|
578
|
+
* - `{{ productName }}` : The name of your website (`metadata.name`)
|
|
579
|
+
* - `{{ productOrigin }}` : The origin url of your website
|
|
580
|
+
* - `{{ 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)
|
|
581
|
+
*
|
|
582
|
+
* Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
|
|
583
|
+
* - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
|
|
584
|
+
* - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* // Multi language config
|
|
589
|
+
* const multiI18n = {
|
|
590
|
+
* fr: {
|
|
591
|
+
* "sdk.modal.title": "Titre de modal",
|
|
592
|
+
* "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
|
|
593
|
+
* },
|
|
594
|
+
* en: "https://example.com/en.json"
|
|
595
|
+
* }
|
|
596
|
+
*
|
|
597
|
+
* // Single language config
|
|
598
|
+
* const singleI18n = {
|
|
599
|
+
* "sdk.modal.title": "Modal title",
|
|
600
|
+
* "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
|
|
601
|
+
* }
|
|
602
|
+
* ```
|
|
603
|
+
*
|
|
604
|
+
* @category Config
|
|
605
|
+
*/
|
|
606
|
+
export declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
|
|
607
|
+
|
|
508
608
|
/**
|
|
509
609
|
* Represent an iframe event
|
|
510
610
|
*/
|
|
@@ -525,10 +625,7 @@ export declare type IFrameLifecycleEvent = {
|
|
|
525
625
|
export declare type IFrameRpcEvent = {
|
|
526
626
|
id: string;
|
|
527
627
|
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
528
|
-
data:
|
|
529
|
-
compressed: string;
|
|
530
|
-
compressedHash: string;
|
|
531
|
-
};
|
|
628
|
+
data: CompressedData;
|
|
532
629
|
};
|
|
533
630
|
|
|
534
631
|
/**
|
|
@@ -581,7 +678,8 @@ export declare type IFrameRpcSchema = [
|
|
|
581
678
|
Method: "frak_displayModal";
|
|
582
679
|
Parameters: [
|
|
583
680
|
requests: ModalRpcStepsInput,
|
|
584
|
-
metadata:
|
|
681
|
+
metadata: ModalRpcMetadata | undefined,
|
|
682
|
+
configMetadata: FrakWalletSdkConfig["metadata"]
|
|
585
683
|
];
|
|
586
684
|
ReturnType: ModalRpcStepsResultType;
|
|
587
685
|
},
|
|
@@ -622,12 +720,12 @@ export declare type IFrameRpcSchema = [
|
|
|
622
720
|
ReturnType: GetProductInformationReturnType;
|
|
623
721
|
},
|
|
624
722
|
/**
|
|
625
|
-
* Method to show the
|
|
723
|
+
* Method to show the embedded wallet, with potential customization
|
|
626
724
|
*/
|
|
627
725
|
{
|
|
628
726
|
Method: "frak_displayEmbededWallet";
|
|
629
727
|
Parameters: [
|
|
630
|
-
DisplayEmbededWalletParamsType,
|
|
728
|
+
request: DisplayEmbededWalletParamsType,
|
|
631
729
|
metadata: FrakWalletSdkConfig["metadata"]
|
|
632
730
|
];
|
|
633
731
|
ReturnType: undefined;
|
|
@@ -703,6 +801,12 @@ export declare type InteractionTypesKey = {
|
|
|
703
801
|
*/
|
|
704
802
|
export declare type KeyProvider<DataType> = (value: DataType) => string[];
|
|
705
803
|
|
|
804
|
+
/**
|
|
805
|
+
* All the languages available
|
|
806
|
+
* @category Config
|
|
807
|
+
*/
|
|
808
|
+
export declare type Language = "fr" | "en";
|
|
809
|
+
|
|
706
810
|
/**
|
|
707
811
|
* Type used for a listening request
|
|
708
812
|
* @inline
|
|
@@ -725,13 +829,21 @@ export declare const locales: {
|
|
|
725
829
|
export declare type LocalesKey = keyof typeof locales;
|
|
726
830
|
|
|
727
831
|
/**
|
|
728
|
-
*
|
|
832
|
+
* A localized i18n config
|
|
833
|
+
* @category Config
|
|
834
|
+
*/
|
|
835
|
+
export declare type LocalizedI18nConfig = `${string}.css` | {
|
|
836
|
+
[key: string]: string;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Some configuration options for the embedded view
|
|
729
841
|
*
|
|
730
|
-
* @group
|
|
842
|
+
* @group Embedded wallet
|
|
731
843
|
*/
|
|
732
844
|
export declare type LoggedInEmbededView = {
|
|
733
845
|
/**
|
|
734
|
-
* The main action to display on the logged in
|
|
846
|
+
* The main action to display on the logged in embedded view
|
|
735
847
|
* If none specified, the user will see his wallet with the activation button
|
|
736
848
|
*/
|
|
737
849
|
action?: EmbededViewAction;
|
|
@@ -739,26 +851,28 @@ export declare type LoggedInEmbededView = {
|
|
|
739
851
|
|
|
740
852
|
/**
|
|
741
853
|
* The view when a user is logged out
|
|
742
|
-
* @group
|
|
854
|
+
* @group Embedded wallet
|
|
743
855
|
*/
|
|
744
856
|
export declare type LoggedOutEmbededView = {
|
|
745
857
|
/**
|
|
746
|
-
* Metadata option when displaying the
|
|
858
|
+
* Metadata option when displaying the embedded view
|
|
747
859
|
*/
|
|
748
860
|
metadata?: {
|
|
749
861
|
/**
|
|
750
862
|
* The main CTA for the logged out view
|
|
751
863
|
* - can include some variable, available ones are:
|
|
752
|
-
* - {REWARD} -> The maximum reward a user can receive when
|
|
864
|
+
* - {REWARD} -> The maximum reward a user can receive when interacting on your website
|
|
753
865
|
* - can be formatted in markdown
|
|
754
866
|
*
|
|
755
|
-
* If not
|
|
867
|
+
* If not set, it will default to a internationalized message
|
|
868
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
756
869
|
*/
|
|
757
870
|
text?: string;
|
|
758
871
|
/**
|
|
759
872
|
* The text that will be displayed on the login button
|
|
760
873
|
*
|
|
761
|
-
* If not set, it will default to a
|
|
874
|
+
* If not set, it will default to a internationalized message
|
|
875
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
762
876
|
*/
|
|
763
877
|
buttonText?: string;
|
|
764
878
|
};
|
|
@@ -785,7 +899,7 @@ declare type LoginWithoutSso = {
|
|
|
785
899
|
/** @inline */
|
|
786
900
|
declare type LoginWithSso = {
|
|
787
901
|
allowSso: true;
|
|
788
|
-
ssoMetadata
|
|
902
|
+
ssoMetadata?: SsoMetadata;
|
|
789
903
|
};
|
|
790
904
|
|
|
791
905
|
/**
|
|
@@ -798,10 +912,16 @@ export declare type ModalRpcMetadata = {
|
|
|
798
912
|
title?: string;
|
|
799
913
|
icon?: string;
|
|
800
914
|
};
|
|
801
|
-
context?: string;
|
|
802
915
|
targetInteraction?: FullInteractionTypesKey;
|
|
916
|
+
/**
|
|
917
|
+
* Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
|
|
918
|
+
*/
|
|
919
|
+
i18n?: I18nConfig;
|
|
803
920
|
} & ({
|
|
804
921
|
isDismissible: true;
|
|
922
|
+
/**
|
|
923
|
+
* @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
|
|
924
|
+
*/
|
|
805
925
|
dismissActionTxt?: string;
|
|
806
926
|
} | {
|
|
807
927
|
isDismissible?: false;
|
|
@@ -835,29 +955,34 @@ export declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalSt
|
|
|
835
955
|
};
|
|
836
956
|
|
|
837
957
|
/**
|
|
838
|
-
* Metadata that can be used to
|
|
958
|
+
* Metadata that can be used to customize a modal step
|
|
839
959
|
* @group Modal Display
|
|
960
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
840
961
|
*/
|
|
841
962
|
export declare type ModalStepMetadata = {
|
|
842
963
|
metadata?: {
|
|
843
964
|
/**
|
|
844
965
|
* Custom title for the step
|
|
845
|
-
* If none provided, it will use an
|
|
966
|
+
* If none provided, it will use an internationalized text
|
|
967
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
846
968
|
*/
|
|
847
969
|
title?: string;
|
|
848
970
|
/**
|
|
849
971
|
* Custom description for the step
|
|
850
|
-
* If none provided, it will use an
|
|
972
|
+
* If none provided, it will use an internationalized text
|
|
973
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
851
974
|
*/
|
|
852
975
|
description?: string;
|
|
853
976
|
/**
|
|
854
977
|
* Custom text for the primary action of the step
|
|
855
|
-
* If none provided, it will use an
|
|
978
|
+
* If none provided, it will use an internationalized text
|
|
979
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
856
980
|
*/
|
|
857
981
|
primaryActionText?: string;
|
|
858
982
|
/**
|
|
859
983
|
* Custom text for the secondary action of the step
|
|
860
|
-
* If none provided, it will use an
|
|
984
|
+
* If none provided, it will use an internationalized text
|
|
985
|
+
* @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
|
|
861
986
|
*/
|
|
862
987
|
secondaryActionText?: string;
|
|
863
988
|
};
|
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{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 i}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()}}class
|
|
13
|
+
`.trim()}}class s{_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 c(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function l(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 d=new e.CborEncoder;function u(e){let t={...e,validationHash:h(e)};return d.encode(t)}function f(e){return d.encode(e)}function p(e){return c(f(e))}function h(e){return(0,t.sha256)(d.encode(e))}let m=new e.CborDecoder;function g(e){if(!e.length)throw new n(a.corruptedResponse,"Missing compressed data");let t=w(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(h(o)!==t.validationHash)throw new n(a.corruptedResponse,"Invalid data validation hash");return t}function w(e){try{return m.decode(e)}catch(t){return console.error("Invalid compressed data",{e:t,data:e}),null}}function y(e){return w(l(e))}let b="nexus-wallet-backup",v={id:"frak-wallet",name:"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()}}(),c=function({iframe:e}){let t=new s;return{handleEvent:async n=>{switch(n.iframeLifecycle){case"connected":t.resolve(!0);break;case"do-backup":n.data.backup?localStorage.setItem(b,n.data.backup):localStorage.removeItem(b);break;case"remove-backup":localStorage.removeItem(b);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}),l=new i(e,t),d=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:c,debugInfo:l}),f=async e=>{if(!await c.isConnected)throw new n(a.clientNotConnected,"The iframe provider isn't connected yet");let t=new s,r=o.createChannel(e=>{let a=g(e.data);a.error?t.reject(new n(a.error.code,a.error.message,a.error?.data)):t.resolve(a.result),o.removeChannel(r)}),i=u(e);return d.sendEvent({id:r,topic:e.method,data:i}),t.promise},p=async(e,t)=>{if(!await c.isConnected)throw new n(a.clientNotConnected,"The iframe provider isn't connected yet");let i=o.createChannel(e=>{let n=g(e.data);if(n.result)t(n.result);else throw new r("No valid result in the response")}),s=u(e);d.sendEvent({id:i,topic:e.method,data:s})},h=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}(d,c),m=async()=>{h(),o.destroy(),d.cleanup(),t.remove()},w=E({config:e,messageHandler:d,lifecycleManager:c}).then(()=>l.updateSetupStatus(!0));return{config:e,debugInfo:l,waitForConnection:c.isConnected,waitForSetup:w,request:f,listenerRequest:p,destroy:m}}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(b);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 c(n)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function U(e){if(e&&0!==e.length)try{let n=l(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,i as DebugInfoGatherer,s as Deferred,q as FrakContextManager,n as FrakRpcError,a as RpcErrorCodes,l as base64urlDecode,c as base64urlEncode,v as baseIframeProps,f as compressJson,p as compressJsonToB64,S as createIFrameFrakClient,C as createIframe,g as decompressDataAndCheckHash,w as decompressJson,y as decompressJsonFromB64,j as formatAmount,L as getCurrencyAmountKey,x as getSupportedCurrency,T as getSupportedLocale,u 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.10",
|
|
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"
|