@account-kit/wallet-client 0.1.0-alpha.8 → 4.50.0

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 (269) 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 +28 -39
  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} +33 -35
  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 +14 -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 +14 -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 +33 -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 +40 -45
  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/{isomorphic/utils/createAccount.ts → internal/account.ts} +37 -54
  113. package/src/types.ts +7 -18
  114. package/src/utils.ts +15 -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 -38
  120. package/dist/esm/capabilities/index.js +0 -12
  121. package/dist/esm/capabilities/index.js.map +0 -1
  122. package/dist/esm/capabilities/overrides.d.ts +0 -26
  123. package/dist/esm/capabilities/overrides.js +0 -14
  124. package/dist/esm/capabilities/overrides.js.map +0 -1
  125. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  126. package/dist/esm/capabilities/paymaster.js +0 -5
  127. package/dist/esm/capabilities/paymaster.js.map +0 -1
  128. package/dist/esm/capabilities/permissions/index.d.ts +0 -145
  129. package/dist/esm/capabilities/permissions/index.js +0 -83
  130. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  131. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  132. package/dist/esm/capabilities/permissions/mav2.js +0 -88
  133. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  134. package/dist/esm/client/actions/createAccount.d.ts +0 -35
  135. package/dist/esm/client/actions/createAccount.js +0 -32
  136. package/dist/esm/client/actions/createAccount.js.map +0 -1
  137. package/dist/esm/client/client.e2e-test.d.ts +0 -1
  138. package/dist/esm/client/client.e2e-test.js +0 -375
  139. package/dist/esm/client/client.e2e-test.js.map +0 -1
  140. package/dist/esm/exports/internal.d.ts +0 -13
  141. package/dist/esm/exports/internal.js +0 -15
  142. package/dist/esm/exports/internal.js.map +0 -1
  143. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
  144. package/dist/esm/isomorphic/actions/createSession.js +0 -89
  145. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  146. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
  147. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
  148. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  149. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
  150. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -101
  151. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  152. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  153. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -148
  154. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  155. package/dist/esm/isomorphic/client.d.ts +0 -239
  156. package/dist/esm/isomorphic/client.js +0 -37
  157. package/dist/esm/isomorphic/client.js.map +0 -1
  158. package/dist/esm/isomorphic/utils/7702.d.ts +0 -18
  159. package/dist/esm/isomorphic/utils/7702.js +0 -74
  160. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  161. package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -23
  162. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  163. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  164. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  165. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  166. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  167. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
  168. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  169. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  170. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  171. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  172. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  173. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  174. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  175. package/dist/esm/local/client.d.ts +0 -3
  176. package/dist/esm/local/client.js +0 -97
  177. package/dist/esm/local/client.js.map +0 -1
  178. package/dist/esm/remote/client.d.ts +0 -9
  179. package/dist/esm/remote/client.js +0 -41
  180. package/dist/esm/remote/client.js.map +0 -1
  181. package/dist/esm/rpc/examples.d.ts +0 -230
  182. package/dist/esm/rpc/examples.js +0 -314
  183. package/dist/esm/rpc/examples.js.map +0 -1
  184. package/dist/esm/rpc/request.d.ts +0 -711
  185. package/dist/esm/rpc/request.js +0 -213
  186. package/dist/esm/rpc/request.js.map +0 -1
  187. package/dist/esm/rpc/schema.d.ts +0 -659
  188. package/dist/esm/rpc/schema.js +0 -5
  189. package/dist/esm/rpc/schema.js.map +0 -1
  190. package/dist/esm/schemas.d.ts +0 -693
  191. package/dist/esm/schemas.js +0 -419
  192. package/dist/esm/schemas.js.map +0 -1
  193. package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
  194. package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
  195. package/dist/types/capabilities/index.d.ts +0 -39
  196. package/dist/types/capabilities/index.d.ts.map +0 -1
  197. package/dist/types/capabilities/overrides.d.ts +0 -27
  198. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  199. package/dist/types/capabilities/paymaster.d.ts +0 -4
  200. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  201. package/dist/types/capabilities/permissions/index.d.ts +0 -146
  202. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  203. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  204. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  205. package/dist/types/client/actions/createAccount.d.ts +0 -36
  206. package/dist/types/client/actions/createAccount.d.ts.map +0 -1
  207. package/dist/types/client/client.e2e-test.d.ts +0 -2
  208. package/dist/types/client/client.e2e-test.d.ts.map +0 -1
  209. package/dist/types/exports/internal.d.ts +0 -14
  210. package/dist/types/exports/internal.d.ts.map +0 -1
  211. package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
  212. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  213. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
  214. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  215. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
  216. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  217. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
  218. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  219. package/dist/types/isomorphic/client.d.ts +0 -240
  220. package/dist/types/isomorphic/client.d.ts.map +0 -1
  221. package/dist/types/isomorphic/utils/7702.d.ts +0 -19
  222. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  223. package/dist/types/isomorphic/utils/createAccount.d.ts +0 -24
  224. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  225. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  226. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  227. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  228. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  229. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  230. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  231. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  232. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  233. package/dist/types/local/client.d.ts +0 -4
  234. package/dist/types/local/client.d.ts.map +0 -1
  235. package/dist/types/remote/client.d.ts +0 -10
  236. package/dist/types/remote/client.d.ts.map +0 -1
  237. package/dist/types/rpc/examples.d.ts +0 -231
  238. package/dist/types/rpc/examples.d.ts.map +0 -1
  239. package/dist/types/rpc/request.d.ts +0 -712
  240. package/dist/types/rpc/request.d.ts.map +0 -1
  241. package/dist/types/rpc/schema.d.ts +0 -660
  242. package/dist/types/rpc/schema.d.ts.map +0 -1
  243. package/dist/types/schemas.d.ts +0 -694
  244. package/dist/types/schemas.d.ts.map +0 -1
  245. package/src/capabilities/eip7702Auth.ts +0 -26
  246. package/src/capabilities/index.ts +0 -12
  247. package/src/capabilities/overrides.ts +0 -35
  248. package/src/capabilities/paymaster.ts +0 -5
  249. package/src/capabilities/permissions/index.ts +0 -163
  250. package/src/capabilities/permissions/mav2.ts +0 -138
  251. package/src/client/actions/createAccount.ts +0 -53
  252. package/src/client/client.e2e-test.ts +0 -463
  253. package/src/exports/internal.ts +0 -16
  254. package/src/isomorphic/actions/createSession.ts +0 -151
  255. package/src/isomorphic/actions/getCallsStatus.ts +0 -170
  256. package/src/isomorphic/actions/prepareCalls.ts +0 -152
  257. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -222
  258. package/src/isomorphic/client.ts +0 -94
  259. package/src/isomorphic/utils/7702.ts +0 -132
  260. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  261. package/src/isomorphic/utils/decodeSignature.ts +0 -18
  262. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
  263. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  264. package/src/local/client.ts +0 -136
  265. package/src/remote/client.ts +0 -67
  266. package/src/rpc/examples.ts +0 -342
  267. package/src/rpc/request.ts +0 -299
  268. package/src/rpc/schema.ts +0 -40
  269. package/src/schemas.ts +0 -585
