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

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 +210 -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 +39 -10
  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 +37 -26
  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 +138 -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 +256 -54
  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 +55 -12
  195. package/src/isomorphic/actions/formatSign.ts +76 -0
  196. package/src/isomorphic/actions/getCallsStatus.ts +46 -32
  197. package/src/isomorphic/actions/prepareCalls.ts +95 -23
  198. package/src/isomorphic/actions/prepareSign.ts +91 -0
  199. package/src/isomorphic/actions/sendPreparedCalls.ts +181 -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
@@ -3,28 +3,35 @@ 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
+ numberToHex,
13
+ parseSignature,
12
14
  toHex,
15
+ type Address,
13
16
  type Chain,
14
17
  type Hex,
15
18
  type Transport,
16
19
  } 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
- >;
20
+ import type {
21
+ wallet_sendPreparedCalls,
22
+ WalletServerViemRpcSchema,
23
+ } from "@alchemy/wallet-api-types/rpc";
24
+ import { decodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
25
+ import { TypeCallId } from "@alchemy/wallet-api-types";
26
+ import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
27
+ import { InvalidRequestError } from "ox/RpcResponse";
28
+ import { assertNever } from "../../utils.js";
29
+ import type { Static } from "@sinclair/typebox";
30
+ import { decodeSignature } from "../utils/decodeSignature.js";
31
+
32
+ export type SendPreparedCallsParams = Static<
33
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
34
+ >[0];
28
35
 
29
36
  export type SendPreparedCallsResult = Static<
30
37
  (typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
@@ -46,50 +53,182 @@ export async function sendPreparedCalls(
46
53
  }
47
54
 
48
55
  const deferredAction: Hex | undefined = (() => {
49
- if (!params.capabilities?.permissions?.context) {
56
+ if (!params.capabilities?.permissions) {
50
57
  return;
51
58
  }
52
59
 
53
60
  const decodedContext = decodePermissionsContext(
54
- params.capabilities.permissions.context,
61
+ params.capabilities.permissions,
55
62
  );
56
63
 
57
64
  if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
58
- throw new Error(
59
- "Remote mode deferred action not supported in isomorphic client",
60
- );
65
+ throw new InvalidRequestError({
66
+ message:
67
+ "Remote mode deferred action not supported in isomorphic client",
68
+ });
61
69
  }
62
70
 
63
71
  return decodedContext.deferredAction;
64
72
  })();
65
73
 
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
- );
74
+ const userOps =
75
+ params.type === "array"
76
+ ? params.data.filter((it) => {
77
+ const isUserOp =
78
+ it.type === "user-operation-v060" ||
79
+ it.type === "user-operation-v070";
80
+ if (isUserOp && it.chainId !== toHex(client.chain.id)) {
81
+ throw new InvalidRequestError({
82
+ message:
83
+ "Multiple chain IDs in a single request are not currently supported.",
84
+ });
85
+ }
86
+ return isUserOp;
87
+ })
88
+ : [params];
89
+
90
+ if (!userOps.length) {
91
+ throw new InvalidRequestError({
92
+ message: "Calls must include at least one user operation",
93
+ });
94
+ }
95
+
96
+ const authorizations =
97
+ params.type === "array"
98
+ ? params.data.filter((it) => it.type === "authorization")
99
+ : [];
100
+
101
+ if (authorizations.length > 1) {
102
+ throw new InvalidRequestError({
103
+ message:
104
+ "Multiple authorizations in a single request are not currently supported",
105
+ });
106
+ }
107
+ const [authorization] = authorizations;
86
108
 
87
- const callId = Value.Encode(TypeCallId, {
88
- chainId: toHex(client.chain.id),
89
- hash,
90
- });
109
+ // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
110
+ if (
111
+ authorization &&
112
+ !isSupportedDelegationAddress7702(authorization.data.address)
113
+ ) {
114
+ throw new InvalidRequestError({
115
+ message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
116
+ });
117
+ }
118
+
119
+ const hashes = await Promise.all(
120
+ userOps.map(async (userOp, idx) => {
121
+ const ep: { address: Address } =
122
+ userOp.type === "user-operation-v060"
123
+ ? getEntryPoint(client.chain, { version: "0.6.0" })
124
+ : userOp.type === "user-operation-v070"
125
+ ? getEntryPoint(client.chain, { version: "0.7.0" })
126
+ : assertNever(userOp, "Unexpected user op type");
127
+ const authSig = authorization
128
+ ? parseSignature(decodeSignature(authorization.signature).data)
129
+ : undefined;
130
+ const uoSigHex = decodeSignature(userOp.signature).data;
131
+
132
+ const { counterfactualInfo, delegation } = await client.request({
133
+ method: "wallet_requestAccount",
134
+ params: [
135
+ {
136
+ accountAddress: userOp.data.sender,
137
+ includeCounterfactualInfo: true,
138
+ },
139
+ ],
140
+ });
141
+
142
+ if (!counterfactualInfo && !delegation) {
143
+ throw new InvalidRequestError({
144
+ message:
145
+ "No counterfactual info or delegated implementation address found.",
146
+ });
147
+ }
148
+
149
+ const factoryType = counterfactualInfo?.factoryType;
150
+
151
+ // build signature based on account type
152
+ const signature = (() => {
153
+ switch (factoryType) {
154
+ // light accounts
155
+ case "LightAccountV1.0.1":
156
+ case "LightAccountV1.0.2":
157
+ case "LightAccountV1.1.0":
158
+ case "MAv1.0.0-MultiOwner":
159
+ // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
160
+ return uoSigHex;
161
+ case "LightAccountV2.0.0":
162
+ // for LAv2, we need to prepend the "SignatureType.EOA" byte.
163
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
164
+ return concat(["0x00", uoSigHex]);
165
+ case undefined: // undefined defaults to sma-b
166
+ case "MAv2.0.0-sma-b":
167
+ // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
168
+ // Signature Segment" and "SignatureType.EOA" bytes
169
+ return deferredAction != null
170
+ ? concatHex([
171
+ `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
172
+ "0xFF",
173
+ "0x00",
174
+ uoSigHex,
175
+ ])
176
+ : concat(["0xFF", "0x00", uoSigHex]);
177
+ case "LightAccountV2.0.0-MultiOwner":
178
+ // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
179
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
180
+ return concat(["0x00", uoSigHex]);
181
+ case "MAv2.0.0-ma-ssv":
182
+ case "MAv2.0.0-ma-webauthn":
183
+ case "MAv1.0.0-MultiSig":
184
+ case "unknown":
185
+ throw new InvalidRequestError({
186
+ message: `Unsupported factory type: ${factoryType}`,
187
+ });
188
+ default:
189
+ return assertNever(factoryType, "Unsupported factory type");
190
+ }
191
+ })();
192
+
193
+ return client
194
+ .sendRawUserOperation(
195
+ {
196
+ ...userOp.data,
197
+ signature,
198
+ eip7702Auth:
199
+ idx === 0 && authorization && authSig
200
+ ? {
201
+ ...authorization.data,
202
+ chainId: authorization.chainId,
203
+ ...{
204
+ ...authSig,
205
+ yParity: numberToHex(authSig.yParity),
206
+ },
207
+ }
208
+ : undefined,
209
+ },
210
+ ep.address,
211
+ )
212
+ .catch((err) => {
213
+ if (
214
+ err instanceof BaseError &&
215
+ err.details.endsWith("is not a contract and initCode is empty")
216
+ ) {
217
+ throw new BaseError(
218
+ `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
219
+ );
220
+ }
221
+ throw err;
222
+ });
223
+ }),
224
+ );
91
225
 
92
226
  return {
93
- preparedCallIds: [callId],
227
+ preparedCallIds: hashes.map((hash) =>
228
+ Value.Encode(TypeCallId, {
229
+ chainId: toHex(client.chain.id),
230
+ hash,
231
+ }),
232
+ ),
94
233
  };
95
234
  }
@@ -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)
@@ -0,0 +1,135 @@
1
+ import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
+ import {
3
+ concatHex,
4
+ numberToHex,
5
+ type Address,
6
+ type Chain,
7
+ type Transport,
8
+ isAddress,
9
+ hexToNumber,
10
+ } from "viem";
11
+ import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
12
+ import {
13
+ Eip7702AccountTypeToDelegationAddress,
14
+ SUPPORTED_DELEGATION_ADDRESSES,
15
+ type Supported7702AccountType,
16
+ type Eip7702AuthCapability,
17
+ } from "@alchemy/wallet-api-types/capabilities";
18
+ import type { PreparedCall_Authorization } from "@alchemy/wallet-api-types";
19
+ import { InvalidRequestError } from "ox/RpcResponse";
20
+ import { hashAuthorization } from "viem/utils";
21
+
22
+ /** Checks if an address is actively delegated on-chain. */
23
+ export const isDelegated = async (
24
+ client: SmartAccountClient<
25
+ Transport,
26
+ Chain,
27
+ SmartContractAccount | undefined,
28
+ Record<string, unknown>,
29
+ WalletServerViemRpcSchema
30
+ >,
31
+ params: { address: Address; delegation: Address },
32
+ ): Promise<boolean> => {
33
+ const expectedCode = concatHex(["0xef0100", params.delegation]);
34
+ const code = (await client.getCode({ address: params.address })) ?? "0x";
35
+ return code.toLowerCase() === expectedCode.toLowerCase();
36
+ };
37
+
38
+ export const createAuthorizationRequest = async (
39
+ client: SmartAccountClient<
40
+ Transport,
41
+ Chain,
42
+ SmartContractAccount | undefined,
43
+ Record<string, unknown>,
44
+ WalletServerViemRpcSchema
45
+ >,
46
+ params: { address: Address; delegation: Address },
47
+ ): Promise<PreparedCall_Authorization> => {
48
+ const data = {
49
+ address: params.delegation,
50
+ nonce: numberToHex(
51
+ await client.getTransactionCount({
52
+ address: params.address,
53
+ }),
54
+ ),
55
+ };
56
+ return {
57
+ type: "authorization" as const,
58
+ data,
59
+ chainId: numberToHex(client.chain.id),
60
+ signatureRequest: {
61
+ type: "eip7702Auth" as const,
62
+ rawPayload: hashAuthorization({
63
+ chainId: client.chain.id,
64
+ nonce: hexToNumber(data.nonce),
65
+ address: params.delegation,
66
+ }),
67
+ },
68
+ };
69
+ };
70
+
71
+ export const DelegationAddressToAccountType: Record<
72
+ Address,
73
+ Supported7702AccountType
74
+ > = Object.fromEntries(
75
+ Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
76
+ value,
77
+ key,
78
+ ]),
79
+ ) as Record<Address, Supported7702AccountType>;
80
+
81
+ export const isSupportedDelegationAddress7702 = (address: Address): boolean => {
82
+ return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);
83
+ };
84
+
85
+ export const getAccountTypeForDelegationAddress7702 = (
86
+ address: Address,
87
+ ): Supported7702AccountType | undefined => {
88
+ return DelegationAddressToAccountType[address];
89
+ };
90
+
91
+ const getDelegationAddressForAccountType7702 = (
92
+ accountType: Supported7702AccountType,
93
+ ): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {
94
+ return Eip7702AccountTypeToDelegationAddress[accountType];
95
+ };
96
+
97
+ const DEFAULT_7702_DELEGATION_ADDR =
98
+ Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
99
+
100
+ export const parseDelegation = (
101
+ eip7702AuthCapability: Eip7702AuthCapability,
102
+ ) => {
103
+ return eip7702AuthCapability === true
104
+ ? DEFAULT_7702_DELEGATION_ADDR
105
+ : isAddress(eip7702AuthCapability.delegation)
106
+ ? eip7702AuthCapability.delegation
107
+ : getDelegationAddressForAccountType7702(
108
+ eip7702AuthCapability.delegation,
109
+ );
110
+ };
111
+
112
+ export const assertValid7702AccountAddress = (
113
+ fromAddress: Address,
114
+ eip7702AuthCapability: Eip7702AuthCapability | undefined,
115
+ ) => {
116
+ if (eip7702AuthCapability) {
117
+ if (
118
+ typeof eip7702AuthCapability === "object" &&
119
+ "account" in eip7702AuthCapability &&
120
+ eip7702AuthCapability?.account !== fromAddress
121
+ ) {
122
+ throw new InvalidRequestError({
123
+ message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
124
+ });
125
+ }
126
+
127
+ const delegation = parseDelegation(eip7702AuthCapability);
128
+
129
+ if (!isSupportedDelegationAddress7702(delegation)) {
130
+ throw new InvalidRequestError({
131
+ message: `Unsupported 7702 delegation address: ${delegation}`,
132
+ });
133
+ }
134
+ }
135
+ };
@@ -1,22 +1,29 @@
1
1
  import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
