@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
@@ -0,0 +1,28 @@
1
+ import { toHex } from "viem";
2
+ import { AccountNotFoundError } from "@aa-sdk/core";
3
+ /**
4
+ * Prepares a signature request for signing messages or transactions.
5
+ *
6
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
7
+ * @param {PrepareSignParams} params - Parameters for preparing the signature request
8
+ * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request
9
+ *
10
+ * @example
11
+ * // Prepare a message to be signed
12
+ * const result = await client.prepareSign({
13
+ * from: "0x1234...",
14
+ * type: "personal_sign",
15
+ * data: "Hello, world!",
16
+ * });
17
+ */
18
+ export async function prepareSign(client, params) {
19
+ const from = params.from ?? client.account?.address;
20
+ if (!from) {
21
+ throw new AccountNotFoundError();
22
+ }
23
+ return client.request({
24
+ method: "wallet_prepareSign",
25
+ params: [{ ...params, from, chainId: toHex(client.chain.id) }],
26
+ });
27
+ }
28
+ //# sourceMappingURL=prepareSign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../../src/client/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAkC,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AASpD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAG/B,MAA4B,EAC5B,MAAmC;IAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC;QACpB,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;KAC/D,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InnerWalletApiClient } from \"../../types.ts\";\nimport { toHex, type Address, type IsUndefined } from \"viem\";\nimport type {\n PrepareSignParams as IsomorphicPrepareSignParams,\n PrepareSignResult as IsomorphicPrepareSignResult,\n} from \"../../isomorphic/actions/prepareSign.ts\";\nimport { AccountNotFoundError } from \"@aa-sdk/core\";\n\nexport type PrepareSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Omit<IsomorphicPrepareSignParams, \"from\" | \"chainId\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });\n\nexport type PrepareSignResult = IsomorphicPrepareSignResult;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * from: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n */\nexport async function prepareSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareSignParams<TAccount>,\n): Promise<PrepareSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n return client.request({\n method: \"wallet_prepareSign\",\n params: [{ ...params, from, chainId: toHex(client.chain.id) }],\n });\n}\n"]}
@@ -1,11 +1,29 @@
1
- import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
1
+ import { type SmartAccountSigner, type SmartContractAccount } from "@aa-sdk/core";
2
2
  import type { Static } from "@sinclair/typebox";
3
3
  import type { Address } from "abitype";
4
- import { type IsUndefined, type JsonRpcAccount } from "viem";
5
- import type { wallet_requestAccount } from "../../rpc/request.js";
4
+ import type { wallet_requestAccount } from "@alchemy/wallet-api-types/rpc";
6
5
  import type { InnerWalletApiClient } from "../../types.js";
7
- export type RequestAccountParams<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined> = IsUndefined<TAccount> extends true ? Omit<Extract<Static<typeof wallet_requestAccount>["Request"]["params"][0], {
6
+ export type RequestAccountParams = Omit<Extract<Static<typeof wallet_requestAccount>["Request"]["params"][0], {
8
7
  signerAddress: Address;
9
- }>, "signerAddress" | "includeCounterfactualInfo"> : never;
8
+ }>, "signerAddress" | "includeCounterfactualInfo"> & {
9
+ accountAddress?: Address;
10
+ };
10
11
  export type RequestAccountResult = SmartContractAccount;
11
- export declare function requestAccount<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(client: InnerWalletApiClient<TAccount>, signer: SmartAccountSigner, params?: RequestAccountParams<TAccount>): Promise<RequestAccountResult>;
12
+ /**
13
+ * Requests an account for the provided signer using the wallet API client.
14
+ * If an account already exists for the signer, it will always return that account unless a new ID is specified.
15
+ * If an account already exists, the creationHint will be ignored.
16
+ *
17
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
18
+ * @param {SmartAccountSigner} signer - The signer that will be associated with the account
19
+ * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
20
+ * @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
21
+ * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
22
+ * @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
23
+ *
24
+ * @example
25
+ * // Request an account with default parameters using a local signer
26
+ * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
27
+ * const account = await client.requestAccount(signer);
28
+ */
29
+ export declare function requestAccount(client: InnerWalletApiClient, signer: SmartAccountSigner, params?: RequestAccountParams): Promise<RequestAccountResult>;
@@ -1,11 +1,30 @@
1
+ import {} from "@aa-sdk/core";
1
2
  import { Value } from "@sinclair/typebox/value";
3
+ import deepEqual from "deep-equal";
2
4
  import { custom } from "viem";
3
5
  import { createAccount } from "../../isomorphic/utils/createAccount.js";
