@frak-labs/nexus-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/dist/chunk-3T2FNW6E.cjs +100 -0
- package/dist/chunk-72IEHEQX.js +48 -0
- package/dist/chunk-BPFJZRJ6.cjs +152 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/{chunk-SZUN32YC.js → chunk-HOX3RRO6.js} +58 -30
- package/dist/chunk-NIFJZD3M.cjs +48 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/{chunk-AYZHGMEV.cjs → chunk-SGLR6RFA.cjs} +59 -31
- package/dist/chunk-T54VMWHQ.js +100 -0
- package/dist/chunk-TPC5PMRC.js +152 -0
- package/dist/{client-BwzXSgqQ.d.ts → client--U_6SK0l.d.cts} +91 -30
- package/dist/{client-BwzXSgqQ.d.cts → client-6_BJp7Ub.d.ts} +91 -30
- package/dist/core/actions/index.cjs +8 -3
- package/dist/core/actions/index.d.cts +25 -13
- package/dist/core/actions/index.d.ts +25 -13
- package/dist/core/actions/index.js +9 -4
- package/dist/core/index.cjs +4 -7
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -12
- package/dist/core/interactions/index.cjs +9 -0
- package/dist/core/interactions/index.d.cts +39 -0
- package/dist/core/interactions/index.d.ts +39 -0
- package/dist/core/interactions/index.js +9 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D_CzyqRE.d.cts +22 -0
- package/dist/interaction-D_CzyqRE.d.ts +22 -0
- package/dist/react/index.cjs +234 -109
- package/dist/react/index.d.cts +69 -19
- package/dist/react/index.d.ts +69 -19
- package/dist/react/index.js +236 -111
- package/dist/{watchUnlockStatus-WJxoDliF.d.ts → watchUnlockStatus-CxnibdQx.d.cts} +3 -3
- package/dist/{watchUnlockStatus-DXClCYH9.d.cts → watchUnlockStatus-g8wIxpeM.d.ts} +3 -3
- package/package.json +11 -5
- package/dist/chunk-PDR3CF3P.js +0 -86
- package/dist/chunk-VK7GPKK4.js +0 -169
- package/dist/chunk-X4JNNWJ4.cjs +0 -86
- package/dist/chunk-ZOLP2FJZ.cjs +0 -169
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": "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
16
|
"repository": "https://github.com/frak-id/wallet",
|
|
17
17
|
"homepage": "https://docs.frak.id/wallet-sdk",
|
|
@@ -49,6 +49,11 @@
|
|
|
49
49
|
"import": "./dist/core/actions/index.js",
|
|
50
50
|
"default": "./dist/core/actions/index.cjs"
|
|
51
51
|
},
|
|
52
|
+
"./interactions": {
|
|
53
|
+
"types": "./dist/core/interactions/index.d.ts",
|
|
54
|
+
"import": "./dist/core/interactions/index.js",
|
|
55
|
+
"default": "./dist/core/interactions/index.cjs"
|
|
56
|
+
},
|
|
52
57
|
"./react": {
|
|
53
58
|
"types": "./dist/react/index.d.ts",
|
|
54
59
|
"import": "./dist/react/index.js",
|
|
@@ -58,9 +63,10 @@
|
|
|
58
63
|
"scripts": {
|
|
59
64
|
"lint": "biome lint .",
|
|
60
65
|
"format:check": "biome check .",
|
|
61
|
-
"format": "biome check --
|
|
66
|
+
"format": "biome check --write .",
|
|
62
67
|
"clean": "rimraf dist",
|
|
63
|
-
"build": "tsup --splitting"
|
|
68
|
+
"build": "tsup --splitting",
|
|
69
|
+
"build:watch": "tsup --watch --splitting --format esm"
|
|
64
70
|
},
|
|
65
71
|
"peerDependencies": {
|
|
66
72
|
"viem": "^2.x",
|
|
@@ -72,9 +78,9 @@
|
|
|
72
78
|
"js-sha256": "^0.11.0"
|
|
73
79
|
},
|
|
74
80
|
"devDependencies": {
|
|
75
|
-
"@tanstack/react-query": ">=5.
|
|
81
|
+
"@tanstack/react-query": ">=5.49.2",
|
|
76
82
|
"@types/node": "^20",
|
|
77
|
-
"tsup": "^8.0
|
|
83
|
+
"tsup": "^8.1.0",
|
|
78
84
|
"typescript": "^5"
|
|
79
85
|
}
|
|
80
86
|
}
|
package/dist/chunk-PDR3CF3P.js
DELETED
|
@@ -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
|
-
};
|
package/dist/chunk-VK7GPKK4.js
DELETED
|
@@ -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
|
-
};
|
package/dist/chunk-X4JNNWJ4.cjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkZOLP2FJZcjs = require('./chunk-ZOLP2FJZ.cjs');
|
|
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 _chunkZOLP2FJZcjs.hashAndCompressData.call(void 0,
|
|
40
|
-
{
|
|
41
|
-
method: "frak_startArticleUnlock",
|
|
42
|
-
params
|
|
43
|
-
},
|
|
44
|
-
_chunkZOLP2FJZcjs.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 = _chunkZOLP2FJZcjs.getRedirectResponseResponseKeyProvider.call(void 0,
|
|
57
|
-
"frak_startArticleUnlock"
|
|
58
|
-
);
|
|
59
|
-
return _chunkZOLP2FJZcjs.decompressDataAndCheckHash.call(void 0,
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.setUserReferred = setUserReferred;
|
package/dist/chunk-ZOLP2FJZ.cjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }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
|
-
var _asynclzstring = require('async-lz-string');
|
|
10
|
-
var _jssha256 = require('js-sha256');
|
|
11
|
-
async function hashAndCompressData(data, keyProvider) {
|
|
12
|
-
const keys = keyProvider(data);
|
|
13
|
-
const validationHash = _jssha256.sha256.call(void 0, keys.join("_"));
|
|
14
|
-
const hashProtectedData = {
|
|
15
|
-
...data,
|
|
16
|
-
validationHash
|
|
17
|
-
};
|
|
18
|
-
const compressed = await compressJson(hashProtectedData);
|
|
19
|
-
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
20
|
-
return {
|
|
21
|
-
compressed,
|
|
22
|
-
compressedHash
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async function compressJson(data) {
|
|
26
|
-
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/core/utils/compression/decompress.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
async function decompressDataAndCheckHash(compressedData, keyAccessor) {
|
|
33
|
-
if (!(_optionalChain([compressedData, 'optionalAccess', _ => _.compressed]) && _optionalChain([compressedData, 'optionalAccess', _2 => _2.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 (!_optionalChain([parsedData, 'optionalAccess', _3 => _3.validationHash])) {
|
|
43
|
-
throw new Error("Missing validation hash");
|
|
44
|
-
}
|
|
45
|
-
const expectedCompressedHash = _jssha256.sha256.call(void 0, compressedData.compressed);
|
|
46
|
-
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
47
|
-
throw new Error("Invalid compressed hash");
|
|
48
|
-
}
|
|
49
|
-
const keys = keyAccessor(parsedData);
|
|
50
|
-
const expectedValidationHash = _jssha256.sha256.call(void 0, 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 _asynclzstring.decompressFromBase64.call(void 0, 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
|
-
_optionalChain([iframe, 'optionalAccess', _4 => _4.addEventListener, 'call', _5 => _5("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
|
-
_nullishCoalesce(response.user, () => ( "0xdeadbeef"))
|
|
155
|
-
];
|
|
156
|
-
}
|
|
157
|
-
throw new Error(`No key provider found for the method ${method}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
exports.__publicField = __publicField; exports.hashAndCompressData = hashAndCompressData; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.iFrameRequestKeyProvider = iFrameRequestKeyProvider; exports.getIFrameResponseKeyProvider = getIFrameResponseKeyProvider; exports.createIframe = createIframe; exports.redirectRequestKeyProvider = redirectRequestKeyProvider; exports.getRedirectResponseResponseKeyProvider = getRedirectResponseResponseKeyProvider;
|