@aa-sdk/core 4.0.0-alpha.0 → 4.0.0-alpha.1

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.
Files changed (169) hide show
  1. package/dist/cjs/account/simple.js.map +1 -1
  2. package/dist/cjs/account/smartContractAccount.js +2 -1
  3. package/dist/cjs/account/smartContractAccount.js.map +1 -1
  4. package/dist/cjs/actions/smartAccount/buildUserOperation.js.map +1 -1
  5. package/dist/cjs/actions/smartAccount/dropAndReplaceUserOperation.js.map +1 -1
  6. package/dist/cjs/actions/smartAccount/sendTransaction.js.map +1 -1
  7. package/dist/cjs/actions/smartAccount/sendTransactions.js.map +1 -1
  8. package/dist/cjs/actions/smartAccount/waitForUserOperationTransacation.js.map +1 -1
  9. package/dist/cjs/client/bundlerClient.js.map +1 -1
  10. package/dist/cjs/client/decorators/bundlerClient.js.map +1 -1
  11. package/dist/cjs/client/decorators/smartAccountClient.js.map +1 -1
  12. package/dist/cjs/client/smartAccountClient.js.map +1 -1
  13. package/dist/cjs/ens/utils.js.map +1 -1
  14. package/dist/cjs/entrypoint/index.js.map +1 -1
  15. package/dist/cjs/errors/account.js.map +1 -1
  16. package/dist/cjs/errors/base.js.map +1 -1
  17. package/dist/cjs/errors/client.js.map +1 -1
  18. package/dist/cjs/errors/entrypoint.js.map +1 -1
  19. package/dist/cjs/errors/signer.js.map +1 -1
  20. package/dist/cjs/errors/transaction.js.map +1 -1
  21. package/dist/cjs/index.d.ts +2 -2
  22. package/dist/cjs/index.js +2 -4
  23. package/dist/cjs/index.js.map +1 -1
  24. package/dist/cjs/logger.js.map +1 -1
  25. package/dist/cjs/middleware/defaults/feeEstimator.d.ts +1 -1
  26. package/dist/cjs/middleware/defaults/feeEstimator.js +17 -15
  27. package/dist/cjs/middleware/defaults/feeEstimator.js.map +1 -1
  28. package/dist/cjs/middleware/defaults/paymasterAndData.js.map +1 -1
  29. package/dist/cjs/middleware/defaults/userOpSigner.js.map +1 -1
  30. package/dist/cjs/signer/local-account.js.map +1 -1
  31. package/dist/cjs/signer/schema.js.map +1 -1
  32. package/dist/cjs/signer/utils.d.ts +1 -9
  33. package/dist/cjs/signer/utils.js +1 -16
  34. package/dist/cjs/signer/utils.js.map +1 -1
  35. package/dist/cjs/signer/wallet-client.js.map +1 -1
  36. package/dist/cjs/utils/index.d.ts +0 -1
  37. package/dist/cjs/utils/index.js +1 -9
  38. package/dist/cjs/utils/index.js.map +1 -1
  39. package/dist/cjs/version.d.ts +1 -1
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/version.js.map +1 -1
  42. package/dist/esm/account/simple.js.map +1 -1
  43. package/dist/esm/account/smartContractAccount.js +2 -1
  44. package/dist/esm/account/smartContractAccount.js.map +1 -1
  45. package/dist/esm/actions/smartAccount/buildUserOperation.js.map +1 -1
  46. package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.js.map +1 -1
  47. package/dist/esm/actions/smartAccount/sendTransaction.js.map +1 -1
  48. package/dist/esm/actions/smartAccount/sendTransactions.js.map +1 -1
  49. package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.js.map +1 -1
  50. package/dist/esm/client/bundlerClient.js.map +1 -1
  51. package/dist/esm/client/decorators/bundlerClient.js.map +1 -1
  52. package/dist/esm/client/decorators/smartAccountClient.js.map +1 -1
  53. package/dist/esm/client/smartAccountClient.js.map +1 -1
  54. package/dist/esm/ens/utils.js.map +1 -1
  55. package/dist/esm/entrypoint/index.js.map +1 -1
  56. package/dist/esm/errors/account.js.map +1 -1
  57. package/dist/esm/errors/base.js.map +1 -1
  58. package/dist/esm/errors/client.js.map +1 -1
  59. package/dist/esm/errors/entrypoint.js.map +1 -1
  60. package/dist/esm/errors/signer.js.map +1 -1
  61. package/dist/esm/errors/transaction.js.map +1 -1
  62. package/dist/esm/index.d.ts +2 -2
  63. package/dist/esm/index.js +2 -2
  64. package/dist/esm/index.js.map +1 -1
  65. package/dist/esm/logger.js.map +1 -1
  66. package/dist/esm/middleware/defaults/feeEstimator.d.ts +1 -1
  67. package/dist/esm/middleware/defaults/feeEstimator.js +17 -15
  68. package/dist/esm/middleware/defaults/feeEstimator.js.map +1 -1
  69. package/dist/esm/middleware/defaults/paymasterAndData.js.map +1 -1
  70. package/dist/esm/middleware/defaults/userOpSigner.js.map +1 -1
  71. package/dist/esm/signer/local-account.js.map +1 -1
  72. package/dist/esm/signer/schema.js.map +1 -1
  73. package/dist/esm/signer/utils.d.ts +1 -9
  74. package/dist/esm/signer/utils.js +0 -14
  75. package/dist/esm/signer/utils.js.map +1 -1
  76. package/dist/esm/signer/wallet-client.js.map +1 -1
  77. package/dist/esm/utils/index.d.ts +0 -1
  78. package/dist/esm/utils/index.js +0 -7
  79. package/dist/esm/utils/index.js.map +1 -1
  80. package/dist/esm/version.d.ts +1 -1
  81. package/dist/esm/version.js +1 -1
  82. package/dist/esm/version.js.map +1 -1
  83. package/dist/types/account/smartContractAccount.d.ts +49 -0
  84. package/dist/types/account/smartContractAccount.d.ts.map +1 -1
  85. package/dist/types/actions/smartAccount/buildUserOperation.d.ts +23 -0
  86. package/dist/types/actions/smartAccount/buildUserOperation.d.ts.map +1 -1
  87. package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts +22 -0
  88. package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts.map +1 -1
  89. package/dist/types/actions/smartAccount/sendTransaction.d.ts +24 -0
  90. package/dist/types/actions/smartAccount/sendTransaction.d.ts.map +1 -1
  91. package/dist/types/actions/smartAccount/sendTransactions.d.ts +23 -0
  92. package/dist/types/actions/smartAccount/sendTransactions.d.ts.map +1 -1
  93. package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts +24 -0
  94. package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts.map +1 -1
  95. package/dist/types/client/bundlerClient.d.ts +15 -0
  96. package/dist/types/client/bundlerClient.d.ts.map +1 -1
  97. package/dist/types/client/decorators/bundlerClient.d.ts +9 -0
  98. package/dist/types/client/decorators/bundlerClient.d.ts.map +1 -1
  99. package/dist/types/client/decorators/smartAccountClient.d.ts +8 -0
  100. package/dist/types/client/decorators/smartAccountClient.d.ts.map +1 -1
  101. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  102. package/dist/types/ens/utils.d.ts +45 -0
  103. package/dist/types/ens/utils.d.ts.map +1 -1
  104. package/dist/types/entrypoint/index.d.ts +14 -0
  105. package/dist/types/entrypoint/index.d.ts.map +1 -1
  106. package/dist/types/errors/account.d.ts +34 -0
  107. package/dist/types/errors/account.d.ts.map +1 -1
  108. package/dist/types/errors/base.d.ts +5 -0
  109. package/dist/types/errors/base.d.ts.map +1 -1
  110. package/dist/types/errors/client.d.ts +9 -0
  111. package/dist/types/errors/client.d.ts.map +1 -1
  112. package/dist/types/errors/entrypoint.d.ts +6 -0
  113. package/dist/types/errors/entrypoint.d.ts.map +1 -1
  114. package/dist/types/errors/signer.d.ts +3 -0
  115. package/dist/types/errors/signer.d.ts.map +1 -1
  116. package/dist/types/errors/transaction.d.ts +6 -0
  117. package/dist/types/errors/transaction.d.ts.map +1 -1
  118. package/dist/types/index.d.ts +2 -2
  119. package/dist/types/index.d.ts.map +1 -1
  120. package/dist/types/logger.d.ts +3 -0
  121. package/dist/types/logger.d.ts.map +1 -1
  122. package/dist/types/middleware/defaults/feeEstimator.d.ts +21 -1
  123. package/dist/types/middleware/defaults/feeEstimator.d.ts.map +1 -1
  124. package/dist/types/middleware/defaults/paymasterAndData.d.ts +8 -0
  125. package/dist/types/middleware/defaults/paymasterAndData.d.ts.map +1 -1
  126. package/dist/types/middleware/defaults/userOpSigner.d.ts +10 -0
  127. package/dist/types/middleware/defaults/userOpSigner.d.ts.map +1 -1
  128. package/dist/types/signer/local-account.d.ts +3 -0
  129. package/dist/types/signer/local-account.d.ts.map +1 -1
  130. package/dist/types/signer/schema.d.ts +14 -0
  131. package/dist/types/signer/schema.d.ts.map +1 -1
  132. package/dist/types/signer/utils.d.ts +21 -9
  133. package/dist/types/signer/utils.d.ts.map +1 -1
  134. package/dist/types/signer/wallet-client.d.ts +3 -0
  135. package/dist/types/signer/wallet-client.d.ts.map +1 -1
  136. package/dist/types/utils/index.d.ts +54 -1
  137. package/dist/types/utils/index.d.ts.map +1 -1
  138. package/dist/types/version.d.ts +1 -1
  139. package/package.json +2 -2
  140. package/src/account/simple.ts +6 -0
  141. package/src/account/smartContractAccount.ts +120 -15
  142. package/src/actions/smartAccount/buildUserOperation.ts +23 -0
  143. package/src/actions/smartAccount/dropAndReplaceUserOperation.ts +22 -0
  144. package/src/actions/smartAccount/sendTransaction.ts +24 -0
  145. package/src/actions/smartAccount/sendTransactions.ts +23 -0
  146. package/src/actions/smartAccount/waitForUserOperationTransacation.ts +24 -0
  147. package/src/client/bundlerClient.ts +32 -0
  148. package/src/client/decorators/bundlerClient.ts +9 -0
  149. package/src/client/decorators/smartAccountClient.ts +8 -0
  150. package/src/client/smartAccountClient.ts +41 -0
  151. package/src/ens/utils.ts +45 -0
  152. package/src/entrypoint/index.ts +30 -62
  153. package/src/errors/account.ts +34 -0
  154. package/src/errors/base.ts +5 -2
  155. package/src/errors/client.ts +9 -0
  156. package/src/errors/entrypoint.ts +6 -0
  157. package/src/errors/signer.ts +3 -0
  158. package/src/errors/transaction.ts +6 -0
  159. package/src/index.ts +1 -5
  160. package/src/logger.ts +3 -0
  161. package/src/middleware/defaults/feeEstimator.ts +24 -4
  162. package/src/middleware/defaults/paymasterAndData.ts +8 -0
  163. package/src/middleware/defaults/userOpSigner.ts +10 -0
  164. package/src/signer/local-account.ts +3 -0
  165. package/src/signer/schema.ts +14 -0
  166. package/src/signer/utils.ts +20 -32
  167. package/src/signer/wallet-client.ts +3 -0
  168. package/src/utils/index.ts +54 -13
  169. package/src/version.ts +1 -1