2
2
  import {
3
+ createLightAccount,
3
4
  createModularAccountV2,
5
+ createMultiOwnerLightAccount,
6
+ createMultiOwnerModularAccount,
4
7
  type ModularAccountV2,
5
8
  } from "@account-kit/smart-contracts";
6
9
  import type { StaticDecode } from "@sinclair/typebox";
7
10
  import type { Address, Chain, Transport } from "viem";
8
11
  import { concatHex, hexToNumber } from "viem";
9
- import type { Capabilities } from "../../capabilities/index.js";
10
- import type { TypeSerializedInitcode } from "../../schemas.js";
11
12
  import { parsePermissionsContext } from "./parsePermissionsContext.js";
13
+ import { assertNever } from "../../utils.js";
14
+ import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
15
+ import { TypeSerializedInitcode } from "@alchemy/wallet-api-types";
16
+ import { PermissionsCapability } from "@alchemy/wallet-api-types/capabilities";
17
+ import { InternalError, InvalidRequestError } from "ox/RpcResponse";
12
18
 
13
19
  type CreateAccountParams = {
14
20
  chain: Chain;
15
21
  transport: Transport;
16
22
  signer: SmartAccountSigner;
17
23
  accountAddress: Address;
18
- counterfactualInfo: StaticDecode<typeof TypeSerializedInitcode>;
19
- capabilities?: StaticDecode<typeof Capabilities>;
24
+ counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts
25
+ permissions?: StaticDecode<typeof PermissionsCapability>;
26
+ delegation?: Address;
20
27
  };