4
- import { TypeSerializedInitcode } from "../../schemas.js";
6
+ import { TypeSerializedInitcode } from "@alchemy/wallet-api-types";
7
+ /**
8
+ * Requests an account for the provided signer using the wallet API client.
9
+ * If an account already exists for the signer, it will always return that account unless a new ID is specified.
10
+ * If an account already exists, the creationHint will be ignored.
11
+ *
12
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
13
+ * @param {SmartAccountSigner} signer - The signer that will be associated with the account
14
+ * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
15
+ * @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
16
+ * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
17
+ * @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
18
+ *
19
+ * @example
20
+ * // Request an account with default parameters using a local signer
21
+ * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
22
+ * const account = await client.requestAccount(signer);
23
+ */
5
24
  export async function requestAccount(client, signer, params) {
6
- const args = client.account && !params
25
+ const args = (client.account && !params) || params?.accountAddress
7
26
  ? {
8
- accountAddress: client.account.address,
27
+ accountAddress: params?.accountAddress ?? client.account.address,
9
28
  includeCounterfactualInfo: true,
10
29
  }
11
30
  : {
@@ -13,16 +32,28 @@ export async function requestAccount(client, signer, params) {
13
32
  signerAddress: await signer.getAddress(),
14
33
  includeCounterfactualInfo: true,
15
34
  };
16
- const { counterfactualInfo, accountAddress } = await client.request({
35
+ const cachedAccount = client.internal.getAccount();
36
+ if (cachedAccount &&
37
+ ((args.accountAddress &&
38
+ cachedAccount.account.address === args.accountAddress) ||
39
+ deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
40
+ return cachedAccount.account;
41
+ }
42
+ const { accountAddress, counterfactualInfo, delegation } = await client.request({
17
43
  method: "wallet_requestAccount",
18
44
  params: [args],
19
45
  });
20
- return createAccount({
21
- accountAddress: accountAddress,
22
- counterfactualInfo: Value.Parse(TypeSerializedInitcode, counterfactualInfo),
46
+ const account = await createAccount({
47
+ accountAddress,
48
+ counterfactualInfo: counterfactualInfo
49
+ ? Value.Parse(TypeSerializedInitcode, counterfactualInfo)
50
+ : undefined,
51
+ delegation,
23
52
  chain: client.chain,
24
53
  transport: custom(client.transport),
25
54
  signer,
26
55
  });
56
+ client.internal.setAccount({ account, requestParams: args });
57
+ return account;
27
58
  }
28
59
  //# sourceMappingURL=requestAccount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../../src/client/actions/requestAccount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AA+B1D,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA0B,EAC1B,MAA6B;IAE7B,MAAM,IAAI,GACR,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM;QACvB,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;YACtC,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa,EAAE,MAAM,MAAM,CAAC,UAAU,EAAE;YACxC,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAClE,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC;QACnB,cAAc,EAAE,cAAc;QAC9B,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAC7B,sBAAsB,EACtB,kBAAmB,CACpB;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM;KACP,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport type { Address } from \"abitype\";\nimport { custom, type IsUndefined, type JsonRpcAccount } from \"viem\";\nimport { createAccount } from \"../../isomorphic/utils/createAccount.js\";\nimport type { wallet_requestAccount } from \"../../rpc/request.js\";\nimport { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { InnerWalletApiClient } from \"../../types.js\";\n\nexport type RequestAccountParams<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n> =\n IsUndefined<TAccount> extends true\n ? Omit<\n Extract<\n Static<typeof wallet_requestAccount>[\"Request\"][\"params\"][0],\n { signerAddress: Address }\n >,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n >\n : never;\n\n// TODO: this could be more specific potentially :shrug:\nexport type RequestAccountResult = SmartContractAccount;\n\nexport function requestAccount<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(\n client: InnerWalletApiClient<TAccount>,\n signer: SmartAccountSigner,\n params?: RequestAccountParams<TAccount>,\n): Promise<RequestAccountResult>;\n\nexport async function requestAccount(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n const args =\n client.account && !params\n ? {\n accountAddress: client.account.address,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress: await signer.getAddress(),\n includeCounterfactualInfo: true,\n };\n\n const { counterfactualInfo, accountAddress } = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n return createAccount({\n accountAddress: accountAddress,\n counterfactualInfo: Value.Parse(\n TypeSerializedInitcode,\n counterfactualInfo!,\n ),\n chain: client.chain,\n transport: custom(client.transport),\n signer,\n });\n}\n"]}
1
+ {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../../src/client/actions/requestAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAanE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA0B,EAC1B,MAA6B;IAE7B,MAAM,IAAI,GACR,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,cAAc;QACnD,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,MAAM,CAAC,OAAQ,CAAC,OAAO;YACjE,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa,EAAE,MAAM,MAAM,CAAC,UAAU,EAAE;YACxC,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAEnD,IACE,aAAa;QACb,CAAC,CAAC,IAAI,CAAC,cAAc;YACnB,aAAa,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,cAAc,CAAC;YACtD,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,OAAO,aAAa,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,GACtD,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEL,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;QAClC,cAAc;QACd,kBAAkB,EAAE,kBAAkB;YACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,sBAAsB,EAAE,kBAAkB,CAAC;YACzD,CAAC,CAAC,SAAS;QACb,UAAU;QACV,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM;KACP,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n type SmartAccountSigner,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport type { Address } from \"abitype\";\nimport deepEqual from \"deep-equal\";\nimport { custom } from \"viem\";\nimport { createAccount } from \"../../isomorphic/utils/createAccount.js\";\nimport type { wallet_requestAccount } from \"@alchemy/wallet-api-types/rpc\";\nimport { TypeSerializedInitcode } from \"@alchemy/wallet-api-types\";\nimport type { InnerWalletApiClient } from \"../../types.js\";\n\nexport type RequestAccountParams = Omit<\n Extract<\n Static<typeof wallet_requestAccount>[\"Request\"][\"params\"][0],\n { signerAddress: Address }\n >,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n> & { accountAddress?: Address };\n\nexport type RequestAccountResult = SmartContractAccount;\n\n/**\n * Requests an account for the provided signer using the wallet API client.\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner} signer - The signer that will be associated with the account\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @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\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance\n *\n * @example\n * // Request an account with default parameters using a local signer\n * const signer = LocalAccountSigner.privateKeyToAccountSigner(\"0x...\");\n * const account = await client.requestAccount(signer);\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n const args =\n (client.account && !params) || params?.accountAddress\n ? {\n accountAddress: params?.accountAddress ?? client.account!.address,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress: await signer.getAddress(),\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n cachedAccount.account.address === args.accountAddress) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n return cachedAccount.account;\n }\n\n const { accountAddress, counterfactualInfo, delegation } =\n await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n const account = await createAccount({\n accountAddress,\n counterfactualInfo: counterfactualInfo\n ? Value.Parse(TypeSerializedInitcode, counterfactualInfo)\n : undefined,\n delegation,\n chain: client.chain,\n transport: custom(client.transport),\n signer,\n });\n\n client.internal.setAccount({ account, requestParams: args });\n\n return account;\n}\n"]}
@@ -1,6 +1,35 @@
1
- import type { Static, StaticDecode } from "@sinclair/typebox";
2
- import type { wallet_sendPreparedCalls } from "../../rpc/request";
3
- import type { InnerWalletApiClient } from "../../types";
4
- export type SendPreparedCallsParams = Omit<StaticDecode<typeof wallet_sendPreparedCalls>["Request"]["params"][0], "chainId">;
1
+ import type { Static } from "@sinclair/typebox";
2
+ import type { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
3
+ import type { InnerWalletApiClient, WithoutChainId } from "../../types.ts";
4
+ export type SendPreparedCallsParams = WithoutChainId<Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0]>;
5
5
  export type SendPreparedCallsResult = Static<typeof wallet_sendPreparedCalls>["ReturnType"];
6
+ /**
7
+ * Sends prepared calls by submitting a signed user operation.
8
+ * This method is used after signing the signature request returned from prepareCalls.
9
+ *
10
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
11
+ * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
12
+ * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
13
+ *
14
+ * @example
15
+ * // First prepare the calls
16
+ * const preparedCalls = await client.prepareCalls({
17
+ * calls: [{
18
+ * to: "0x1234...",
19
+ * data: "0xabcdef...",
20
+ * value: "0x0"
21
+ * }],
22
+ * capabilities: {
23
+ * paymasterService: { policyId: "your-policy-id" }
24
+ * }
25
+ * });
26
+ *
27
+ * // Then sign the calls
28
+ * const signedCalls = await client.signPreparedCalls(preparedCalls);
29
+ *
30
+ * // Then send the prepared calls with the signature
31
+ * const result = await client.sendPreparedCalls({
32
+ * signedCalls,
33
+ * });
34
+ */
6
35
  export declare function sendPreparedCalls(client: InnerWalletApiClient, params: SendPreparedCallsParams): Promise<SendPreparedCallsResult>;
@@ -1,8 +1,44 @@
1
1
  import { toHex } from "viem";
2
+ /**
3
+ * Sends prepared calls by submitting a signed user operation.
4
+ * This method is used after signing the signature request returned from prepareCalls.
5
+ *
6
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
7
+ * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
8
+ * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
9
+ *
10
+ * @example
11
+ * // First prepare the calls
12
+ * const preparedCalls = await client.prepareCalls({
13
+ * calls: [{
14
+ * to: "0x1234...",
15
+ * data: "0xabcdef...",
16
+ * value: "0x0"
17
+ * }],
18
+ * capabilities: {
19
+ * paymasterService: { policyId: "your-policy-id" }
20
+ * }
21
+ * });
22
+ *
23
+ * // Then sign the calls
24
+ * const signedCalls = await client.signPreparedCalls(preparedCalls);
25
+ *
26
+ * // Then send the prepared calls with the signature
27
+ * const result = await client.sendPreparedCalls({
28
+ * signedCalls,
29
+ * });
30
+ */
2
31
  export async function sendPreparedCalls(client, params) {
3
32
  return client.request({
4
33
  method: "wallet_sendPreparedCalls",
5
- params: [{ ...params, chainId: toHex(client.chain.id) }],
34
+ params: [
35
+ params.type === "array"
36
+ ? params
37
+ : {
38
+ ...params,
39
+ chainId: toHex(client.chain.id),
40
+ },
41
+ ],
6
42
  });
7
43
  }
8
44
  //# sourceMappingURL=sendPreparedCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAa7B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,MAA+B;IAE/B,OAAO,MAAM,CAAC,OAAO,CAAC;QACpB,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;KACzD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Static, StaticDecode } from \"@sinclair/typebox\";\nimport { toHex } from \"viem\";\nimport type { wallet_sendPreparedCalls } from \"../../rpc/request\";\nimport type { InnerWalletApiClient } from \"../../types\";\n\nexport type SendPreparedCallsParams = Omit<\n StaticDecode<typeof wallet_sendPreparedCalls>[\"Request\"][\"params\"][0],\n \"chainId\"\n>;\n\nexport type SendPreparedCallsResult = Static<\n typeof wallet_sendPreparedCalls\n>[\"ReturnType\"];\n\nexport async function sendPreparedCalls(\n client: InnerWalletApiClient,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n return client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [{ ...params, chainId: toHex(client.chain.id) }],\n });\n}\n"]}
1
+ {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAc7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,MAA+B;IAE/B,OAAO,MAAM,CAAC,OAAO,CAAC;QACpB,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE;YACN,MAAM,CAAC,IAAI,KAAK,OAAO;gBACrB,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC;oBACE,GAAG,MAAM;oBACT,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;iBAChC;SACN;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Static } from \"@sinclair/typebox\";\nimport { toHex } from \"viem\";\nimport type { wallet_sendPreparedCalls } from \"@alchemy/wallet-api-types/rpc\";\nimport type { InnerWalletApiClient, WithoutChainId } from \"../../types.ts\";\n\nexport type SendPreparedCallsParams = WithoutChainId<\n Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0]\n>;\n\nexport type SendPreparedCallsResult = Static<\n typeof wallet_sendPreparedCalls\n>[\"ReturnType\"];\n\n/**\n * Sends prepared calls by submitting a signed user operation.\n * This method is used after signing the signature request returned from prepareCalls.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls\n * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs\n *\n * @example\n * // First prepare the calls\n * const preparedCalls = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // Then sign the calls\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Then send the prepared calls with the signature\n * const result = await client.sendPreparedCalls({\n * signedCalls,\n * });\n */\nexport async function sendPreparedCalls(\n client: InnerWalletApiClient,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n return client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [\n params.type === \"array\"\n ? params\n : {\n ...params,\n chainId: toHex(client.chain.id),\n },\n ],\n });\n}\n"]}
@@ -1,6 +1,26 @@
1
- import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import { type Address, type Hex, type JsonRpcAccount, type SignableMessage } from "viem";
3
- import type { InnerWalletApiClient } from "../../types";
4
- export type SignMessageParams = SignableMessage;
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";
4
+ export type SignMessageParams = {
5
+ message: SignableMessage;
6
+ account?: Address;
7
+ };
5
8
  export type SignMessageResult = Hex;
6
- export declare function signMessage<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(client: InnerWalletApiClient<TAccount>, signer: SmartAccountSigner, params: SignMessageParams): Promise<SignMessageResult>;
9
+ /**
10
+ * Signs a message using the smart account.
11
+ * This method requests the account associated with the signer and uses it to sign the message.
12
+ *
13
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
+ * @param {SmartAccountSigner} signer - The signer of the smart account
15
+ * @param {SignableMessage} message - The message to sign
16
+ * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
17
+ *
18
+ * @example
19
+ * // Sign a simple text message
20
+ * const signature = await client.signMessage("Hello, world!");
21
+ *
22
+ * @example
23
+ * // Sign a raw hex message
24
+ * const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
25
+ */
26
+ export declare function signMessage(client: InnerWalletApiClient, signer: SmartAccountSigner, params: SignMessageParams): Promise<SignMessageResult>;
@@ -1,7 +1,27 @@
1
+ import {} from "@aa-sdk/core";
1
2
  import {} from "viem";
2
3
  import { requestAccount } from "./requestAccount.js";
4
+ /**
5
+ * Signs a message using the smart account.
6
+ * This method requests the account associated with the signer and uses it to sign the message.
7
+ *
8
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
9
+ * @param {SmartAccountSigner} signer - The signer of the smart account
10
+ * @param {SignableMessage} message - The message to sign
11
+ * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
12
+ *
13
+ * @example
14
+ * // Sign a simple text message
15
+ * const signature = await client.signMessage("Hello, world!");
16
+ *
17
+ * @example
18
+ * // Sign a raw hex message
19
+ * const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
20
+ */
3
21
  export async function signMessage(client, signer, params) {
4
- const account = await requestAccount(client, signer);
5
- return account.signMessageWith6492({ message: params });
22
+ const account = await requestAccount(client, signer, {
23
+ accountAddress: params.account ?? client.account?.address,
24
+ });
25
+ return account.signMessageWith6492({ message: params.message });
6
26
  }
7
27
  //# sourceMappingURL=signMessage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../../src/client/actions/signMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAKN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAgBrD,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAA0B,EAC1B,MAAyB;IAEzB,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,OAAO,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n type Address,\n type Hex,\n type JsonRpcAccount,\n type SignableMessage,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../../types\";\nimport { requestAccount } from \"./requestAccount.js\";\n\nexport type SignMessageParams = SignableMessage;\n\nexport type SignMessageResult = Hex;\n\nexport async function signMessage<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(\n client: InnerWalletApiClient<TAccount>,\n signer: SmartAccountSigner,\n params: SignMessageParams,\n): Promise<SignMessageResult>;\n\nexport async function signMessage(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const account = await requestAccount(client, signer);\n return account.signMessageWith6492({ message: params });\n}\n"]}
1
+ {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../../src/client/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,cAAc,CAAC;AACvD,OAAO,EAAgD,MAAM,MAAM,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAA0B,EAC1B,MAAyB;IAEzB,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE;QACnD,cAAc,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO;KAC1D,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { type SmartAccountSigner } from \"@aa-sdk/core\";\nimport { type Address, type Hex, type SignableMessage } from \"viem\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\nimport { requestAccount } from \"./requestAccount.js\";\n\nexport type SignMessageParams = { message: SignableMessage; account?: Address };\n\nexport type SignMessageResult = Hex;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner} signer - The signer of the smart account\n * @param {SignableMessage} message - The message to sign\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * @example\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const account = await requestAccount(client, signer, {\n accountAddress: params.account ?? client.account?.address,\n });\n\n return account.signMessageWith6492({ message: params.message });\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { PrepareCallsResult } from "./prepareCalls.ts";
2
+ import type { SmartAccountSigner } from "@aa-sdk/core";
3
+ import type { Static } from "@sinclair/typebox";
4
+ import { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
5
+ export type SignPreparedCallsParams = PrepareCallsResult;
6
+ export type SignPreparedCallsResult = Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0];
7
+ /**
8
+ * Signs prepared calls using the provided signer.
9
+ *
10
+ * @param {SmartAccountSigner} signer - The signer to use
11
+ * @param {SignPreparedCallsParams} params - The prepared calls with signature requests
12
+ * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
13
+ **/
14
+ export declare function signPreparedCalls(signer: SmartAccountSigner, params: SignPreparedCallsParams): Promise<SignPreparedCallsResult>;
@@ -0,0 +1,43 @@
1
+ import { signSignatureRequest } from "./signSignatureRequest.js";
2
+ import { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
3
+ import {} from "@alchemy/wallet-api-types";
4
+ /**
5
+ * Signs prepared calls using the provided signer.
6
+ *
7
+ * @param {SmartAccountSigner} signer - The signer to use
8
+ * @param {SignPreparedCallsParams} params - The prepared calls with signature requests
9
+ * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
10
+ **/
11
+ export async function signPreparedCalls(signer, params) {
12
+ const signAuthorizationCall = async (call) => {
13
+ const { signatureRequest: _signatureRequest, ...rest } = call;
14
+ const signature = await signSignatureRequest(signer, {
15
+ type: "eip7702Auth",
16
+ data: {
17
+ ...rest.data,
18
+ chainId: call.chainId,
19
+ },
20
+ });
21
+ return {
22
+ ...rest,
23
+ signature,
24
+ };
25
+ };
26
+ const signUserOperationCall = async (call) => {
27
+ const { signatureRequest, ...rest } = call;
28
+ const signature = await signSignatureRequest(signer, signatureRequest);
29
+ return {
30
+ ...rest,
31
+ signature,
32
+ };
33
+ };
34
+ return params.type === "array"
35
+ ? {
36
+ type: "array",
37
+ data: await Promise.all(params.data.map((call) => call.type === "authorization"
38
+ ? signAuthorizationCall(call)
39
+ : signUserOperationCall(call))),
40
+ }
41
+ : signUserOperationCall(params);
42
+ }
43
+ //# sourceMappingURL=signPreparedCalls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/signPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAIN,MAAM,2BAA2B,CAAC;AAQnC;;;;;;IAMI;AACJ,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA0B,EAC1B,MAA+B;IAE/B,MAAM,qBAAqB,GAAG,KAAK,EAAE,IAAgC,EAAE,EAAE;QACvE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE;YACnD,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE;gBACJ,GAAG,IAAI,CAAC,IAAI;gBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC,CAAC;QACH,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,KAAK,EACjC,IAAuD,EACvD,EAAE;QACF,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC3C,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACvE,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO;QAC5B,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CACrB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACvB,IAAI,CAAC,IAAI,KAAK,eAAe;gBAC3B,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;gBAC7B,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAChC,CACF;SACF;QACH,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { PrepareCallsResult } from \"./prepareCalls.ts\";\nimport type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { wallet_sendPreparedCalls } from \"@alchemy/wallet-api-types/rpc\";\nimport {\n type PreparedCall_Authorization,\n type PreparedCall_UserOpV060,\n type PreparedCall_UserOpV070,\n} from \"@alchemy/wallet-api-types\";\n\nexport type SignPreparedCallsParams = PrepareCallsResult;\n\nexport type SignPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\n/**\n * Signs prepared calls using the provided signer.\n *\n * @param {SmartAccountSigner} signer - The signer to use\n * @param {SignPreparedCallsParams} params - The prepared calls with signature requests\n * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls\n **/\nexport async function signPreparedCalls(\n signer: SmartAccountSigner,\n params: SignPreparedCallsParams,\n): Promise<SignPreparedCallsResult> {\n const signAuthorizationCall = async (call: PreparedCall_Authorization) => {\n const { signatureRequest: _signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(signer, {\n type: \"eip7702Auth\",\n data: {\n ...rest.data,\n chainId: call.chainId,\n },\n });\n return {\n ...rest,\n signature,\n };\n };\n\n const signUserOperationCall = async (\n call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,\n ) => {\n const { signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(signer, signatureRequest);\n return {\n ...rest,\n signature,\n };\n };\n\n return params.type === \"array\"\n ? {\n type: \"array\" as const,\n data: await Promise.all(\n params.data.map((call) =>\n call.type === \"authorization\"\n ? signAuthorizationCall(call)\n : signUserOperationCall(call),\n ),\n ),\n }\n : signUserOperationCall(params);\n}\n"]}
@@ -1,10 +1,44 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import type { Static } from "@sinclair/typebox";
3
2
  import { type Hex } from "viem";
4
- import { TypeSignatureRequest } from "../../schemas.js";
5
- export type SignSignatureRequestParams = Static<typeof TypeSignatureRequest>;
3
+ import { type TypePersonalSignSignatureRequest, type TypeTypedDataSignatureRequest, type TypeAuthorizationSignatureRequest, type TypeEip7702UnsignedAuth } from "@alchemy/wallet-api-types";
4
+ import type { WithoutRawPayload } from "../../types.ts";
5
+ export type SignSignatureRequestParams = WithoutRawPayload<TypePersonalSignSignatureRequest | TypeTypedDataSignatureRequest | (TypeAuthorizationSignatureRequest & {
6
+ data: TypeEip7702UnsignedAuth;
7
+ })>;
6
8
  export type SignSignatureRequestResult = {
7
- type: "ecdsa";
8
- signature: Hex;
9
+ type: "secp256k1";
10
+ data: Hex;
9
11
  };
12
+ /**
13
+ * Signs a signature request using the provided signer.
14
+ * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
15
+ *
16
+ * @param {SmartAccountSigner} signer - The signer to use for signing the request
17
+ * @param {SignSignatureRequestParams} params - The signature request parameters
18
+ * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
19
+ * @param {any} params.data - The data to sign, format depends on the signature type
20
+ * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
21
+ * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)
22
+ * @returns {Hex} result.signature - The hex-encoded signature
23
+ * @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
24
+ *
25
+ * @example
26
+ * // Sign a personal message
27
+ * const result = await client.signSignatureRequest({
28
+ * type: 'personal_sign',
29
+ * data: 'Hello, world!'
30
+ * });
31
+ *
32
+ * @example
33
+ * // Sign typed data (EIP-712)
34
+ * const result = await client.signSignatureRequest({
35
+ * type: 'eth_signTypedData_v4',
36
+ * data: {
37
+ * domain: { ... },
38
+ * types: { ... },
39
+ * primaryType: '...',
40
+ * message: { ... }
41
+ * }
42
+ * });
43
+ */
10
44
  export declare function signSignatureRequest(signer: SmartAccountSigner, params: SignSignatureRequestParams): Promise<SignSignatureRequestResult>;
@@ -1,15 +1,73 @@
1
- import {} from "viem";
2
- import { TypeSignatureRequest } from "../../schemas.js";
1
+ import { hexToNumber, serializeSignature } from "viem";
3
2
  import { assertNever } from "../../utils.js";
3
+ import {} from "@alchemy/wallet-api-types";
4
+ import { vToYParity } from "ox/Signature";
5
+ /**
6
+ * Signs a signature request using the provided signer.
7
+ * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
8
+ *
9
+ * @param {SmartAccountSigner} signer - The signer to use for signing the request
10
+ * @param {SignSignatureRequestParams} params - The signature request parameters
11
+ * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
12
+ * @param {any} params.data - The data to sign, format depends on the signature type
13
+ * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
14
+ * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)
15
+ * @returns {Hex} result.signature - The hex-encoded signature
16
+ * @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
17
+ *
18
+ * @example
19
+ * // Sign a personal message
20
+ * const result = await client.signSignatureRequest({
21
+ * type: 'personal_sign',
22
+ * data: 'Hello, world!'
23
+ * });
24
+ *
25
+ * @example
26
+ * // Sign typed data (EIP-712)
27
+ * const result = await client.signSignatureRequest({
28
+ * type: 'eth_signTypedData_v4',
29
+ * data: {
30
+ * domain: { ... },
31
+ * types: { ... },
32
+ * primaryType: '...',
33
+ * message: { ... }
34
+ * }
35
+ * });
36
+ */
4
37
  export async function signSignatureRequest(signer, params) {
5
- const signature = params.type === "personal_sign"
6
- ? await signer.signMessage(params.data)
7
- : params.type === "eth_signTypedData_v4"
8
- ? await signer.signTypedData(params.data)
9
- : assertNever(params, "Unexpected signature request type");
10
- return {
11
- type: "ecdsa",
12
- signature,
13
- };
38
+ switch (params.type) {
39
+ case "personal_sign": {
40
+ return {
41
+ type: "secp256k1",
42
+ data: await signer.signMessage(params.data),
43
+ };
44
+ }
45
+ case "eth_signTypedData_v4": {
46
+ return {
47
+ type: "secp256k1",
48
+ data: await signer.signTypedData(params.data),
49
+ };
50
+ }
51
+ case "eip7702Auth": {
52
+ if (!signer.signAuthorization) {
53
+ throw new Error("Signer does not implement signAuthorization");
54
+ }
55
+ const { r, s, v, yParity } = await signer.signAuthorization({
56
+ ...params.data,
57
+ chainId: hexToNumber(params.data.chainId),
58
+ nonce: hexToNumber(params.data.nonce),
59
+ });
60
+ return {
61
+ type: "secp256k1",
62
+ data: serializeSignature({
63
+ r,
64
+ s,
65
+ yParity: yParity ?? vToYParity(Number(v)),
66
+ }),
67
+ };
68
+ }
69
+ default:
70
+ return assertNever(params, `Unexpected signature request type.`);
71
+ }
14
72
  }
15
73
  //# sourceMappingURL=signSignatureRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAc7C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0B,EAC1B,MAAkC;IAElC,MAAM,SAAS,GACb,MAAM,CAAC,IAAI,KAAK,eAAe;QAC7B,CAAC,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,sBAAsB;YACtC,CAAC,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;YACzC,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAEjE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { type Hex } from \"viem\";\nimport { TypeSignatureRequest } from \"../../schemas.js\";\nimport { assertNever } from \"../../utils.js\";\n\nexport type SignSignatureRequestParams = Static<typeof TypeSignatureRequest>;\n\nexport type SignSignatureRequestResult = {\n type: \"ecdsa\";\n signature: Hex;\n};\n\nexport function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult>;\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n const signature =\n params.type === \"personal_sign\"\n ? await signer.signMessage(params.data)\n : params.type === \"eth_signTypedData_v4\"\n ? await signer.signTypedData(params.data)\n : assertNever(params, \"Unexpected signature request type\");\n\n return {\n type: \"ecdsa\",\n signature,\n };\n}\n"]}
1
+ {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAKN,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0B,EAC1B,MAAkC;IAElC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;aAC5C,CAAC;QACJ,CAAC;QACD,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC5B,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;aAC9C,CAAC;QACJ,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;gBAC1D,GAAG,MAAM,CAAC,IAAI;gBACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBACzC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtC,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO,EAAE,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAC1C,CAAC;aACH,CAAC;QACJ,CAAC;QACD;YACE,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { type Hex, hexToNumber, serializeSignature } from \"viem\";\nimport { assertNever } from \"../../utils.js\";\nimport {\n type TypePersonalSignSignatureRequest,\n type TypeTypedDataSignatureRequest,\n type TypeAuthorizationSignatureRequest,\n type TypeEip7702UnsignedAuth,\n} from \"@alchemy/wallet-api-types\";\nimport { vToYParity } from \"ox/Signature\";\nimport type { WithoutRawPayload } from \"../../types.ts\";\n\nexport type SignSignatureRequestParams = WithoutRawPayload<\n | TypePersonalSignSignatureRequest\n | TypeTypedDataSignatureRequest\n | (TypeAuthorizationSignatureRequest & {\n data: TypeEip7702UnsignedAuth;\n })\n>;\n\nexport type SignSignatureRequestResult = {\n type: \"secp256k1\";\n data: Hex;\n};\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {any} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)\n * @returns {Hex} result.signature - The hex-encoded signature\n * @returns {Eip7702ExtendedFields[\"eip7702Auth\"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable\n *\n * @example\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * @example\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n */\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n switch (params.type) {\n case \"personal_sign\": {\n return {\n type: \"secp256k1\",\n data: await signer.signMessage(params.data),\n };\n }\n case \"eth_signTypedData_v4\": {\n return {\n type: \"secp256k1\",\n data: await signer.signTypedData(params.data),\n };\n }\n case \"eip7702Auth\": {\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n const { r, s, v, yParity } = await signer.signAuthorization({\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n\n return {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity: yParity ?? vToYParity(Number(v)),\n }),\n };\n }\n default:\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
@@ -1,6 +1,39 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import { type Address, type Hex, type JsonRpcAccount, type TypedDataDefinition } from "viem";
3
- import type { InnerWalletApiClient } from "../../types";
4
- export type SignTypedDataParams = TypedDataDefinition;
2
+ import { type Address, type Hex, type TypedDataDefinition } from "viem";
3
+ import type { InnerWalletApiClient } from "../../types.ts";
4
+ export type SignTypedDataParams = TypedDataDefinition & {
5
+ account?: Address;
6
+ };
5
7
  export type SignTypedDataResult = Hex;
6
- export declare function signTypedData<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(client: InnerWalletApiClient<TAccount>, signer: SmartAccountSigner, params: SignTypedDataParams): Promise<SignTypedDataResult>;
8
+ /**
9
+ * Signs typed data (EIP-712) using the smart account.
10
+ * This method requests the account associated with the signer and uses it to sign the typed data.
11
+ *
12
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
13
+ * @param {SmartAccountSigner} signer - The signer of the smart account
14
+ * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
15
+ * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
16
+ *
17
+ * @example
18
+ * // Sign typed data
19
+ * const signature = await client.signTypedData({
20
+ * domain: {
21
+ * name: 'Example DApp',
22
+ * version: '1',
23
+ * chainId: 1,
24
+ * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
25
+ * },
26
+ * types: {
27
+ * Person: [
28
+ * { name: 'name', type: 'string' },
29
+ * { name: 'wallet', type: 'address' }
30
+ * ]
31
+ * },
32
+ * primaryType: 'Person',
33
+ * message: {
34
+ * name: 'John Doe',
35
+ * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'
36
+ * }
37
+ * });
38
+ */
39
+ export declare function signTypedData(client: InnerWalletApiClient, signer: SmartAccountSigner, params: SignTypedDataParams): Promise<SignTypedDataResult>;