@account-kit/wallet-client 0.1.0-alpha.0 → 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 (264) hide show
  1. package/dist/esm/abi/index.d.ts +8 -8
  2. package/dist/esm/abi/index.js +8 -8
  3. package/dist/esm/abi/index.js.map +1 -1
  4. package/dist/esm/client/actions/createAccount.d.ts +27 -2
  5. package/dist/esm/client/actions/createAccount.js +25 -0
  6. package/dist/esm/client/actions/createAccount.js.map +1 -1
  7. package/dist/esm/client/actions/formatSign.d.ts +28 -0
  8. package/dist/esm/client/actions/formatSign.js +30 -0
  9. package/dist/esm/client/actions/formatSign.js.map +1 -0
  10. package/dist/esm/client/actions/getCallsStatus.d.ts +22 -4
  11. package/dist/esm/client/actions/getCallsStatus.js +19 -0
  12. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  13. package/dist/esm/client/actions/grantPermissions.d.ts +63 -6
  14. package/dist/esm/client/actions/grantPermissions.js +63 -3
  15. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  16. package/dist/esm/client/actions/listAccounts.d.ts +32 -4
  17. package/dist/esm/client/actions/listAccounts.js +35 -2
  18. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  19. package/dist/esm/client/actions/prepareCalls.d.ts +32 -6
  20. package/dist/esm/client/actions/prepareCalls.js +39 -5
  21. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  22. package/dist/esm/client/actions/prepareSign.d.ts +25 -0
  23. package/dist/esm/client/actions/prepareSign.js +28 -0
  24. package/dist/esm/client/actions/prepareSign.js.map +1 -0
  25. package/dist/esm/client/actions/requestAccount.d.ts +25 -7
  26. package/dist/esm/client/actions/requestAccount.js +39 -8
  27. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  28. package/dist/esm/client/actions/sendPreparedCalls.d.ts +33 -4
  29. package/dist/esm/client/actions/sendPreparedCalls.js +37 -1
  30. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  31. package/dist/esm/client/actions/signMessage.d.ts +25 -5
  32. package/dist/esm/client/actions/signMessage.js +23 -3
  33. package/dist/esm/client/actions/signMessage.js.map +1 -1
  34. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  35. package/dist/esm/client/actions/signPreparedCalls.js +43 -0
  36. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  37. package/dist/esm/client/actions/signSignatureRequest.d.ts +39 -5
  38. package/dist/esm/client/actions/signSignatureRequest.js +70 -12
  39. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  40. package/dist/esm/client/actions/signTypedData.d.ts +37 -4
  41. package/dist/esm/client/actions/signTypedData.js +35 -2
  42. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  43. package/dist/esm/client/client.e2e-test.js +211 -46
  44. package/dist/esm/client/client.e2e-test.js.map +1 -1
  45. package/dist/esm/client/decorator.d.ts +19 -15
  46. package/dist/esm/client/decorator.js +13 -11
  47. package/dist/esm/client/decorator.js.map +1 -1
  48. package/dist/esm/client/index.d.ts +39 -13
  49. package/dist/esm/client/index.js +3 -6
  50. package/dist/esm/client/index.js.map +1 -1
  51. package/dist/esm/exports/index.d.ts +12 -13
  52. package/dist/esm/exports/index.js +12 -14
  53. package/dist/esm/exports/index.js.map +1 -1
  54. package/dist/esm/exports/internal.d.ts +4 -13
  55. package/dist/esm/exports/internal.js +2 -14
  56. package/dist/esm/exports/internal.js.map +1 -1
  57. package/dist/esm/internal/decorator.d.ts +2 -0
  58. package/dist/esm/internal/decorator.js +10 -0
  59. package/dist/esm/internal/decorator.js.map +1 -0
  60. package/dist/esm/isomorphic/actions/createSession.d.ts +2 -3
  61. package/dist/esm/isomorphic/actions/createSession.js +41 -12
  62. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  63. package/dist/esm/isomorphic/actions/formatSign.d.ts +8 -0
  64. package/dist/esm/isomorphic/actions/formatSign.js +42 -0
  65. package/dist/esm/isomorphic/actions/formatSign.js.map +1 -0
  66. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +1 -15
  67. package/dist/esm/isomorphic/actions/getCallsStatus.js +39 -28
  68. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
  69. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +1 -2
  70. package/dist/esm/isomorphic/actions/prepareCalls.js +80 -22
  71. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  72. package/dist/esm/isomorphic/actions/prepareSign.d.ts +7 -0
  73. package/dist/esm/isomorphic/actions/prepareSign.js +49 -0
  74. package/dist/esm/isomorphic/actions/prepareSign.js.map +1 -0
  75. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
  76. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +138 -25
  77. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  78. package/dist/esm/isomorphic/client.d.ts +209 -32
  79. package/dist/esm/isomorphic/client.js +10 -6
  80. package/dist/esm/isomorphic/client.js.map +1 -1
  81. package/dist/esm/isomorphic/utils/7702.d.ts +19 -0
  82. package/dist/esm/isomorphic/utils/7702.js +70 -0
  83. package/dist/esm/isomorphic/utils/7702.js.map +1 -0
  84. package/dist/esm/isomorphic/utils/createAccount.d.ts +5 -4
  85. package/dist/esm/isomorphic/utils/createAccount.js +85 -11
  86. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  87. package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
  88. package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
  89. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  90. package/dist/esm/isomorphic/utils/decodeSignature.js +15 -0
  91. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  92. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
  93. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +19 -6
  94. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
  95. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
  96. package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
  97. package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
  98. package/dist/esm/local/client.d.ts +3 -3
  99. package/dist/esm/local/client.js +14 -7
  100. package/dist/esm/local/client.js.map +1 -1
  101. package/dist/esm/remote/client.d.ts +9 -3
  102. package/dist/esm/remote/client.js +11 -12
  103. package/dist/esm/remote/client.js.map +1 -1
  104. package/dist/esm/types.d.ts +27 -13
  105. package/dist/esm/types.js.map +1 -1
  106. package/dist/esm/utils.d.ts +1 -0
  107. package/dist/esm/utils.js.map +1 -1
  108. package/dist/types/abi/index.d.ts +8 -8
  109. package/dist/types/abi/index.d.ts.map +1 -1
  110. package/dist/types/client/actions/createAccount.d.ts +27 -2
  111. package/dist/types/client/actions/createAccount.d.ts.map +1 -1
  112. package/dist/types/client/actions/formatSign.d.ts +29 -0
  113. package/dist/types/client/actions/formatSign.d.ts.map +1 -0
  114. package/dist/types/client/actions/getCallsStatus.d.ts +22 -4
  115. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  116. package/dist/types/client/actions/grantPermissions.d.ts +63 -6
  117. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  118. package/dist/types/client/actions/listAccounts.d.ts +32 -4
  119. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  120. package/dist/types/client/actions/prepareCalls.d.ts +32 -6
  121. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  122. package/dist/types/client/actions/prepareSign.d.ts +26 -0
  123. package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
  124. package/dist/types/client/actions/requestAccount.d.ts +25 -7
  125. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  126. package/dist/types/client/actions/sendPreparedCalls.d.ts +33 -4
  127. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  128. package/dist/types/client/actions/signMessage.d.ts +25 -5
  129. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  130. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  131. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  132. package/dist/types/client/actions/signSignatureRequest.d.ts +39 -5
  133. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  134. package/dist/types/client/actions/signTypedData.d.ts +37 -4
  135. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  136. package/dist/types/client/decorator.d.ts +19 -15
  137. package/dist/types/client/decorator.d.ts.map +1 -1
  138. package/dist/types/client/index.d.ts +39 -13
  139. package/dist/types/client/index.d.ts.map +1 -1
  140. package/dist/types/exports/index.d.ts +12 -13
  141. package/dist/types/exports/index.d.ts.map +1 -1
  142. package/dist/types/exports/internal.d.ts +4 -13
  143. package/dist/types/exports/internal.d.ts.map +1 -1
  144. package/dist/types/internal/decorator.d.ts +3 -0
  145. package/dist/types/internal/decorator.d.ts.map +1 -0
  146. package/dist/types/isomorphic/actions/createSession.d.ts +2 -3
  147. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  148. package/dist/types/isomorphic/actions/formatSign.d.ts +9 -0
  149. package/dist/types/isomorphic/actions/formatSign.d.ts.map +1 -0
  150. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +1 -15
  151. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
  152. package/dist/types/isomorphic/actions/prepareCalls.d.ts +1 -2
  153. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  154. package/dist/types/isomorphic/actions/prepareSign.d.ts +8 -0
  155. package/dist/types/isomorphic/actions/prepareSign.d.ts.map +1 -0
  156. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
  157. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  158. package/dist/types/isomorphic/client.d.ts +209 -32
  159. package/dist/types/isomorphic/client.d.ts.map +1 -1
  160. package/dist/types/isomorphic/utils/7702.d.ts +20 -0
  161. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
  162. package/dist/types/isomorphic/utils/createAccount.d.ts +5 -4
  163. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  164. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
  165. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  166. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  167. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
  168. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
  169. package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
  170. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
  171. package/dist/types/local/client.d.ts +3 -3
  172. package/dist/types/local/client.d.ts.map +1 -1
  173. package/dist/types/remote/client.d.ts +9 -3
  174. package/dist/types/remote/client.d.ts.map +1 -1
  175. package/dist/types/types.d.ts +27 -13
  176. package/dist/types/types.d.ts.map +1 -1
  177. package/dist/types/utils.d.ts +1 -0
  178. package/dist/types/utils.d.ts.map +1 -1
  179. package/package.json +15 -7
  180. package/src/abi/index.ts +8 -8
  181. package/src/client/actions/createAccount.ts +27 -2
  182. package/src/client/actions/formatSign.ts +53 -0
  183. package/src/client/actions/getCallsStatus.ts +21 -12
  184. package/src/client/actions/grantPermissions.ts +69 -26
  185. package/src/client/actions/listAccounts.ts +44 -6
  186. package/src/client/actions/prepareCalls.ts +46 -26
  187. package/src/client/actions/prepareSign.ts +46 -0
  188. package/src/client/actions/requestAccount.ts +62 -43
  189. package/src/client/actions/sendPreparedCalls.ts +44 -7
  190. package/src/client/actions/signMessage.ts +27 -22
  191. package/src/client/actions/signPreparedCalls.ts +67 -0
  192. package/src/client/actions/signSignatureRequest.ts +85 -21
  193. package/src/client/actions/signTypedData.ts +41 -20
  194. package/src/client/client.e2e-test.ts +257 -55
  195. package/src/client/decorator.ts +41 -39
  196. package/src/client/index.ts +55 -42
  197. package/src/exports/index.ts +13 -21
  198. package/src/exports/internal.ts +5 -13
  199. package/src/internal/decorator.ts +12 -0
  200. package/src/isomorphic/actions/createSession.ts +65 -22
  201. package/src/isomorphic/actions/formatSign.ts +76 -0
  202. package/src/isomorphic/actions/getCallsStatus.ts +49 -35
  203. package/src/isomorphic/actions/prepareCalls.ts +97 -25
  204. package/src/isomorphic/actions/prepareSign.ts +91 -0
  205. package/src/isomorphic/actions/sendPreparedCalls.ts +181 -42
  206. package/src/isomorphic/client.ts +17 -6
  207. package/src/isomorphic/utils/7702.ts +135 -0
  208. package/src/isomorphic/utils/createAccount.ts +102 -14
  209. package/src/isomorphic/utils/createDummySigner.ts +3 -2
  210. package/src/isomorphic/utils/decodeSignature.ts +21 -0
  211. package/src/isomorphic/utils/parsePermissionsContext.ts +29 -11
  212. package/src/isomorphic/utils/supportsFeature.ts +34 -0
  213. package/src/local/client.ts +61 -58
  214. package/src/remote/client.ts +20 -20
  215. package/src/types.ts +29 -23
  216. package/src/utils.ts +2 -0
  217. package/dist/esm/capabilities/index.d.ts +0 -31
  218. package/dist/esm/capabilities/index.js +0 -10
  219. package/dist/esm/capabilities/index.js.map +0 -1
  220. package/dist/esm/capabilities/overrides.d.ts +0 -26
  221. package/dist/esm/capabilities/overrides.js +0 -14
  222. package/dist/esm/capabilities/overrides.js.map +0 -1
  223. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  224. package/dist/esm/capabilities/paymaster.js +0 -5
  225. package/dist/esm/capabilities/paymaster.js.map +0 -1
  226. package/dist/esm/capabilities/permissions/index.d.ts +0 -138
  227. package/dist/esm/capabilities/permissions/index.js +0 -71
  228. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  229. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  230. package/dist/esm/capabilities/permissions/mav2.js +0 -79
  231. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  232. package/dist/esm/rpc/request.d.ts +0 -352
  233. package/dist/esm/rpc/request.js +0 -204
  234. package/dist/esm/rpc/request.js.map +0 -1
  235. package/dist/esm/rpc/schema.d.ts +0 -342
  236. package/dist/esm/rpc/schema.js +0 -5
  237. package/dist/esm/rpc/schema.js.map +0 -1
  238. package/dist/esm/schemas.d.ts +0 -216
  239. package/dist/esm/schemas.js +0 -211
  240. package/dist/esm/schemas.js.map +0 -1
  241. package/dist/types/capabilities/index.d.ts +0 -32
  242. package/dist/types/capabilities/index.d.ts.map +0 -1
  243. package/dist/types/capabilities/overrides.d.ts +0 -27
  244. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  245. package/dist/types/capabilities/paymaster.d.ts +0 -4
  246. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  247. package/dist/types/capabilities/permissions/index.d.ts +0 -139
  248. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  249. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  250. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  251. package/dist/types/rpc/request.d.ts +0 -353
  252. package/dist/types/rpc/request.d.ts.map +0 -1
  253. package/dist/types/rpc/schema.d.ts +0 -343
  254. package/dist/types/rpc/schema.d.ts.map +0 -1
  255. package/dist/types/schemas.d.ts +0 -217
  256. package/dist/types/schemas.d.ts.map +0 -1
  257. package/src/capabilities/index.ts +0 -13
  258. package/src/capabilities/overrides.ts +0 -20
  259. package/src/capabilities/paymaster.ts +0 -5
  260. package/src/capabilities/permissions/index.ts +0 -142
  261. package/src/capabilities/permissions/mav2.ts +0 -127
  262. package/src/rpc/request.ts +0 -273
  263. package/src/rpc/schema.ts +0 -40
  264. package/src/schemas.ts +0 -257
