@frak-labs/nexus-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.
Files changed (43) hide show
  1. package/dist/chunk-5CFD5FM2.js +86 -0
  2. package/dist/chunk-7MVQQ2X6.js +381 -0
  3. package/dist/chunk-ETV4XYOV.cjs +7 -0
  4. package/dist/chunk-GUDT2W6I.js +70 -0
  5. package/dist/chunk-IQQTTKJL.cjs +70 -0
  6. package/dist/chunk-PKBMQBKP.js +7 -0
  7. package/dist/chunk-S5FVCA2E.cjs +86 -0
  8. package/dist/chunk-V3S6RBRJ.cjs +381 -0
  9. package/dist/client-C7u9zGwC.d.cts +332 -0
  10. package/dist/client-gE3fYzkD.d.ts +332 -0
  11. package/dist/core/actions/index.cjs +3 -3
  12. package/dist/core/actions/index.d.cts +21 -28
  13. package/dist/core/actions/index.d.ts +21 -28
  14. package/dist/core/actions/index.js +12 -12
  15. package/dist/core/index.cjs +3 -8
  16. package/dist/core/index.d.cts +8 -35
  17. package/dist/core/index.d.ts +8 -35
  18. package/dist/core/index.js +9 -14
  19. package/dist/core/interactions/index.cjs +13 -0
  20. package/dist/core/interactions/index.d.cts +53 -0
  21. package/dist/core/interactions/index.d.ts +53 -0
  22. package/dist/core/interactions/index.js +13 -0
  23. package/dist/error-C4Zm5nQe.d.cts +27 -0
  24. package/dist/error-C4Zm5nQe.d.ts +27 -0
  25. package/dist/interaction-D3-M3nBh.d.cts +22 -0
  26. package/dist/interaction-D3-M3nBh.d.ts +22 -0
  27. package/dist/react/index.cjs +279 -166
  28. package/dist/react/index.d.cts +80 -37
  29. package/dist/react/index.d.ts +80 -37
  30. package/dist/react/index.js +291 -178
  31. package/dist/sendTransaction-BZW627cT.d.cts +30 -0
  32. package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
  33. package/package.json +16 -7
  34. package/dist/chunk-AYZHGMEV.cjs +0 -171
  35. package/dist/chunk-PDR3CF3P.js +0 -86
  36. package/dist/chunk-SZUN32YC.js +0 -171
  37. package/dist/chunk-VK7GPKK4.js +0 -169
  38. package/dist/chunk-X4JNNWJ4.cjs +0 -86
  39. package/dist/chunk-ZOLP2FJZ.cjs +0 -169
  40. package/dist/client-BwzXSgqQ.d.cts +0 -278
  41. package/dist/client-BwzXSgqQ.d.ts +0 -278
  42. package/dist/watchUnlockStatus-DXClCYH9.d.cts +0 -43
  43. package/dist/watchUnlockStatus-WJxoDliF.d.ts +0 -43
package/package.json CHANGED
@@ -11,9 +11,12 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.9",
14
+ "version": "0.0.11",
15
15
  "description": "Nexus Wallet client SDK, helping any person to interact with the Frak wallet, and require the unlock of a premium article within the Frak ecosystem.",
16
- "repository": "https://github.com/frak-id/wallet",
16
+ "repository": {
17
+ "url": "https://github.com/frak-id/wallet",
18
+ "directory": "packages/sdk"
19
+ },
17
20
  "homepage": "https://docs.frak.id/wallet-sdk",
18
21
  "keywords": [
19
22
  "frak-labs",
@@ -49,6 +52,11 @@
49
52
  "import": "./dist/core/actions/index.js",
50
53
  "default": "./dist/core/actions/index.cjs"
51
54
  },
