@lumiapassport/ui-kit 1.14.25 → 1.15.0

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.js CHANGED
@@ -3750,6 +3750,11 @@ async function createAccountSession(params = {}) {
3750
3750
  }
3751
3751
  const saltZero = "0x0000000000000000000000000000000000000000000000000000000000000000";
3752
3752
  const smartAccountAddress = await predictCompatAddress(ownerAddress, factoryAddress, saltZero);
3753
+ if (mpcUserId) {
3754
+ registerSmartAccountAddress(smartAccountAddress).catch((error) => {
3755
+ console.warn("[Account] Background Smart Account registration failed:", error);
3756
+ });
3757
+ }
3753
3758
  return { ownerAddress, smartAccountAddress, factoryAddress, ownerPrivateKey, mpcUserId: privateKey ? void 0 : mpcUserId, usePaymaster, kind: "lumia", address: smartAccountAddress };
3754
3759
  }
3755
3760
  async function predictCompatAddress(owner, factory, salt) {
@@ -3761,6 +3766,47 @@ async function predictCompatAddress(owner, factory, salt) {
3761
3766
  throw new Error(`Failed to predict account address: ${error}`);
3762
3767
  }
3763
3768
  }
3769
+ async function registerSmartAccountAddress(smartAccountAddress) {
3770
+ const { jwtTokenManager: jwtTokenManager4 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
3771
+ const accessToken = jwtTokenManager4.getAccessToken();
3772
+ if (!accessToken) {
3773
+ console.warn("[Account] No access token available for Smart Account registration");
3774
+ return { success: true, smartAccountAddress, alreadySet: false };
3775
+ }
3776
+ const tssUrl = getTssUrl2();
3777
+ try {
3778
+ const response = await fetch(`${tssUrl}/api/tss/wallet/smart-account`, {
3779
+ method: "POST",
3780
+ headers: {
3781
+ "Authorization": `Bearer ${accessToken}`,
3782
+ "Content-Type": "application/json"
3783
+ },
3784
+ body: JSON.stringify({ smartAccountAddress })
3785
+ });
3786
+ if (!response.ok) {
3787
+ const errorData = await response.json().catch(() => ({}));
3788
+ if (response.status === 409) {
3789
+ console.warn("[Account] Smart Account address conflict:", errorData.error);
3790
+ return { success: true, smartAccountAddress, alreadySet: true };
3791
+ }
3792
+ if (response.status === 404) {
3793
+ console.warn("[Account] DKG not completed on server:", errorData.error);
3794
+ return { success: false, smartAccountAddress, alreadySet: false };
3795
+ }
3796
+ console.warn("[Account] Failed to register Smart Account:", errorData.error || response.statusText);
3797
+ return { success: false, smartAccountAddress, alreadySet: false };
3798
+ }
3799
+ const result = await response.json();
3800
+ console.log("[Account] Smart Account registered:", {
3801
+ address: result.smartAccountAddress,
3802
+ alreadySet: result.alreadySet
3803
+ });
3804
+ return result;
3805
+ } catch (error) {
3806
+ console.warn("[Account] Error registering Smart Account address:", error);
3807
+ return { success: false, smartAccountAddress, alreadySet: false };
3808
+ }
3809
+ }
3764
3810
  async function sendUserOperation(session, callTarget, amountWei, innerData = "0x", feeType = "standard", entryPointVersion = "v0.7") {
3765
3811
  const entryPointAddress = entryPointVersion === "v0.6" ? ENTRYPOINT_V06 : ENTRYPOINT_V07;
3766
3812
  const amountWeiBigInt = BigInt(amountWei);
@@ -4342,8 +4388,9 @@ async function changeNickname(handle) {
4342
4388
  }
4343
4389
  async function checkNicknameAvailability(handle) {
4344
4390
  const normalizedHandle = handle.toLowerCase().replace(/^@/, "");
4345
- const response = await tssClient.get(
4346
- `/api/auth/nicknames/${encodeURIComponent(normalizedHandle)}/check`,
4391
+ const response = await tssClient.post(
4392
+ "/api/auth/nicknames/check",
4393
+ { handle: normalizedHandle },
4347
4394
  false
4348
4395
  // Public endpoint, no auth required
4349
4396
  );
@@ -4355,14 +4402,15 @@ async function checkNicknameAvailability(handle) {
4355
4402
  }
4356
4403
  async function resolveNickname(handle) {
4357
4404
  const normalizedHandle = handle.toLowerCase().replace(/^@/, "");
4358
- const response = await tssClient.get(
4359
- `/api/auth/nicknames/${encodeURIComponent(normalizedHandle)}/resolve`,
4405
+ const response = await tssClient.post(
4406
+ "/api/auth/nicknames/resolve",
4407
+ { handle: normalizedHandle },
4360
4408
  false
4361
4409
  // Public endpoint, no auth required
4362
4410
  );
4363
4411
  if (!response.success || !response.data) {
4364
- const errorData = response.data;
4365
- if (errorData?.code === "NICKNAME_NOT_FOUND") {
4412
+ const errorData = response.data || {};
4413
+ if (errorData.code === "NICKNAME_NOT_FOUND") {
4366
4414
  const error = new Error("Nickname not found");
4367
4415
  error.code = "NICKNAME_NOT_FOUND";
4368
4416
  throw error;
@@ -5457,7 +5505,7 @@ function Header() {
5457
5505
  // package.json
5458
5506
  var package_default = {
5459
5507
  name: "@lumiapassport/ui-kit",
5460
- version: "1.14.25",
5508
+ version: "1.15.0",
5461
5509
  description: "React UI components and hooks for Lumia Passport authentication and Account Abstraction",
5462
5510
  type: "module",
5463
5511
  main: "./dist/index.cjs",
@@ -5900,12 +5948,21 @@ function useBackupStatusChanges() {
5900
5948
  const { mutate: handleBackupStatusChanged } = useMutation2({
5901
5949
  mutationFn: async (event) => {
5902
5950
  const customEvent = event;
5903
- return await getShareRecoveryStats();
5951
+ console.log("[BACKUP STATUS] changed:", customEvent?.detail);
5952
+ return { stats: await getShareRecoveryStats(), detail: customEvent?.detail };
5904
5953
  },
5905
- onSuccess: (stats) => {
5954
+ onSuccess: ({ stats, detail }) => {
5906
5955
  const hasRecoveryData = stats && (!!stats.created || !!stats?.devices?.length);
5907
5956
  if (!!hasRecoveryData) {
5957
+ console.log(
5958
+ "[BACKUP STATUS] Recovery data found after backup status change.\n Redirect to main menu:",
5959
+ detail?.navigateToMainMenu
5960
+ );
5908
5961
  setHasServerVault(true);
5962
+ if (!!detail?.navigateToMainMenu) {
5963
+ setTimeout(() => setPage("main-menu" /* MAIN_MENU */), 1e3);
5964
+ }
5965
+ console.info("[BACKUP STATUS] Recovery data found in vault, marking as has-server-vault");
5909
5966
  } else {
5910
5967
  setHasServerVault(false);
5911
5968
  setPage("keysare-backup" /* KEYSARE_BACKUP */);
@@ -8320,6 +8377,9 @@ Switch.displayName = "Switch";
8320
8377
  import { Cloud, FileDown, FileUp } from "lucide-react";
8321
8378
  import { Fragment as Fragment8, useMemo as useMemo2 } from "react";
8322
8379
 
8380
+ // src/internal/components/KeyshareRestoreMenu/hooks/useOnRestoreSuccess.ts
8381
+ import { useCallback as useCallback9 } from "react";
8382
+
8323
8383
  // src/internal/components/KeyshareRestoreMenu/hooks/useRestoreStore.ts
8324
8384
  import { create as create4 } from "zustand";
8325
8385
  var useRestoreStore = create4((set) => ({
@@ -8348,7 +8408,6 @@ var useRestoreStore = create4((set) => ({
8348
8408
  }));
8349
8409
 
8350
8410
  // src/internal/components/KeyshareRestoreMenu/hooks/useOnRestoreSuccess.ts
8351
- import { useCallback as useCallback9 } from "react";
8352
8411
  function useOnRestoreSuccess() {
8353
8412
  const { config, callbacks } = useLumiaPassportConfig();
8354
8413
  const setIsDialogForced = useLayoutStore((st) => st.setIsDialogForced);
@@ -8486,20 +8545,25 @@ function useCreateBackup() {
8486
8545
  if (!usePasskey && !restorePassword) {
8487
8546
  throw new Error("Please provide a password for the backup");
8488
8547
  }
8489
- return await iframeManager.createBackup(
8490
- passportUserId,
8491
- { method: "server", password: restorePassword },
8492
- jwt.accessToken
8493
- );
8548
+ const navigateToMainMenu = jwt.isNewUser || !hasServerVault;
8549
+ console.log("[BACKUP STATUS] is new user:", jwt.isNewUser, !hasServerVault);
8550
+ return {
8551
+ response: await iframeManager.createBackup(
8552
+ passportUserId,
8553
+ { method: "server", password: restorePassword },
8554
+ jwt.accessToken
8555
+ ),
8556
+ navigateToMainMenu
8557
+ };
8494
8558
  },
8495
- onSuccess: async (response) => {
8559
+ onSuccess: async ({ response, navigateToMainMenu }) => {
8496
8560
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
8497
8561
  if (response.success) {
8498
8562
  setSuccess("Successfully created server backup");
8499
8563
  if (typeof window !== "undefined") {
8500
8564
  window.dispatchEvent(
8501
8565
  new CustomEvent("lumia-passport-backup-status-changed", {
8502
- detail: { method: "server", success: true }
8566
+ detail: { method: "server", success: true, navigateToMainMenu }
8503
8567
  })
8504
8568
  );
8505
8569
  }
@@ -9550,6 +9614,12 @@ function KeyshareBackupMenu() {
9550
9614
  useEffect19(() => {
9551
9615
  setMainPageHeight(DEFAULT_SETTINGS_MENU_HEIGHT);
9552
9616
  return () => {
9617
+ setSuccess(null);
9618
+ setError(null);
9619
+ setRestoreFile(null);
9620
+ setRestorePassword("");
9621
+ setShowPassword(false);
9622
+ setUsePasskey(false);
9553
9623
  setMethod(null);
9554
9624
  };
9555
9625
  }, []);