@account-kit/wallet-client 0.1.0-alpha.9 → 4.50.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 (276) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/client/actions/formatSign.d.ts +30 -0
  3. package/dist/esm/client/actions/formatSign.js +32 -0
  4. package/dist/esm/client/actions/formatSign.js.map +1 -0
  5. package/dist/esm/client/actions/getCallsStatus.d.ts +6 -3
  6. package/dist/esm/client/actions/getCallsStatus.js +3 -0
  7. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +10 -11
  9. package/dist/esm/client/actions/grantPermissions.js +26 -12
  10. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  11. package/dist/esm/client/actions/listAccounts.d.ts +10 -3
  12. package/dist/esm/client/actions/listAccounts.js +14 -2
  13. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  14. package/dist/esm/client/actions/prepareCalls.d.ts +6 -3
  15. package/dist/esm/client/actions/prepareCalls.js +12 -8
  16. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  17. package/dist/esm/client/actions/prepareSign.d.ts +28 -0
  18. package/dist/esm/client/actions/prepareSign.js +31 -0
  19. package/dist/esm/client/actions/prepareSign.js.map +1 -0
  20. package/dist/esm/client/actions/requestAccount.d.ts +3 -1
  21. package/dist/esm/client/actions/requestAccount.js +5 -3
  22. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  23. package/dist/esm/client/actions/sendPreparedCalls.d.ts +3 -1
  24. package/dist/esm/client/actions/sendPreparedCalls.js +2 -0
  25. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  26. package/dist/esm/client/actions/signMessage.d.ts +5 -2
  27. package/dist/esm/client/actions/signMessage.js +5 -2
  28. package/dist/esm/client/actions/signMessage.js.map +1 -1
  29. package/dist/esm/client/actions/signPreparedCalls.d.ts +2 -2
  30. package/dist/esm/client/actions/signPreparedCalls.js +3 -3
  31. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
  32. package/dist/esm/client/actions/signSignatureRequest.d.ts +6 -10
  33. package/dist/esm/client/actions/signSignatureRequest.js +4 -7
  34. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  35. package/dist/esm/client/actions/signTypedData.d.ts +2 -0
  36. package/dist/esm/client/actions/signTypedData.js +2 -0
  37. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  38. package/dist/esm/client/decorator.d.ts +0 -2
  39. package/dist/esm/client/decorator.js +1 -3
  40. package/dist/esm/client/decorator.js.map +1 -1
  41. package/dist/esm/client/index.d.ts +10 -6
  42. package/dist/esm/client/index.js +18 -21
  43. package/dist/esm/client/index.js.map +1 -1
  44. package/dist/esm/exports/index.d.ts +1 -5
  45. package/dist/esm/exports/index.js +1 -6
  46. package/dist/esm/exports/index.js.map +1 -1
  47. package/dist/esm/internal/account.d.ts +33 -0
  48. package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +25 -49
  49. package/dist/esm/internal/account.js.map +1 -0
  50. package/dist/esm/types.d.ts +5 -11
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils.d.ts +13 -1
  53. package/dist/esm/utils.js +13 -1
  54. package/dist/esm/utils.js.map +1 -1
  55. package/dist/esm/version.d.ts +1 -0
  56. package/dist/esm/version.js +4 -0
  57. package/dist/esm/version.js.map +1 -0
  58. package/dist/types/client/actions/formatSign.d.ts +31 -0
  59. package/dist/types/client/actions/formatSign.d.ts.map +1 -0
  60. package/dist/types/client/actions/getCallsStatus.d.ts +6 -3
  61. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  62. package/dist/types/client/actions/grantPermissions.d.ts +10 -11
  63. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  64. package/dist/types/client/actions/listAccounts.d.ts +10 -3
  65. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  66. package/dist/types/client/actions/prepareCalls.d.ts +6 -3
  67. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  68. package/dist/types/client/actions/prepareSign.d.ts +29 -0
  69. package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
  70. package/dist/types/client/actions/requestAccount.d.ts +3 -1
  71. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  72. package/dist/types/client/actions/sendPreparedCalls.d.ts +3 -1
  73. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  74. package/dist/types/client/actions/signMessage.d.ts +5 -2
  75. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  76. package/dist/types/client/actions/signPreparedCalls.d.ts +2 -2
  77. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
  78. package/dist/types/client/actions/signSignatureRequest.d.ts +6 -10
  79. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  80. package/dist/types/client/actions/signTypedData.d.ts +2 -0
  81. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  82. package/dist/types/client/decorator.d.ts +0 -2
  83. package/dist/types/client/decorator.d.ts.map +1 -1
  84. package/dist/types/client/index.d.ts +10 -6
  85. package/dist/types/client/index.d.ts.map +1 -1
  86. package/dist/types/exports/index.d.ts +1 -5
  87. package/dist/types/exports/index.d.ts.map +1 -1
  88. package/dist/types/internal/account.d.ts +34 -0
  89. package/dist/types/internal/account.d.ts.map +1 -0
  90. package/dist/types/types.d.ts +5 -11
  91. package/dist/types/types.d.ts.map +1 -1
  92. package/dist/types/utils.d.ts +13 -1
  93. package/dist/types/utils.d.ts.map +1 -1
  94. package/dist/types/version.d.ts +2 -0
  95. package/dist/types/version.d.ts.map +1 -0
  96. package/package.json +32 -28
  97. package/src/client/actions/formatSign.ts +55 -0
  98. package/src/client/actions/getCallsStatus.ts +10 -6
  99. package/src/client/actions/grantPermissions.ts +46 -18
  100. package/src/client/actions/listAccounts.ts +22 -5
  101. package/src/client/actions/prepareCalls.ts +22 -16
  102. package/src/client/actions/prepareSign.ts +51 -0
  103. package/src/client/actions/requestAccount.ts +6 -4
  104. package/src/client/actions/sendPreparedCalls.ts +3 -1
  105. package/src/client/actions/signMessage.ts +5 -2
  106. package/src/client/actions/signPreparedCalls.ts +8 -12
  107. package/src/client/actions/signSignatureRequest.ts +12 -15
  108. package/src/client/actions/signTypedData.ts +2 -0
  109. package/src/client/decorator.ts +1 -8
  110. package/src/client/index.ts +41 -33
  111. package/src/exports/index.ts +1 -13
  112. package/src/internal/account.ts +120 -0
  113. package/src/types.ts +7 -18
  114. package/src/utils.ts +13 -1
  115. package/src/version.ts +3 -0
  116. package/dist/esm/capabilities/eip7702Auth.d.ts +0 -4
  117. package/dist/esm/capabilities/eip7702Auth.js +0 -18
  118. package/dist/esm/capabilities/eip7702Auth.js.map +0 -1
  119. package/dist/esm/capabilities/index.d.ts +0 -41
  120. package/dist/esm/capabilities/index.js +0 -14
  121. package/dist/esm/capabilities/index.js.map +0 -1
  122. package/dist/esm/capabilities/multiDimensionalNonce.d.ts +0 -3
  123. package/dist/esm/capabilities/multiDimensionalNonce.js +0 -7
  124. package/dist/esm/capabilities/multiDimensionalNonce.js.map +0 -1
  125. package/dist/esm/capabilities/overrides.d.ts +0 -26
  126. package/dist/esm/capabilities/overrides.js +0 -14
  127. package/dist/esm/capabilities/overrides.js.map +0 -1
  128. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  129. package/dist/esm/capabilities/paymaster.js +0 -5
  130. package/dist/esm/capabilities/paymaster.js.map +0 -1
  131. package/dist/esm/capabilities/permissions/index.d.ts +0 -145
  132. package/dist/esm/capabilities/permissions/index.js +0 -83
  133. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  134. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  135. package/dist/esm/capabilities/permissions/mav2.js +0 -88
  136. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  137. package/dist/esm/client/actions/createAccount.d.ts +0 -35
  138. package/dist/esm/client/actions/createAccount.js +0 -32
  139. package/dist/esm/client/actions/createAccount.js.map +0 -1
  140. package/dist/esm/client/client.e2e-test.d.ts +0 -1
  141. package/dist/esm/client/client.e2e-test.js +0 -375
  142. package/dist/esm/client/client.e2e-test.js.map +0 -1
  143. package/dist/esm/exports/internal.d.ts +0 -14
  144. package/dist/esm/exports/internal.js +0 -16
  145. package/dist/esm/exports/internal.js.map +0 -1
  146. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
  147. package/dist/esm/isomorphic/actions/createSession.js +0 -95
  148. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  149. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
  150. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
  151. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  152. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
  153. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
  154. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  155. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  156. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -157
  157. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  158. package/dist/esm/isomorphic/client.d.ts +0 -239
  159. package/dist/esm/isomorphic/client.js +0 -37
  160. package/dist/esm/isomorphic/client.js.map +0 -1
  161. package/dist/esm/isomorphic/utils/7702.d.ts +0 -23
  162. package/dist/esm/isomorphic/utils/7702.js +0 -75
  163. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  164. package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -24
  165. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  166. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  167. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  168. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  169. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  170. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
  171. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  172. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  173. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  174. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  175. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  176. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  177. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  178. package/dist/esm/local/client.d.ts +0 -3
  179. package/dist/esm/local/client.js +0 -97
  180. package/dist/esm/local/client.js.map +0 -1
  181. package/dist/esm/remote/client.d.ts +0 -9
  182. package/dist/esm/remote/client.js +0 -41
  183. package/dist/esm/remote/client.js.map +0 -1
  184. package/dist/esm/rpc/examples.d.ts +0 -230
  185. package/dist/esm/rpc/examples.js +0 -314
  186. package/dist/esm/rpc/examples.js.map +0 -1
  187. package/dist/esm/rpc/request.d.ts +0 -755
  188. package/dist/esm/rpc/request.js +0 -214
  189. package/dist/esm/rpc/request.js.map +0 -1
  190. package/dist/esm/rpc/schema.d.ts +0 -703
  191. package/dist/esm/rpc/schema.js +0 -5
  192. package/dist/esm/rpc/schema.js.map +0 -1
  193. package/dist/esm/schemas.d.ts +0 -712
  194. package/dist/esm/schemas.js +0 -463
  195. package/dist/esm/schemas.js.map +0 -1
  196. package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
  197. package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
  198. package/dist/types/capabilities/index.d.ts +0 -42
  199. package/dist/types/capabilities/index.d.ts.map +0 -1
  200. package/dist/types/capabilities/multiDimensionalNonce.d.ts +0 -4
  201. package/dist/types/capabilities/multiDimensionalNonce.d.ts.map +0 -1
  202. package/dist/types/capabilities/overrides.d.ts +0 -27
  203. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  204. package/dist/types/capabilities/paymaster.d.ts +0 -4
  205. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  206. package/dist/types/capabilities/permissions/index.d.ts +0 -146
  207. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  208. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  209. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  210. package/dist/types/client/actions/createAccount.d.ts +0 -36
  211. package/dist/types/client/actions/createAccount.d.ts.map +0 -1
  212. package/dist/types/client/client.e2e-test.d.ts +0 -2
  213. package/dist/types/client/client.e2e-test.d.ts.map +0 -1
  214. package/dist/types/exports/internal.d.ts +0 -15
  215. package/dist/types/exports/internal.d.ts.map +0 -1
  216. package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
  217. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  218. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
  219. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  220. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
  221. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  222. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
  223. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  224. package/dist/types/isomorphic/client.d.ts +0 -240
  225. package/dist/types/isomorphic/client.d.ts.map +0 -1
  226. package/dist/types/isomorphic/utils/7702.d.ts +0 -24
  227. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  228. package/dist/types/isomorphic/utils/createAccount.d.ts +0 -25
  229. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  230. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  231. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  232. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  233. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  234. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  235. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  236. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  237. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  238. package/dist/types/local/client.d.ts +0 -4
  239. package/dist/types/local/client.d.ts.map +0 -1
  240. package/dist/types/remote/client.d.ts +0 -10
  241. package/dist/types/remote/client.d.ts.map +0 -1
  242. package/dist/types/rpc/examples.d.ts +0 -231
  243. package/dist/types/rpc/examples.d.ts.map +0 -1
  244. package/dist/types/rpc/request.d.ts +0 -756
  245. package/dist/types/rpc/request.d.ts.map +0 -1
  246. package/dist/types/rpc/schema.d.ts +0 -704
  247. package/dist/types/rpc/schema.d.ts.map +0 -1
  248. package/dist/types/schemas.d.ts +0 -713
  249. package/dist/types/schemas.d.ts.map +0 -1
  250. package/src/capabilities/eip7702Auth.ts +0 -26
  251. package/src/capabilities/index.ts +0 -14
  252. package/src/capabilities/multiDimensionalNonce.ts +0 -7
  253. package/src/capabilities/overrides.ts +0 -35
  254. package/src/capabilities/paymaster.ts +0 -5
  255. package/src/capabilities/permissions/index.ts +0 -163
  256. package/src/capabilities/permissions/mav2.ts +0 -138
  257. package/src/client/actions/createAccount.ts +0 -53
  258. package/src/client/client.e2e-test.ts +0 -463
  259. package/src/exports/internal.ts +0 -17
  260. package/src/isomorphic/actions/createSession.ts +0 -159
  261. package/src/isomorphic/actions/getCallsStatus.ts +0 -170
  262. package/src/isomorphic/actions/prepareCalls.ts +0 -170
  263. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -232
  264. package/src/isomorphic/client.ts +0 -94
  265. package/src/isomorphic/utils/7702.ts +0 -143
  266. package/src/isomorphic/utils/createAccount.ts +0 -170
  267. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  268. package/src/isomorphic/utils/decodeSignature.ts +0 -18
  269. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
  270. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  271. package/src/local/client.ts +0 -136
  272. package/src/remote/client.ts +0 -67
  273. package/src/rpc/examples.ts +0 -342
  274. package/src/rpc/request.ts +0 -300
  275. package/src/rpc/schema.ts +0 -40
  276. package/src/schemas.ts +0 -657
