@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,50 +1,53 @@
1
- import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
1
+ import {
2
+ type SmartAccountSigner,
3
+ type SmartContractAccount,
4
+ } from "@aa-sdk/core";
2
5
  import type { Static } from "@sinclair/typebox";
3
6
  import { Value } from "@sinclair/typebox/value";
4
7
  import type { Address } from "abitype";
5
- import { custom, type IsUndefined, type JsonRpcAccount } from "viem";
8
+ import deepEqual from "deep-equal";
9
+ import { custom } from "viem";
6
10
  import { createAccount } from "../../isomorphic/utils/createAccount.js";
7
- import type { wallet_requestAccount } from "../../rpc/request.js";
8
- import { TypeSerializedInitcode } from "../../schemas.js";
11
+ import type { wallet_requestAccount } from "@alchemy/wallet-api-types/rpc";
12
+ import { SerializedInitcode } from "@alchemy/wallet-api-types";
9
13
  import type { InnerWalletApiClient } from "../../types.js";
10
14
 
11
- export type RequestAccountParams<
12
- TAccount extends JsonRpcAccount<Address> | undefined =
13
- | JsonRpcAccount<Address>
14
- | undefined,
15
- > =
16
- IsUndefined<TAccount> extends true
17
- ? Omit<
18
- Extract<
19
- Static<typeof wallet_requestAccount>["Request"]["params"][0],
20
- { signerAddress: Address }
21
- >,
22
- "signerAddress" | "includeCounterfactualInfo"
23
- >
24
- : never;
15
+ export type RequestAccountParams = Omit<
16
+ Extract<
17
+ Static<typeof wallet_requestAccount>["Request"]["params"][0],
18
+ { signerAddress: Address }
19
+ >,
20
+ "signerAddress" | "includeCounterfactualInfo"
21
+ > & { accountAddress?: Address };
25
22
 
26
- // TODO: this could be more specific potentially :shrug:
27
23
  export type RequestAccountResult = SmartContractAccount;
28
24
 
