@frak-labs/nexus-sdk 0.0.20 → 0.0.22

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 (38) hide show
  1. package/dist/{client-ALy_TEwJ.d.ts → FrakContext-CDVlUN75.d.ts} +9 -1
  2. package/dist/{client-DaEox5q4.d.cts → FrakContext-DBdWC7ls.d.cts} +9 -1
  3. package/dist/bundle/bundle.js +3 -3
  4. package/dist/{chunk-QRECYKIR.cjs → chunk-4CWA7EWX.cjs} +68 -48
  5. package/dist/{chunk-A3XYA7S7.cjs → chunk-4OJ2NPAS.cjs} +15 -15
  6. package/dist/chunk-F3F4BCGV.cjs +860 -0
  7. package/dist/chunk-H3T2GAEC.js +79 -0
  8. package/dist/{chunk-TIKEZMSD.js → chunk-P4QEVLVV.js} +1 -1
  9. package/dist/{chunk-6LI5YIZB.js → chunk-Q3SIIAX2.js} +60 -40
  10. package/dist/chunk-QSXZKZJA.cjs +79 -0
  11. package/dist/{chunk-2SDBW6QC.cjs → chunk-QYOOKB34.cjs} +20 -18
  12. package/dist/{chunk-54MUKMZK.js → chunk-VVF4NKYR.js} +3 -1
  13. package/dist/chunk-ZQSA2VQ4.js +860 -0
  14. package/dist/core/actions/index.cjs +5 -5
  15. package/dist/core/actions/index.d.cts +6 -21
  16. package/dist/core/actions/index.d.ts +6 -21
  17. package/dist/core/actions/index.js +4 -4
  18. package/dist/core/index.cjs +4 -4
  19. package/dist/core/index.d.cts +8 -7
  20. package/dist/core/index.d.ts +8 -7
  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-BWSIamn2.d.cts +53 -0
  25. package/dist/processReferral-CFyGAENf.d.ts +53 -0
  26. package/dist/react/index.cjs +31 -28
  27. package/dist/react/index.d.cts +8 -3
  28. package/dist/react/index.d.ts +8 -3
  29. package/dist/react/index.js +10 -7
  30. package/package.json +2 -11
  31. package/dist/FrakContext-LbQht1ep.d.cts +0 -10
  32. package/dist/FrakContext-LbQht1ep.d.ts +0 -10
  33. package/dist/chunk-7K4L7VQC.js +0 -288
  34. package/dist/chunk-HY6YATLS.js +0 -53
  35. package/dist/chunk-UFJ7W6CQ.cjs +0 -53
  36. package/dist/chunk-YDZBXUC4.cjs +0 -288
  37. package/dist/sendTransaction-BOd-pvXr.d.ts +0 -30
  38. package/dist/sendTransaction-MhdJPTWd.d.cts +0 -30
@@ -1,288 +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 _chunkUFJ7W6CQcjs = require('./chunk-UFJ7W6CQ.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
- serverErrorForInteractionDelegation: -32006
38
- };
39
-
40
- // src/core/utils/Deferred.ts
41
- var Deferred = class {
42
- constructor() {
43
- _chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_promise");
44
- _chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_resolve");
45
- _chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "_reject");
46
- _chunkUFJ7W6CQcjs.__publicField.call(void 0, this, "resolve", (value) => {
47
- _optionalChain([this, 'access', _2 => _2._resolve, 'optionalCall', _3 => _3(value)]);
48
- });
49
- _chunkUFJ7W6CQcjs.__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, 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
- _optionalChain([iframe, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("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
- var _viem = require('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 (!_optionalChain([context, 'optionalAccess', _11 => _11.r])) return;
206
- try {
207
- const bytes = _viem.hexToBytes.call(void 0, 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: _viem.bytesToHex.call(void 0, 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;
239
- const compressedContext = compress(mergedContext);
240
- if (!compressedContext) return;
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,
252
- context
253
- }) {
254
- if (!_optionalChain([window, 'access', _12 => _12.location, 'optionalAccess', _13 => _13.href]) || typeof window === "undefined") {
255
- console.error("No window found, can't update context");
256
- return;
257
- }
258
- const newUrl = update({
259
- url,
260
- context
261
- });
262
- if (!newUrl) return;
263
- window.history.replaceState(null, "", newUrl.toString());
264
- }
265
- var FrakContextManager = {
266
- compress,
267
- decompress,
268
- parse,
269
- update,
270
- remove,
271
- replaceUrl
272
- };
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
- exports.FrakRpcError = FrakRpcError; exports.InternalError = InternalError; 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.changeIframeVisibility = changeIframeVisibility; exports.FrakContextManager = FrakContextManager;
@@ -1,30 +0,0 @@
1
- import { g as SiweAuthenticationParams, b as ModalRpcMetadata, a as NexusClient, h as SiweAuthenticateReturnType, j as SendTransactionModalStepType, k as SendTransactionReturnType } from './client-ALy_TEwJ.js';
2
-
3
- /**
4
- * Partial SIWE params, since we can rebuild them from the SDK if they are empty
5
- */
6
- type SiweAuthenticateModalParams = {
7
- siwe?: Partial<SiweAuthenticationParams>;
8
- metadata?: ModalRpcMetadata;
9
- };
10
- /**
11
- * Function used to launch a siwe authentication
12
- * @param client
13
- * @param siwe
14
- * @param context
15
- */
16
- declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
17
-
18
- type SendTransactionParams = {
19
- tx: SendTransactionModalStepType["params"]["tx"];
20
- metadata?: ModalRpcMetadata;
21
- };
22
- /**
23
- * Function used to send a user transaction
24
- * @param client
25
- * @param tx
26
- * @param context
27
- */
28
- declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
29
-
30
- export { type SendTransactionParams as S, type SiweAuthenticateModalParams as a, sendTransaction as b, siweAuthenticate as s };
@@ -1,30 +0,0 @@
1
- import { g as SiweAuthenticationParams, b as ModalRpcMetadata, a as NexusClient, h as SiweAuthenticateReturnType, j as SendTransactionModalStepType, k as SendTransactionReturnType } from './client-DaEox5q4.cjs';
2
-
3
- /**
4
- * Partial SIWE params, since we can rebuild them from the SDK if they are empty
5
- */
6
- type SiweAuthenticateModalParams = {
7
- siwe?: Partial<SiweAuthenticationParams>;
8
- metadata?: ModalRpcMetadata;
9
- };
10
- /**
11
- * Function used to launch a siwe authentication
12
- * @param client
13
- * @param siwe
14
- * @param context
15
- */
16
- declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
17
-
18
- type SendTransactionParams = {
19
- tx: SendTransactionModalStepType["params"]["tx"];
20
- metadata?: ModalRpcMetadata;
21
- };
22
- /**
23
- * Function used to send a user transaction
24
- * @param client
25
- * @param tx
26
- * @param context
27
- */
28
- declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
29
-
30
- export { type SendTransactionParams as S, type SiweAuthenticateModalParams as a, sendTransaction as b, siweAuthenticate as s };