@chipi-stack/chipi-react 14.12.2 → 14.13.1
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/hooks.js +30 -6
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +30 -6
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/hooks.js
CHANGED
|
@@ -45,6 +45,18 @@ function useChipiContext() {
|
|
|
45
45
|
}
|
|
46
46
|
return context;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
// src/utils/with-error-code.ts
|
|
50
|
+
function withErrorCode(wrapped, original) {
|
|
51
|
+
const code = original.code;
|
|
52
|
+
if (typeof code === "string") {
|
|
53
|
+
Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
|
|
54
|
+
}
|
|
55
|
+
Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
|
|
56
|
+
return wrapped;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/hooks/useCreateWallet.ts
|
|
48
60
|
function useCreateWallet() {
|
|
49
61
|
const { chipiSDK } = useChipiContext();
|
|
50
62
|
const mutation = reactQuery.useMutation({
|
|
@@ -75,7 +87,7 @@ function useCreateWallet() {
|
|
|
75
87
|
}
|
|
76
88
|
} catch (error) {
|
|
77
89
|
if (error instanceof Error) {
|
|
78
|
-
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
90
|
+
throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
|
|
79
91
|
}
|
|
80
92
|
throw new Error("Failed to create passkey for wallet");
|
|
81
93
|
}
|
|
@@ -202,7 +214,14 @@ function useChipiWallet(config3) {
|
|
|
202
214
|
}
|
|
203
215
|
});
|
|
204
216
|
const createWalletMutation = reactQuery.useMutation({
|
|
205
|
-
|
|
217
|
+
// P2.2 default flip (CHIPI -> SHHH, #301) reached ChipiSDK.createWallet
|
|
218
|
+
// but missed this hook, which kept minting legacy CHIPI v29 for callers
|
|
219
|
+
// that omitted walletType while the docs promised SHHH V8.4. Found by an
|
|
220
|
+
// integrator whose omitted-walletType wallet came back as class
|
|
221
|
+
// 0x053f4f87... on mainnet (2026-09-09). Passing the default explicitly
|
|
222
|
+
// is still right (the SDK honours explicit values); it just has to be
|
|
223
|
+
// the SAME default the SDK documents.
|
|
224
|
+
mutationFn: async ({ encryptKey, walletType = "SHHH" }) => {
|
|
206
225
|
if (!trimmedUserId) throw new Error("External user ID is required");
|
|
207
226
|
const bearerToken = await getBearerToken();
|
|
208
227
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
@@ -317,18 +336,21 @@ function useChipiSession(config3) {
|
|
|
317
336
|
staleTime: 3e4
|
|
318
337
|
// 30 seconds
|
|
319
338
|
});
|
|
339
|
+
const [revokedSessionKey, setRevokedSessionKey] = react.useState(null);
|
|
320
340
|
const sessionState = react.useMemo(() => {
|
|
321
341
|
if (!localSession) return "none";
|
|
342
|
+
if (revokedSessionKey === localSession.publicKey) return "revoked";
|
|
343
|
+
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
322
344
|
const status = sessionStatusQuery.data;
|
|
323
345
|
if (status) {
|
|
324
|
-
if (
|
|
346
|
+
if (status.validUntil === 0) return "created";
|
|
325
347
|
if (status.validUntil * 1e3 < Date.now()) return "expired";
|
|
326
348
|
if (status.remainingCalls <= 0) return "expired";
|
|
349
|
+
if (!status.isActive) return "revoked";
|
|
327
350
|
return "active";
|
|
328
351
|
}
|
|
329
|
-
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
330
352
|
return "created";
|
|
331
|
-
}, [localSession, sessionStatusQuery.data]);
|
|
353
|
+
}, [localSession, revokedSessionKey, sessionStatusQuery.data]);
|
|
332
354
|
const hasActiveSession = sessionState === "active";
|
|
333
355
|
const isSessionExpired = sessionState === "expired";
|
|
334
356
|
const remainingCalls = sessionStatusQuery.data?.remainingCalls;
|
|
@@ -383,6 +405,7 @@ function useChipiSession(config3) {
|
|
|
383
405
|
},
|
|
384
406
|
onSuccess: () => {
|
|
385
407
|
setError(null);
|
|
408
|
+
if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
|
|
386
409
|
queryClient.invalidateQueries({
|
|
387
410
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
388
411
|
});
|
|
@@ -411,6 +434,7 @@ function useChipiSession(config3) {
|
|
|
411
434
|
},
|
|
412
435
|
onSuccess: () => {
|
|
413
436
|
setError(null);
|
|
437
|
+
if (localSession) setRevokedSessionKey(localSession.publicKey);
|
|
414
438
|
queryClient.invalidateQueries({
|
|
415
439
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
416
440
|
});
|
|
@@ -651,7 +675,7 @@ function useMigrateWalletToPasskey() {
|
|
|
651
675
|
};
|
|
652
676
|
} catch (error) {
|
|
653
677
|
if (error instanceof Error) {
|
|
654
|
-
throw new Error(`Migration failed: ${error.message}`);
|
|
678
|
+
throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
|
|
655
679
|
}
|
|
656
680
|
throw new Error("Failed to migrate wallet to passkey");
|
|
657
681
|
}
|