@frak-labs/nexus-sdk 0.0.21 → 0.0.23

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 (34) hide show
  1. package/dist/{FrakContext-p0Jtv9gl.d.ts → FrakContext-CDVlUN75.d.ts} +1 -0
  2. package/dist/{FrakContext-BsezWx2F.d.cts → FrakContext-DBdWC7ls.d.cts} +1 -0
  3. package/dist/bundle/bundle.js +4 -4
  4. package/dist/{chunk-A3XYA7S7.cjs → chunk-4OJ2NPAS.cjs} +15 -15
  5. package/dist/{chunk-MDGMJ6EQ.js → chunk-4Q2OHGWX.js} +134 -25
  6. package/dist/{chunk-BSCR57ZI.cjs → chunk-BHZDDGW6.cjs} +148 -39
  7. package/dist/chunk-F3F4BCGV.cjs +860 -0
  8. package/dist/chunk-H3T2GAEC.js +79 -0
  9. package/dist/{chunk-TIKEZMSD.js → chunk-P4QEVLVV.js} +1 -1
  10. package/dist/chunk-QSXZKZJA.cjs +79 -0
  11. package/dist/{chunk-WXNW7ZMU.cjs → chunk-QYOOKB34.cjs} +20 -18
  12. package/dist/{chunk-ZZ7LUFNV.js → chunk-VVF4NKYR.js} +3 -1
  13. package/dist/chunk-ZQSA2VQ4.js +860 -0
  14. package/dist/core/actions/index.cjs +7 -5
  15. package/dist/core/actions/index.d.cts +45 -6
  16. package/dist/core/actions/index.d.ts +45 -6
  17. package/dist/core/actions/index.js +8 -6
  18. package/dist/core/index.cjs +4 -4
  19. package/dist/core/index.d.cts +5 -3
  20. package/dist/core/index.d.ts +5 -3
  21. package/dist/core/index.js +3 -3
  22. package/dist/core/interactions/index.cjs +3 -3
  23. package/dist/core/interactions/index.js +2 -2
  24. package/dist/{processReferral-YbCg90hu.d.cts → processReferral-BWSIamn2.d.cts} +1 -1
  25. package/dist/{processReferral-t3gUNwJu.d.ts → processReferral-CFyGAENf.d.ts} +1 -1
  26. package/dist/react/index.cjs +30 -30
  27. package/dist/react/index.d.cts +5 -2
  28. package/dist/react/index.d.ts +5 -2
  29. package/dist/react/index.js +11 -11
  30. package/package.json +2 -11
  31. package/dist/chunk-E527CMMJ.cjs +0 -294
  32. package/dist/chunk-HY6YATLS.js +0 -53
  33. package/dist/chunk-UFJ7W6CQ.cjs +0 -53
  34. package/dist/chunk-ZRPCX25Q.js +0 -294
