@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (258) hide show
  1. package/dist/esm/client/actions/createAccount.d.ts +27 -2
  2. package/dist/esm/client/actions/createAccount.js +25 -0
  3. package/dist/esm/client/actions/createAccount.js.map +1 -1
  4. package/dist/esm/client/actions/formatSign.d.ts +28 -0
  5. package/dist/esm/client/actions/formatSign.js +30 -0
  6. package/dist/esm/client/actions/formatSign.js.map +1 -0
  7. package/dist/esm/client/actions/getCallsStatus.d.ts +22 -4
  8. package/dist/esm/client/actions/getCallsStatus.js +19 -0
  9. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  10. package/dist/esm/client/actions/grantPermissions.d.ts +63 -6
  11. package/dist/esm/client/actions/grantPermissions.js +63 -3
  12. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  13. package/dist/esm/client/actions/listAccounts.d.ts +32 -4
  14. package/dist/esm/client/actions/listAccounts.js +35 -2
  15. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  16. package/dist/esm/client/actions/prepareCalls.d.ts +32 -6
  17. package/dist/esm/client/actions/prepareCalls.js +39 -5
  18. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  19. package/dist/esm/client/actions/prepareSign.d.ts +25 -0
  20. package/dist/esm/client/actions/prepareSign.js +28 -0
  21. package/dist/esm/client/actions/prepareSign.js.map +1 -0
  22. package/dist/esm/client/actions/requestAccount.d.ts +24 -6
  23. package/dist/esm/client/actions/requestAccount.js +38 -7
  24. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  25. package/dist/esm/client/actions/sendPreparedCalls.d.ts +33 -4
  26. package/dist/esm/client/actions/sendPreparedCalls.js +37 -1
  27. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  28. package/dist/esm/client/actions/signMessage.d.ts +25 -5
  29. package/dist/esm/client/actions/signMessage.js +22 -2
  30. package/dist/esm/client/actions/signMessage.js.map +1 -1
  31. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  32. package/dist/esm/client/actions/signPreparedCalls.js +43 -0
  33. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  34. package/dist/esm/client/actions/signSignatureRequest.d.ts +39 -5
  35. package/dist/esm/client/actions/signSignatureRequest.js +69 -11
  36. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  37. package/dist/esm/client/actions/signTypedData.d.ts +37 -4
  38. package/dist/esm/client/actions/signTypedData.js +34 -1
  39. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  40. package/dist/esm/client/client.e2e-test.js +249 -45
  41. package/dist/esm/client/client.e2e-test.js.map +1 -1
  42. package/dist/esm/client/decorator.d.ts +12 -8
  43. package/dist/esm/client/decorator.js +5 -3
  44. package/dist/esm/client/decorator.js.map +1 -1
  45. package/dist/esm/client/index.d.ts +38 -12
  46. package/dist/esm/client/index.js +0 -3
  47. package/dist/esm/client/index.js.map +1 -1
  48. package/dist/esm/exports/index.d.ts +5 -6
  49. package/dist/esm/exports/index.js +4 -6
  50. package/dist/esm/exports/index.js.map +1 -1
  51. package/dist/esm/exports/internal.d.ts +1 -10
  52. package/dist/esm/exports/internal.js +0 -12
  53. package/dist/esm/exports/internal.js.map +1 -1
  54. package/dist/esm/internal/decorator.d.ts +2 -0
  55. package/dist/esm/internal/decorator.js +10 -0
  56. package/dist/esm/internal/decorator.js.map +1 -0
  57. package/dist/esm/isomorphic/actions/createSession.d.ts +1 -2
  58. package/dist/esm/isomorphic/actions/createSession.js +40 -11
  59. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  60. package/dist/esm/isomorphic/actions/formatSign.d.ts +8 -0
  61. package/dist/esm/isomorphic/actions/formatSign.js +42 -0
  62. package/dist/esm/isomorphic/actions/formatSign.js.map +1 -0
  63. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +1 -15
  64. package/dist/esm/isomorphic/actions/getCallsStatus.js +38 -27
  65. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
  66. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +1 -2
  67. package/dist/esm/isomorphic/actions/prepareCalls.js +78 -20
  68. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  69. package/dist/esm/isomorphic/actions/prepareSign.d.ts +7 -0
  70. package/dist/esm/isomorphic/actions/prepareSign.js +49 -0
  71. package/dist/esm/isomorphic/actions/prepareSign.js.map +1 -0
  72. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
  73. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +165 -25
  74. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  75. package/dist/esm/isomorphic/client.d.ts +204 -27
  76. package/dist/esm/isomorphic/client.js +6 -2
  77. package/dist/esm/isomorphic/client.js.map +1 -1
  78. package/dist/esm/isomorphic/utils/7702.d.ts +19 -0
  79. package/dist/esm/isomorphic/utils/7702.js +70 -0
  80. package/dist/esm/isomorphic/utils/7702.js.map +1 -0
  81. package/dist/esm/isomorphic/utils/createAccount.d.ts +5 -4
  82. package/dist/esm/isomorphic/utils/createAccount.js +84 -10
  83. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  84. package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
  85. package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
  86. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  87. package/dist/esm/isomorphic/utils/decodeSignature.js +15 -0
  88. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  89. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
  90. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +19 -6
  91. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
  92. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
  93. package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
  94. package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
  95. package/dist/esm/local/client.d.ts +3 -3
  96. package/dist/esm/local/client.js +11 -4
  97. package/dist/esm/local/client.js.map +1 -1
  98. package/dist/esm/remote/client.d.ts +9 -3
  99. package/dist/esm/remote/client.js +10 -11
  100. package/dist/esm/remote/client.js.map +1 -1
  101. package/dist/esm/types.d.ts +27 -13
  102. package/dist/esm/types.js.map +1 -1
  103. package/dist/esm/utils.d.ts +1 -0
  104. package/dist/esm/utils.js.map +1 -1
  105. package/dist/types/client/actions/createAccount.d.ts +27 -2
  106. package/dist/types/client/actions/createAccount.d.ts.map +1 -1
  107. package/dist/types/client/actions/formatSign.d.ts +29 -0
  108. package/dist/types/client/actions/formatSign.d.ts.map +1 -0
  109. package/dist/types/client/actions/getCallsStatus.d.ts +22 -4
  110. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  111. package/dist/types/client/actions/grantPermissions.d.ts +63 -6
  112. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  113. package/dist/types/client/actions/listAccounts.d.ts +32 -4
  114. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  115. package/dist/types/client/actions/prepareCalls.d.ts +32 -6
  116. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  117. package/dist/types/client/actions/prepareSign.d.ts +26 -0
  118. package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
  119. package/dist/types/client/actions/requestAccount.d.ts +24 -6
  120. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  121. package/dist/types/client/actions/sendPreparedCalls.d.ts +33 -4
  122. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  123. package/dist/types/client/actions/signMessage.d.ts +25 -5
  124. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  125. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  126. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  127. package/dist/types/client/actions/signSignatureRequest.d.ts +39 -5
  128. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  129. package/dist/types/client/actions/signTypedData.d.ts +37 -4
  130. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  131. package/dist/types/client/decorator.d.ts +12 -8
  132. package/dist/types/client/decorator.d.ts.map +1 -1
  133. package/dist/types/client/index.d.ts +38 -12
  134. package/dist/types/client/index.d.ts.map +1 -1
  135. package/dist/types/exports/index.d.ts +5 -6
  136. package/dist/types/exports/index.d.ts.map +1 -1
  137. package/dist/types/exports/internal.d.ts +1 -10
  138. package/dist/types/exports/internal.d.ts.map +1 -1
  139. package/dist/types/internal/decorator.d.ts +3 -0
  140. package/dist/types/internal/decorator.d.ts.map +1 -0
  141. package/dist/types/isomorphic/actions/createSession.d.ts +1 -2
  142. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  143. package/dist/types/isomorphic/actions/formatSign.d.ts +9 -0
  144. package/dist/types/isomorphic/actions/formatSign.d.ts.map +1 -0
  145. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +1 -15
  146. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
  147. package/dist/types/isomorphic/actions/prepareCalls.d.ts +1 -2
  148. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  149. package/dist/types/isomorphic/actions/prepareSign.d.ts +8 -0
  150. package/dist/types/isomorphic/actions/prepareSign.d.ts.map +1 -0
  151. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
  152. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  153. package/dist/types/isomorphic/client.d.ts +204 -27
  154. package/dist/types/isomorphic/client.d.ts.map +1 -1
  155. package/dist/types/isomorphic/utils/7702.d.ts +20 -0
  156. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
  157. package/dist/types/isomorphic/utils/createAccount.d.ts +5 -4
  158. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  159. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
  160. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  161. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  162. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
  163. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
  164. package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
  165. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
  166. package/dist/types/local/client.d.ts +3 -3
  167. package/dist/types/local/client.d.ts.map +1 -1
  168. package/dist/types/remote/client.d.ts +9 -3
  169. package/dist/types/remote/client.d.ts.map +1 -1
  170. package/dist/types/types.d.ts +27 -13
  171. package/dist/types/types.d.ts.map +1 -1
  172. package/dist/types/utils.d.ts +1 -0
  173. package/dist/types/utils.d.ts.map +1 -1
  174. package/package.json +9 -6
  175. package/src/client/actions/createAccount.ts +27 -2
  176. package/src/client/actions/formatSign.ts +53 -0
  177. package/src/client/actions/getCallsStatus.ts +21 -12
  178. package/src/client/actions/grantPermissions.ts +69 -26
  179. package/src/client/actions/listAccounts.ts +44 -6
  180. package/src/client/actions/prepareCalls.ts +46 -26
  181. package/src/client/actions/prepareSign.ts +46 -0
  182. package/src/client/actions/requestAccount.ts +60 -41
  183. package/src/client/actions/sendPreparedCalls.ts +44 -7
  184. package/src/client/actions/signMessage.ts +26 -21
  185. package/src/client/actions/signPreparedCalls.ts +67 -0
  186. package/src/client/actions/signSignatureRequest.ts +84 -20
  187. package/src/client/actions/signTypedData.ts +40 -19
  188. package/src/client/client.e2e-test.ts +408 -127
  189. package/src/client/decorator.ts +28 -26
  190. package/src/client/index.ts +50 -40
  191. package/src/exports/index.ts +5 -13
  192. package/src/exports/internal.ts +2 -10
  193. package/src/internal/decorator.ts +12 -0
  194. package/src/isomorphic/actions/createSession.ts +56 -13
  195. package/src/isomorphic/actions/formatSign.ts +76 -0
  196. package/src/isomorphic/actions/getCallsStatus.ts +47 -33
  197. package/src/isomorphic/actions/prepareCalls.ts +95 -23
  198. package/src/isomorphic/actions/prepareSign.ts +88 -0
  199. package/src/isomorphic/actions/sendPreparedCalls.ts +218 -42
  200. package/src/isomorphic/client.ts +10 -2
  201. package/src/isomorphic/utils/7702.ts +135 -0
  202. package/src/isomorphic/utils/createAccount.ts +101 -13
  203. package/src/isomorphic/utils/createDummySigner.ts +3 -2
  204. package/src/isomorphic/utils/decodeSignature.ts +21 -0
  205. package/src/isomorphic/utils/parsePermissionsContext.ts +29 -11
  206. package/src/isomorphic/utils/supportsFeature.ts +34 -0
  207. package/src/local/client.ts +58 -55
  208. package/src/remote/client.ts +19 -19
  209. package/src/types.ts +29 -23
  210. package/src/utils.ts +2 -0
  211. package/dist/esm/capabilities/index.d.ts +0 -31
  212. package/dist/esm/capabilities/index.js +0 -10
  213. package/dist/esm/capabilities/index.js.map +0 -1
  214. package/dist/esm/capabilities/overrides.d.ts +0 -26
  215. package/dist/esm/capabilities/overrides.js +0 -14
  216. package/dist/esm/capabilities/overrides.js.map +0 -1
  217. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  218. package/dist/esm/capabilities/paymaster.js +0 -5
  219. package/dist/esm/capabilities/paymaster.js.map +0 -1
  220. package/dist/esm/capabilities/permissions/index.d.ts +0 -138
  221. package/dist/esm/capabilities/permissions/index.js +0 -71
  222. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  223. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  224. package/dist/esm/capabilities/permissions/mav2.js +0 -79
  225. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  226. package/dist/esm/rpc/request.d.ts +0 -352
  227. package/dist/esm/rpc/request.js +0 -204
  228. package/dist/esm/rpc/request.js.map +0 -1
  229. package/dist/esm/rpc/schema.d.ts +0 -342
  230. package/dist/esm/rpc/schema.js +0 -5
  231. package/dist/esm/rpc/schema.js.map +0 -1
  232. package/dist/esm/schemas.d.ts +0 -216
  233. package/dist/esm/schemas.js +0 -211
  234. package/dist/esm/schemas.js.map +0 -1
  235. package/dist/types/capabilities/index.d.ts +0 -32
  236. package/dist/types/capabilities/index.d.ts.map +0 -1
  237. package/dist/types/capabilities/overrides.d.ts +0 -27
  238. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  239. package/dist/types/capabilities/paymaster.d.ts +0 -4
  240. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  241. package/dist/types/capabilities/permissions/index.d.ts +0 -139
  242. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  243. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  244. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  245. package/dist/types/rpc/request.d.ts +0 -353
  246. package/dist/types/rpc/request.d.ts.map +0 -1
  247. package/dist/types/rpc/schema.d.ts +0 -343
  248. package/dist/types/rpc/schema.d.ts.map +0 -1
  249. package/dist/types/schemas.d.ts +0 -217
  250. package/dist/types/schemas.d.ts.map +0 -1
  251. package/src/capabilities/index.ts +0 -13
  252. package/src/capabilities/overrides.ts +0 -20
  253. package/src/capabilities/paymaster.ts +0 -5
  254. package/src/capabilities/permissions/index.ts +0 -142
  255. package/src/capabilities/permissions/mav2.ts +0 -127
  256. package/src/rpc/request.ts +0 -273
  257. package/src/rpc/schema.ts +0 -40
  258. package/src/schemas.ts +0 -257
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  deepHexlify,
3
+ default7702GasEstimator,
3
4
  type SmartAccountClient,