@@ -0,0 +1,91 @@
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 {
19
+ TypeSignableMessage,
20
+ jsonSafeTypedData,
21
+ } from "@alchemy/wallet-api-types";
22
+ import { createAccount } from "../utils/createAccount.js";
23
+ import { createDummySigner } from "../utils/createDummySigner.js";
24
+ import { Value } from "@sinclair/typebox/value";
25
+
26
+ export type PrepareSignParams = Static<
27
+ (typeof wallet_prepareSign)["properties"]["Request"]["properties"]["params"]
28
+ >[0];
29
+
30
+ export type PrepareSignResult = Static<
31
+ (typeof wallet_prepareSign)["properties"]["ReturnType"]
32
+ >;
33
+
34
+ export async function prepareSign(
35
+ client: SmartAccountClient<
36
+ Transport,
37
+ Chain,
38
+ SmartContractAccount | undefined,
39
+ Record<string, unknown>,
40
+ WalletServerViemRpcSchema
41
+ >,
42
+ params: PrepareSignParams,
43
+ ): Promise<PrepareSignResult> {
44
+ if (!client.chain) {
45
+ throw new ChainNotFoundError();
46
+ }
47
+
48
+ const { counterfactualInfo, delegation } = await client.request({
49
+ method: "wallet_requestAccount",
50
+ params: [
51
+ {
52
+ accountAddress: params.from,
53
+ includeCounterfactualInfo: true,
54
+ },
55
+ ],
56
+ });
57
+
58
+ const account = await createAccount({
59
+ chain: client.chain,
60
+ transport: custom(client.transport),
61
+ signer: createDummySigner(params.from),
62
+ accountAddress: params.from,
63
+ counterfactualInfo,
64
+ permissions: params.capabilities?.permissions,
65
+ delegation,
66
+ });
67
+
68
+ const signatureRequest = await account.prepareSign(
69
+ params.signatureRequest as SignatureRequest,
70
+ );
71
+
72
+ if (signatureRequest.type === "personal_sign") {
73
+ return {
74
+ chainId: toHex(client.chain.id),
75
+ signatureRequest: {
76
+ type: signatureRequest.type,
77
+ data: Value.Encode(TypeSignableMessage, signatureRequest.data),
78
+ },
79
+ };
80
+ } else {
81
+ const typedData = signatureRequest.data;
82
+
83
+ return {
84
+ chainId: toHex(client.chain.id),
85
+ signatureRequest: {
86
+ type: signatureRequest.type,
87
+ data: jsonSafeTypedData(typedData),
88
+ },
89
+ };
90
+ }
91
+ }
@@ -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";
18
- import type { wallet_sendPreparedCalls } from "../../rpc/request";
19
- import type { WalletServerViemRpcSchema } from "../../rpc/schema";
20
- import { TypeCallId } from "../../schemas";
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,20 +12,25 @@ 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";
15
+ import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
15
16
  import {
16
17
  createSession,
17
18
  type CreateSessionParams,
18
- } from "./actions/createSession";
19
+ } from "./actions/createSession.js";
19
20
  import {
20
21
  getCallsStatus,
21
22
  type GetCallsStatusParams,
22
- } from "./actions/getCallsStatus";
23
- import { prepareCalls, type PrepareCallsParams } from "./actions/prepareCalls";
23
+ } from "./actions/getCallsStatus.js";
24
+ import {
25
+ prepareCalls,
26
+ type PrepareCallsParams,
27
+ } from "./actions/prepareCalls.js";
24
28
  import {
25
29
  sendPreparedCalls,
26
30
  type SendPreparedCallsParams,
27
- } from "./actions/sendPreparedCalls";
31
+ } from "./actions/sendPreparedCalls.js";
32
+ import { prepareSign, type PrepareSignParams } from "./actions/prepareSign.js";
33
+ import { formatSign, type FormatSignParams } from "./actions/formatSign.js";
28
34
 