@@ -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,152 +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 } 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
- // If using 7702, we need an Authorization (unless it's already authorized).
90
- const authorizationRequest = delegation
91
- ? await createAuthorizationRequest(client, {
92
- address: account.address,
93
- delegation,
94
- })
95
- : undefined;
96
-
97
- if (authorizationRequest) {
98
- // @ts-expect-error - this is available but not typed as public
99
- client.middleware.gasEstimator = default7702GasEstimator();
100
- }
101
-
102
- // TODO: oops we don't actually support setting the policyId as an override here
103
- // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
104
- const builtUo = await client.buildUserOperation({
105
- uo: params.calls.map((x) => ({
106
- target: x.to,
107
- data: x.data ?? "0x",
108
- value: x.value ? fromHex(x.value, "bigint") : undefined,
109
- })),
110
- account,
111
- overrides: params.capabilities?.gasParamsOverride,
112
- });
113
-
114
- // The eip7702Auth field should never be included in the UO sig
115
- // request. It's handled by a separate authorization request.
116
- if ("eip7702Auth" in builtUo) {
117
- builtUo.eip7702Auth = undefined;
118
- }
119
-
120
- const hexlifiedUo = deepHexlify(builtUo);
121
-
122
- const ep = account.getEntryPoint();
123
-
124
- const uoHash = ep.getUserOperationHash(hexlifiedUo);
125
-
126
- const uoRequest = {
127
- type:
128
- ep.version === "0.7.0"
129
- ? ("user-operation-v070" as const)
130
- : ep.version === "0.6.0"
131
- ? ("user-operation-v060" as const)
132
- : assertNever(ep.version, "Unexpected entry point version"),
133
- data: hexlifiedUo,
134
- chainId: toHex(client.chain.id),
135
- signatureRequest: {
136
- type: "personal_sign" as const,
137
- data: {
138
- raw: uoHash,
139
- },
140
- rawPayload: hashMessage({
141
- raw: uoHash,
142
- }),
143
- },
144
- };
145
-
146
- return authorizationRequest
147
- ? {
148
- type: "array" as const,
149
- data: [authorizationRequest, uoRequest],
150
- }
151
- : uoRequest;
152
- }
@@ -1,222 +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
- const authorizations =
89
- params.type === "array"
90
- ? params.data.filter((it) => it.type === "authorization")
91
- : [];
92
-
93
- if (authorizations.length > 1) {
94
- throw new InvalidRequestError({
95
- message:
96
- "Multiple authorizations in a single request are not currently supported",
97
- });
98
- }
99
- const [authorization] = authorizations;
100
-
101
- // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
102
- if (
103
- authorization &&
104
- !isSupportedDelegationAddress7702(authorization.data.address)
105
- ) {
106
- throw new InvalidRequestError({
107
- message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
108
- });
109
- }
110
-
111
- const hashes = await Promise.all(
112
- userOps.map(async (userOp, idx) => {
113
- const ep: { address: Address } =
114
- userOp.type === "user-operation-v060"
115
- ? getEntryPoint(client.chain, { version: "0.6.0" })
116
- : userOp.type === "user-operation-v070"
117
- ? getEntryPoint(client.chain, { version: "0.7.0" })
118
- : assertNever(userOp, "Unexpected user op type");
119
- const authSig = authorization
120
- ? parseSignature(decodeSignature(authorization.signature).data)
121
- : undefined;
122
- const uoSigHex = decodeSignature(userOp.signature).data;
123
-
124
- const { counterfactualInfo, delegation } = await client.request({
125
- method: "wallet_requestAccount",
126
- params: [
127
- {
128
- accountAddress: userOp.data.sender,
129
- includeCounterfactualInfo: true,
130
- },
131
- ],
132
- });
133
-
134
- if (!counterfactualInfo && !delegation) {
135
- throw new InvalidRequestError({
136
- message:
137
- "No counterfactual info or delegated implementation address found.",
138
- });
139
- }
140
-
141
- const factoryType = counterfactualInfo?.factoryType;
142
-
143
- // build signature based on account type
144
- const signature = (() => {
145
- switch (factoryType) {
146
- // light accounts
147
- case "LightAccountV1.0.1":
148
- case "LightAccountV1.0.2":
149
- case "LightAccountV1.1.0":
150
- // For LAv1, we always just pass the signature.
151
- return uoSigHex;
152
- case "LightAccountV2.0.0":
153
- // for LAv2, we need to prepend the "SignatureType.EOA" byte
154
- return concat(["0x00", uoSigHex]);
155
- case undefined: // undefined defaults to sma-b
156
- case "MAv2.0.0-sma-b":
157
- // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
158
- // Signature Segment" and "SignatureType.EOA" bytes
159
- return deferredAction != null
160
- ? concatHex([
161
- `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
162
- "0xFF",
163
- "0x00",
164
- uoSigHex,
165
- ])
166
- : concat(["0xFF", "0x00", uoSigHex]);
167
- case "MAv2.0.0-ma-ssv":
168
- case "MAv2.0.0-ma-webauthn":
169
- case "LightAccountV2.0.0-MultiOwner":
170
- case "MAv1.0.0-MultiOwner":
171
- case "MAv1.0.0-MultiSig":
172
- case "unknown":
173
- throw new InvalidRequestError({
174
- message: `Unsupported factory type: ${factoryType}`,
175
- });
176
- default:
177
- return assertNever(factoryType, "Unsupported factory type");
178
- }
179
- })();
180
-
181
- return client
182
- .sendRawUserOperation(
183
- {
184
- ...userOp.data,
185
- signature,
186
- eip7702Auth:
187
- idx === 0 && authorization && authSig
188
- ? {
189
- ...authorization.data,
190
- chainId: authorization.chainId,
191
- ...{
192
- ...authSig,
193
- yParity: numberToHex(authSig.yParity),
194
- },
195
- }
196
- : undefined,
197
- },
198
- ep.address,
199
- )
200
- .catch((err) => {
201
- if (
202
- err instanceof BaseError &&
203
- err.details.endsWith("is not a contract and initCode is empty")
204
- ) {
205
- throw new BaseError(
206
- `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
207
- );
208
- }
209
- throw err;
210
- });
211
- }),
212
- );
213
-
214
- return {
215
- preparedCallIds: hashes.map((hash) =>
216
- Value.Encode(TypeCallId, {
217
- chainId: toHex(client.chain.id),
218
- hash,
219
- }),
220
- ),
221
- };
222
- }
@@ -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>;