@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
|
@@ -0,0 +1,100 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkBPFJZRJ6cjs = require('./chunk-BPFJZRJ6.cjs');
|
|
5
|
+
|
|
6
|
+
// src/core/actions/getUnlockOptions.ts
|
|
7
|
+
function getArticleUnlockOptions(client, { articleId, contentId }) {
|
|
8
|
+
return client.request({
|
|
9
|
+
method: "frak_getArticleUnlockOptions",
|
|
10
|
+
params: [contentId, articleId]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/core/actions/watchUnlockStatus.ts
|
|
15
|
+
function watchUnlockStatus(client, { articleId, contentId }, callback) {
|
|
16
|
+
return client.listenerRequest(
|
|
17
|
+
{
|
|
18
|
+
method: "frak_listenToArticleUnlockStatus",
|
|
19
|
+
params: [contentId, articleId]
|
|
20
|
+
},
|
|
21
|
+
callback
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/core/actions/watchWalletStatus.ts
|
|
26
|
+
function watchWalletStatus(client, callback) {
|
|
27
|
+
return client.listenerRequest(
|
|
28
|
+
{
|
|
29
|
+
method: "frak_listenToWalletStatus"
|
|
30
|
+
},
|
|
31
|
+
callback
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/core/actions/startUnlock.ts
|
|
36
|
+
async function getStartArticleUnlockUrl(config, params) {
|
|
37
|
+
const { compressed, compressedHash } = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, {
|
|
38
|
+
method: "frak_startArticleUnlock",
|
|
39
|
+
params
|
|
40
|
+
});
|
|
41
|
+
const outputUrl = new URL(config.walletUrl);
|
|
42
|
+
outputUrl.pathname = "/paywall";
|
|
43
|
+
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
44
|
+
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
45
|
+
return outputUrl.toString();
|
|
46
|
+
}
|
|
47
|
+
async function decodeStartUnlockReturn({
|
|
48
|
+
result,
|
|
49
|
+
hash
|
|
50
|
+
}) {
|
|
51
|
+
return _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, {
|
|
52
|
+
compressed: decodeURIComponent(result),
|
|
53
|
+
compressedHash: decodeURIComponent(hash)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/core/actions/sendTransaction.ts
|
|
58
|
+
async function sendTransaction(client, { tx, context }) {
|
|
59
|
+
return await client.request({
|
|
60
|
+
method: "frak_sendTransaction",
|
|
61
|
+
params: [tx, context]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/core/actions/siweAuthenticate.ts
|
|
66
|
+
var _siwe = require('viem/siwe');
|
|
67
|
+
async function siweAuthenticate(client, { siwe, context }) {
|
|
68
|
+
const realStatement = _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _ => _.statement]), () => ( `I confirm that I want to use my Nexus wallet on: ${client.config.metadata.name}`));
|
|
69
|
+
const builtSiwe = {
|
|
70
|
+
...siwe,
|
|
71
|
+
statement: realStatement,
|
|
72
|
+
nonce: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _2 => _2.nonce]), () => ( _siwe.generateSiweNonce.call(void 0, ))),
|
|
73
|
+
uri: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _3 => _3.uri]), () => ( `https://${client.config.domain}`)),
|
|
74
|
+
version: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _4 => _4.version]), () => ( "1")),
|
|
75
|
+
domain: client.config.domain
|
|
76
|
+
};
|
|
77
|
+
return await client.request({
|
|
78
|
+
method: "frak_siweAuthenticate",
|
|
79
|
+
params: [builtSiwe, context]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/core/actions/sendInteraction.ts
|
|
84
|
+
async function sendInteraction(client, { contentId, interaction, validation }) {
|
|
85
|
+
return await client.request({
|
|
86
|
+
method: "frak_sendInteraction",
|
|
87
|
+
params: [contentId, interaction, validation]
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.sendTransaction = sendTransaction; exports.siweAuthenticate = siweAuthenticate; exports.sendInteraction = sendInteraction;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/core/interactions/pressEncoder.ts
|
|
2
|
+
import { concatHex, pad } from "viem";
|
|
3
|
+
var PressTypeSelector = "0x02";
|
|
4
|
+
var PressActionsSelector = {
|
|
5
|
+
OpenArticle: "0xc0a24ffb",
|
|
6
|
+
ReadArticle: "0xd5bd0fbe",
|
|
7
|
+
Referred: "0x3d1508ad"
|
|
8
|
+
};
|
|
9
|
+
function openArticle({ articleId }) {
|
|
10
|
+
const interactionData = concatHex([
|
|
11
|
+
PressActionsSelector.OpenArticle,
|
|
12
|
+
pad(articleId, { size: 32 })
|
|
13
|
+
]);
|
|
14
|
+
return {
|
|
15
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
16
|
+
interactionData
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function readArticle({ articleId }) {
|
|
20
|
+
const interactionData = concatHex([
|
|
21
|
+
PressActionsSelector.ReadArticle,
|
|
22
|
+
pad(articleId, { size: 32 })
|
|
23
|
+
]);
|
|
24
|
+
return {
|
|
25
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
26
|
+
interactionData
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function referred({ referrer }) {
|
|
30
|
+
const interactionData = concatHex([
|
|
31
|
+
PressActionsSelector.Referred,
|
|
32
|
+
pad(referrer, { size: 32 })
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
36
|
+
interactionData
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var PressInteractionEncoder = {
|
|
40
|
+
openArticle,
|
|
41
|
+
readArticle,
|
|
42
|
+
referred
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
PressActionsSelector,
|
|
47
|
+
PressInteractionEncoder
|
|
48
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
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; }// src/core/types/rpc/error.ts
|
|
2
|
+
var FrakRpcError = class extends Error {
|
|
3
|
+
constructor(code, message, data) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.data = data;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var ClientNotFound = class extends FrakRpcError {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(RpcErrorCodes.clientNotConnected, "Client not found");
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var RpcErrorCodes = {
|
|
15
|
+
// Standard JSON-RPC 2.0 errors
|
|
16
|
+
parseError: -32700,
|
|
17
|
+
invalidRequest: -32600,
|
|
18
|
+
methodNotFound: -32601,
|
|
19
|
+
invalidParams: -32602,
|
|
20
|
+
internalError: -32603,
|
|
21
|
+
serverError: -32e3,
|
|
22
|
+
// Frak specific errors (from -32001 to -32099)
|
|
23
|
+
clientNotConnected: -32001,
|
|
24
|
+
configError: -32002,
|
|
25
|
+
corruptedResponse: -32003,
|
|
26
|
+
clientAborted: -32004,
|
|
27
|
+
walletNotConnected: -32005,
|
|
28
|
+
noInteractionSession: -32006
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/core/utils/compression/compress.ts
|
|
32
|
+
var _asynclzstring = require('async-lz-string');
|
|
33
|
+
var _jssha256 = require('js-sha256');
|
|
34
|
+
async function hashAndCompressData(data) {
|
|
35
|
+
const validationHash = _jssha256.sha256.call(void 0, JSON.stringify(data));
|
|
36
|
+
const hashProtectedData = {
|
|
37
|
+
...data,
|
|
38
|
+
validationHash
|
|
39
|
+
};
|
|
40
|
+
const compressed = await compressJson(hashProtectedData);
|
|
41
|
+
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
42
|
+
return {
|
|
43
|
+
compressed,
|
|
44
|
+
compressedHash
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function compressJson(data) {
|
|
48
|
+
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/core/utils/compression/decompress.ts
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async function decompressDataAndCheckHash(compressedData) {
|
|
55
|
+
if (!(_optionalChain([compressedData, 'optionalAccess', _2 => _2.compressed]) && _optionalChain([compressedData, 'optionalAccess', _3 => _3.compressedHash]))) {
|
|
56
|
+
throw new FrakRpcError(
|
|
57
|
+
RpcErrorCodes.corruptedResponse,
|
|
58
|
+
"Missing compressed data"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const parsedData = await decompressJson(
|
|
62
|
+
compressedData.compressed
|
|
63
|
+
);
|
|
64
|
+
if (!parsedData) {
|
|
65
|
+
throw new FrakRpcError(
|
|
66
|
+
RpcErrorCodes.corruptedResponse,
|
|
67
|
+
"Invalid compressed data"
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (!_optionalChain([parsedData, 'optionalAccess', _4 => _4.validationHash])) {
|
|
71
|
+
throw new FrakRpcError(
|
|
72
|
+
RpcErrorCodes.corruptedResponse,
|
|
73
|
+
"Missing validation hash"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const expectedCompressedHash = _jssha256.sha256.call(void 0, compressedData.compressed);
|
|
77
|
+
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
78
|
+
throw new FrakRpcError(
|
|
79
|
+
RpcErrorCodes.corruptedResponse,
|
|
80
|
+
"Invalid compressed hash"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const { validationHash: _, ...rawResultData } = parsedData;
|
|
84
|
+
const expectedValidationHash = _jssha256.sha256.call(void 0, JSON.stringify(rawResultData));
|
|
85
|
+
if (expectedValidationHash !== parsedData.validationHash) {
|
|
86
|
+
throw new FrakRpcError(
|
|
87
|
+
RpcErrorCodes.corruptedResponse,
|
|
88
|
+
"Invalid data validation hash"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return parsedData;
|
|
92
|
+
}
|
|
93
|
+
async function decompressJson(data) {
|
|
94
|
+
const decompressed = await _asynclzstring.decompressFromBase64.call(void 0, data);
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(decompressed);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error("Invalid compressed data", e);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/utils/iframeHelper.ts
|
|
104
|
+
function createIframe({
|
|
105
|
+
walletBaseUrl
|
|
106
|
+
}) {
|
|
107
|
+
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
108
|
+
if (alreadyCreatedIFrame) {
|
|
109
|
+
return Promise.resolve(void 0);
|
|
110
|
+
}
|
|
111
|
+
const iframe = document.createElement("iframe");
|
|
112
|
+
iframe.name = "nexus-wallet";
|
|
113
|
+
iframe.id = "nexus-wallet";
|
|
114
|
+
iframe.style.zIndex = "1000";
|
|
115
|
+
changeIframeVisibility({ iframe, isVisible: false });
|
|
116
|
+
document.body.appendChild(iframe);
|
|
117
|
+
return new Promise((resolve) => {
|
|
118
|
+
_optionalChain([iframe, 'optionalAccess', _5 => _5.addEventListener, 'call', _6 => _6("load", () => resolve(iframe))]);
|
|
119
|
+
iframe.src = `${walletBaseUrl}/listener`;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function changeIframeVisibility({
|
|
123
|
+
iframe,
|
|
124
|
+
isVisible
|
|
125
|
+
}) {
|
|
126
|
+
if (!isVisible) {
|
|
127
|
+
iframe.style.width = "0";
|
|
128
|
+
iframe.style.height = "0";
|
|
129
|
+
iframe.style.border = "0";
|
|
130
|
+
iframe.style.position = "fixed";
|
|
131
|
+
iframe.style.top = "-1000px";
|
|
132
|
+
iframe.style.left = "-1000px";
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
iframe.style.position = "fixed";
|
|
136
|
+
iframe.style.top = "0";
|
|
137
|
+
iframe.style.left = "0";
|
|
138
|
+
iframe.style.width = "100%";
|
|
139
|
+
iframe.style.height = "100%";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
exports.FrakRpcError = FrakRpcError; exports.ClientNotFound = ClientNotFound; exports.RpcErrorCodes = RpcErrorCodes; exports.hashAndCompressData = hashAndCompressData; exports.compressJson = compressJson; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.decompressJson = decompressJson; exports.createIframe = createIframe; exports.changeIframeVisibility = changeIframeVisibility;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.__publicField = __publicField;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
FrakRpcError,
|
|
3
|
+
RpcErrorCodes,
|
|
4
|
+
changeIframeVisibility,
|
|
3
5
|
decompressDataAndCheckHash,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
hashAndCompressData
|
|
7
|
+
} from "./chunk-TPC5PMRC.js";
|
|
8
|
+
import {
|
|
9
|
+
__publicField
|
|
10
|
+
} from "./chunk-PKBMQBKP.js";
|
|
8
11
|
|
|
9
12
|
// src/core/utils/Deferred.ts
|
|
10
13
|
var Deferred = class {
|
|
@@ -51,10 +54,16 @@ function createIFrameMessageHandler({
|
|
|
51
54
|
channelManager
|
|
52
55
|
}) {
|
|
53
56
|
if (typeof window === "undefined") {
|
|
54
|
-
throw new
|
|
57
|
+
throw new FrakRpcError(
|
|
58
|
+
RpcErrorCodes.configError,
|
|
59
|
+
"iframe client should be used in the browser"
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
if (!iframe.contentWindow) {
|
|
57
|
-
throw new
|
|
63
|
+
throw new FrakRpcError(
|
|
64
|
+
RpcErrorCodes.configError,
|
|
65
|
+
"The iframe does not have a content window"
|
|
66
|
+
);
|
|
58
67
|
}
|
|
59
68
|
const contentWindow = iframe.contentWindow;
|
|
60
69
|
const isConnected = new Deferred();
|
|
@@ -66,7 +75,18 @@ function createIFrameMessageHandler({
|
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
77
|
if ("lifecycle" in event.data) {
|
|
69
|
-
|
|
78
|
+
switch (event.data.lifecycle) {
|
|
79
|
+
case "connected":
|
|
80
|
+
isConnected.resolve(true);
|
|
81
|
+
break;
|
|
82
|
+
case "show":
|
|
83
|
+
case "hide":
|
|
84
|
+
changeIframeVisibility({
|
|
85
|
+
iframe,
|
|
86
|
+
isVisible: event.data.lifecycle === "show"
|
|
87
|
+
});
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
70
90
|
return;
|
|
71
91
|
}
|
|
72
92
|
const channel = event.data.id;
|
|
@@ -106,24 +126,31 @@ function createIFrameNexusClient({
|
|
|
106
126
|
const request = async (args) => {
|
|
107
127
|
const isConnected = await messageHandler.isConnected;
|
|
108
128
|
if (!isConnected) {
|
|
109
|
-
throw new
|
|
129
|
+
throw new FrakRpcError(
|
|
130
|
+
RpcErrorCodes.clientNotConnected,
|
|
131
|
+
"The iframe provider isn't connected yet"
|
|
132
|
+
);
|
|
110
133
|
}
|
|
111
134
|
const result = new Deferred();
|
|
112
|
-
const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
|
|
113
135
|
const channelId = channelManager.createChannel(async (message) => {
|
|
114
|
-
const decompressed = await decompressDataAndCheckHash(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
136
|
+
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
137
|
+
if (decompressed.error) {
|
|
138
|
+
result.reject(
|
|
139
|
+
new FrakRpcError(
|
|
140
|
+
decompressed.error.code,
|
|
141
|
+
decompressed.error.message,
|
|
142
|
+
decompressed.error?.data
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
result.resolve(decompressed.result);
|
|
147
|
+
}
|
|
119
148
|
channelManager.removeChannel(channelId);
|
|
120
149
|
});
|
|
121
|
-
const compressedMessage = await hashAndCompressData(
|
|
122
|
-
args,
|
|
123
|
-
iFrameRequestKeyProvider
|
|
124
|
-
);
|
|
150
|
+
const compressedMessage = await hashAndCompressData(args);
|
|
125
151
|
messageHandler.sendEvent({
|
|
126
152
|
id: channelId,
|
|
153
|
+
// @ts-ignore, todo: idk why the fck it's needed
|
|
127
154
|
topic: args.method,
|
|
128
155
|
data: compressedMessage
|
|
129
156
|
});
|
|
@@ -132,20 +159,21 @@ function createIFrameNexusClient({
|
|
|
132
159
|
const listenerRequest = async (args, callback) => {
|
|
133
160
|
const isConnected = await messageHandler.isConnected;
|
|
134
161
|
if (!isConnected) {
|
|
135
|
-
throw new
|
|
162
|
+
throw new FrakRpcError(
|
|
163
|
+
RpcErrorCodes.clientNotConnected,
|
|
164
|
+
"The iframe provider isn't connected yet"
|
|
165
|
+
);
|
|
136
166
|
}
|
|
137
|
-
const resultCompressionKeyProvider = getIFrameResponseKeyProvider(args);
|
|
138
167
|
const channelId = channelManager.createChannel(async (message) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)
|
|
143
|
-
|
|
168
|
+
console.log("Will try to decompress", { message, args });
|
|
169
|
+
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
170
|
+
console.log("Decompressed listening data", { args, decompressed });
|
|
171
|
+
if (decompressed.result) {
|
|
172
|
+
callback(decompressed.result);
|
|
173
|
+
} else {
|
|
174
|
+
}
|
|
144
175
|
});
|
|
145
|
-
const compressedMessage = await hashAndCompressData(
|
|
146
|
-
args,
|
|
147
|
-
iFrameRequestKeyProvider
|
|
148
|
-
);
|
|
176
|
+
const compressedMessage = await hashAndCompressData(args);
|
|
149
177
|
messageHandler.sendEvent({
|
|
150
178
|
id: channelId,
|
|
151
179
|
topic: args.method,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/interactions/pressEncoder.ts
|
|
2
|
+
var _viem = require('viem');
|
|
3
|
+
var PressTypeSelector = "0x02";
|
|
4
|
+
var PressActionsSelector = {
|
|
5
|
+
OpenArticle: "0xc0a24ffb",
|
|
6
|
+
ReadArticle: "0xd5bd0fbe",
|
|
7
|
+
Referred: "0x3d1508ad"
|
|
8
|
+
};
|
|
9
|
+
function openArticle({ articleId }) {
|
|
10
|
+
const interactionData = _viem.concatHex.call(void 0, [
|
|
11
|
+
PressActionsSelector.OpenArticle,
|
|
12
|
+
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
13
|
+
]);
|
|
14
|
+
return {
|
|
15
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
16
|
+
interactionData
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function readArticle({ articleId }) {
|
|
20
|
+
const interactionData = _viem.concatHex.call(void 0, [
|
|
21
|
+
PressActionsSelector.ReadArticle,
|
|
22
|
+
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
23
|
+
]);
|
|
24
|
+
return {
|
|
25
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
26
|
+
interactionData
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function referred({ referrer }) {
|
|
30
|
+
const interactionData = _viem.concatHex.call(void 0, [
|
|
31
|
+
PressActionsSelector.Referred,
|
|
32
|
+
_viem.pad.call(void 0, referrer, { size: 32 })
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
handlerTypeDenominator: PressTypeSelector,
|
|
36
|
+
interactionData
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var PressInteractionEncoder = {
|
|
40
|
+
openArticle,
|
|
41
|
+
readArticle,
|
|
42
|
+
referred
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
exports.PressActionsSelector = PressActionsSelector; exports.PressInteractionEncoder = PressInteractionEncoder;
|
|
@@ -0,0 +1,7 @@
|
|
|
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
__publicField
|
|
7
|
+
};
|
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkBPFJZRJ6cjs = require('./chunk-BPFJZRJ6.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkETV4XYOVcjs = require('./chunk-ETV4XYOV.cjs');
|
|
8
11
|
|
|
9
12
|
// src/core/utils/Deferred.ts
|
|
10
13
|
var Deferred = class {
|
|
11
14
|
constructor() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_promise");
|
|
16
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_resolve");
|
|
17
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_reject");
|
|
18
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
16
19
|
_optionalChain([this, 'access', _ => _._resolve, 'optionalCall', _2 => _2(value)]);
|
|
17
20
|
});
|
|
18
|
-
|
|
21
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
19
22
|
_optionalChain([this, 'access', _3 => _3._reject, 'optionalCall', _4 => _4(reason)]);
|
|
20
23
|
});
|
|
21
24
|
this._promise = new Promise((resolve, reject) => {
|
|
@@ -51,10 +54,16 @@ function createIFrameMessageHandler({
|
|
|
51
54
|
channelManager
|
|
52
55
|
}) {
|
|
53
56
|
if (typeof window === "undefined") {
|
|
54
|
-
throw new
|
|
57
|
+
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
58
|
+
_chunkBPFJZRJ6cjs.RpcErrorCodes.configError,
|
|
59
|
+
"iframe client should be used in the browser"
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
if (!iframe.contentWindow) {
|
|
57
|
-
throw new
|
|
63
|
+
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
64
|
+
_chunkBPFJZRJ6cjs.RpcErrorCodes.configError,
|
|
65
|
+
"The iframe does not have a content window"
|
|
66
|
+
);
|
|
58
67
|
}
|
|
59
68
|
const contentWindow = iframe.contentWindow;
|
|
60
69
|
const isConnected = new Deferred();
|
|
@@ -66,7 +75,18 @@ function createIFrameMessageHandler({
|
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
77
|
if ("lifecycle" in event.data) {
|
|
69
|
-
|
|
78
|
+
switch (event.data.lifecycle) {
|
|
79
|
+
case "connected":
|
|
80
|
+
isConnected.resolve(true);
|
|
81
|
+
break;
|
|
82
|
+
case "show":
|
|
83
|
+
case "hide":
|
|
84
|
+
_chunkBPFJZRJ6cjs.changeIframeVisibility.call(void 0, {
|
|
85
|
+
iframe,
|
|
86
|
+
isVisible: event.data.lifecycle === "show"
|
|
87
|
+
});
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
70
90
|
return;
|
|
71
91
|
}
|
|
72
92
|
const channel = event.data.id;
|
|
@@ -106,24 +126,31 @@ function createIFrameNexusClient({
|
|
|
106
126
|
const request = async (args) => {
|
|
107
127
|
const isConnected = await messageHandler.isConnected;
|
|
108
128
|
if (!isConnected) {
|
|
109
|
-
throw new
|
|
129
|
+
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
130
|
+
_chunkBPFJZRJ6cjs.RpcErrorCodes.clientNotConnected,
|
|
131
|
+
"The iframe provider isn't connected yet"
|
|
132
|
+
);
|
|
110
133
|
}
|
|
111
134
|
const result = new Deferred();
|
|
112
|
-
const resultCompressionKeyProvider = _chunkZOLP2FJZcjs.getIFrameResponseKeyProvider.call(void 0, args);
|
|
113
135
|
const channelId = channelManager.createChannel(async (message) => {
|
|
114
|
-
const decompressed = await
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
136
|
+
const decompressed = await _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
137
|
+
if (decompressed.error) {
|
|
138
|
+
result.reject(
|
|
139
|
+
new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
140
|
+
decompressed.error.code,
|
|
141
|
+
decompressed.error.message,
|
|
142
|
+
_optionalChain([decompressed, 'access', _5 => _5.error, 'optionalAccess', _6 => _6.data])
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
result.resolve(decompressed.result);
|
|
147
|
+
}
|
|
119
148
|
channelManager.removeChannel(channelId);
|
|
120
149
|
});
|
|
121
|
-
const compressedMessage = await
|
|
122
|
-
args,
|
|
123
|
-
_chunkZOLP2FJZcjs.iFrameRequestKeyProvider
|
|
124
|
-
);
|
|
150
|
+
const compressedMessage = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, args);
|
|
125
151
|
messageHandler.sendEvent({
|
|
126
152
|
id: channelId,
|
|
153
|
+
// @ts-ignore, todo: idk why the fck it's needed
|
|
127
154
|
topic: args.method,
|
|
128
155
|
data: compressedMessage
|
|
129
156
|
});
|
|
@@ -132,20 +159,21 @@ function createIFrameNexusClient({
|
|
|
132
159
|
const listenerRequest = async (args, callback) => {
|
|
133
160
|
const isConnected = await messageHandler.isConnected;
|
|
134
161
|
if (!isConnected) {
|
|
135
|
-
throw new
|
|
162
|
+
throw new (0, _chunkBPFJZRJ6cjs.FrakRpcError)(
|
|
163
|
+
_chunkBPFJZRJ6cjs.RpcErrorCodes.clientNotConnected,
|
|
164
|
+
"The iframe provider isn't connected yet"
|
|
165
|
+
);
|
|
136
166
|
}
|
|
137
|
-
const resultCompressionKeyProvider = _chunkZOLP2FJZcjs.getIFrameResponseKeyProvider.call(void 0, args);
|
|
138
167
|
const channelId = channelManager.createChannel(async (message) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)
|
|
143
|
-
|
|
168
|
+
console.log("Will try to decompress", { message, args });
|
|
169
|
+
const decompressed = await _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, message.data);
|
|
170
|
+
console.log("Decompressed listening data", { args, decompressed });
|
|
171
|
+
if (decompressed.result) {
|
|
172
|
+
callback(decompressed.result);
|
|
173
|
+
} else {
|
|
174
|
+
}
|
|
144
175
|
});
|
|
145
|
-
const compressedMessage = await
|
|
146
|
-
args,
|
|
147
|
-
_chunkZOLP2FJZcjs.iFrameRequestKeyProvider
|
|
148
|
-
);
|
|
176
|
+
const compressedMessage = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, args);
|
|
149
177
|
messageHandler.sendEvent({
|
|
150
178
|
id: channelId,
|
|
151
179
|
topic: args.method,
|