@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/index.d.cts CHANGED
@@ -644,6 +644,12 @@ interface AlchemyResolveOptions {
644
644
  modeOverride?: AAExecutionMode;
645
645
  publicOnly?: boolean;
646
646
  throwOnMissingConfig?: boolean;
647
+ /**
648
+ * Pre-resolved API key. Use this in Next.js client-side code where
649
+ * dynamic `process.env[name]` access doesn't work.
650
+ */
651
+ apiKey?: string;
652
+ gasPolicyId?: string;
647
653
  }
648
654
  interface AlchemyResolvedConfig {
649
655
  chainConfig: AAChainConfig;
@@ -664,6 +670,11 @@ interface PimlicoResolveOptions {
664
670
  modeOverride?: AAExecutionMode;
665
671
  publicOnly?: boolean;
666
672
  throwOnMissingConfig?: boolean;
673
+ /**
674
+ * Pre-resolved API key. Use this in Next.js client-side code where
675
+ * dynamic `process.env[name]` access doesn't work.
676
+ */
677
+ apiKey?: string;
667
678
  }
668
679
  interface PimlicoResolvedConfig {
669
680
  chainConfig: AAChainConfig;
@@ -675,10 +686,20 @@ interface PimlicoResolvedConfig {
675
686
  }
676
687
  declare function resolvePimlicoConfig(options: PimlicoResolveOptions): PimlicoResolvedConfig | null;
677
688
 
689
+ type CreateAAOwner = {
690
+ kind: "direct";
691
+ privateKey: `0x${string}`;
692
+ } | {
693
+ kind: "session";
694
+ adapter: string;
695
+ session: unknown;
696
+ signer?: unknown;
697
+ address?: Hex;
698
+ };
678
699
  interface CreateAAProviderStateOptions {
679
700
  provider: AAProvider;
680
701
  chain: Chain;
681
- privateKey: `0x${string}`;
702
+ owner: CreateAAOwner;
682
703
  rpcUrl: string;
683
704
  callList: WalletExecutionCall[];
684
705
  mode?: AAExecutionMode;
@@ -694,4 +715,4 @@ interface CreateAAProviderStateOptions {
694
715
  */
695
716
  declare function createAAProviderState(options: CreateAAProviderStateOptions): Promise<AAProviderState>;
696
717
 
697
- export { type AAChainConfig, type AAConfig, type AAExecutionMode, type AAExecutionPlan, type AALike, type AAProvider, type AAProviderQuery, type AAProviderState, type AASponsorshipMode, type AlchemyHookParams, type AlchemyResolveOptions, type AlchemyResolvedConfig, type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type CreateAAProviderStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type Logger, type ParaSmartAccountLike, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendCallsSyncArgs, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type TransactionExecutionResult, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type WalletAtomicCapability, type WalletEip712Payload, type WalletExecutionCall, type WalletPrimitiveCall, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isProviderConfigured, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, parseAAConfig, readEnv, resolveAlchemyConfig, resolveDefaultProvider, resolvePimlicoConfig, unwrapSystemEvent };
718
+ export { type AAChainConfig, type AAConfig, type AAExecutionMode, type AAExecutionPlan, type AALike, type AAProvider, type AAProviderQuery, type AAProviderState, type AASponsorshipMode, type AlchemyHookParams, type AlchemyResolveOptions, type AlchemyResolvedConfig, type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type CreateAAOwner, type CreateAAProviderStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type Logger, type ParaSmartAccountLike, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendCallsSyncArgs, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type TransactionExecutionResult, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type WalletAtomicCapability, type WalletEip712Payload, type WalletExecutionCall, type WalletPrimitiveCall, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isProviderConfigured, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, parseAAConfig, readEnv, resolveAlchemyConfig, resolveDefaultProvider, resolvePimlicoConfig, unwrapSystemEvent };
package/dist/index.d.ts CHANGED
@@ -644,6 +644,12 @@ interface AlchemyResolveOptions {
644
644
  modeOverride?: AAExecutionMode;
645
645
  publicOnly?: boolean;
646
646
  throwOnMissingConfig?: boolean;
647
+ /**
648
+ * Pre-resolved API key. Use this in Next.js client-side code where
649
+ * dynamic `process.env[name]` access doesn't work.
650
+ */
651
+ apiKey?: string;
652
+ gasPolicyId?: string;
647
653
  }
648
654
  interface AlchemyResolvedConfig {
649
655
  chainConfig: AAChainConfig;
@@ -664,6 +670,11 @@ interface PimlicoResolveOptions {
664
670
  modeOverride?: AAExecutionMode;
665
671
  publicOnly?: boolean;
666
672
  throwOnMissingConfig?: boolean;
673
+ /**
674
+ * Pre-resolved API key. Use this in Next.js client-side code where
675
+ * dynamic `process.env[name]` access doesn't work.
676
+ */
677
+ apiKey?: string;
667
678
  }
668
679
  interface PimlicoResolvedConfig {
669
680
  chainConfig: AAChainConfig;
@@ -675,10 +686,20 @@ interface PimlicoResolvedConfig {
675
686
  }
676
687
  declare function resolvePimlicoConfig(options: PimlicoResolveOptions): PimlicoResolvedConfig | null;
677
688
 
689
+ type CreateAAOwner = {
690
+ kind: "direct";
691
+ privateKey: `0x${string}`;
692
+ } | {
693
+ kind: "session";
694
+ adapter: string;
695
+ session: unknown;
696
+ signer?: unknown;
697
+ address?: Hex;
698
+ };
678
699
  interface CreateAAProviderStateOptions {
679
700
  provider: AAProvider;
680
701
  chain: Chain;
681
- privateKey: `0x${string}`;
702
+ owner: CreateAAOwner;
682
703
  rpcUrl: string;
683
704
  callList: WalletExecutionCall[];
684
705
  mode?: AAExecutionMode;
@@ -694,4 +715,4 @@ interface CreateAAProviderStateOptions {
694
715
  */
695
716
  declare function createAAProviderState(options: CreateAAProviderStateOptions): Promise<AAProviderState>;
696
717
 
697
- export { type AAChainConfig, type AAConfig, type AAExecutionMode, type AAExecutionPlan, type AALike, type AAProvider, type AAProviderQuery, type AAProviderState, type AASponsorshipMode, type AlchemyHookParams, type AlchemyResolveOptions, type AlchemyResolvedConfig, type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type CreateAAProviderStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type Logger, type ParaSmartAccountLike, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendCallsSyncArgs, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type TransactionExecutionResult, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type WalletAtomicCapability, type WalletEip712Payload, type WalletExecutionCall, type WalletPrimitiveCall, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isProviderConfigured, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, parseAAConfig, readEnv, resolveAlchemyConfig, resolveDefaultProvider, resolvePimlicoConfig, unwrapSystemEvent };
718
+ export { type AAChainConfig, type AAConfig, type AAExecutionMode, type AAExecutionPlan, type AALike, type AAProvider, type AAProviderQuery, type AAProviderState, type AASponsorshipMode, type AlchemyHookParams, type AlchemyResolveOptions, type AlchemyResolvedConfig, type AomiChatResponse, AomiClient, type AomiClientOptions, type AomiCreateThreadResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type CreateAAOwner, type CreateAAProviderStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type Logger, type ParaSmartAccountLike, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendCallsSyncArgs, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type TransactionExecutionResult, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type WalletAtomicCapability, type WalletEip712Payload, type WalletExecutionCall, type WalletPrimitiveCall, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isProviderConfigured, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, parseAAConfig, readEnv, resolveAlchemyConfig, resolveDefaultProvider, resolvePimlicoConfig, unwrapSystemEvent };
package/dist/index.js CHANGED
@@ -1404,7 +1404,9 @@ function resolveAlchemyConfig(options) {
1404
1404
  },
1405
1405
  modeOverride,
1406
1406
  publicOnly = false,
1407
- throwOnMissingConfig = false
1407
+ throwOnMissingConfig = false,
1408
+ apiKey: preResolvedApiKey,
1409
+ gasPolicyId: preResolvedGasPolicyId
1408
1410
  } = options;
1409
1411
  if (!calls || localPrivateKey) {
1410
1412
  return null;
@@ -1422,7 +1424,7 @@ function resolveAlchemyConfig(options) {
1422
1424
  }
1423
1425
  return null;
1424
1426
  }
1425
- const apiKey = readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
1427
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(ALCHEMY_API_KEY_ENVS, { publicOnly });
1426
1428
  if (!apiKey) {
1427
1429
  if (throwOnMissingConfig) {
1428
1430
  throw new Error("Alchemy AA requires ALCHEMY_API_KEY.");
@@ -1433,7 +1435,7 @@ function resolveAlchemyConfig(options) {
1433
1435
  if (!chain) {
1434
1436
  return null;
1435
1437
  }
1436
- const gasPolicyId = readGasPolicyEnv(
1438
+ const gasPolicyId = preResolvedGasPolicyId != null ? preResolvedGasPolicyId : readGasPolicyEnv(
1437
1439
  chainConfig.chainId,
1438
1440
  chainSlugById,
1439
1441
  ALCHEMY_GAS_POLICY_ENVS,
@@ -1476,7 +1478,8 @@ function resolvePimlicoConfig(options) {
1476
1478
  rpcUrl,
1477
1479
  modeOverride,
1478
1480
  publicOnly = false,
1479
- throwOnMissingConfig = false
1481
+ throwOnMissingConfig = false,
1482
+ apiKey: preResolvedApiKey
1480
1483
  } = options;
1481
1484
  if (!calls || localPrivateKey) {
1482
1485
  return null;
@@ -1494,7 +1497,7 @@ function resolvePimlicoConfig(options) {
1494
1497
  }
1495
1498
  return null;
1496
1499
  }
1497
- const apiKey = readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
1500
+ const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
1498
1501
  if (!apiKey) {
1499
1502
  if (throwOnMissingConfig) {
1500
1503
  throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
@@ -1627,15 +1630,94 @@ import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
1627
1630
  import { privateKeyToAccount } from "viem/accounts";
1628
1631
  async function createAAProviderState(options) {
1629
1632
  if (options.provider === "alchemy") {
1630
- return createAlchemyAAState(options);
1633
+ return createAlchemyAAState({
1634
+ chain: options.chain,
1635
+ owner: options.owner,
1636
+ rpcUrl: options.rpcUrl,
1637
+ callList: options.callList,
1638
+ mode: options.mode,
1639
+ apiKey: options.apiKey,
1640
+ gasPolicyId: options.gasPolicyId,
1641
+ sponsored: options.sponsored
1642
+ });
1643
+ }
1644
+ return createPimlicoAAState({
1645
+ chain: options.chain,
1646
+ owner: options.owner,
1647
+ rpcUrl: options.rpcUrl,
1648
+ callList: options.callList,
1649
+ mode: options.mode,
1650
+ apiKey: options.apiKey
1651
+ });
1652
+ }
1653
+ function getDirectOwnerParams(owner) {
1654
+ return {
1655
+ kind: "ready",
1656
+ ownerParams: {
1657
+ para: void 0,
1658
+ signer: privateKeyToAccount(owner.privateKey)
1659
+ }
1660
+ };
1661
+ }
1662
+ function getParaSessionOwnerParams(owner) {
1663
+ if (owner.signer) {
1664
+ return {
1665
+ kind: "ready",
1666
+ ownerParams: __spreadValues({
1667
+ para: owner.session,
1668
+ signer: owner.signer
1669
+ }, owner.address ? { address: owner.address } : {})
1670
+ };
1671
+ }
1672
+ return {
1673
+ kind: "ready",
1674
+ ownerParams: __spreadValues({
1675
+ para: owner.session
1676
+ }, owner.address ? { address: owner.address } : {})
1677
+ };
1678
+ }
1679
+ function getSessionOwnerParams(owner) {
1680
+ switch (owner.adapter) {
1681
+ case "para":
1682
+ return getParaSessionOwnerParams(owner);
1683
+ default:
1684
+ return { kind: "unsupported_adapter", adapter: owner.adapter };
1685
+ }
1686
+ }
1687
+ function getOwnerParams(owner) {
1688
+ if (!owner) {
1689
+ return { kind: "missing" };
1690
+ }
1691
+ switch (owner.kind) {
1692
+ case "direct":
1693
+ return getDirectOwnerParams(owner);
1694
+ case "session":
1695
+ return getSessionOwnerParams(owner);
1631
1696
  }
1632
- return createPimlicoAAState(options);
1697
+ }
1698
+ function getMissingOwnerState(plan, provider) {
1699
+ return {
1700
+ plan,
1701
+ AA: null,
1702
+ isPending: false,
1703
+ error: new Error(
1704
+ `${provider} AA account creation requires a direct owner or a supported session owner.`
1705
+ )
1706
+ };
1707
+ }
1708
+ function getUnsupportedAdapterState(plan, adapter) {
1709
+ return {
1710
+ plan,
1711
+ AA: null,
1712
+ isPending: false,
1713
+ error: new Error(`Session adapter "${adapter}" is not implemented.`)
1714
+ };
1633
1715
  }
1634
1716
  async function createAlchemyAAState(options) {
1635
1717
  var _a, _b;
1636
1718
  const {
1637
1719
  chain,
1638
- privateKey,
1720
+ owner,
1639
1721
  rpcUrl,
1640
1722
  callList,
1641
1723
  mode,
@@ -1646,7 +1728,9 @@ async function createAlchemyAAState(options) {
1646
1728
  chainsById: { [chain.id]: chain },
1647
1729
  modeOverride: mode,
1648
1730
  throwOnMissingConfig: true,
1649
- getPreferredRpcUrl: () => rpcUrl
1731
+ getPreferredRpcUrl: () => rpcUrl,
1732
+ apiKey: options.apiKey,
1733
+ gasPolicyId: options.gasPolicyId
1650
1734
  });
1651
1735
  if (!resolved) {
1652
1736
  throw new Error("Alchemy AA config resolution failed.");
@@ -1657,17 +1741,21 @@ async function createAlchemyAAState(options) {
1657
1741
  sponsorship: gasPolicyId ? resolved.plan.sponsorship : "disabled",
1658
1742
  fallbackToEoa: false
1659
1743
  });
1660
- const signer = privateKeyToAccount(privateKey);
1744
+ const ownerParams = getOwnerParams(owner);
1745
+ if (ownerParams.kind === "missing") {
1746
+ return getMissingOwnerState(plan, "alchemy");
1747
+ }
1748
+ if (ownerParams.kind === "unsupported_adapter") {
1749
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
1750
+ }
1661
1751
  try {
1662
- const smartAccount = await createAlchemySmartAccount({
1663
- para: void 0,
1664
- signer,
1752
+ const smartAccount = await createAlchemySmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
1665
1753
  apiKey,
1666
1754
  gasPolicyId,
1667
1755
  chain,
1668
1756
  rpcUrl,
1669
1757
  mode: plan.mode
1670
- });
1758
+ }));
1671
1759
  if (!smartAccount) {
1672
1760
  return {
1673
1761
  plan,
@@ -1695,7 +1783,7 @@ async function createPimlicoAAState(options) {
1695
1783
  var _a;
1696
1784
  const {
1697
1785
  chain,
1698
- privateKey,
1786
+ owner,
1699
1787
  rpcUrl,
1700
1788
  callList,
1701
1789
  mode
@@ -1705,7 +1793,8 @@ async function createPimlicoAAState(options) {
1705
1793
  chainsById: { [chain.id]: chain },
1706
1794
  rpcUrl,
1707
1795
  modeOverride: mode,
1708
- throwOnMissingConfig: true
1796
+ throwOnMissingConfig: true,
1797
+ apiKey: options.apiKey
1709
1798
  });
1710
1799
  if (!resolved) {
1711
1800
  throw new Error("Pimlico AA config resolution failed.");
@@ -1714,16 +1803,20 @@ async function createPimlicoAAState(options) {
1714
1803
  const plan = __spreadProps(__spreadValues({}, resolved.plan), {
1715
1804
  fallbackToEoa: false
1716
1805
  });
1717
- const signer = privateKeyToAccount(privateKey);
1806
+ const ownerParams = getOwnerParams(owner);
1807
+ if (ownerParams.kind === "missing") {
1808
+ return getMissingOwnerState(plan, "pimlico");
1809
+ }
1810
+ if (ownerParams.kind === "unsupported_adapter") {
1811
+ return getUnsupportedAdapterState(plan, ownerParams.adapter);
1812
+ }
1718
1813
  try {
1719
- const smartAccount = await createPimlicoSmartAccount({
1720
- para: void 0,
1721
- signer,
1814
+ const smartAccount = await createPimlicoSmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
1722
1815
  apiKey,
1723
1816
  chain,
1724
1817
  rpcUrl,
1725
1818
  mode: plan.mode
1726
- });
1819
+ }));
1727
1820
  if (!smartAccount) {
1728
1821
  return {
1729
1822
  plan,