4
5
  type SmartContractAccount,
5
6
  } from "@aa-sdk/core";
@@ -8,15 +9,21 @@ import {
8
9
  ChainNotFoundError,
9
10
  custom,
10
11
  fromHex,
12
+ hashMessage,
11
13
  toHex,
12
- zeroAddress,
13
14
  type Chain,
14
15
  type Transport,
15
16
  } from "viem";
16
- import type { wallet_prepareCalls } from "../../rpc/request.js";
17
- import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
17
+ import type {
18
+ wallet_prepareCalls,
19
+ WalletServerViemRpcSchema,
20
+ } from "@alchemy/wallet-api-types/rpc";
18
21
  import { createAccount } from "../utils/createAccount.js";
19
22
  import { createDummySigner } from "../utils/createDummySigner.js";
23
+ import { createAuthorizationRequest, isDelegated } from "../utils/7702.js";
24
+ import { InvalidRequestError } from "ox/RpcResponse";
25
+ import { assertNever } from "../../utils.js";
26
+ import { assertValid7702AccountAddress } from "../utils/7702.js";
20
27
 
21
28
  export type PrepareCallsParams = Omit<
22
29
  Static<
@@ -29,7 +36,6 @@ export type PrepareCallsResult = Static<
29
36
  (typeof wallet_prepareCalls)["properties"]["ReturnType"]