@@ -1,170 +0,0 @@
1
- import {
2
- type SmartAccountClient,
3
- type SmartContractAccount,
4
- } from "@aa-sdk/core";
5
- import type { Static } from "@sinclair/typebox";
6
- import { Value } from "@sinclair/typebox/value";
7
- import {
8
- ChainNotFoundError,
9
- hexToNumber,
10
- isHex,
11
- type Chain,
12
- type Hex,
13
- type TransactionReceipt,
14
- type Transport,
15
- } from "viem";
16
- import type { wallet_getCallsStatus } from "../../rpc/request.js";
17
- import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
18
- import { TypeCallId } from "../../schemas.js";
19
- import { castToHex } from "../../utils.js";
20
- import { InternalError, BaseError } from "ox/RpcResponse";
21
- import {
22
- polygon,
23
- mainnet,
24
- base,
25
- worldchain,
26
- optimism,
27
- arbitrum,
28
- sepolia,
29
- polygonAmoy,
30
- baseSepolia,
31
- optimismSepolia,
32
- worldchainSepolia,
33
- arbitrumSepolia,
34
- } from "viem/chains";
35
-
36
- export type GetCallsStatusParams = Static<
37
- (typeof wallet_getCallsStatus)["properties"]["Request"]["properties"]["params"]
38
- >[0];
39
-
40
- export type GetCallsStatusResponse = Static<
41
- (typeof wallet_getCallsStatus)["properties"]["ReturnType"]
42
- >;
43
-
44
- const ReceiptStatus: Record<TransactionReceipt["status"], Hex> = {
45
- reverted: "0x0",
46
- success: "0x1",
47
- };
48
-
49
- /** EIP-5792 call status codes */
50
- export const CallStatusCode = {
51
- /** Batch has been received by the wallet but has not completed execution onchain */
52
- PENDING: 100,
53
- /** Batch has been included onchain without reverts, receipts array contains info of all calls */
54
- CONFIRMED: 200,
55
- /** Batch has not been included onchain and wallet will not retry */
56
- OFFCHAIN_FAILURE: 400,
57
- /** Batch reverted *completely* and only changes related to gas charge may have been included onchain */
58
- CHAIN_RULES_FAILURE: 500,
59
- /** Batch reverted *partially* and some changes related to batch calls may have been included onchain */
60
- PARTIAL_CHAIN_RULES_FAILURE: 600,
61
- } as const;
62
-
63
- // https://eips.ethereum.org/EIPS/eip-5792#error-codes
64
- const ErrorCode = {
65
- UNKNOWN_BUNDLE_ID: 5730,
66
- };
67
-
68
- // "eth_getUserOperationByHash" is limited to the last 150 blocks
69
- // for all networks except those in this list.
70
- // https://www.alchemy.com/docs/node/bundler-api/bundler-api-endpoints/eth-get-user-operation-by-hash
71
- const GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS: number[] = [
72
- mainnet.id,
73
- sepolia.id,
74
- polygon.id,
75
- polygonAmoy.id,
76
- base.id,
77
- baseSepolia.id,
78
- optimism.id,
79
- optimismSepolia.id,
80
- worldchain.id,
81
- worldchainSepolia.id,
82
- arbitrum.id,
83
- arbitrumSepolia.id,
84
- ];
85
-
86
- export async function getCallsStatus(
87
- client: SmartAccountClient<
88
- Transport,
89
- Chain,
90
- SmartContractAccount | undefined,
91
- Record<string, unknown>,
92
- WalletServerViemRpcSchema
93
- >,
94
- callId: GetCallsStatusParams,
95
- ): Promise<GetCallsStatusResponse> {
96
- if (!client.chain) {
97
- throw new ChainNotFoundError();
98
- }
99
- const { chainId, hash } = Value.Decode(TypeCallId, callId);
100
-
101
- const baseResp = {
102
- id: callId,
103
- chainId,
104
- atomic: true,
105
- };
106
-
107
- const result = await client.getUserOperationByHash(hash);
108
- if (
109
- !result &&
110
- GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS.includes(hexToNumber(chainId))
111
- ) {
112
- // This network has unlimited range, so we should always have a result here if the callId is valid.
113
- throw new BaseError({
114
- message: `callId ${callId} not found`,
115
- code: ErrorCode.UNKNOWN_BUNDLE_ID,
116
- });
117
- }
118
- if (result && !result.transactionHash) {
119
- // A result but no txn hash means it's valid but pending.
120
- return {
121
- ...baseResp,
122
- status: CallStatusCode.PENDING,
123
- };
124
- }
125
-
126
- const receipt = await client.getUserOperationReceipt(hash);
127
- if (result?.transactionHash && !receipt) {
128
- // This should never happen.
129
- throw new InternalError({
130
- message: `Failed to get receipt for callId ${callId}`,
131
- });
132
- }
133
- if (!receipt) {
134
- // This covers txns older than 150 blocks which were not retrievable by "eth_getUserOperationByHash".
135
- throw new BaseError({
136
- message: `callId ${callId} not found`,
137
- code: ErrorCode.UNKNOWN_BUNDLE_ID,
138
- });
139
- }
140
-
141
- return {
142
- ...baseResp,
143
- status: receipt.success
144
- ? CallStatusCode.CONFIRMED
145
- : CallStatusCode.CHAIN_RULES_FAILURE,
146
- receipts: [transformReceipt(receipt.receipt)],
147
- };
148
- }
149
-
150
- function transformReceipt(
151
- receipt: TransactionReceipt,
152
- ): NonNullable<GetCallsStatusResponse["receipts"]>[number] {
153
- return {
154
- // viem's type for status is "success" | "reverted", but the actual value seems to already be 0x0 or 0x1
155
- status: isHex(receipt.status)
156
- ? receipt.status
157
- : ReceiptStatus[receipt.status],
158
- blockHash: receipt.blockHash,
159
- // viem's type for blockNumber is bigint, but the actual value seems to already be a hex string
160
- blockNumber: castToHex(receipt.blockNumber),
161
- // viem's type for gasUsed is bigint, but the actual value seems to already be a hex string
162
- gasUsed: castToHex(receipt.gasUsed),
163
- transactionHash: receipt.transactionHash,
164
- logs: receipt.logs.map((log) => ({
165
- address: log.address,
166
- data: log.data,
167
- topics: log.topics,
168
- })),
169
- };
170
- }
@@ -1,170 +0,0 @@
1
- import {
2
- deepHexlify,
3
- default7702GasEstimator,
4
- type SmartAccountClient,
5
- type SmartContractAccount,
6
- } from "@aa-sdk/core";
7
- import type { Static } from "@sinclair/typebox";
8
- import {
9
- ChainNotFoundError,
10
- custom,
11
- fromHex,
12
- hashMessage,
13
- toHex,
14
- type Chain,
15
- type Transport,
16
- } from "viem";
17
- import type { wallet_prepareCalls } from "../../rpc/request.js";
18
- import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
19
- import { createAccount } from "../utils/createAccount.js";
20
- import { createDummySigner } from "../utils/createDummySigner.js";
21
- import { createAuthorizationRequest, isDelegated } from "../utils/7702.js";
22
- import { InvalidRequestError } from "ox/RpcResponse";
23
- import { assertNever } from "../../utils.js";
24
- import { assertValid7702AccountAddress } from "../utils/7702.js";
25
-
26
- export type PrepareCallsParams = Omit<
27
- Static<
28
- (typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]
29
- >[0],
30
- "chainId"
31
- >;
32
-
33
- export type PrepareCallsResult = Static<
34
- (typeof wallet_prepareCalls)["properties"]["ReturnType"]
35
- >;
36
-
37
- export async function prepareCalls(
38
- client: SmartAccountClient<
39
- Transport,
40
- Chain,
41
- SmartContractAccount | undefined,
42
- Record<string, unknown>,
43
- WalletServerViemRpcSchema
44
- >,
45
- params: PrepareCallsParams,
46
- ): Promise<PrepareCallsResult> {
47
- if (!client.chain) {
48
- throw new ChainNotFoundError();
49
- }
50
-
51
- assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
52
-
53
- // in local mode, we probably want some kind of caching for this
54
- const { counterfactualInfo, delegation } = await client.request({
55
- method: "wallet_requestAccount",
56
- params: [
57
- params.capabilities?.eip7702Auth
58
- ? {
59
- signerAddress: params.from,
60
- creationHint: {
61
- accountType: "7702",
62
- },
63
- includeCounterfactualInfo: true,
64
- }
65
- : {
66
- accountAddress: params.from,
67
- includeCounterfactualInfo: true,
68
- },
69
- ],
70
- });
71
-
72
- if (!counterfactualInfo && !delegation) {
73
- throw new InvalidRequestError({
74
- message:
75
- "No counterfactual info or delegated implementation address found.",
76
- });
77
- }
78
-
79
- const account = await createAccount({
80
- chain: client.chain,
81
- transport: custom(client.transport),
82
- signer: createDummySigner(params.from),
83
- accountAddress: params.from,
84
- counterfactualInfo,
85
- permissions: params.capabilities?.permissions,
86
- delegation,
87
- });
88
-
89
- const authorizationRequest =
90
- delegation &&
91
- !(await isDelegated(client, {
92
- address: account.address,
93
- delegation,
94
- }))
95
- ? await createAuthorizationRequest(client, {
96
- address: account.address,
97
- delegation,
98
- })
99
- : undefined;
100
-
101
- if (params.capabilities?.permissions && authorizationRequest) {
102
- // The user shouldn't see this in most cases since we require
103
- // the account to be delegated before creating the session.
104
- throw new InvalidRequestError({
105
- message:
106
- "When using a 7702 account with a session key, the account must be delegated before preparing calls.",
107
- });
108
- }
109
-
110
- if (authorizationRequest) {
111
- // @ts-expect-error - this is available but not typed as public
112
- client.middleware.gasEstimator = default7702GasEstimator();
113
- }
114
-
115
- // TODO: oops we don't actually support setting the policyId as an override here
116
- // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
117
- const builtUo = await client.buildUserOperation({
118
- uo: params.calls.map((x) => ({
119
- target: x.to,
120
- data: x.data ?? "0x",
121
- value: x.value ? fromHex(x.value, "bigint") : undefined,
122
- })),
123
- account,
124
- overrides: {
125
- ...params.capabilities?.gasParamsOverride,
126
- nonceKey: params.capabilities?.nonceOverride?.nonceKey
127
- ? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
128
- : undefined,
129
- },
130
- });
131
-
132
- // The eip7702Auth field should never be included in the UO sig
133
- // request. It's handled by a separate authorization request.
134
- if ("eip7702Auth" in builtUo) {
135
- builtUo.eip7702Auth = undefined;
136
- }
137
-
138
- const hexlifiedUo = deepHexlify(builtUo);
139
-
140
- const ep = account.getEntryPoint();
141
-
142
- const uoHash = ep.getUserOperationHash(hexlifiedUo);
143
-
144
- const uoRequest = {
145
- type:
146
- ep.version === "0.7.0"
147
- ? ("user-operation-v070" as const)
148
- : ep.version === "0.6.0"
149
- ? ("user-operation-v060" as const)
150
- : assertNever(ep.version, "Unexpected entry point version"),
151
- data: hexlifiedUo,
152
- chainId: toHex(client.chain.id),
153
- signatureRequest: {
154
- type: "personal_sign" as const,
155
- data: {
156
- raw: uoHash,
157
- },
158
- rawPayload: hashMessage({
159
- raw: uoHash,
160
- }),
161
- },
162
- };
163
-
164
- return authorizationRequest
165
- ? {
166
- type: "array" as const,
167
- data: [authorizationRequest, uoRequest],
168
- }
169
- : uoRequest;
170
- }
@@ -1,232 +0,0 @@
1
- import {
2
- getEntryPoint,
3
- type SmartAccountClient,
4
- type SmartContractAccount,
5
- } from "@aa-sdk/core";
6
- import { Value } from "@sinclair/typebox/value";
7
- import {
8
- BaseError,
9
- ChainNotFoundError,
10
- concat,
11
- concatHex,
12
- numberToHex,
13
- parseSignature,
14
- toHex,
15
- type Address,
16
- type Chain,
17
- type Hex,
18
- type Transport,
19
- } from "viem";
20
- import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
21
- import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
22
- import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
23
- import { TypeCallId } from "../../schemas.js";
24
- import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
25
- import { InvalidRequestError } from "ox/RpcResponse";
26
- import { assertNever } from "../../utils.js";
27
- import type { Static } from "@sinclair/typebox";
28
- import { decodeSignature } from "../utils/decodeSignature.js";
29
-
30
- export type SendPreparedCallsParams = Static<
31
- (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
32
- >[0];
33
-
34
- export type SendPreparedCallsResult = Static<
35
- (typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
36
- >;
37
-
38
- // TODO: this only supports MAv2 right now, we need to fix this
39
- export async function sendPreparedCalls(
40
- client: SmartAccountClient<
41
- Transport,
42
- Chain,
43
- SmartContractAccount | undefined,
44
- Record<string, unknown>,
45
- WalletServerViemRpcSchema
46
- >,
47
- params: SendPreparedCallsParams,
48
- ): Promise<SendPreparedCallsResult> {
49
- if (!client.chain) {
50
- throw new ChainNotFoundError();
51
- }
52
-
53
- const deferredAction: Hex | undefined = (() => {
54
- if (!params.capabilities?.permissions) {
55
- return;
56
- }
57
-
58
- const decodedContext = decodePermissionsContext(
59
- params.capabilities.permissions,
60
- );
61
-
62
- if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
63
- throw new InvalidRequestError({
64
- message:
65
- "Remote mode deferred action not supported in isomorphic client",
66
- });
67
- }
68
-
69
- return decodedContext.deferredAction;
70
- })();
71
-
72
- const userOps =
73
- params.type === "array"
74
- ? params.data.filter((it) => {
75
- const isUserOp =
76
- it.type === "user-operation-v060" ||
77
- it.type === "user-operation-v070";
78
- if (isUserOp && it.chainId !== toHex(client.chain.id)) {
79
- throw new InvalidRequestError({
80
- message:
81
- "Multiple chain IDs in a single request are not currently supported.",
82
- });
83
- }
84
- return isUserOp;
85
- })
86
- : [params];
87
-
88
- if (!userOps.length) {
89
- throw new InvalidRequestError({
90
- message: "Calls must include at least one user operation",
91
- });
92
- }
93
-
94
- const authorizations =
95
- params.type === "array"
96
- ? params.data.filter((it) => it.type === "authorization")
97
- : [];
98
-
99
- if (authorizations.length > 1) {
100
- throw new InvalidRequestError({
101
- message:
102
- "Multiple authorizations in a single request are not currently supported",
103
- });
104
- }
105
- const [authorization] = authorizations;
106
-
107
- // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
108
- if (
109
- authorization &&
110
- !isSupportedDelegationAddress7702(authorization.data.address)
111
- ) {
112
- throw new InvalidRequestError({
113
- message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
114
- });
115
- }
116
-
117
- const hashes = await Promise.all(
118
- userOps.map(async (userOp, idx) => {
119
- const ep: { address: Address } =
120
- userOp.type === "user-operation-v060"
121
- ? getEntryPoint(client.chain, { version: "0.6.0" })
122
- : userOp.type === "user-operation-v070"
123
- ? getEntryPoint(client.chain, { version: "0.7.0" })
124
- : assertNever(userOp, "Unexpected user op type");
125
- const authSig = authorization
126
- ? parseSignature(decodeSignature(authorization.signature).data)
127
- : undefined;
128
- const uoSigHex = decodeSignature(userOp.signature).data;
129
-
130
- const { counterfactualInfo, delegation } = await client.request({
131
- method: "wallet_requestAccount",
132
- params: [
133
- {
134
- accountAddress: userOp.data.sender,
135
- includeCounterfactualInfo: true,
136
- },
137
- ],
138
- });
139
-
140
- if (!counterfactualInfo && !delegation) {
141
- throw new InvalidRequestError({
142
- message:
143
- "No counterfactual info or delegated implementation address found.",
144
- });
145
- }
146
-
147
- const factoryType = counterfactualInfo?.factoryType;
148
-
149
- // build signature based on account type
150
- const signature = (() => {
151
- switch (factoryType) {
152
- // light accounts
153
- case "LightAccountV1.0.1":
154
- case "LightAccountV1.0.2":
155
- case "LightAccountV1.1.0":
156
- case "MAv1.0.0-MultiOwner":
157
- // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
158
- return uoSigHex;
159
- case "LightAccountV2.0.0":
160
- // for LAv2, we need to prepend the "SignatureType.EOA" byte.
161
- // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
162
- return concat(["0x00", uoSigHex]);
163
- case undefined: // undefined defaults to sma-b
164
- case "MAv2.0.0-sma-b":
165
- // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
166
- // Signature Segment" and "SignatureType.EOA" bytes
167
- return deferredAction != null
168
- ? concatHex([
169
- `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
170
- "0xFF",
171
- "0x00",
172
- uoSigHex,
173
- ])
174
- : concat(["0xFF", "0x00", uoSigHex]);
175
- case "LightAccountV2.0.0-MultiOwner":
176
- // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
177
- // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
178
- return concat(["0x00", uoSigHex]);
179
- case "MAv2.0.0-ma-ssv":
180
- case "MAv2.0.0-ma-webauthn":
181
- case "MAv1.0.0-MultiSig":
182
- case "unknown":
183
- throw new InvalidRequestError({
184
- message: `Unsupported factory type: ${factoryType}`,
185
- });
186
- default:
187
- return assertNever(factoryType, "Unsupported factory type");
188
- }
189
- })();
190
-
191
- return client
192
- .sendRawUserOperation(
193
- {
194
- ...userOp.data,
195
- signature,
196
- eip7702Auth:
197
- idx === 0 && authorization && authSig
198
- ? {
199
- ...authorization.data,
200
- chainId: authorization.chainId,
201
- ...{
202
- ...authSig,
203
- yParity: numberToHex(authSig.yParity),
204
- },
205
- }
206
- : undefined,
207
- },
208
- ep.address,
209
- )
210
- .catch((err) => {
211
- if (
212
- err instanceof BaseError &&
213
- err.details.endsWith("is not a contract and initCode is empty")
214
- ) {
215
- throw new BaseError(
216
- `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
217
- );
218
- }
219
- throw err;
220
- });
221
- }),
222
- );
223
-
224
- return {
225
- preparedCallIds: hashes.map((hash) =>
226
- Value.Encode(TypeCallId, {
227
- chainId: toHex(client.chain.id),
228
- hash,
229
- }),
230
- ),
231
- };
232
- }
@@ -1,94 +0,0 @@
1
- import {
2
- createSmartAccountClient,
3
- type SmartAccountClient,
4
- type SmartAccountClientRpcSchema,
5
- type SmartContractAccount,
6
- } from "@aa-sdk/core";
7
- import {
8
- alchemyFeeEstimator,
9
- alchemyGasAndPaymasterAndDataMiddleware,
10
- alchemyGasManagerMiddleware,
11
- type AlchemyTransport,
12
- } from "@account-kit/infra";
13
- import { type Chain, type Transport } from "viem";
14
- import type { WalletServerViemRpcSchema } from "../rpc/schema.js";
15
- import {
16
- createSession,
17
- type CreateSessionParams,
18
- } from "./actions/createSession.js";
19
- import {
20
- getCallsStatus,
21
- type GetCallsStatusParams,
22
- } from "./actions/getCallsStatus.js";
23
- import {
24
- prepareCalls,
25
- type PrepareCallsParams,
26
- } from "./actions/prepareCalls.js";
27
- import {
28
- sendPreparedCalls,
29
- type SendPreparedCallsParams,
30
- } from "./actions/sendPreparedCalls.js";
31
-
32
- // let's start with something that takes in as many params as possible, then we can eliminate them as we don't need them
33
- type ClientParams = {
34
- chain: Chain;
35
- transport: Transport;
36
- policyId?: string;
37
- useErc7677middleware?: boolean;
38
- };
39
-
40
- export function isomorphicClientActions(
41
- client: SmartAccountClient<
42
- Transport,
43
- Chain,
44
- SmartContractAccount | undefined,
45
- Record<string, unknown>,
46
- WalletServerViemRpcSchema
47
- >,
48
- ) {
49
- return {
50
- prepareCalls: (params: PrepareCallsParams) => prepareCalls(client, params),
51
- sendPreparedCalls: (params: SendPreparedCallsParams) =>
52
- sendPreparedCalls(client, params),
53
- getCallsStatus: (params: GetCallsStatusParams) =>
54
- getCallsStatus(client, params),
55
- createSession: (params: CreateSessionParams) =>
56
- createSession(client, params),
57
- };
58
- }
59
-
60
- // the isomorphic client likely won't be exposed directly. This client contains the business logic that can be run on the wallet server or on the client
61
- // if the dev chooses to run the client in "local" mode.
62
- export function createIsomorphicClient({
63
- chain,
64
- transport,
65
- policyId,
66
- useErc7677middleware = true,
67
- }: ClientParams): SmartAccountClient<
68
- Transport,
69
- Chain,
70
- SmartContractAccount | undefined,
71
- ReturnType<typeof isomorphicClientActions>,
72
- WalletServerViemRpcSchema & SmartAccountClientRpcSchema
73
- > {
74
- // This must be a smart account client since as of now we use it to build UOs under the hood
75
- const client = createSmartAccountClient({
76
- transport,
77
- chain,
78
- // TODO: we will want to enforce alchemy transport here probably
79
- feeEstimator: alchemyFeeEstimator(transport as AlchemyTransport),
80
- ...(policyId
81
- ? useErc7677middleware
82
- ? alchemyGasManagerMiddleware(policyId)
83
- : // NOTE: DO NOT USE THIS MIDDLEWARE in the server, currently we require using the erc7677 middleware
84
- alchemyGasAndPaymasterAndDataMiddleware({
85
- policyId,
86
- transport: transport as AlchemyTransport,
87
- })
88
- : {}),
89
- }).extend(isomorphicClientActions);
90
-
91
- return client;
92
- }
93
-
94
- export type IsomorphicClient = ReturnType<typeof createIsomorphicClient>;