@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.mjs CHANGED
@@ -23,6 +23,18 @@ function useChipiContext() {
23
23
  }
24
24
  return context;
25
25
  }
26
+
27
+ // src/utils/with-error-code.ts
28
+ function withErrorCode(wrapped, original) {
29
+ const code = original.code;
30
+ if (typeof code === "string") {
31
+ Object.defineProperty(wrapped, "code", { value: code, enumerable: true });
32
+ }
33
+ Object.defineProperty(wrapped, "cause", { value: original, enumerable: false });
34
+ return wrapped;
35
+ }
36
+
37
+ // src/hooks/useCreateWallet.ts
26
38
  function useCreateWallet() {
27
39
  const { chipiSDK } = useChipiContext();
28
40
  const mutation = useMutation({
@@ -53,7 +65,7 @@ function useCreateWallet() {
53
65
  }
54
66
  } catch (error) {
55
67
  if (error instanceof Error) {
56
- throw new Error(`Passkey creation failed: ${error.message}`);
68
+ throw withErrorCode(new Error(`Passkey creation failed: ${error.message}`), error);
57
69
  }
58
70
  throw new Error("Failed to create passkey for wallet");
59
71
  }
@@ -180,7 +192,14 @@ function useChipiWallet(config3) {
180
192
  }
181
193
  });
182
194
  const createWalletMutation = useMutation({
183
- mutationFn: async ({ encryptKey, walletType = "CHIPI" }) => {
195
+ // P2.2 default flip (CHIPI -> SHHH, #301) reached ChipiSDK.createWallet
196
+ // but missed this hook, which kept minting legacy CHIPI v29 for callers
197
+ // that omitted walletType while the docs promised SHHH V8.4. Found by an
198
+ // integrator whose omitted-walletType wallet came back as class
199
+ // 0x053f4f87... on mainnet (2026-09-09). Passing the default explicitly
200
+ // is still right (the SDK honours explicit values); it just has to be
201
+ // the SAME default the SDK documents.
202
+ mutationFn: async ({ encryptKey, walletType = "SHHH" }) => {
184
203
  if (!trimmedUserId) throw new Error("External user ID is required");
185
204
  const bearerToken = await getBearerToken();
186
205
  if (!bearerToken) throw new Error("Bearer token is required");
@@ -295,18 +314,21 @@ function useChipiSession(config3) {
295
314
  staleTime: 3e4
296
315
  // 30 seconds
297
316
  });
317
+ const [revokedSessionKey, setRevokedSessionKey] = useState(null);
298
318
  const sessionState = useMemo(() => {
299
319
  if (!localSession) return "none";
320
+ if (revokedSessionKey === localSession.publicKey) return "revoked";
321
+ if (localSession.validUntil * 1e3 < Date.now()) return "expired";
300
322
  const status = sessionStatusQuery.data;
301
323
  if (status) {
302
- if (!status.isActive) return "revoked";
324
+ if (status.validUntil === 0) return "created";
303
325
  if (status.validUntil * 1e3 < Date.now()) return "expired";
304
326
  if (status.remainingCalls <= 0) return "expired";
327
+ if (!status.isActive) return "revoked";
305
328
  return "active";
306
329
  }
307
- if (localSession.validUntil * 1e3 < Date.now()) return "expired";
308
330
  return "created";
309
- }, [localSession, sessionStatusQuery.data]);
331
+ }, [localSession, revokedSessionKey, sessionStatusQuery.data]);
310
332
  const hasActiveSession = sessionState === "active";
311
333
  const isSessionExpired = sessionState === "expired";
312
334
  const remainingCalls = sessionStatusQuery.data?.remainingCalls;
@@ -361,6 +383,7 @@ function useChipiSession(config3) {
361
383
  },
362
384
  onSuccess: () => {
363
385
  setError(null);
386
+ if (localSession && revokedSessionKey === localSession.publicKey) setRevokedSessionKey(null);
364
387
  queryClient.invalidateQueries({
365
388
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
366
389
  });
@@ -389,6 +412,7 @@ function useChipiSession(config3) {
389
412
  },
390
413
  onSuccess: () => {
391
414
  setError(null);
415
+ if (localSession) setRevokedSessionKey(localSession.publicKey);
392
416
  queryClient.invalidateQueries({
393
417
  queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
394
418
  });
@@ -629,7 +653,7 @@ function useMigrateWalletToPasskey() {
629
653
  };
630
654
  } catch (error) {
631
655
  if (error instanceof Error) {
632
- throw new Error(`Migration failed: ${error.message}`);
656
+ throw withErrorCode(new Error(`Migration failed: ${error.message}`), error);
633
657
  }
634
658
  throw new Error("Failed to migrate wallet to passkey");
635
659
  }