@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/index.js
CHANGED
|
@@ -95,6 +95,18 @@ function useChipiContext() {
|
|
|
95
95
|
}
|
|
96
96
|
return context;
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
// src/utils/with-error-code.ts
|
|
100
|
+
function withErrorCode(wrapped, original) {
|
|
101
|
+
const code = original.code;
|
|
102
|
+
if (typeof code === "string") {
|
|
103
|
+
Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
|
|
104
|
+
}
|
|
105
|
+
Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
|
|
106
|
+
return wrapped;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/hooks/useCreateWallet.ts
|
|
98
110
|
function useCreateWallet() {
|
|
99
111
|
const { chipiSDK } = useChipiContext();
|
|
100
112
|
const mutation = reactQuery.useMutation({
|
|
@@ -125,7 +137,7 @@ function useCreateWallet() {
|
|
|
125
137
|
}
|
|
126
138
|
} catch (error) {
|
|
127
139
|
if (error instanceof Error) {
|
|
128
|
-
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
140
|
+
throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
|
|
129
141
|
}
|
|
130
142
|
throw new Error("Failed to create passkey for wallet");
|
|
131
143
|
}
|
|
@@ -252,7 +264,14 @@ function useChipiWallet(config3) {
|
|
|
252
264
|
}
|
|
253
265
|
});
|
|
254
266
|
const createWalletMutation = reactQuery.useMutation({
|
|
255
|
-
|
|
267
|
+
// P2.2 default flip (CHIPI -> SHHH, #301) reached ChipiSDK.createWallet
|
|
268
|
+
// but missed this hook, which kept minting legacy CHIPI v29 for callers
|
|
269
|
+
// that omitted walletType while the docs promised SHHH V8.4. Found by an
|
|
270
|
+
// integrator whose omitted-walletType wallet came back as class
|
|
271
|
+
// 0x053f4f87... on mainnet (2026-09-09). Passing the default explicitly
|
|
272
|
+
// is still right (the SDK honours explicit values); it just has to be
|
|
273
|
+
// the SAME default the SDK documents.
|
|
274
|
+
mutationFn: async ({ encryptKey, walletType = "SHHH" }) => {
|
|
256
275
|
if (!trimmedUserId) throw new Error("External user ID is required");
|
|
257
276
|
const bearerToken = await getBearerToken();
|
|
258
277
|
if (!bearerToken) throw new Error("Bearer token is required");
|
|
@@ -367,18 +386,21 @@ function useChipiSession(config3) {
|
|
|
367
386
|
staleTime: 3e4
|
|
368
387
|
// 30 seconds
|
|
369
388
|
});
|
|
389
|
+
const [revokedSessionKey, setRevokedSessionKey] = React.useState(null);
|
|
370
390
|
const sessionState = React.useMemo(() => {
|
|
371
391
|
if (!localSession) return "none";
|
|
392
|
+
if (revokedSessionKey === localSession.publicKey) return "revoked";
|
|
393
|
+
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
372
394
|
const status = sessionStatusQuery.data;
|
|
373
395
|
if (status) {
|
|
374
|
-
if (
|
|
396
|
+
if (status.validUntil === 0) return "created";
|
|
375
397
|
if (status.validUntil * 1e3 < Date.now()) return "expired";
|
|
376
398
|
if (status.remainingCalls <= 0) return "expired";
|
|
399
|
+
if (!status.isActive) return "revoked";
|
|
377
400
|
return "active";
|
|
378
401
|
}
|
|
379
|
-
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
380
402
|
return "created";
|
|
381
|
-
}, [localSession, sessionStatusQuery.data]);
|
|
403
|
+
}, [localSession, revokedSessionKey, sessionStatusQuery.data]);
|
|
382
404
|
const hasActiveSession = sessionState === "active";
|
|
383
405
|
const isSessionExpired = sessionState === "expired";
|
|
384
406
|
const remainingCalls = sessionStatusQuery.data?.remainingCalls;
|
|
@@ -433,6 +455,7 @@ function useChipiSession(config3) {
|
|
|
433
455
|
},
|
|
434
456
|
onSuccess: () => {
|
|
435
457
|
setError(null);
|
|
458
|
+
if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
|
|
436
459
|
queryClient.invalidateQueries({
|
|
437
460
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
438
461
|
});
|
|
@@ -461,6 +484,7 @@ function useChipiSession(config3) {
|
|
|
461
484
|
},
|
|
462
485
|
onSuccess: () => {
|
|
463
486
|
setError(null);
|
|
487
|
+
if (localSession) setRevokedSessionKey(localSession.publicKey);
|
|
464
488
|
queryClient.invalidateQueries({
|
|
465
489
|
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
466
490
|
});
|
|
@@ -701,7 +725,7 @@ function useMigrateWalletToPasskey() {
|
|
|
701
725
|
};
|
|
702
726
|
} catch (error) {
|
|
703
727
|
if (error instanceof Error) {
|
|
704
|
-
throw new Error(`Migration failed: ${error.message}`);
|
|
728
|
+
throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
|
|
705
729
|
}
|
|
706
730
|
throw new Error("Failed to migrate wallet to passkey");
|
|
707
731
|
}
|