@frak-labs/nexus-sdk 0.0.10 → 0.0.11
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/dist/chunk-5CFD5FM2.js +86 -0
- package/dist/chunk-7MVQQ2X6.js +381 -0
- package/dist/{chunk-72IEHEQX.js → chunk-GUDT2W6I.js} +32 -10
- package/dist/{chunk-NIFJZD3M.cjs → chunk-IQQTTKJL.cjs} +30 -8
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/chunk-V3S6RBRJ.cjs +381 -0
- package/dist/{client-6_BJp7Ub.d.ts → client-C7u9zGwC.d.cts} +135 -142
- package/dist/{client--U_6SK0l.d.cts → client-gE3fYzkD.d.ts} +135 -142
- package/dist/core/actions/index.cjs +2 -7
- package/dist/core/actions/index.d.cts +16 -35
- package/dist/core/actions/index.d.ts +16 -35
- package/dist/core/actions/index.js +5 -10
- package/dist/core/index.cjs +2 -4
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +2 -4
- package/dist/core/interactions/index.cjs +6 -2
- package/dist/core/interactions/index.d.cts +20 -6
- package/dist/core/interactions/index.d.ts +20 -6
- package/dist/core/interactions/index.js +7 -3
- package/dist/{interaction-D_CzyqRE.d.cts → interaction-D3-M3nBh.d.cts} +2 -2
- package/dist/{interaction-D_CzyqRE.d.ts → interaction-D3-M3nBh.d.ts} +2 -2
- package/dist/react/index.cjs +146 -158
- package/dist/react/index.d.cts +44 -51
- package/dist/react/index.d.ts +44 -51
- package/dist/react/index.js +152 -164
- package/dist/sendTransaction-BZW627cT.d.cts +30 -0
- package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
- package/package.json +8 -5
- package/dist/chunk-3T2FNW6E.cjs +0 -100
- package/dist/chunk-BPFJZRJ6.cjs +0 -152
- package/dist/chunk-HOX3RRO6.js +0 -199
- package/dist/chunk-SGLR6RFA.cjs +0 -199
- package/dist/chunk-T54VMWHQ.js +0 -100
- package/dist/chunk-TPC5PMRC.js +0 -152
- package/dist/watchUnlockStatus-CxnibdQx.d.cts +0 -43
- package/dist/watchUnlockStatus-g8wIxpeM.d.ts +0 -43
package/dist/react/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createIFrameNexusClient
|
|
3
|
-
} from "../chunk-HOX3RRO6.js";
|
|
4
|
-
import {
|
|
5
|
-
getArticleUnlockOptions,
|
|
6
|
-
sendInteraction,
|
|
7
|
-
sendTransaction,
|
|
8
|
-
siweAuthenticate,
|
|
9
|
-
watchUnlockStatus,
|
|
10
|
-
watchWalletStatus
|
|
11
|
-
} from "../chunk-T54VMWHQ.js";
|
|
12
1
|
import {
|
|
13
2
|
ClientNotFound,
|
|
3
|
+
Deferred,
|
|
14
4
|
FrakRpcError,
|
|
15
5
|
RpcErrorCodes,
|
|
6
|
+
baseIframeProps,
|
|
16
7
|
compressJson,
|
|
8
|
+
createIFrameNexusClient,
|
|
17
9
|
decompressJson
|
|
18
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-7MVQQ2X6.js";
|
|
19
11
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
displayModal,
|
|
13
|
+
openSso,
|
|
14
|
+
sendInteraction,
|
|
15
|
+
sendTransaction,
|
|
16
|
+
siweAuthenticate,
|
|
17
|
+
watchWalletStatus
|
|
18
|
+
} from "../chunk-5CFD5FM2.js";
|
|
19
|
+
import {
|
|
20
|
+
ReferralInteractionEncoder
|
|
21
|
+
} from "../chunk-GUDT2W6I.js";
|
|
22
22
|
import "../chunk-PKBMQBKP.js";
|
|
23
23
|
|
|
24
24
|
// src/react/provider/NexusConfigProvider.ts
|
|
@@ -65,36 +65,8 @@ function useNexusClient() {
|
|
|
65
65
|
return useContext2(NexusIFrameClientContext);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
// src/react/hook/useArticleUnlockOptions.ts
|
|
69
|
-
import { useQuery } from "@tanstack/react-query";
|
|
70
|
-
function useArticleUnlockOptions({
|
|
71
|
-
articleId,
|
|
72
|
-
contentId
|
|
73
|
-
}) {
|
|
74
|
-
const client = useNexusClient();
|
|
75
|
-
return useQuery({
|
|
76
|
-
queryKey: [
|
|
77
|
-
"nexus-sdk",
|
|
78
|
-
"article-unlock-options",
|
|
79
|
-
articleId ?? "no-article-id"
|
|
80
|
-
],
|
|
81
|
-
queryFn: async () => {
|
|
82
|
-
if (!client) return;
|
|
83
|
-
if (!(articleId && contentId)) {
|
|
84
|
-
throw new Error("No article id provided");
|
|
85
|
-
}
|
|
86
|
-
return await getArticleUnlockOptions(client, {
|
|
87
|
-
articleId,
|
|
88
|
-
contentId
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
enabled: !!client && !!articleId && !!contentId,
|
|
92
|
-
gcTime: 0
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
68
|
// src/react/hook/useWalletStatus.ts
|
|
97
|
-
import { useQuery
|
|
69
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
98
70
|
import { useCallback } from "react";
|
|
99
71
|
function useWalletStatus() {
|
|
100
72
|
const queryClient = useQueryClient();
|
|
@@ -108,75 +80,28 @@ function useWalletStatus() {
|
|
|
108
80
|
},
|
|
109
81
|
[queryClient]
|
|
110
82
|
);
|
|
111
|
-
return
|
|
83
|
+
return useQuery({
|
|
112
84
|
gcTime: 0,
|
|
113
85
|
queryKey: ["nexus-sdk", "wallet-status-listener"],
|
|
114
86
|
queryFn: async () => {
|
|
115
87
|
if (!client) {
|
|
116
|
-
|
|
88
|
+
throw new ClientNotFound();
|
|
117
89
|
}
|
|
118
|
-
|
|
119
|
-
|
|
90
|
+
const firstResult = new Deferred();
|
|
91
|
+
let hasResolved = false;
|
|
92
|
+
await watchWalletStatus(client, (status) => {
|
|
93
|
+
newStatusUpdated(status);
|
|
94
|
+
if (!hasResolved) {
|
|
95
|
+
firstResult.resolve(status);
|
|
96
|
+
hasResolved = true;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return firstResult.promise;
|
|
120
100
|
},
|
|
121
101
|
enabled: !!client
|
|
122
102
|
});
|
|
123
103
|
}
|
|
124
104
|
|
|
125
|
-
// src/react/hook/useArticleUnlockStatus.ts
|
|
126
|
-
import { useQuery as useQuery3, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
127
|
-
import { useCallback as useCallback2 } from "react";
|
|
128
|
-
function useArticleUnlockStatus({
|
|
129
|
-
articleId,
|
|
130
|
-
contentId
|
|
131
|
-
}) {
|
|
132
|
-
const queryClient = useQueryClient2();
|
|
133
|
-
const client = useNexusClient();
|
|
134
|
-
const newStatusUpdated = useCallback2(
|
|
135
|
-
(event) => {
|
|
136
|
-
queryClient.setQueryData(
|
|
137
|
-
[
|
|
138
|
-
"nexus-sdk",
|
|
139
|
-
"article-unlock-status",
|
|
140
|
-
articleId ?? "no-article-id",
|
|
141
|
-
contentId ?? "no-contentId-id"
|
|
142
|
-
],
|
|
143
|
-
event
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
[articleId, contentId, queryClient]
|
|
147
|
-
);
|
|
148
|
-
return useQuery3({
|
|
149
|
-
queryKey: [
|
|
150
|
-
"nexus-sdk",
|
|
151
|
-
"article-unlock-status",
|
|
152
|
-
articleId ?? "no-article-id",
|
|
153
|
-
contentId ?? "no-contentId-id"
|
|
154
|
-
],
|
|
155
|
-
gcTime: 0,
|
|
156
|
-
queryFn: async () => {
|
|
157
|
-
if (!client) {
|
|
158
|
-
return {
|
|
159
|
-
status: "waiting-response",
|
|
160
|
-
key: "waiting-response"
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (!(articleId && contentId)) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
await watchUnlockStatus(
|
|
167
|
-
client,
|
|
168
|
-
{ articleId, contentId },
|
|
169
|
-
newStatusUpdated
|
|
170
|
-
);
|
|
171
|
-
return {
|
|
172
|
-
status: "waiting-response",
|
|
173
|
-
key: "waiting-response"
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
enabled: !!client && !!articleId && !!contentId
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
105
|
// src/react/hook/useSendTransaction.ts
|
|
181
106
|
import { useMutation } from "@tanstack/react-query";
|
|
182
107
|
function useSendTransactionAction({
|
|
@@ -217,18 +142,36 @@ function useSiweAuthenticate({
|
|
|
217
142
|
});
|
|
218
143
|
}
|
|
219
144
|
|
|
220
|
-
// src/react/hook/helper/
|
|
221
|
-
import { useQuery as
|
|
222
|
-
import { useMemo as useMemo2 } from "react";
|
|
145
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
146
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
147
|
+
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
223
148
|
import { isAddressEqual } from "viem";
|
|
224
149
|
|
|
225
|
-
// src/react/hook/
|
|
150
|
+
// src/react/hook/useDisplayModal.ts
|
|
226
151
|
import { useMutation as useMutation3 } from "@tanstack/react-query";
|
|
227
|
-
function
|
|
152
|
+
function useDisplayModal({
|
|
228
153
|
mutations
|
|
229
154
|
} = {}) {
|
|
230
155
|
const client = useNexusClient();
|
|
231
156
|
return useMutation3({
|
|
157
|
+
...mutations,
|
|
158
|
+
mutationKey: ["nexus-sdk", "display-modal"],
|
|
159
|
+
mutationFn: async (args) => {
|
|
160
|
+
if (!client) {
|
|
161
|
+
throw new ClientNotFound();
|
|
162
|
+
}
|
|
163
|
+
return displayModal(client, args);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/react/hook/useSendInteraction.ts
|
|
169
|
+
import { useMutation as useMutation4 } from "@tanstack/react-query";
|
|
170
|
+
function useSendInteraction({
|
|
171
|
+
mutations
|
|
172
|
+
} = {}) {
|
|
173
|
+
const client = useNexusClient();
|
|
174
|
+
return useMutation4({
|
|
232
175
|
...mutations,
|
|
233
176
|
mutationKey: ["nexus-sdk", "send-interaction"],
|
|
234
177
|
mutationFn: async (params) => {
|
|
@@ -241,7 +184,7 @@ function useSendInteraction({
|
|
|
241
184
|
}
|
|
242
185
|
|
|
243
186
|
// src/react/hook/utils/useNexusContext.ts
|
|
244
|
-
import { useMutation as
|
|
187
|
+
import { useMutation as useMutation5, useQuery as useQuery2 } from "@tanstack/react-query";
|
|
245
188
|
|
|
246
189
|
// src/react/hook/utils/useWindowLocation.ts
|
|
247
190
|
import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
@@ -283,7 +226,7 @@ function useWindowLocation() {
|
|
|
283
226
|
var contextKey = "nCtx";
|
|
284
227
|
function useNexusContext() {
|
|
285
228
|
const { location } = useWindowLocation();
|
|
286
|
-
const { data: nexusContext } =
|
|
229
|
+
const { data: nexusContext } = useQuery2({
|
|
287
230
|
queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
|
|
288
231
|
queryFn: async () => {
|
|
289
232
|
if (!location?.href) return null;
|
|
@@ -293,9 +236,10 @@ function useNexusContext() {
|
|
|
293
236
|
const parsedContext = await decompressJson(nexusContext2);
|
|
294
237
|
if (!parsedContext) return null;
|
|
295
238
|
return parsedContext;
|
|
296
|
-
}
|
|
239
|
+
},
|
|
240
|
+
enabled: !!location?.href
|
|
297
241
|
});
|
|
298
|
-
const { mutate: updateContext, mutateAsync: updateContextAsync } =
|
|
242
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation5({
|
|
299
243
|
mutationKey: ["nexus-sdk", "update-context"],
|
|
300
244
|
mutationFn: async (newContext) => {
|
|
301
245
|
if (!location || typeof window === "undefined") return;
|
|
@@ -307,47 +251,95 @@ function useNexusContext() {
|
|
|
307
251
|
window.history.replaceState(null, "", url.toString());
|
|
308
252
|
}
|
|
309
253
|
});
|
|
310
|
-
return {
|
|
254
|
+
return {
|
|
255
|
+
nexusContext,
|
|
256
|
+
updateContext,
|
|
257
|
+
updateContextAsync
|
|
258
|
+
};
|
|
311
259
|
}
|
|
312
260
|
|
|
313
|
-
// src/react/hook/helper/
|
|
314
|
-
function
|
|
261
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
262
|
+
function useReferralInteraction({
|
|
263
|
+
contentId,
|
|
264
|
+
modalConfig
|
|
265
|
+
} = {}) {
|
|
315
266
|
const { nexusContext, updateContextAsync } = useNexusContext();
|
|
316
267
|
const { data: walletStatus } = useWalletStatus();
|
|
317
268
|
const { mutateAsync: sendInteraction2 } = useSendInteraction();
|
|
318
|
-
const
|
|
269
|
+
const ensureWalletConnected = useEnsureWalletConnected({
|
|
270
|
+
modalConfig,
|
|
271
|
+
walletStatus
|
|
272
|
+
});
|
|
273
|
+
const processReferral = useCallback2(async () => {
|
|
274
|
+
try {
|
|
275
|
+
const currentWallet = await ensureWalletConnected();
|
|
276
|
+
if (!nexusContext?.r) {
|
|
277
|
+
if (currentWallet) {
|
|
278
|
+
await updateContextAsync({ r: currentWallet });
|
|
279
|
+
}
|
|
280
|
+
return "no-referrer";
|
|
281
|
+
}
|
|
282
|
+
if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
|
|
283
|
+
return "self-referral";
|
|
284
|
+
}
|
|
285
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
286
|
+
referrer: nexusContext.r
|
|
287
|
+
});
|
|
288
|
+
await sendInteraction2({ contentId, interaction });
|
|
289
|
+
if (currentWallet) {
|
|
290
|
+
await updateContextAsync({ r: currentWallet });
|
|
291
|
+
}
|
|
292
|
+
return "success";
|
|
293
|
+
} catch (error2) {
|
|
294
|
+
return mapErrorToState(error2);
|
|
295
|
+
}
|
|
296
|
+
}, [
|
|
297
|
+
nexusContext,
|
|
298
|
+
contentId,
|
|
299
|
+
ensureWalletConnected,
|
|
300
|
+
sendInteraction2,
|
|
301
|
+
updateContextAsync
|
|
302
|
+
]);
|
|
303
|
+
const {
|
|
304
|
+
data: referralState,
|
|
305
|
+
error,
|
|
306
|
+
status
|
|
307
|
+
} = useQuery3({
|
|
319
308
|
gcTime: 0,
|
|
309
|
+
staleTime: 0,
|
|
320
310
|
queryKey: [
|
|
321
311
|
"nexus-sdk",
|
|
322
|
-
"auto-
|
|
312
|
+
"auto-referral-interaction",
|
|
323
313
|
nexusContext?.r ?? "no-referrer",
|
|
324
314
|
walletStatus?.key ?? "no-wallet-status"
|
|
325
315
|
],
|
|
326
|
-
queryFn:
|
|
327
|
-
|
|
328
|
-
await updateContextAsync({ r: walletStatus.wallet });
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
if (!nexusContext || walletStatus?.key !== "connected") return null;
|
|
332
|
-
if (isAddressEqual(nexusContext.r, walletStatus.wallet))
|
|
333
|
-
return null;
|
|
334
|
-
const interaction = PressInteractionEncoder.referred({
|
|
335
|
-
referrer: nexusContext.r
|
|
336
|
-
});
|
|
337
|
-
await sendInteraction2({ contentId, interaction });
|
|
338
|
-
await updateContextAsync({ r: walletStatus.wallet });
|
|
339
|
-
return { referrer: nexusContext.r };
|
|
340
|
-
}
|
|
316
|
+
queryFn: processReferral,
|
|
317
|
+
enabled: !!walletStatus
|
|
341
318
|
});
|
|
342
|
-
return
|
|
319
|
+
return useMemo2(() => {
|
|
320
|
+
if (status === "pending") return "processing";
|
|
321
|
+
if (status === "error") return mapErrorToState(error);
|
|
322
|
+
return referralState || "idle";
|
|
323
|
+
}, [referralState, status, error]);
|
|
343
324
|
}
|
|
344
|
-
function
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
status
|
|
325
|
+
function useEnsureWalletConnected({
|
|
326
|
+
modalConfig,
|
|
327
|
+
walletStatus
|
|
348
328
|
}) {
|
|
349
|
-
const
|
|
350
|
-
|
|
329
|
+
const { mutateAsync: displayModal2 } = useDisplayModal();
|
|
330
|
+
return useCallback2(async () => {
|
|
331
|
+
if (walletStatus?.key !== "connected" || !walletStatus.interactionSession) {
|
|
332
|
+
if (!modalConfig) {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
const result = await displayModal2(modalConfig);
|
|
336
|
+
return result?.login?.wallet ?? void 0;
|
|
337
|
+
}
|
|
338
|
+
return walletStatus.wallet ?? void 0;
|
|
339
|
+
}, [walletStatus, modalConfig, displayModal2]);
|
|
340
|
+
}
|
|
341
|
+
function mapErrorToState(error) {
|
|
342
|
+
if (error instanceof FrakRpcError) {
|
|
351
343
|
switch (error.code) {
|
|
352
344
|
case RpcErrorCodes.walletNotConnected:
|
|
353
345
|
return "no-wallet";
|
|
@@ -356,32 +348,30 @@ function useOutputStateMapper({
|
|
|
356
348
|
default:
|
|
357
349
|
return "error";
|
|
358
350
|
}
|
|
359
|
-
}
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
351
|
+
}
|
|
352
|
+
return "error";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/react/hook/useOpenSso.ts
|
|
356
|
+
import { useMutation as useMutation6 } from "@tanstack/react-query";
|
|
357
|
+
function useOpenSso({ mutations } = {}) {
|
|
358
|
+
const client = useNexusClient();
|
|
359
|
+
return useMutation6({
|
|
360
|
+
...mutations,
|
|
361
|
+
mutationKey: ["nexus-sdk", "open-sso"],
|
|
362
|
+
mutationFn: async (params) => {
|
|
363
|
+
if (!client) {
|
|
364
|
+
throw new ClientNotFound();
|
|
365
|
+
}
|
|
366
|
+
return openSso(client, params);
|
|
368
367
|
}
|
|
369
|
-
}
|
|
368
|
+
});
|
|
370
369
|
}
|
|
371
370
|
|
|
372
371
|
// src/react/provider/NexusIFrameClientProvider.ts
|
|
373
372
|
var NexusIFrameClientContext = createContext2(
|
|
374
373
|
void 0
|
|
375
374
|
);
|
|
376
|
-
var defaultIframeStyle = {
|
|
377
|
-
width: "0",
|
|
378
|
-
height: "0",
|
|
379
|
-
border: "0",
|
|
380
|
-
position: "absolute",
|
|
381
|
-
zIndex: 1e3,
|
|
382
|
-
top: "-1000px",
|
|
383
|
-
left: "-1000px"
|
|
384
|
-
};
|
|
385
375
|
function NexusIFrameClientProvider({
|
|
386
376
|
style,
|
|
387
377
|
children
|
|
@@ -389,11 +379,9 @@ function NexusIFrameClientProvider({
|
|
|
389
379
|
const config = useNexusConfig();
|
|
390
380
|
const [client, setClient] = useState3(void 0);
|
|
391
381
|
const iFrame = createElement2("iframe", {
|
|
392
|
-
|
|
393
|
-
name: "nexus-wallet",
|
|
382
|
+
...baseIframeProps,
|
|
394
383
|
src: `${config.walletUrl}/listener`,
|
|
395
|
-
style: style ??
|
|
396
|
-
allow: "publickey-credentials-get *",
|
|
384
|
+
style: style ?? baseIframeProps.style,
|
|
397
385
|
ref: (iframe) => {
|
|
398
386
|
if (!iframe || client) {
|
|
399
387
|
return;
|
|
@@ -418,11 +406,11 @@ export {
|
|
|
418
406
|
NexusConfigProvider,
|
|
419
407
|
NexusIFrameClientContext,
|
|
420
408
|
NexusIFrameClientProvider,
|
|
421
|
-
|
|
422
|
-
useArticleUnlockStatus,
|
|
409
|
+
useDisplayModal,
|
|
423
410
|
useNexusClient,
|
|
424
411
|
useNexusConfig,
|
|
425
|
-
|
|
412
|
+
useOpenSso,
|
|
413
|
+
useReferralInteraction,
|
|
426
414
|
useSendInteraction,
|
|
427
415
|
useSendTransactionAction,
|
|
428
416
|
useSiweAuthenticate,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-C7u9zGwC.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 SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-gE3fYzkD.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 SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|
package/package.json
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.11",
|
|
15
15
|
"description": "Nexus 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
|
-
"repository":
|
|
16
|
+
"repository": {
|
|
17
|
+
"url": "https://github.com/frak-id/wallet",
|
|
18
|
+
"directory": "packages/sdk"
|
|
19
|
+
},
|
|
17
20
|
"homepage": "https://docs.frak.id/wallet-sdk",
|
|
18
21
|
"keywords": [
|
|
19
22
|
"frak-labs",
|
|
@@ -78,9 +81,9 @@
|
|
|
78
81
|
"js-sha256": "^0.11.0"
|
|
79
82
|
},
|
|
80
83
|
"devDependencies": {
|
|
81
|
-
"@tanstack/react-query": ">=5.
|
|
82
|
-
"@types/node": "^
|
|
83
|
-
"tsup": "^8.
|
|
84
|
+
"@tanstack/react-query": ">=5.51.15",
|
|
85
|
+
"@types/node": "^22",
|
|
86
|
+
"tsup": "^8.2.3",
|
|
84
87
|
"typescript": "^5"
|
|
85
88
|
}
|
|
86
89
|
}
|
package/dist/chunk-3T2FNW6E.cjs
DELETED
|
@@ -1,100 +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
|
-
|
|
4
|
-
var _chunkBPFJZRJ6cjs = require('./chunk-BPFJZRJ6.cjs');
|
|
5
|
-
|
|
6
|
-
// src/core/actions/getUnlockOptions.ts
|
|
7
|
-
function getArticleUnlockOptions(client, { articleId, contentId }) {
|
|
8
|
-
return client.request({
|
|
9
|
-
method: "frak_getArticleUnlockOptions",
|
|
10
|
-
params: [contentId, articleId]
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// src/core/actions/watchUnlockStatus.ts
|
|
15
|
-
function watchUnlockStatus(client, { articleId, contentId }, callback) {
|
|
16
|
-
return client.listenerRequest(
|
|
17
|
-
{
|
|
18
|
-
method: "frak_listenToArticleUnlockStatus",
|
|
19
|
-
params: [contentId, articleId]
|
|
20
|
-
},
|
|
21
|
-
callback
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/core/actions/watchWalletStatus.ts
|
|
26
|
-
function watchWalletStatus(client, callback) {
|
|
27
|
-
return client.listenerRequest(
|
|
28
|
-
{
|
|
29
|
-
method: "frak_listenToWalletStatus"
|
|
30
|
-
},
|
|
31
|
-
callback
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/actions/startUnlock.ts
|
|
36
|
-
async function getStartArticleUnlockUrl(config, params) {
|
|
37
|
-
const { compressed, compressedHash } = await _chunkBPFJZRJ6cjs.hashAndCompressData.call(void 0, {
|
|
38
|
-
method: "frak_startArticleUnlock",
|
|
39
|
-
params
|
|
40
|
-
});
|
|
41
|
-
const outputUrl = new URL(config.walletUrl);
|
|
42
|
-
outputUrl.pathname = "/paywall";
|
|
43
|
-
outputUrl.searchParams.set("params", encodeURIComponent(compressed));
|
|
44
|
-
outputUrl.searchParams.set("hash", encodeURIComponent(compressedHash));
|
|
45
|
-
return outputUrl.toString();
|
|
46
|
-
}
|
|
47
|
-
async function decodeStartUnlockReturn({
|
|
48
|
-
result,
|
|
49
|
-
hash
|
|
50
|
-
}) {
|
|
51
|
-
return _chunkBPFJZRJ6cjs.decompressDataAndCheckHash.call(void 0, {
|
|
52
|
-
compressed: decodeURIComponent(result),
|
|
53
|
-
compressedHash: decodeURIComponent(hash)
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/core/actions/sendTransaction.ts
|
|
58
|
-
async function sendTransaction(client, { tx, context }) {
|
|
59
|
-
return await client.request({
|
|
60
|
-
method: "frak_sendTransaction",
|
|
61
|
-
params: [tx, context]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/core/actions/siweAuthenticate.ts
|
|
66
|
-
var _siwe = require('viem/siwe');
|
|
67
|
-
async function siweAuthenticate(client, { siwe, context }) {
|
|
68
|
-
const realStatement = _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _ => _.statement]), () => ( `I confirm that I want to use my Nexus wallet on: ${client.config.metadata.name}`));
|
|
69
|
-
const builtSiwe = {
|
|
70
|
-
...siwe,
|
|
71
|
-
statement: realStatement,
|
|
72
|
-
nonce: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _2 => _2.nonce]), () => ( _siwe.generateSiweNonce.call(void 0, ))),
|
|
73
|
-
uri: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _3 => _3.uri]), () => ( `https://${client.config.domain}`)),
|
|
74
|
-
version: _nullishCoalesce(_optionalChain([siwe, 'optionalAccess', _4 => _4.version]), () => ( "1")),
|
|
75
|
-
domain: client.config.domain
|
|
76
|
-
};
|
|
77
|
-
return await client.request({
|
|
78
|
-
method: "frak_siweAuthenticate",
|
|
79
|
-
params: [builtSiwe, context]
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/core/actions/sendInteraction.ts
|
|
84
|
-
async function sendInteraction(client, { contentId, interaction, validation }) {
|
|
85
|
-
return await client.request({
|
|
86
|
-
method: "frak_sendInteraction",
|
|
87
|
-
params: [contentId, interaction, validation]
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
exports.getArticleUnlockOptions = getArticleUnlockOptions; exports.watchUnlockStatus = watchUnlockStatus; exports.watchWalletStatus = watchWalletStatus; exports.getStartArticleUnlockUrl = getStartArticleUnlockUrl; exports.decodeStartUnlockReturn = decodeStartUnlockReturn; exports.sendTransaction = sendTransaction; exports.siweAuthenticate = siweAuthenticate; exports.sendInteraction = sendInteraction;
|