@frak-labs/nexus-sdk 0.0.14 → 0.0.16
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/README.md +4 -4
- package/dist/FrakContext-LbQht1ep.d.cts +10 -0
- package/dist/FrakContext-LbQht1ep.d.ts +10 -0
- package/dist/bundle/bundle.js +21 -0
- package/dist/chunk-A3XYA7S7.cjs +114 -0
- package/dist/{chunk-5LZQXBFJ.js → chunk-AHUMDUJC.js} +12 -196
- package/dist/chunk-D77BTQYS.js +210 -0
- package/dist/chunk-DAGCBEBQ.cjs +243 -0
- package/dist/chunk-FO2GFD5C.cjs +210 -0
- package/dist/chunk-FYMOOHMT.js +254 -0
- package/dist/chunk-HY6YATLS.js +53 -0
- package/dist/chunk-J655X6YR.cjs +254 -0
- package/dist/chunk-TIKEZMSD.js +114 -0
- package/dist/chunk-UFJ7W6CQ.cjs +53 -0
- package/dist/{client-DJd7-ajw.d.ts → client-ALy_TEwJ.d.ts} +34 -11
- package/dist/{client-DXITs1Kf.d.cts → client-DaEox5q4.d.cts} +34 -11
- package/dist/core/actions/index.cjs +11 -3
- package/dist/core/actions/index.d.cts +28 -5
- package/dist/core/actions/index.d.ts +28 -5
- package/dist/core/actions/index.js +10 -2
- package/dist/core/index.cjs +15 -4
- package/dist/core/index.d.cts +98 -4
- package/dist/core/index.d.ts +98 -4
- package/dist/core/index.js +15 -4
- package/dist/core/interactions/index.cjs +3 -4
- package/dist/core/interactions/index.d.cts +27 -15
- package/dist/core/interactions/index.d.ts +27 -15
- package/dist/core/interactions/index.js +8 -9
- package/dist/{error-C4Zm5nQe.d.cts → error-Dflr3G5x.d.cts} +1 -1
- package/dist/{error-C4Zm5nQe.d.ts → error-Dflr3G5x.d.ts} +1 -1
- package/dist/react/index.cjs +79 -155
- package/dist/react/index.d.cts +4 -5
- package/dist/react/index.d.ts +4 -5
- package/dist/react/index.js +78 -154
- package/dist/{sendTransaction-fLvpfqaQ.d.ts → sendTransaction-BOd-pvXr.d.ts} +2 -2
- package/dist/{sendTransaction-C19oCc6X.d.cts → sendTransaction-MhdJPTWd.d.cts} +2 -2
- package/package.json +6 -6
- package/dist/chunk-22T2NHQK.js +0 -22
- package/dist/chunk-5SGDBU5S.cjs +0 -427
- package/dist/chunk-AANA3LEO.cjs +0 -22
- package/dist/chunk-ETV4XYOV.cjs +0 -7
- package/dist/chunk-IH3QWPWT.js +0 -72
- package/dist/chunk-PKBMQBKP.js +0 -7
- package/dist/chunk-PURWUKEM.cjs +0 -72
- package/dist/chunk-S223FMEJ.js +0 -86
- package/dist/chunk-UOEVM7TR.cjs +0 -86
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -0
package/dist/chunk-5SGDBU5S.cjs
DELETED
|
@@ -1,427 +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
|
-
var _chunkETV4XYOVcjs = require('./chunk-ETV4XYOV.cjs');
|
|
4
|
-
|
|
5
|
-
// src/core/types/rpc/error.ts
|
|
6
|
-
var FrakRpcError = class extends Error {
|
|
7
|
-
constructor(code, message, data) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.data = data;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var InternalError = class extends FrakRpcError {
|
|
14
|
-
constructor(message) {
|
|
15
|
-
super(RpcErrorCodes.internalError, message);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var ClientNotFound = class extends FrakRpcError {
|
|
19
|
-
constructor() {
|
|
20
|
-
super(RpcErrorCodes.clientNotConnected, "Client not found");
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var RpcErrorCodes = {
|
|
24
|
-
// Standard JSON-RPC 2.0 errors
|
|
25
|
-
parseError: -32700,
|
|
26
|
-
invalidRequest: -32600,
|
|
27
|
-
methodNotFound: -32601,
|
|
28
|
-
invalidParams: -32602,
|
|
29
|
-
internalError: -32603,
|
|
30
|
-
serverError: -32e3,
|
|
31
|
-
// Frak specific errors (from -32001 to -32099)
|
|
32
|
-
clientNotConnected: -32001,
|
|
33
|
-
configError: -32002,
|
|
34
|
-
corruptedResponse: -32003,
|
|
35
|
-
clientAborted: -32004,
|
|
36
|
-
walletNotConnected: -32005,
|
|
37
|
-
noInteractionSession: -32006
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/core/utils/Deferred.ts
|
|
41
|
-
var Deferred = class {
|
|
42
|
-
constructor() {
|
|
43
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_promise");
|
|
44
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_resolve");
|
|
45
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_reject");
|
|
46
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
47
|
-
_optionalChain([this, 'access', _2 => _2._resolve, 'optionalCall', _3 => _3(value)]);
|
|
48
|
-
});
|
|
49
|
-
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
50
|
-
_optionalChain([this, 'access', _4 => _4._reject, 'optionalCall', _5 => _5(reason)]);
|
|
51
|
-
});
|
|
52
|
-
this._promise = new Promise((resolve, reject) => {
|
|
53
|
-
this._resolve = resolve;
|
|
54
|
-
this._reject = reject;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
get promise() {
|
|
58
|
-
return this._promise;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/core/utils/compression/compress.ts
|
|
63
|
-
var _asynclzstring = require('async-lz-string');
|
|
64
|
-
var _jssha256 = require('js-sha256');
|
|
65
|
-
async function hashAndCompressData(data) {
|
|
66
|
-
const validationHash = _jssha256.sha256.call(void 0, JSON.stringify(data));
|
|
67
|
-
const hashProtectedData = {
|
|
68
|
-
...data,
|
|
69
|
-
validationHash
|
|
70
|
-
};
|
|
71
|
-
const compressed = await compressJson(hashProtectedData);
|
|
72
|
-
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
73
|
-
return {
|
|
74
|
-
compressed,
|
|
75
|
-
compressedHash
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async function compressJson(data) {
|
|
79
|
-
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/core/utils/compression/decompress.ts
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
async function decompressDataAndCheckHash(compressedData) {
|
|
86
|
-
if (!(_optionalChain([compressedData, 'optionalAccess', _6 => _6.compressed]) && _optionalChain([compressedData, 'optionalAccess', _7 => _7.compressedHash]))) {
|
|
87
|
-
throw new FrakRpcError(
|
|
88
|
-
RpcErrorCodes.corruptedResponse,
|
|
89
|
-
"Missing compressed data"
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
const parsedData = await decompressJson(
|
|
93
|
-
compressedData.compressed
|
|
94
|
-
);
|
|
95
|
-
if (!parsedData) {
|
|
96
|
-
throw new FrakRpcError(
|
|
97
|
-
RpcErrorCodes.corruptedResponse,
|
|
98
|
-
"Invalid compressed data"
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
if (!_optionalChain([parsedData, 'optionalAccess', _8 => _8.validationHash])) {
|
|
102
|
-
throw new FrakRpcError(
|
|
103
|
-
RpcErrorCodes.corruptedResponse,
|
|
104
|
-
"Missing validation hash"
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
const expectedCompressedHash = _jssha256.sha256.call(void 0, compressedData.compressed);
|
|
108
|
-
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
109
|
-
throw new FrakRpcError(
|
|
110
|
-
RpcErrorCodes.corruptedResponse,
|
|
111
|
-
"Invalid compressed hash"
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
const { validationHash: _, ...rawResultData } = parsedData;
|
|
115
|
-
const expectedValidationHash = _jssha256.sha256.call(void 0, JSON.stringify(rawResultData));
|
|
116
|
-
if (expectedValidationHash !== parsedData.validationHash) {
|
|
117
|
-
throw new FrakRpcError(
|
|
118
|
-
RpcErrorCodes.corruptedResponse,
|
|
119
|
-
"Invalid data validation hash"
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return parsedData;
|
|
123
|
-
}
|
|
124
|
-
async function decompressJson(data) {
|
|
125
|
-
const decompressed = await _asynclzstring.decompressFromBase64.call(void 0, data);
|
|
126
|
-
try {
|
|
127
|
-
return JSON.parse(decompressed);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
console.error("Invalid compressed data", e);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/core/utils/constants.ts
|
|
135
|
-
var BACKUP_KEY = "nexus-wallet-backup";
|
|
136
|
-
|
|
137
|
-
// src/core/clients/transports/iframeChannelManager.ts
|
|
138
|
-
function createIFrameChannelManager() {
|
|
139
|
-
const channels = /* @__PURE__ */ new Map();
|
|
140
|
-
return {
|
|
141
|
-
// TODO: Better id system?? uid stuff?
|
|
142
|
-
createChannel: (resolver) => {
|
|
143
|
-
const id = Math.random().toString(36).substring(7);
|
|
144
|
-
channels.set(id, resolver);
|
|
145
|
-
return id;
|
|
146
|
-
},
|
|
147
|
-
getRpcResolver: (id) => channels.get(id),
|
|
148
|
-
removeChannel: (id) => channels.delete(id),
|
|
149
|
-
destroy: () => channels.clear()
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/core/utils/iframeHelper.ts
|
|
154
|
-
var baseIframeProps = {
|
|
155
|
-
id: "nexus-wallet",
|
|
156
|
-
name: "nexus-wallet",
|
|
157
|
-
allow: "publickey-credentials-get *; clipboard-write; web-share *",
|
|
158
|
-
style: {
|
|
159
|
-
width: "0",
|
|
160
|
-
height: "0",
|
|
161
|
-
border: "0",
|
|
162
|
-
position: "absolute",
|
|
163
|
-
zIndex: 1e3,
|
|
164
|
-
top: "-1000px",
|
|
165
|
-
left: "-1000px"
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
function createIframe({
|
|
169
|
-
walletBaseUrl
|
|
170
|
-
}) {
|
|
171
|
-
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
172
|
-
if (alreadyCreatedIFrame) {
|
|
173
|
-
return Promise.resolve(void 0);
|
|
174
|
-
}
|
|
175
|
-
const iframe = document.createElement("iframe");
|
|
176
|
-
iframe.id = baseIframeProps.id;
|
|
177
|
-
iframe.name = baseIframeProps.name;
|
|
178
|
-
iframe.allow = baseIframeProps.allow;
|
|
179
|
-
iframe.style.zIndex = baseIframeProps.style.zIndex.toString();
|
|
180
|
-
changeIframeVisibility({ iframe, isVisible: false });
|
|
181
|
-
document.body.appendChild(iframe);
|
|
182
|
-
return new Promise((resolve) => {
|
|
183
|
-
_optionalChain([iframe, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("load", () => resolve(iframe))]);
|
|
184
|
-
iframe.src = `${walletBaseUrl}/listener`;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
function changeIframeVisibility({
|
|
188
|
-
iframe,
|
|
189
|
-
isVisible
|
|
190
|
-
}) {
|
|
191
|
-
if (!isVisible) {
|
|
192
|
-
iframe.style.width = "0";
|
|
193
|
-
iframe.style.height = "0";
|
|
194
|
-
iframe.style.border = "0";
|
|
195
|
-
iframe.style.position = "fixed";
|
|
196
|
-
iframe.style.top = "-1000px";
|
|
197
|
-
iframe.style.left = "-1000px";
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
iframe.style.position = "fixed";
|
|
201
|
-
iframe.style.top = "0";
|
|
202
|
-
iframe.style.left = "0";
|
|
203
|
-
iframe.style.width = "100%";
|
|
204
|
-
iframe.style.height = "100%";
|
|
205
|
-
iframe.style.pointerEvents = "auto";
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// src/core/clients/transports/iframeLifecycleManager.ts
|
|
209
|
-
function createIFrameLifecycleManager({
|
|
210
|
-
iframe
|
|
211
|
-
}) {
|
|
212
|
-
const isConnectedDeferred = new Deferred();
|
|
213
|
-
const handler = async (messageEvent) => {
|
|
214
|
-
switch (messageEvent.iframeLifecycle) {
|
|
215
|
-
// Resolve the isConnected promise
|
|
216
|
-
case "connected":
|
|
217
|
-
isConnectedDeferred.resolve(true);
|
|
218
|
-
break;
|
|
219
|
-
// Perform a nexus backup
|
|
220
|
-
case "do-backup":
|
|
221
|
-
if (messageEvent.data.backup) {
|
|
222
|
-
localStorage.setItem(BACKUP_KEY, messageEvent.data.backup);
|
|
223
|
-
} else {
|
|
224
|
-
localStorage.removeItem(BACKUP_KEY);
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
// Change iframe visibility
|
|
228
|
-
case "show":
|
|
229
|
-
case "hide":
|
|
230
|
-
changeIframeVisibility({
|
|
231
|
-
iframe,
|
|
232
|
-
isVisible: messageEvent.iframeLifecycle === "show"
|
|
233
|
-
});
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
return {
|
|
238
|
-
handleEvent: handler,
|
|
239
|
-
isConnected: isConnectedDeferred.promise
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/core/clients/transports/iframeMessageHandler.ts
|
|
244
|
-
function createIFrameMessageHandler({
|
|
245
|
-
nexusWalletUrl,
|
|
246
|
-
iframe,
|
|
247
|
-
channelManager,
|
|
248
|
-
iframeLifecycleManager
|
|
249
|
-
}) {
|
|
250
|
-
if (typeof window === "undefined") {
|
|
251
|
-
throw new FrakRpcError(
|
|
252
|
-
RpcErrorCodes.configError,
|
|
253
|
-
"iframe client should be used in the browser"
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
if (!iframe.contentWindow) {
|
|
257
|
-
throw new FrakRpcError(
|
|
258
|
-
RpcErrorCodes.configError,
|
|
259
|
-
"The iframe does not have a product window"
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
const contentWindow = iframe.contentWindow;
|
|
263
|
-
const msgHandler = async (event) => {
|
|
264
|
-
if (!event.origin) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if ("iframeLifecycle" in event.data) {
|
|
271
|
-
await iframeLifecycleManager.handleEvent(event.data);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
if ("clientLifecycle" in event.data) {
|
|
275
|
-
console.error(
|
|
276
|
-
"Client lifecycle event received on the client side, dismissing it"
|
|
277
|
-
);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const channel = event.data.id;
|
|
281
|
-
const resolver = channelManager.getRpcResolver(channel);
|
|
282
|
-
if (!resolver) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
await resolver(event.data);
|
|
286
|
-
};
|
|
287
|
-
window.addEventListener("message", msgHandler);
|
|
288
|
-
const sendEvent = (message) => {
|
|
289
|
-
contentWindow.postMessage(message, {
|
|
290
|
-
targetOrigin: nexusWalletUrl
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
const cleanup = () => {
|
|
294
|
-
window.removeEventListener("message", msgHandler);
|
|
295
|
-
};
|
|
296
|
-
return {
|
|
297
|
-
sendEvent,
|
|
298
|
-
cleanup
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// src/core/clients/createIFrameNexusClient.ts
|
|
303
|
-
function createIFrameNexusClient({
|
|
304
|
-
config,
|
|
305
|
-
iframe
|
|
306
|
-
}) {
|
|
307
|
-
const channelManager = createIFrameChannelManager();
|
|
308
|
-
const lifecycleManager = createIFrameLifecycleManager({ iframe });
|
|
309
|
-
const messageHandler = createIFrameMessageHandler({
|
|
310
|
-
nexusWalletUrl: config.walletUrl,
|
|
311
|
-
iframe,
|
|
312
|
-
channelManager,
|
|
313
|
-
iframeLifecycleManager: lifecycleManager
|
|
314
|
-
});
|
|
315
|
-
const request = async (args) => {
|
|
316
|
-
const isConnected = await lifecycleManager.isConnected;
|
|
317
|
-
if (!isConnected) {
|
|
318
|
-
throw new FrakRpcError(
|
|
319
|
-
RpcErrorCodes.clientNotConnected,
|
|
320
|
-
"The iframe provider isn't connected yet"
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
const result = new Deferred();
|
|
324
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
325
|
-
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
326
|
-
if (decompressed.error) {
|
|
327
|
-
result.reject(
|
|
328
|
-
new FrakRpcError(
|
|
329
|
-
decompressed.error.code,
|
|
330
|
-
decompressed.error.message,
|
|
331
|
-
_optionalChain([decompressed, 'access', _11 => _11.error, 'optionalAccess', _12 => _12.data])
|
|
332
|
-
)
|
|
333
|
-
);
|
|
334
|
-
} else {
|
|
335
|
-
result.resolve(decompressed.result);
|
|
336
|
-
}
|
|
337
|
-
channelManager.removeChannel(channelId);
|
|
338
|
-
});
|
|
339
|
-
const compressedMessage = await hashAndCompressData(args);
|
|
340
|
-
messageHandler.sendEvent({
|
|
341
|
-
id: channelId,
|
|
342
|
-
topic: args.method,
|
|
343
|
-
data: compressedMessage
|
|
344
|
-
});
|
|
345
|
-
return result.promise;
|
|
346
|
-
};
|
|
347
|
-
const listenerRequest = async (args, callback) => {
|
|
348
|
-
const isConnected = await lifecycleManager.isConnected;
|
|
349
|
-
if (!isConnected) {
|
|
350
|
-
throw new FrakRpcError(
|
|
351
|
-
RpcErrorCodes.clientNotConnected,
|
|
352
|
-
"The iframe provider isn't connected yet"
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
const channelId = channelManager.createChannel(async (message) => {
|
|
356
|
-
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
357
|
-
if (decompressed.result) {
|
|
358
|
-
callback(decompressed.result);
|
|
359
|
-
} else {
|
|
360
|
-
throw new InternalError("No valid result in the response");
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
const compressedMessage = await hashAndCompressData(args);
|
|
364
|
-
messageHandler.sendEvent({
|
|
365
|
-
id: channelId,
|
|
366
|
-
topic: args.method,
|
|
367
|
-
data: compressedMessage
|
|
368
|
-
});
|
|
369
|
-
};
|
|
370
|
-
const destroy = async () => {
|
|
371
|
-
channelManager.destroy();
|
|
372
|
-
messageHandler.cleanup();
|
|
373
|
-
iframe.remove();
|
|
374
|
-
};
|
|
375
|
-
const waitForSetup = postConnectionSetup({
|
|
376
|
-
config,
|
|
377
|
-
messageHandler,
|
|
378
|
-
lifecycleManager
|
|
379
|
-
});
|
|
380
|
-
return {
|
|
381
|
-
config,
|
|
382
|
-
waitForConnection: lifecycleManager.isConnected,
|
|
383
|
-
waitForSetup,
|
|
384
|
-
request,
|
|
385
|
-
listenerRequest,
|
|
386
|
-
destroy
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
async function postConnectionSetup({
|
|
390
|
-
config,
|
|
391
|
-
messageHandler,
|
|
392
|
-
lifecycleManager
|
|
393
|
-
}) {
|
|
394
|
-
await lifecycleManager.isConnected;
|
|
395
|
-
const pushCss = async () => {
|
|
396
|
-
const cssLink = config.metadata.css;
|
|
397
|
-
if (!cssLink) return;
|
|
398
|
-
messageHandler.sendEvent({
|
|
399
|
-
clientLifecycle: "modal-css",
|
|
400
|
-
data: { cssLink }
|
|
401
|
-
});
|
|
402
|
-
};
|
|
403
|
-
const pushBackup = async () => {
|
|
404
|
-
if (typeof window === "undefined") return;
|
|
405
|
-
const backup = window.localStorage.getItem(BACKUP_KEY);
|
|
406
|
-
if (!backup) return;
|
|
407
|
-
messageHandler.sendEvent({
|
|
408
|
-
clientLifecycle: "restore-backup",
|
|
409
|
-
data: { backup }
|
|
410
|
-
});
|
|
411
|
-
};
|
|
412
|
-
await Promise.all([pushCss(), pushBackup()]);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
exports.FrakRpcError = FrakRpcError; exports.ClientNotFound = ClientNotFound; exports.RpcErrorCodes = RpcErrorCodes; exports.Deferred = Deferred; exports.hashAndCompressData = hashAndCompressData; exports.compressJson = compressJson; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.decompressJson = decompressJson; exports.baseIframeProps = baseIframeProps; exports.createIframe = createIframe; exports.createIFrameNexusClient = createIFrameNexusClient;
|
package/dist/chunk-AANA3LEO.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/constants/productTypes.ts
|
|
2
|
-
var productTypes = {
|
|
3
|
-
// content type
|
|
4
|
-
dapp: 1,
|
|
5
|
-
press: 2,
|
|
6
|
-
// feature type
|
|
7
|
-
referral: 30
|
|
8
|
-
};
|
|
9
|
-
var productTypesMask = Object.entries(
|
|
10
|
-
productTypes
|
|
11
|
-
).reduce(
|
|
12
|
-
(acc, [key, value]) => {
|
|
13
|
-
acc[key] = BigInt(1) << BigInt(value);
|
|
14
|
-
return acc;
|
|
15
|
-
},
|
|
16
|
-
{}
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.productTypes = productTypes; exports.productTypesMask = productTypesMask;
|
package/dist/chunk-ETV4XYOV.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
package/dist/chunk-IH3QWPWT.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
productTypes
|
|
3
|
-
} from "./chunk-22T2NHQK.js";
|
|
4
|
-
|
|
5
|
-
// src/core/interactions/pressEncoder.ts
|
|
6
|
-
import { concatHex, pad, toHex } from "viem";
|
|
7
|
-
var PressActionsSelector = {
|
|
8
|
-
OpenArticle: "0xc0a24ffb",
|
|
9
|
-
ReadArticle: "0xd5bd0fbe"
|
|
10
|
-
};
|
|
11
|
-
function openArticle({ articleId }) {
|
|
12
|
-
const interactionData = concatHex([
|
|
13
|
-
PressActionsSelector.OpenArticle,
|
|
14
|
-
pad(articleId, { size: 32 })
|
|
15
|
-
]);
|
|
16
|
-
return {
|
|
17
|
-
handlerTypeDenominator: toHex(productTypes.press),
|
|
18
|
-
interactionData
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function readArticle({ articleId }) {
|
|
22
|
-
const interactionData = concatHex([
|
|
23
|
-
PressActionsSelector.ReadArticle,
|
|
24
|
-
pad(articleId, { size: 32 })
|
|
25
|
-
]);
|
|
26
|
-
return {
|
|
27
|
-
handlerTypeDenominator: toHex(productTypes.press),
|
|
28
|
-
interactionData
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
var PressInteractionEncoder = {
|
|
32
|
-
openArticle,
|
|
33
|
-
readArticle
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// src/core/interactions/referralEncoder.ts
|
|
37
|
-
import { concatHex as concatHex2, pad as pad2, toHex as toHex2 } from "viem";
|
|
38
|
-
var ReferralActionsSelector = {
|
|
39
|
-
CreateLink: "0xb2c0f17c",
|
|
40
|
-
Referred: "0x010cc3b9"
|
|
41
|
-
};
|
|
42
|
-
function createLink() {
|
|
43
|
-
const interactionData = concatHex2([
|
|
44
|
-
ReferralActionsSelector.CreateLink,
|
|
45
|
-
"0x"
|
|
46
|
-
]);
|
|
47
|
-
return {
|
|
48
|
-
handlerTypeDenominator: toHex2(productTypes.referral),
|
|
49
|
-
interactionData
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function referred({ referrer }) {
|
|
53
|
-
const interactionData = concatHex2([
|
|
54
|
-
ReferralActionsSelector.Referred,
|
|
55
|
-
pad2(referrer, { size: 32 })
|
|
56
|
-
]);
|
|
57
|
-
return {
|
|
58
|
-
handlerTypeDenominator: toHex2(productTypes.referral),
|
|
59
|
-
interactionData
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
var ReferralInteractionEncoder = {
|
|
63
|
-
createLink,
|
|
64
|
-
referred
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
PressActionsSelector,
|
|
69
|
-
PressInteractionEncoder,
|
|
70
|
-
ReferralActionsSelector,
|
|
71
|
-
ReferralInteractionEncoder
|
|
72
|
-
};
|
package/dist/chunk-PKBMQBKP.js
DELETED
|
@@ -1,7 +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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
__publicField
|
|
7
|
-
};
|
package/dist/chunk-PURWUKEM.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkAANA3LEOcjs = require('./chunk-AANA3LEO.cjs');
|
|
4
|
-
|
|
5
|
-
// src/core/interactions/pressEncoder.ts
|
|
6
|
-
var _viem = require('viem');
|
|
7
|
-
var PressActionsSelector = {
|
|
8
|
-
OpenArticle: "0xc0a24ffb",
|
|
9
|
-
ReadArticle: "0xd5bd0fbe"
|
|
10
|
-
};
|
|
11
|
-
function openArticle({ articleId }) {
|
|
12
|
-
const interactionData = _viem.concatHex.call(void 0, [
|
|
13
|
-
PressActionsSelector.OpenArticle,
|
|
14
|
-
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
15
|
-
]);
|
|
16
|
-
return {
|
|
17
|
-
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkAANA3LEOcjs.productTypes.press),
|
|
18
|
-
interactionData
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function readArticle({ articleId }) {
|
|
22
|
-
const interactionData = _viem.concatHex.call(void 0, [
|
|
23
|
-
PressActionsSelector.ReadArticle,
|
|
24
|
-
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
25
|
-
]);
|
|
26
|
-
return {
|
|
27
|
-
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkAANA3LEOcjs.productTypes.press),
|
|
28
|
-
interactionData
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
var PressInteractionEncoder = {
|
|
32
|
-
openArticle,
|
|
33
|
-
readArticle
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// src/core/interactions/referralEncoder.ts
|
|
37
|
-
|
|
38
|
-
var ReferralActionsSelector = {
|
|
39
|
-
CreateLink: "0xb2c0f17c",
|
|
40
|
-
Referred: "0x010cc3b9"
|
|
41
|
-
};
|
|
42
|
-
function createLink() {
|
|
43
|
-
const interactionData = _viem.concatHex.call(void 0, [
|
|
44
|
-
ReferralActionsSelector.CreateLink,
|
|
45
|
-
"0x"
|
|
46
|
-
]);
|
|
47
|
-
return {
|
|
48
|
-
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkAANA3LEOcjs.productTypes.referral),
|
|
49
|
-
interactionData
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function referred({ referrer }) {
|
|
53
|
-
const interactionData = _viem.concatHex.call(void 0, [
|
|
54
|
-
ReferralActionsSelector.Referred,
|
|
55
|
-
_viem.pad.call(void 0, referrer, { size: 32 })
|
|
56
|
-
]);
|
|
57
|
-
return {
|
|
58
|
-
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkAANA3LEOcjs.productTypes.referral),
|
|
59
|
-
interactionData
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
var ReferralInteractionEncoder = {
|
|
63
|
-
createLink,
|
|
64
|
-
referred
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exports.PressActionsSelector = PressActionsSelector; exports.PressInteractionEncoder = PressInteractionEncoder; exports.ReferralActionsSelector = ReferralActionsSelector; exports.ReferralInteractionEncoder = ReferralInteractionEncoder;
|
package/dist/chunk-S223FMEJ.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// src/core/actions/watchWalletStatus.ts
|
|
2
|
-
function watchWalletStatus(client, callback) {
|
|
3
|
-
return client.listenerRequest(
|
|
4
|
-
{
|
|
5
|
-
method: "frak_listenToWalletStatus"
|
|
6
|
-
},
|
|
7
|
-
callback
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// src/core/utils/computeProductId.ts
|
|
12
|
-
import { keccak256, toHex } from "viem";
|
|
13
|
-
function computeProductId({ domain }) {
|
|
14
|
-
return keccak256(toHex(domain));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/core/actions/sendInteraction.ts
|
|
18
|
-
async function sendInteraction(client, { productId, interaction, validation }) {
|
|
19
|
-
const pId = productId ?? computeProductId(client.config);
|
|
20
|
-
return await client.request({
|
|
21
|
-
method: "frak_sendInteraction",
|
|
22
|
-
params: [pId, interaction, validation]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/core/actions/displayModal.ts
|
|
27
|
-
async function displayModal(client, { steps, metadata }) {
|
|
28
|
-
return await client.request({
|
|
29
|
-
method: "frak_displayModal",
|
|
30
|
-
params: [steps, client.config.metadata.name, metadata]
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/core/actions/openSso.ts
|
|
35
|
-
async function openSso(client, args) {
|
|
36
|
-
const { metadata } = client.config;
|
|
37
|
-
await client.request({
|
|
38
|
-
method: "frak_sso",
|
|
39
|
-
params: [args, metadata.name, metadata.css]
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/core/actions/wrapper/siweAuthenticate.ts
|
|
44
|
-
import { generateSiweNonce } from "viem/siwe";
|
|
45
|
-
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
46
|
-
const realStatement = siwe?.statement ?? `I confirm that I want to use my Nexus wallet on: ${client.config.metadata.name}`;
|
|
47
|
-
const builtSiwe = {
|
|
48
|
-
...siwe,
|
|
49
|
-
statement: realStatement,
|
|
50
|
-
nonce: siwe?.nonce ?? generateSiweNonce(),
|
|
51
|
-
uri: siwe?.uri ?? `https://${client.config.domain}`,
|
|
52
|
-
version: siwe?.version ?? "1",
|
|
53
|
-
domain: client.config.domain
|
|
54
|
-
};
|
|
55
|
-
const result = await displayModal(client, {
|
|
56
|
-
metadata,
|
|
57
|
-
steps: {
|
|
58
|
-
login: {},
|
|
59
|
-
siweAuthenticate: {
|
|
60
|
-
siwe: builtSiwe
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return result.siweAuthenticate;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/core/actions/wrapper/sendTransaction.ts
|
|
68
|
-
async function sendTransaction(client, { tx, metadata }) {
|
|
69
|
-
const result = await displayModal(client, {
|
|
70
|
-
metadata,
|
|
71
|
-
steps: {
|
|
72
|
-
login: {},
|
|
73
|
-
sendTransaction: { tx }
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return result.sendTransaction;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export {
|
|
80
|
-
watchWalletStatus,
|
|
81
|
-
sendInteraction,
|
|
82
|
-
displayModal,
|
|
83
|
-
openSso,
|
|
84
|
-
siweAuthenticate,
|
|
85
|
-
sendTransaction
|
|
86
|
-
};
|