@aa-sdk/core 4.0.0-alpha.4 → 4.0.0-alpha.6

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 (239) hide show
  1. package/dist/cjs/account/smartContractAccount.d.ts +9 -3
  2. package/dist/cjs/account/smartContractAccount.js +11 -6
  3. package/dist/cjs/account/smartContractAccount.js.map +1 -1
  4. package/dist/cjs/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
  5. package/dist/cjs/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
  6. package/dist/cjs/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
  7. package/dist/cjs/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
  8. package/dist/cjs/actions/smartAccount/internal/initUserOperation.js.map +1 -1
  9. package/dist/cjs/actions/smartAccount/internal/runMiddlewareStack.js.map +1 -1
  10. package/dist/cjs/actions/smartAccount/internal/sendUserOperation.js.map +1 -1
  11. package/dist/cjs/actions/smartAccount/sendUserOperation.js.map +1 -1
  12. package/dist/cjs/client/bundlerClient.js.map +1 -1
  13. package/dist/cjs/client/decorators/bundlerClient.js.map +1 -1
  14. package/dist/cjs/client/isSmartAccountClient.js.map +1 -1
  15. package/dist/cjs/client/types.d.ts +2 -7
  16. package/dist/cjs/client/types.js.map +1 -1
  17. package/dist/cjs/errors/account.js.map +1 -1
  18. package/dist/cjs/errors/client.js.map +1 -1
  19. package/dist/cjs/errors/entrypoint.js.map +1 -1
  20. package/dist/cjs/errors/signer.js.map +1 -1
  21. package/dist/cjs/errors/transaction.js.map +1 -1
  22. package/dist/cjs/errors/useroperation.js.map +1 -1
  23. package/dist/cjs/index.d.ts +3 -5
  24. package/dist/cjs/index.js +6 -9
  25. package/dist/cjs/index.js.map +1 -1
  26. package/dist/cjs/logger.js.map +1 -1
  27. package/dist/cjs/middleware/actions.js +2 -18
  28. package/dist/cjs/middleware/actions.js.map +1 -1
  29. package/dist/cjs/middleware/defaults/gasEstimator.js +3 -2
  30. package/dist/cjs/middleware/defaults/gasEstimator.js.map +1 -1
  31. package/dist/cjs/middleware/erc7677middleware.d.ts +40 -0
  32. package/dist/cjs/middleware/erc7677middleware.js +77 -0
  33. package/dist/cjs/middleware/erc7677middleware.js.map +1 -0
  34. package/dist/cjs/middleware/noopMiddleware.d.ts +2 -1
  35. package/dist/cjs/middleware/noopMiddleware.js.map +1 -1
  36. package/dist/cjs/middleware/types.d.ts +3 -2
  37. package/dist/cjs/middleware/types.js.map +1 -1
  38. package/dist/cjs/signer/local-account.d.ts +46 -46
  39. package/dist/cjs/signer/local-account.js.map +1 -1
  40. package/dist/cjs/signer/wallet-client.d.ts +46 -46
  41. package/dist/cjs/signer/wallet-client.js.map +1 -1
  42. package/dist/cjs/transport/split.js.map +1 -1
  43. package/dist/cjs/utils/bigint.js.map +1 -1
  44. package/dist/cjs/utils/bytes.js.map +1 -1
  45. package/dist/cjs/utils/defaults.d.ts +1 -3
  46. package/dist/cjs/utils/defaults.js +1 -41
  47. package/dist/cjs/utils/defaults.js.map +1 -1
  48. package/dist/cjs/utils/index.js.map +1 -1
  49. package/dist/cjs/utils/types.js.map +1 -1
  50. package/dist/cjs/utils/userop.js.map +1 -1
  51. package/dist/cjs/version.d.ts +1 -1
  52. package/dist/cjs/version.js +1 -1
  53. package/dist/cjs/version.js.map +1 -1
  54. package/dist/esm/account/smartContractAccount.d.ts +9 -3
  55. package/dist/esm/account/smartContractAccount.js +6 -1
  56. package/dist/esm/account/smartContractAccount.js.map +1 -1
  57. package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
  58. package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
  59. package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
  60. package/dist/esm/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
  61. package/dist/esm/actions/smartAccount/internal/initUserOperation.js.map +1 -1
  62. package/dist/esm/actions/smartAccount/internal/runMiddlewareStack.js.map +1 -1
  63. package/dist/esm/actions/smartAccount/internal/sendUserOperation.js.map +1 -1
  64. package/dist/esm/actions/smartAccount/sendUserOperation.js.map +1 -1
  65. package/dist/esm/client/bundlerClient.js.map +1 -1
  66. package/dist/esm/client/decorators/bundlerClient.js.map +1 -1
  67. package/dist/esm/client/isSmartAccountClient.js.map +1 -1
  68. package/dist/esm/client/types.d.ts +2 -7
  69. package/dist/esm/client/types.js.map +1 -1
  70. package/dist/esm/errors/account.js.map +1 -1
  71. package/dist/esm/errors/client.js.map +1 -1
  72. package/dist/esm/errors/entrypoint.js.map +1 -1
  73. package/dist/esm/errors/signer.js.map +1 -1
  74. package/dist/esm/errors/transaction.js.map +1 -1
  75. package/dist/esm/errors/useroperation.js.map +1 -1
  76. package/dist/esm/index.d.ts +3 -5
  77. package/dist/esm/index.js +2 -3
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/logger.js.map +1 -1
  80. package/dist/esm/middleware/actions.js +3 -18
  81. package/dist/esm/middleware/actions.js.map +1 -1
  82. package/dist/esm/middleware/defaults/gasEstimator.js +3 -2
  83. package/dist/esm/middleware/defaults/gasEstimator.js.map +1 -1
  84. package/dist/esm/middleware/erc7677middleware.d.ts +40 -0
  85. package/dist/esm/middleware/erc7677middleware.js +73 -0
  86. package/dist/esm/middleware/erc7677middleware.js.map +1 -0
  87. package/dist/esm/middleware/noopMiddleware.d.ts +2 -1
  88. package/dist/esm/middleware/noopMiddleware.js.map +1 -1
  89. package/dist/esm/middleware/types.d.ts +3 -2
  90. package/dist/esm/middleware/types.js.map +1 -1
  91. package/dist/esm/signer/local-account.d.ts +46 -46
  92. package/dist/esm/signer/local-account.js.map +1 -1
  93. package/dist/esm/signer/wallet-client.d.ts +46 -46
  94. package/dist/esm/signer/wallet-client.js.map +1 -1
  95. package/dist/esm/transport/split.js.map +1 -1
  96. package/dist/esm/utils/bigint.js.map +1 -1
  97. package/dist/esm/utils/bytes.js.map +1 -1
  98. package/dist/esm/utils/defaults.d.ts +1 -3
  99. package/dist/esm/utils/defaults.js +1 -40
  100. package/dist/esm/utils/defaults.js.map +1 -1
  101. package/dist/esm/utils/index.js.map +1 -1
  102. package/dist/esm/utils/types.js.map +1 -1
  103. package/dist/esm/utils/userop.js.map +1 -1
  104. package/dist/esm/version.d.ts +1 -1
  105. package/dist/esm/version.js +1 -1
  106. package/dist/esm/version.js.map +1 -1
  107. package/dist/types/account/smartContractAccount.d.ts +17 -11
  108. package/dist/types/account/smartContractAccount.d.ts.map +1 -1
  109. package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts +33 -33
  110. package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts +43 -59
  111. package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts.map +1 -1
  112. package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +18 -18
  113. package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts +3 -3
  114. package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts +3 -4
  115. package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts.map +1 -1
  116. package/dist/types/actions/smartAccount/internal/runMiddlewareStack.d.ts +0 -14
  117. package/dist/types/actions/smartAccount/internal/runMiddlewareStack.d.ts.map +1 -1
  118. package/dist/types/actions/smartAccount/internal/sendUserOperation.d.ts +0 -7
  119. package/dist/types/actions/smartAccount/internal/sendUserOperation.d.ts.map +1 -1
  120. package/dist/types/actions/smartAccount/sendUserOperation.d.ts +17 -3
  121. package/dist/types/actions/smartAccount/sendUserOperation.d.ts.map +1 -1
  122. package/dist/types/client/bundlerClient.d.ts +2 -2
  123. package/dist/types/client/decorators/bundlerClient.d.ts +8 -8
  124. package/dist/types/client/isSmartAccountClient.d.ts +4 -4
  125. package/dist/types/client/types.d.ts +2 -7
  126. package/dist/types/client/types.d.ts.map +1 -1
  127. package/dist/types/errors/account.d.ts +53 -4
  128. package/dist/types/errors/account.d.ts.map +1 -1
  129. package/dist/types/errors/client.d.ts +15 -0
  130. package/dist/types/errors/client.d.ts.map +1 -1
  131. package/dist/types/errors/entrypoint.d.ts +12 -0
  132. package/dist/types/errors/entrypoint.d.ts.map +1 -1
  133. package/dist/types/errors/signer.d.ts +5 -0
  134. package/dist/types/errors/signer.d.ts.map +1 -1
  135. package/dist/types/errors/transaction.d.ts +8 -1
  136. package/dist/types/errors/transaction.d.ts.map +1 -1
  137. package/dist/types/errors/useroperation.d.ts +5 -5
  138. package/dist/types/errors/useroperation.d.ts.map +1 -1
  139. package/dist/types/index.d.ts +3 -5
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/logger.d.ts +88 -0
  142. package/dist/types/logger.d.ts.map +1 -1
  143. package/dist/types/middleware/actions.d.ts +3 -3
  144. package/dist/types/middleware/actions.d.ts.map +1 -1
  145. package/dist/types/middleware/defaults/gasEstimator.d.ts +2 -2
  146. package/dist/types/middleware/defaults/gasEstimator.d.ts.map +1 -1
  147. package/dist/types/middleware/erc7677middleware.d.ts +62 -0
  148. package/dist/types/middleware/erc7677middleware.d.ts.map +1 -0
  149. package/dist/types/middleware/noopMiddleware.d.ts +4 -4
  150. package/dist/types/middleware/noopMiddleware.d.ts.map +1 -1
  151. package/dist/types/middleware/types.d.ts +3 -2
  152. package/dist/types/middleware/types.d.ts.map +1 -1
  153. package/dist/types/signer/local-account.d.ts +139 -47
  154. package/dist/types/signer/local-account.d.ts.map +1 -1
  155. package/dist/types/signer/wallet-client.d.ts +135 -46
  156. package/dist/types/signer/wallet-client.d.ts.map +1 -1
  157. package/dist/types/transport/split.d.ts +2 -2
  158. package/dist/types/utils/bigint.d.ts +14 -14
  159. package/dist/types/utils/bigint.d.ts.map +1 -1
  160. package/dist/types/utils/bytes.d.ts +5 -5
  161. package/dist/types/utils/defaults.d.ts +1 -11
  162. package/dist/types/utils/defaults.d.ts.map +1 -1
  163. package/dist/types/utils/index.d.ts +12 -12
  164. package/dist/types/utils/types.d.ts +2 -2
  165. package/dist/types/utils/userop.d.ts +33 -33
  166. package/dist/types/version.d.ts +1 -1
  167. package/package.json +3 -2
  168. package/src/account/smartContractAccount.ts +19 -12
  169. package/src/actions/smartAccount/buildUserOperationFromTx.ts +35 -35
  170. package/src/actions/smartAccount/buildUserOperationFromTxs.ts +44 -60
  171. package/src/actions/smartAccount/checkGasSponsorshipEligibility.ts +19 -19
  172. package/src/actions/smartAccount/estimateUserOperationGas.ts +3 -3
  173. package/src/actions/smartAccount/internal/initUserOperation.ts +3 -4
  174. package/src/actions/smartAccount/internal/runMiddlewareStack.ts +0 -22
  175. package/src/actions/smartAccount/internal/sendUserOperation.ts +0 -7
  176. package/src/actions/smartAccount/sendUserOperation.ts +17 -3
  177. package/src/client/bundlerClient.ts +2 -2
  178. package/src/client/decorators/bundlerClient.ts +8 -8
  179. package/src/client/isSmartAccountClient.ts +4 -4
  180. package/src/client/types.ts +2 -15
  181. package/src/errors/account.ts +64 -4
  182. package/src/errors/client.ts +18 -0
  183. package/src/errors/entrypoint.ts +12 -0
  184. package/src/errors/signer.ts +6 -0
  185. package/src/errors/transaction.ts +10 -1
  186. package/src/errors/useroperation.ts +5 -6
  187. package/src/index.ts +2 -8
  188. package/src/logger.ts +88 -0
  189. package/src/middleware/actions.ts +6 -27
  190. package/src/middleware/defaults/gasEstimator.ts +8 -5
  191. package/src/middleware/erc7677middleware.ts +201 -0
  192. package/src/middleware/noopMiddleware.ts +6 -4
  193. package/src/middleware/types.ts +16 -7
  194. package/src/signer/local-account.ts +94 -2
  195. package/src/signer/wallet-client.ts +89 -0
  196. package/src/transport/split.ts +2 -2
  197. package/src/utils/bigint.ts +15 -15
  198. package/src/utils/bytes.ts +5 -5
  199. package/src/utils/defaults.ts +2 -74
  200. package/src/utils/index.ts +12 -12
  201. package/src/utils/types.ts +2 -2
  202. package/src/utils/userop.ts +33 -33
  203. package/src/version.ts +1 -1
  204. package/dist/cjs/account/base.d.ts +0 -49
  205. package/dist/cjs/account/base.js +0 -257
  206. package/dist/cjs/account/base.js.map +0 -1
  207. package/dist/cjs/account/schema.d.ts +0 -100
  208. package/dist/cjs/account/schema.js +0 -43
  209. package/dist/cjs/account/schema.js.map +0 -1
  210. package/dist/cjs/account/simple.d.ts +0 -14
  211. package/dist/cjs/account/simple.js +0 -119
  212. package/dist/cjs/account/simple.js.map +0 -1
  213. package/dist/cjs/account/types.d.ts +0 -30
  214. package/dist/cjs/account/types.js +0 -3
  215. package/dist/cjs/account/types.js.map +0 -1
  216. package/dist/esm/account/base.d.ts +0 -49
  217. package/dist/esm/account/base.js +0 -253
  218. package/dist/esm/account/base.js.map +0 -1
  219. package/dist/esm/account/schema.d.ts +0 -100
  220. package/dist/esm/account/schema.js +0 -35
  221. package/dist/esm/account/schema.js.map +0 -1
  222. package/dist/esm/account/simple.d.ts +0 -14
  223. package/dist/esm/account/simple.js +0 -115
  224. package/dist/esm/account/simple.js.map +0 -1
  225. package/dist/esm/account/types.d.ts +0 -30
  226. package/dist/esm/account/types.js +0 -2
  227. package/dist/esm/account/types.js.map +0 -1
  228. package/dist/types/account/base.d.ts +0 -128
  229. package/dist/types/account/base.d.ts.map +0 -1
  230. package/dist/types/account/schema.d.ts +0 -101
  231. package/dist/types/account/schema.d.ts.map +0 -1
  232. package/dist/types/account/simple.d.ts +0 -15
  233. package/dist/types/account/simple.d.ts.map +0 -1
  234. package/dist/types/account/types.d.ts +0 -144
  235. package/dist/types/account/types.d.ts.map +0 -1
  236. package/src/account/base.ts +0 -415
  237. package/src/account/schema.ts +0 -51
  238. package/src/account/simple.ts +0 -221
  239. package/src/account/types.ts +0 -184
