@aomi-labs/client 0.1.22 → 0.1.24

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
@@ -1,4 +1,4 @@
1
- import { Chain, Hex, TransactionReceipt } from 'viem';
1
+ import { Hex, Chain, TransactionReceipt } from 'viem';
2
2
 
3
3
  /**
4
4
  * Client-side user state synced with the backend.
@@ -315,28 +315,116 @@ type Listener<T = unknown> = (payload: T) => void;
315
315
  */
316
316
  declare class TypedEventEmitter<EventMap extends Record<string, unknown> = Record<string, unknown>> {
317
317
  private listeners;
318
- /**
319
- * Subscribe to an event type. Returns an unsubscribe function.
320
- */
321
318
  on<K extends keyof EventMap & string>(type: K, handler: Listener<EventMap[K]>): () => void;
322
- /**
323
- * Subscribe to an event type for a single emission, then auto-unsubscribe.
324
- */
325
319
  once<K extends keyof EventMap & string>(type: K, handler: Listener<EventMap[K]>): () => void;
326
- /**
327
- * Emit an event to all listeners of `type` and wildcard `"*"` listeners.
328
- */
329
320
  emit<K extends keyof EventMap & string>(type: K, payload: EventMap[K]): void;
330
- /**
331
- * Remove a specific handler from an event type.
332
- */
333
321
  off<K extends keyof EventMap & string>(type: K, handler: Listener<EventMap[K]>): void;
334
- /**
335
- * Remove all listeners for all event types.
336
- */
337
322
  removeAllListeners(): void;
338
323
  }
339
324
 
