@aomi-labs/client 0.1.7 → 0.1.9

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/cli.js CHANGED
@@ -2602,7 +2602,9 @@ function resolveAlchemyConfig(options) {
2602
2602
  },
2603
2603
  modeOverride,
2604
2604
  publicOnly = false,
2605
- throwOnMissingConfig = false
2605
+ throwOnMissingConfig = false,
2606
+ apiKey: preResolvedApiKey,
2607
+ gasPolicyId: preResolvedGasPolicyId
2606
2608
  } = options;
2607
2609
  if (!calls || localPrivateKey) {
2608
2610
  return null;
@@ -2620,7 +2622,7 @@ function resolveAlchemyConfig(options) {
2620
2622
  }
2621
2623
  return null;
2622
2624
  }
2623
- const apiKey = readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
2625
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
2624
2626
  if (!apiKey) {
2625
2627
  if (throwOnMissingConfig) {
2626
2628
  throw new Error("Alchemy AA requires ALCHEMY_API_KEY.");
@@ -2631,7 +2633,7 @@ function resolveAlchemyConfig(options) {
2631
2633
  if (!chain) {
2632
2634
  return null;
2633
2635
  }
2634
- const gasPolicyId = readGasPolicyEnv(
2636
+ const gasPolicyId = preResolvedGasPolicyId != null ? preResolvedGasPolicyId : readGasPolicyEnv(
2635
2637
  chainConfig.chainId,
2636
2638
  chainSlugById,
2637
2639
  ALCHEMY_GAS_POLICY_ENVS,
@@ -2674,7 +2676,8 @@ function resolvePimlicoConfig(options) {
2674
2676
  rpcUrl,
2675
2677
  modeOverride,
2676
2678
  publicOnly = false,
2677
- throwOnMissingConfig = false
2679
+ throwOnMissingConfig = false,
2680
+ apiKey: preResolvedApiKey
2678
2681
  } = options;
2679
2682
  if (!calls || localPrivateKey) {
2680
2683
  return null;
@@ -2692,7 +2695,7 @@ function resolvePimlicoConfig(options) {
2692
2695
  }
2693
2696
  return null;
2694
2697
  }
2695
- const apiKey = readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
2698
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
2696
2699
  if (!apiKey) {
2697
2700
  if (throwOnMissingConfig) {
2698
2701
  throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
@@ -2752,15 +2755,94 @@ import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
2752
2755
  import { privateKeyToAccount } from "viem/accounts";
2753
2756
  async function createAAProviderState(options) {
2754
2757
  if (options.provider === "alchemy") {
2755
- return createAlchemyAAState(options);
2758
+ return createAlchemyAAState({
2759
+ chain: options.chain,
2760
+ owner: options.owner,
2761
+ rpcUrl: options.rpcUrl,
2762
+ callList: options.callList,
2763
+ mode: options.mode,
2764
+ apiKey: options.apiKey,
2765
+ gasPolicyId: options.gasPolicyId,
2766
+ sponsored: options.sponsored
2767
+ });
2756
2768
  }
2757
- return createPimlicoAAState(options);
2769
+ return createPimlicoAAState({
2770
+ chain: options.chain,
2771
+ owner: options.owner,
2772
+ rpcUrl: options.rpcUrl,
2773
+ callList: options.callList,
2774
+ mode: options.mode,
2775
+ apiKey: options.apiKey
2776
+ });
2777
+ }
2778
+ function getDirectOwnerParams(owner) {
2779
+ return {
2780
+ kind: "ready",
2781
+ ownerParams: {
2782
+ para: void 0,
2783
+ signer: privateKeyToAccount(owner.privateKey)
2784
+ }
2785
+ };
2786
+ }
2787
+ function getParaSessionOwnerParams(owner) {
2788
+ if (owner.signer) {
2789
+ return {
2790
+ kind: "ready",
2791
+ ownerParams: __spreadValues({
2792
+ para: owner.session,
2793
+ signer: owner.signer
2794
+ }, owner.address ? { address: owner.address } : {})
2795
+ };
2796
+ }
2797
+ return {
2798
+ kind: "ready",
2799
+ ownerParams: __spreadValues({
2800
+ para: owner.session
2801
+ }, owner.address ? { address: owner.address } : {})
2802
+ };
2803
+ }
2804
+ function getSessionOwnerParams(owner) {
2805
+ switch (owner.adapter) {
2806
+ case "para":
2807
+ return getParaSessionOwnerParams(owner);
2808
+ default:
2809
+ return { kind: "unsupported_adapter", adapter: owner.adapter };
2810
+ }
2811
+ }
2812
+ function getOwnerParams(owner) {
2813
+ if (!owner) {
2814
+ return { kind: "missing" };
2815
+ }
2816
+ switch (owner.kind) {
2817
+ case "direct":
2818
+ return getDirectOwnerParams(owner);
2819
+ case "session":
2820
+ return getSessionOwnerParams(owner);
2821
+ }
2822
+ }
2823
+ function getMissingOwnerState(plan, provider) {
2824
+ return {
2825
+ plan,
2826
+ AA: null,
2827
+ isPending: false,
2828
+ error: new Error(
2829
+ `${provider} AA account creation requires a direct owner or a supported session owner.`
2830
+ )
2831
+ };
2832
+ }
2833
+ function getUnsupportedAdapterState(plan, adapter) {
2834
+ return {
2835
+ plan,
2836
+ AA: null,
2837
+ isPending: false,
2838
+ error: new Error(`Session adapter "${adapter}" is not implemented.`)
2839
+ };
2758
2840
  }
2759
2841
  async function createAlchemyAAState(options) {
2760
2842
  var _a3, _b;
2761
2843
  const {
2762
2844
  chain,
2763
- privateKey,
2845
+ owner,
2764
2846
  rpcUrl,
2765
2847
  callList,
2766
2848
  mode,
@@ -2771,7 +2853,9 @@ async function createAlchemyAAState(options) {
2771
2853
  chainsById: { [chain.id]: chain },
2772
2854
  modeOverride: mode,
2773
2855
  throwOnMissingConfig: true,
2774
- getPreferredRpcUrl: () => rpcUrl
2856
+ getPreferredRpcUrl: () => rpcUrl,
2857
+ apiKey: options.apiKey,
2858
+ gasPolicyId: options.gasPolicyId
2775
2859
  });
2776
2860
  if (!resolved) {
2777
2861
  throw new Error("Alchemy AA config resolution failed.");
@@ -2782,17 +2866,21 @@ async function createAlchemyAAState(options) {
2782
2866
  sponsorship: gasPolicyId ? resolved.plan.sponsorship : "disabled",
2783
2867
  fallbackToEoa: false
2784
2868
  });
2785
- const signer = privateKeyToAccount(privateKey);
2869
+ const ownerParams = getOwnerParams(owner);
2870
+ if (ownerParams.kind === "missing") {
2871
+ return getMissingOwnerState(plan, "alchemy");
2872
+ }
2873
+ if (ownerParams.kind === "unsupported_adapter") {
2874
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
2875
+ }
2786
2876
  try {
2787
- const smartAccount = await createAlchemySmartAccount({
2788
- para: void 0,
2789
- signer,
2877
+ const smartAccount = await createAlchemySmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
2790
2878
  apiKey,
2791
2879
  gasPolicyId,
2792
2880
  chain,
2793
2881
  rpcUrl,
2794
2882
  mode: plan.mode
2795
- });
2883
+ }));
2796
2884
  if (!smartAccount) {
2797
2885
  return {
2798
2886
  plan,
@@ -2820,7 +2908,7 @@ async function createPimlicoAAState(options) {
2820
2908
  var _a3;
2821
2909
  const {
2822
2910
  chain,
2823
- privateKey,
2911
+ owner,
2824
2912
  rpcUrl,
2825
2913
  callList,
2826
2914
  mode
@@ -2830,7 +2918,8 @@ async function createPimlicoAAState(options) {
2830
2918
  chainsById: { [chain.id]: chain },
2831
2919
  rpcUrl,
2832
2920
  modeOverride: mode,
2833
- throwOnMissingConfig: true
2921
+ throwOnMissingConfig: true,
2922
+ apiKey: options.apiKey
2834
2923
  });
2835
2924
  if (!resolved) {
2836
2925
  throw new Error("Pimlico AA config resolution failed.");
@@ -2839,16 +2928,20 @@ async function createPimlicoAAState(options) {
2839
2928
  const plan = __spreadProps(__spreadValues({}, resolved.plan), {
2840
2929
  fallbackToEoa: false
2841
2930
  });
2842
- const signer = privateKeyToAccount(privateKey);
2931
+ const ownerParams = getOwnerParams(owner);
2932
+ if (ownerParams.kind === "missing") {
2933
+ return getMissingOwnerState(plan, "pimlico");
2934
+ }
2935
+ if (ownerParams.kind === "unsupported_adapter") {
2936
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
2937
+ }
2843
2938
  try {
2844
- const smartAccount = await createPimlicoSmartAccount({
2845
- para: void 0,
2846
- signer,
2939
+ const smartAccount = await createPimlicoSmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
2847
2940
  apiKey,
2848
2941
  chain,
2849
2942
  rpcUrl,
2850
2943
  mode: plan.mode
2851
- });
2944
+ }));
2852
2945
  if (!smartAccount) {
2853
2946
  return {
2854
2947
  plan,
@@ -2915,7 +3008,7 @@ async function createCliProviderState(params) {
2915
3008
  return createAAProviderState({
2916
3009
  provider: decision.provider,
2917
3010
  chain,
2918
- privateKey,
3011
+ owner: { kind: "direct", privateKey },
2919
3012
  rpcUrl,
2920
3013
  callList,
2921
3014
  mode: decision.aaMode,
package/dist/index.cjs CHANGED
@@ -1462,7 +1462,9 @@ function resolveAlchemyConfig(options) {
1462
1462
  },
1463
1463
  modeOverride,
1464
1464
  publicOnly = false,
1465
- throwOnMissingConfig = false
1465
+ throwOnMissingConfig = false,
1466
+ apiKey: preResolvedApiKey,
1467
+ gasPolicyId: preResolvedGasPolicyId
1466
1468
  } = options;
1467
1469
  if (!calls || localPrivateKey) {
1468
1470
  return null;
@@ -1480,7 +1482,7 @@ function resolveAlchemyConfig(options) {
1480
1482
  }
1481
1483
  return null;
1482
1484
  }
1483
- const apiKey = readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
1485
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
1484
1486
  if (!apiKey) {
1485
1487
  if (throwOnMissingConfig) {
1486
1488
  throw new Error("Alchemy AA requires ALCHEMY_API_KEY.");
@@ -1491,7 +1493,7 @@ function resolveAlchemyConfig(options) {
1491
1493
  if (!chain) {
1492
1494
  return null;
1493
1495
  }
1494
- const gasPolicyId = readGasPolicyEnv(
1496
+ const gasPolicyId = preResolvedGasPolicyId != null ? preResolvedGasPolicyId : readGasPolicyEnv(
1495
1497
  chainConfig.chainId,
1496
1498
  chainSlugById,
1497
1499
  ALCHEMY_GAS_POLICY_ENVS,
@@ -1534,7 +1536,8 @@ function resolvePimlicoConfig(options) {
1534
1536
  rpcUrl,
1535
1537
  modeOverride,
1536
1538
  publicOnly = false,
1537
- throwOnMissingConfig = false
1539
+ throwOnMissingConfig = false,
1540
+ apiKey: preResolvedApiKey
1538
1541
  } = options;
1539
1542
  if (!calls || localPrivateKey) {
1540
1543
  return null;
@@ -1552,7 +1555,7 @@ function resolvePimlicoConfig(options) {
1552
1555
  }
1553
1556
  return null;
1554
1557
  }
1555
- const apiKey = readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
1558
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
1556
1559
  if (!apiKey) {
1557
1560
  if (throwOnMissingConfig) {
1558
1561
  throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
@@ -1685,15 +1688,94 @@ var import_aa_pimlico = require("@getpara/aa-pimlico");
1685
1688
  var import_accounts = require("viem/accounts");
1686
1689
  async function createAAProviderState(options) {
1687
1690
  if (options.provider === "alchemy") {
1688
- return createAlchemyAAState(options);
1691
+ return createAlchemyAAState({
1692
+ chain: options.chain,
1693
+ owner: options.owner,
1694
+ rpcUrl: options.rpcUrl,
1695
+ callList: options.callList,
1696
+ mode: options.mode,
1697
+ apiKey: options.apiKey,
1698
+ gasPolicyId: options.gasPolicyId,
1699
+ sponsored: options.sponsored
1700
+ });
1701
+ }
1702
+ return createPimlicoAAState({
1703
+ chain: options.chain,
1704
+ owner: options.owner,
1705
+ rpcUrl: options.rpcUrl,
1706
+ callList: options.callList,
1707
+ mode: options.mode,
1708
+ apiKey: options.apiKey
1709
+ });
1710
+ }
1711
+ function getDirectOwnerParams(owner) {
1712
+ return {
1713
+ kind: "ready",
1714
+ ownerParams: {
1715
+ para: void 0,
1716
+ signer: (0, import_accounts.privateKeyToAccount)(owner.privateKey)
1717
+ }
1718
+ };
1719
+ }
1720
+ function getParaSessionOwnerParams(owner) {
1721
+ if (owner.signer) {
1722
+ return {
1723
+ kind: "ready",
1724
+ ownerParams: __spreadValues({
1725
+ para: owner.session,
1726
+ signer: owner.signer
1727
+ }, owner.address ? { address: owner.address } : {})
1728
+ };
1729
+ }
1730
+ return {
1731
+ kind: "ready",
1732
+ ownerParams: __spreadValues({
1733
+ para: owner.session
1734
+ }, owner.address ? { address: owner.address } : {})
1735
+ };
1736
+ }
1737
+ function getSessionOwnerParams(owner) {
1738
+ switch (owner.adapter) {
1739
+ case "para":
1740
+ return getParaSessionOwnerParams(owner);
1741
+ default:
1742
+ return { kind: "unsupported_adapter", adapter: owner.adapter };
1743
+ }
1744
+ }
1745
+ function getOwnerParams(owner) {
1746
+ if (!owner) {
1747
+ return { kind: "missing" };
1748
+ }
1749
+ switch (owner.kind) {
1750
+ case "direct":
1751
+ return getDirectOwnerParams(owner);
1752
+ case "session":
1753
+ return getSessionOwnerParams(owner);
1689
1754
  }
1690
- return createPimlicoAAState(options);
1755
+ }
1756
+ function getMissingOwnerState(plan, provider) {
1757
+ return {
1758
+ plan,
1759
+ AA: null,
1760
+ isPending: false,
1761
+ error: new Error(
1762
+ `${provider} AA account creation requires a direct owner or a supported session owner.`
1763
+ )
1764
+ };
1765
+ }
1766
+ function getUnsupportedAdapterState(plan, adapter) {
1767
+ return {
1768
+ plan,
1769
+ AA: null,
1770
+ isPending: false,
1771
+ error: new Error(`Session adapter "${adapter}" is not implemented.`)
1772
+ };
1691
1773
  }
1692
1774
  async function createAlchemyAAState(options) {
1693
1775
  var _a, _b;
1694
1776
  const {
1695
1777
  chain,
1696
- privateKey,
1778
+ owner,
1697
1779
  rpcUrl,
1698
1780
  callList,
1699
1781
  mode,
@@ -1704,7 +1786,9 @@ async function createAlchemyAAState(options) {
1704
1786
  chainsById: { [chain.id]: chain },
1705
1787
  modeOverride: mode,
1706
1788
  throwOnMissingConfig: true,
1707
- getPreferredRpcUrl: () => rpcUrl
1789
+ getPreferredRpcUrl: () => rpcUrl,
1790
+ apiKey: options.apiKey,
1791
+ gasPolicyId: options.gasPolicyId
1708
1792
  });
1709
1793
  if (!resolved) {
1710
1794
  throw new Error("Alchemy AA config resolution failed.");
@@ -1715,17 +1799,21 @@ async function createAlchemyAAState(options) {
1715
1799
  sponsorship: gasPolicyId ? resolved.plan.sponsorship : "disabled",
1716
1800
  fallbackToEoa: false
1717
1801
  });
1718
- const signer = (0, import_accounts.privateKeyToAccount)(privateKey);
1802
+ const ownerParams = getOwnerParams(owner);
1803
+ if (ownerParams.kind === "missing") {
1804
+ return getMissingOwnerState(plan, "alchemy");
1805
+ }
1806
+ if (ownerParams.kind === "unsupported_adapter") {
1807
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
1808
+ }
1719
1809
  try {
1720
- const smartAccount = await (0, import_aa_alchemy.createAlchemySmartAccount)({
1721
- para: void 0,
1722
- signer,
1810
+ const smartAccount = await (0, import_aa_alchemy.createAlchemySmartAccount)(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
1723
1811
  apiKey,
1724
1812
  gasPolicyId,
1725
1813
  chain,
1726
1814
  rpcUrl,
1727
1815
  mode: plan.mode
1728
- });
1816
+ }));
1729
1817
  if (!smartAccount) {
1730
1818
  return {
1731
1819
  plan,
@@ -1753,7 +1841,7 @@ async function createPimlicoAAState(options) {
1753
1841
  var _a;
1754
1842
  const {
1755
1843
  chain,
1756
- privateKey,
1844
+ owner,
1757
1845
  rpcUrl,
1758
1846
  callList,
1759
1847
  mode
@@ -1763,7 +1851,8 @@ async function createPimlicoAAState(options) {
1763
1851
  chainsById: { [chain.id]: chain },
1764
1852
  rpcUrl,
1765
1853
  modeOverride: mode,
1766
- throwOnMissingConfig: true
1854
+ throwOnMissingConfig: true,
1855
+ apiKey: options.apiKey
1767
1856
  });
1768
1857
  if (!resolved) {
1769
1858
  throw new Error("Pimlico AA config resolution failed.");
@@ -1772,16 +1861,20 @@ async function createPimlicoAAState(options) {
1772
1861
  const plan = __spreadProps(__spreadValues({}, resolved.plan), {
1773
1862
  fallbackToEoa: false
1774
1863
  });
1775
- const signer = (0, import_accounts.privateKeyToAccount)(privateKey);
1864
+ const ownerParams = getOwnerParams(owner);
1865
+ if (ownerParams.kind === "missing") {
1866
+ return getMissingOwnerState(plan, "pimlico");
1867
+ }
1868
+ if (ownerParams.kind === "unsupported_adapter") {
1869
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
1870
+ }
1776
1871
  try {
1777
- const smartAccount = await (0, import_aa_pimlico.createPimlicoSmartAccount)({
1778
- para: void 0,
1779
- signer,
1872
+ const smartAccount = await (0, import_aa_pimlico.createPimlicoSmartAccount)(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
1780
1873
  apiKey,
1781
1874
  chain,
1782
1875
  rpcUrl,
1783
1876
  mode: plan.mode
1784
- });
1877
+ }));
1785
1878
  if (!smartAccount) {
1786
1879
  return {
1787
1880
  plan,