21
28
 
22
29
  /**
@@ -28,12 +35,14 @@ export async function createAccount(
28
35
  params: CreateAccountParams,
29
36
  ): Promise<SmartContractAccount> {
30
37
  const { counterfactualInfo: ci, ...accountParams } = params;
31
- // TODO: Implement support for other account types.
32
- if (ci.factoryType !== "MAv2.0.0-sma-b") {
33
- throw new Error("Only MAv2 SMA-B accounts are currently supported");
34
- }
35
38
 
36
- const parsedContext = parsePermissionsContext(params.capabilities, ci);
39
+ // This throws if we pass a permission context and the account is not MA-v2
40
+ // TODO: test that this edge case is handled correctly
41
+ const parsedContext = parsePermissionsContext(
42
+ params.permissions,
43
+ ci,
44
+ params.delegation,
45
+ );
37
46
 
38
47
  const signerEntity =
39
48
  parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
@@ -43,12 +52,91 @@ export async function createAccount(
43
52
  }
44
53
  : undefined;
45
54
 
46
- return createModularAccountV2({
55
+ const mode = params.delegation ? "7702" : "default";
56
+
57
+ if (mode === "7702") {
58
+ const accountType = getAccountTypeForDelegationAddress7702(
59
+ params.delegation!,
60
+ );
61
+ if (accountType !== "ModularAccountV2") {
62
+ throw new Error("7702 mode currently only supports ModularAccountV2");
63
+ }
64
+ return createModularAccountV2({
65
+ ...accountParams,
66
+ signerEntity,
67
+ deferredAction: parsedContext?.deferredAction,
68
+ mode,
69
+ });
70
+ }
71
+
72
+ if (mode !== "default") {
73
+ return assertNever(mode, "Unexpected mode in createAccount");
74
+ }
75
+
76
+ // At this point, we are guaranteed to be in default mode, where ci
77
+ // (counterfactualInfo) must be defined
78
+
79
+ if (!ci) {
80
+ throw new InternalError({
81
+ message: "Counterfactual info not found",
82
+ });
83
+ }
84
+
85
+ const factoryType = ci.factoryType;
86
+ const commonParams = {
47
87
  ...accountParams,
48
- signerEntity,
49
- deferredAction: parsedContext?.deferredAction,
50
88
  initCode: concatHex([ci.factoryAddress, ci.factoryData]),
51
- });
89
+ };
90
+
91
+ // Return the account created based on the factory type
92
+ switch (factoryType) {
93
+ case "MAv2.0.0-sma-b":
94
+ return createModularAccountV2({
95
+ ...commonParams,
96
+ signerEntity,
97
+ deferredAction: parsedContext?.deferredAction,
98
+ mode,
99
+ });
100
+ case "LightAccountV2.0.0":
101
+ return createLightAccount({
102
+ ...commonParams,
103
+ version: "v2.0.0",
104
+ });
105
+ case "LightAccountV1.0.1":
106
+ return createLightAccount({
107
+ ...commonParams,
108
+ version: "v1.0.1",
109
+ });
110
+ case "LightAccountV1.0.2":
111
+ return createLightAccount({
112
+ ...commonParams,
113
+ version: "v1.0.2",
114
+ });
115
+ case "LightAccountV1.1.0":
116
+ return createLightAccount({
117
+ ...commonParams,
118
+ version: "v1.1.0",
119
+ });
120
+ case "MAv1.0.0-MultiOwner":
121
+ return createMultiOwnerModularAccount({
122
+ ...commonParams,
123
+ });
124
+ case "LightAccountV2.0.0-MultiOwner":
125
+ return createMultiOwnerLightAccount({
126
+ ...commonParams,
127
+ version: "v2.0.0",
128
+ });
129
+ case "MAv1.0.0-MultiSig":
130
+ case "MAv2.0.0-ma-ssv":
131
+ case "MAv2.0.0-ma-webauthn":
132
+ case "unknown":
133
+ case undefined:
134
+ throw new InvalidRequestError({
135
+ message: `Account type currently unsupported: ${factoryType}`,
136
+ });
137
+ default:
138
+ return assertNever(factoryType, "Unsupported factory type");
139
+ }
52
140
  }
53
141
 
54
142
  export function isModularAccountV2(
@@ -1,6 +1,7 @@
1
1
  import { type SmartAccountSigner } from "@aa-sdk/core";
2
2
  import type { TypedData } from "abitype";
3
3
  import {
4
+ BaseError,
4
5
  type Address,
5
6
  type Hex,
6
7
  type SignableMessage,
@@ -15,12 +16,12 @@ export const createDummySigner = (address: Address): SmartAccountSigner => ({
15
16
  },
16
17
  // Not supported on the server
17
18
  signMessage: function (_message: SignableMessage): Promise<Hex> {
18
- throw new Error("Function not implemented.");
19
+ throw new BaseError("signMessage not implemented by dummy signer.");
19
20
  },
20
21
  signTypedData: function <
21
22
  const TTypedData extends TypedData | Record<string, unknown>,
22
23
  TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData,
23
24
  >(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {
24
- throw new Error("Function not implemented.");
25
+ throw new BaseError("signTypedData not implemented by dummy signer.");
25
26
  },
26
27
  });
@@ -0,0 +1,21 @@
1
+ import { Value } from "@sinclair/typebox/value";
2
+ import type { StaticDecode } from "@sinclair/typebox";
3
+ import {
4
+ TypeEcdsaSig,
5
+ type TypeEcdsaSig as TypeEcdsaSigType,
6
+ } from "@alchemy/wallet-api-types";
7
+ import { assertNever } from "../../utils.js";
8
+
9
+ export const decodeSignature = (
10
+ signature: TypeEcdsaSigType["signature"],
11
+ ): StaticDecode<typeof TypeEcdsaSig>["signature"] => {
12
+ switch (signature.type) {
13
+ case "ecdsa":
14
+ case "secp256k1":
15
+ return Value.Decode(TypeEcdsaSig, {
16
+ signature,
17
+ } satisfies TypeEcdsaSigType).signature;
18
+ default:
19
+ return assertNever(signature, "Unexpected signature type");
20
+ }
21
+ };