@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,6 +1,6 @@
1
1
  import {
2
2
  createIFrameNexusClient
3
- } from "../chunk-ZZ7LUFNV.js";
3
+ } from "../chunk-VVF4NKYR.js";
4
4
  import {
5
5
  displayModal,
6
6
  openSso,
@@ -8,17 +8,17 @@ import {
8
8
  sendInteraction,
9
9
  sendTransaction,
10
10
  siweAuthenticate,
11
- walletStatus
12
- } from "../chunk-MDGMJ6EQ.js";
11
+ watchWalletStatus
12
+ } from "../chunk-4Q2OHGWX.js";
13
13
  import {
14
14
  ClientNotFound,
15
15
  FrakContextManager,
16
16
  FrakRpcError,
17
17
  RpcErrorCodes,
18
18
  baseIframeProps
19
- } from "../chunk-ZRPCX25Q.js";
20
- import "../chunk-TIKEZMSD.js";
21
- import "../chunk-HY6YATLS.js";
19
+ } from "../chunk-ZQSA2VQ4.js";
20
+ import "../chunk-P4QEVLVV.js";
21
+ import "../chunk-H3T2GAEC.js";
22
22
 
23
23
  // src/react/provider/NexusConfigProvider.ts
24
24
  import { createContext, createElement } from "react";
@@ -87,7 +87,7 @@ function useWalletStatus() {
87
87
  if (!client) {
88
88
  throw new ClientNotFound();
89
89
  }
90
- return walletStatus(client, newStatusUpdated);
90
+ return watchWalletStatus(client, newStatusUpdated);
91
91
  },
92
92
  enabled: !!client
93
93
  });
@@ -207,7 +207,7 @@ function useReferralInteraction({
207
207
  } = {}) {
208
208
  const client = useNexusClient();
209
209
  const { frakContext } = useFrakContext();
210
- const { data: walletStatus2 } = useWalletStatus();
210
+ const { data: walletStatus } = useWalletStatus();
211
211
  const {
212
212
  data: referralState,
213
213
  error,
@@ -219,7 +219,7 @@ function useReferralInteraction({
219
219
  "nexus-sdk",
220
220
  "auto-referral-interaction",
221
221
  frakContext?.r ?? "no-referrer",
222
- walletStatus2?.key ?? "no-wallet-status",
222
+ walletStatus?.key ?? "no-wallet-status",
223
223
  productId ?? "no-product-id"
224
224
  ],
225
225
  queryFn: () => {
@@ -227,14 +227,14 @@ function useReferralInteraction({
227
227
  throw new ClientNotFound();
228
228
  }
229
229
  return processReferral(client, {
230
- walletStatus: walletStatus2,
230
+ walletStatus,
231
231
  frakContext,
232
232
  modalConfig,
233
233
  productId,
234
234
  options
235
235
  });
236
236
  },
237
- enabled: !!walletStatus2
237
+ enabled: !!walletStatus
238
238
  });
239
239
  return useMemo3(() => {
240
240
  if (status === "pending") return "processing";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.21",
14
+ "version": "0.0.23",
15
15
  "description": "Frak 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": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -28,20 +28,11 @@
28
28
  "license": "GNU GPL 3.0",
29
29
  "sideEffects": false,
30
30
  "private": false,
31
- "main": "dist/index.cjs",
32
- "module": "dist/index.js",
33
- "types": "dist/index.d.ts",
34
- "typings": "dist/index.d.ts",
35
31
  "type": "module",
36
32
  "files": [
37
33
  "/dist"
38
34
  ],
39
35
  "exports": {
40
- ".": {
41
- "types": "./dist/index.d.ts",
42
- "import": "./dist/index.js",
43
- "default": "./dist/index.cjs"
44
- },
45
36
  "./core": {
46
37
  "types": "./dist/core/index.d.ts",
47
38
  "import": "./dist/core/index.js",
@@ -83,7 +74,7 @@
83
74
  "devDependencies": {
84
75
  "@tanstack/react-query": ">=5.59.15",
85
76
  "@types/node": "^22",
86
- "tsup": "^8.3.0",
77
+ "tsup": "^8.3.4",
87
78
  "typescript": "^5"
88
79
  }
89
80
  }
@@ -1,294 +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; }
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 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 (!_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 url = _nullishCoalesce(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
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
- 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,53 +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
- // src/core/constants/productTypes.ts
6
- var productTypes = {
7
- // content type
8
- dapp: 1,
9
- press: 2,
10
- webshop: 3,
11
- // feature type
12
- referral: 30,
13
- purchase: 31
14
- };
15
- var productTypesMask = Object.entries(
16
- productTypes
17
- ).reduce(
18
- (acc, [key, value]) => {
19
- acc[key] = BigInt(1) << BigInt(value);
20
- return acc;
21
- },
22
- {}
23
- );
24
-
25
- // src/core/constants/interactionTypes.ts
26
- var interactionTypes = {
27
- press: {
28
- openArticle: "0xc0a24ffb",
29
- readArticle: "0xd5bd0fbe"
30
- },
31
- dapp: {
32
- proofVerifiableStorageUpdate: "0x2ab2aeef",
33
- callableVerifiableStorageUpdate: "0xa07da986"
34
- },
35
- webshop: {
36
- open: "0xb311798f"
37
- },
38
- referral: {
39
- referred: "0x010cc3b9",
40
- createLink: "0xb2c0f17c"
41
- },
42
- purchase: {
43
- started: "0xd87e90c3",
44
- completed: "0x8403aeb4"
45
- }
46
- };
47
-
48
- export {
49
- __publicField,
50
- productTypes,
51
- productTypesMask,
52
- interactionTypes
53
- };
@@ -1,53 +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
- // src/core/constants/productTypes.ts
6
- var productTypes = {
7
- // content type
8
- dapp: 1,
9
- press: 2,
10
- webshop: 3,
11
- // feature type
12
- referral: 30,
13
- purchase: 31
14
- };
15
- var productTypesMask = Object.entries(
16
- productTypes
17
- ).reduce(
18
- (acc, [key, value]) => {
19
- acc[key] = BigInt(1) << BigInt(value);
20
- return acc;
21
- },
22
- {}
23
- );
24
-
25
- // src/core/constants/interactionTypes.ts
26
- var interactionTypes = {
27
- press: {
28
- openArticle: "0xc0a24ffb",
29
- readArticle: "0xd5bd0fbe"
30
- },
31
- dapp: {
32
- proofVerifiableStorageUpdate: "0x2ab2aeef",
33
- callableVerifiableStorageUpdate: "0xa07da986"
34
- },
35
- webshop: {
36
- open: "0xb311798f"
37
- },
38
- referral: {
39
- referred: "0x010cc3b9",
40
- createLink: "0xb2c0f17c"
41
- },
42
- purchase: {
43
- started: "0xd87e90c3",
44
- completed: "0x8403aeb4"
45
- }
46
- };
47
-
48
-
49
-
50
-
51
-
52
-
53
- exports.__publicField = __publicField; exports.productTypes = productTypes; exports.productTypesMask = productTypesMask; exports.interactionTypes = interactionTypes;