@frak-labs/nexus-sdk 0.0.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ import { Hex, Address, RpcSchema } from 'viem';
2
+ import { Prettify } from 'viem/chains';
3
+
4
+ /**
5
+ * Configuration for the Frak Wallet SDK
6
+ */
7
+ type FrakWalletSdkConfig = Readonly<{
8
+ walletUrl: string;
9
+ contentId: Hex;
10
+ contentTitle: string;
11
+ }>;
12
+
13
+ type PaidArticleUnlockPrice = Readonly<{
14
+ index: number;
15
+ unlockDurationInSec: number;
16
+ frkAmount: Hex;
17
+ }>;
18
+
19
+ /**
20
+ * Request to unlock a paid article
21
+ */
22
+ type StartArticleUnlockParams = Readonly<{
23
+ articleId: Hex;
24
+ contentId: Hex;
25
+ imageUrl: string;
26
+ articleTitle: string;
27
+ contentTitle: string;
28
+ price: PaidArticleUnlockPrice;
29
+ articleUrl: string;
30
+ redirectUrl: string;
31
+ previewUrl?: string;
32
+ }>;
33
+ /**
34
+ * Return type of the unlock request
35
+ */
36
+ type StartArticleUnlockReturnType = UnlockSuccess | AlreadyUnlocked | UnlockError;
37
+ type UnlockSuccess = {
38
+ key: "success";
39
+ status: "in-progress";
40
+ user: Address;
41
+ userOpHash: Hex;
42
+ };
43
+ type AlreadyUnlocked = {
44
+ key: "already-unlocked";
45
+ status: "unlocked";
46
+ user: Address;
47
+ };
48
+ type UnlockError = {
49
+ key: "error" | "cancelled";
50
+ status: "locked";
51
+ user?: Address;
52
+ reason?: string;
53
+ };
54
+
55
+ /**
56
+ * The response to the get unlock options response
57
+ */
58
+ type UnlockOptionsReturnType = Readonly<{
59
+ prices: {
60
+ index: number;
61
+ unlockDurationInSec: number;
62
+ frkAmount: Hex;
63
+ isUserAccessible: boolean | null;
64
+ }[];
65
+ }>;
66
+
67
+ /**
68
+ * The different types of response for the current unlock status
69
+ */
70
+ type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
71
+ /**
72
+ * When the content unlocked was expired a few time ago
73
+ */
74
+ type UnlockStatusLocked = {
75
+ key: "expired";
76
+ status: "locked";
77
+ expiredAt: number;
78
+ } | {
79
+ key: "not-unlocked";
80
+ status: "locked";
81
+ };
82
+ /**
83
+ * When the content unlocked was expired a few time ago
84
+ */
85
+ type UnlockStatusProcessing = {
86
+ key: "preparing" | "waiting-user-validation";
87
+ } | {
88
+ key: "waiting-transaction-bundling";
89
+ userOpHash: Hex;
90
+ } | {
91
+ key: "waiting-transaction-confirmation";
92
+ userOpHash: Hex;
93
+ txHash: Hex;
94
+ };
95
+ /**
96
+ * When the content unlocked was expired a few time ago
97
+ */
98
+ type UnlockStatusValid = {
99
+ key: "valid";
100
+ status: "unlocked";
101
+ allowedUntil: number;
102
+ };
103
+ /**
104
+ * When the content unlocked was expired a few time ago
105
+ */
106
+ type UnlockStatusError = {
107
+ key: "error";
108
+ status: "locked";
109
+ reason: string;
110
+ };
111
+
112
+ type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
113
+ type WalletConnected = {
114
+ key: "connected";
115
+ wallet: Address;
116
+ frkBalanceAsHex: Hex;
117
+ };
118
+ type WalletNotConnected = {
119
+ key: "not-connected";
120
+ };
121
+
122
+ /**
123
+ * RPC interface that's used for the iframe communication
124
+ */
125
+ type IFrameRpcSchema = [
126
+ /**
127
+ * Method used to fetch an article unlock options
128
+ */
129
+ {
130
+ Method: "frak_getArticleUnlockOptions";
131
+ Parameters: [contentId: Hex, articleId: Hex];
132
+ ReturnType: UnlockOptionsReturnType;
133
+ },
134
+ /**
135
+ * Method used to listen to the wallet status
136
+ */
137
+ {
138
+ Method: "frak_listenToWalletStatus";
139
+ Parameters?: undefined;
140
+ ReturnType: WalletStatusReturnType;
141
+ },
142
+ /**
143
+ * Method used to listen to an article unlock status
144
+ */
145
+ {
146
+ Method: "frak_listenToArticleUnlockStatus";
147
+ Parameters: [contentId: Hex, articleId: Hex];
148
+ ReturnType: ArticleUnlockStatusReturnType;
149
+ }
150
+ ];
151
+ /**
152
+ * RPC interface that's used for the redirection communication
153
+ */
154
+ type RedirectRpcSchema = [
155
+ /**
156
+ * Method used to start the unlock of an article
157
+ */
158
+ {
159
+ Method: "frak_startArticleUnlock";
160
+ Path: "/paywall";
161
+ Parameters: StartArticleUnlockParams;
162
+ ReturnType: StartArticleUnlockReturnType;
163
+ }
164
+ ];
165
+
166
+ /**
167
+ * Type that extract the possible parameters from a RPC Schema
168
+ */
169
+ type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema | undefined = undefined> = TRpcSchema extends RpcSchema ? {
170
+ [K in keyof TRpcSchema]: Prettify<{
171
+ method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
172
+ } & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
173
+ params?: never;
174
+ } : {
175
+ params: TRpcSchema[K]["Parameters"];
176
+ } : never)>;
177
+ }[number] : {
178
+ method: string;
179
+ params?: unknown;
180
+ };
181
+ /**
182
+ * Type that extract the possible return type from a RPC Schema
183
+ */
184
+ type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema | undefined = undefined, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = TRpcSchema extends RpcSchema ? ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"] : unknown;
185
+ /**
186
+ * Type that extract the possible return type from a RPC Schema
187
+ */
188
+ type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema | undefined = undefined, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = TRpcSchema extends RpcSchema ? Extract<TRpcSchema[number], {
189
+ Method: TMethod;
190
+ }> : unknown;
191
+ /**
192
+ * Type used for a one shot request function
193
+ */
194
+ type RequestFn<TRpcSchema extends RpcSchema | undefined = undefined> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
195
+ /**
196
+ * Type used for a one shot request function
197
+ */
198
+ type ListenerRequestFn<TRpcSchema extends RpcSchema | undefined = undefined> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
199
+ /**
200
+ * IFrame transport interface
201
+ */
202
+ type IFrameTransport = {
203
+ /**
204
+ * Wait for the connection to be established
205
+ */
206
+ waitForConnection: Promise<boolean>;
207
+ /**
208
+ * Function used to perform a single request via the iframe transport
209
+ */
210
+ request: RequestFn<IFrameRpcSchema>;
211
+ /**
212
+ * Function used to listen to a request response via the iframe transport
213
+ */
214
+ listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
215
+ /**
216
+ * Function used to destroy the iframe transport
217
+ */
218
+ destroy: () => Promise<void>;
219
+ };
220
+ /**
221
+ * Represent an iframe event
222
+ */
223
+ type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent;
224
+ /**
225
+ * Represent an iframe rpc event
226
+ */
227
+ type IFrameRpcEvent = {
228
+ id: string;
229
+ topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
230
+ data: {
231
+ compressed: string;
232
+ compressedHash: string;
233
+ };
234
+ };
235
+ type IFrameLifecycleEvent = {
236
+ lifecycle: "connected";
237
+ };
238
+
239
+ /**
240
+ * Representing a Frak client
241
+ */
242
+ type FrakClient = {
243
+ config: FrakWalletSdkConfig;
244
+ } & IFrameTransport;
245
+
246
+ export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, FrakClient as F, IFrameRpcSchema as I, PaidArticleUnlockPrice as P, RedirectRpcSchema as R, StartArticleUnlockReturnType as S, UnlockOptionsReturnType as U, WalletStatusReturnType as W, FrakWalletSdkConfig as a, StartArticleUnlockParams as b, ExtractedReturnTypeFromRpc as c, IFrameTransport as d, IFrameRpcEvent as e, IFrameEvent as f };
@@ -0,0 +1,77 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunk4X75PGSKcjs = require('../../chunk-4X75PGSK.cjs');
7
+
8
+ // src/core/actions/getUnlockOptions.ts
9
+ function getArticleUnlockOptions(client, { articleId }) {
10
+ return client.request({
11
+ method: "frak_getArticleUnlockOptions",
12
+ params: [client.config.contentId, articleId]
13
+ });
14
+ }
15
+
16
+ // src/core/actions/watchUnlockStatus.ts
17
+ function watchUnlockStatus(client, { articleId }, callback) {
18
+ return client.listenerRequest(
19
+ {
20
+ method: "frak_listenToArticleUnlockStatus",
21
+ params: [client.config.contentId, articleId]
22
+ },
23
+ callback
24
+ );
25
+ }
26
+
27
+ // src/core/actions/watchWalletStatus.ts
28
+ function watchWalletStatus(client, callback) {
29
+ return client.listenerRequest(
30
+ {
31
+ method: "frak_listenToWalletStatus"
32
+ },
33
+ callback
34
+ );
35
+ }
36
+
37
+ // src/core/actions/startUnlock.ts
38
+ async function getStartArticleUnlockUrl(config, params) {
39
+ const { compressed, compressedHash } = await _chunk4X75PGSKcjs.hashAndCompressData.call(void 0,
40
+ {
41
+ method: "frak_startArticleUnlock",
42
+ params: {
43
+ ...params,
44
+ contentId: config.contentId,
45
+ contentTitle: config.contentTitle
46
+ }
47
+ },
48
+ _chunk4X75PGSKcjs.redirectRequestKeyProvider
49
+ );
50
+ const outputUrl = new URL(config.walletUrl);
51
+ outputUrl.pathname = "/paywall";
52
+ outputUrl.searchParams.set("params", encodeURIComponent(compressed));
53
+ outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
54
+ return outputUrl.toString();
55
+ }
56
+ async function decodeStartUnlockReturn({
57
+ result,
58
+ hash
59
+ }) {
60
+ const keyProvider = _chunk4X75PGSKcjs.getRedirectResponseResponseKeyProvider.call(void 0,
61
+ "frak_startArticleUnlock"
62
+ );
63
+ return _chunk4X75PGSKcjs.decompressDataAndCheckHash.call(void 0,
64
+ {
65
+ compressed: decodeURIComponent(result),
66
+ compressedHash: decodeURIComponent(hash)
67
+ },
68
+ keyProvider
69
+ );
70
+ }
71
+
72
+
73
+
74
+
75
+
76
+
77
+ exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus;
@@ -0,0 +1,63 @@
1
+ import { Hex } from 'viem';
2
+ import { F as FrakClient, A as ArticleUnlockStatusReturnType, W as WalletStatusReturnType, a as FrakWalletSdkConfig, S as StartArticleUnlockReturnType, b as StartArticleUnlockParams } from '../../client-SCwoh_kP.cjs';
3
+ import 'viem/chains';
4
+
5
+ /**
6
+ * Type used to get the unlock options
7
+ */
8
+ type GetUnlockOptionsParams = {
9
+ articleId: Hex;
10
+ };
11
+ /**
12
+ * Function used to fetch the unlock option for the given client
13
+ * @param client
14
+ * @param articleId
15
+ */
16
+ declare function getArticleUnlockOptions(client: FrakClient, { articleId }: GetUnlockOptionsParams): Promise<Readonly<{
17
+ prices: {
18
+ index: number;
19
+ unlockDurationInSec: number;
20
+ frkAmount: `0x${string}`;
21
+ isUserAccessible: boolean | null;
22
+ }[];
23
+ }>>;
24
+
25
+ /**
26
+ * Type used to get the unlock options
27
+ */
28
+ type WatchUnlockStatusParams = {
29
+ articleId: Hex;
30
+ };
31
+ /**
32
+ * Function used to watch a current article unlock status
33
+ * @param client
34
+ * @param articleId
35
+ * @param callback
36
+ */
37
+ declare function watchUnlockStatus(client: FrakClient, { articleId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
38
+
39
+ /**
40
+ * Function used to watch the current nexus wallet status
41
+ * @param client
42
+ * @param callback
43
+ */
44
+ declare function watchWalletStatus(client: FrakClient, callback: (status: WalletStatusReturnType) => void): Promise<void>;
45
+
46
+ type GetStartUnlockUrlParams = Omit<StartArticleUnlockParams, "contentId" | "contentTitle">;
47
+ /**
48
+ * Function used to build the unlock URL for a given article
49
+ * @param config
50
+ * @param params
51
+ */
52
+ declare function getStartArticleUnlockUrl(config: FrakWalletSdkConfig, params: GetStartUnlockUrlParams): Promise<string>;
53
+ /**
54
+ * Function used to decode the response from the start unlock request (return typed passed as query param)
55
+ */
56
+ declare function decodeStartUnlockReturn({ result, hash, }: {
57
+ result: string;
58
+ hash: string;
59
+ }): Promise<Readonly<StartArticleUnlockReturnType & {
60
+ validationHash: string;
61
+ }>>;
62
+
63
+ export { decodeStartUnlockReturn, getArticleUnlockOptions, getStartArticleUnlockUrl, watchUnlockStatus, watchWalletStatus };
@@ -0,0 +1,63 @@
1
+ import { Hex } from 'viem';
2
+ import { F as FrakClient, A as ArticleUnlockStatusReturnType, W as WalletStatusReturnType, a as FrakWalletSdkConfig, S as StartArticleUnlockReturnType, b as StartArticleUnlockParams } from '../../client-SCwoh_kP.js';
3
+ import 'viem/chains';
4
+
5
+ /**
6
+ * Type used to get the unlock options
7
+ */
8
+ type GetUnlockOptionsParams = {
9
+ articleId: Hex;
10
+ };
11
+ /**
12
+ * Function used to fetch the unlock option for the given client
13
+ * @param client
14
+ * @param articleId
15
+ */
16
+ declare function getArticleUnlockOptions(client: FrakClient, { articleId }: GetUnlockOptionsParams): Promise<Readonly<{
17
+ prices: {
18
+ index: number;
19
+ unlockDurationInSec: number;
20
+ frkAmount: `0x${string}`;
21
+ isUserAccessible: boolean | null;
22
+ }[];
23
+ }>>;
24
+
25
+ /**
26
+ * Type used to get the unlock options
27
+ */
28
+ type WatchUnlockStatusParams = {
29
+ articleId: Hex;
30
+ };
31
+ /**
32
+ * Function used to watch a current article unlock status
33
+ * @param client
34
+ * @param articleId
35
+ * @param callback
36
+ */
37
+ declare function watchUnlockStatus(client: FrakClient, { articleId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
38
+
39
+ /**
40
+ * Function used to watch the current nexus wallet status
41
+ * @param client
42
+ * @param callback
43
+ */
44
+ declare function watchWalletStatus(client: FrakClient, callback: (status: WalletStatusReturnType) => void): Promise<void>;
45
+
46
+ type GetStartUnlockUrlParams = Omit<StartArticleUnlockParams, "contentId" | "contentTitle">;
47
+ /**
48
+ * Function used to build the unlock URL for a given article
49
+ * @param config
50
+ * @param params
51
+ */
52
+ declare function getStartArticleUnlockUrl(config: FrakWalletSdkConfig, params: GetStartUnlockUrlParams): Promise<string>;
53
+ /**
54
+ * Function used to decode the response from the start unlock request (return typed passed as query param)
55
+ */
56
+ declare function decodeStartUnlockReturn({ result, hash, }: {
57
+ result: string;
58
+ hash: string;
59
+ }): Promise<Readonly<StartArticleUnlockReturnType & {
60
+ validationHash: string;
61
+ }>>;
62
+
63
+ export { decodeStartUnlockReturn, getArticleUnlockOptions, getStartArticleUnlockUrl, watchUnlockStatus, watchWalletStatus };
@@ -0,0 +1,77 @@
1
+ import {
2
+ decompressDataAndCheckHash,
3
+ getRedirectResponseResponseKeyProvider,
4
+ hashAndCompressData,
5
+ redirectRequestKeyProvider
6
+ } from "../../chunk-JE64MPH2.js";
7
+
8
+ // src/core/actions/getUnlockOptions.ts
9
+ function getArticleUnlockOptions(client, { articleId }) {
10
+ return client.request({
11
+ method: "frak_getArticleUnlockOptions",
12
+ params: [client.config.contentId, articleId]
13
+ });
14
+ }
15
+
16
+ // src/core/actions/watchUnlockStatus.ts
17
+ function watchUnlockStatus(client, { articleId }, callback) {
18
+ return client.listenerRequest(
19
+ {
20
+ method: "frak_listenToArticleUnlockStatus",
21
+ params: [client.config.contentId, articleId]
22
+ },
23
+ callback
24
+ );
25
+ }
26
+
27
+ // src/core/actions/watchWalletStatus.ts
28
+ function watchWalletStatus(client, callback) {
29
+ return client.listenerRequest(
30
+ {
31
+ method: "frak_listenToWalletStatus"
32
+ },
33
+ callback
34
+ );
35
+ }
36
+
37
+ // src/core/actions/startUnlock.ts
38
+ async function getStartArticleUnlockUrl(config, params) {
39
+ const { compressed, compressedHash } = await hashAndCompressData(
40
+ {
41
+ method: "frak_startArticleUnlock",
42
+ params: {
43
+ ...params,
44
+ contentId: config.contentId,
45
+ contentTitle: config.contentTitle
46
+ }
47
+ },
48
+ redirectRequestKeyProvider
49
+ );
50
+ const outputUrl = new URL(config.walletUrl);
51
+ outputUrl.pathname = "/paywall";
52
+ outputUrl.searchParams.set("params", encodeURIComponent(compressed));
53
+ outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
54
+ return outputUrl.toString();
55
+ }
56
+ async function decodeStartUnlockReturn({
57
+ result,
58
+ hash
59
+ }) {
60
+ const keyProvider = getRedirectResponseResponseKeyProvider(
61
+ "frak_startArticleUnlock"
62
+ );
63
+ return decompressDataAndCheckHash(
64
+ {
65
+ compressed: decodeURIComponent(result),
66
+ compressedHash: decodeURIComponent(hash)
67
+ },
68
+ keyProvider
69
+ );
70
+ }
71
+ export {
72
+ decodeStartUnlockReturn,
73
+ getArticleUnlockOptions,
74
+ getStartArticleUnlockUrl,
75
+ watchUnlockStatus,
76
+ watchWalletStatus
77
+ };
@@ -0,0 +1,179 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _chunk4X75PGSKcjs = require('../chunk-4X75PGSK.cjs');
11
+
12
+ // src/core/utils/Deferred.ts
13
+ var Deferred = class {
14
+ constructor() {
15
+ _chunk4X75PGSKcjs.__publicField.call(void 0, this, "_promise");
16
+ _chunk4X75PGSKcjs.__publicField.call(void 0, this, "_resolve");
17
+ _chunk4X75PGSKcjs.__publicField.call(void 0, this, "_reject");
18
+ _chunk4X75PGSKcjs.__publicField.call(void 0, this, "resolve", (value) => {
19
+ _optionalChain([this, 'access', _ => _._resolve, 'optionalCall', _2 => _2(value)]);
20
+ });
21
+ _chunk4X75PGSKcjs.__publicField.call(void 0, this, "reject", (reason) => {
22
+ _optionalChain([this, 'access', _3 => _3._reject, 'optionalCall', _4 => _4(reason)]);
23
+ });
24
+ this._promise = new Promise((resolve, reject) => {
25
+ this._resolve = resolve;
26
+ this._reject = reject;
27
+ });
28
+ }
29
+ get promise() {
30
+ return this._promise;
31
+ }
32
+ };
33
+
34
+ // src/core/clients/transports/iframeChannelManager.ts
35
+ function createIFrameChannelManager() {
36
+ const channels = /* @__PURE__ */ new Map();
37
+ return {
38
+ // TODO: Better id system?? uid stuff?
39
+ createChannel: (resolver) => {
40
+ const id = Math.random().toString(36).substring(7);
41
+ channels.set(id, resolver);
42
+ return id;
43
+ },
44
+ getRpcResolver: (id) => channels.get(id),
45
+ removeChannel: (id) => channels.delete(id),
46
+ destroy: () => channels.clear()
47
+ };
48
+ }
49
+
50
+ // src/core/clients/transports/iframeMessageHandler.ts
51
+ function createIFrameMessageHandler({
52
+ frakWalletUrl,
53
+ iframe,
54
+ channelManager
55
+ }) {
56
+ if (typeof window === "undefined") {
57
+ throw new Error("iframe client should be used in the browser");
58
+ }
59
+ if (!iframe.contentWindow) {
60
+ throw new Error("The iframe does not have a content window");
61
+ }
62
+ const contentWindow = iframe.contentWindow;
63
+ const isConnected = new Deferred();
64
+ const msgHandler = async (event) => {
65
+ if (!event.origin) {
66
+ return;
67
+ }
68
+ if (new URL(event.origin).origin.toLowerCase() !== new URL(frakWalletUrl).origin.toLowerCase()) {
69
+ return;
70
+ }
71
+ if ("lifecycle" in event.data) {
72
+ isConnected.resolve(event.data.lifecycle === "connected");
73
+ return;
74
+ }
75
+ const channel = event.data.id;
76
+ const resolver = channelManager.getRpcResolver(channel);
77
+ if (!resolver) {
78
+ return;
79
+ }
80
+ await resolver(event.data);
81
+ };
82
+ window.addEventListener("message", msgHandler);
83
+ const sendEvent = (message) => {
84
+ contentWindow.postMessage(message, {
85
+ targetOrigin: frakWalletUrl
86
+ });
87
+ };
88
+ const cleanup = () => {
89
+ window.removeEventListener("message", msgHandler);
90
+ };
91
+ return {
92
+ isConnected: isConnected.promise,
93
+ sendEvent,
94
+ cleanup
95
+ };
96
+ }
97
+
98
+ // src/core/clients/createIFrameFrakClient.ts
99
+ function createIFrameFrakClient({
100
+ config,
101
+ iframe
102
+ }) {
103
+ const channelManager = createIFrameChannelManager();
104
+ const messageHandler = createIFrameMessageHandler({
105
+ frakWalletUrl: config.walletUrl,
106
+ iframe,
107
+ channelManager
108
+ });
109
+ const request = async (args) => {
110
+ const isConnected = await messageHandler.isConnected;
111
+ if (!isConnected) {
112
+ throw new Error("The iframe provider isn't connected yet");
113
+ }
114
+ const result = new Deferred();
115
+ const resultCompressionKeyProvider = _chunk4X75PGSKcjs.getIFrameResponseKeyProvider.call(void 0, args);
116
+ const channelId = channelManager.createChannel(async (message) => {
117
+ const decompressed = await _chunk4X75PGSKcjs.decompressDataAndCheckHash.call(void 0,
118
+ message.data,
119
+ resultCompressionKeyProvider
120
+ );
121
+ result.resolve(decompressed);
122
+ channelManager.removeChannel(channelId);
123
+ });
124
+ const compressedMessage = await _chunk4X75PGSKcjs.hashAndCompressData.call(void 0,
125
+ args,
126
+ _chunk4X75PGSKcjs.iFrameRequestKeyProvider
127
+ );
128
+ messageHandler.sendEvent({
129
+ id: channelId,
130
+ topic: args.method,
131
+ data: compressedMessage
132
+ });
133
+ return result.promise;
134
+ };
135
+ const listenerRequest = async (args, callback) => {
136
+ const isConnected = await messageHandler.isConnected;
137
+ if (!isConnected) {
138
+ throw new Error("The iframe provider isn't connected yet");
139
+ }
140
+ const resultCompressionKeyProvider = _chunk4X75PGSKcjs.getIFrameResponseKeyProvider.call(void 0, args);
141
+ const channelId = channelManager.createChannel(async (message) => {
142
+ const decompressed = await _chunk4X75PGSKcjs.decompressDataAndCheckHash.call(void 0,
143
+ message.data,
144
+ resultCompressionKeyProvider
145
+ );
146
+ callback(decompressed);
147
+ });
148
+ const compressedMessage = await _chunk4X75PGSKcjs.hashAndCompressData.call(void 0,
149
+ args,
150
+ _chunk4X75PGSKcjs.iFrameRequestKeyProvider
151
+ );
152
+ messageHandler.sendEvent({
153
+ id: channelId,
154
+ topic: args.method,
155
+ data: compressedMessage
156
+ });
157
+ };
158
+ const destroy = async () => {
159
+ channelManager.destroy();
160
+ messageHandler.cleanup();
161
+ };
162
+ return {
163
+ config,
164
+ waitForConnection: messageHandler.isConnected,
165
+ request,
166
+ listenerRequest,
167
+ destroy
168
+ };
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ exports.createIFrameFrakClient = createIFrameFrakClient; exports.createIframe = _chunk4X75PGSKcjs.createIframe; exports.decompressDataAndCheckHash = _chunk4X75PGSKcjs.decompressDataAndCheckHash; exports.getIFrameResponseKeyProvider = _chunk4X75PGSKcjs.getIFrameResponseKeyProvider; exports.getRedirectResponseResponseKeyProvider = _chunk4X75PGSKcjs.getRedirectResponseResponseKeyProvider; exports.hashAndCompressData = _chunk4X75PGSKcjs.hashAndCompressData; exports.iFrameRequestKeyProvider = _chunk4X75PGSKcjs.iFrameRequestKeyProvider; exports.redirectRequestKeyProvider = _chunk4X75PGSKcjs.redirectRequestKeyProvider;