@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/index.mjs CHANGED
@@ -71,6 +71,18 @@ function useChipiContext() {
71
71
  }
72
72
  return context;
73
73
  }
74
+
75
+ // src/utils/with-error-code.ts
76
+ function withErrorCode(wrapped, original) {
77
+ const code = original.code;
78
+ if (typeof code === "string") {
79
+ Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
80
+ }
81
+ Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
82
+ return wrapped;
83
+ }
84
+
85
+ // src/hooks/useCreateWallet.ts
74
86
  function useCreateWallet() {
75
87
  const { chipiSDK } = useChipiContext();
76
88
  const mutation = useMutation({
@@ -101,7 +113,7 @@ function useCreateWallet() {
101
113
  }
102
114
  } catch (error) {
103
115
  if (error instanceof Error) {
104
- throw new Error(`Passkey creation failed: ${error.message}`);
116
+ throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
105
117
  }
106
118
  throw new Error("Failed to create passkey for wallet");
107
119
  }
@@ -228,7 +240,14 @@ function useChipiWallet(config3) {
228
240
  }
229
241
  });
230
242
  const createWalletMutation = useMutation({
231
- mutationFn: async ({ encryptKey, walletType = "CHIPI" }) => {
243
+ // P2.2 default flip (CHIPI -> SHHH, #301) reached ChipiSDK.createWallet
244
+ // but missed this hook, which kept minting legacy CHIPI v29 for callers
245
+ // that omitted walletType while the docs promised SHHH V8.4. Found by an
246
+ // integrator whose omitted-walletType wallet came back as class
247
+ // 0x053f4f87... on mainnet (2026-09-09). Passing the default explicitly
248
+ // is still right (the SDK honours explicit values); it just has to be
249
+ // the SAME default the SDK documents.
250
+ mutationFn: async ({ encryptKey, walletType = "SHHH" }) => {
232
251
  if (!trimmedUserId) throw new Error("External user ID is required");
233
252
  const bearerToken = await getBearerToken();
234
253
  if (!bearerToken) throw new Error("Bearer token is required");
@@ -343,18 +362,21 @@ function useChipiSession(config3) {
343
362
  staleTime: 3e4
344
363
  // 30 seconds
345
364
  });
365
+ const [revokedSessionKey, setRevokedSessionKey] = useState(null);
346
366
  const sessionState = useMemo(() => {
347
367
  if (!localSession) return "none";
368
+ if (revokedSessionKey === localSession.publicKey) return "revoked";
369
+ if (localSession.validUntil * 1e3 < Date.now()) return "expired";
348
370
  const status = sessionStatusQuery.data;
349
371
  if (status) {
350
- if (!status.isActive) return "revoked";
372
+ if (status.validUntil === 0) return "created";
351
373
  if (status.validUntil * 1e3 < Date.now()) return "expired";
352
374
  if (status.remainingCalls <= 0) return "expired";
375
+ if (!status.isActive) return "revoked";
353
376
  return "active";
354
377
  }
355
- if (localSession.validUntil * 1e3 < Date.now()) return "expired";
356
378
  return "created";
357
- }, [localSession, sessionStatusQuery.data]);
379
+ }, [localSession, revokedSessionKey, sessionStatusQuery.data]);
358
380
  const hasActiveSession = sessionState === "active";
359
381
  const isSessionExpired = sessionState === "expired";
360
382
  const remainingCalls = sessionStatusQuery.data?.remainingCalls;
@@ -409,6 +431,7 @@ function useChipiSession(config3) {
409
431
  },
410
432
  onSuccess: () => {
411
433
  setError(null);
434
+ if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
412
435
  queryClient.invalidateQueries({
413
436
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
414
437
  });
@@ -437,6 +460,7 @@ function useChipiSession(config3) {
437
460
  },
438
461
  onSuccess: () => {
439
462
  setError(null);
463
+ if (localSession) setRevokedSessionKey(localSession.publicKey);
440
464
  queryClient.invalidateQueries({
441
465
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
442
466
  });
@@ -677,7 +701,7 @@ function useMigrateWalletToPasskey() {
677
701
  };
678
702
  } catch (error) {
679
703
  if (error instanceof Error) {
680
- throw new Error(`Migration failed: ${error.message}`);
704
+ throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
681
705
  }
682
706
  throw new Error("Failed to migrate wallet to passkey");
683
707
  }