29
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
30
36
  type ClientParams = {
@@ -32,6 +38,7 @@ type ClientParams = {
32
38
  transport: Transport;
33
39
  policyId?: string;
34
40
  useErc7677middleware?: boolean;
41
+ feeEstimator?: ClientMiddlewareFn;
35
42
  };
36
43
 
37
44
  export function isomorphicClientActions(
@@ -51,6 +58,8 @@ export function isomorphicClientActions(
51
58
  getCallsStatus(client, params),
52
59
  createSession: (params: CreateSessionParams) =>
53
60
  createSession(client, params),
61
+ prepareSign: (params: PrepareSignParams) => prepareSign(client, params),
62
+ formatSign: (params: FormatSignParams) => formatSign(client, params),
54
63
  };
55
64
  }
56
65
 
@@ -61,6 +70,7 @@ export function createIsomorphicClient({
61
70
  transport,
62
71
  policyId,
63
72
  useErc7677middleware = true,
73
+ feeEstimator,
64
74
  }: ClientParams): SmartAccountClient<
65
75
  Transport,
66
76
  Chain,
@@ -73,7 +83,8 @@ export function createIsomorphicClient({
73
83
  transport,
74
84
  chain,
75
85
  // TODO: we will want to enforce alchemy transport here probably
76
- feeEstimator: alchemyFeeEstimator(transport as AlchemyTransport),
86
+ feeEstimator:
87
+ feeEstimator ?? alchemyFeeEstimator(transport as AlchemyTransport),
77
88
  ...(policyId
78
89
  ? useErc7677middleware
79
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
+ };