@@ -0,0 +1,201 @@
1
+ import {
2
+ toHex,
3
+ type Address,
4
+ type Chain,
5
+ type Client,
6
+ type Hex,
7
+ type Transport,
8
+ } from "viem";
9
+ import type { ClientMiddlewareConfig } from "../client/types";
10
+ import type { EntryPointVersion } from "../entrypoint/types";
11
+ import { ChainNotFoundError } from "../errors/client.js";
12
+ import type {
13
+ UserOperationFeeOptions,
14
+ UserOperationOverrides,
15
+ UserOperationRequest,
16
+ UserOperationStruct,
17
+ } from "../types";
18
+ import {
19
+ deepHexlify,
20
+ resolveProperties,
21
+ type Deferrable,
22
+ } from "../utils/index.js";
23
+ import type { ClientMiddlewareFn } from "./types";
24
+
25
+ export type Erc7677RpcSchema = [
26
+ {
27
+ Method: "pm_getPaymasterStubData";
28
+ Parameters: [UserOperationRequest, Address, Hex, Record<string, any>];
29
+ ReturnType: {
30
+ sponsor?: { name: string; icon?: string }; // Sponsor info
31
+ paymaster?: Address; // Paymaster address (entrypoint v0.7)
32
+ paymasterData?: Hex; // Paymaster data (entrypoint v0.7)
33
+ paymasterVerificationGasLimit?: Hex; // Paymaster validation gas (entrypoint v0.7)
34
+ paymasterPostOpGasLimit?: Hex; // Paymaster post-op gas (entrypoint v0.7)
35
+ paymasterAndData?: Hex; // Paymaster and data (entrypoint v0.6)
36
+ isFinal?: boolean; // Indicates that the caller does not need to call pm_getPaymasterData
37
+ };
38
+ },
39
+ {
40
+ Method: "pm_getPaymasterData";
41
+ Parameters: [UserOperationRequest, Address, Hex, Record<string, any>];
42
+ ReturnType: {
43
+ paymaster?: Address; // Paymaster address (entrypoint v0.7)
44
+ paymasterData?: Hex; // Paymaster data (entrypoint v0.7)
45
+ paymasterAndData?: Hex; // Paymaster and data (entrypoint v0.6)
46
+ };
47
+ }
48
+ ];
49
+
50
+ export type Erc7677Client<T extends Transport = Transport> = Client<
51
+ T,
52
+ Chain,
53
+ undefined,
54
+ Erc7677RpcSchema
55
+ >;
56
+
57
+ export type Erc7677MiddlewareParams<
58
+ TContext extends Record<string, any> | undefined =
59
+ | Record<string, any>
60
+ | undefined,
61
+ TEntryPointVersion extends EntryPointVersion = EntryPointVersion
62
+ > = {
63
+ context?:
64
+ | ((
65
+ struct: Deferrable<UserOperationStruct<TEntryPointVersion>>,
66
+ args: {
67
+ overrides?: UserOperationOverrides<TEntryPointVersion>;
68
+ feeOptions?: UserOperationFeeOptions;
69
+ }
70
+ ) => Promise<TContext>)
71
+ | TContext;
72
+ };
73
+
74
+ /**
75
+ * Middleware function for interacting with ERC-7677 enabled clients. It supports resolving paymaster and data fields for user operations.
76
+ * This middleware assumes that your RPC provider supports the ERC-7677 methods (pm_getPaymasterStubData and pm_getPaymasterData).
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { createSmartAccountClient, erc7677Middleware } from "@aa-sdk/core";
81
+ * import { http } from "viem";
82
+ * import { sepolia } from "viem/chains";
83
+ *
84
+ * const client = createSmartAccountClient({
85
+ * transport: http("rpc-url"),
86
+ * chain: sepolia,
87
+ * // this assumes that your RPC provider supports the ERC-7677 methods AND takes no context
88
+ * ...erc7677Middleware(),
89
+ * })
90
+ * ```
91
+ *
92
+ * @param {Erc7677MiddlewareParams<TContext>} params Middleware parameters including context function or object. Context can be resolved dynamically by passing in a function which takes in the context at the time of sending a user op
93
+ * @returns {Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData">} An object containing middleware functions `dummyPaymasterAndData` and `paymasterAndData` for processing user operations with the paymaster data
94
+ */
95
+ export function erc7677Middleware<
96
+ TContext extends Record<string, any> | undefined =
97
+ | Record<string, any>
98
+ | undefined
99
+ >(
100
+ params?: Erc7677MiddlewareParams<TContext>
101
+ ): Pick<ClientMiddlewareConfig, "dummyPaymasterAndData" | "paymasterAndData"> {
102
+ const dummyPaymasterAndData: ClientMiddlewareFn = async (
103
+ uo,
104
+ { client, account, feeOptions, overrides }
105
+ ) => {
106
+ const userOp = deepHexlify(await resolveProperties(uo));
107
+
108
+ // Those values will be set after fee estimation.
109
+ userOp.maxFeePerGas = "0x0";
110
+ userOp.maxPriorityFeePerGas = "0x0";
111
+ userOp.callGasLimit = "0x0";
112
+ userOp.verificationGasLimit = "0x0";
113
+ userOp.preVerificationGas = "0x0";
114
+
115
+ const entrypoint = account.getEntryPoint();
116
+
117
+ if (entrypoint.version === "0.7.0") {
118
+ userOp.paymasterVerificationGasLimit = "0x0";
119
+ userOp.paymasterPostOpGasLimit = "0x0";
120
+ }
121
+
122
+ const context =
123
+ (typeof params?.context === "function"
124
+ ? await params?.context(userOp, { overrides, feeOptions })
125
+ : params?.context) ?? {};
126
+
127
+ if (!client.chain) {
128
+ throw new ChainNotFoundError();
129
+ }
130
+
131
+ const erc7677client = client as Erc7677Client;
132
+ // TODO: probably need to handle the sponsor and isFinal fields
133
+ const {
134
+ paymaster,
135
+ paymasterAndData,
136
+ paymasterData,
137
+ paymasterPostOpGasLimit,
138
+ paymasterVerificationGasLimit,
139
+ } = await erc7677client.request({
140
+ method: "pm_getPaymasterStubData",
141
+ params: [userOp, entrypoint.address, toHex(client.chain.id), context],
142
+ });
143
+
144
+ if (entrypoint.version === "0.6.0") {
145
+ return {
146
+ ...uo,
147
+ paymasterAndData,
148
+ };
149
+ }
150
+
151
+ return {
152
+ ...uo,
153
+ paymaster,
154
+ paymasterData,
155
+ paymasterPostOpGasLimit,
156
+ paymasterVerificationGasLimit,
157
+ };
158
+ };
159
+
160
+ const paymasterAndData: ClientMiddlewareFn = async (
161
+ uo,
162
+ { client, account, feeOptions, overrides }
163
+ ) => {
164
+ const userOp = deepHexlify(await resolveProperties(uo));
165
+ const context =
166
+ (typeof params?.context === "function"
167
+ ? await params?.context(userOp, { overrides, feeOptions })
168
+ : params?.context) ?? {};
169
+
170
+ if (!client.chain) {
171
+ throw new ChainNotFoundError();
172
+ }
173
+
174
+ const erc7677client = client as Erc7677Client;
175
+
176
+ const entrypoint = account.getEntryPoint();
177
+ const { paymaster, paymasterAndData, paymasterData } =
178
+ await erc7677client.request({
179
+ method: "pm_getPaymasterData",
180
+ params: [userOp, entrypoint.address, toHex(client.chain.id), context],
181
+ });
182
+
183
+ if (entrypoint.version === "0.6.0") {
184
+ return {
185
+ ...uo,
186
+ paymasterAndData,
187
+ };
188
+ }
189
+
190
+ return {
191
+ ...uo,
192
+ paymaster,
193
+ paymasterData,
194
+ };
195
+ };
196
+
197
+ return {
198
+ dummyPaymasterAndData,
199
+ paymasterAndData,
200
+ };
201
+ }
@@ -1,12 +1,14 @@
1
+ import type { UserOperationContext } from "../actions/smartAccount/types";
1
2
  import type { ClientMiddlewareFn } from "./types";