55
+ "./interactions": {
56
+ "types": "./dist/core/interactions/index.d.ts",
57
+ "import": "./dist/core/interactions/index.js",
58
+ "default": "./dist/core/interactions/index.cjs"
59
+ },
52
60
  "./react": {
53
61
  "types": "./dist/react/index.d.ts",
54
62
  "import": "./dist/react/index.js",
@@ -58,9 +66,10 @@
58
66
  "scripts": {
59
67
  "lint": "biome lint .",
60
68
  "format:check": "biome check .",
61
- "format": "biome check --apply .",
69
+ "format": "biome check --write .",
62
70
  "clean": "rimraf dist",
63
- "build": "tsup --splitting"
71
+ "build": "tsup --splitting",
72
+ "build:watch": "tsup --watch --splitting --format esm"
64
73
  },
65
74
  "peerDependencies": {
66
75
  "viem": "^2.x",
@@ -72,9 +81,9 @@
72
81
  "js-sha256": "^0.11.0"
73
82
  },
74
83
  "devDependencies": {
75
- "@tanstack/react-query": ">=5.32.0",
76
- "@types/node": "^20",
77
- "tsup": "^8.0.2",
84
+ "@tanstack/react-query": ">=5.51.15",
85
+ "@types/node": "^22",
86
+ "tsup": "^8.2.3",
78
87
  "typescript": "^5"
79
88
  }
80
89
  }