@@ -135,6 +135,26 @@ export function createSmartAccountClient<
135
135
  config: SmartAccountClientConfig<TTransport, TChain, TAccount, TContext>
136
136
  ): SmartAccountClient<TTransport, TChain, TAccount>;
137
137
 
138
+ /**
139
+ * Creates a smart account client using the provided configuration. This client handles various Ethereum transactions and message signing operations.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { createSmartAccountClient, toSmartContractAccount } from "@aa-sdk/core";
144
+ * import { http } from "viem";
145
+ * import { sepolia } from "viem/chains";
146
+ *
147
+ * const client = createSmartAccountClient({
148
+ * chain: sepolia,
149
+ * transport: http("RPC_URL"),
150
+ * // optionally hoist the account
151
+ * account: toSmartContractAccount(...),
152
+ * });
153
+ * ```
154
+ *
155
+ * @param {SmartAccountClientConfig} config The configuration for creating the smart account client
156
+ * @returns {SmartAccountClient} A smart account client capable of handling transactions, message signing, and other operations on a smart account
157
+ */
138
158
  export function createSmartAccountClient(
139
159
  config: SmartAccountClientConfig
140
160
  ): SmartAccountClient {
@@ -263,6 +283,27 @@ export function createSmartAccountClientFromExisting<
263
283
  TContext
264
284
  >;
265
285
 
286
+ /**
287
+ * Creates a smart account client using an existing client and specific configuration. This function can be used to reuse a pre-existing BundlerClient while customizing other aspects of the smart account.
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * import {
292
+ * createBundlerClient,
293
+ * createSmartAccountClientFromExisting,
294
+ * toSmartContractAccount
295
+ * } from "@aa-sdk/core";
296
+ *
297
+ * const bundlerClient = createBundlerClient(...);
298
+ * const client = createSmartAccountClientFromExisting({
299
+ * client,
300
+ * account: toSmartContractAccount(...),
301
+ * })
302
+ * ```
303
+ *
304
+ * @param {Omit<SmartAccountClientConfig, "transport" | "chain"> & {client: BundlerClient}} config the configuration object which includes the client
305
+ * @returns {SmartAccountClient} A smart account client created from the existing BundlerClient
306
+ */
266
307
  export function createSmartAccountClientFromExisting(
267
308
  config: Omit<SmartAccountClientConfig, "transport" | "chain"> & {
268
309
  client: BundlerClient;
package/src/ens/utils.ts CHANGED
@@ -6,6 +6,20 @@ export const ChainsById: Map<number, chains.Chain> = new Map(
6
6
  Object.values(chains).map((x) => [x.id, x])
7
7
  );
8
8
 
9
+ /**
10
+ * Converts a given chain ID to a coin type, following specific standards for mainnet and non-mainnet chains.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { convertChainIdToCoinType } from "@aa-sdk/core";
15
+ * import { sepolia } from "viem/chains";
16
+ *
17
+ * const coinType = convertChainIdToCoinType(sepolia.id);
18
+ * ```
19
+ *
20
+ * @param {number} chainId the blockchain chain ID that you want to convert to a coin type
21
+ * @returns {number} the corresponding coin type for the given chain ID
22
+ */
9
23
  export const convertChainIdToCoinType = (chainId: number): number => {
10
24
  if (chainId === mainnet.id) {
11
25
  // this comes from [ensip-9](https://docs.ens.domains/ens-improvement-proposals/ensip-9-multichain-address-resolution)
@@ -16,6 +30,21 @@ export const convertChainIdToCoinType = (chainId: number): number => {
16
30
  return (0x80000000 | chainId) >>> 0;
17
31
  };
18
32
 
33
+ /**
34
+ * Converts a coin type to a chain ID based on predefined mappings. This function follows ENSIP-9 for coin type 60 and ENSIP-11 for other coin types.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { convertChainIdToCoinType, convertCoinTypeToChainId } from "@aa-sdk/core";
39
+ * import { sepolia } from "viem/chains";
40
+ *
41
+ * const coinType = convertChainIdToCoinType(sepolia.id);
42
+ * const chainId = convertCoinTypeToChainId(coinType);
43
+ * ```
44
+ *
45
+ * @param {number} coinType the coin type to be converted to a chain ID
46
+ * @returns {number} the corresponding chain ID
47
+ */
19
48
  export const convertCoinTypeToChainId = (coinType: number): number => {
20
49
  if (coinType === 60) {
21
50
  // this comes from [ensip-9](https://docs.ens.domains/ens-improvement-proposals/ensip-9-multichain-address-resolution)
@@ -26,6 +55,22 @@ export const convertCoinTypeToChainId = (coinType: number): number => {
26
55
  return (0x7fffffff & coinType) >> 0;
27
56
  };
28
57
 
58
+ /**
59
+ * Converts a coin type to its corresponding blockchain chain based on a predefined mapping.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { convertChainIdToCoinType, convertCoinTypeToChain } from "@aa-sdk/core";
64
+ * import { sepolia } from "viem/chains";
65
+ *
66
+ * const coinType = convertChainIdToCoinType(sepolia.id);
67
+ * const chain = convertCoinTypeToChain(coinType);
68
+ * ```
69
+ *
70
+ * @param {number} coinType The numerical identifier for the coin type
71
+ * @returns {Chain} The corresponding blockchain chain
72
+ * @throws {Error} If the coin type does not map to a supported chain
73
+ */
29
74
  export const convertCoinTypeToChain = (coinType: number): Chain => {
30
75
  const chainId = convertCoinTypeToChainId(coinType);
31
76
  const chain = ChainsById.get(chainId);
@@ -17,6 +17,20 @@ export const entryPointRegistry: EntryPointRegistry = {
17
17
  "0.7.0": EntryPoint_v7,
18
18
  };
19
19
 
20
+ /**
21
+ * Checks if the given value is a valid key of the EntryPointRegistry.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { isEntryPointVersion } from "@aa-sdk/core";
26
+ *
27
+ * const valid = isEntryPointVersion("0.6.0");
28
+ * const invalid = isEntryPointVersion("0.8.0");
29
+ * ```
30
+ *
31
+ * @param {*} value The value to be checked
32
+ * @returns {boolean} true if the value is a valid key of EntryPointRegistry, false otherwise
33
+ */
20
34
  export const isEntryPointVersion = (
21
35
  value: any
22
36
  ): value is keyof EntryPointRegistry => {
@@ -44,6 +58,22 @@ export function getEntryPoint<TChain extends Chain = Chain>(
44
58
  options?: GetEntryPointOptions<DefaultEntryPointVersion>
45
59
  ): EntryPointDefRegistry<TChain>[DefaultEntryPointVersion];
46
60
 
61
+ /**
62
+ * Retrieves the entry point definition for the specified chain and version, falling back to the default version if not provided. Throws an error if the entry point address cannot be found.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { getEntryPoint } from "@aa-sdk/core";
67
+ * import { sepolia } from "viem/chains";
68
+ *
69
+ * const entryPoint060 = getEntryPoint(sepolia);
70
+ * const entryPoint070 = getEntryPoint(sepolia, { version: "0.7.0" });
71
+ * ```
72
+ *
73
+ * @param {Chain} chain The chain for which the entry point is being retrieved
74
+ * @param {GetEntryPointOptions<TEntryPointVersion>} options Options containing the version and address overrides for the entry point
75
+ * @returns {EntryPointDefRegistry<TChain>[EntryPointVersion]} The entry point definition for the specified chain and version
76
+ */
47
77
  export function getEntryPoint<
48
78
  TEntryPointVersion extends EntryPointVersion,
49
79
  TChain extends Chain = Chain
@@ -88,65 +118,3 @@ export function getEntryPoint<
88
118
 
89
119
  throw new EntryPointNotFoundError(chain, version);
90
120
  }
91
-
92
- // // =================================================================================
93
- // // TODO: Add tests for the following cases
94
-
95
- // const chain: Chain = mainnet;
96
-
97
- // // 1. left and right hand side version type should match, as well as the param
98
-
99
- // // === Error ===
100
- // const ep1_a: EntryPointDef<"0.6.0"> = getEntryPoint(chain, {
101
- // version: "0.7.0",
102
- // }); // error
103
- // const ep1_b: EntryPointDef<"0.7.0"> = getEntryPoint(chain); // error
104
- // const ep1_c: EntryPointDef<"0.6.0"> = getEntryPoint(chain, {
105
- // version: "0.7.0",
106
- // }); // error
107
- // const ep1_d: EntryPointDef<"0.6.0"> = getEntryPoint<"0.6.0">(chain, {
108
- // version: "0.7.0",
109
- // }); // error
110
-
111
- // // === Valid ===
112
- // const ep1a: EntryPointDef<"0.6.0"> = getEntryPoint(chain);
113
- // const ep1b: EntryPointDef<"0.6.0"> = getEntryPoint(chain, { version: "0.6.0" });
114
- // const ep1c: EntryPointDef<"0.7.0"> = getEntryPoint(chain, { version: "0.7.0" });
115
- // const ep1d: EntryPointDef<"0.6.0"> = getEntryPoint(chain, {
116
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
117
- // });
118
- // const ep1e: EntryPointDef<"0.6.0"> = getEntryPoint(chain, {
119
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
120
- // version: "0.6.0",
121
- // });
122
- // const ep1f: EntryPointDef<"0.7.0"> = getEntryPoint(chain, {
123
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
124
- // version: "0.7.0",
125
- // });
126
-
127
- // // 2. If non-default type is specified, version option param of the type is required
128
-
129
- // // === Error ===
130
- // const ep2_a: EntryPointDef<"0.7.0"> = getEntryPoint<"0.7.0">(chain); // error
131
- // const ep2_b: EntryPointDef<"0.7.0"> = getEntryPoint<"0.7.0">(chain, {
132
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
133
- // });
134
-
135
- // // === Valid ===
136
- // const ep2a: EntryPointDef<"0.7.0"> = getEntryPoint<"0.7.0">(chain, {
137
- // version: "0.7.0",
138
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
139
- // });
140
- // const ep2b: EntryPointDef<"0.6.0"> = getEntryPoint<"0.6.0">(chain, {
141
- // version: "0.6.0",
142
- // });
143
- // const ep2c: EntryPointDef<"0.6.0"> = getEntryPoint<"0.6.0">(chain);
144
- // const ep2d: EntryPointDef<"0.6.0"> = getEntryPoint<"0.6.0">(chain, {
145
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
146
- // });
147
- // const ep2e: EntryPointDef<"0.7.0"> = getEntryPoint<"0.7.0">(chain, {
148
- // version: "0.7.0",
149
- // addressOverride: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
150
- // });
151
-
152
- // // =================================================================================
@@ -2,6 +2,9 @@ import type { Chain } from "viem";
2
2
  import type { EntryPointVersion } from "../entrypoint/types.js";
3
3
  import { BaseError } from "./base.js";
4
4
 
5
+ /**
6
+ * This error is thrown when an account could not be found to execute a specific action. It extends the `BaseError` class.
7
+ */
5
8
  export class AccountNotFoundError extends BaseError {
6
9
  override name = "AccountNotFoundError";
7
10
 
@@ -11,6 +14,10 @@ export class AccountNotFoundError extends BaseError {
11
14
  }
12
15
  }
13
16
 
17
+ /**
18
+ * Represents an error that is thrown when no default factory is defined for a specific account type on a given chain and entry point version.
19
+ * This error suggests providing an override via the `factoryAddress` parameter when creating an account.
20
+ */
14
21
  export class DefaultFactoryNotDefinedError extends BaseError {
15
22
  override name = "DefaultFactoryNotDefinedError";
16
23
  constructor(accountType: string, chain: Chain, version: EntryPointVersion) {
@@ -23,6 +30,9 @@ export class DefaultFactoryNotDefinedError extends BaseError {
23
30
  }
24
31
  }
25
32
 
33
+ /**
34
+ * Custom error class for handling errors when getting a counterfactual address. This extends the `BaseError` class and provides a custom error message and name.
35
+ */
26
36
  export class GetCounterFactualAddressError extends BaseError {
27
37
  override name = "GetCounterFactualAddressError";
28
38
  constructor() {
@@ -30,6 +40,9 @@ export class GetCounterFactualAddressError extends BaseError {
30
40
  }
31
41
  }
32
42
 
43
+ /**
44
+ * An error class representing the condition where upgrades are not supported for a specific account type. This error extends the `BaseError` class and provides a custom error message based on the account type.
45
+ */
33
46
  export class UpgradesNotSupportedError extends BaseError {
34
47
  override name = "UpgradesNotSupported";
35
48
  constructor(accountType: string) {
@@ -37,6 +50,9 @@ export class UpgradesNotSupportedError extends BaseError {
37
50
  }
38
51
  }
39
52
 
53
+ /**
54
+ * Error thrown when attempting to sign a transaction that is not supported by smart contracts.
55
+ */
40
56
  export class SignTransactionNotSupportedError extends BaseError {
41
57
  override name = "SignTransactionNotSupported";
42
58
  constructor() {
@@ -44,6 +60,9 @@ export class SignTransactionNotSupportedError extends BaseError {
44
60
  }
45
61
  }
46
62
 
63
+ /**
64
+ * Custom error class `FailedToGetStorageSlotError` which is used to signal a failure when attempting to retrieve a storage slot. This error includes the slot and slot descriptor in its message and inherits from `BaseError`.
65
+ */
47
66
  export class FailedToGetStorageSlotError extends BaseError {
48
67
  override name = "FailedToGetStorageSlotError";
49
68
  constructor(slot: string, slotDescriptor: string) {
@@ -51,6 +70,9 @@ export class FailedToGetStorageSlotError extends BaseError {
51
70
  }
52
71
  }
53
72
 
73
+ /**
74
+ * Represents an error indicating that batch execution is not supported for a specific account type.
75
+ */
54
76
  export class BatchExecutionNotSupportedError extends BaseError {
55
77
  override name = "BatchExecutionNotSupportedError";
56
78
  constructor(accountType: string) {
@@ -58,6 +80,9 @@ export class BatchExecutionNotSupportedError extends BaseError {
58
80
  }
59
81
  }
60
82
 
83
+ /**
84
+ * Represents an error that occurs when an account requires an owner to execute but none is provided.
85
+ */
61
86
  export class AccountRequiresOwnerError extends BaseError {
62
87
  override name = "AccountRequiresOwnerError";
63
88
  constructor(accountType: string) {
@@ -65,6 +90,9 @@ export class AccountRequiresOwnerError extends BaseError {
65
90
  }
66
91
  }
67
92
 
93
+ /**
94
+ * Represents an error that occurs when an attempt is made to call `UpgradeToAndCall` on an account type that does not support it. Includes the account type in the error message.
95
+ */
68
96
  export class UpgradeToAndCallNotSupportedError extends BaseError {
69
97
  override name = "UpgradeToAndCallNotSupportedError";
70
98
  constructor(accountType: string) {
@@ -72,6 +100,9 @@ export class UpgradeToAndCallNotSupportedError extends BaseError {
72
100
  }
73
101
  }
74
102
 
103
+ /**
104
+ * Represents an error thrown when an account type does not match the expected type.
105
+ */
75
106
  export class IncorrectAccountType extends BaseError {
76
107
  override name = "IncorrectAccountTypeError";
77
108
  constructor(expected: string, actual: string) {
@@ -79,6 +110,9 @@ export class IncorrectAccountType extends BaseError {
79
110
  }
80
111
  }
81
112
 
113
+ /**
114
+ * Error class indicating that a smart account operation requires a signer.
115
+ */
82
116
  export class SmartAccountWithSignerRequiredError extends BaseError {
83
117
  override name = "SmartAccountWithSignerRequiredError";
84
118
  constructor() {
@@ -16,8 +16,11 @@ type BaseErrorParameters = {
16
16
  }
17
17
  );
18
18
 
19
- // This is based on on viem's BaseError type (obviously from the import and extend)
20
- // we want the errors here to point to our docs if we supply a docsPath though
19
+ /**
20
+ * A custom error class that extends from `ViemBaseError`. This class allows for error messages to include links to relevant documentation based on provided `docsPath` and `docsSlug` parameters.
21
+ * This is based on on viem's BaseError type (obviously from the import and extend)
22
+ * we want the errors here to point to our docs if we supply a docsPath though
23
+ */
21
24
  export class BaseError extends ViemBaseError {
22
25
  override name = "AASDKError";
23
26
  override version = VERSION;
@@ -1,6 +1,9 @@
1
1
  import type { Client } from "viem";
2
2
  import { BaseError } from "./base.js";
3
3
 
4
+ /**
5
+ * Represents an error thrown when a client is not compatible with the expected client type for a specific method. The error message provides guidance on how to create a compatible client.
6
+ */
4
7
  export class IncompatibleClientError extends BaseError {
5
8
  override name = "IncompatibleClientError";
6
9
  constructor(expectedClient: string, method: string, client: Client) {
@@ -13,6 +16,9 @@ export class IncompatibleClientError extends BaseError {
13
16
  }
14
17
  }
15
18
 
19
+ /**
20
+ * Represents an error that occurs when an invalid RPC URL is provided. This class extends the `BaseError` class and includes the invalid URL in the error message.
21
+ */
16
22
  export class InvalidRpcUrlError extends BaseError {
17
23
  override name = "InvalidRpcUrlError";
18
24
  constructor(rpcUrl?: string) {
@@ -20,6 +26,9 @@ export class InvalidRpcUrlError extends BaseError {
20
26
  }
21
27
  }
22
28
 
29
+ /**
30
+ * Error class representing a "Chain Not Found" error, typically thrown when no chain is supplied to the client.
31
+ */
23
32
  export class ChainNotFoundError extends BaseError {
24
33
  override name = "ChainNotFoundError";
25
34
  constructor() {
@@ -1,6 +1,9 @@
1
1
  import type { Chain } from "viem";
2
2
  import { BaseError } from "./base.js";
3
3
 
4
+ /**
5
+ * Represents an error thrown when an entry point is not found for a specific chain and entry point version. This error indicates that a default entry point does not exist for the given chain and version, and suggests providing an override.
6
+ */
4
7
  export class EntryPointNotFoundError extends BaseError {
5
8
  override name = "EntryPointNotFoundError";
6
9
 
@@ -14,6 +17,9 @@ export class EntryPointNotFoundError extends BaseError {
14
17
  }
15
18
  }
16
19
 
20
+ /**
21
+ * Represents an error thrown when an invalid entry point version is encountered for a specific chain. This error extends the `BaseError` class.
22
+ */
17
23
  export class InvalidEntryPointError extends BaseError {
18
24
  override name = "InvalidEntryPointError";
19
25
 
@@ -1,5 +1,8 @@
1
1
  import { BaseError } from "./base.js";
2
2
 
3
+ /**
4
+ * Represents an error thrown when an invalid signer type is provided to the SmartAccountSigner.
5
+ */
3
6
  export class InvalidSignerTypeError extends BaseError {
4
7
  override name = "InvalidSignerTypeError";
5
8
  constructor(signerType?: string) {
@@ -1,6 +1,9 @@
1
1
  import type { Hex } from "viem";
2
2
  import { BaseError } from "./base.js";
3
3
 
4
+ /**
5
+ * Error thrown when a transaction is missing the `to` address parameter. This class extends the `BaseError` class.
6
+ */
4
7
  export class TransactionMissingToParamError extends BaseError {
5
8
  override name = "TransactionMissingToParamError";
6
9
  constructor() {
@@ -8,6 +11,9 @@ export class TransactionMissingToParamError extends BaseError {
8
11
  }
9
12
  }
10
13
 
14
+ /**
15
+ * Represents an error that occurs when a transaction cannot be found for a given user operation. This error extends from `BaseError`. The `hash` of the transaction is provided to indicate which transaction could not be found.
16
+ */
11
17
  export class FailedToFindTransactionError extends BaseError {
12
18
  override name = "FailedToFindTransactionError";
13
19
  constructor(hash: Hex) {
package/src/index.ts CHANGED
@@ -130,10 +130,7 @@ export type {
130
130
  SmartAccountAuthenticator,
131
131
  SmartAccountSigner,
132
132
  } from "./signer/types.js";
133
- export {
134
- verifyEIP6492Signature,
135
- wrapSignatureWith6492,
136
- } from "./signer/utils.js";
133
+ export { wrapSignatureWith6492 } from "./signer/utils.js";
137
134
  export { WalletClientSigner } from "./signer/wallet-client.js";
138
135
  export { split, type SplitTransportParams } from "./transport/split.js";
139
136
  export type * from "./types.js";
@@ -156,7 +153,6 @@ export {
156
153
  bypassPaymasterAndDataEmptyHex,
157
154
  concatPaymasterAndData,
158
155
  deepHexlify,
159
- defineReadOnly,
160
156
  filterUndefined,
161
157
  getChain,
162
158
  getDefaultSimpleAccountFactoryAddress,
package/src/logger.ts CHANGED
@@ -7,6 +7,9 @@ export enum LogLevel {
7
7
  NONE = 0,
8
8
  }
9
9
 
10
+ /**
11
+ * Logger class provides static methods for logging at different levels such as error, warn, debug, info, and verbose. This class allows setting log levels and log filters to control the logging behavior.
12
+ */
10
13
  export class Logger {
11
14
  static logLevel: LogLevel = LogLevel.INFO;
12
15
  static logFilter?: string;
@@ -3,11 +3,30 @@ import { applyUserOpOverrideOrFeeOption } from "../../utils/index.js";
3
3
  import type { MiddlewareClient } from "../actions";
4
4
  import type { ClientMiddlewareFn } from "../types";
5
5
 
6
- export const defaultFeeEstimator: <C extends MiddlewareClient>(
6
+ /**
7
+ * Default fee estimator middleware function that estimates the maximum fee per gas and maximum priority fee per gas for a given client and applies the necessary overrides and fee options.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { createSmartAccountClient, defaultFeeEstimator, createBundlerClient } from "@aa-sdk/core";
12
+ *
13
+ * const bundlerClient = createBundlerClient(...);
14
+ *
15
+ * // NOTE: this is already provided by the smart account client
16
+ * const client = createSmartAccountClient({
17
+ * feeEstimator: defaultFeeEstimator(bundlerClient),
18
+ * ...otherParams
19
+ * });
20
+ * ```
21
+ *
22
+ * @template {MiddlewareClient} C The type of the client
23
+ * @param {C} client The client to perform the fee estimation
24
+ * @returns {ClientMiddlewareFn} A middleware function that takes in the struct and options, estimates the fees, and updates the struct with the estimated fees
25
+ */
26
+ export function defaultFeeEstimator<C extends MiddlewareClient>(
7
27
  client: C
8
- ) => ClientMiddlewareFn =
9
- (client) =>
10
- async (struct, { overrides, feeOptions }) => {
28
+ ): ClientMiddlewareFn {
29
+ return async (struct, { overrides, feeOptions }) => {
11
30
  // maxFeePerGas must be at least the sum of maxPriorityFeePerGas and baseFee
12
31
  // so we need to accommodate for the fee option applied maxPriorityFeePerGas for the maxFeePerGas
13
32
  //
@@ -48,3 +67,4 @@ export const defaultFeeEstimator: <C extends MiddlewareClient>(
48
67
  struct.maxPriorityFeePerGas = maxPriorityFeePerGas;
49
68
  return struct;
50
69
  };
70
+ }
@@ -1,6 +1,14 @@
1
1
  import type { UserOperationStruct } from "../../types";
2
2
  import type { ClientMiddlewareFn } from "../types";
3
3
 
4
+ /**
5
+ * Middleware function that sets the `paymasterAndData` field in the given struct based on the entry point version of the account.
6
+ * This is the default used by `createSmartAccountClient` and is not necessary to be used directly.
7
+ *
8
+ * @param {UserOperationStruct} struct the user operation structure to be modified
9
+ * @param {{ account: Account }} context an object containing the account information
10
+ * @returns {Promise<UserOperationStruct>} a promise that resolves to the modified user operation structure
11
+ */
4
12
  export const defaultPaymasterAndData: ClientMiddlewareFn = async (
5
13
  struct,
6
14
  { account }
@@ -8,6 +8,16 @@ import {
8
8
  } from "../../utils/index.js";
9
9
  import type { ClientMiddlewareFn } from "../types";
10
10
 
11
+ /**
12
+ * Provides a default middleware function for signing user operations with a client account. This function validates the request and adds the signature to it.
13
+ * This is already included in the client returned from `createSmartAccountClient`
14
+ *
15
+ * @param {UserOperationStruct} struct The user operation structure to be signed
16
+ * @param {*} context The middleware context containing the client and account information
17
+ * @param {Client} context.client The client object, which should include account and chain information
18
+ * @param {Account} [context.account] Optional, the account used for signing, defaults to the client's account if not provided
19
+ * @returns {Promise<UserOperationStruct>} A promise that resolves to the signed user operation structure
20
+ */
11
21
  export const defaultUserOpSigner: ClientMiddlewareFn = async (
12
22
  struct,
13
23
  { client, account = client.account }
@@ -11,6 +11,9 @@ import {
11
11
  import { mnemonicToAccount, privateKeyToAccount } from "viem/accounts";
12
12
  import type { SmartAccountSigner } from "./types.js";
13
13
 
14
+ /**
15
+ * Represents a local account signer and provides methods to sign messages and transactions, as well as static methods to create the signer from mnemonic or private key.
16
+ */
14
17
  export class LocalAccountSigner<
15
18
  T extends HDAccount | PrivateKeyAccount | LocalAccount
16
19
  > implements SmartAccountSigner<T>
@@ -1,6 +1,20 @@
1
1
  import { z } from "zod";
2
2
  import type { SmartAccountSigner } from "./types";
3
3
 
4
+ /**
5
+ * Checks if the provided object is a `SmartAccountSigner`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { isSigner, LocalAccountSigner } from "@aa-sdk/core";
10
+ *
11
+ * const signer = new LocalAccountSigner(...);
12
+ * console.log(isSigner(signer)); // true
13
+ * ```
14
+ *
15
+ * @param {any} signer the object to check
16
+ * @returns {boolean} A boolean indicating whether the object is a `SmartAccountSigner`
17
+ */
4
18
  export const isSigner = (signer: any): signer is SmartAccountSigner => {
5
19
  return (
6
20
  signer != null &&
@@ -5,7 +5,6 @@ import {
5
5
  type Address,
6
6
  type Hash,
7
7
  type Hex,
8
- type PublicClient,
9
8
  } from "viem";
10
9
 
11
10
  export type SignWith6492Params = {
@@ -14,13 +13,26 @@ export type SignWith6492Params = {
14
13
  signature: Hash;
15
14
  };
16
15
 
17
- type VerifyEIP6492SignatureParams = {
18
- signer: Address;
19
- hash: Hash;
20
- signature: Hash;
21
- client: PublicClient;
22
- };
23
-
16
+ /**
17
+ * Wraps a given signature with additional data following the EIP-6492 standard.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { wrapSignatureWith6492 } from "@aa-sdk/core";
22
+ *
23
+ * const signature = wrapSignatureWith6492({
24
+ * factoryAddress: "0x...",
25
+ * factoryCalldata: "0x...",
26
+ * signature: "0x...",
27
+ * });
28
+ * ```
29
+ *
30
+ * @param {SignWith6492Params} params The parameters to wrap the signature
31
+ * @param {Hex} params.factoryAddress The address of the factory
32
+ * @param {Hex} params.factoryCalldata The calldata for the factory
33
+ * @param {Hex} params.signature The original signature that needs to be wrapped
34
+ * @returns {Hash} The wrapped signature
35
+ */
24
36
  export const wrapSignatureWith6492 = ({
25
37
  factoryAddress,
26
38
  factoryCalldata,
@@ -42,27 +54,3 @@ export const wrapSignatureWith6492 = ({
42
54
  "0x6492649264926492649264926492649264926492649264926492649264926492",
43
55
  ]);
44
56
  };
45
-
46
- // defined in https://github.com/AmbireTech/signature-validator/blob/main/index.ts#L13C17-L13C17
47
- const universalValidatorByteCode =
48
- "0x60806040523480156200001157600080fd5b50604051620007003803806200070083398101604081905262000034916200056f565b6000620000438484846200004f565b9050806000526001601ff35b600080846001600160a01b0316803b806020016040519081016040528181526000908060200190933c90507f6492649264926492649264926492649264926492649264926492649264926492620000a68462000451565b036200021f57600060608085806020019051810190620000c79190620005ce565b8651929550909350915060000362000192576000836001600160a01b031683604051620000f5919062000643565b6000604051808303816000865af19150503d806000811462000134576040519150601f19603f3d011682016040523d82523d6000602084013e62000139565b606091505b5050905080620001905760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b505b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90620001c4908b90869060040162000661565b602060405180830381865afa158015620001e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020891906200069d565b6001600160e01b031916149450505050506200044a565b805115620002b157604051630b135d3f60e11b808252906001600160a01b03871690631626ba7e9062000259908890889060040162000661565b602060405180830381865afa15801562000277573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029d91906200069d565b6001600160e01b031916149150506200044a565b8251604114620003195760405162461bcd60e51b815260206004820152603a6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e677468000000000000606482015260840162000187565b620003236200046b565b506020830151604080850151855186939260009185919081106200034b576200034b620006c9565b016020015160f81c9050601b81148015906200036b57508060ff16601c14155b15620003cf5760405162461bcd60e51b815260206004820152603b6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c75650000000000606482015260840162000187565b6040805160008152602081018083528a905260ff83169181019190915260608101849052608081018390526001600160a01b038a169060019060a0016020604051602081039080840390855afa1580156200042e573d6000803e3d6000fd5b505050602060405103516001600160a01b031614955050505050505b9392505050565b60006020825110156200046357600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b03811681146200049f57600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620004d5578181015183820152602001620004bb565b50506000910152565b600082601f830112620004f057600080fd5b81516001600160401b03808211156200050d576200050d620004a2565b604051601f8301601f19908116603f01168101908282118183101715620005385762000538620004a2565b816040528381528660208588010111156200055257600080fd5b62000565846020830160208901620004b8565b9695505050505050565b6000806000606084860312156200058557600080fd5b8351620005928162000489565b6020850151604086015191945092506001600160401b03811115620005b657600080fd5b620005c486828701620004de565b9150509250925092565b600080600060608486031215620005e457600080fd5b8351620005f18162000489565b60208501519093506001600160401b03808211156200060f57600080fd5b6200061d87838801620004de565b935060408601519150808211156200063457600080fd5b50620005c486828701620004de565b6000825162000657818460208701620004b8565b9190910192915050565b828152604060208201526000825180604084015262000688816060850160208701620004b8565b601f01601f1916919091016060019392505050565b600060208284031215620006b057600080fd5b81516001600160e01b0319811681146200044a57600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572";
49
-
50
- export const verifyEIP6492Signature = async ({
51
- signer,
52
- hash,
53
- signature,
54
- client,
55
- }: VerifyEIP6492SignatureParams): Promise<boolean> => {
56
- const result = await client.call({
57
- data: concat([
58
- universalValidatorByteCode,
59
- encodeAbiParameters(parseAbiParameters("address, bytes32, bytes"), [
60
- signer,
61
- hash,
62
- signature,
63
- ]),
64
- ]),
65
- });
66
-
67
- return result.data === "0x01";
68
- };
@@ -9,6 +9,9 @@ import {
9
9
  import { InvalidSignerTypeError } from "../errors/signer.js";
10
10
  import type { SmartAccountSigner } from "./types";
11
11
 
12
+ /**
13
+ * Represents a wallet client signer for smart accounts, providing methods to get the address, sign messages, and sign typed data.
14
+ */
12
15
  export class WalletClientSigner implements SmartAccountSigner<WalletClient> {
13
16
  signerType: string;
14
17
  inner: WalletClient;