2
3
 
3
4
  /**
4
5
  * Noop middleware that does nothing and passes the arguments through
5
6
  *
6
- * @async
7
- * @param args the client middleware arguments passed to the middleware
8
- * @returns the arguments passed to the middleware and returned as is without modification
7
+ * @param {Deferrable<UserOperationStruct<TEntryPointVersion>>} args the client middleware arguments passed to the middleware
8
+ * @returns {Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>>} the arguments passed to the middleware and returned as is without modification
9
9
  */
10
- export const noopMiddleware: ClientMiddlewareFn = async (args) => {
10
+ export const noopMiddleware: ClientMiddlewareFn<
11
+ UserOperationContext | undefined
12
+ > = async (args) => {
11
13
  return args;
12
14
  };
@@ -11,6 +11,21 @@ import type {
11
11
  import type { Deferrable } from "../utils";
12
12
  import type { MiddlewareClient } from "./actions";
13
13
 
14
+ export type ClientMiddlewareArgs<
15
+ TAccount extends SmartContractAccount,
16
+ C extends MiddlewareClient,
17
+ TContext extends UserOperationContext | undefined =
18
+ | UserOperationContext
19
+ | undefined,
20
+ TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
21
+ > = {
22
+ overrides?: UserOperationOverrides<TEntryPointVersion>;
23
+ context?: TContext;
24
+ feeOptions?: UserOperationFeeOptions;
25
+ account: TAccount;
26
+ client: C;
27
+ };
28
+
14
29
  // [!region ClientMiddlewareFn]
15
30
  export type ClientMiddlewareFn<
16
31
  TContext extends UserOperationContext | undefined =
@@ -22,13 +37,7 @@ export type ClientMiddlewareFn<
22
37
  TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
23
38
  >(
24
39
  struct: Deferrable<UserOperationStruct<TEntryPointVersion>>,
25
- args: {
26
- overrides?: UserOperationOverrides<TEntryPointVersion>;
27
- context?: TContext;
28
- feeOptions?: UserOperationFeeOptions;
29
- account: TAccount;
30
- client: C;
31
- }
40
+ args: ClientMiddlewareArgs<TAccount, C, TContext, TEntryPointVersion>
32
41
  ) => Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>>;
33
42
  // [!endregion ClientMiddlewareFn]
34
43
 
@@ -21,17 +21,67 @@ export class LocalAccountSigner<
21
21
  inner: T;
22
22
  signerType: string;
23
23
 
24
+ /**
25
+ * A function to initialize an object with an inner parameter and derive a signerType from it.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { LocalAccountSigner } from "@aa-sdk/core";
30
+ * import { privateKeyToAccount, generatePrivateKey } from "viem";
31
+ *
32
+ * const signer = new LocalAccountSigner(
33
+ * privateKeyToAccount(generatePrivateKey()),
34
+ * );
35
+ * ```
36
+ *
37
+ * @param {T} inner The inner parameter containing the necessary data
38
+ */
24
39
  constructor(inner: T) {
25
40
  this.inner = inner;
26
41
  this.signerType = inner.type; // type: "local"
27
42
  }
28
43
 
44
+ /**
45
+ * Signs the provided message using the inner signMessage function.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { LocalAccountSigner } from "@aa-sdk/core";
50
+ * import { generatePrivateKey } from "viem";
51
+ *
52
+ * const signer = LocalAccountSigner.mnemonicToAccountSigner(generatePrivateKey());
53
+ * const signature = await signer.signMessage("Hello, world!");
54
+ * ```
55
+ *
56
+ * @param {string} message The message to be signed
57
+ * @returns {Promise<any>} A promise that resolves to the signed message
58
+ */
29
59
  readonly signMessage: (message: SignableMessage) => Promise<`0x${string}`> = (
30
60
  message
31
61
  ) => {
32
62
  return this.inner.signMessage({ message });
33
63
  };
34
64
 
65
+ /**
66
+ * Signs typed data using the given parameters.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { LocalAccountSigner } from "@aa-sdk/core";
71
+ * import { generatePrivateKey } from "viem";
72
+ *
73
+ * const signer = LocalAccountSigner.mnemonicToAccountSigner(generatePrivateKey());
74
+ * const signature = await signer.signTypedData({
75
+ * domain: {},
76
+ * types: {},
77
+ * primaryType: "",
78
+ * message: {},
79
+ * });
80
+ * ```
81
+ *
82
+ * @param {TypedDataDefinition<TTypedData, TPrimaryType>} params The parameters defining the typed data and primary type
83
+ * @returns {Promise<Hex>} A promise that resolves to the signed data in hexadecimal format
84
+ */
35
85
  readonly signTypedData = async <
36
86
  const TTypedData extends TypedData | { [key: string]: unknown },
37
87
  TPrimaryType extends string = string
@@ -41,10 +91,39 @@ export class LocalAccountSigner<
41
91
  return this.inner.signTypedData(params);
42
92
  };
43
93
 
44
- readonly getAddress: () => Promise<`0x${string}`> = async () => {
94
+ /**
95
+ * Returns the address of the inner object in a specific hexadecimal format.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { LocalAccountSigner } from "@aa-sdk/core";
100
+ * import { generatePrivateKey } from "viem";
101
+ *
102
+ * const signer = LocalAccountSigner.mnemonicToAccountSigner(generatePrivateKey());
103
+ * const address = await signer.getAddress();
104
+ * ```
105
+ *
106
+ * @returns {Promise<Hex>} A promise that resolves to the address in the format `0x{string}`
107
+ */
108
+ readonly getAddress = async (): Promise<`0x${string}`> => {
45
109
  return this.inner.address;
46
110
  };
47
111
 
112
+ /**
113
+ * Creates a LocalAccountSigner using the provided mnemonic key and optional HD options.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { LocalAccountSigner } from "@aa-sdk/core";
118
+ * import { generateMnemonic } from "viem";
119
+ *
120
+ * const signer = LocalAccountSigner.mnemonicToAccountSigner(generateMnemonic());
121
+ * ```
122
+ *
123
+ * @param {string} key The mnemonic key to derive the account from.
124
+ * @param {HDOptions} [opts] Optional HD options for deriving the account.
125
+ * @returns {LocalAccountSigner<HDAccount>} A LocalAccountSigner object for the derived account.
126
+ */
48
127
  static mnemonicToAccountSigner(
49
128
  key: string,
50
129
  opts?: HDOptions
@@ -53,7 +132,20 @@ export class LocalAccountSigner<
53
132
  return new LocalAccountSigner(signer);
54
133
  }
55
134
 
56
- static privateKeyToAccountSigner(
135
+ /**
136
+ * Creates a `LocalAccountSigner` instance using the provided private key.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { LocalAccountSigner } from "@aa-sdk/core";
141
+ * import { generatePrivateKey } from "viem";
142
+ *
143
+ * const signer = LocalAccountSigner.mnemonicToAccountSigner(generatePrivateKey());
144
+ * ```
145
+ *
146
+ * @param {Hex} key The private key in hexadecimal format
147
+ * @returns {LocalAccountSigner<PrivateKeyAccount>} An instance of `LocalAccountSigner` initialized with the provided private key
148
+ */ static privateKeyToAccountSigner(
57
149
  key: Hex
58
150
  ): LocalAccountSigner<PrivateKeyAccount> {
59
151
  const signer = privateKeyToAccount(key);
@@ -16,6 +16,27 @@ export class WalletClientSigner implements SmartAccountSigner<WalletClient> {
16
16
  signerType: string;
17
17
  inner: WalletClient;
18
18
 
19
+ /**
20
+ * Initializes a signer with a given wallet client and signer type.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { WalletClientSigner } from "@aa-sdk/core";
25
+ * import { createWalletClient, custom } from 'viem'
26
+ * import { mainnet } from 'viem/chains'
27
+ *
28
+ * const client = createWalletClient({
29
+ * chain: mainnet,
30
+ * transport: custom(window.ethereum!)
31
+ * });
32
+ *
33
+ * const signer = new WalletClientSigner(client, 'wallet');
34
+ * ```
35
+ *
36
+ * @param {WalletClient} client The wallet client to interact with
37
+ * @param {string} signerType The type of signer; must be a valid signer type, otherwise an error will be thrown
38
+ * @throws {InvalidSignerTypeError} If the signer type is invalid
39
+ */
19
40
  constructor(client: WalletClient, signerType: string) {
20
41
  this.inner = client;
21
42
  if (!signerType) {
@@ -24,11 +45,52 @@ export class WalletClientSigner implements SmartAccountSigner<WalletClient> {
24
45
  this.signerType = signerType;
25
46
  }
26
47
 
48
+ /**
49
+ * Asynchronously retrieves addresses from the inner object and returns the first address after applying the `getAddress` function.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { WalletClientSigner } from "@aa-sdk/core";
54
+ * import { createWalletClient, custom } from 'viem'
55
+ * import { mainnet } from 'viem/chains'
56
+ *
57
+ * const client = createWalletClient({
58
+ * chain: mainnet,
59
+ * transport: custom(window.ethereum!)
60
+ * });
61
+ *
62
+ * const signer = new WalletClientSigner(client, 'wallet');
63
+ * console.log(await signer.getAddress());
64
+ * ```
65
+ *
66
+ * @returns {Promise<string>} A promise that resolves to the first address after being processed by the `getAddress` function.
67
+ */
27
68
  getAddress: () => Promise<`0x${string}`> = async () => {
28
69
  let addresses = await this.inner.getAddresses();
29
70
  return getAddress(addresses[0]);
30
71
  };
31
72
 
73
+ /**
74
+ * Signs a message using the account's signing method.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { WalletClientSigner } from "@aa-sdk/core";
79
+ * import { createWalletClient, custom } from 'viem'
80
+ * import { mainnet } from 'viem/chains'
81
+ *
82
+ * const client = createWalletClient({
83
+ * chain: mainnet,
84
+ * transport: custom(window.ethereum!)
85
+ * });
86
+ *
87
+ * const signer = new WalletClientSigner(client, 'wallet');
88
+ * console.log(await signer.signMessage("hello"));
89
+ * ```
90
+ *
91
+ * @param {string} message the message string that needs to be signed
92
+ * @returns {Promise<string>} a promise that resolves to the signed message
93
+ */
32
94
  readonly signMessage: (message: SignableMessage) => Promise<`0x${string}`> =
33
95
  async (message) => {
34
96
  const account = this.inner.account ?? (await this.getAddress());
@@ -36,6 +98,33 @@ export class WalletClientSigner implements SmartAccountSigner<WalletClient> {
36
98
  return this.inner.signMessage({ message, account });
37
99
  };
38
100
 
101
+ /**
102
+ * Signs the provided typed data using the account's private key.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { WalletClientSigner } from "@aa-sdk/core";
107
+ * import { createWalletClient, custom } from 'viem'
108
+ * import { mainnet } from 'viem/chains'
109
+ *
110
+ * const client = createWalletClient({
111
+ * chain: mainnet,
112
+ * transport: custom(window.ethereum!)
113
+ * });
114
+ *
115
+ * const signer = new WalletClientSigner(client, 'wallet');
116
+ * console.log(await signer.signTypedData({
117
+ * types: {
118
+ * "Message": [{ name: "content", type: "string" }]
119
+ * },
120
+ * primaryType: "Message",
121
+ * message: { content: "Hello" },
122
+ * }));
123
+ * ```
124
+ *
125
+ * @param {TypedDataDefinition<TTypedData, TPrimaryType>} typedData The typed data to be signed
126
+ * @returns {Promise<Hex>} A promise that resolves to a hex string representing the signed data
127
+ */
39
128
  signTypedData = async <
40
129
  const TTypedData extends TypedData | { [key: string]: unknown },
41
130
  TPrimaryType extends string = string
@@ -37,8 +37,8 @@ export interface SplitTransportParams {
37
37
  * });
38
38
  * ```
39
39
  *
40
- * @param params {@link SplitTransportParams} split transport configuration containing the methods overrides and fallback transport
41
- * @returns a {@link CustomTransport} that splits traffic
40
+ * @param {SplitTransportParams} params split transport configuration containing the methods overrides and fallback transport
41
+ * @returns {CustomTransport} a viem Transport that splits traffic
42
42
  */
43
43
  export const split = (params: SplitTransportParams): CustomTransport => {
44
44
  const overrideMap = params.overrides.reduce((accum, curr) => {
@@ -5,8 +5,8 @@ import { isMultiplier } from "./schema.js";
5
5
  /**
6
6
  * Returns the max bigint in a list of bigints
7
7
  *
8
- * @param args a list of bigints to get the max of
9
- * @returns the max bigint in the list
8
+ * @param {bigint[]} args a list of bigints to get the max of
9
+ * @returns {bigint} the max bigint in the list
10
10
  */
11
11
  export const bigIntMax = (...args: bigint[]): bigint => {
12
12
  if (!args.length) {
@@ -19,8 +19,8 @@ export const bigIntMax = (...args: bigint[]): bigint => {
19
19
  /**
20
20
  * Returns the min bigint in a list of bigints
21
21
  *
22
- * @param args a list of bigints to get the max of
23
- * @returns the min bigint in the list
22
+ * @param {bigint[]} args a list of bigints to get the max of
23
+ * @returns {bigint} the min bigint in the list
24
24
  */
25
25
  export const bigIntMin = (...args: bigint[]): bigint => {
26
26
  if (!args.length) {
@@ -33,16 +33,16 @@ export const bigIntMin = (...args: bigint[]): bigint => {
33
33
  /**
34
34
  * Given a bigint and a min-max range, returns the min-max clamped bigint value
35
35
  *
36
- * @param value a bigint value to clamp
37
- * @param lower lower bound min max tuple value
38
- * @param upper upper bound min max tuple value
39
- * @returns the clamped bigint value per given range
36
+ * @param {BigNumberish} value a bigint value to clamp
37
+ * @param {BigNumberish | undefined} lower lower bound min max tuple value
38
+ * @param {BigNumberish | undefined} upper upper bound min max tuple value
39
+ * @returns {bigint} the clamped bigint value per given range
40
40
  */
41
41
  export const bigIntClamp = (
42
42
  value: BigNumberish,
43
43
  lower: BigNumberish | null | undefined,
44
44
  upper: BigNumberish | null | undefined
45
- ) => {
45
+ ): bigint => {
46
46
  lower = lower != null ? BigInt(lower) : null;
47
47
  upper = upper != null ? BigInt(upper) : null;
48
48
 
@@ -71,10 +71,10 @@ export enum RoundingMode {
71
71
  * Given a bigint and a number (which can be a float), returns the bigint value.
72
72
  * Note: this function has loss and will round down to the nearest integer.
73
73
  *
74
- * @param base - the number to be multiplied
75
- * @param multiplier - the amount to multiply by
76
- * @param roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP
77
- * @returns the bigint value of the multiplication with the number rounded by the rounding mode
74
+ * @param {BigNumberish} base - the number to be multiplied
75
+ * @param {number} multiplier - the amount to multiply by
76
+ * @param {RoundingMode} roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP
77
+ * @returns {bigint} the bigint value of the multiplication with the number rounded by the rounding mode
78
78
  */
79
79
  export const bigIntMultiply = (
80
80
  base: BigNumberish,
@@ -111,8 +111,8 @@ export const bigIntMultiply = (
111
111
  * });
112
112
  * ```
113
113
  *
114
- * @param phrase -- any string value.
115
- * @returns the bigint value of the hashed string
114
+ * @param {string} phrase -- any string value.
115
+ * @returns {bigint} the bigint value of the hashed string
116
116
  */
117
117
  export const stringToIndex = (phrase: string): bigint =>
118
118
  BigInt(keccak256(toHex(phrase)));
@@ -8,11 +8,11 @@ type TakeBytesOpts = {
8
8
  /**
9
9
  * Given a bytes string, returns a slice of the bytes
10
10
  *
11
- * @param bytes - the hex string representing bytes
12
- * @param opts - optional parameters for slicing the bytes
13
- * @param opts.offset - the offset in bytes to start slicing from
14
- * @param opts.count - the number of bytes to slice
15
- * @returns the sliced bytes
11
+ * @param {Hex} bytes - the hex string representing bytes
12
+ * @param {TakeBytesOpts} opts - optional parameters for slicing the bytes
13
+ * @param {number} opts.offset - the offset in bytes to start slicing from
14
+ * @param {number} opts.count - the number of bytes to slice
15
+ * @returns {Hex} the sliced bytes
16
16
  */
17
17
  export const takeBytes = (bytes: Hex, opts: TakeBytesOpts = {}): Hex => {
18
18
  const { offset, count } = opts;
@@ -1,79 +1,7 @@
1
- import { type Address, type Chain } from "viem";
2
- import {
3
- arbitrum,
4
- arbitrumGoerli,
5
- arbitrumSepolia,
6
- base,
7
- baseGoerli,
8
- baseSepolia,
9
- fraxtal,
10
- goerli,
11
- mainnet,
12
- optimism,
13
- optimismGoerli,
14
- optimismSepolia,
15
- polygon,
16
- polygonAmoy,
17
- polygonMumbai,
18
- sepolia,
19
- zora,
20
- zoraSepolia,
21
- } from "viem/chains";
22
- import { defaultEntryPointVersion } from "../entrypoint/index.js";
23
- import type { EntryPointVersion } from "../entrypoint/types.js";
24
- import { DefaultFactoryNotDefinedError } from "../errors/account.js";
1
+ import { type Chain } from "viem";
2
+ import { arbitrum, arbitrumGoerli, arbitrumSepolia } from "viem/chains";
25
3
  import type { UserOperationFeeOptions } from "../types.js";
26
4
 
27
- /**
28
- * Utility method returning the default simple account factory address given a {@link Chain} object
29
- *
30
- * @param chain - a {@link Chain} object
31
- * @param version - {@link EntryPointVersion} value that defaults to `defaultEntryPointVersion`
32
- * @returns a {@link abi.Address} for the given chain
33
- * @throws if the chain doesn't have an address currently deployed
34
- */
35
- export const getDefaultSimpleAccountFactoryAddress = (
36
- chain: Chain,
37
- version: EntryPointVersion = defaultEntryPointVersion
38
- ): Address => {
39
- switch (version) {
40
- case "0.6.0":
41
- switch (chain.id) {
42
- case mainnet.id:
43
- case polygon.id:
44
- case polygonAmoy.id:
45
- case optimism.id:
46
- case optimismSepolia.id:
47
- case arbitrum.id:
48
- case arbitrumSepolia.id:
49
- case base.id:
50
- case baseGoerli.id:
51
- case baseSepolia.id:
52
- case fraxtal.id:
53
- case 2523:
54
- case zora.id:
55
- case zoraSepolia.id:
56
- return "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232";
57
- case sepolia.id:
58
- case goerli.id:
59
- case polygonMumbai.id:
60
- case optimismGoerli.id:
61
- case arbitrumGoerli.id:
62
- return "0x9406Cc6185a346906296840746125a0E44976454";
63
- default:
64
- break;
65
- }
66
- break;
67
- case "0.7.0":
68
- switch (chain.id) {
69
- default:
70
- return "0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985";
71
- }
72
- }
73
-
74
- throw new DefaultFactoryNotDefinedError("SimpleAccount", chain, version);
75
- };
76
-
77
5
  export const minPriorityFeePerBidDefaults = new Map<number, bigint>([
78
6
  [arbitrum.id, 10_000_000n],
79
7
  [arbitrumGoerli.id, 10_000_000n],