30
37
  >;
31
38
 
32
- // TODO: handle capabilities like permissions and paymaster here
33
39
  export async function prepareCalls(
34
40
  client: SmartAccountClient<
35
41
  Transport,
@@ -44,29 +50,70 @@ export async function prepareCalls(
44
50
  throw new ChainNotFoundError();
45
51
  }
46
52
 
53
+ assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
54
+
47
55
  // in local mode, we probably want some kind of caching for this
48
- const { counterfactualInfo } = await client.request({
56
+ const { counterfactualInfo, delegation } = await client.request({
49
57
  method: "wallet_requestAccount",
50
58
  params: [
51
- {
52
- accountAddress: params.from,
53
- includeCounterfactualInfo: true,
54
- },
59
+ params.capabilities?.eip7702Auth
60
+ ? {
61
+ signerAddress: params.from,
62
+ creationHint: {
63
+ accountType: "7702",
64
+ },
65
+ includeCounterfactualInfo: true,
66
+ }
67
+ : {
68
+ accountAddress: params.from,
69
+ includeCounterfactualInfo: true,
70
+ },
55
71
  ],
56
72
  });
57
- if (!counterfactualInfo) {
58
- throw new Error("No counterfactual info found.");
73
+
74
+ if (!counterfactualInfo && !delegation) {
75
+ throw new InvalidRequestError({
76
+ message:
77
+ "No counterfactual info or delegated implementation address found.",
78
+ });
59
79
  }
60
80
 
61
81
  const account = await createAccount({
62
82
  chain: client.chain,
63
83
  transport: custom(client.transport),
64
- signer: createDummySigner(zeroAddress),
84
+ signer: createDummySigner(params.from),
65
85
  accountAddress: params.from,
66
86
  counterfactualInfo,
67
- capabilities: params.capabilities,
87
+ permissions: params.capabilities?.permissions,
88
+ delegation,
68
89
  });
69
90
 
91
+ const authorizationRequest =
92
+ delegation &&
93
+ !(await isDelegated(client, {
94
+ address: account.address,
95
+ delegation,
96
+ }))
97
+ ? await createAuthorizationRequest(client, {
98
+ address: account.address,
99
+ delegation,
100
+ })
101
+ : undefined;
102
+
103
+ if (params.capabilities?.permissions && authorizationRequest) {
104
+ // The user shouldn't see this in most cases since we require
105
+ // the account to be delegated before creating the session.
106
+ throw new InvalidRequestError({
107
+ message:
108
+ "When using a 7702 account with a session key, the account must be delegated before preparing calls.",
109
+ });
110
+ }
111
+
112
+ if (authorizationRequest) {
113
+ // @ts-expect-error - this is available but not typed as public
114
+ client.middleware.gasEstimator = default7702GasEstimator();
115
+ }
116
+
70
117
  // TODO: oops we don't actually support setting the policyId as an override here
71
118
  // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
72
119
  const builtUo = await client.buildUserOperation({
@@ -76,25 +123,50 @@ export async function prepareCalls(
76
123
  value: x.value ? fromHex(x.value, "bigint") : undefined,
77
124
  })),
78
125
  account,
79
- overrides: params.capabilities?.gasParamsOverride,
126
+ overrides: {
127
+ ...params.capabilities?.gasParamsOverride,
128
+ nonceKey: params.capabilities?.nonceOverride?.nonceKey
129
+ ? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
130
+ : undefined,
131
+ },
80
132
  });
81
133
 
82
- const uoRequest = deepHexlify(builtUo);
134
+ // The eip7702Auth field should never be included in the UO sig
135
+ // request. It's handled by a separate authorization request.
136
+ if ("eip7702Auth" in builtUo) {
137
+ builtUo.eip7702Auth = undefined;
138
+ }
139
+
140
+ const hexlifiedUo = deepHexlify(builtUo);
141
+
142
+ const ep = account.getEntryPoint();
83
143
 
84
- const hash = account.getEntryPoint().getUserOperationHash(uoRequest);
144
+ const uoHash = ep.getUserOperationHash(hexlifiedUo);
85
145
 
86
- return {
146
+ const uoRequest = {
87
147
  type:
88
- account.getEntryPoint().version === "0.7.0"
89
- ? "user-operation-v070"
90
- : "user-operation-v060",
91
- data: uoRequest,
148
+ ep.version === "0.7.0"
149
+ ? ("user-operation-v070" as const)
150
+ : ep.version === "0.6.0"
151
+ ? ("user-operation-v060" as const)
152
+ : assertNever(ep.version, "Unexpected entry point version"),
153
+ data: hexlifiedUo,
92
154
  chainId: toHex(client.chain.id),
93
155
  signatureRequest: {
94
- type: "personal_sign",
156
+ type: "personal_sign" as const,
95
157
  data: {
96
- raw: hash,
158
+ raw: uoHash,
97
159
  },
160
+ rawPayload: hashMessage({
161
+ raw: uoHash,
162
+ }),
98
163
  },
99
164
  };
165
+
166
+ return authorizationRequest
167
+ ? {
168
+ type: "array" as const,
169
+ data: [authorizationRequest, uoRequest],
170
+ }
171
+ : uoRequest;
100
172
  }
@@ -0,0 +1,88 @@
1
+ import type { Static } from "@sinclair/typebox";
2
+ import type {
3
+ SignatureRequest,
4
+ SmartAccountClient,
5
+ SmartContractAccount,
6
+ } from "@aa-sdk/core";
7
+ import {
8
+ ChainNotFoundError,
9
+ custom,
10
+ toHex,
11
+ type Chain,
12
+ type Transport,
13
+ } from "viem";
14
+ import type {
15
+ wallet_prepareSign,
16
+ WalletServerViemRpcSchema,
17
+ } from "@alchemy/wallet-api-types/rpc";
18
+ import { SignableMessage, jsonSafeTypedData } from "@alchemy/wallet-api-types";
19
+ import { createAccount } from "../utils/createAccount.js";
20
+ import { createDummySigner } from "../utils/createDummySigner.js";
21
+ import { Value } from "@sinclair/typebox/value";
22
+
23
+ export type PrepareSignParams = Static<
24
+ (typeof wallet_prepareSign)["properties"]["Request"]["properties"]["params"]
25
+ >[0];
26
+
27
+ export type PrepareSignResult = Static<
28
+ (typeof wallet_prepareSign)["properties"]["ReturnType"]
29
+ >;
30
+
31
+ export async function prepareSign(
32
+ client: SmartAccountClient<
33
+ Transport,
34
+ Chain,
35
+ SmartContractAccount | undefined,
36
+ Record<string, unknown>,
37
+ WalletServerViemRpcSchema
38
+ >,
39
+ params: PrepareSignParams,
40
+ ): Promise<PrepareSignResult> {
41
+ if (!client.chain) {
42
+ throw new ChainNotFoundError();
43
+ }
44
+
45
+ const { counterfactualInfo, delegation } = await client.request({
46
+ method: "wallet_requestAccount",
47
+ params: [
48
+ {
49
+ accountAddress: params.from,
50
+ includeCounterfactualInfo: true,
51
+ },
52
+ ],
53
+ });
54
+
55
+ const account = await createAccount({
56
+ chain: client.chain,
57
+ transport: custom(client.transport),
58
+ signer: createDummySigner(params.from),
59
+ accountAddress: params.from,
60
+ counterfactualInfo,
61
+ permissions: params.capabilities?.permissions,
62
+ delegation,
63
+ });
64
+
65
+ const signatureRequest = await account.prepareSign(
66
+ params.signatureRequest as SignatureRequest,
67
+ );
68
+
69
+ if (signatureRequest.type === "personal_sign") {
70
+ return {
71
+ chainId: toHex(client.chain.id),
72
+ signatureRequest: {
73
+ type: signatureRequest.type,
74
+ data: Value.Encode(SignableMessage, signatureRequest.data),
75
+ },
76
+ };
77
+ } else {
78
+ const typedData = signatureRequest.data;
79
+
80
+ return {
81
+ chainId: toHex(client.chain.id),
82
+ signatureRequest: {
83
+ type: signatureRequest.type,
84
+ data: jsonSafeTypedData(typedData),
85
+ },
86
+ };
87
+ }
88
+ }
@@ -3,28 +3,36 @@ import {
3
3
  type SmartAccountClient,
4
4
  type SmartContractAccount,
5
5
  } from "@aa-sdk/core";
6
- import type { Static, StaticDecode } from "@sinclair/typebox";
7
6
  import { Value } from "@sinclair/typebox/value";
8
7
  import {
8
+ BaseError,
9
9
  ChainNotFoundError,
10
10
  concat,
11
11
  concatHex,
12
+ getContract,
13
+ numberToHex,
14
+ parseSignature,
12
15
  toHex,
16
+ type Address,
13
17
  type Chain,
14
18
  type Hex,
15
19
  type Transport,
16
20
  } from "viem";
17
- import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
18
- import type { wallet_sendPreparedCalls } from "../../rpc/request.js";
19
- import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
20
- import { TypeCallId } from "../../schemas.js";
21
-
22
- export type SendPreparedCallsParams = Omit<
23
- StaticDecode<
24
- (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
25
- >[0],
26
- "chainId"
27
- >;
21
+ import type {
22
+ wallet_sendPreparedCalls,
23
+ WalletServerViemRpcSchema,
24
+ } from "@alchemy/wallet-api-types/rpc";
25
+ import { decodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
26
+ import { CallId } from "@alchemy/wallet-api-types";
27
+ import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
28
+ import { InvalidRequestError } from "ox/RpcResponse";
29
+ import { assertNever } from "../../utils.js";
30
+ import type { Static } from "@sinclair/typebox";
31
+ import { decodeSignature } from "../utils/decodeSignature.js";
32
+
33
+ export type SendPreparedCallsParams = Static<
34
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
35
+ >[0];
28
36
 
29
37
  export type SendPreparedCallsResult = Static<
30
38
  (typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
@@ -46,50 +54,218 @@ export async function sendPreparedCalls(
46
54
  }
47
55
 
48
56
  const deferredAction: Hex | undefined = (() => {
49
- if (!params.capabilities?.permissions?.context) {
57
+ if (!params.capabilities?.permissions) {
50
58
  return;
51
59
  }
52
60
 
53
61
  const decodedContext = decodePermissionsContext(
54
- params.capabilities.permissions.context,
62
+ params.capabilities.permissions,
55
63
  );
56
64
 
57
65
  if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
58
- throw new Error(
59
- "Remote mode deferred action not supported in isomorphic client",
60
- );
66
+ throw new InvalidRequestError({
67
+ message:
68
+ "Remote mode deferred action not supported in isomorphic client",
69
+ });
61
70
  }
62
71
 
63
72
  return decodedContext.deferredAction;
64
73
  })();
65
74
 
66
- const entryPoint =
67
- params.type === "user-operation-v060"
68
- ? getEntryPoint(client.chain, { version: "0.6.0" })
69
- : getEntryPoint(client.chain, { version: "0.7.0" });
70
-
71
- const hash = await client.sendRawUserOperation(
72
- {
73
- ...params.data,
74
- signature:
75
- deferredAction != null
76
- ? concatHex([
77
- `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).
78
- "0xff",
79
- "0x00",
80
- params.signature.signature,
81
- ])
82
- : concat(["0xFF", "0x00", params.signature.signature]),
83
- },
84
- entryPoint.address,
85
- );
75
+ const userOps =
76
+ params.type === "array"
77
+ ? params.data.filter((it) => {
78
+ const isUserOp =
79
+ it.type === "user-operation-v060" ||
80
+ it.type === "user-operation-v070";
81
+ if (isUserOp && it.chainId !== toHex(client.chain.id)) {
82
+ throw new InvalidRequestError({
83
+ message:
84
+ "Multiple chain IDs in a single request are not currently supported.",
85
+ });
86
+ }
87
+ return isUserOp;
88
+ })
89
+ : [params];
90
+
91
+ if (!userOps.length) {
92
+ throw new InvalidRequestError({
93
+ message: "Calls must include at least one user operation",
94
+ });
95
+ }
96
+
97
+ const authorizations =
98
+ params.type === "array"
99
+ ? params.data.filter((it) => it.type === "authorization")
100
+ : [];
101
+
102
+ if (authorizations.length > 1) {
103
+ throw new InvalidRequestError({
104
+ message:
105
+ "Multiple authorizations in a single request are not currently supported",
106
+ });
107
+ }
108
+ const [authorization] = authorizations;
109
+
110
+ // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
111
+ if (
112
+ authorization &&
113
+ !isSupportedDelegationAddress7702(authorization.data.address)
114
+ ) {
115
+ throw new InvalidRequestError({
116
+ message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
117
+ });
118
+ }
119
+
120
+ const hashes = await Promise.all(
121
+ userOps.map(async (userOp, idx) => {
122
+ const ep: { address: Address } =
123
+ userOp.type === "user-operation-v060"
124
+ ? getEntryPoint(client.chain, { version: "0.6.0" })
125
+ : userOp.type === "user-operation-v070"
126
+ ? getEntryPoint(client.chain, { version: "0.7.0" })
127
+ : assertNever(userOp, "Unexpected user op type");
128
+ const authSig = authorization
129
+ ? parseSignature(decodeSignature(authorization.signature).data)
130
+ : undefined;
131
+ const uoSigHex = decodeSignature(userOp.signature).data;
132
+
133
+ const { counterfactualInfo, delegation } = await client.request({
134
+ method: "wallet_requestAccount",
135
+ params: [
136
+ {
137
+ accountAddress: userOp.data.sender,
138
+ includeCounterfactualInfo: true,
139
+ },
140
+ ],
141
+ });
86
142
 
87
- const callId = Value.Encode(TypeCallId, {
88
- chainId: toHex(client.chain.id),
89
- hash,
90
- });
143
+ if (!counterfactualInfo && !delegation) {
144
+ throw new InvalidRequestError({
145
+ message:
146
+ "No counterfactual info or delegated implementation address found.",
147
+ });
148
+ }
149
+
150
+ const deferredActionData: Hex | undefined = deferredAction
151
+ ? await (async () => {
152
+ // determine whether the data should be appended to the signature.
153
+ // logic ported from @account-kit/smart-contracts `modularAccountV2Base.ts`
154
+
155
+ const deferredActionNonce = BigInt(
156
+ `0x${deferredAction.slice(4, 68)}`,
157
+ );
158
+
159
+ const entryPoint = getEntryPoint(client.chain, {
160
+ version: "0.7.0",
161
+ });
162
+
163
+ const entryPointContract = getContract({
164
+ address: entryPoint.address,
165
+ abi: entryPoint.abi,
166
+ client,
167
+ });
168
+
169
+ // Set these values if the deferred action has not been consumed. We check this with the EP
170
+ const nextNonceForDeferredAction: bigint =
171
+ (await entryPointContract.read.getNonce([
172
+ userOp.data.sender,
173
+ deferredActionNonce >> 64n,
174
+ ])) as bigint;
175
+
176
+ if (deferredActionNonce === nextNonceForDeferredAction) {
177
+ return `0x${deferredAction.slice(68)}`;
178
+ } else if (deferredActionNonce > nextNonceForDeferredAction) {
179
+ // if nonce is greater than the next nonce, its invalid, so we throw
180
+ throw new InvalidRequestError({
181
+ message: "Invalid session nonce",
182
+ });
183
+ }
184
+
185
+ // In this case, the deferred action has already been consumed, so no data should be appended to the signature.
186
+ // The signer entity should already be accounted for in `userOp.nonce`.
187
+ return undefined;
188
+ })()
189
+ : undefined;
190
+
191
+ const factoryType = counterfactualInfo?.factoryType;
192
+
193
+ // build signature based on account type
194
+ const signature = (() => {
195
+ switch (factoryType) {
196
+ // light accounts
197
+ case "LightAccountV1.0.1":
198
+ case "LightAccountV1.0.2":
199
+ case "LightAccountV1.1.0":
200
+ case "MAv1.0.0-MultiOwner":
201
+ // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
202
+ return uoSigHex;
203
+ case "LightAccountV2.0.0":
204
+ // for LAv2, we need to prepend the "SignatureType.EOA" byte.
205
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
206
+ return concat(["0x00", uoSigHex]);
207
+ case undefined: // undefined defaults to sma-b
208
+ case "MAv2.0.0-sma-b":
209
+ // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
210
+ // Signature Segment" and "SignatureType.EOA" bytes
211
+ return deferredActionData != null
212
+ ? concatHex([deferredActionData, "0xFF", "0x00", uoSigHex])
213
+ : concat(["0xFF", "0x00", uoSigHex]);
214
+ case "LightAccountV2.0.0-MultiOwner":
215
+ // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
216
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
217
+ return concat(["0x00", uoSigHex]);
218
+ case "MAv2.0.0-ma-ssv":
219
+ case "MAv2.0.0-ma-webauthn":
220
+ case "MAv1.0.0-MultiSig":
221
+ case "unknown":
222
+ throw new InvalidRequestError({
223
+ message: `Unsupported factory type: ${factoryType}`,
224
+ });
225
+ default:
226
+ return assertNever(factoryType, "Unsupported factory type");
227
+ }
228
+ })();
229
+
230
+ return client
231
+ .sendRawUserOperation(
232
+ {
233
+ ...userOp.data,
234
+ signature,
235
+ eip7702Auth:
236
+ idx === 0 && authorization && authSig
237
+ ? {
238
+ ...authorization.data,
239
+ chainId: authorization.chainId,
240
+ ...{
241
+ ...authSig,
242
+ yParity: numberToHex(authSig.yParity),
243
+ },
244
+ }
245
+ : undefined,
246
+ },
247
+ ep.address,
248
+ )
249
+ .catch((err) => {
250
+ if (
251
+ err instanceof BaseError &&
252
+ err.details.endsWith("is not a contract and initCode is empty")
253
+ ) {
254
+ throw new BaseError(
255
+ `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
256
+ );
257
+ }
258
+ throw err;
259
+ });
260
+ }),
261
+ );
91
262
 
92
263
  return {
93
- preparedCallIds: [callId],
264
+ preparedCallIds: hashes.map((hash) =>
265
+ Value.Encode(CallId, {
266
+ chainId: toHex(client.chain.id),
267
+ hash,
268
+ }),
269
+ ),
94
270
  };
95
271
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  createSmartAccountClient,
3
+ type ClientMiddlewareFn,
3
4
  type SmartAccountClient,
4
5
  type SmartAccountClientRpcSchema,
5
6
  type SmartContractAccount,
@@ -11,7 +12,7 @@ import {
11
12
  type AlchemyTransport,
12
13
  } from "@account-kit/infra";
13
14
  import { type Chain, type Transport } from "viem";
14
- import type { WalletServerViemRpcSchema } from "../rpc/schema.js";
15
+ import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
15
16
  import {
16
17
  createSession,
17
18
  type CreateSessionParams,
@@ -28,6 +29,8 @@ import {
28
29
  sendPreparedCalls,
29
30
  type SendPreparedCallsParams,
30
31
  } from "./actions/sendPreparedCalls.js";
32
+ import { prepareSign, type PrepareSignParams } from "./actions/prepareSign.js";
33
+ import { formatSign, type FormatSignParams } from "./actions/formatSign.js";
31
34
 
32
35
  // 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
36
  type ClientParams = {
@@ -35,6 +38,7 @@ type ClientParams = {
35
38
  transport: Transport;
36
39
  policyId?: string;
37
40
  useErc7677middleware?: boolean;
41
+ feeEstimator?: ClientMiddlewareFn;
38
42
  };
39
43
 
40
44
  export function isomorphicClientActions(
@@ -54,6 +58,8 @@ export function isomorphicClientActions(
54
58
  getCallsStatus(client, params),
55
59
  createSession: (params: CreateSessionParams) =>
56
60
  createSession(client, params),
61
+ prepareSign: (params: PrepareSignParams) => prepareSign(client, params),
62
+ formatSign: (params: FormatSignParams) => formatSign(client, params),
57
63
  };
58
64
  }
59
65
 
@@ -64,6 +70,7 @@ export function createIsomorphicClient({
64
70
  transport,
65
71
  policyId,
66
72
  useErc7677middleware = true,
73
+ feeEstimator,
67
74
  }: ClientParams): SmartAccountClient<
68
75
  Transport,
69
76
  Chain,
@@ -76,7 +83,8 @@ export function createIsomorphicClient({
76
83
  transport,
77
84
  chain,
78
85
  // TODO: we will want to enforce alchemy transport here probably
79
- feeEstimator: alchemyFeeEstimator(transport as AlchemyTransport),
86
+ feeEstimator:
87
+ feeEstimator ?? alchemyFeeEstimator(transport as AlchemyTransport),
80
88
  ...(policyId
81
89
  ? useErc7677middleware
82
90
  ? alchemyGasManagerMiddleware(policyId)