@@ -1,294 +0,0 @@
1
- import {
2
- __publicField
3
- } from "./chunk-HY6YATLS.js";
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
- serverErrorForInteractionDelegation: -32006
38
- };
39
-
40
- // src/core/utils/Deferred.ts
41
- var Deferred = class {
42
- constructor() {
43
- __publicField(this, "_promise");
44
- __publicField(this, "_resolve");
45
- __publicField(this, "_reject");
46
- __publicField(this, "resolve", (value) => {
47
- this._resolve?.(value);
48
- });
49
- __publicField(this, "reject", (reason) => {
50
- this._reject?.(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
- import { compressToBase64 } from "async-lz-string";
64
- import { sha256 } from "js-sha256";
65
- async function hashAndCompressData(data) {
66
- const validationHash = sha256(JSON.stringify(data));
67
- const hashProtectedData = {
68
- ...data,
69
- validationHash
70
- };
71
- const compressed = await compressJson(hashProtectedData);
72
- const compressedHash = sha256(compressed);
73
- return {
74
- compressed,
75
- compressedHash
76
- };
77
- }
78
- async function compressJson(data) {
79
- return compressToBase64(JSON.stringify(data));
80
- }
81
-
82
- // src/core/utils/compression/decompress.ts
83
- import { decompressFromBase64 } from "async-lz-string";
84
- import { sha256 as sha2562 } from "js-sha256";
85
- async function decompressDataAndCheckHash(compressedData) {
86
- if (!(compressedData?.compressed && compressedData?.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 (!parsedData?.validationHash) {
102
- throw new FrakRpcError(
103
- RpcErrorCodes.corruptedResponse,
104
- "Missing validation hash"
105
- );
106
- }
107
- const expectedCompressedHash = sha2562(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 = sha2562(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 decompressFromBase64(data);
126
- try {
127
- return JSON.parse(decompressed);
128
- } catch (e) {
129
- console.error("Invalid compressed data", { e, decompressed });
130
- return null;
131
- }
132
- }
133
-
134
- // src/core/utils/iframeHelper.ts
135
- var baseIframeProps = {
136
- id: "nexus-wallet",
137
- name: "nexus-wallet",
138
- allow: "publickey-credentials-get *; clipboard-write; web-share *",
139
- style: {
140
- width: "0",
141
- height: "0",
142
- border: "0",
143
- position: "absolute",
144
- zIndex: 1e3,
145
- top: "-1000px",
146
- left: "-1000px"
147
- }
148
- };
149
- function createIframe({
150
- walletBaseUrl
151
- }) {
152
- const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
153
- if (alreadyCreatedIFrame) {
154
- return Promise.resolve(alreadyCreatedIFrame);
155
- }
156
- const iframe = document.createElement("iframe");
157
- iframe.id = baseIframeProps.id;
158
- iframe.name = baseIframeProps.name;
159
- iframe.allow = baseIframeProps.allow;
160
- iframe.style.zIndex = baseIframeProps.style.zIndex.toString();
161
- changeIframeVisibility({ iframe, isVisible: false });
162
- document.body.appendChild(iframe);
163
- return new Promise((resolve) => {
164
- iframe?.addEventListener("load", () => resolve(iframe));
165
- iframe.src = `${walletBaseUrl}/listener`;
166
- });
167
- }
168
- function changeIframeVisibility({
169
- iframe,
170
- isVisible
171
- }) {
172
- if (!isVisible) {
173
- iframe.style.width = "0";
174
- iframe.style.height = "0";
175
- iframe.style.border = "0";
176
- iframe.style.position = "fixed";
177
- iframe.style.top = "-1000px";
178
- iframe.style.left = "-1000px";
179
- return;
180
- }
181
- iframe.style.position = "fixed";
182
- iframe.style.top = "0";
183
- iframe.style.left = "0";
184
- iframe.style.width = "100%";
185
- iframe.style.height = "100%";
186
- iframe.style.pointerEvents = "auto";
187
- }
188
-
189
- // src/core/utils/FrakContext.ts
190
- import { bytesToHex, hexToBytes } from "viem";
191
- var contextKey = "fCtx";
192
- function base64url_encode(buffer) {
193
- return btoa(Array.from(buffer, (b) => String.fromCharCode(b)).join("")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
194
- }
195
- function base64url_decode(value) {
196
- const m = value.length % 4;
197
- return Uint8Array.from(
198
- atob(
199
- value.replace(/-/g, "+").replace(/_/g, "/").padEnd(value.length + (m === 0 ? 0 : 4 - m), "=")
200
- ),
201
- (c) => c.charCodeAt(0)
202
- );
203
- }
204
- function compress(context) {
205
- if (!context?.r) return;
206
- try {
207
- const bytes = hexToBytes(context.r);
208
- return base64url_encode(bytes);
209
- } catch (e) {
210
- console.error("Error compressing Frak context", { e, context });
211
- }
212
- return void 0;
213
- }
214
- function decompress(context) {
215
- if (!context || context.length === 0) return;
216
- try {
217
- const bytes = base64url_decode(context);
218
- return { r: bytesToHex(bytes, { size: 20 }) };
219
- } catch (e) {
220
- console.error("Error decompressing Frak context", { e, context });
221
- }
222
- return void 0;
223
- }
224
- function parse({ url }) {
225
- if (!url) return null;
226
- const urlObj = new URL(url);
227
- const frakContext = urlObj.searchParams.get(contextKey);
228
- if (!frakContext) return null;
229
- return decompress(frakContext);
230
- }
231
- function update({
232
- url,
233
- context
234
- }) {
235
- if (!url) return null;
236
- const currentContext = parse({ url });
237
- const mergedContext = currentContext ? { ...currentContext, ...context } : context;
238
- if (!mergedContext.r) return null;
239
- const compressedContext = compress(mergedContext);
240
- if (!compressedContext) return null;
241
- const urlObj = new URL(url);
242
- urlObj.searchParams.set(contextKey, compressedContext);
243
- return urlObj.toString();
244
- }
245
- function remove(url) {
246
- const urlObj = new URL(url);
247
- urlObj.searchParams.delete(contextKey);
248
- return urlObj.toString();
249
- }
250
- function replaceUrl({
251
- url: baseUrl,
252
- context
253
- }) {
254
- if (!window.location?.href || typeof window === "undefined") {
255
- console.error("No window found, can't update context");
256
- return;
257
- }
258
- const url = baseUrl ?? window.location.href;
259
- let newUrl;
260
- if (context !== null) {
261
- newUrl = update({
262
- url,
263
- context
264
- });
265
- } else {
266
- newUrl = remove(url);
267
- }
268
- if (!newUrl) return;
269
- window.history.replaceState(null, "", newUrl.toString());
270
- }
271
- var FrakContextManager = {
272
- compress,
273
- decompress,
274
- parse,
275
- update,
276
- remove,
277
- replaceUrl
278
- };
279
-
280
- export {
281
- FrakRpcError,
282
- InternalError,
283
- ClientNotFound,
284
- RpcErrorCodes,
285
- Deferred,
286
- hashAndCompressData,
287
- compressJson,
288
- decompressDataAndCheckHash,
289
- decompressJson,
290
- baseIframeProps,
291
- createIframe,
292
- changeIframeVisibility,
293
- FrakContextManager
294
- };