@@ -1,171 +0,0 @@
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
- var _chunkZOLP2FJZcjs = require('./chunk-ZOLP2FJZ.cjs');
8
-
9
- // src/core/utils/Deferred.ts
10
- var Deferred = class {
11
- constructor() {
12
- _chunkZOLP2FJZcjs.__publicField.call(void 0, this, "_promise");
13
- _chunkZOLP2FJZcjs.__publicField.call(void 0, this, "_resolve");
14
- _chunkZOLP2FJZcjs.__publicField.call(void 0, this, "_reject");
15
- _chunkZOLP2FJZcjs.__publicField.call(void 0, this, "resolve", (value) => {
16
- _optionalChain([this, 'access', _ => _._resolve, 'optionalCall', _2 => _2(value)]);
17
- });
18
- _chunkZOLP2FJZcjs.__publicField.call(void 0, this, "reject", (reason) => {
19
- _optionalChain([this, 'access', _3 => _3._reject, 'optionalCall', _4 => _4(reason)]);
20
- });
21
- this._promise = new Promise((resolve, reject) => {
22
- this._resolve = resolve;
23
- this._reject = reject;
24
- });
25
- }
26
- get promise() {
27
- return this._promise;
28
- }
29
- };
30
-
31
- // src/core/clients/transports/iframeChannelManager.ts
32
- function createIFrameChannelManager() {
33
- const channels = /* @__PURE__ */ new Map();
34
- return {
35
- // TODO: Better id system?? uid stuff?
36
- createChannel: (resolver) => {
37
- const id = Math.random().toString(36).substring(7);
38
- channels.set(id, resolver);
39
- return id;
40
- },
41
- getRpcResolver: (id) => channels.get(id),
42
- removeChannel: (id) => channels.delete(id),
43
- destroy: () => channels.clear()
44
- };
45
- }
46
-
47
- // src/core/clients/transports/iframeMessageHandler.ts
48
- function createIFrameMessageHandler({
49
- nexusWalletUrl,
50
- iframe,
51
- channelManager
52
- }) {
53
- if (typeof window === "undefined") {
54
- throw new Error("iframe client should be used in the browser");
55
- }
56
- if (!iframe.contentWindow) {
57
- throw new Error("The iframe does not have a content window");
58
- }
59
- const contentWindow = iframe.contentWindow;
60
- const isConnected = new Deferred();
61
- const msgHandler = async (event) => {
62
- if (!event.origin) {
63
- return;
64
- }
65
- if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
66
- return;
67
- }
68
- if ("lifecycle" in event.data) {
69
- isConnected.resolve(event.data.lifecycle === "connected");
70
- return;
71
- }
72
- const channel = event.data.id;
73
- const resolver = channelManager.getRpcResolver(channel);
74
- if (!resolver) {
75
- return;
76
- }
77
- await resolver(event.data);
78
- };
79
- window.addEventListener("message", msgHandler);
80
- const sendEvent = (message) => {
81
- contentWindow.postMessage(message, {
82
- targetOrigin: nexusWalletUrl
83
- });
84
- };
85
- const cleanup = () => {
86
- window.removeEventListener("message", msgHandler);
87
- };
88
- return {
89
- isConnected: isConnected.promise,
90
- sendEvent,
91
- cleanup
92
- };
93
- }
94
-
95
- // src/core/clients/createIFrameNexusClient.ts
96
- function createIFrameNexusClient({
97
- config,
98
- iframe
99
- }) {
100
- const channelManager = createIFrameChannelManager();
101
- const messageHandler = createIFrameMessageHandler({
102
- nexusWalletUrl: config.walletUrl,
103
- iframe,
104
- channelManager
105
- });
106
- const request = async (args) => {
107
- const isConnected = await messageHandler.isConnected;
108
- if (!isConnected) {
109
- throw new Error("The iframe provider isn't connected yet");
110
- }
111
- const result = new Deferred();
112
- const resultCompressionKeyProvider = _chunkZOLP2FJZcjs.getIFrameResponseKeyProvider.call(void 0, args);
113
- const channelId = channelManager.createChannel(async (message) => {
114
- const decompressed = await _chunkZOLP2FJZcjs.decompressDataAndCheckHash.call(void 0,
115
- message.data,
116
- resultCompressionKeyProvider
117
- );
118
- result.resolve(decompressed);
119
- channelManager.removeChannel(channelId);
120
- });
121
- const compressedMessage = await _chunkZOLP2FJZcjs.hashAndCompressData.call(void 0,
122
- args,
123
- _chunkZOLP2FJZcjs.iFrameRequestKeyProvider
124
- );
125
- messageHandler.sendEvent({
126
- id: channelId,
127
- topic: args.method,
128
- data: compressedMessage
129
- });
130
- return result.promise;
131
- };
132
- const listenerRequest = async (args, callback) => {
133
- const isConnected = await messageHandler.isConnected;
134
- if (!isConnected) {
135
- throw new Error("The iframe provider isn't connected yet");
136
- }
137
- const resultCompressionKeyProvider = _chunkZOLP2FJZcjs.getIFrameResponseKeyProvider.call(void 0, args);
138
- const channelId = channelManager.createChannel(async (message) => {
139
- const decompressed = await _chunkZOLP2FJZcjs.decompressDataAndCheckHash.call(void 0,
140
- message.data,
141
- resultCompressionKeyProvider
142
- );
143
- callback(decompressed);
144
- });
145
- const compressedMessage = await _chunkZOLP2FJZcjs.hashAndCompressData.call(void 0,
146
- args,
147
- _chunkZOLP2FJZcjs.iFrameRequestKeyProvider
148
- );
149
- messageHandler.sendEvent({
150
- id: channelId,
151
- topic: args.method,
152
- data: compressedMessage
153
- });
154
- };
155
- const destroy = async () => {
156
- channelManager.destroy();
157
- messageHandler.cleanup();
158
- iframe.remove();
159
- };
160
- return {
161
- config,
162
- waitForConnection: messageHandler.isConnected,
163
- request,
164
- listenerRequest,
165
- destroy
166
- };
167
- }
168
-
169
-
170
-
171
- exports.createIFrameNexusClient = createIFrameNexusClient;
@@ -1,86 +0,0 @@
1
- import {
2
- decompressDataAndCheckHash,
3
- getRedirectResponseResponseKeyProvider,
4
- hashAndCompressData,
5
- redirectRequestKeyProvider
6
- } from "./chunk-VK7GPKK4.js";
7
-
8
- // src/core/actions/getUnlockOptions.ts
9
- function getArticleUnlockOptions(client, { articleId, contentId }) {
10
- return client.request({
11
- method: "frak_getArticleUnlockOptions",
12
- params: [contentId, articleId]
13
- });
14
- }
15
-
16
- // src/core/actions/watchUnlockStatus.ts
17
- function watchUnlockStatus(client, { articleId, contentId }, callback) {
18
- return client.listenerRequest(
19
- {
20
- method: "frak_listenToArticleUnlockStatus",
21
- params: [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
- },
44
- redirectRequestKeyProvider
45
- );
46
- const outputUrl = new URL(config.walletUrl);
47
- outputUrl.pathname = "/paywall";
48
- outputUrl.searchParams.set("params", encodeURIComponent(compressed));
49
- outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
50
- return outputUrl.toString();
51
- }
52
- async function decodeStartUnlockReturn({
53
- result,
54
- hash
55
- }) {
56
- const keyProvider = getRedirectResponseResponseKeyProvider(
57
- "frak_startArticleUnlock"
58
- );
59
- return decompressDataAndCheckHash(
60
- {
61
- compressed: decodeURIComponent(result),
62
- compressedHash: decodeURIComponent(hash)
63
- },
64
- keyProvider
65
- );
66
- }
67
-
68
- // src/core/actions/setUserReferred.ts
69
- function setUserReferred(client, { contentId, walletAddress }, callback) {
70
- return client.listenerRequest(
71
- {
72
- method: "frak_listenToSetUserReferred",
73
- params: [contentId, walletAddress]
74
- },
75
- callback
76
- );
77
- }
78
-
79
- export {
80
- getArticleUnlockOptions,
81
- watchUnlockStatus,
82
- watchWalletStatus,
83
- getStartArticleUnlockUrl,
84
- decodeStartUnlockReturn,
85
- setUserReferred
86
- };
@@ -1,171 +0,0 @@
1
- import {
2
- __publicField,
3
- decompressDataAndCheckHash,
4
- getIFrameResponseKeyProvider,
5
- hashAndCompressData,
6
- iFrameRequestKeyProvider
7
- } from "./chunk-VK7GPKK4.js";
8
-
9
- // src/core/utils/Deferred.ts
10
- var Deferred = class {
11
- constructor() {
12
- __publicField(this, "_promise");
13
- __publicField(this, "_resolve");
14
- __publicField(this, "_reject");
15
- __publicField(this, "resolve", (value) => {
16
- this._resolve?.(value);
17
- });
18
- __publicField(this, "reject", (reason) => {
19
- this._reject?.(reason);
20
- });
21
- this._promise = new Promise((resolve, reject) => {
22
- this._resolve = resolve;
23
- this._reject = reject;
24
- });
25
- }
26
- get promise() {
27
- return this._promise;
28
- }
29
- };
30
-
31
- // src/core/clients/transports/iframeChannelManager.ts
32
- function createIFrameChannelManager() {
33
- const channels = /* @__PURE__ */ new Map();
34
- return {
35
- // TODO: Better id system?? uid stuff?
36
- createChannel: (resolver) => {
37
- const id = Math.random().toString(36).substring(7);
38
- channels.set(id, resolver);
39
- return id;
40
- },
41
- getRpcResolver: (id) => channels.get(id),
42
- removeChannel: (id) => channels.delete(id),
43
- destroy: () => channels.clear()
44
- };
45
- }
46
-
47
- // src/core/clients/transports/iframeMessageHandler.ts
48
- function createIFrameMessageHandler({
49
- nexusWalletUrl,
50
- iframe,
51
- channelManager
52
- }) {
53
- if (typeof window === "undefined") {
54
- throw new Error("iframe client should be used in the browser");
55
- }
56
- if (!iframe.contentWindow) {
57
- throw new Error("The iframe does not have a content window");
58
- }
59
- const contentWindow = iframe.contentWindow;
60
- const isConnected = new Deferred();
61
- const msgHandler = async (event) => {
62
- if (!event.origin) {
63
- return;
64
- }
65
- if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
66
- return;
67
- }
68
- if ("lifecycle" in event.data) {
69
- isConnected.resolve(event.data.lifecycle === "connected");
70
- return;
71
- }
72
- const channel = event.data.id;
73
- const resolver = channelManager.getRpcResolver(channel);
74
- if (!resolver) {
75
- return;
76
- }
77
- await resolver(event.data);
78
- };
79
- window.addEventListener("message", msgHandler);
80
- const sendEvent = (message) => {
81
- contentWindow.postMessage(message, {
82
- targetOrigin: nexusWalletUrl
83
- });
84
- };
85
- const cleanup = () => {
86
- window.removeEventListener("message", msgHandler);
87
- };
88
- return {
89
- isConnected: isConnected.promise,
90
- sendEvent,
91
- cleanup
92
- };
93
- }
94
-
95
- // src/core/clients/createIFrameNexusClient.ts
96
- function createIFrameNexusClient({
97
- config,
98
- iframe
99
- }) {
100
- const channelManager = createIFrameChannelManager();
101
- const messageHandler = createIFrameMessageHandler({
102
- nexusWalletUrl: config.walletUrl,
103
- iframe,
104
- channelManager
105
- });
106
- const request = async (args) => {
107
- const isConnected = await messageHandler.isConnected;
108
- if (!isConnected) {
109
- throw new Error("The iframe provider isn't connected yet");
110
- }
111
- const result = new Deferred();
112
- const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
113
- const channelId = channelManager.createChannel(async (message) => {
114
- const decompressed = await decompressDataAndCheckHash(
115
- message.data,
116
- resultCompressionKeyProvider
117
- );
118
- result.resolve(decompressed);
119
- channelManager.removeChannel(channelId);
120
- });
121
- const compressedMessage = await hashAndCompressData(
122
- args,
123
- iFrameRequestKeyProvider
124
- );
125
- messageHandler.sendEvent({
126
- id: channelId,
127
- topic: args.method,
128
- data: compressedMessage
129
- });
130
- return result.promise;
131
- };
132
- const listenerRequest = async (args, callback) => {
133
- const isConnected = await messageHandler.isConnected;
134
- if (!isConnected) {
135
- throw new Error("The iframe provider isn't connected yet");
136
- }
137
- const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
138
- const channelId = channelManager.createChannel(async (message) => {
139
- const decompressed = await decompressDataAndCheckHash(
140
- message.data,
141
- resultCompressionKeyProvider
142
- );
143
- callback(decompressed);
144
- });
145
- const compressedMessage = await hashAndCompressData(
146
- args,
147
- iFrameRequestKeyProvider
148
- );
149
- messageHandler.sendEvent({
150
- id: channelId,
151
- topic: args.method,
152
- data: compressedMessage
153
- });
154
- };
155
- const destroy = async () => {
156
- channelManager.destroy();
157
- messageHandler.cleanup();
158
- iframe.remove();
159
- };
160
- return {
161
- config,
162
- waitForConnection: messageHandler.isConnected,
163
- request,
164
- listenerRequest,
165
- destroy
166
- };
167
- }
168
-
169
- export {
170
- createIFrameNexusClient
171
- };
@@ -1,169 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
-
8
- // src/core/utils/compression/compress.ts
9
- import { compressToBase64 } from "async-lz-string";
10
- import { sha256 } from "js-sha256";
11
- async function hashAndCompressData(data, keyProvider) {
12
- const keys = keyProvider(data);
13
- const validationHash = sha256(keys.join("_"));
14
- const hashProtectedData = {
15
- ...data,
16
- validationHash
17
- };
18
- const compressed = await compressJson(hashProtectedData);
19
- const compressedHash = sha256(compressed);
20
- return {
21
- compressed,
22
- compressedHash
23
- };
24
- }
25
- async function compressJson(data) {
26
- return compressToBase64(JSON.stringify(data));
27
- }
28
-
29
- // src/core/utils/compression/decompress.ts
30
- import { decompressFromBase64 } from "async-lz-string";
31
- import { sha256 as sha2562 } from "js-sha256";
32
- async function decompressDataAndCheckHash(compressedData, keyAccessor) {
33
- if (!(compressedData?.compressed && compressedData?.compressedHash)) {
34
- throw new Error("Missing compressed data");
35
- }
36
- const parsedData = await decompressJson(
37
- compressedData.compressed
38
- );
39
- if (!parsedData) {
40
- throw new Error(`Invalid compressed data: ${parsedData}`);
41
- }
42
- if (!parsedData?.validationHash) {
43
- throw new Error("Missing validation hash");
44
- }
45
- const expectedCompressedHash = sha2562(compressedData.compressed);
46
- if (expectedCompressedHash !== compressedData.compressedHash) {
47
- throw new Error("Invalid compressed hash");
48
- }
49
- const keys = keyAccessor(parsedData);
50
- const expectedValidationHash = sha2562(keys.join("_"));
51
- if (expectedValidationHash !== parsedData.validationHash) {
52
- throw new Error("Invalid data validation hash");
53
- }
54
- return parsedData;
55
- }
56
- async function decompressJson(data) {
57
- const decompressed = await decompressFromBase64(data);
58
- try {
59
- return JSON.parse(decompressed);
60
- } catch (e) {
61
- console.error("Invalid compressed data", e);
62
- return null;
63
- }
64
- }
65
-
66
- // src/core/utils/compression/iframeRpcKeyProvider.ts
67
- var iFrameRequestKeyProvider = (args) => {
68
- if (args.method === "frak_getArticleUnlockOptions") {
69
- return ["get-price", args.params[0], args.params[1]];
70
- }
71
- if (args.method === "frak_listenToWalletStatus") {
72
- return ["wallet-status"];
73
- }
74
- if (args.method === "frak_listenToArticleUnlockStatus") {
75
- return ["article-unlock-status", args.params[0], args.params[1]];
76
- }
77
- if (args.method === "frak_listenToSetUserReferred") {
78
- return ["user-referred", args.params[0], args.params[1]];
79
- }
80
- throw new Error(`No key provider found for the arguments ${args}`);
81
- };
82
- function getIFrameResponseKeyProvider(param) {
83
- if (param.method === "frak_getArticleUnlockOptions") {
84
- return (response) => [
85
- "get-price-response",
86
- response.prices.length
87
- ];
88
- }
89
- if (param.method === "frak_listenToWalletStatus") {
90
- return (response) => [
91
- "wallet-status",
92
- response.key,
93
- response.key === "connected" ? response.wallet : "0xdeadbeef"
94
- ];
95
- }
96
- if (param.method === "frak_listenToArticleUnlockStatus") {
97
- return (response) => [
98
- "article-unlock-status",
99
- response.key,
100
- response.key === "valid" ? response.allowedUntil.toString(16) : "deadbeef"
101
- ];
102
- }
103
- if (param.method === "frak_listenToSetUserReferred") {
104
- return (response) => [
105
- "user-referred",
106
- response.key
107
- ];
108
- }
109
- throw new Error(`No key provider found for the request ${param}`);
110
- }
111
-
112
- // src/core/utils/iframeHelper.ts
113
- function createIframe({
114
- walletBaseUrl
115
- }) {
116
- const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
117
- if (alreadyCreatedIFrame) {
118
- return Promise.resolve(void 0);
119
- }
120
- const iframe = document.createElement("iframe");
121
- iframe.name = "nexus-wallet";
122
- iframe.id = "nexus-wallet";
123
- iframe.style.width = "0";
124
- iframe.style.height = "0";
125
- iframe.style.border = "0";
126
- iframe.style.position = "absolute";
127
- iframe.style.top = "-1000px";
128
- iframe.style.left = "-1000px";
129
- document.body.appendChild(iframe);
130
- return new Promise((resolve) => {
131
- iframe?.addEventListener("load", () => resolve(iframe));
132
- iframe.src = `${walletBaseUrl}/listener`;
133
- });
134
- }
135
-
136
- // src/core/utils/compression/redirectKeyProvider.ts
137
- var redirectRequestKeyProvider = (args) => {
138
- if (args.method === "frak_startArticleUnlock") {
139
- return [
140
- "start-unlock",
141
- args.params.contentId,
142
- args.params.articleId,
143
- args.params.price.index.toString()
144
- ];
145
- }
146
- throw new Error(`No key provider found for the arguments ${args}`);
147
- };
148
- function getRedirectResponseResponseKeyProvider(method) {
149
- if (method === "frak_startArticleUnlock") {
150
- return (response) => [
151
- "start-unlock",
152
- response.key,
153
- response.status,
154
- response.user ?? "0xdeadbeef"
155
- ];
156
- }
157
- throw new Error(`No key provider found for the method ${method}`);
158
- }
159
-
160
- export {
161
- __publicField,
162
- hashAndCompressData,
163
- decompressDataAndCheckHash,
164
- iFrameRequestKeyProvider,
165
- getIFrameResponseKeyProvider,
166
- createIframe,
167
- redirectRequestKeyProvider,
168
- getRedirectResponseResponseKeyProvider
169
- };