325
+ type UnwrappedEvent = {
326
+ type: string;
327
+ payload: unknown;
328
+ };
329
+ declare function unwrapSystemEvent(event: AomiSystemEvent): UnwrappedEvent | null;
330
+
331
+ type AAProvider = "alchemy" | "pimlico";
332
+ type AAMode = "4337" | "7702";
333
+ type AASponsorship = "disabled" | "optional" | "required";
334
+ type AAWalletCall = {
335
+ to: Hex;
336
+ value: bigint;
337
+ data?: Hex;
338
+ chainId: number;
339
+ };
340
+ type WalletAtomicCapability = {
341
+ atomic?: {
342
+ status?: string;
343
+ };
344
+ };
345
+ interface AAChainConfig {
346
+ chainId: number;
347
+ enabled: boolean;
348
+ defaultMode: AAMode;
349
+ supportedModes: AAMode[];
350
+ allowBatching: boolean;
351
+ sponsorship: AASponsorship;
352
+ }
353
+ interface AAConfig {
354
+ enabled: boolean;
355
+ provider: AAProvider;
356
+ fallbackToEoa: boolean;
357
+ chains: AAChainConfig[];
358
+ }
359
+ interface AAResolvedConfig {
360
+ provider: AAProvider;
361
+ chainId: number;
362
+ mode: AAMode;
363
+ batchingEnabled: boolean;
364
+ sponsorship: AASponsorship;
365
+ fallbackToEoa: boolean;
366
+ }
367
+ /** The subset of AAWalletCall passed to smart account send methods (chainId already resolved). */
368
+ type AACallPayload = Omit<AAWalletCall, "chainId">;
369
+ interface SmartAccount {
370
+ provider: string;
371
+ mode: string;
372
+ AAAddress?: Hex;
373
+ delegationAddress?: Hex;
374
+ sendTransaction: (call: AACallPayload) => Promise<{
375
+ transactionHash: string;
376
+ }>;
377
+ sendBatchTransaction: (calls: AACallPayload[]) => Promise<{
378
+ transactionHash: string;
379
+ }>;
380
+ }
381
+ interface AAState<TAccount extends SmartAccount = SmartAccount> {
382
+ resolved: AAResolvedConfig | null;
383
+ account?: TAccount | null;
384
+ pending: boolean;
385
+ error: Error | null;
386
+ }
387
+ interface ExecutionResult {
388
+ txHash: string;
389
+ txHashes: string[];
390
+ executionKind: string;
391
+ batched: boolean;
392
+ sponsored: boolean;
393
+ AAAddress?: Hex;
394
+ delegationAddress?: Hex;
395
+ }
396
+ interface AtomicBatchArgs {
397
+ calls: AACallPayload[];
398
+ capabilities?: {
399
+ atomic?: {
400
+ required?: boolean;
401
+ };
402
+ };
403
+ }
404
+ interface ExecuteWalletCallsParams<TAccount extends SmartAccount = SmartAccount> {
405
+ callList: AAWalletCall[];
406
+ currentChainId: number;
407
+ capabilities: Record<string, WalletAtomicCapability> | undefined;
408
+ localPrivateKey: `0x${string}` | null;
409
+ providerState: AAState<TAccount>;
410
+ sendCallsSyncAsync: (args: AtomicBatchArgs) => Promise<unknown>;
411
+ sendTransactionAsync: (args: {
412
+ chainId: number;
413
+ to: Hex;
414
+ value: bigint;
415
+ data?: Hex;
416
+ }) => Promise<string>;
417
+ switchChainAsync: (params: {
418
+ chainId: number;
419
+ }) => Promise<unknown>;
420
+ chainsById: Record<number, Chain>;
421
+ getPreferredRpcUrl: (chain: Chain) => string;
422
+ }
423
+ declare function getAAChainConfig(config: AAConfig, calls: AAWalletCall[], chainsById: Record<number, Chain>): AAChainConfig | null;
424
+ declare function buildAAExecutionPlan(config: AAConfig, chainConfig: AAChainConfig): AAResolvedConfig;
425
+ declare function getWalletExecutorReady(providerState: AAState): boolean;
426
+ declare const DEFAULT_AA_CONFIG: AAConfig;
427
+
340
428
  type WalletTxPayload = {
341
429
  to: string;
342
430
  value?: string;
@@ -375,6 +463,11 @@ declare function normalizeTxPayload(payload: unknown): WalletTxPayload | null;
375
463
  * Normalize an EIP-712 signing request payload.
376
464
  */
377
465
  declare function normalizeEip712Payload(payload: unknown): WalletEip712Payload;
466
+ /**
467
+ * Convert a normalized WalletTxPayload into an AAWalletCall.
468
+ * This is the single boundary conversion point from backend payloads to AA-ready calls.
469
+ */
470
+ declare function toAAWalletCall(payload: WalletTxPayload, defaultChainId?: number): AAWalletCall;
378
471
  /**
379
472
  * Convert normalized EIP-712 payloads into the viem signing shape used by both
380
473
  * the CLI and widget component layers.
@@ -536,8 +629,20 @@ declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
536
629
  removeExtValue(key: string): void;
537
630
  resolveWallet(address: string, chainId?: number): void;
538
631
  syncUserState(): Promise<AomiStateResponse>;
539
- private startPolling;
540
- private stopPolling;
632
+ /** Whether the session is currently polling for state updates. */
633
+ getIsPolling(): boolean;
634
+ /**
635
+ * Fetch the current state from the backend (one-shot).
636
+ * Automatically starts polling if the backend is processing.
637
+ */
638
+ fetchCurrentState(): Promise<void>;
639
+ /**
640
+ * Start polling for state updates. Idempotent — no-op if already polling.
641
+ * Useful for resuming polling after resolving a wallet request.
642
+ */
643
+ startPolling(): void;
644
+ /** Stop polling for state updates. Idempotent — no-op if not polling. */
645
+ stopPolling(): void;
541
646
  private pollTick;
542
647
  private applyState;
543
648
  private dispatchSystemEvents;
@@ -550,165 +655,8 @@ declare class ClientSession extends TypedEventEmitter<SessionEventMap> {
550
655
  private assertUserStateAligned;
551
656
  }
552
657
 
553
- type UnwrappedEvent = {
554
- type: string;
555
- payload: unknown;
556
- };
557
- /**
558
- * Unwrap a tagged-enum AomiSystemEvent from the backend into a flat event.
559
- *
560
- * ```ts
561
- * const event: AomiSystemEvent = { InlineCall: { type: "wallet_tx_request", payload: { to: "0x..." } } };
562
- * const unwrapped = unwrapSystemEvent(event);
563
- * // => { type: "wallet_tx_request", payload: { to: "0x..." } }
564
- * ```
565
- */
566
- declare function unwrapSystemEvent(event: AomiSystemEvent): UnwrappedEvent | null;
567
-
568
- /**
569
- * Reads the first non-empty env var from `candidates`.
570
- * When `publicOnly` is true, only `NEXT_PUBLIC_*` names are considered.
571
- */
572
- declare function readEnv(candidates: readonly string[], options?: {
573
- publicOnly?: boolean;
574
- }): string | undefined;
575
- type AAProvider = "alchemy" | "pimlico";
576
- /**
577
- * Returns true if the given provider has a configured API key.
578
- */
579
- declare function isProviderConfigured(provider: AAProvider, options?: {
580
- publicOnly?: boolean;
581
- }): boolean;
582
- /**
583
- * Picks the first configured provider (alchemy > pimlico).
584
- * Throws if neither is configured.
585
- */
586
- declare function resolveDefaultProvider(options?: {
587
- publicOnly?: boolean;
588
- }): AAProvider;
589
-
590
- type AAMode = "4337" | "7702";
591
- type AASponsorship = "disabled" | "optional" | "required";
592
- type WalletCall = {
593
- to: string;
594
- value: string;
595
- data?: string;
596
- chainId: number;
597
- };
598
- type WalletAtomicCapability = {
599
- atomic?: {
600
- status?: string;
601
- };
602
- };
603
- type WalletPrimitiveCall = {
604
- to: Hex;
605
- value: bigint;
606
- data?: Hex;
607
- };
608
- interface AAChainConfig {
609
- chainId: number;
610
- enabled: boolean;
611
- defaultMode: AAMode;
612
- supportedModes: AAMode[];
613
- allowBatching: boolean;
614
- sponsorship: AASponsorship;
615
- }
616
- interface AAConfig {
617
- enabled: boolean;
618
- provider: AAProvider;
619
- fallbackToEoa: boolean;
620
- chains: AAChainConfig[];
621
- }
622
- interface AAResolvedConfig {
623
- provider: AAProvider;
624
- chainId: number;
625
- mode: AAMode;
626
- batchingEnabled: boolean;
627
- sponsorship: AASponsorship;
628
- fallbackToEoa: boolean;
629
- }
630
- interface SmartAccount {
631
- provider: string;
632
- mode: string;
633
- AAAddress?: Hex;
634
- delegationAddress?: Hex;
635
- sendTransaction: (call: WalletPrimitiveCall) => Promise<{
636
- transactionHash: string;
637
- }>;
638
- sendBatchTransaction: (calls: WalletPrimitiveCall[]) => Promise<{
639
- transactionHash: string;
640
- }>;
641
- }
642
- interface AAState<TAccount extends SmartAccount = SmartAccount> {
643
- resolved: AAResolvedConfig | null;
644
- account?: TAccount | null;
645
- pending: boolean;
646
- error: Error | null;
647
- }
648
- interface ExecutionResult {
649
- txHash: string;
650
- txHashes: string[];
651
- executionKind: string;
652
- batched: boolean;
653
- sponsored: boolean;
654
- AAAddress?: Hex;
655
- delegationAddress?: Hex;
656
- }
657
- interface AtomicBatchArgs {
658
- calls: WalletPrimitiveCall[];
659
- capabilities?: {
660
- atomic?: {
661
- required?: boolean;
662
- };
663
- };
664
- }
665
- interface ExecuteWalletCallsParams<TAccount extends SmartAccount = SmartAccount> {
666
- callList: WalletCall[];
667
- currentChainId: number;
668
- capabilities: Record<string, WalletAtomicCapability> | undefined;
669
- localPrivateKey: `0x${string}` | null;
670
- providerState: AAState<TAccount>;
671
- sendCallsSyncAsync: (args: AtomicBatchArgs) => Promise<unknown>;
672
- sendTransactionAsync: (args: {
673
- chainId: number;
674
- to: Hex;
675
- value: bigint;
676
- data?: Hex;
677
- }) => Promise<string>;
678
- switchChainAsync: (params: {
679
- chainId: number;
680
- }) => Promise<unknown>;
681
- chainsById: Record<number, Chain>;
682
- getPreferredRpcUrl: (chain: Chain) => string;
683
- }
684
- declare function parseAAConfig(value: unknown): AAConfig;
685
- declare function getAAChainConfig(config: AAConfig, calls: WalletCall[], chainsById: Record<number, Chain>): AAChainConfig | null;
686
- declare function buildAAExecutionPlan(config: AAConfig, chainConfig: AAChainConfig): AAResolvedConfig;
687
- declare function getWalletExecutorReady(providerState: AAState): boolean;
688
- declare const DEFAULT_AA_CONFIG: AAConfig;
689
658
  declare function executeWalletCalls(params: ExecuteWalletCallsParams): Promise<ExecutionResult>;
690
659
 
691
- interface AlchemyResolveOptions {
692
- calls: WalletCall[] | null;
693
- localPrivateKey?: `0x${string}` | null;
694
- accountAbstractionConfig?: AAConfig;
695
- chainsById: Record<number, Chain>;
696
- chainSlugById?: Record<number, string>;
697
- getPreferredRpcUrl?: (chain: Chain) => string;
698
- modeOverride?: AAMode;
699
- publicOnly?: boolean;
700
- throwOnMissingConfig?: boolean;
701
- apiKey?: string;
702
- gasPolicyId?: string;
703
- }
704
- interface AlchemyResolvedConfig extends AAResolvedConfig {
705
- apiKey: string;
706
- chain: Chain;
707
- rpcUrl: string;
708
- gasPolicyId?: string;
709
- }
710
- declare function resolveAlchemyConfig(options: AlchemyResolveOptions): AlchemyResolvedConfig | null;
711
-
712
660
  interface AlchemyHookParams {
713
661
  enabled: boolean;
714
662
  apiKey: string;
@@ -732,7 +680,7 @@ interface CreateAlchemyAAProviderOptions<TAccount extends SmartAccount = SmartAc
732
680
  apiKeyEnvVar?: string;
733
681
  gasPolicyEnvVar?: string;
734
682
  }
735
- declare function createAlchemyAAProvider<TAccount extends SmartAccount = SmartAccount>({ accountAbstractionConfig, useAlchemyAA, chainsById, chainSlugById, getPreferredRpcUrl, }: CreateAlchemyAAProviderOptions<TAccount>): (calls: WalletCall[] | null, localPrivateKey: `0x${string}` | null) => AAState<TAccount>;
683
+ declare function createAlchemyAAProvider<TAccount extends SmartAccount = SmartAccount>({ accountAbstractionConfig, useAlchemyAA, chainsById, chainSlugById, getPreferredRpcUrl, }: CreateAlchemyAAProviderOptions<TAccount>): (calls: AAWalletCall[] | null, localPrivateKey: `0x${string}` | null) => AAState<TAccount>;
736
684
 
737
685
  type AAOwner = {
738
686
  kind: "direct";
@@ -746,7 +694,7 @@ type AAOwner = {
746
694
  };
747
695
 
748
696
  interface PimlicoResolveOptions {
749
- calls: WalletCall[] | null;
697
+ calls: AAWalletCall[] | null;
750
698
  localPrivateKey?: `0x${string}` | null;
751
699
  accountAbstractionConfig?: AAConfig;
752
700
  chainsById: Record<number, Chain>;
@@ -783,15 +731,15 @@ interface CreatePimlicoAAProviderOptions<TAccount extends SmartAccount = SmartAc
783
731
  apiKeyEnvVar?: string;
784
732
  rpcUrl?: string;
785
733
  }
786
- declare function createPimlicoAAProvider<TAccount extends SmartAccount = SmartAccount>({ accountAbstractionConfig, usePimlicoAA, chainsById, rpcUrl, }: CreatePimlicoAAProviderOptions<TAccount>): (calls: WalletCall[] | null, localPrivateKey: `0x${string}` | null) => AAState<TAccount>;
734
+ declare function createPimlicoAAProvider<TAccount extends SmartAccount = SmartAccount>({ accountAbstractionConfig, usePimlicoAA, chainsById, rpcUrl, }: CreatePimlicoAAProviderOptions<TAccount>): (calls: AAWalletCall[] | null, localPrivateKey: `0x${string}` | null) => AAState<TAccount>;
787
735
 
788
736
  type SdkSmartAccount = {
789
737
  provider: string;
790
738
  mode: AAMode;
791
739
  smartAccountAddress: Hex;
792
740
  delegationAddress?: Hex;
793
- sendTransaction: (call: WalletPrimitiveCall, options?: unknown) => Promise<TransactionReceipt>;
794
- sendBatchTransaction: (calls: WalletPrimitiveCall[], options?: unknown) => Promise<TransactionReceipt>;
741
+ sendTransaction: (call: AACallPayload, options?: unknown) => Promise<TransactionReceipt>;
742
+ sendBatchTransaction: (calls: AACallPayload[], options?: unknown) => Promise<TransactionReceipt>;
795
743
  };
796
744
  /**
797
745
  * Bridges the provider SDK smart-account shape into the library's
@@ -810,11 +758,13 @@ interface CreateAAStateOptions {
810
758
  chain: Chain;
811
759
  owner: AAOwner;
812
760
  rpcUrl: string;
813
- callList: WalletCall[];
761
+ callList: AAWalletCall[];
814
762
  mode?: AAMode;
815
763
  apiKey?: string;
816
764
  gasPolicyId?: string;
817
765
  sponsored?: boolean;
766
+ /** Backend proxy base URL for Alchemy. Used when apiKey is omitted. */
767
+ proxyBaseUrl?: string;
818
768
  }
819
769
  /**
820
770
  * Creates an AA state by instantiating the appropriate smart account via
@@ -822,4 +772,4 @@ interface CreateAAStateOptions {
822
772
  */
823
773
  declare function createAAProviderState(options: CreateAAStateOptions): Promise<AAState>;
824
774
 
825
- export { type AAChainConfig, type AAConfig, type AAMode, type AAOwner, type AAProvider, type AAResolvedConfig, type AASponsorship, type AAState, type AlchemyHookParams, type AlchemyResolveOptions, type AlchemyResolvedConfig, type AomiChatResponse, type AomiClearSecretsResponse, AomiClient, type AomiClientOptions, type AomiClientType, type AomiCreateThreadResponse, type AomiIngestSecretsResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiSimulateFee, type AomiSimulateResponse, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type AtomicBatchArgs, CLIENT_TYPE_TS_CLI, CLIENT_TYPE_WEB_UI, type CreateAAStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type ExecutionResult, type Logger, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type SmartAccount, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type ViemSignTypedDataArgs, type WalletAtomicCapability, type WalletCall, type WalletEip712Payload, type WalletPrimitiveCall, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, addUserStateExt, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isProviderConfigured, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, parseAAConfig, readEnv, resolveAlchemyConfig, resolveDefaultProvider, resolvePimlicoConfig, toViemSignTypedDataArgs, unwrapSystemEvent };
775
+ export { type AACallPayload, type AAChainConfig, type AAConfig, type AAMode, type AAOwner, type AAProvider, type AAResolvedConfig, type AASponsorship, type AAState, type AAWalletCall, type AlchemyHookParams, type AomiChatResponse, type AomiClearSecretsResponse, AomiClient, type AomiClientOptions, type AomiClientType, type AomiCreateThreadResponse, type AomiIngestSecretsResponse, type AomiInterruptResponse, type AomiMessage, type AomiSSEEvent, type AomiSSEEventType, type AomiSimulateFee, type AomiSimulateResponse, type AomiStateResponse, type AomiSystemEvent, type AomiSystemResponse, type AomiThread, type AtomicBatchArgs, CLIENT_TYPE_TS_CLI, CLIENT_TYPE_WEB_UI, type CreateAAStateOptions, type CreateAlchemyAAProviderOptions, type CreatePimlicoAAProviderOptions, DEFAULT_AA_CONFIG, type ExecuteWalletCallsParams, type ExecutionResult, type Logger, type PimlicoHookParams, type PimlicoResolveOptions, type PimlicoResolvedConfig, type SendResult, ClientSession as Session, type SessionEventMap, type SessionOptions, type SmartAccount, TypedEventEmitter, type UnwrappedEvent, type UseAlchemyAAHook, type UsePimlicoAAHook, type UserState, type ViemSignTypedDataArgs, type WalletAtomicCapability, type WalletEip712Payload, type WalletRequest, type WalletRequestKind, type WalletRequestResult, type WalletTxPayload, adaptSmartAccount, addUserStateExt, buildAAExecutionPlan, createAAProviderState, createAlchemyAAProvider, createPimlicoAAProvider, executeWalletCalls, getAAChainConfig, getWalletExecutorReady, isAlchemySponsorshipLimitError, isAsyncCallback, isInlineCall, isSystemError, isSystemNotice, normalizeEip712Payload, normalizeTxPayload, resolvePimlicoConfig, toAAWalletCall, toViemSignTypedDataArgs, unwrapSystemEvent };