@frak-labs/core-sdk 0.1.0-beta.afa252b0 → 0.1.0-beta.b0bd1f8a

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.
Files changed (139) hide show
  1. package/cdn/bundle.iife.js +14 -0
  2. package/dist/actions-CEEObPYc.js +1 -0
  3. package/dist/actions-DbQhWYx8.cjs +1 -0
  4. package/dist/actions.cjs +1 -1
  5. package/dist/actions.d.cts +3 -1481
  6. package/dist/actions.d.ts +3 -1481
  7. package/dist/actions.js +1 -1
  8. package/dist/bundle.cjs +1 -13
  9. package/dist/bundle.d.cts +6 -2087
  10. package/dist/bundle.d.ts +6 -2087
  11. package/dist/bundle.js +1 -13
  12. package/dist/index-7OZ39x1U.d.ts +195 -0
  13. package/dist/index-C6FxkWPC.d.cts +511 -0
  14. package/dist/index-UFX7xCg3.d.ts +351 -0
  15. package/dist/index-d8xS4ryI.d.ts +511 -0
  16. package/dist/index-p4FqSp8z.d.cts +351 -0
  17. package/dist/index-zDq-VlKx.d.cts +195 -0
  18. package/dist/index.cjs +1 -13
  19. package/dist/index.d.cts +4 -1387
  20. package/dist/index.d.ts +4 -1387
  21. package/dist/index.js +1 -13
  22. package/dist/interaction-DMJ3ZfaF.d.cts +45 -0
  23. package/dist/interaction-KX1h9a7V.d.ts +45 -0
  24. package/dist/interactions-DnfM3oe0.js +1 -0
  25. package/dist/interactions-EIXhNLf6.cjs +1 -0
  26. package/dist/interactions.cjs +1 -1
  27. package/dist/interactions.d.cts +2 -182
  28. package/dist/interactions.d.ts +2 -182
  29. package/dist/interactions.js +1 -1
  30. package/dist/openSso-D--Airj6.d.cts +1018 -0
  31. package/dist/openSso-DsKJ4y0j.d.ts +1018 -0
  32. package/dist/productTypes-BUkXJKZ7.cjs +1 -0
  33. package/dist/productTypes-CGb1MmBF.js +1 -0
  34. package/dist/src-B_xO0AR6.cjs +13 -0
  35. package/dist/src-D2d52OZa.js +13 -0
  36. package/dist/trackEvent-CHnYa85W.js +1 -0
  37. package/dist/trackEvent-GuQm_1Nm.cjs +1 -0
  38. package/package.json +23 -18
  39. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  40. package/src/actions/displayEmbeddedWallet.ts +20 -0
  41. package/src/actions/displayModal.test.ts +387 -0
  42. package/src/actions/displayModal.ts +131 -0
  43. package/src/actions/getProductInformation.test.ts +133 -0
  44. package/src/actions/getProductInformation.ts +14 -0
  45. package/src/actions/index.ts +29 -0
  46. package/src/actions/openSso.test.ts +407 -0
  47. package/src/actions/openSso.ts +116 -0
  48. package/src/actions/prepareSso.test.ts +223 -0
  49. package/src/actions/prepareSso.ts +48 -0
  50. package/src/actions/referral/processReferral.ts +230 -0
  51. package/src/actions/referral/referralInteraction.ts +57 -0
  52. package/src/actions/sendInteraction.test.ts +219 -0
  53. package/src/actions/sendInteraction.ts +32 -0
  54. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  55. package/src/actions/trackPurchaseStatus.ts +53 -0
  56. package/src/actions/watchWalletStatus.test.ts +372 -0
  57. package/src/actions/watchWalletStatus.ts +94 -0
  58. package/src/actions/wrapper/modalBuilder.ts +212 -0
  59. package/src/actions/wrapper/sendTransaction.ts +62 -0
  60. package/src/actions/wrapper/siweAuthenticate.ts +94 -0
  61. package/src/bundle.ts +3 -0
  62. package/src/clients/DebugInfo.ts +182 -0
  63. package/src/clients/createIFrameFrakClient.ts +287 -0
  64. package/src/clients/index.ts +3 -0
  65. package/src/clients/setupClient.test.ts +343 -0
  66. package/src/clients/setupClient.ts +73 -0
  67. package/src/clients/transports/iframeLifecycleManager.test.ts +399 -0
  68. package/src/clients/transports/iframeLifecycleManager.ts +90 -0
  69. package/src/constants/interactionTypes.ts +44 -0
  70. package/src/constants/locales.ts +14 -0
  71. package/src/constants/productTypes.ts +33 -0
  72. package/src/index.ts +101 -0
  73. package/src/interactions/index.ts +5 -0
  74. package/src/interactions/pressEncoder.test.ts +215 -0
  75. package/src/interactions/pressEncoder.ts +53 -0
  76. package/src/interactions/purchaseEncoder.test.ts +291 -0
  77. package/src/interactions/purchaseEncoder.ts +99 -0
  78. package/src/interactions/referralEncoder.test.ts +170 -0
  79. package/src/interactions/referralEncoder.ts +47 -0
  80. package/src/interactions/retailEncoder.test.ts +107 -0
  81. package/src/interactions/retailEncoder.ts +37 -0
  82. package/src/interactions/webshopEncoder.test.ts +56 -0
  83. package/src/interactions/webshopEncoder.ts +30 -0
  84. package/src/types/client.ts +14 -0
  85. package/src/types/compression.ts +22 -0
  86. package/src/types/config.ts +111 -0
  87. package/src/types/context.ts +13 -0
  88. package/src/types/index.ts +71 -0
  89. package/src/types/lifecycle/client.ts +46 -0
  90. package/src/types/lifecycle/iframe.ts +35 -0
  91. package/src/types/lifecycle/index.ts +2 -0
  92. package/src/types/rpc/displayModal.ts +84 -0
  93. package/src/types/rpc/embedded/index.ts +68 -0
  94. package/src/types/rpc/embedded/loggedIn.ts +55 -0
  95. package/src/types/rpc/embedded/loggedOut.ts +28 -0
  96. package/src/types/rpc/interaction.ts +43 -0
  97. package/src/types/rpc/modal/final.ts +46 -0
  98. package/src/types/rpc/modal/generic.ts +46 -0
  99. package/src/types/rpc/modal/index.ts +20 -0
  100. package/src/types/rpc/modal/login.ts +32 -0
  101. package/src/types/rpc/modal/openSession.ts +25 -0
  102. package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
  103. package/src/types/rpc/modal/transaction.ts +33 -0
  104. package/src/types/rpc/productInformation.ts +59 -0
  105. package/src/types/rpc/sso.ts +80 -0
  106. package/src/types/rpc/walletStatus.ts +35 -0
  107. package/src/types/rpc.ts +158 -0
  108. package/src/types/transport.ts +34 -0
  109. package/src/utils/FrakContext.test.ts +407 -0
  110. package/src/utils/FrakContext.ts +158 -0
  111. package/src/utils/compression/b64.test.ts +181 -0
  112. package/src/utils/compression/b64.ts +29 -0
  113. package/src/utils/compression/compress.test.ts +123 -0
  114. package/src/utils/compression/compress.ts +11 -0
  115. package/src/utils/compression/decompress.test.ts +145 -0
  116. package/src/utils/compression/decompress.ts +11 -0
  117. package/src/utils/compression/index.ts +3 -0
  118. package/src/utils/computeProductId.test.ts +80 -0
  119. package/src/utils/computeProductId.ts +11 -0
  120. package/src/utils/constants.test.ts +23 -0
  121. package/src/utils/constants.ts +4 -0
  122. package/src/utils/formatAmount.test.ts +113 -0
  123. package/src/utils/formatAmount.ts +18 -0
  124. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  125. package/src/utils/getCurrencyAmountKey.ts +15 -0
  126. package/src/utils/getSupportedCurrency.test.ts +51 -0
  127. package/src/utils/getSupportedCurrency.ts +14 -0
  128. package/src/utils/getSupportedLocale.test.ts +64 -0
  129. package/src/utils/getSupportedLocale.ts +16 -0
  130. package/src/utils/iframeHelper.test.ts +450 -0
  131. package/src/utils/iframeHelper.ts +143 -0
  132. package/src/utils/index.ts +21 -0
  133. package/src/utils/sso.test.ts +361 -0
  134. package/src/utils/sso.ts +119 -0
  135. package/src/utils/ssoUrlListener.ts +60 -0
  136. package/src/utils/trackEvent.test.ts +162 -0
  137. package/src/utils/trackEvent.ts +26 -0
  138. package/cdn/bundle.js +0 -19
  139. package/cdn/bundle.js.LICENSE.txt +0 -10
