@embarkai/ui-kit 0.4.19 → 0.4.20

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.cjs CHANGED
@@ -710,10 +710,13 @@ async function signDigestWithMpc(userId, digest32, userOpDetails) {
710
710
  if (!accessToken) {
711
711
  throw new Error("No access token available for signing");
712
712
  }
713
+ const batchOperations = userOpDetails?.operations || [];
714
+ const firstBatchOperation = batchOperations[0];
715
+ const batchValue = batchOperations.length > 0 ? batchOperations.reduce((total, operation) => total + BigInt(operation.value || "0"), 0n).toString() : void 0;
713
716
  const transaction = {
714
- to: userOpDetails?.callTarget || "0x0000000000000000000000000000000000000000",
715
- value: userOpDetails?.value || "0",
716
- data: userOpDetails?.callData || "0x",
717
+ to: userOpDetails?.callTarget || firstBatchOperation?.to || "0x0000000000000000000000000000000000000000",
718
+ value: userOpDetails?.value || batchValue || "0",
719
+ data: userOpDetails?.callData || firstBatchOperation?.data || "0x",
717
720
  digest32,
718
721
  // Pre-computed digest - DO NOT recompute!
719
722
  // Additional UserOp fields for display in confirmation modal
@@ -1049,11 +1052,14 @@ var init_BalanceFeedProvider2 = __esm({
1049
1052
  });
1050
1053
 
1051
1054
  // src/internal/clients/account/constants.ts
1052
- var PAYMASTER_VERIFICATION_GAS_LIMIT, PAYMASTER_POSTOP_GAS_LIMIT, SALT_ZERO, SALT_ZERO_UINT256, COMPAT_CREATE_ABI, executeAbi, entryPointDepositAbi;
1055
+ var PAYMASTER_VERIFICATION_GAS_LIMIT, PAYMASTER_POSTOP_GAS_LIMIT, MAX_BUNDLER_VERIFICATION_GAS, PAYMASTER_VERIFICATION_GAS, PAYMASTER_POSTOP_GAS, SALT_ZERO, SALT_ZERO_UINT256, COMPAT_CREATE_ABI, executeAbi, executeBatchAbi, entryPointDepositAbi;
1053
1056
  var init_constants2 = __esm({
1054
1057
  "src/internal/clients/account/constants.ts"() {
1055
1058
  PAYMASTER_VERIFICATION_GAS_LIMIT = "0x249f0";
1056
1059
  PAYMASTER_POSTOP_GAS_LIMIT = "0x186a0";
1060
+ MAX_BUNDLER_VERIFICATION_GAS = 5000000n;
1061
+ PAYMASTER_VERIFICATION_GAS = 150000n;
1062
+ PAYMASTER_POSTOP_GAS = 100000n;
1057
1063
  SALT_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000";
1058
1064
  SALT_ZERO_UINT256 = 0n;
1059
1065
  COMPAT_CREATE_ABI = [
@@ -1081,6 +1087,19 @@ var init_constants2 = __esm({
1081
1087
  outputs: []
1082
1088
  }
1083
1089
  ];
1090
+ executeBatchAbi = [
1091
+ {
1092
+ type: "function",
1093
+ name: "executeBatch",
1094
+ stateMutability: "payable",
1095
+ inputs: [
1096
+ { name: "dest", type: "address[]" },
1097
+ { name: "value", type: "uint256[]" },
1098
+ { name: "func", type: "bytes[]" }
1099
+ ],
1100
+ outputs: []
1101
+ }
1102
+ ];
1084
1103
  entryPointDepositAbi = [
1085
1104
  {
1086
1105
  type: "function",
@@ -1285,317 +1304,6 @@ var init_ChainSync2 = __esm({
1285
1304
  }
1286
1305
  });
1287
1306
 
1288
- // src/internal/akHelpers.ts
1289
- async function fetchEntryPointNonce(account, entryPoint, context) {
1290
- const { client } = context;
1291
- try {
1292
- const nonce = await client.readContract({
1293
- address: entryPoint,
1294
- abi: ENTRY_POINT_NONCE_ABI,
1295
- functionName: "getNonce",
1296
- args: [account, 0n]
1297
- });
1298
- if (typeof nonce === "bigint") return `0x${nonce.toString(16)}`;
1299
- } catch {
1300
- }
1301
- return "0x0";
1302
- }
1303
- var pack2x128;
1304
- var init_akHelpers = __esm({
1305
- "src/internal/akHelpers.ts"() {
1306
- init_abis();
1307
- pack2x128 = (hi, lo) => {
1308
- return `0x${(hi << 128n | lo & (1n << 128n) - 1n).toString(16).padStart(64, "0")}`;
1309
- };
1310
- }
1311
- });
1312
-
1313
- // src/internal/clients/account/resolve-paymaster.ts
1314
- async function resolveUiKitPaymaster(chainId, shouldUsePaymaster) {
1315
- if (!shouldUsePaymaster) {
1316
- return {
1317
- address: null,
1318
- source: "none",
1319
- chainId
1320
- };
1321
- }
1322
- const chainConfig = (0, import_read3.getChainConfig)(chainId);
1323
- return (0, import_core.resolveProjectPaymaster)({
1324
- chainId,
1325
- projectId: getProjectId(),
1326
- defaultPaymasterAddress: chainConfig?.paymasterAddress,
1327
- dashboardApiUrl: getDashboardApiUrl()
1328
- });
1329
- }
1330
- var import_core, import_read3;
1331
- var init_resolve_paymaster = __esm({
1332
- "src/internal/clients/account/resolve-paymaster.ts"() {
1333
- import_core = require("@embarkai/core");
1334
- import_read3 = require("@embarkai/core/read");
1335
- init_base();
1336
- init_projectId();
1337
- }
1338
- });
1339
-
1340
- // src/internal/clients/account/deposit-for-smart-account.ts
1341
- async function depositForSmartAccount(address, amountEth = "0.01") {
1342
- const chainId = requireActiveChainId();
1343
- const chainConfig = (0, import_read4.getChainConfig)(chainId);
1344
- if (!FUNDER_PK) throw new Error("VITE_FUNDER_PK is not set");
1345
- const entryPointAddress = chainConfig.entryPointV07Address;
1346
- const funder = (0, import_accounts.privateKeyToAccount)(FUNDER_PK);
1347
- const viemChain = (0, import_read4.getViemChain)(chainId);
1348
- const wallet = (0, import_viem3.createWalletClient)({
1349
- account: funder,
1350
- chain: viemChain,
1351
- transport: (0, import_viem3.http)(viemChain.rpcUrls.default.http[0])
1352
- });
1353
- const hash = await wallet.writeContract({
1354
- address: entryPointAddress,
1355
- abi: entryPointDepositAbi,
1356
- functionName: "depositTo",
1357
- args: [address],
1358
- value: (0, import_viem3.parseEther)(amountEth),
1359
- type: "legacy",
1360
- gasPrice: 1000000000n
1361
- });
1362
- return hash;
1363
- }
1364
- var import_read4, import_viem3, import_accounts;
1365
- var init_deposit_for_smart_account = __esm({
1366
- "src/internal/clients/account/deposit-for-smart-account.ts"() {
1367
- init_index();
1368
- import_read4 = require("@embarkai/core/read");
1369
- import_viem3 = require("viem");
1370
- import_accounts = require("viem/accounts");
1371
- init_base();
1372
- init_constants2();
1373
- }
1374
- });
1375
-
1376
- // src/internal/clients/account/user-operations.ts
1377
- async function sendUserOperation(session, params) {
1378
- const chainId = params.chainId ?? requireActiveChainId();
1379
- const chainConfig = (0, import_read5.getChainConfig)(chainId);
1380
- if (!chainConfig) {
1381
- throw new Error(`Chain ${chainId} is not supported`);
1382
- }
1383
- const chainPublicClient = (0, import_read5.createPublicClientForChain)(chainId);
1384
- const bundlerUrl = chainConfig.bundlerUrl;
1385
- const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
1386
- const entryPointAddress = chainConfig.entryPointV07Address;
1387
- const amountWeiBigInt = BigInt(amountWei);
1388
- const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
1389
- let callData;
1390
- if (isMinimalTest) {
1391
- callData = "0x";
1392
- } else {
1393
- callData = (0, import_viem4.encodeFunctionData)({
1394
- abi: executeAbi,
1395
- functionName: "execute",
1396
- args: [callTarget, amountWeiBigInt, innerData]
1397
- });
1398
- }
1399
- let isDeployed = false;
1400
- try {
1401
- const code = await chainPublicClient.getCode({ address: session.smartAccountAddress });
1402
- if (code && code !== "0x" && code.length > 2) {
1403
- isDeployed = true;
1404
- }
1405
- } catch {
1406
- }
1407
- const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
1408
- client: chainPublicClient
1409
- });
1410
- const nonceValue = BigInt(nonce);
1411
- if (!isDeployed && nonceValue !== 0n) {
1412
- throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
1413
- }
1414
- const shouldIncludeFactory = !isDeployed;
1415
- let userOp;
1416
- if (shouldIncludeFactory) {
1417
- const factoryData = (0, import_viem4.encodeFunctionData)({
1418
- abi: COMPAT_CREATE_ABI,
1419
- functionName: "createAccount",
1420
- args: [session.ownerAddress, SALT_ZERO_UINT256]
1421
- });
1422
- userOp = await (0, import_bundler.createUserOperationWithDynamicFees)(
1423
- {
1424
- sender: session.smartAccountAddress,
1425
- nonce,
1426
- callData,
1427
- includeFactory: true,
1428
- factoryAddress: session.factoryAddress,
1429
- factoryData,
1430
- feeType
1431
- },
1432
- { client: chainPublicClient, bundlerUrl, chainConfig }
1433
- );
1434
- } else {
1435
- userOp = await (0, import_bundler.createUserOperationWithDynamicFees)(
1436
- {
1437
- sender: session.smartAccountAddress,
1438
- nonce,
1439
- callData,
1440
- includeFactory: false,
1441
- feeType
1442
- },
1443
- { client: chainPublicClient, bundlerUrl, chainConfig }
1444
- );
1445
- }
1446
- const storeUsePaymaster = useSession.getState().usePaymaster;
1447
- const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
1448
- const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
1449
- if (resolvedPaymaster.address) {
1450
- userOp.paymaster = resolvedPaymaster.address;
1451
- userOp.paymasterData = "0x";
1452
- userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT;
1453
- userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT;
1454
- }
1455
- try {
1456
- const gasEst = await (0, import_bundler.estimateUserOperationGas)(
1457
- { ...userOp, signature: `0x${"00".repeat(65)}` },
1458
- { chainId: chainConfig.id, retryWithoutFactory: true }
1459
- );
1460
- console.log("[Account] Gas estimation from bundler:", {
1461
- callGasLimit: gasEst.callGasLimit,
1462
- verificationGasLimit: gasEst.verificationGasLimit,
1463
- preVerificationGas: gasEst.preVerificationGas
1464
- });
1465
- userOp.callGasLimit = gasEst.callGasLimit;
1466
- userOp.verificationGasLimit = gasEst.verificationGasLimit;
1467
- userOp.preVerificationGas = gasEst.preVerificationGas;
1468
- } catch (e) {
1469
- console.log("[Account] Gas estimation failed:", e);
1470
- throw new Error(`Gas estimation failed: ${e}`);
1471
- }
1472
- const signUserOp = async (nonce2) => {
1473
- userOp.nonce = nonce2;
1474
- const hasFactoryData = !!(userOp.factory && userOp.factoryData);
1475
- const initCode = hasFactoryData ? (() => {
1476
- const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
1477
- const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
1478
- return `0x${factoryAddr}${factoryDataClean}`;
1479
- })() : "0x";
1480
- const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
1481
- const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
1482
- let paymasterAndData = "0x";
1483
- if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
1484
- const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
1485
- const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
1486
- const paymasterDataField = userOp.paymasterData || "0x";
1487
- const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
1488
- const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
1489
- const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
1490
- paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
1491
- }
1492
- const packedForHash = {
1493
- sender: session.smartAccountAddress,
1494
- nonce: BigInt(nonce2),
1495
- initCode,
1496
- callData,
1497
- accountGasLimits,
1498
- preVerificationGas: BigInt(userOp.preVerificationGas),
1499
- gasFees,
1500
- paymasterAndData,
1501
- signature: "0x"
1502
- };
1503
- const opHash = await chainPublicClient.readContract({
1504
- address: entryPointAddress,
1505
- abi: import_account_abstraction.entryPoint07Abi,
1506
- functionName: "getUserOpHash",
1507
- args: [packedForHash]
1508
- });
1509
- let signature;
1510
- if (session.mpcUserId) {
1511
- signature = await signDigestWithMpc(session.mpcUserId, opHash, {
1512
- sender: userOp.sender,
1513
- nonce: userOp.nonce,
1514
- callData: userOp.callData,
1515
- callGasLimit: userOp.callGasLimit,
1516
- verificationGasLimit: userOp.verificationGasLimit,
1517
- preVerificationGas: userOp.preVerificationGas,
1518
- maxFeePerGas: userOp.maxFeePerGas,
1519
- maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
1520
- paymaster: userOp.paymaster,
1521
- factory: userOp.factory,
1522
- factoryData: userOp.factoryData,
1523
- callTarget,
1524
- value: amountWei
1525
- });
1526
- } else if (session.ownerPrivateKey) {
1527
- const account = (0, import_accounts2.privateKeyToAccount)(session.ownerPrivateKey);
1528
- const rawSig = await account.sign({ hash: opHash });
1529
- signature = normalizeSignature(rawSig);
1530
- } else {
1531
- throw new Error("No signing method available");
1532
- }
1533
- userOp.signature = signature;
1534
- if (typeof userOp.sender !== "string") {
1535
- userOp.sender = session.smartAccountAddress;
1536
- }
1537
- return userOp;
1538
- };
1539
- userOp = await signUserOp(nonce);
1540
- const hash = await (0, import_bundler.sendUserOperationWithRetry)(userOp, signUserOp, { chainId, maxRetries: 1 });
1541
- return hash;
1542
- }
1543
- var import_bundler, import_read5, import_viem4, import_account_abstraction, import_accounts2;
1544
- var init_user_operations = __esm({
1545
- "src/internal/clients/account/user-operations.ts"() {
1546
- init_SessionContext();
1547
- import_bundler = require("@embarkai/core/bundler");
1548
- import_read5 = require("@embarkai/core/read");
1549
- import_viem4 = require("viem");
1550
- import_account_abstraction = require("viem/account-abstraction");
1551
- import_accounts2 = require("viem/accounts");
1552
- init_akHelpers();
1553
- init_iframe_mpc_client();
1554
- init_constants2();
1555
- init_helpers();
1556
- init_resolve_paymaster();
1557
- }
1558
- });
1559
-
1560
- // src/internal/clients/account/deploy-account.ts
1561
- async function deployAccount(session, feeType = "economy", options) {
1562
- const chainId = options?.chainId ?? requireActiveChainId();
1563
- if (!options?.force) {
1564
- const publicClient = (0, import_read6.createPublicClientForChain)(chainId);
1565
- try {
1566
- const code = await publicClient.getCode({
1567
- address: session.smartAccountAddress
1568
- });
1569
- const isDeployed = code && code !== "0x" && code.length > 2;
1570
- if (isDeployed) {
1571
- console.log("[deployAccount] Account already deployed, skipping deployment");
1572
- return null;
1573
- }
1574
- console.log("[deployAccount] Account not deployed, initiating deployment");
1575
- } catch (error) {
1576
- console.warn("[deployAccount] Failed to check deployment status, proceeding with deployment:", error);
1577
- }
1578
- }
1579
- return sendUserOperation(session, {
1580
- to: "0x0000000000000000000000000000000000000000",
1581
- // to: burn address
1582
- value: "0",
1583
- // value: 0 (no funds)
1584
- data: "0x",
1585
- // data: empty (no contract call)
1586
- feeType,
1587
- chainId
1588
- });
1589
- }
1590
- var import_read6;
1591
- var init_deploy_account = __esm({
1592
- "src/internal/clients/account/deploy-account.ts"() {
1593
- init_SessionContext();
1594
- import_read6 = require("@embarkai/core/read");
1595
- init_user_operations();
1596
- }
1597
- });
1598
-
1599
1307
  // src/internal/clients/account/register-smart-account-address.ts
1600
1308
  async function registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress) {
1601
1309
  const accessToken = import_auth20.jwtTokenManager.getAccessToken();
@@ -1706,221 +1414,186 @@ var init_register_smart_account_address = __esm({
1706
1414
  }
1707
1415
  });
1708
1416
 
1709
- // src/internal/clients/account.ts
1710
- function normalizeSignature2(signature) {
1711
- const sig = signature.slice(2);
1712
- const r = sig.slice(0, 64);
1713
- const s = sig.slice(64, 128);
1714
- const v = sig.slice(128, 130);
1715
- const sBigInt = BigInt(`0x${s}`);
1716
- const secp256k1n = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
1717
- const secp256k1nHalf = secp256k1n >> 1n;
1718
- let canonicalS = sBigInt;
1719
- let canonicalV = parseInt(v, 16);
1720
- if (sBigInt > secp256k1nHalf) {
1721
- canonicalS = secp256k1n - sBigInt;
1722
- canonicalV = canonicalV === 27 ? 28 : canonicalV === 28 ? 27 : canonicalV === 0 ? 1 : 0;
1723
- }
1724
- const canonicalSHex = canonicalS.toString(16).padStart(64, "0");
1725
- const canonicalVHex = canonicalV.toString(16).padStart(2, "0");
1726
- return `0x${r}${canonicalSHex}${canonicalVHex}`;
1727
- }
1728
- async function prepareUserOperation(session, params) {
1729
- const chainId = params.chainId ?? requireActiveChainId();
1730
- const chainConfig = (0, import_read7.getChainConfig)(chainId);
1731
- const chainPublicClient = (0, import_read7.createPublicClientForChain)(chainId);
1732
- const bundlerUrl = chainConfig.bundlerUrl;
1733
- const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
1734
- const entryPointAddress = chainConfig.entryPointV07Address;
1735
- const amountWeiBigInt = BigInt(amountWei);
1736
- const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
1737
- let callData;
1738
- if (isMinimalTest) {
1739
- callData = "0x";
1740
- } else {
1741
- callData = (0, import_viem5.encodeFunctionData)({
1742
- abi: executeAbi,
1743
- functionName: "execute",
1744
- args: [callTarget, amountWeiBigInt, innerData]
1745
- });
1417
+ // src/internal/clients/account/session.ts
1418
+ async function createAccountSession(params) {
1419
+ const { privateKey, mpcUserId, usePaymaster = false, chainId } = params;
1420
+ if (!privateKey && !mpcUserId) throw new Error("Either privateKey or mpcUserId must be provided");
1421
+ if (!privateKey && mpcUserId && !mpcUserId.trim()) throw new Error("mpcUserId cannot be empty when using MPC mode");
1422
+ const chainConfig = (0, import_read3.getChainConfig)(chainId);
1423
+ if (!chainConfig) {
1424
+ throw new Error(`Chain ${chainId} is not supported`);
1746
1425
  }
1747
- let isDeployed = false;
1748
- try {
1749
- const code = await chainPublicClient.getCode({ address: session.smartAccountAddress });
1750
- if (code && code !== "0x" && code.length > 2) {
1751
- isDeployed = true;
1752
- }
1753
- } catch {
1426
+ const factoryAddress = chainConfig.factoryAddress;
1427
+ if (!factoryAddress) {
1428
+ throw new Error(`Factory address not configured for chain ${chainId}`);
1754
1429
  }
1755
- const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
1756
- client: chainPublicClient
1757
- });
1758
- const nonceValue = BigInt(nonce);
1759
- if (!isDeployed && nonceValue !== 0n) {
1760
- throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
1430
+ const publicClient = (0, import_read3.createPublicClientForChain)(chainId);
1431
+ let ownerAddress;
1432
+ let ownerPrivateKey;
1433
+ if (privateKey) {
1434
+ const account = (0, import_accounts.privateKeyToAccount)(privateKey);
1435
+ ownerAddress = account.address;
1436
+ ownerPrivateKey = privateKey;
1437
+ } else if (mpcUserId) {
1438
+ const dkgResult = await ensureDkgAndGetOwner(mpcUserId);
1439
+ if (!dkgResult.ownerAddress) throw new Error("Failed to get owner address from DKG");
1440
+ ownerAddress = dkgResult.ownerAddress;
1441
+ } else {
1442
+ throw new Error("Either privateKey or mpcUserId must be provided");
1761
1443
  }
1762
- const shouldIncludeFactory = !isDeployed;
1763
- let userOp;
1764
- if (shouldIncludeFactory) {
1765
- const factoryData = (0, import_viem5.encodeFunctionData)({
1766
- abi: COMPAT_CREATE_ABI,
1767
- functionName: "createAccount",
1768
- args: [session.ownerAddress, SALT_ZERO_UINT256]
1444
+ const smartAccountAddress = await predictCompatAddress(ownerAddress, factoryAddress, SALT_ZERO, { client: publicClient });
1445
+ if (mpcUserId) {
1446
+ registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress).catch((error) => {
1447
+ console.warn("[Account] Background Smart Account registration failed:", error);
1769
1448
  });
1770
- userOp = await (0, import_bundler2.createUserOperationWithDynamicFees)(
1771
- {
1772
- sender: session.smartAccountAddress,
1773
- nonce,
1774
- callData,
1775
- includeFactory: true,
1776
- factoryAddress: session.factoryAddress,
1777
- factoryData,
1778
- feeType
1779
- },
1780
- { client: chainPublicClient, bundlerUrl, chainConfig }
1781
- );
1782
- } else {
1783
- userOp = await (0, import_bundler2.createUserOperationWithDynamicFees)(
1784
- {
1785
- sender: session.smartAccountAddress,
1786
- nonce,
1787
- callData,
1788
- includeFactory: false,
1789
- feeType
1790
- },
1791
- { client: chainPublicClient, bundlerUrl, chainConfig }
1792
- );
1793
1449
  }
1794
- const storeUsePaymaster = useSession.getState().usePaymaster;
1795
- const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
1796
- const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
1797
- if (resolvedPaymaster.address) {
1798
- userOp.paymaster = resolvedPaymaster.address;
1799
- userOp.paymasterData = "0x";
1800
- userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT2;
1801
- userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT2;
1450
+ return {
1451
+ ownerAddress,
1452
+ smartAccountAddress,
1453
+ factoryAddress,
1454
+ ownerPrivateKey,
1455
+ mpcUserId: privateKey ? void 0 : mpcUserId,
1456
+ usePaymaster,
1457
+ kind: "lumia",
1458
+ address: smartAccountAddress
1459
+ };
1460
+ }
1461
+ var import_accounts, import_read3;
1462
+ var init_session = __esm({
1463
+ "src/internal/clients/account/session.ts"() {
1464
+ import_accounts = require("viem/accounts");
1465
+ import_read3 = require("@embarkai/core/read");
1466
+ init_iframe_mpc_client();
1467
+ init_constants2();
1468
+ init_helpers();
1469
+ init_register_smart_account_address();
1802
1470
  }
1471
+ });
1472
+
1473
+ // src/internal/akHelpers.ts
1474
+ async function fetchEntryPointNonce(account, entryPoint, context) {
1475
+ const { client } = context;
1803
1476
  try {
1804
- const gasEst = await (0, import_bundler2.estimateUserOperationGas)(userOp, { chainId, retryWithoutFactory: true });
1805
- console.log("[Account] Gas estimation from bundler:", {
1806
- callGasLimit: gasEst.callGasLimit,
1807
- verificationGasLimit: gasEst.verificationGasLimit,
1808
- preVerificationGas: gasEst.preVerificationGas
1477
+ const nonce = await client.readContract({
1478
+ address: entryPoint,
1479
+ abi: ENTRY_POINT_NONCE_ABI,
1480
+ functionName: "getNonce",
1481
+ args: [account, 0n]
1809
1482
  });
1810
- userOp.callGasLimit = gasEst.callGasLimit;
1811
- userOp.verificationGasLimit = gasEst.verificationGasLimit;
1812
- userOp.preVerificationGas = gasEst.preVerificationGas;
1813
- } catch (e) {
1814
- console.log("[Account] Gas estimation failed:", e);
1815
- throw new Error(`Gas estimation failed: ${e}`);
1483
+ if (typeof nonce === "bigint") return `0x${nonce.toString(16)}`;
1484
+ } catch {
1816
1485
  }
1817
- userOp.nonce = nonce;
1818
- const hasFactoryData = !!(userOp.factory && userOp.factoryData);
1819
- const initCode = hasFactoryData ? (() => {
1820
- const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
1821
- const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
1822
- return `0x${factoryAddr}${factoryDataClean}`;
1823
- })() : "0x";
1824
- const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
1825
- const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
1826
- let paymasterAndData = "0x";
1827
- if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
1828
- const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
1829
- const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
1830
- const paymasterDataField = userOp.paymasterData || "0x";
1831
- const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
1832
- const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
1833
- const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
1834
- paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
1486
+ return "0x0";
1487
+ }
1488
+ var pack2x128;
1489
+ var init_akHelpers = __esm({
1490
+ "src/internal/akHelpers.ts"() {
1491
+ init_abis();
1492
+ pack2x128 = (hi, lo) => {
1493
+ return `0x${(hi << 128n | lo & (1n << 128n) - 1n).toString(16).padStart(64, "0")}`;
1494
+ };
1835
1495
  }
1836
- const packedForHash = {
1837
- sender: session.smartAccountAddress,
1838
- nonce: BigInt(nonce),
1839
- initCode,
1840
- callData,
1841
- accountGasLimits,
1842
- preVerificationGas: BigInt(userOp.preVerificationGas),
1843
- gasFees,
1844
- paymasterAndData,
1845
- signature: "0x"
1846
- };
1847
- const opHash = await chainPublicClient.readContract({
1848
- address: entryPointAddress,
1849
- abi: import_account_abstraction2.entryPoint07Abi,
1850
- functionName: "getUserOpHash",
1851
- args: [packedForHash]
1496
+ });
1497
+
1498
+ // src/internal/clients/account/resolve-paymaster.ts
1499
+ async function resolveUiKitPaymaster(chainId, shouldUsePaymaster) {
1500
+ if (!shouldUsePaymaster) {
1501
+ return {
1502
+ address: null,
1503
+ source: "none",
1504
+ chainId
1505
+ };
1506
+ }
1507
+ const chainConfig = (0, import_read4.getChainConfig)(chainId);
1508
+ return (0, import_core.resolveProjectPaymaster)({
1509
+ chainId,
1510
+ projectId: getProjectId(),
1511
+ defaultPaymasterAddress: chainConfig?.paymasterAddress,
1512
+ dashboardApiUrl: getDashboardApiUrl()
1852
1513
  });
1853
- let signature;
1854
- if (session.mpcUserId) {
1855
- signature = await signDigestWithMpc(session.mpcUserId, opHash, {
1856
- sender: userOp.sender,
1857
- nonce: userOp.nonce,
1858
- callData: userOp.callData,
1859
- callGasLimit: userOp.callGasLimit,
1860
- verificationGasLimit: userOp.verificationGasLimit,
1861
- preVerificationGas: userOp.preVerificationGas,
1862
- maxFeePerGas: userOp.maxFeePerGas,
1863
- maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
1864
- paymaster: userOp.paymaster,
1865
- factory: userOp.factory,
1866
- factoryData: userOp.factoryData
1867
- });
1868
- } else if (session.ownerPrivateKey) {
1869
- const account = (0, import_accounts3.privateKeyToAccount)(session.ownerPrivateKey);
1870
- const rawSig = await account.sign({ hash: opHash });
1871
- signature = normalizeSignature2(rawSig);
1872
- } else {
1873
- throw new Error("No signing method available");
1514
+ }
1515
+ var import_core, import_read4;
1516
+ var init_resolve_paymaster = __esm({
1517
+ "src/internal/clients/account/resolve-paymaster.ts"() {
1518
+ import_core = require("@embarkai/core");
1519
+ import_read4 = require("@embarkai/core/read");
1520
+ init_base();
1521
+ init_projectId();
1874
1522
  }
1875
- userOp.signature = signature;
1876
- if (typeof userOp.sender !== "string") {
1877
- userOp.sender = session.smartAccountAddress;
1523
+ });
1524
+
1525
+ // src/internal/clients/account/user-operations.ts
1526
+ function resolveExecutionContext(chainIdOverride) {
1527
+ const chainId = chainIdOverride ?? requireActiveChainId();
1528
+ const chainConfig = (0, import_read5.getChainConfig)(chainId);
1529
+ if (!chainConfig) {
1530
+ throw new Error(`Chain ${chainId} is not supported`);
1878
1531
  }
1879
- return { userOp, userOpHash: opHash };
1532
+ return {
1533
+ bundlerUrl: chainConfig.bundlerUrl,
1534
+ chainConfig,
1535
+ chainId,
1536
+ chainPublicClient: (0, import_read5.createPublicClientForChain)(chainId),
1537
+ entryPointAddress: chainConfig.entryPointV07Address
1538
+ };
1880
1539
  }
1881
- async function sendUserOperation2(session, params) {
1882
- const chainId = params.chainId ?? requireActiveChainId();
1883
- const chainConfig = (0, import_read7.getChainConfig)(chainId);
1884
- const chainPublicClient = (0, import_read7.createPublicClientForChain)(chainId);
1885
- const bundlerUrl = chainConfig.bundlerUrl;
1886
- const { to: callTarget, value: amountWei, data: innerData = "0x", feeType = "standard" } = params;
1887
- const entryPointAddress = chainConfig.entryPointV07Address;
1888
- const amountWeiBigInt = BigInt(amountWei);
1889
- const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && amountWei === "0" && innerData === "0x";
1890
- let callData;
1540
+ function encodeSingleExecution(params) {
1541
+ const { to: callTarget, value, data = "0x" } = params;
1542
+ const amountWeiBigInt = BigInt(value);
1543
+ const isMinimalTest = callTarget === "0x0000000000000000000000000000000000000000" && value === "0" && data === "0x";
1891
1544
  if (isMinimalTest) {
1892
- callData = "0x";
1893
- } else {
1894
- callData = (0, import_viem5.encodeFunctionData)({
1545
+ return {
1546
+ callData: "0x",
1547
+ signingMetadata: { callTarget, value }
1548
+ };
1549
+ }
1550
+ return {
1551
+ callData: (0, import_viem3.encodeFunctionData)({
1895
1552
  abi: executeAbi,
1896
1553
  functionName: "execute",
1897
- args: [callTarget, amountWeiBigInt, innerData]
1898
- });
1554
+ args: [callTarget, amountWeiBigInt, data]
1555
+ }),
1556
+ signingMetadata: { callTarget, value }
1557
+ };
1558
+ }
1559
+ function encodeBatchExecution(operations) {
1560
+ if (!operations.length) {
1561
+ throw new Error("At least one operation is required for batch UserOperation");
1899
1562
  }
1900
- let isDeployed = false;
1563
+ return {
1564
+ callData: (0, import_viem3.encodeFunctionData)({
1565
+ abi: executeBatchAbi,
1566
+ functionName: "executeBatch",
1567
+ args: [operations.map((operation) => operation.to), operations.map((operation) => BigInt(operation.value)), operations.map((operation) => operation.data)]
1568
+ }),
1569
+ signingMetadata: { operations }
1570
+ };
1571
+ }
1572
+ async function isAccountDeployed(context, smartAccountAddress) {
1901
1573
  try {
1902
- const code = await chainPublicClient.getCode({ address: session.smartAccountAddress });
1903
- if (code && code !== "0x" && code.length > 2) {
1904
- isDeployed = true;
1905
- }
1574
+ const code = await context.chainPublicClient.getCode({ address: smartAccountAddress });
1575
+ return !!code && code !== "0x" && code.length > 2;
1906
1576
  } catch {
1577
+ return false;
1907
1578
  }
1908
- const nonce = await fetchEntryPointNonce(session.smartAccountAddress, entryPointAddress, {
1909
- client: chainPublicClient
1579
+ }
1580
+ async function createUnsignedUserOperation(session, context, callData, feeType) {
1581
+ const deployed = await isAccountDeployed(context, session.smartAccountAddress);
1582
+ const nonce = await fetchEntryPointNonce(session.smartAccountAddress, context.entryPointAddress, {
1583
+ client: context.chainPublicClient
1910
1584
  });
1911
1585
  const nonceValue = BigInt(nonce);
1912
- if (!isDeployed && nonceValue !== 0n) {
1586
+ if (!deployed && nonceValue !== 0n) {
1913
1587
  throw new Error(`Undeployed account has non-zero nonce: ${nonce}. This will cause CodeHashChanged error.`);
1914
1588
  }
1915
- const shouldIncludeFactory = !isDeployed;
1916
1589
  let userOp;
1917
- if (shouldIncludeFactory) {
1918
- const factoryData = (0, import_viem5.encodeFunctionData)({
1590
+ if (!deployed) {
1591
+ const factoryData = (0, import_viem3.encodeFunctionData)({
1919
1592
  abi: COMPAT_CREATE_ABI,
1920
1593
  functionName: "createAccount",
1921
1594
  args: [session.ownerAddress, SALT_ZERO_UINT256]
1922
1595
  });
1923
- userOp = await (0, import_bundler2.createUserOperationWithDynamicFees)(
1596
+ userOp = await (0, import_bundler.createUserOperationWithDynamicFees)(
1924
1597
  {
1925
1598
  sender: session.smartAccountAddress,
1926
1599
  nonce,
@@ -1930,10 +1603,10 @@ async function sendUserOperation2(session, params) {
1930
1603
  factoryData,
1931
1604
  feeType
1932
1605
  },
1933
- { client: chainPublicClient, bundlerUrl, chainConfig }
1606
+ { client: context.chainPublicClient, bundlerUrl: context.bundlerUrl, chainConfig: context.chainConfig }
1934
1607
  );
1935
1608
  } else {
1936
- userOp = await (0, import_bundler2.createUserOperationWithDynamicFees)(
1609
+ userOp = await (0, import_bundler.createUserOperationWithDynamicFees)(
1937
1610
  {
1938
1611
  sender: session.smartAccountAddress,
1939
1612
  nonce,
@@ -1941,23 +1614,23 @@ async function sendUserOperation2(session, params) {
1941
1614
  includeFactory: false,
1942
1615
  feeType
1943
1616
  },
1944
- { client: chainPublicClient, bundlerUrl, chainConfig }
1617
+ { client: context.chainPublicClient, bundlerUrl: context.bundlerUrl, chainConfig: context.chainConfig }
1945
1618
  );
1946
1619
  }
1947
1620
  const storeUsePaymaster = useSession.getState().usePaymaster;
1948
1621
  const shouldUsePaymaster = storeUsePaymaster ?? session.usePaymaster ?? false;
1949
- const resolvedPaymaster = await resolveUiKitPaymaster(chainId, shouldUsePaymaster);
1622
+ const resolvedPaymaster = await resolveUiKitPaymaster(context.chainId, shouldUsePaymaster);
1950
1623
  if (resolvedPaymaster.address) {
1951
1624
  userOp.paymaster = resolvedPaymaster.address;
1952
1625
  userOp.paymasterData = "0x";
1953
- userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT2;
1954
- userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT2;
1626
+ userOp.paymasterVerificationGasLimit = PAYMASTER_VERIFICATION_GAS_LIMIT;
1627
+ userOp.paymasterPostOpGasLimit = PAYMASTER_POSTOP_GAS_LIMIT;
1955
1628
  }
1956
1629
  try {
1957
- const gasEst = await (0, import_bundler2.estimateUserOperationGas)(userOp, {
1958
- chainId,
1959
- retryWithoutFactory: true
1960
- });
1630
+ const gasEst = await (0, import_bundler.estimateUserOperationGas)(
1631
+ { ...userOp, signature: `0x${"00".repeat(65)}` },
1632
+ { chainId: context.chainId, retryWithoutFactory: true }
1633
+ );
1961
1634
  console.log("[Account] Gas estimation from bundler:", {
1962
1635
  callGasLimit: gasEst.callGasLimit,
1963
1636
  verificationGasLimit: gasEst.verificationGasLimit,
@@ -1966,81 +1639,129 @@ async function sendUserOperation2(session, params) {
1966
1639
  userOp.callGasLimit = gasEst.callGasLimit;
1967
1640
  userOp.verificationGasLimit = gasEst.verificationGasLimit;
1968
1641
  userOp.preVerificationGas = gasEst.preVerificationGas;
1969
- } catch (e) {
1970
- console.log("[Account] Gas estimation failed:", e);
1971
- throw new Error(`Gas estimation failed: ${e}`);
1972
- }
1973
- const signUserOp = async (nonce2) => {
1974
- userOp.nonce = nonce2;
1975
- const hasFactoryData = !!(userOp.factory && userOp.factoryData);
1976
- const initCode = hasFactoryData ? (() => {
1977
- const factoryAddr = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
1978
- const factoryDataClean = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
1979
- return `0x${factoryAddr}${factoryDataClean}`;
1980
- })() : "0x";
1981
- const accountGasLimits = pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit));
1982
- const gasFees = pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas));
1983
- let paymasterAndData = "0x";
1984
- if (userOp.paymaster && userOp.paymaster !== "0x0000000000000000000000000000000000000000") {
1985
- const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
1986
- const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
1987
- const paymasterDataField = userOp.paymasterData || "0x";
1988
- const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
1989
- const paymasterAddr = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
1990
- const paymasterDataClean = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
1991
- paymasterAndData = `0x${paymasterAddr}${packedPaymasterGasLimits.slice(2)}${paymasterDataClean}`;
1992
- }
1993
- const packedForHash = {
1994
- sender: session.smartAccountAddress,
1995
- nonce: BigInt(nonce2),
1996
- initCode,
1997
- callData,
1998
- accountGasLimits,
1999
- preVerificationGas: BigInt(userOp.preVerificationGas),
2000
- gasFees,
2001
- paymasterAndData,
2002
- signature: "0x"
2003
- };
2004
- const opHash = await chainPublicClient.readContract({
2005
- address: entryPointAddress,
2006
- abi: import_account_abstraction2.entryPoint07Abi,
2007
- functionName: "getUserOpHash",
2008
- args: [packedForHash]
1642
+ } catch (error) {
1643
+ console.log("[Account] Gas estimation failed:", error);
1644
+ throw new Error(`Gas estimation failed: ${error}`);
1645
+ }
1646
+ return { nonce, userOp };
1647
+ }
1648
+ function buildInitCode(userOp) {
1649
+ if (!(userOp.factory && userOp.factoryData)) {
1650
+ return "0x";
1651
+ }
1652
+ const factoryAddress = userOp.factory.startsWith("0x") ? userOp.factory.slice(2) : userOp.factory;
1653
+ const factoryData = userOp.factoryData.startsWith("0x") ? userOp.factoryData.slice(2) : userOp.factoryData;
1654
+ return `0x${factoryAddress}${factoryData}`;
1655
+ }
1656
+ function buildPaymasterAndData(userOp) {
1657
+ if (!userOp.paymaster || userOp.paymaster === "0x0000000000000000000000000000000000000000") {
1658
+ return "0x";
1659
+ }
1660
+ const verificationGasLimit = userOp.paymasterVerificationGasLimit || "0x186a0";
1661
+ const postOpGasLimit = userOp.paymasterPostOpGasLimit || "0x186a0";
1662
+ const paymasterDataField = userOp.paymasterData || "0x";
1663
+ const packedPaymasterGasLimits = pack2x128(BigInt(verificationGasLimit), BigInt(postOpGasLimit));
1664
+ const paymasterAddress = userOp.paymaster.startsWith("0x") ? userOp.paymaster.slice(2) : userOp.paymaster;
1665
+ const paymasterData = paymasterDataField === "0x" ? "" : paymasterDataField.startsWith("0x") ? paymasterDataField.slice(2) : paymasterDataField;
1666
+ return `0x${paymasterAddress}${packedPaymasterGasLimits.slice(2)}${paymasterData}`;
1667
+ }
1668
+ async function signPreparedUserOperation(session, context, userOp, nonce, signingMetadata) {
1669
+ userOp.nonce = nonce;
1670
+ const packedForHash = {
1671
+ sender: session.smartAccountAddress,
1672
+ nonce: BigInt(nonce),
1673
+ initCode: buildInitCode(userOp),
1674
+ callData: userOp.callData,
1675
+ accountGasLimits: pack2x128(BigInt(userOp.verificationGasLimit), BigInt(userOp.callGasLimit)),
1676
+ preVerificationGas: BigInt(userOp.preVerificationGas),
1677
+ gasFees: pack2x128(BigInt(userOp.maxPriorityFeePerGas), BigInt(userOp.maxFeePerGas)),
1678
+ paymasterAndData: buildPaymasterAndData(userOp),
1679
+ signature: "0x"
1680
+ };
1681
+ const userOpHash = await context.chainPublicClient.readContract({
1682
+ address: context.entryPointAddress,
1683
+ abi: import_account_abstraction.entryPoint07Abi,
1684
+ functionName: "getUserOpHash",
1685
+ args: [packedForHash]
1686
+ });
1687
+ if (session.mpcUserId) {
1688
+ const primaryBatchOperation = signingMetadata.operations?.[0];
1689
+ userOp.signature = await signDigestWithMpc(session.mpcUserId, userOpHash, {
1690
+ sender: userOp.sender,
1691
+ nonce: userOp.nonce,
1692
+ callData: userOp.callData,
1693
+ callGasLimit: userOp.callGasLimit,
1694
+ verificationGasLimit: userOp.verificationGasLimit,
1695
+ preVerificationGas: userOp.preVerificationGas,
1696
+ maxFeePerGas: userOp.maxFeePerGas,
1697
+ maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
1698
+ paymaster: userOp.paymaster,
1699
+ factory: userOp.factory,
1700
+ factoryData: userOp.factoryData,
1701
+ callTarget: signingMetadata.callTarget ?? primaryBatchOperation?.to,
1702
+ value: signingMetadata.value,
1703
+ operations: signingMetadata.operations
2009
1704
  });
2010
- let signature;
2011
- if (session.mpcUserId) {
2012
- signature = await signDigestWithMpc(session.mpcUserId, opHash, {
2013
- sender: userOp.sender,
2014
- nonce: userOp.nonce,
2015
- callData: userOp.callData,
2016
- callGasLimit: userOp.callGasLimit,
2017
- verificationGasLimit: userOp.verificationGasLimit,
2018
- preVerificationGas: userOp.preVerificationGas,
2019
- maxFeePerGas: userOp.maxFeePerGas,
2020
- maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
2021
- paymaster: userOp.paymaster,
2022
- factory: userOp.factory,
2023
- factoryData: userOp.factoryData,
2024
- callTarget,
2025
- value: amountWei
2026
- });
2027
- } else if (session.ownerPrivateKey) {
2028
- const account = (0, import_accounts3.privateKeyToAccount)(session.ownerPrivateKey);
2029
- const rawSig = await account.sign({ hash: opHash });
2030
- signature = normalizeSignature2(rawSig);
2031
- } else {
2032
- throw new Error("No signing method available");
2033
- }
2034
- userOp.signature = signature;
2035
- if (typeof userOp.sender !== "string") {
2036
- userOp.sender = session.smartAccountAddress;
2037
- }
2038
- return userOp;
1705
+ } else if (session.ownerPrivateKey) {
1706
+ const account = (0, import_accounts2.privateKeyToAccount)(session.ownerPrivateKey);
1707
+ userOp.signature = normalizeSignature(await account.sign({ hash: userOpHash }));
1708
+ } else {
1709
+ throw new Error("No signing method available");
1710
+ }
1711
+ if (typeof userOp.sender !== "string") {
1712
+ userOp.sender = session.smartAccountAddress;
1713
+ }
1714
+ return { userOp, userOpHash };
1715
+ }
1716
+ async function prepareExecutionUserOperation(session, params, callData, signingMetadata) {
1717
+ const context = resolveExecutionContext(params.chainId);
1718
+ const { nonce, userOp } = await createUnsignedUserOperation(session, context, callData, params.feeType ?? "standard");
1719
+ return signPreparedUserOperation(session, context, userOp, nonce, signingMetadata);
1720
+ }
1721
+ async function sendExecutionUserOperation(session, params, callData, signingMetadata) {
1722
+ const context = resolveExecutionContext(params.chainId);
1723
+ const { nonce, userOp } = await createUnsignedUserOperation(session, context, callData, params.feeType ?? "standard");
1724
+ const signUserOp = async (nextNonce) => {
1725
+ const { userOp: signedUserOp2 } = await signPreparedUserOperation(session, context, userOp, nextNonce, signingMetadata);
1726
+ return signedUserOp2;
2039
1727
  };
2040
- userOp = await signUserOp(nonce);
2041
- const hash = await (0, import_bundler2.sendUserOperationWithRetry)(userOp, signUserOp, { maxRetries: 1, chainId });
2042
- return hash;
1728
+ const signedUserOp = await signUserOp(nonce);
1729
+ return (0, import_bundler.sendUserOperationWithRetry)(signedUserOp, signUserOp, { chainId: context.chainId, maxRetries: 1 });
2043
1730
  }
1731
+ async function prepareUserOperation(session, params) {
1732
+ const { callData, signingMetadata } = encodeSingleExecution(params);
1733
+ return prepareExecutionUserOperation(session, params, callData, signingMetadata);
1734
+ }
1735
+ async function prepareBatchUserOperation(session, params) {
1736
+ const { callData, signingMetadata } = encodeBatchExecution(params.operations);
1737
+ return prepareExecutionUserOperation(session, params, callData, signingMetadata);
1738
+ }
1739
+ async function sendUserOperation(session, params) {
1740
+ const { callData, signingMetadata } = encodeSingleExecution(params);
1741
+ return sendExecutionUserOperation(session, params, callData, signingMetadata);
1742
+ }
1743
+ async function sendBatchUserOperation(session, params) {
1744
+ const { callData, signingMetadata } = encodeBatchExecution(params.operations);
1745
+ return sendExecutionUserOperation(session, params, callData, signingMetadata);
1746
+ }
1747
+ var import_bundler, import_read5, import_viem3, import_account_abstraction, import_accounts2;
1748
+ var init_user_operations = __esm({
1749
+ "src/internal/clients/account/user-operations.ts"() {
1750
+ init_SessionContext();
1751
+ import_bundler = require("@embarkai/core/bundler");
1752
+ import_read5 = require("@embarkai/core/read");
1753
+ import_viem3 = require("viem");
1754
+ import_account_abstraction = require("viem/account-abstraction");
1755
+ import_accounts2 = require("viem/accounts");
1756
+ init_akHelpers();
1757
+ init_iframe_mpc_client();
1758
+ init_constants2();
1759
+ init_helpers();
1760
+ init_resolve_paymaster();
1761
+ }
1762
+ });
1763
+
1764
+ // src/internal/clients/account/signing.ts
2044
1765
  async function signTypedData(session, params) {
2045
1766
  const { domain, types, primaryType, message, chainId: paramsChainId } = params;
2046
1767
  if (paramsChainId !== void 0 && domain.chainId !== void 0 && paramsChainId !== domain.chainId) {
@@ -2048,7 +1769,7 @@ async function signTypedData(session, params) {
2048
1769
  `[signTypedData] Warning: params.chainId (${paramsChainId}) differs from domain.chainId (${domain.chainId}). Using domain.chainId for EIP712 hash computation.`
2049
1770
  );
2050
1771
  }
2051
- const digest = (0, import_viem5.hashTypedData)({
1772
+ const digest = (0, import_viem4.hashTypedData)({
2052
1773
  domain,
2053
1774
  types,
2054
1775
  primaryType,
@@ -2087,94 +1808,66 @@ async function signTypedData(session, params) {
2087
1808
  } else if (session.ownerPrivateKey) {
2088
1809
  const account = (0, import_accounts3.privateKeyToAccount)(session.ownerPrivateKey);
2089
1810
  const rawSig = await account.sign({ hash: digest });
2090
- signature = normalizeSignature2(rawSig);
1811
+ signature = normalizeSignature(rawSig);
2091
1812
  } else {
2092
1813
  throw new Error("No signing method available");
2093
1814
  }
2094
1815
  return signature;
2095
1816
  }
2096
- var import_bundler2, import_read7, import_viem5, import_account_abstraction2, import_accounts3, PAYMASTER_VERIFICATION_GAS_LIMIT2, PAYMASTER_POSTOP_GAS_LIMIT2;
2097
- var init_account = __esm({
2098
- "src/internal/clients/account.ts"() {
2099
- init_constants2();
2100
- init_SessionContext();
2101
- import_bundler2 = require("@embarkai/core/bundler");
2102
- import_read7 = require("@embarkai/core/read");
2103
- import_viem5 = require("viem");
2104
- import_account_abstraction2 = require("viem/account-abstraction");
1817
+ var import_viem4, import_accounts3;
1818
+ var init_signing = __esm({
1819
+ "src/internal/clients/account/signing.ts"() {
1820
+ import_viem4 = require("viem");
2105
1821
  import_accounts3 = require("viem/accounts");
2106
- init_akHelpers();
2107
1822
  init_iframe_mpc_client();
2108
- init_resolve_paymaster();
2109
- init_deposit_for_smart_account();
2110
- init_deploy_account();
2111
- init_register_smart_account_address();
2112
- PAYMASTER_VERIFICATION_GAS_LIMIT2 = "0x249f0";
2113
- PAYMASTER_POSTOP_GAS_LIMIT2 = "0x186a0";
1823
+ init_helpers();
2114
1824
  }
2115
1825
  });
2116
1826
 
2117
- // src/internal/clients/account/session.ts
2118
- async function createAccountSession(params) {
2119
- const { privateKey, mpcUserId, usePaymaster = false, chainId } = params;
2120
- if (!privateKey && !mpcUserId) throw new Error("Either privateKey or mpcUserId must be provided");
2121
- if (!privateKey && mpcUserId && !mpcUserId.trim()) throw new Error("mpcUserId cannot be empty when using MPC mode");
2122
- const chainConfig = (0, import_read8.getChainConfig)(chainId);
2123
- if (!chainConfig) {
2124
- throw new Error(`Chain ${chainId} is not supported`);
2125
- }
2126
- const factoryAddress = chainConfig.factoryAddress;
2127
- if (!factoryAddress) {
2128
- throw new Error(`Factory address not configured for chain ${chainId}`);
2129
- }
2130
- const publicClient = (0, import_read8.createPublicClientForChain)(chainId);
2131
- let ownerAddress;
2132
- let ownerPrivateKey;
2133
- if (privateKey) {
2134
- const account = (0, import_accounts4.privateKeyToAccount)(privateKey);
2135
- ownerAddress = account.address;
2136
- ownerPrivateKey = privateKey;
2137
- } else if (mpcUserId) {
2138
- const dkgResult = await ensureDkgAndGetOwner(mpcUserId);
2139
- if (!dkgResult.ownerAddress) throw new Error("Failed to get owner address from DKG");
2140
- ownerAddress = dkgResult.ownerAddress;
2141
- } else {
2142
- throw new Error("Either privateKey or mpcUserId must be provided");
2143
- }
2144
- const smartAccountAddress = await predictCompatAddress(ownerAddress, factoryAddress, SALT_ZERO, { client: publicClient });
2145
- if (mpcUserId) {
2146
- registerSmartAccountAddress(chainId, smartAccountAddress, factoryAddress).catch((error) => {
2147
- console.warn("[Account] Background Smart Account registration failed:", error);
2148
- });
1827
+ // src/internal/clients/account/deploy-account.ts
1828
+ async function deployAccount(session, feeType = "economy", options) {
1829
+ const chainId = options?.chainId ?? requireActiveChainId();
1830
+ if (!options?.force) {
1831
+ const publicClient = (0, import_read6.createPublicClientForChain)(chainId);
1832
+ try {
1833
+ const code = await publicClient.getCode({
1834
+ address: session.smartAccountAddress
1835
+ });
1836
+ const isDeployed = code && code !== "0x" && code.length > 2;
1837
+ if (isDeployed) {
1838
+ console.log("[deployAccount] Account already deployed, skipping deployment");
1839
+ return null;
1840
+ }
1841
+ console.log("[deployAccount] Account not deployed, initiating deployment");
1842
+ } catch (error) {
1843
+ console.warn("[deployAccount] Failed to check deployment status, proceeding with deployment:", error);
1844
+ }
2149
1845
  }
2150
- return {
2151
- ownerAddress,
2152
- smartAccountAddress,
2153
- factoryAddress,
2154
- ownerPrivateKey,
2155
- mpcUserId: privateKey ? void 0 : mpcUserId,
2156
- usePaymaster,
2157
- kind: "lumia",
2158
- address: smartAccountAddress
2159
- };
1846
+ return sendUserOperation(session, {
1847
+ to: "0x0000000000000000000000000000000000000000",
1848
+ // to: burn address
1849
+ value: "0",
1850
+ // value: 0 (no funds)
1851
+ data: "0x",
1852
+ // data: empty (no contract call)
1853
+ feeType,
1854
+ chainId
1855
+ });
2160
1856
  }
2161
- var import_accounts4, import_read8;
2162
- var init_session = __esm({
2163
- "src/internal/clients/account/session.ts"() {
2164
- import_accounts4 = require("viem/accounts");
2165
- import_read8 = require("@embarkai/core/read");
2166
- init_iframe_mpc_client();
2167
- init_constants2();
2168
- init_helpers();
2169
- init_register_smart_account_address();
1857
+ var import_read6;
1858
+ var init_deploy_account = __esm({
1859
+ "src/internal/clients/account/deploy-account.ts"() {
1860
+ init_SessionContext();
1861
+ import_read6 = require("@embarkai/core/read");
1862
+ init_user_operations();
2170
1863
  }
2171
1864
  });
2172
1865
 
2173
1866
  // src/internal/clients/account/get-entry-point-deposit.ts
2174
1867
  async function getEntryPointDeposit(address) {
2175
1868
  const chainId = requireActiveChainId();
2176
- const chainConfig = (0, import_read9.getChainConfig)(chainId);
2177
- const publicClient = (0, import_read9.createPublicClientForChain)(chainId);
1869
+ const chainConfig = (0, import_read7.getChainConfig)(chainId);
1870
+ const publicClient = (0, import_read7.createPublicClientForChain)(chainId);
2178
1871
  const entryPointAddress = chainConfig.entryPointV07Address;
2179
1872
  const depositAbi = [{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ name: "", type: "uint256" }] }];
2180
1873
  return await publicClient.readContract({
@@ -2184,11 +1877,68 @@ async function getEntryPointDeposit(address) {
2184
1877
  args: [address]
2185
1878
  });
2186
1879
  }
2187
- var import_read9;
1880
+ var import_read7;
2188
1881
  var init_get_entry_point_deposit = __esm({
2189
1882
  "src/internal/clients/account/get-entry-point-deposit.ts"() {
2190
1883
  init_index();
2191
- import_read9 = require("@embarkai/core/read");
1884
+ import_read7 = require("@embarkai/core/read");
1885
+ }
1886
+ });
1887
+
1888
+ // src/internal/clients/account/deposit-for-smart-account.ts
1889
+ async function depositForSmartAccount(address, amountEth = "0.01") {
1890
+ const chainId = requireActiveChainId();
1891
+ const chainConfig = (0, import_read8.getChainConfig)(chainId);
1892
+ if (!FUNDER_PK) throw new Error("VITE_FUNDER_PK is not set");
1893
+ const entryPointAddress = chainConfig.entryPointV07Address;
1894
+ const funder = (0, import_accounts4.privateKeyToAccount)(FUNDER_PK);
1895
+ const viemChain = (0, import_read8.getViemChain)(chainId);
1896
+ const wallet = (0, import_viem5.createWalletClient)({
1897
+ account: funder,
1898
+ chain: viemChain,
1899
+ transport: (0, import_viem5.http)(viemChain.rpcUrls.default.http[0])
1900
+ });
1901
+ const hash = await wallet.writeContract({
1902
+ address: entryPointAddress,
1903
+ abi: entryPointDepositAbi,
1904
+ functionName: "depositTo",
1905
+ args: [address],
1906
+ value: (0, import_viem5.parseEther)(amountEth),
1907
+ type: "legacy",
1908
+ gasPrice: 1000000000n
1909
+ });
1910
+ return hash;
1911
+ }
1912
+ var import_read8, import_viem5, import_accounts4;
1913
+ var init_deposit_for_smart_account = __esm({
1914
+ "src/internal/clients/account/deposit-for-smart-account.ts"() {
1915
+ init_index();
1916
+ import_read8 = require("@embarkai/core/read");
1917
+ import_viem5 = require("viem");
1918
+ import_accounts4 = require("viem/accounts");
1919
+ init_base();
1920
+ init_constants2();
1921
+ }
1922
+ });
1923
+
1924
+ // src/internal/clients/account/index.ts
1925
+ var init_account = __esm({
1926
+ "src/internal/clients/account/index.ts"() {
1927
+ init_constants2();
1928
+ init_session();
1929
+ init_user_operations();
1930
+ init_signing();
1931
+ init_deploy_account();
1932
+ init_get_entry_point_deposit();
1933
+ init_deposit_for_smart_account();
1934
+ init_register_smart_account_address();
1935
+ }
1936
+ });
1937
+
1938
+ // src/internal/clients/account.ts
1939
+ var init_account2 = __esm({
1940
+ "src/internal/clients/account.ts"() {
1941
+ init_account();
2192
1942
  }
2193
1943
  });
2194
1944
 
@@ -2415,12 +2165,23 @@ var init_nickname_types = __esm({
2415
2165
  // src/internal/clients/index.ts
2416
2166
  var clients_exports = {};
2417
2167
  __export(clients_exports, {
2168
+ COMPAT_CREATE_ABI: () => COMPAT_CREATE_ABI,
2418
2169
  FUNDER_PK: () => FUNDER_PK,
2170
+ MAX_BUNDLER_VERIFICATION_GAS: () => MAX_BUNDLER_VERIFICATION_GAS,
2171
+ PAYMASTER_POSTOP_GAS: () => PAYMASTER_POSTOP_GAS,
2172
+ PAYMASTER_POSTOP_GAS_LIMIT: () => PAYMASTER_POSTOP_GAS_LIMIT,
2173
+ PAYMASTER_VERIFICATION_GAS: () => PAYMASTER_VERIFICATION_GAS,
2174
+ PAYMASTER_VERIFICATION_GAS_LIMIT: () => PAYMASTER_VERIFICATION_GAS_LIMIT,
2175
+ SALT_ZERO: () => SALT_ZERO,
2176
+ SALT_ZERO_UINT256: () => SALT_ZERO_UINT256,
2419
2177
  changeNickname: () => changeNickname,
2420
2178
  checkNicknameAvailability: () => checkNicknameAvailability,
2421
2179
  createAccountSession: () => createAccountSession,
2422
2180
  deployAccount: () => deployAccount,
2423
2181
  depositForSmartAccount: () => depositForSmartAccount,
2182
+ entryPointDepositAbi: () => entryPointDepositAbi,
2183
+ executeAbi: () => executeAbi,
2184
+ executeBatchAbi: () => executeBatchAbi,
2424
2185
  getAllSmartAccounts: () => getAllSmartAccounts,
2425
2186
  getBundlerClient: () => getBundlerClient,
2426
2187
  getDashboardApiUrl: () => getDashboardApiUrl,
@@ -2432,15 +2193,18 @@ __export(clients_exports, {
2432
2193
  getTssUrl: () => getTssUrl2,
2433
2194
  lumiaBeamTestnet: () => lumiaBeamTestnet,
2434
2195
  lumiaPrisma: () => lumiaPrisma,
2196
+ prepareBatchUserOperation: () => prepareBatchUserOperation,
2435
2197
  prepareUserOperation: () => prepareUserOperation,
2198
+ registerSmartAccountAddress: () => registerSmartAccountAddress,
2436
2199
  resolveNickname: () => resolveNickname,
2437
- sendUserOperation: () => sendUserOperation2,
2200
+ sendBatchUserOperation: () => sendBatchUserOperation,
2201
+ sendUserOperation: () => sendUserOperation,
2438
2202
  signTypedData: () => signTypedData
2439
2203
  });
2440
2204
  var init_clients = __esm({
2441
2205
  "src/internal/clients/index.ts"() {
2442
2206
  init_base();
2443
- init_account();
2207
+ init_account2();
2444
2208
  init_utils();
2445
2209
  init_nickname();
2446
2210
  init_nickname_types();
@@ -6775,14 +6539,14 @@ var init_api = __esm({
6775
6539
  });
6776
6540
 
6777
6541
  // src/internal/components/BuyMenu/binance/networks.ts
6778
- var import_read10, CHAIN_ID_TO_BINANCE_NETWORK_NAMES;
6542
+ var import_read9, CHAIN_ID_TO_BINANCE_NETWORK_NAMES;
6779
6543
  var init_networks = __esm({
6780
6544
  "src/internal/components/BuyMenu/binance/networks.ts"() {
6781
- import_read10 = require("@embarkai/core/read");
6545
+ import_read9 = require("@embarkai/core/read");
6782
6546
  CHAIN_ID_TO_BINANCE_NETWORK_NAMES = {
6783
- [import_read10.LUMIA_MAINNET_CHAIN_ID]: "LUMIA",
6784
- [import_read10.LUMIA_TESTNET_CHAIN_ID]: "LUMIA",
6785
- [import_read10.BSC_TESTNET_CHAIN_ID]: "BSC"
6547
+ [import_read9.LUMIA_MAINNET_CHAIN_ID]: "LUMIA",
6548
+ [import_read9.LUMIA_TESTNET_CHAIN_ID]: "LUMIA",
6549
+ [import_read9.BSC_TESTNET_CHAIN_ID]: "BSC"
6786
6550
  // TODO: change to BSC mainnet when supported by EmbarkAI
6787
6551
  };
6788
6552
  }
@@ -8006,14 +7770,14 @@ var init_FinchPayTxHistory = __esm({
8006
7770
  });
8007
7771
 
8008
7772
  // src/internal/components/BuyMenu/finchpay/networks.ts
8009
- var import_read11, CHAIN_ID_TO_FINCHPAY_NAME;
7773
+ var import_read10, CHAIN_ID_TO_FINCHPAY_NAME;
8010
7774
  var init_networks2 = __esm({
8011
7775
  "src/internal/components/BuyMenu/finchpay/networks.ts"() {
8012
- import_read11 = require("@embarkai/core/read");
7776
+ import_read10 = require("@embarkai/core/read");
8013
7777
  CHAIN_ID_TO_FINCHPAY_NAME = {
8014
- [import_read11.LUMIA_MAINNET_CHAIN_ID]: "LUM20",
8015
- [import_read11.LUMIA_TESTNET_CHAIN_ID]: "LUM20",
8016
- [import_read11.BSC_TESTNET_CHAIN_ID]: "BSC"
7778
+ [import_read10.LUMIA_MAINNET_CHAIN_ID]: "LUM20",
7779
+ [import_read10.LUMIA_TESTNET_CHAIN_ID]: "LUM20",
7780
+ [import_read10.BSC_TESTNET_CHAIN_ID]: "BSC"
8017
7781
  // TODO: change to BSC mainnet when supported by EmbarkAI
8018
7782
  };
8019
7783
  }
@@ -9192,7 +8956,7 @@ var init_LumiaIcon2 = __esm({
9192
8956
  });
9193
8957
 
9194
8958
  // src/config/networks.ts
9195
- var import_read12, NETWORK_OPTIONS;
8959
+ var import_read11, NETWORK_OPTIONS;
9196
8960
  var init_networks3 = __esm({
9197
8961
  "src/config/networks.ts"() {
9198
8962
  init_ArbitrumIcon();
@@ -9200,45 +8964,45 @@ var init_networks3 = __esm({
9200
8964
  init_BnbIcon2();
9201
8965
  init_EthereumIcon();
9202
8966
  init_LumiaIcon2();
9203
- import_read12 = require("@embarkai/core/read");
8967
+ import_read11 = require("@embarkai/core/read");
9204
8968
  NETWORK_OPTIONS = [
9205
8969
  {
9206
- chainId: import_read12.LUMIA_TESTNET_CHAIN_ID,
8970
+ chainId: import_read11.LUMIA_TESTNET_CHAIN_ID,
9207
8971
  name: "Lumia Beam",
9208
8972
  badge: "TESTNET",
9209
8973
  Icon: LumiaIcon2,
9210
8974
  isActive: true
9211
8975
  },
9212
8976
  {
9213
- chainId: import_read12.LUMIA_MAINNET_CHAIN_ID,
8977
+ chainId: import_read11.LUMIA_MAINNET_CHAIN_ID,
9214
8978
  name: "Lumia Prism",
9215
8979
  badge: "MAINNET",
9216
8980
  Icon: LumiaIcon2,
9217
8981
  isActive: true
9218
8982
  },
9219
8983
  {
9220
- chainId: import_read12.SEPOLIA_CHAIN_ID,
8984
+ chainId: import_read11.SEPOLIA_CHAIN_ID,
9221
8985
  name: "Sepolia",
9222
8986
  badge: "TESTNET",
9223
8987
  Icon: EthereumIcon,
9224
8988
  isActive: true
9225
8989
  },
9226
8990
  {
9227
- chainId: import_read12.BSC_TESTNET_CHAIN_ID,
8991
+ chainId: import_read11.BSC_TESTNET_CHAIN_ID,
9228
8992
  name: "BSC Testnet",
9229
8993
  badge: "TESTNET",
9230
8994
  Icon: BnbIcon2,
9231
8995
  isActive: true
9232
8996
  },
9233
8997
  {
9234
- chainId: import_read12.ARBITRUM_SEPOLIA_CHAIN_ID,
8998
+ chainId: import_read11.ARBITRUM_SEPOLIA_CHAIN_ID,
9235
8999
  name: "Arbitrum Sepolia",
9236
9000
  badge: "TESTNET",
9237
9001
  Icon: ArbitrumIcon,
9238
9002
  isActive: true
9239
9003
  },
9240
9004
  {
9241
- chainId: import_read12.BASE_SEPOLIA_CHAIN_ID,
9005
+ chainId: import_read11.BASE_SEPOLIA_CHAIN_ID,
9242
9006
  name: "Base Sepolia",
9243
9007
  badge: "TESTNET",
9244
9008
  Icon: BaseIcon,
@@ -9276,7 +9040,7 @@ var init_truncateMiddle = __esm({
9276
9040
 
9277
9041
  // src/internal/components/ChainsMenu/ChainsMenu.tsx
9278
9042
  function getPaymasterExplorerUrl(chainId, paymasterAddress) {
9279
- const chainConfig = (0, import_read13.getChainConfig)(chainId);
9043
+ const chainConfig = (0, import_read12.getChainConfig)(chainId);
9280
9044
  const explorerUrl = chainConfig?.blockExplorerUrl;
9281
9045
  if (!explorerUrl) return paymasterAddress;
9282
9046
  return `${explorerUrl.replace(/\/$/, "")}/address/${paymasterAddress}`;
@@ -9293,7 +9057,7 @@ function ChainsMenu() {
9293
9057
  const maxScrollHeight = useLayoutStore((st) => st.maxScrollHeight);
9294
9058
  const setPage = useLayoutDataStore((st) => st.setPage);
9295
9059
  const visibleNetworks = NETWORK_OPTIONS.filter((option) => option.isActive);
9296
- const activeChainConfig = activeChainId ? (0, import_read13.getChainConfig)(activeChainId) : null;
9060
+ const activeChainConfig = activeChainId ? (0, import_read12.getChainConfig)(activeChainId) : null;
9297
9061
  const activeDefaultPaymasterAddress = activeChainConfig?.paymasterAddress;
9298
9062
  const activePaymasterQuery = (0, import_react_query16.useQuery)({
9299
9063
  queryKey: ["chain-paymaster", config.current.projectId, activeChainId],
@@ -9434,7 +9198,7 @@ function ChainsMenu() {
9434
9198
  }
9435
9199
  );
9436
9200
  }
9437
- var import_core2, import_read13, import_react_query16, import_lucide_react20, import_react29, import_jsx_runtime49;
9201
+ var import_core2, import_read12, import_react_query16, import_lucide_react20, import_react29, import_jsx_runtime49;
9438
9202
  var init_ChainsMenu = __esm({
9439
9203
  "src/internal/components/ChainsMenu/ChainsMenu.tsx"() {
9440
9204
  init_networks3();
@@ -9442,7 +9206,7 @@ var init_ChainsMenu = __esm({
9442
9206
  init_SessionContext();
9443
9207
  init_useT();
9444
9208
  import_core2 = require("@embarkai/core");
9445
- import_read13 = require("@embarkai/core/read");
9209
+ import_read12 = require("@embarkai/core/read");
9446
9210
  import_react_query16 = require("@tanstack/react-query");
9447
9211
  import_lucide_react20 = require("lucide-react");
9448
9212
  import_react29 = require("react");
@@ -16782,7 +16546,7 @@ function useSendTransaction() {
16782
16546
  return null;
16783
16547
  }
16784
16548
  }
16785
- const hash = await sendUserOperation2(session, {
16549
+ const hash = await sendUserOperation(session, {
16786
16550
  to: callTarget,
16787
16551
  value: valueWei,
16788
16552
  data: innerData,
@@ -16819,7 +16583,7 @@ var init_useSendTransaction = __esm({
16819
16583
  import_react62 = require("react");
16820
16584
  import_viem11 = require("viem");
16821
16585
  init_SessionContext();
16822
- init_account();
16586
+ init_account2();
16823
16587
  ERC20_TRANSFER_ABI = [
16824
16588
  {
16825
16589
  type: "function",
@@ -18192,27 +17956,27 @@ function getHistoryUrls(params) {
18192
17956
  }
18193
17957
  return getBlockscoutHistoryUrls(params);
18194
17958
  }
18195
- var import_read14, ETHERSCAN_V2_API_URL, BLOCKSCOUT_API_URLS, CHAIN_SPECIFIC_API_URLS, ETHERSCAN_CHAINS, UNSUPPORTED_HISTORY_CHAINS, TX_HISTORY_URLS;
17959
+ var import_read13, ETHERSCAN_V2_API_URL, BLOCKSCOUT_API_URLS, CHAIN_SPECIFIC_API_URLS, ETHERSCAN_CHAINS, UNSUPPORTED_HISTORY_CHAINS, TX_HISTORY_URLS;
18196
17960
  var init_txUrls = __esm({
18197
17961
  "src/internal/components/TransactionsMenu/txUrls.ts"() {
18198
- import_read14 = require("@embarkai/core/read");
17962
+ import_read13 = require("@embarkai/core/read");
18199
17963
  init_base();
18200
17964
  ETHERSCAN_V2_API_URL = "https://api.etherscan.io/v2/api";
18201
17965
  BLOCKSCOUT_API_URLS = {
18202
- [import_read14.ARBITRUM_SEPOLIA_CHAIN_ID]: "https://arbitrum-sepolia.blockscout.com/api",
18203
- [import_read14.BASE_SEPOLIA_CHAIN_ID]: "https://base-sepolia.blockscout.com/api"
17966
+ [import_read13.ARBITRUM_SEPOLIA_CHAIN_ID]: "https://arbitrum-sepolia.blockscout.com/api",
17967
+ [import_read13.BASE_SEPOLIA_CHAIN_ID]: "https://base-sepolia.blockscout.com/api"
18204
17968
  };
18205
17969
  CHAIN_SPECIFIC_API_URLS = {};
18206
17970
  ETHERSCAN_CHAINS = /* @__PURE__ */ new Set([
18207
- import_read14.SEPOLIA_CHAIN_ID,
18208
- import_read14.ARBITRUM_SEPOLIA_CHAIN_ID,
18209
- import_read14.BASE_SEPOLIA_CHAIN_ID
17971
+ import_read13.SEPOLIA_CHAIN_ID,
17972
+ import_read13.ARBITRUM_SEPOLIA_CHAIN_ID,
17973
+ import_read13.BASE_SEPOLIA_CHAIN_ID
18210
17974
  ]);
18211
17975
  UNSUPPORTED_HISTORY_CHAINS = /* @__PURE__ */ new Set([
18212
- import_read14.BSC_TESTNET_CHAIN_ID
17976
+ import_read13.BSC_TESTNET_CHAIN_ID
18213
17977
  ]);
18214
17978
  TX_HISTORY_URLS = {
18215
- [import_read14.LUMIA_TESTNET_CHAIN_ID]: (p) => {
17979
+ [import_read13.LUMIA_TESTNET_CHAIN_ID]: (p) => {
18216
17980
  const result = getBlockscoutHistoryUrls(p);
18217
17981
  return {
18218
17982
  transactionsUrl: result.transactionsUrl,
@@ -18220,7 +17984,7 @@ var init_txUrls = __esm({
18220
17984
  tokenTransfersUrl: result.tokenTransfersUrl
18221
17985
  };
18222
17986
  },
18223
- [import_read14.LUMIA_MAINNET_CHAIN_ID]: (p) => {
17987
+ [import_read13.LUMIA_MAINNET_CHAIN_ID]: (p) => {
18224
17988
  const result = getBlockscoutHistoryUrls(p);
18225
17989
  return {
18226
17990
  transactionsUrl: result.transactionsUrl,
@@ -19384,7 +19148,7 @@ var init_package = __esm({
19384
19148
  "package.json"() {
19385
19149
  package_default = {
19386
19150
  name: "@embarkai/ui-kit",
19387
- version: "0.4.19",
19151
+ version: "0.4.20",
19388
19152
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
19389
19153
  type: "module",
19390
19154
  main: "./dist/index.cjs",
@@ -20520,9 +20284,9 @@ function getChainParams(chainCfg) {
20520
20284
  return {
20521
20285
  activeChainId: chainCfg.id,
20522
20286
  chainConfig: chainCfg,
20523
- publicClient: (0, import_read15.createPublicClientForChain)(chainCfg.id),
20524
- bundlerClient: (0, import_read15.createBundlerClientForChain)(chainCfg.id),
20525
- viemChain: (0, import_read15.getViemChain)(chainCfg.id)
20287
+ publicClient: (0, import_read14.createPublicClientForChain)(chainCfg.id),
20288
+ bundlerClient: (0, import_read14.createBundlerClientForChain)(chainCfg.id),
20289
+ viemChain: (0, import_read14.getViemChain)(chainCfg.id)
20526
20290
  };
20527
20291
  }
20528
20292
  function waitForStoreHydration() {
@@ -20548,10 +20312,10 @@ function SessionProvider({ children }) {
20548
20312
  /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(Dialog2, {})
20549
20313
  ] });
20550
20314
  }
20551
- var import_read15, import_react77, import_zustand8, import_middleware, import_jsx_runtime109, useSession, requireActiveChainId;
20315
+ var import_read14, import_react77, import_zustand8, import_middleware, import_jsx_runtime109, useSession, requireActiveChainId;
20552
20316
  var init_SessionContext = __esm({
20553
20317
  "src/context/SessionContext.tsx"() {
20554
- import_read15 = require("@embarkai/core/read");
20318
+ import_read14 = require("@embarkai/core/read");
20555
20319
  import_react77 = require("react");
20556
20320
  import_zustand8 = require("zustand");
20557
20321
  import_middleware = require("zustand/middleware");
@@ -20623,7 +20387,7 @@ var init_SessionContext = __esm({
20623
20387
  // Set default chainId after hydration if not persisted
20624
20388
  onRehydrateStorage: () => (state) => {
20625
20389
  if (!state) return;
20626
- const hydartedChain = getChainParams((0, import_read15.getChainConfig)(state.activeChainId || import_read15.DEFAULT_CHAIN_ID));
20390
+ const hydartedChain = getChainParams((0, import_read14.getChainConfig)(state.activeChainId || import_read14.DEFAULT_CHAIN_ID));
20627
20391
  state.activeChainId = hydartedChain.activeChainId;
20628
20392
  state.publicClient = hydartedChain.publicClient;
20629
20393
  state.bundlerClient = hydartedChain.bundlerClient;
@@ -20698,31 +20462,31 @@ function getExplorerUrl() {
20698
20462
  const paramUrl = typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("explorerUrl") || void 0 : void 0;
20699
20463
  const net = getSelectedNetwork();
20700
20464
  const chainId = requireActiveChainId();
20701
- const chainConfig = (0, import_read16.getChainConfig)(chainId);
20465
+ const chainConfig = (0, import_read15.getChainConfig)(chainId);
20702
20466
  console.log("[getExplorerUrl] ", paramUrl, chainConfig.blockExplorerUrl);
20703
20467
  return paramUrl || chainConfig.blockExplorerUrl;
20704
20468
  }
20705
20469
  function getBundlerClient() {
20706
20470
  const chainId = requireActiveChainId();
20707
- const chainConfig = (0, import_read16.getChainConfig)(chainId);
20708
- const viemChain = (0, import_read16.getViemChain)(chainId);
20709
- return (0, import_account_abstraction3.createBundlerClient)({
20471
+ const chainConfig = (0, import_read15.getChainConfig)(chainId);
20472
+ const viemChain = (0, import_read15.getViemChain)(chainId);
20473
+ return (0, import_account_abstraction2.createBundlerClient)({
20710
20474
  chain: viemChain,
20711
20475
  transport: (0, import_viem16.http)(chainConfig.bundlerUrl, { timeout: 1e4, retryCount: 0, fetchOptions: { mode: "cors" } })
20712
20476
  });
20713
20477
  }
20714
- var import_read16, import_viem16, import_account_abstraction3, BUILD_NETWORK, lumiaBeamTestnet, lumiaPrisma, FUNDER_PK;
20478
+ var import_read15, import_viem16, import_account_abstraction2, BUILD_NETWORK, lumiaBeamTestnet, lumiaPrisma, FUNDER_PK;
20715
20479
  var init_base = __esm({
20716
20480
  "src/internal/clients/base.ts"() {
20717
20481
  init_initial();
20718
20482
  init_SessionContext();
20719
- import_read16 = require("@embarkai/core/read");
20483
+ import_read15 = require("@embarkai/core/read");
20720
20484
  import_viem16 = require("viem");
20721
- import_account_abstraction3 = require("viem/account-abstraction");
20485
+ import_account_abstraction2 = require("viem/account-abstraction");
20722
20486
  init_env();
20723
20487
  BUILD_NETWORK = true ? "" : "";
20724
- lumiaBeamTestnet = import_read16.lumiaTestnetChain;
20725
- lumiaPrisma = import_read16.lumiaMainnetChain;
20488
+ lumiaBeamTestnet = import_read15.lumiaTestnetChain;
20489
+ lumiaPrisma = import_read15.lumiaMainnetChain;
20726
20490
  FUNDER_PK = getEnvVar("VITE_FUNDER_PK") || "";
20727
20491
  }
20728
20492
  });
@@ -22963,10 +22727,10 @@ var init_iframe_manager = __esm({
22963
22727
  });
22964
22728
 
22965
22729
  // src/config/rainbowkit.ts
22966
- var import_read17, import_rainbowkit2, import_wallets, import_wagmi4, import_chains, getProjectId2, WALLET_MAP, getWagmiStorageKey, buildRainbowChains, createRainbowConfig, rainbowTheme;
22730
+ var import_read16, import_rainbowkit2, import_wallets, import_wagmi4, import_chains, getProjectId2, WALLET_MAP, getWagmiStorageKey, buildRainbowChains, createRainbowConfig, rainbowTheme;
22967
22731
  var init_rainbowkit = __esm({
22968
22732
  "src/config/rainbowkit.ts"() {
22969
- import_read17 = require("@embarkai/core/read");
22733
+ import_read16 = require("@embarkai/core/read");
22970
22734
  import_rainbowkit2 = require("@rainbow-me/rainbowkit");
22971
22735
  import_wallets = require("@rainbow-me/rainbowkit/wallets");
22972
22736
  import_wagmi4 = require("wagmi");
@@ -22991,8 +22755,8 @@ var init_rainbowkit = __esm({
22991
22755
  };
22992
22756
  buildRainbowChains = (supportedChains, preferredChainId) => {
22993
22757
  const availableChains = [
22994
- import_read17.lumiaMainnetChain,
22995
- import_read17.lumiaTestnetChain,
22758
+ import_read16.lumiaMainnetChain,
22759
+ import_read16.lumiaTestnetChain,
22996
22760
  import_chains.mainnet,
22997
22761
  import_chains.polygon,
22998
22762
  import_chains.bsc,
@@ -23304,18 +23068,18 @@ function buildTransport(urls) {
23304
23068
  retryCount: 0
23305
23069
  });
23306
23070
  }
23307
- var import_read18, import_viem17, import_wagmi6, wagmiConfig;
23071
+ var import_read17, import_viem17, import_wagmi6, wagmiConfig;
23308
23072
  var init_wagmi = __esm({
23309
23073
  "src/config/wagmi.ts"() {
23310
- import_read18 = require("@embarkai/core/read");
23074
+ import_read17 = require("@embarkai/core/read");
23311
23075
  import_viem17 = require("viem");
23312
23076
  import_wagmi6 = require("wagmi");
23313
23077
  wagmiConfig = (0, import_wagmi6.createConfig)({
23314
- chains: [import_read18.lumiaMainnetChain, import_read18.lumiaTestnetChain],
23078
+ chains: [import_read17.lumiaMainnetChain, import_read17.lumiaTestnetChain],
23315
23079
  storage: (0, import_wagmi6.createStorage)({ key: "embark-wagmi-static-v2" }),
23316
23080
  transports: {
23317
- [import_read18.lumiaTestnetChain.id]: buildTransport(import_read18.lumiaTestnetChain.rpcUrls.default.http),
23318
- [import_read18.lumiaMainnetChain.id]: buildTransport(import_read18.lumiaMainnetChain.rpcUrls.default.http)
23081
+ [import_read17.lumiaTestnetChain.id]: buildTransport(import_read17.lumiaTestnetChain.rpcUrls.default.http),
23082
+ [import_read17.lumiaMainnetChain.id]: buildTransport(import_read17.lumiaMainnetChain.rpcUrls.default.http)
23319
23083
  }
23320
23084
  });
23321
23085
  }
@@ -23813,7 +23577,7 @@ var init_LangToggle = __esm({
23813
23577
  // src/clients/bundler/getUserOperationByHash.ts
23814
23578
  async function getUserOperationByHash(userOpHash, chainId) {
23815
23579
  const targetChainId = chainId ?? requireActiveChainId();
23816
- const chainConfig = (0, import_read19.getChainConfig)(targetChainId);
23580
+ const chainConfig = (0, import_read18.getChainConfig)(targetChainId);
23817
23581
  if (!chainConfig) {
23818
23582
  throw new Error(`Chain ${targetChainId} is not supported`);
23819
23583
  }
@@ -23841,19 +23605,19 @@ async function getUserOperationByHash(userOpHash, chainId) {
23841
23605
  return null;
23842
23606
  }
23843
23607
  }
23844
- var import_core3, import_read19;
23608
+ var import_core3, import_read18;
23845
23609
  var init_getUserOperationByHash = __esm({
23846
23610
  "src/clients/bundler/getUserOperationByHash.ts"() {
23847
23611
  init_SessionContext();
23848
23612
  import_core3 = require("@embarkai/core");
23849
- import_read19 = require("@embarkai/core/read");
23613
+ import_read18 = require("@embarkai/core/read");
23850
23614
  }
23851
23615
  });
23852
23616
 
23853
23617
  // src/clients/bundler/getUserOperationReceipt.ts
23854
23618
  async function getUserOperationReceipt(userOpHash, chainId) {
23855
23619
  const targetChainId = chainId ?? requireActiveChainId();
23856
- const chainConfig = (0, import_read20.getChainConfig)(targetChainId);
23620
+ const chainConfig = (0, import_read19.getChainConfig)(targetChainId);
23857
23621
  if (!chainConfig) {
23858
23622
  throw new Error(`Chain ${targetChainId} is not supported`);
23859
23623
  }
@@ -23887,12 +23651,12 @@ async function getUserOperationReceipt(userOpHash, chainId) {
23887
23651
  return null;
23888
23652
  }
23889
23653
  }
23890
- var import_core4, import_read20;
23654
+ var import_core4, import_read19;
23891
23655
  var init_getUserOperationReceipt = __esm({
23892
23656
  "src/clients/bundler/getUserOperationReceipt.ts"() {
23893
23657
  init_SessionContext();
23894
23658
  import_core4 = require("@embarkai/core");
23895
- import_read20 = require("@embarkai/core/read");
23659
+ import_read19 = require("@embarkai/core/read");
23896
23660
  }
23897
23661
  });
23898
23662
 
@@ -24778,7 +24542,7 @@ function useTransferToLinkedWallet() {
24778
24542
  args: [toAddress, (0, import_viem19.parseUnits)(params.amount, decimals)]
24779
24543
  });
24780
24544
  }
24781
- const hash = await sendUserOperation2(session, {
24545
+ const hash = await sendUserOperation(session, {
24782
24546
  to,
24783
24547
  value,
24784
24548
  data,
@@ -24810,7 +24574,7 @@ var init_useTransferToLinkedWallet = __esm({
24810
24574
  import_react86 = require("react");
24811
24575
  import_viem19 = require("viem");
24812
24576
  init_SessionContext();
24813
- init_account();
24577
+ init_account2();
24814
24578
  init_linkedProfiles();
24815
24579
  ERC20_TRANSFER_ABI2 = [
24816
24580
  {
@@ -24943,7 +24707,7 @@ var init_clients2 = __esm({
24943
24707
  // src/modules/transactions.ts
24944
24708
  function useTransactions() {
24945
24709
  const chainId = requireActiveChainId();
24946
- const viemChain = (0, import_read21.getViemChain)(chainId);
24710
+ const viemChain = (0, import_read20.getViemChain)(chainId);
24947
24711
  const publicClient = (0, import_wagmi12.usePublicClient)({ chainId });
24948
24712
  const { data: walletClient } = (0, import_wagmi12.useWalletClient)();
24949
24713
  const { address } = (0, import_wagmi12.useAccount)();
@@ -25001,11 +24765,11 @@ function useTransactions() {
25001
24765
  isConnected: !!address && !!walletClient
25002
24766
  };
25003
24767
  }
25004
- var import_read21, import_viem20, import_wagmi12;
24768
+ var import_read20, import_viem20, import_wagmi12;
25005
24769
  var init_transactions = __esm({
25006
24770
  "src/modules/transactions.ts"() {
25007
24771
  init_SessionContext();
25008
- import_read21 = require("@embarkai/core/read");
24772
+ import_read20 = require("@embarkai/core/read");
25009
24773
  import_viem20 = require("viem");
25010
24774
  import_wagmi12 = require("wagmi");
25011
24775
  }
@@ -25288,9 +25052,11 @@ __export(index_exports, {
25288
25052
  jwtTokenManager: () => import_auth20.jwtTokenManager,
25289
25053
  logout: () => import_auth20.logout,
25290
25054
  looksLikeNickname: () => looksLikeNickname,
25055
+ prepareBatchUserOperation: () => prepareBatchUserOperation,
25291
25056
  prepareUserOperation: () => prepareUserOperation,
25292
25057
  requireActiveChainId: () => requireActiveChainId,
25293
- sendUserOperation: () => sendUserOperation2,
25058
+ sendBatchUserOperation: () => sendBatchUserOperation,
25059
+ sendUserOperation: () => sendUserOperation,
25294
25060
  signTypedData: () => signTypedData,
25295
25061
  updateUserProfile: () => updateUserProfile,
25296
25062
  useAccountSession: () => useAccountSession,
@@ -25375,7 +25141,7 @@ var init_index = __esm({
25375
25141
  init_useNativeWalletSignature();
25376
25142
  init_useLogout();
25377
25143
  init_useNicknameResolve();
25378
- init_account();
25144
+ init_account2();
25379
25145
  init_clients2();
25380
25146
  init_auth();
25381
25147
  init_profile();
@@ -25435,8 +25201,10 @@ init_index();
25435
25201
  jwtTokenManager,
25436
25202
  logout,
25437
25203
  looksLikeNickname,
25204
+ prepareBatchUserOperation,
25438
25205
  prepareUserOperation,
25439
25206
  requireActiveChainId,
25207
+ sendBatchUserOperation,
25440
25208
  sendUserOperation,
25441
25209
  signTypedData,
25442
25210
  updateUserProfile,