@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,12 +1,12 @@
1
1
  import * as react from 'react';
2
2
  import { PropsWithChildren, CSSProperties, ReactNode } from 'react';
3
- import { N as NexusWalletSdkConfig, a as NexusClient, W as WalletStatusReturnType, k as SendTransactionReturnType, h as SiweAuthenticateReturnType, D as DisplayModalParamsType, M as ModalStepTypes, d as ModalRpcStepsResultType, O as OpenSsoParamsType } from '../client-ALy_TEwJ.js';
3
+ import { N as NexusWalletSdkConfig, a as NexusClient, W as WalletStatusReturnType, k as SendTransactionReturnType, h as SiweAuthenticateReturnType, D as DisplayModalParamsType, M as ModalStepTypes, d as ModalRpcStepsResultType, O as OpenSsoParamsType } from '../FrakContext-CDVlUN75.js';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { UseMutationOptions } from '@tanstack/react-query';
6
6
  import * as viem from 'viem';
7
7
  import { Hex } from 'viem';
8
8
  import { F as FrakRpcError } from '../error-Dflr3G5x.js';
9
- import { S as SendTransactionParams, a as SiweAuthenticateModalParams } from '../sendTransaction-BOd-pvXr.js';
9
+ import { S as SendTransactionParams, a as SiweAuthenticateModalParams, P as ProcessReferralOptions } from '../processReferral-CFyGAENf.js';
10
10
  import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-BngPoHA0.js';
11
11
  import 'viem/chains';
12
12
  import 'viem/siwe';
@@ -19,6 +19,7 @@ declare const NexusConfigContext: react.Context<Readonly<{
19
19
  metadata: {
20
20
  name: string;
21
21
  css?: string;
22
+ buttonShare?: string;
22
23
  };
23
24
  domain: string;
24
25
  }> | undefined>;
@@ -40,6 +41,7 @@ declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigPr
40
41
  metadata: {
41
42
  name: string;
42
43
  css?: string;
44
+ buttonShare?: string;
43
45
  };
44
46
  domain: string;
45
47
  }> | undefined>>;
@@ -75,6 +77,7 @@ declare function useNexusConfig(): Readonly<{
75
77
  metadata: {
76
78
  name: string;
77
79
  css?: string;
80
+ buttonShare?: string;
78
81
  };
79
82
  domain: string;
80
83
  }>;
@@ -117,10 +120,12 @@ declare function useSiweAuthenticate({ mutations, }?: UseSiweAuthenticateParams)
117
120
  * -> And automatically set the referral context in the url
118
121
  * @param productId
119
122
  * @param modalConfig
123
+ * @param options
120
124
  */
121
- declare function useReferralInteraction({ productId, modalConfig, }?: {
125
+ declare function useReferralInteraction({ productId, modalConfig, options, }?: {
122
126
  productId?: Hex;
123
127
  modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
128
+ options?: ProcessReferralOptions;
124
129
  }): Error | ("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral");
125
130
 
126
131
  type MutationOptions$2 = Omit<UseMutationOptions<SendInteractionReturnType, FrakRpcError, SendInteractionParamsType>, "mutationFn" | "mutationKey">;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createIFrameNexusClient
3
- } from "../chunk-54MUKMZK.js";
3
+ } from "../chunk-VVF4NKYR.js";
4
4
  import {
5
5
  displayModal,
6
6
  openSso,
@@ -9,16 +9,16 @@ import {
9
9
  sendTransaction,
10
10
  siweAuthenticate,
11
11
  walletStatus
12
- } from "../chunk-6LI5YIZB.js";
12
+ } from "../chunk-Q3SIIAX2.js";
13
13
  import {
14
14
  ClientNotFound,
15
15
  FrakContextManager,
16
16
  FrakRpcError,
17
17
  RpcErrorCodes,
18
18
  baseIframeProps
19
- } from "../chunk-7K4L7VQC.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";
@@ -81,6 +81,7 @@ function useWalletStatus() {
81
81
  );
82
82
  return useQuery({
83
83
  gcTime: 0,
84
+ staleTime: 0,
84
85
  queryKey: ["nexus-sdk", "wallet-status-listener"],
85
86
  queryFn: async () => {
86
87
  if (!client) {
@@ -201,7 +202,8 @@ function useFrakContext() {
201
202
  // src/react/hook/helper/useReferralInteraction.ts
202
203
  function useReferralInteraction({
203
204
  productId,
204
- modalConfig
205
+ modalConfig,
206
+ options
205
207
  } = {}) {
206
208
  const client = useNexusClient();
207
209
  const { frakContext } = useFrakContext();
@@ -228,7 +230,8 @@ function useReferralInteraction({
228
230
  walletStatus: walletStatus2,
229
231
  frakContext,
230
232
  modalConfig,
231
- productId
233
+ productId,
234
+ options
232
235
  });
233
236
  },
234
237
  enabled: !!walletStatus2
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.20",
14
+ "version": "0.0.22",
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,10 +0,0 @@
1
- import { Address } from 'viem';
2
-
3
- /**
4
- * The type of the nexus context
5
- */
6
- type FrakContext = Readonly<{
7
- r: Address;
8
- }>;
9
-
10
- export type { FrakContext as F };
@@ -1,10 +0,0 @@
1
- import { Address } from 'viem';
2
-
3
- /**
4
- * The type of the nexus context
5
- */
6
- type FrakContext = Readonly<{
7
- r: Address;
8
- }>;
9
-
10
- export type { FrakContext as F };
@@ -1,288 +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;
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 (!window.location?.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
- export {
275
- FrakRpcError,
276
- InternalError,
277
- ClientNotFound,
278
- RpcErrorCodes,
279
- Deferred,
280
- hashAndCompressData,
281
- compressJson,
282
- decompressDataAndCheckHash,
283
- decompressJson,
284
- baseIframeProps,
285
- createIframe,
286
- changeIframeVisibility,
287
- FrakContextManager
288
- };
@@ -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;