@@ -0,0 +1,351 @@
1
+ import { J as Currency, L as PrepareSsoParamsType, Y as FrakWalletSdkConfig, a as FrakClient, d as TokenAmountType, i as FrakContext, z as SsoMetadata } from "./openSso-DsKJ4y0j.js";
2
+ import { Hex } from "viem";
3
+ import { RpcMessage, RpcResponse } from "@frak-labs/frame-connector";
4
+
5
+ //#region src/types/compression.d.ts
6
+ /**
7
+ * The received encoded data from a client
8
+ * -> The encoded should contain a HashProtectedData once decoded
9
+ * @ignore
10
+ */
11
+ type CompressedData = Uint8Array;
12
+ /**
13
+ * The encoded data to send to a client / received by a client
14
+ * @ignore
15
+ */
16
+ type HashProtectedData<DataType> = Readonly<DataType & {
17
+ validationHash: string;
18
+ }>;
19
+ /**
20
+ * Represent a key provider used for the hashed and secure compression
21
+ * @ignore
22
+ */
23
+ type KeyProvider<DataType> = (value: DataType) => string[];
24
+ //#endregion
25
+ //#region src/clients/createIFrameFrakClient.d.ts
26
+ /**
27
+ * Create a new iframe Frak client
28
+ * @param args
29
+ * @param args.config - The configuration to use for the Frak Wallet SDK
30
+ * @param args.iframe - The iframe to use for the communication
31
+ * @returns The created Frak Client
32
+ *
33
+ * @example
34
+ * const frakConfig: FrakWalletSdkConfig = {
35
+ * metadata: {
36
+ * name: "My app title",
37
+ * },
38
+ * }
39
+ * const iframe = await createIframe({ config: frakConfig });
40
+ * const client = createIFrameFrakClient({ config: frakConfig, iframe });
41
+ */
42
+ declare function createIFrameFrakClient({
43
+ config,
44
+ iframe
45
+ }: {
46
+ config: FrakWalletSdkConfig;
47
+ iframe: HTMLIFrameElement;
48
+ }): FrakClient;
49
+ //#endregion
50
+ //#region src/clients/DebugInfo.d.ts
51
+ /** @ignore */
52
+ declare class DebugInfoGatherer {
53
+ private config?;
54
+ private iframe?;
55
+ private isSetupDone;
56
+ private lastResponse;
57
+ private lastRequest;
58
+ constructor(config?: FrakWalletSdkConfig, iframe?: HTMLIFrameElement);
59
+ setLastResponse(message: RpcMessage, response: RpcResponse): void;
60
+ setLastRequest(event: RpcMessage): void;
61
+ updateSetupStatus(status: boolean): void;
62
+ private base64Encode;
63
+ /**
64
+ * Extract information from the iframe status
65
+ */
66
+ private getIframeStatus;
67
+ private getNavigatorInfo;
68
+ private gatherDebugInfo;
69
+ static empty(): DebugInfoGatherer;
70
+ /**
71
+ * Format Frak debug information
72
+ */
73
+ formatDebugInfo(error: Error | unknown | string): string;
74
+ }
75
+ //#endregion
76
+ //#region src/clients/setupClient.d.ts
77
+ /**
78
+ * Directly setup the Frak client with an iframe
79
+ * Return when the FrakClient is ready (setup and communication estbalished with the wallet)
80
+ *
81
+ * @param config - The configuration to use for the Frak Wallet SDK
82
+ * @returns a Promise with the Frak Client
83
+ *
84
+ * @example
85
+ * const frakConfig: FrakWalletSdkConfig = {
86
+ * metadata: {
87
+ * name: "My app title",
88
+ * },
89
+ * }
90
+ * const client = await setupClient({ config: frakConfig });
91
+ */
92
+ declare function setupClient({
93
+ config
94
+ }: {
95
+ config: FrakWalletSdkConfig;
96
+ }): Promise<FrakClient | undefined>;
97
+ //#endregion
98
+ //#region src/constants/locales.d.ts
99
+ /**
100
+ * The keys for each locales
101
+ * @inline
102
+ */
103
+ type LocalesKey = keyof typeof locales;
104
+ /**
105
+ * Map the currency to the locale
106
+ */
107
+ declare const locales: {
108
+ readonly eur: "fr-FR";
109
+ readonly usd: "en-US";
110
+ readonly gbp: "en-GB";
111
+ };
112
+ //#endregion
113
+ //#region src/utils/compression/b64.d.ts
114
+ /**
115
+ * Encode a buffer to a base64url encoded string
116
+ * @param buffer The buffer to encode
117
+ * @returns The encoded string
118
+ */
119
+ declare function base64urlEncode(buffer: Uint8Array): string;
120
+ /**
121
+ * Decode a base64url encoded string
122
+ * @param value The value to decode
123
+ * @returns The decoded value
124
+ */
125
+ declare function base64urlDecode(value: string): Uint8Array;
126
+ //#endregion
127
+ //#region src/utils/compression/compress.d.ts
128
+ /**
129
+ * Compress json data
130
+ * @param data
131
+ * @ignore
132
+ */
133
+ declare function compressJsonToB64(data: unknown): string;
134
+ //#endregion
135
+ //#region src/utils/compression/decompress.d.ts
136
+ /**
137
+ * Decompress json data
138
+ * @param data
139
+ * @ignore
140
+ */
141
+ declare function decompressJsonFromB64<T>(data: string): T | null;
142
+ //#endregion
143
+ //#region src/utils/FrakContext.d.ts
144
+ /**
145
+ * Compress the current Frak context
146
+ * @param context - The context to be compressed
147
+ * @returns A compressed string containing the Frak context
148
+ */
149
+ declare function compress(context?: Partial<FrakContext>): string | undefined;
150
+ /**
151
+ * Decompress the given Frak context
152
+ * @param context - The raw context to be decompressed into a `FrakContext`
153
+ * @returns The decompressed Frak context, or undefined if it fails
154
+ */
155
+ declare function decompress(context?: string): FrakContext | undefined;
156
+ /**
157
+ * Parse the current URL into a Frak Context
158
+ * @param args
159
+ * @param args.url - The url to parse
160
+ * @returns The parsed Frak context
161
+ */
162
+ declare function parse({
163
+ url
164
+ }: {
165
+ url: string;
166
+ }): FrakContext | null | undefined;
167
+ /**
168
+ * Populate the current url with the given Frak context
169
+ * @param args
170
+ * @param args.url - The url to update
171
+ * @param args.context - The context to update
172
+ * @returns The new url with the Frak context
173
+ */
174
+ declare function update({
175
+ url,
176
+ context
177
+ }: {
178
+ url?: string;
179
+ context: Partial<FrakContext>;
180
+ }): string | null;
181
+ /**
182
+ * Remove Frak context from current url
183
+ * @param url - The url to update
184
+ * @returns The new url without the Frak context
185
+ */
186
+ declare function remove(url: string): string;
187
+ /**
188
+ * Replace the current url with the given Frak context
189
+ * @param args
190
+ * @param args.url - The url to update
191
+ * @param args.context - The context to update
192
+ */
193
+ declare function replaceUrl({
194
+ url: baseUrl,
195
+ context
196
+ }: {
197
+ url?: string;
198
+ context: Partial<FrakContext> | null;
199
+ }): void;
200
+ /**
201
+ * Export our frak context
202
+ */
203
+ declare const FrakContextManager: {
204
+ compress: typeof compress;
205
+ decompress: typeof decompress;
206
+ parse: typeof parse;
207
+ update: typeof update;
208
+ remove: typeof remove;
209
+ replaceUrl: typeof replaceUrl;
210
+ };
211
+ //#endregion
212
+ //#region src/utils/formatAmount.d.ts
213
+ declare function formatAmount(amount: number, currency?: Currency): string;
214
+ //#endregion
215
+ //#region src/utils/getCurrencyAmountKey.d.ts
216
+ /**
217
+ * Get the currency amount key for a given currency
218
+ * @param currency - The currency to use
219
+ * @returns The currency amount key
220
+ */
221
+ declare function getCurrencyAmountKey(currency?: Currency): keyof TokenAmountType;
222
+ //#endregion
223
+ //#region src/utils/getSupportedCurrency.d.ts
224
+ /**
225
+ * Get the supported currency for a given currency
226
+ * @param currency - The currency to use
227
+ * @returns The supported currency
228
+ */
229
+ declare function getSupportedCurrency(currency?: Currency): Currency;
230
+ //#endregion
231
+ //#region src/utils/getSupportedLocale.d.ts
232
+ /**
233
+ * Get the supported locale for a given currency
234
+ * @param currency - The currency to use
235
+ * @returns The supported locale
236
+ */
237
+ declare function getSupportedLocale(currency?: Currency): (typeof locales)[LocalesKey];
238
+ //#endregion
239
+ //#region src/utils/iframeHelper.d.ts
240
+ /**
241
+ * Base props for the iframe
242
+ * @ignore
243
+ */
244
+ declare const baseIframeProps: {
245
+ id: string;
246
+ name: string;
247
+ title: string;
248
+ allow: string;
249
+ style: {
250
+ width: string;
251
+ height: string;
252
+ border: string;
253
+ position: string;
254
+ zIndex: number;
255
+ top: string;
256
+ left: string;
257
+ colorScheme: string;
258
+ };
259
+ };
260
+ /**
261
+ * Create the Frak iframe
262
+ * @param args
263
+ * @param args.walletBaseUrl - Use `config.walletUrl` instead. Will be removed in future versions.
264
+ * @param args.config - The configuration object containing iframe options, including the replacement for `walletBaseUrl`.
265
+ */
266
+ declare function createIframe({
267
+ walletBaseUrl,
268
+ config
269
+ }: {
270
+ walletBaseUrl?: string;
271
+ config?: FrakWalletSdkConfig;
272
+ }): Promise<HTMLIFrameElement | undefined>;
273
+ /**
274
+ * Find an iframe within window.opener by pathname
275
+ *
276
+ * When a popup is opened via window.open from an iframe, window.opener points to
277
+ * the parent window, not the iframe itself. This utility searches through all frames
278
+ * in window.opener to find an iframe matching the specified pathname.
279
+ *
280
+ * @param pathname - The pathname to search for (default: "/listener")
281
+ * @returns The matching iframe window, or null if not found
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * // Find the default /listener iframe
286
+ * const listenerIframe = findIframeInOpener();
287
+ *
288
+ * // Find a custom iframe
289
+ * const customIframe = findIframeInOpener("/my-custom-iframe");
290
+ * ```
291
+ */
292
+ declare function findIframeInOpener(pathname?: string): Window | null;
293
+ //#endregion
294
+ //#region src/utils/sso.d.ts
295
+ type AppSpecificSsoMetadata = SsoMetadata & {
296
+ name: string;
297
+ css?: string;
298
+ };
299
+ /**
300
+ * The full SSO params that will be used for compression
301
+ */
302
+ type FullSsoParams = Omit<PrepareSsoParamsType, "metadata"> & {
303
+ metadata: AppSpecificSsoMetadata;
304
+ productId: Hex;
305
+ };
306
+ /**
307
+ * Generate SSO URL with compressed parameters
308
+ * This mirrors the wallet's getOpenSsoLink() function
309
+ *
310
+ * @param walletUrl - Base wallet URL (e.g., "https://wallet.frak.id")
311
+ * @param params - SSO parameters
312
+ * @param productId - Product identifier
313
+ * @param name - Application name
314
+ * @param css - Optional custom CSS
315
+ * @returns Complete SSO URL ready to open in popup or redirect
316
+ *
317
+ * @example
318
+ * ```ts
319
+ * const ssoUrl = generateSsoUrl(
320
+ * "https://wallet.frak.id",
321
+ * { metadata: { logoUrl: "..." }, directExit: true },
322
+ * "0x123...",
323
+ * "My App"
324
+ * );
325
+ * // Returns: https://wallet.frak.id/sso?p=<compressed_base64>
326
+ * ```
327
+ */
328
+ declare function generateSsoUrl(walletUrl: string, params: PrepareSsoParamsType, productId: Hex, name: string, css?: string): string;
329
+ /**
330
+ * Type of compressed the sso data
331
+ */
332
+ type CompressedSsoData = {
333
+ id?: Hex;
334
+ r?: string;
335
+ d?: boolean;
336
+ l?: "en" | "fr";
337
+ p: Hex;
338
+ m: {
339
+ n: string;
340
+ css?: string;
341
+ l?: string;
342
+ h?: string;
343
+ };
344
+ };
345
+ //#endregion
346
+ //#region src/utils/trackEvent.d.ts
347
+ type FrakEvent = "share_button_clicked" | "wallet_button_clicked" | "share_modal_error" | "user_referred";
348
+ type EventProps = Record<string, unknown>;
349
+ declare function trackEvent(client: FrakClient | undefined, event: FrakEvent, props?: EventProps): void;
350
+ //#endregion
351
+ export { CompressedData as C, createIFrameFrakClient as S, KeyProvider as T, base64urlEncode as _, generateSsoUrl as a, setupClient as b, findIframeInOpener as c, getCurrencyAmountKey as d, formatAmount as f, base64urlDecode as g, compressJsonToB64 as h, FullSsoParams as i, getSupportedLocale as l, decompressJsonFromB64 as m, AppSpecificSsoMetadata as n, baseIframeProps as o, FrakContextManager as p, CompressedSsoData as r, createIframe as s, trackEvent as t, getSupportedCurrency as u, LocalesKey as v, HashProtectedData as w, DebugInfoGatherer as x, locales as y };