29
- export function requestAccount<
30
- TAccount extends JsonRpcAccount<Address> | undefined =
31
- | JsonRpcAccount<Address>
32
- | undefined,
33
- >(
34
- client: InnerWalletApiClient<TAccount>,
35
- signer: SmartAccountSigner,
36
- params?: RequestAccountParams<TAccount>,
37
- ): Promise<RequestAccountResult>;
38
-
25
+ /**
26
+ * Requests an account for the provided signer using the wallet API client.
27
+ * If an account already exists for the signer, it will always return that account unless a new ID is specified.
28
+ * If an account already exists, the creationHint will be ignored.
29
+ *
30
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
31
+ * @param {SmartAccountSigner} signer - The signer that will be associated with the account
32
+ * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
33
+ * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer
34
+ * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
35
+ * @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
36
+ *
37
+ * @example
38
+ * // Request an account with default parameters using a local signer
39
+ * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
40
+ * const account = await client.requestAccount(signer);
41
+ */
39
42
  export async function requestAccount(
40
43
  client: InnerWalletApiClient,
41
44
  signer: SmartAccountSigner,
42
45
  params?: RequestAccountParams,
43
46
  ): Promise<RequestAccountResult> {
44
47
  const args =
45
- client.account && !params
48
+ (client.account && !params) || params?.accountAddress
46
49
  ? {
47
- accountAddress: client.account.address,
50
+ accountAddress: params?.accountAddress ?? client.account!.address,
48
51
  includeCounterfactualInfo: true,
49
52
  }
50
53
  : {
@@ -53,19 +56,35 @@ export async function requestAccount(
53
56
  includeCounterfactualInfo: true,
54
57
  };
55
58
 
56
- const { counterfactualInfo, accountAddress } = await client.request({
57
- method: "wallet_requestAccount",
58
- params: [args],
59
- });
59
+ const cachedAccount = client.internal.getAccount();
60
+
61
+ if (
62
+ cachedAccount &&
63
+ ((args.accountAddress &&
64
+ cachedAccount.account.address === args.accountAddress) ||
65
+ deepEqual(cachedAccount.requestParams, args, { strict: true }))
66
+ ) {
67
+ return cachedAccount.account;
68
+ }
60
69
 
61
- return createAccount({
62
- accountAddress: accountAddress,
63
- counterfactualInfo: Value.Parse(
64
- TypeSerializedInitcode,
65
- counterfactualInfo!,
66
- ),
70
+ const { accountAddress, counterfactualInfo, delegation } =
71
+ await client.request({
72
+ method: "wallet_requestAccount",
73
+ params: [args],
74
+ });
75
+
76
+ const account = await createAccount({
77
+ accountAddress,
78
+ counterfactualInfo: counterfactualInfo
79
+ ? Value.Parse(SerializedInitcode, counterfactualInfo)
80
+ : undefined,
81
+ delegation,
67
82
  chain: client.chain,
68
83
  transport: custom(client.transport),
69
84
  signer,
70
85
  });
86
+
87
+ client.internal.setAccount({ account, requestParams: args });
88
+
89
+ return account;
71
90
  }
@@ -1,23 +1,60 @@
1
- import type { Static, StaticDecode } from "@sinclair/typebox";
1
+ import type { Static } from "@sinclair/typebox";
2
2
  import { toHex } from "viem";
3
- import type { wallet_sendPreparedCalls } from "../../rpc/request";
4
- import type { InnerWalletApiClient } from "../../types";
3
+ import type { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
4
+ import type { InnerWalletApiClient, WithoutChainId } from "../../types.ts";
5
5
 
6
- export type SendPreparedCallsParams = Omit<
7
- StaticDecode<typeof wallet_sendPreparedCalls>["Request"]["params"][0],
8
- "chainId"
6
+ export type SendPreparedCallsParams = WithoutChainId<
7
+ Static<
8
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
9
+ >[0]
9
10
  >;
10
11
 
11
12
  export type SendPreparedCallsResult = Static<
12
13
  typeof wallet_sendPreparedCalls
13
14
  >["ReturnType"];
14
15
 
16
+ /**
17
+ * Sends prepared calls by submitting a signed user operation.
18
+ * This method is used after signing the signature request returned from prepareCalls.
19
+ *
20
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
21
+ * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
22
+ * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
23
+ *
24
+ * @example
25
+ * // First prepare the calls
26
+ * const preparedCalls = await client.prepareCalls({
27
+ * calls: [{
28
+ * to: "0x1234...",
29
+ * data: "0xabcdef...",
30
+ * value: "0x0"
31
+ * }],
32
+ * capabilities: {
33
+ * paymasterService: { policyId: "your-policy-id" }
34
+ * }
35
+ * });
36
+ *
37
+ * // Then sign the calls
38
+ * const signedCalls = await client.signPreparedCalls(preparedCalls);
39
+ *
40
+ * // Then send the prepared calls with the signature
41
+ * const result = await client.sendPreparedCalls({
42
+ * signedCalls,
43
+ * });
44
+ */
15
45
  export async function sendPreparedCalls(
16
46
  client: InnerWalletApiClient,
17
47
  params: SendPreparedCallsParams,
18
48
  ): Promise<SendPreparedCallsResult> {
19
49
  return client.request({
20
50
  method: "wallet_sendPreparedCalls",
21
- params: [{ ...params, chainId: toHex(client.chain.id) }],
51
+ params: [
52
+ params.type === "array"
53
+ ? params
54
+ : {
55
+ ...params,
56
+ chainId: toHex(client.chain.id),
57
+ },
58
+ ],
22
59
  });
23
60
  }
@@ -1,32 +1,37 @@
1
- import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import {
3
- type Address,
4
- type Hex,
5
- type JsonRpcAccount,
6
- type SignableMessage,
7
- } from "viem";
8
- import type { InnerWalletApiClient } from "../../types";
1
+ import { type SmartAccountSigner } from "@aa-sdk/core";
2
+ import { type Address, type Hex, type SignableMessage } from "viem";
3
+ import type { InnerWalletApiClient } from "../../types.ts";
9
4
  import { requestAccount } from "./requestAccount.js";
10
5
 
11
- export type SignMessageParams = SignableMessage;
6
+ export type SignMessageParams = { message: SignableMessage; account?: Address };
12
7
 
13
8
  export type SignMessageResult = Hex;
14
9
 
15
- export async function signMessage<
16
- TAccount extends JsonRpcAccount<Address> | undefined =
17
- | JsonRpcAccount<Address>
18
- | undefined,
19
- >(
20
- client: InnerWalletApiClient<TAccount>,
21
- signer: SmartAccountSigner,
22
- params: SignMessageParams,
23
- ): Promise<SignMessageResult>;
24
-
10
+ /**
11
+ * Signs a message using the smart account.
12
+ * This method requests the account associated with the signer and uses it to sign the message.
13
+ *
14
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
15
+ * @param {SmartAccountSigner} signer - The signer of the smart account
16
+ * @param {SignableMessage} message - The message to sign
17
+ * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
18
+ *
19
+ * @example
20
+ * // Sign a simple text message
21
+ * const signature = await client.signMessage("Hello, world!");
22
+ *
23
+ * @example
24
+ * // Sign a raw hex message
25
+ * const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
26
+ */
25
27
  export async function signMessage(
26
28
  client: InnerWalletApiClient,
27
29
  signer: SmartAccountSigner,
28
30
  params: SignMessageParams,
29
31
  ): Promise<SignMessageResult> {
30
- const account = await requestAccount(client, signer);
31
- return account.signMessageWith6492({ message: params });
32
+ const account = await requestAccount(client, signer, {
33
+ accountAddress: params.account ?? client.account?.address,
34
+ });
35
+
36
+ return account.signMessageWith6492({ message: params.message });
32
37
  }
@@ -0,0 +1,67 @@
1
+ import type { PrepareCallsResult } from "./prepareCalls.ts";
2
+ import type { SmartAccountSigner } from "@aa-sdk/core";
3
+ import { signSignatureRequest } from "./signSignatureRequest.js";
4
+ import type { Static } from "@sinclair/typebox";
5
+ import { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
6
+ import {
7
+ type PreparedCall_Authorization,
8
+ type PreparedCall_UserOpV060,
9
+ type PreparedCall_UserOpV070,
10
+ } from "@alchemy/wallet-api-types";
11
+
12
+ export type SignPreparedCallsParams = PrepareCallsResult;
13
+
14
+ export type SignPreparedCallsResult = Static<
15
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
16
+ >[0];
17
+
18
+ /**
19
+ * Signs prepared calls using the provided signer.
20
+ *
21
+ * @param {SmartAccountSigner} signer - The signer to use
22
+ * @param {SignPreparedCallsParams} params - The prepared calls with signature requests
23
+ * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
24
+ **/
25
+ export async function signPreparedCalls(
26
+ signer: SmartAccountSigner,
27
+ params: SignPreparedCallsParams,
28
+ ): Promise<SignPreparedCallsResult> {
29
+ const signAuthorizationCall = async (call: PreparedCall_Authorization) => {
30
+ const { signatureRequest: _signatureRequest, ...rest } = call;
31
+ const signature = await signSignatureRequest(signer, {
32
+ type: "eip7702Auth",
33
+ data: {
34
+ ...rest.data,
35
+ chainId: call.chainId,
36
+ },
37
+ });
38
+ return {
39
+ ...rest,
40
+ signature,
41
+ };
42
+ };
43
+
44
+ const signUserOperationCall = async (
45
+ call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,
46
+ ) => {
47
+ const { signatureRequest, ...rest } = call;
48
+ const signature = await signSignatureRequest(signer, signatureRequest);
49
+ return {
50
+ ...rest,
51
+ signature,
52
+ };
53
+ };
54
+
55
+ return params.type === "array"
56
+ ? {
57
+ type: "array" as const,
58
+ data: await Promise.all(
59
+ params.data.map((call) =>
60
+ call.type === "authorization"
61
+ ? signAuthorizationCall(call)
62
+ : signUserOperationCall(call),
63
+ ),
64
+ ),
65
+ }
66
+ : signUserOperationCall(params);
67
+ }
@@ -1,34 +1,98 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import type { Static } from "@sinclair/typebox";
3
- import { type Hex } from "viem";
4
- import { TypeSignatureRequest } from "../../schemas.js";
2
+ import { type Hex, hexToNumber, serializeSignature } from "viem";
5
3
  import { assertNever } from "../../utils.js";
4
+ import {
5
+ type PersonalSignSignatureRequest,
6
+ type TypedDataSignatureRequest,
7
+ type AuthorizationSignatureRequest,
8
+ type Eip7702UnsignedAuth,
9
+ } from "@alchemy/wallet-api-types";
10
+ import { vToYParity } from "ox/Signature";
11
+ import type { WithoutRawPayload } from "../../types.ts";
6
12
 
7
- export type SignSignatureRequestParams = Static<typeof TypeSignatureRequest>;
13
+ export type SignSignatureRequestParams = WithoutRawPayload<
14
+ | PersonalSignSignatureRequest
15
+ | TypedDataSignatureRequest
16
+ | (AuthorizationSignatureRequest & {
17
+ data: Eip7702UnsignedAuth;
18
+ })
19
+ >;
8
20
 
9
21
  export type SignSignatureRequestResult = {
10
- type: "ecdsa";
11
- signature: Hex;
22
+ type: "secp256k1";
23
+ data: Hex;
12
24
  };
13
25
 
14
- export function signSignatureRequest(
15
- signer: SmartAccountSigner,
16
- params: SignSignatureRequestParams,
17
- ): Promise<SignSignatureRequestResult>;
26
+ /**
27
+ * Signs a signature request using the provided signer.
28
+ * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
29
+ *
30
+ * @param {SmartAccountSigner} signer - The signer to use for signing the request
31
+ * @param {SignSignatureRequestParams} params - The signature request parameters
32
+ * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
33
+ * @param {any} params.data - The data to sign, format depends on the signature type
34
+ * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
35
+ * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)
36
+ * @returns {Hex} result.signature - The hex-encoded signature
37
+ * @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
38
+ *
39
+ * @example
40
+ * // Sign a personal message
41
+ * const result = await client.signSignatureRequest({
42
+ * type: 'personal_sign',
43
+ * data: 'Hello, world!'
44
+ * });
45
+ *
46
+ * @example
47
+ * // Sign typed data (EIP-712)
48
+ * const result = await client.signSignatureRequest({
49
+ * type: 'eth_signTypedData_v4',
50
+ * data: {
51
+ * domain: { ... },
52
+ * types: { ... },
53
+ * primaryType: '...',
54
+ * message: { ... }
55
+ * }
56
+ * });
57
+ */
18
58
 
19
59
  export async function signSignatureRequest(
20
60
  signer: SmartAccountSigner,
21
61
  params: SignSignatureRequestParams,
22
62
  ): Promise<SignSignatureRequestResult> {
23
- const signature =
24
- params.type === "personal_sign"
25
- ? await signer.signMessage(params.data)
26
- : params.type === "eth_signTypedData_v4"
27
- ? await signer.signTypedData(params.data)
28
- : assertNever(params, "Unexpected signature request type");
63
+ switch (params.type) {
64
+ case "personal_sign": {
65
+ return {
66
+ type: "secp256k1",
67
+ data: await signer.signMessage(params.data),
68
+ };
69
+ }
70
+ case "eth_signTypedData_v4": {
71
+ return {
72
+ type: "secp256k1",
73
+ data: await signer.signTypedData(params.data),
74
+ };
75
+ }
76
+ case "eip7702Auth": {
77
+ if (!signer.signAuthorization) {
78
+ throw new Error("Signer does not implement signAuthorization");
79
+ }
80
+ const { r, s, v, yParity } = await signer.signAuthorization({
81
+ ...params.data,
82
+ chainId: hexToNumber(params.data.chainId),
83
+ nonce: hexToNumber(params.data.nonce),
84
+ });
29
85
 
30
- return {
31
- type: "ecdsa",
32
- signature,
33
- };
86
+ return {
87
+ type: "secp256k1",
88
+ data: serializeSignature({
89
+ r,
90
+ s,
91
+ yParity: yParity ?? vToYParity(Number(v)),
92
+ }),
93
+ };
94
+ }
95
+ default:
96
+ return assertNever(params, `Unexpected signature request type.`);
97
+ }
34
98
  }
@@ -1,32 +1,53 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import {
3
- type Address,
4
- type Hex,
5
- type JsonRpcAccount,
6
- type TypedDataDefinition,
7
- } from "viem";
8
- import type { InnerWalletApiClient } from "../../types";
2
+ import { type Address, type Hex, type TypedDataDefinition } from "viem";
3
+ import type { InnerWalletApiClient } from "../../types.ts";
9
4
  import { requestAccount } from "./requestAccount.js";
10
5
 
11
- export type SignTypedDataParams = TypedDataDefinition;
6
+ export type SignTypedDataParams = TypedDataDefinition & {
7
+ account?: Address;
8
+ };
12
9
 
13
10
  export type SignTypedDataResult = Hex;
14
11
 
15
- export async function signTypedData<
16
- TAccount extends JsonRpcAccount<Address> | undefined =
17
- | JsonRpcAccount<Address>
18
- | undefined,
19
- >(
20
- client: InnerWalletApiClient<TAccount>,
21
- signer: SmartAccountSigner,
22
- params: SignTypedDataParams,
23
- ): Promise<SignTypedDataResult>;
24
-
12
+ /**
13
+ * Signs typed data (EIP-712) using the smart account.
14
+ * This method requests the account associated with the signer and uses it to sign the typed data.
15
+ *
16
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
17
+ * @param {SmartAccountSigner} signer - The signer of the smart account
18
+ * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
19
+ * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
20
+ *
21
+ * @example
22
+ * // Sign typed data
23
+ * const signature = await client.signTypedData({
24
+ * domain: {
25
+ * name: 'Example DApp',
26
+ * version: '1',
27
+ * chainId: 1,
28
+ * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
29
+ * },
30
+ * types: {
31
+ * Person: [
32
+ * { name: 'name', type: 'string' },
33
+ * { name: 'wallet', type: 'address' }
34
+ * ]
35
+ * },
36
+ * primaryType: 'Person',
37
+ * message: {
38
+ * name: 'John Doe',
39
+ * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'
40
+ * }
41
+ * });
42
+ */
25
43
  export async function signTypedData(
26
44
  client: InnerWalletApiClient,
27
45
  signer: SmartAccountSigner,
28
46
  params: SignTypedDataParams,
29
47
  ): Promise<SignTypedDataResult> {
30
- const account = await requestAccount(client, signer);
48
+ const account = await requestAccount(client, signer, {
49
+ accountAddress: params.account ?? client.account?.address,
50
+ });
51
+
31
52
  return account.signTypedDataWith6492(params);
32
53
  }