@alchemy/wallet-apis 0.0.0-alpha.17 → 0.0.0-alpha.19

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 (191) hide show
  1. package/dist/esm/actions/formatSign.d.ts +13 -15
  2. package/dist/esm/actions/formatSign.js +18 -12
  3. package/dist/esm/actions/formatSign.js.map +1 -1
  4. package/dist/esm/actions/getCapabilities.d.ts +27 -0
  5. package/dist/esm/actions/getCapabilities.js +49 -0
  6. package/dist/esm/actions/getCapabilities.js.map +1 -0
  7. package/dist/esm/actions/grantPermissions.d.ts +13 -17
  8. package/dist/esm/actions/grantPermissions.js +23 -26
  9. package/dist/esm/actions/grantPermissions.js.map +1 -1
  10. package/dist/esm/actions/listAccounts.d.ts +8 -17
  11. package/dist/esm/actions/listAccounts.js +16 -29
  12. package/dist/esm/actions/listAccounts.js.map +1 -1
  13. package/dist/esm/actions/prepareCalls.d.ts +24 -22
  14. package/dist/esm/actions/prepareCalls.js +30 -25
  15. package/dist/esm/actions/prepareCalls.js.map +1 -1
  16. package/dist/esm/actions/prepareSign.d.ts +13 -16
  17. package/dist/esm/actions/prepareSign.js +18 -17
  18. package/dist/esm/actions/prepareSign.js.map +1 -1
  19. package/dist/esm/actions/requestAccount.d.ts +21 -21
  20. package/dist/esm/actions/requestAccount.js +30 -46
  21. package/dist/esm/actions/requestAccount.js.map +1 -1
  22. package/dist/esm/actions/sendCalls.d.ts +18 -12
  23. package/dist/esm/actions/sendCalls.js +21 -17
  24. package/dist/esm/actions/sendCalls.js.map +1 -1
  25. package/dist/esm/actions/sendPreparedCalls.d.ts +14 -13
  26. package/dist/esm/actions/sendPreparedCalls.js +22 -16
  27. package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
  28. package/dist/esm/actions/signMessage.d.ts +4 -3
  29. package/dist/esm/actions/signMessage.js +9 -12
  30. package/dist/esm/actions/signMessage.js.map +1 -1
  31. package/dist/esm/actions/signPreparedCalls.d.ts +18 -2
  32. package/dist/esm/actions/signPreparedCalls.js +2 -7
  33. package/dist/esm/actions/signPreparedCalls.js.map +1 -1
  34. package/dist/esm/actions/signSignatureRequest.d.ts +3 -9
  35. package/dist/esm/actions/signSignatureRequest.js +5 -36
  36. package/dist/esm/actions/signSignatureRequest.js.map +1 -1
  37. package/dist/esm/actions/signTypedData.d.ts +3 -2
  38. package/dist/esm/actions/signTypedData.js +8 -11
  39. package/dist/esm/actions/signTypedData.js.map +1 -1
  40. package/dist/esm/client.d.ts +18 -23
  41. package/dist/esm/client.js +20 -31
  42. package/dist/esm/client.js.map +1 -1
  43. package/dist/esm/decorators/smartWalletActions.d.ts +10 -9
  44. package/dist/esm/decorators/smartWalletActions.js +5 -4
  45. package/dist/esm/decorators/smartWalletActions.js.map +1 -1
  46. package/dist/esm/experimental/actions/requestQuoteV0.d.ts +19 -20
  47. package/dist/esm/experimental/actions/requestQuoteV0.js +26 -23
  48. package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
  49. package/dist/esm/experimental/swapActionsDecorator.d.ts +4 -5
  50. package/dist/esm/experimental/swapActionsDecorator.js +1 -1
  51. package/dist/esm/experimental/swapActionsDecorator.js.map +1 -1
  52. package/dist/esm/exports/index.d.ts +6 -4
  53. package/dist/esm/exports/index.js +3 -2
  54. package/dist/esm/exports/index.js.map +1 -1
  55. package/dist/esm/exports/internal.d.ts +0 -4
  56. package/dist/esm/exports/internal.js +0 -2
  57. package/dist/esm/exports/internal.js.map +1 -1
  58. package/dist/esm/transport.d.ts +3 -0
  59. package/dist/esm/transport.js +8 -0
  60. package/dist/esm/transport.js.map +1 -0
  61. package/dist/esm/types.d.ts +12 -11
  62. package/dist/esm/types.js.map +1 -1
  63. package/dist/esm/utils/assertions.d.ts +2 -4
  64. package/dist/esm/utils/assertions.js +0 -3
  65. package/dist/esm/utils/assertions.js.map +1 -1
  66. package/dist/esm/utils/capabilities.d.ts +41 -2
  67. package/dist/esm/utils/capabilities.js +57 -11
  68. package/dist/esm/utils/capabilities.js.map +1 -1
  69. package/dist/esm/utils/format.d.ts +1 -3
  70. package/dist/esm/utils/format.js +1 -11
  71. package/dist/esm/utils/format.js.map +1 -1
  72. package/dist/esm/utils/resolve.d.ts +7 -0
  73. package/dist/esm/utils/resolve.js +4 -0
  74. package/dist/esm/utils/resolve.js.map +1 -0
  75. package/dist/esm/utils/schema.d.ts +24 -0
  76. package/dist/esm/utils/schema.js +7 -0
  77. package/dist/esm/utils/schema.js.map +1 -0
  78. package/dist/esm/version.d.ts +1 -1
  79. package/dist/esm/version.js +1 -1
  80. package/dist/esm/version.js.map +1 -1
  81. package/dist/types/actions/formatSign.d.ts +13 -15
  82. package/dist/types/actions/formatSign.d.ts.map +1 -1
  83. package/dist/types/actions/getCapabilities.d.ts +28 -0
  84. package/dist/types/actions/getCapabilities.d.ts.map +1 -0
  85. package/dist/types/actions/grantPermissions.d.ts +13 -17
  86. package/dist/types/actions/grantPermissions.d.ts.map +1 -1
  87. package/dist/types/actions/listAccounts.d.ts +8 -17
  88. package/dist/types/actions/listAccounts.d.ts.map +1 -1
  89. package/dist/types/actions/prepareCalls.d.ts +24 -22
  90. package/dist/types/actions/prepareCalls.d.ts.map +1 -1
  91. package/dist/types/actions/prepareSign.d.ts +13 -16
  92. package/dist/types/actions/prepareSign.d.ts.map +1 -1
  93. package/dist/types/actions/requestAccount.d.ts +21 -21
  94. package/dist/types/actions/requestAccount.d.ts.map +1 -1
  95. package/dist/types/actions/sendCalls.d.ts +18 -12
  96. package/dist/types/actions/sendCalls.d.ts.map +1 -1
  97. package/dist/types/actions/sendPreparedCalls.d.ts +14 -13
  98. package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
  99. package/dist/types/actions/signMessage.d.ts +4 -3
  100. package/dist/types/actions/signMessage.d.ts.map +1 -1
  101. package/dist/types/actions/signPreparedCalls.d.ts +18 -2
  102. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
  103. package/dist/types/actions/signSignatureRequest.d.ts +3 -9
  104. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
  105. package/dist/types/actions/signTypedData.d.ts +3 -2
  106. package/dist/types/actions/signTypedData.d.ts.map +1 -1
  107. package/dist/types/client.d.ts +18 -23
  108. package/dist/types/client.d.ts.map +1 -1
  109. package/dist/types/decorators/smartWalletActions.d.ts +10 -9
  110. package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
  111. package/dist/types/experimental/actions/requestQuoteV0.d.ts +19 -20
  112. package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
  113. package/dist/types/experimental/swapActionsDecorator.d.ts +4 -5
  114. package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -1
  115. package/dist/types/exports/index.d.ts +6 -4
  116. package/dist/types/exports/index.d.ts.map +1 -1
  117. package/dist/types/exports/internal.d.ts +0 -4
  118. package/dist/types/exports/internal.d.ts.map +1 -1
  119. package/dist/types/transport.d.ts +4 -0
  120. package/dist/types/transport.d.ts.map +1 -0
  121. package/dist/types/types.d.ts +12 -11
  122. package/dist/types/types.d.ts.map +1 -1
  123. package/dist/types/utils/assertions.d.ts +2 -4
  124. package/dist/types/utils/assertions.d.ts.map +1 -1
  125. package/dist/types/utils/capabilities.d.ts +41 -2
  126. package/dist/types/utils/capabilities.d.ts.map +1 -1
  127. package/dist/types/utils/format.d.ts +1 -3
  128. package/dist/types/utils/format.d.ts.map +1 -1
  129. package/dist/types/utils/resolve.d.ts +8 -0
  130. package/dist/types/utils/resolve.d.ts.map +1 -0
  131. package/dist/types/utils/schema.d.ts +25 -0
  132. package/dist/types/utils/schema.d.ts.map +1 -0
  133. package/dist/types/version.d.ts +1 -1
  134. package/package.json +6 -7
  135. package/src/actions/formatSign.ts +37 -32
  136. package/src/actions/getCapabilities.ts +64 -0
  137. package/src/actions/grantPermissions.ts +42 -57
  138. package/src/actions/listAccounts.ts +38 -54
  139. package/src/actions/prepareCalls.ts +56 -45
  140. package/src/actions/prepareSign.ts +38 -38
  141. package/src/actions/requestAccount.ts +49 -78
  142. package/src/actions/sendCalls.ts +33 -28
  143. package/src/actions/sendPreparedCalls.ts +49 -28
  144. package/src/actions/signMessage.ts +10 -26
  145. package/src/actions/signPreparedCalls.ts +33 -24
  146. package/src/actions/signSignatureRequest.ts +14 -78
  147. package/src/actions/signTypedData.ts +9 -24
  148. package/src/client.ts +34 -60
  149. package/src/decorators/smartWalletActions.ts +17 -21
  150. package/src/experimental/actions/requestQuoteV0.ts +55 -50
  151. package/src/experimental/swapActionsDecorator.ts +6 -11
  152. package/src/exports/index.ts +7 -7
  153. package/src/exports/internal.ts +0 -6
  154. package/src/transport.ts +16 -0
  155. package/src/types.ts +12 -17
  156. package/src/utils/assertions.ts +2 -9
  157. package/src/utils/capabilities.ts +105 -16
  158. package/src/utils/format.ts +1 -20
  159. package/src/utils/resolve.ts +11 -0
  160. package/src/utils/schema.ts +32 -0
  161. package/src/version.ts +1 -1
  162. package/dist/esm/provider.d.ts +0 -26
  163. package/dist/esm/provider.js +0 -191
  164. package/dist/esm/provider.js.map +0 -1
  165. package/dist/esm/testSetup.d.ts +0 -3
  166. package/dist/esm/testSetup.js +0 -18
  167. package/dist/esm/testSetup.js.map +0 -1
  168. package/dist/esm/utils/signer.d.ts +0 -10
  169. package/dist/esm/utils/signer.js +0 -28
  170. package/dist/esm/utils/signer.js.map +0 -1
  171. package/dist/esm/utils/viemDecode.d.ts +0 -8
  172. package/dist/esm/utils/viemDecode.js +0 -231
  173. package/dist/esm/utils/viemDecode.js.map +0 -1
  174. package/dist/esm/utils/viemEncode.d.ts +0 -40
  175. package/dist/esm/utils/viemEncode.js +0 -216
  176. package/dist/esm/utils/viemEncode.js.map +0 -1
  177. package/dist/types/provider.d.ts +0 -27
  178. package/dist/types/provider.d.ts.map +0 -1
  179. package/dist/types/testSetup.d.ts +0 -4
  180. package/dist/types/testSetup.d.ts.map +0 -1
  181. package/dist/types/utils/signer.d.ts +0 -11
  182. package/dist/types/utils/signer.d.ts.map +0 -1
  183. package/dist/types/utils/viemDecode.d.ts +0 -9
  184. package/dist/types/utils/viemDecode.d.ts.map +0 -1
  185. package/dist/types/utils/viemEncode.d.ts +0 -41
  186. package/dist/types/utils/viemEncode.d.ts.map +0 -1
  187. package/src/provider.ts +0 -261
  188. package/src/testSetup.ts +0 -24
  189. package/src/utils/signer.ts +0 -36
  190. package/src/utils/viemDecode.ts +0 -313
  191. package/src/utils/viemEncode.ts +0 -345
@@ -1,58 +1,63 @@
1
- import { toHex } from "viem";
2
- import { AccountNotFoundError } from "@alchemy/common";
3
1
  import { LOGGER } from "../logger.js";
4
- import { mergeClientCapabilities } from "../utils/capabilities.js";
2
+ import { mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
3
+ import { resolveAddress } from "../utils/resolve.js";
4
+ import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
5
+ import { Value } from "typebox/value";
6
+ import { methodSchema, } from "../utils/schema.js";
7
+ const schema = methodSchema(MethodSchema);
5
8
  /**
6
9
  * Prepares a set of contract calls for execution by building a user operation.
7
10
  * Returns the built user operation and a signature request that needs to be signed
8
11
  * before submitting to sendPreparedCalls.
9
12
  *
10
- * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
11
- * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
12
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
13
- * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
13
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
14
+ * this directly without first calling `requestAccount`.
15
+ *
16
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
17
+ * @param {PrepareCallsParams} params - Parameters for preparing calls
18
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
19
+ * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
14
20
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
15
21
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
16
22
  * the user operation data and signature request
17
23
  *
18
24
  * @example
19
25
  * ```ts
20
- * // Prepare a sponsored user operation call
26
+ * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
21
27
  * const result = await client.prepareCalls({
22
28
  * calls: [{
23
29
  * to: "0x1234...",
24
30
  * data: "0xabcdef...",
25
- * value: "0x0"
31
+ * value: 0n
26
32
  * }],
27
33
  * capabilities: {
28
- * paymasterService: { policyId: "your-policy-id" }
34
+ * paymaster: { policyId: "your-policy-id" }
29
35
  * }
30
36
  * });
31
37
  * ```
32
38
  */
33
39
  export async function prepareCalls(client, params) {
34
- const from = params.from ?? client.account?.address;
35
- if (!from) {
36
- LOGGER.warn("prepareCalls:no-from", { hasClientAccount: !!client.account });
37
- throw new AccountNotFoundError();
38
- }
40
+ const from = params.account
41
+ ? resolveAddress(params.account)
42
+ : client.account.address;
43
+ const chainId = params.chainId ?? client.chain.id;
39
44
  const capabilities = mergeClientCapabilities(client, params.capabilities);
40
45
  LOGGER.debug("prepareCalls:start", {
41
46
  callsCount: params.calls?.length,
42
47
  hasCapabilities: !!params.capabilities,
43
48
  });
44
- const res = await client.request({
49
+ const { account: _, chainId: __, ...rest } = params;
50
+ const rpcParams = Value.Encode(schema.request, {
51
+ ...rest,
52
+ chainId,
53
+ from,
54
+ capabilities: toRpcCapabilities(capabilities),
55
+ });
56
+ const rpcResp = await client.request({
45
57
  method: "wallet_prepareCalls",
46
- params: [
47
- {
48
- ...params,
49
- chainId: params.chainId ?? toHex(client.chain.id),
50
- from,
51
- capabilities,
52
- },
53
- ],
58
+ params: [rpcParams],
54
59
  });
55
60
  LOGGER.debug("prepareCalls:done");
56
- return res;
61
+ return Value.Decode(schema.response, rpcResp);
57
62
  }
58
63
  //# sourceMappingURL=prepareCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAqBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,MAA4B,EAC5B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI;gBACJ,YAAY;aACb;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareCalls\";\n };\n }\n>;\n\nexport type PrepareCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call\n * const result = 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 */\nexport async function prepareCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareCallsParams<TAccount>,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareCalls:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const res = await client.request({\n method: \"wallet_prepareCalls\",\n params: [\n {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n from,\n capabilities,\n },\n ],\n });\n LOGGER.debug(\"prepareCalls:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAe1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAElD,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,OAAO;QACP,IAAI;QACJ,YAAY,EAAE,iBAAiB,CAAC,YAAY,CAAC;KACb,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n mergeClientCapabilities,\n toRpcCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { wallet_prepareCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareCallsParams = MethodParams<typeof MethodSchema>;\ntype PrepareCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareCallsParams = Prettify<\n WithCapabilities<\n DistributiveOmit<BasePrepareCallsParams, \"from\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n >\n>;\n\nexport type PrepareCallsResult = PrepareCallsResponse;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * The client defaults to using EIP-7702 with the signer's address, so you can call\n * this directly without first calling `requestAccount`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute\n * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls(\n client: InnerWalletApiClient,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const chainId = params.chainId ?? client.chain.id;\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n chainId,\n from,\n capabilities: toRpcCapabilities(capabilities),\n } satisfies BasePrepareCallsParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareCalls:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
@@ -1,17 +1,14 @@
1
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
2
- import { type Address, type IsUndefined, type Prettify } from "viem";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_prepareSign";
7
- };
8
- }>;
9
- export type PrepareSignParams<TAccount extends Address | undefined = Address | undefined> = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "from">> & (IsUndefined<TAccount> extends true ? {
10
- from: Address;
11
- } : {
12
- from?: never;
13
- })>;
14
- export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
1
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
2
+ import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
3
+ import { type AccountParam } from "../utils/resolve.js";
4
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
5
+ type BasePrepareSignParams = MethodParams<typeof MethodSchema>;
6
+ type PrepareSignResponse = MethodResponse<typeof MethodSchema>;
7
+ export type PrepareSignParams = DistributiveOmit<BasePrepareSignParams, "from" | "chainId"> & {
8
+ account?: AccountParam;
9
+ chainId?: number;
10
+ };
11
+ export type PrepareSignResult = PrepareSignResponse;
15
12
  /**
16
13
  * Prepares a signature request for signing messages or transactions.
17
14
  *
@@ -23,11 +20,11 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
23
20
  * ```ts
24
21
  * // Prepare a message to be signed
25
22
  * const result = await client.prepareSign({
26
- * from: "0x1234...",
23
+ * account: "0x1234...",
27
24
  * type: "personal_sign",
28
25
  * data: "Hello, world!",
29
26
  * });
30
27
  * ```
31
28
  */
32
- export declare function prepareSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareSignParams<TAccount>): Promise<PrepareSignResult>;
29
+ export declare function prepareSign(client: InnerWalletApiClient, params: PrepareSignParams): Promise<PrepareSignResult>;
33
30
  export {};
@@ -1,6 +1,9 @@
1
- import { toHex } from "viem";
2
- import { AccountNotFoundError } from "@alchemy/common";
1
+ import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
3
2
  import { LOGGER } from "../logger.js";
3
+ import { resolveAddress } from "../utils/resolve.js";
4
+ import { Value } from "typebox/value";
5
+ import { methodSchema, } from "../utils/schema.js";
6
+ const schema = methodSchema(MethodSchema);
4
7
  /**
5
8
  * Prepares a signature request for signing messages or transactions.
6
9
  *
@@ -12,30 +15,28 @@ import { LOGGER } from "../logger.js";
12
15
  * ```ts
13
16
  * // Prepare a message to be signed
14
17
  * const result = await client.prepareSign({
15
- * from: "0x1234...",
18
+ * account: "0x1234...",
16
19
  * type: "personal_sign",
17
20
  * data: "Hello, world!",
18
21
  * });
19
22
  * ```
20
23
  */
21
24
  export async function prepareSign(client, params) {
22
- const from = params.from ?? client.account?.address;
23
- if (!from) {
24
- LOGGER.warn("prepareSign:no-from", { hasClientAccount: !!client.account });
25
- throw new AccountNotFoundError();
26
- }
25
+ const from = params.account
26
+ ? resolveAddress(params.account)
27
+ : client.account.address;
27
28
  LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
28
- const res = await client.request({
29
+ const { account: _, chainId: __, ...rest } = params;
30
+ const rpcParams = Value.Encode(schema.request, {
31
+ ...rest,
32
+ from,
33
+ chainId: params.chainId ?? client.chain.id,
34
+ });
35
+ const rpcResp = await client.request({
29
36
  method: "wallet_prepareSign",
30
- params: [
31
- {
32
- ...params,
33
- from,
34
- chainId: params.chainId ?? toHex(client.chain.id),
35
- },
36
- ],
37
+ params: [rpcParams],
37
38
  });
38
39
  LOGGER.debug("prepareSign:done");
39
- return res;
40
+ return Value.Decode(schema.response, rpcResp);
40
41
  }
41
42
  //# sourceMappingURL=prepareSign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;GAgBG;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,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,IAAI;gBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareSign\";\n };\n }\n>;\n\nexport type PrepareSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\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 * ```ts\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 * ```\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 LOGGER.warn(\"prepareSign:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n const res = await client.request({\n method: \"wallet_prepareSign\",\n params: [\n {\n ...params,\n from,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"prepareSign:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1E,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;KACX,CAAC,CAAC;IAEnC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_prepareSign as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareSignParams = MethodParams<typeof MethodSchema>;\ntype PrepareSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareSignParams = DistributiveOmit<\n BasePrepareSignParams,\n \"from\" | \"chainId\"\n> & {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type PrepareSignResult = PrepareSignResponse;\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 * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * account: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign(\n client: InnerWalletApiClient,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n } satisfies BasePrepareSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
@@ -1,25 +1,26 @@
1
1
  import type { Address } from "abitype";
2
- import { type Prettify } from "viem";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { InnerWalletApiClient } from "../types";
5
- import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
6
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
7
- Request: {
8
- method: "wallet_requestAccount";
9
- };
10
- }>;
11
- export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
2
+ import { type JsonRpcAccount, type Prettify } from "viem";
3
+ import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types";
5
+ import { type MethodParams } from "../utils/schema.js";
6
+ type BaseRequestAccountParams = MethodParams<typeof MethodSchema>;
7
+ export type RequestAccountParams = Prettify<DistributiveOmit<Extract<BaseRequestAccountParams, {
12
8
  signerAddress: Address;
9
+ }>, "signerAddress" | "includeCounterfactualInfo"> & ({
10
+ signerAddress?: Address;
11
+ accountAddress?: never;
13
12
  } | {
14
- signerPublicKey: WebAuthnPublicKey;
15
- }>, "signerAddress" | "signerPublicKey" | "includeCounterfactualInfo"> & {
16
- accountAddress?: Address;
17
- }>;
18
- export type RequestAccountResult = Prettify<{
19
- address: Address;
20
- }>;
13
+ signerAddress?: never;
14
+ accountAddress: Address;
15
+ })>;
16
+ export type RequestAccountResult = JsonRpcAccount<Address>;
21
17
  /**
22
- * Requests an account for the provided signer using the wallet API client.
18
+ * Requests a smart account address for the provided signer using the wallet API client.
19
+ *
20
+ * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
21
+ * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
22
+ * directly without first calling `requestAccount`.
23
+ *
23
24
  * If an account already exists for the signer, it will always return that account unless a new ID is specified.
24
25
  * If an account already exists, the creationHint will be ignored.
25
26
  *
@@ -31,9 +32,8 @@ export type RequestAccountResult = Prettify<{
31
32
  *
32
33
  * @example
33
34
  * ```ts
34
- * // Request an account with default parameters using a local signer
35
- * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
36
- * const account = await client.requestAccount(signer);
35
+ * // Request a non-7702 smart account
36
+ * const account = await client.requestAccount();
37
37
  * ```
38
38
  */
39
39
  export declare function requestAccount(client: InnerWalletApiClient, params?: RequestAccountParams): Promise<RequestAccountResult>;
@@ -1,10 +1,18 @@
1
- import { BaseError } from "viem";
1
+ import { isAddressEqual } from "viem";
2
+ import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
2
3
  import deepEqual from "deep-equal";
3
4
  import { LOGGER } from "../logger.js";
4
- import { isWebAuthnAccount } from "../utils/assertions.js";
5
- import { getSignerAddressOrPublicKey } from "../utils/signer.js";
5
+ import { isLocalAccount } from "../utils/assertions.js";
6
+ import { Value } from "typebox/value";
7
+ import { methodSchema } from "../utils/schema.js";
8
+ const schema = methodSchema(MethodSchema);
6
9
  /**
7
- * Requests an account for the provided signer using the wallet API client.
10
+ * Requests a smart account address for the provided signer using the wallet API client.
11
+ *
12
+ * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
13
+ * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
14
+ * directly without first calling `requestAccount`.
15
+ *
8
16
  * If an account already exists for the signer, it will always return that account unless a new ID is specified.
9
17
  * If an account already exists, the creationHint will be ignored.
10
18
  *
@@ -16,9 +24,8 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
16
24
  *
17
25
  * @example
18
26
  * ```ts
19
- * // Request an account with default parameters using a local signer
20
- * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
21
- * const account = await client.requestAccount(signer);
27
+ * // Request a non-7702 smart account
28
+ * const account = await client.requestAccount();
22
29
  * ```
23
30
  */
24
31
  export async function requestAccount(client, params) {
@@ -26,63 +33,39 @@ export async function requestAccount(client, params) {
26
33
  hasParams: !!params,
27
34
  hasAccountOnClient: !!client.account,
28
35
  });
29
- const { creationHint = {} } = params ?? {};
30
- if (isWebAuthnAccount(client.owner)) {
31
- if (creationHint.accountType &&
32
- creationHint.accountType !== "mav2-webauthn") {
33
- throw new BaseError("WebAuthn signers are only supported with mav2-webauthn account type");
34
- }
35
- }
36
- else {
37
- // Non-webauthn signers do not support the "mav2-webauthn" account type.
38
- if (creationHint.accountType === "mav2-webauthn") {
39
- throw new BaseError("ECDSA (secp256k1) signers are not supported with mav2-webauthn account type");
40
- }
41
- }
42
- const owner = getSignerAddressOrPublicKey(client.owner);
43
- const args = (client.account && !params) || params?.accountAddress
36
+ const signerAddress = (params && "signerAddress" in params ? params.signerAddress : undefined) ??
37
+ (isLocalAccount(client.owner)
38
+ ? client.owner.address
39
+ : client.owner.account.address);
40
+ const args = params && "accountAddress" in params && params.accountAddress
44
41
  ? {
45
- accountAddress: params?.accountAddress ?? client.account.address,
42
+ accountAddress: params.accountAddress,
46
43
  includeCounterfactualInfo: true,
47
44
  }
48
45
  : {
49
- ...(owner.type === "webauthn-p256"
50
- ? {
51
- signerPublicKey: {
52
- ...owner.publicKey,
53
- type: "webauthn-p256",
54
- },
55
- // Casts here are safe due to our checks above.
56
- ...(creationHint
57
- ? { creationHint: creationHint }
58
- : {}),
59
- }
60
- : {
61
- signerAddress: owner.address,
62
- ...(creationHint
63
- ? {
64
- creationHint: creationHint,
65
- }
66
- : {}),
67
- }),
46
+ ...params,
47
+ signerAddress,
68
48
  includeCounterfactualInfo: true,
69
49
  };
70
50
  const cachedAccount = client.internal?.getAccount();
71
51
  if (cachedAccount &&
72
- ((params?.accountAddress &&
73
- cachedAccount.address === params.accountAddress) ||
52
+ ((args.accountAddress &&
53
+ isAddressEqual(cachedAccount.address, args.accountAddress)) ||
74
54
  deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
75
55
  LOGGER.debug("requestAccount:cache-hit", {
76
56
  address: cachedAccount.address,
77
57
  });
78
58
  return {
79
59
  address: cachedAccount.address,
60
+ type: "json-rpc",
80
61
  };
81
62
  }
82
- const resp = await client.request({
63
+ const rpcParams = Value.Encode(schema.request, args);
64
+ const rpcResp = await client.request({
83
65
  method: "wallet_requestAccount",
84
- params: [args],
66
+ params: [rpcParams],
85
67
  });
68
+ const resp = Value.Decode(schema.response, rpcResp);
86
69
  client.internal?.setAccount({
87
70
  address: resp.accountAddress,
88
71
  requestParams: args,
@@ -90,6 +73,7 @@ export async function requestAccount(client, params) {
90
73
  LOGGER.debug("requestAccount:done", { address: resp.accountAddress });
91
74
  return {
92
75
  address: resp.accountAddress,
76
+ type: "json-rpc",
93
77
  };
94
78
  }
95
79
  //# sourceMappingURL=requestAccount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiB,MAAM,MAAM,CAAC;AAEhD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAMtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAuBjE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA6B;IAE7B,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;QACnC,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;KACrC,CAAC,CAAC;IAEH,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IAE3C,IAAI,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,IACE,YAAY,CAAC,WAAW;YACxB,YAAY,CAAC,WAAW,KAAK,eAAe,EAC5C,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,qEAAqE,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,wEAAwE;QACxE,IAAI,YAAY,CAAC,WAAW,KAAK,eAAe,EAAE,CAAC;YACjD,MAAM,IAAI,SAAS,CACjB,6EAA6E,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,2BAA2B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExD,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,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe;gBAChC,CAAC,CAAC;oBACE,eAAe,EAAE;wBACf,GAAG,KAAK,CAAC,SAAS;wBAClB,IAAI,EAAE,eAAe;qBACtB;oBACD,+CAA+C;oBAC/C,GAAG,CAAC,YAAY;wBACd,CAAC,CAAC,EAAE,YAAY,EAAE,YAA0C,EAAE;wBAC9D,CAAC,CAAC,EAAE,CAAC;iBACR;gBACH,CAAC,CAAC;oBACE,aAAa,EAAE,KAAK,CAAC,OAAO;oBAC5B,GAAG,CAAC,YAAY;wBACd,CAAC,CAAC;4BACE,YAAY,EACV,YAA8C;yBACjD;wBACH,CAAC,CAAC,EAAE,CAAC;iBACR,CAAC;YACN,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEpD,IACE,aAAa;QACb,CAAC,CAAC,MAAM,EAAE,cAAc;YACtB,aAAa,CAAC,OAAO,KAAK,MAAM,CAAC,cAAc,CAAC;YAChD,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { BaseError, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport type {\n CreationOptionsByPublicKey,\n CreationOptionsBySignerAddress,\n WebAuthnPublicKey,\n} from \"@alchemy/wallet-api-types\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\nimport { getSignerAddressOrPublicKey } from \"../utils/signer.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_requestAccount\";\n };\n }\n>;\n\nexport type RequestAccountParams = Prettify<\n Omit<\n Extract<\n RpcSchema[\"Request\"][\"params\"][0],\n { signerAddress: Address } | { signerPublicKey: WebAuthnPublicKey }\n >,\n \"signerAddress\" | \"signerPublicKey\" | \"includeCounterfactualInfo\"\n > & { accountAddress?: Address }\n>;\n\nexport type RequestAccountResult = Prettify<{ address: Address }>;\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 {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 an object containing a smart account address\n *\n * @example\n * ```ts\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 * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const { creationHint = {} } = params ?? {};\n\n if (isWebAuthnAccount(client.owner)) {\n if (\n creationHint.accountType &&\n creationHint.accountType !== \"mav2-webauthn\"\n ) {\n throw new BaseError(\n \"WebAuthn signers are only supported with mav2-webauthn account type\",\n );\n }\n } else {\n // Non-webauthn signers do not support the \"mav2-webauthn\" account type.\n if (creationHint.accountType === \"mav2-webauthn\") {\n throw new BaseError(\n \"ECDSA (secp256k1) signers are not supported with mav2-webauthn account type\",\n );\n }\n }\n\n const owner = getSignerAddressOrPublicKey(client.owner);\n\n const args: RpcSchema[\"Request\"][\"params\"][0] =\n (client.account && !params) || params?.accountAddress\n ? {\n accountAddress: params?.accountAddress ?? client.account!.address,\n includeCounterfactualInfo: true,\n }\n : {\n ...(owner.type === \"webauthn-p256\"\n ? {\n signerPublicKey: {\n ...owner.publicKey,\n type: \"webauthn-p256\",\n },\n // Casts here are safe due to our checks above.\n ...(creationHint\n ? { creationHint: creationHint as CreationOptionsByPublicKey }\n : {}),\n }\n : {\n signerAddress: owner.address,\n ...(creationHint\n ? {\n creationHint:\n creationHint as CreationOptionsBySignerAddress,\n }\n : {}),\n }),\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((params?.accountAddress &&\n cachedAccount.address === params.accountAddress) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n };\n }\n\n const resp = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n return {\n address: resp.accountAddress,\n };\n}\n"]}
1
+ {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsC,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAErE,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA6B;IAE7B,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;QACnC,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;KACrC,CAAC,CAAC;IAEH,MAAM,aAAa,GACjB,CAAC,MAAM,IAAI,eAAe,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,IAAI,GACR,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc;QAC3D,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa;YACb,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEpD,IACE,aAAa;QACb,CAAC,CAAC,IAAI,CAAC,cAAc;YACnB,cAAc,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3D,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,IAAI,EAAE,UAAU;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAC5B,MAAM,CAAC,OAAO,EACd,IAAuC,CACxC,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAEtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type JsonRpcAccount, type Prettify } from \"viem\";\nimport { wallet_requestAccount as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\nimport { Value } from \"typebox/value\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseRequestAccountParams = MethodParams<typeof MethodSchema>;\n\nexport type RequestAccountParams = Prettify<\n DistributiveOmit<\n Extract<BaseRequestAccountParams, { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = JsonRpcAccount<Address>;\n\n/**\n * Requests a smart account address for the provided signer using the wallet API client.\n *\n * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using\n * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`\n * directly without first calling `requestAccount`.\n *\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 {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 an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request a non-7702 smart account\n * const account = await client.requestAccount();\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const signerAddress =\n (params && \"signerAddress\" in params ? params.signerAddress : undefined) ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n const args =\n params && \"accountAddress\" in params && params.accountAddress\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n isAddressEqual(cachedAccount.address, args.accountAddress)) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n type: \"json-rpc\",\n };\n }\n\n const rpcParams = Value.Encode(\n schema.request,\n args satisfies BaseRequestAccountParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_requestAccount\",\n params: [rpcParams],\n });\n\n const resp = Value.Decode(schema.response, rpcResp);\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n\n return {\n address: resp.accountAddress,\n type: \"json-rpc\",\n };\n}\n"]}
@@ -1,38 +1,44 @@
1
- import type { Address, Prettify } from "viem";
2
- import type { InnerWalletApiClient } from "../types.js";
1
+ import type { Chain, Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.js";
3
3
  import { type PrepareCallsParams } from "./prepareCalls.js";
4
4
  import { type SendPreparedCallsResult } from "./sendPreparedCalls.js";
5
- export type SendCallsParams<TAccount extends Address | undefined = Address | undefined> = Prettify<PrepareCallsParams<TAccount>>;
5
+ export type SendCallsParams = Prettify<DistributiveOmit<PrepareCallsParams, "chainId"> & {
6
+ chain?: Pick<Chain, "id">;
7
+ }>;
6
8
  export type SendCallsResult = Prettify<SendPreparedCallsResult>;
7
9
  /**
8
10
  * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
9
11
  *
12
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
13
+ * this directly without first calling `requestAccount`.
14
+ *
10
15
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
11
- * @param {PrepareCallsParams<TAccount>} params - Parameters for sending calls
12
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
13
- * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
16
+ * @param {SendCallsParams} params - Parameters for sending calls
17
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
18
+ * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
14
19
  * @param {object} [params.capabilities] - Optional capabilities to include with the request.
15
- * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs.
20
+ * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
16
21
  *
17
22
  * @example
18
23
  * ```ts
24
+ * // Send calls (uses signer address via EIP-7702 by default)
19
25
  * const result = await client.sendCalls({
20
26
  * calls: [{
21
27
  * to: "0x1234...",
22
28
  * data: "0xabcdef...",
23
- * value: "0x0"
29
+ * value: 0n
24
30
  * }],
25
31
  * capabilities: {
26
- * paymasterService: { policyId: "your-policy-id" }
32
+ * paymaster: { policyId: "your-policy-id" }
27
33
  * }
28
34
  * });
29
35
  *
30
- * // The result contains the prepared call IDs
31
- * console.log(result.preparedCallIds);
36
+ * // The result contains the call ID
37
+ * console.log(result.id);
32
38
  * ```
33
39
  * <Note>
34
40
  * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
35
41
  * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.
36
42
  * </Note>
37
43
  */
38
- export declare function sendCalls<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: SendCallsParams<TAccount>): Promise<SendCallsResult>;
44
+ export declare function sendCalls(client: InnerWalletApiClient, params: SendCallsParams): Promise<SendCallsResult>;
@@ -3,34 +3,36 @@ import { signPreparedCalls } from "./signPreparedCalls.js";
3
3
  import { sendPreparedCalls, } from "./sendPreparedCalls.js";
4
4
  import { LOGGER } from "../logger.js";
5
5
  import { signSignatureRequest } from "./signSignatureRequest.js";
6
- import { isWebAuthnAccount } from "../utils/assertions.js";
7
- import { extractCapabilitiesForSending } from "../utils/capabilities.js";
8
- import { BaseError } from "@alchemy/common";
6
+ import { extractCapabilitiesForSending, fromRpcCapabilities, } from "../utils/capabilities.js";
9
7
  /**
10
8
  * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
11
9
  *
10
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
11
+ * this directly without first calling `requestAccount`.
12
+ *
12
13
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
13
- * @param {PrepareCallsParams<TAccount>} params - Parameters for sending calls
14
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
15
- * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
14
+ * @param {SendCallsParams} params - Parameters for sending calls
15
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
16
+ * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
16
17
  * @param {object} [params.capabilities] - Optional capabilities to include with the request.
17
- * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs.
18
+ * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
18
19
  *
19
20
  * @example
20
21
  * ```ts
22
+ * // Send calls (uses signer address via EIP-7702 by default)
21
23
  * const result = await client.sendCalls({
22
24
  * calls: [{
23
25
  * to: "0x1234...",
24
26
  * data: "0xabcdef...",
25
- * value: "0x0"
27
+ * value: 0n
26
28
  * }],
27
29
  * capabilities: {
28
- * paymasterService: { policyId: "your-policy-id" }
30
+ * paymaster: { policyId: "your-policy-id" }
29
31
  * }
30
32
  * });
31
33
  *
32
- * // The result contains the prepared call IDs
33
- * console.log(result.preparedCallIds);
34
+ * // The result contains the call ID
35
+ * console.log(result.id);
34
36
  * ```
35
37
  * <Note>
36
38
  * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
@@ -42,16 +44,18 @@ export async function sendCalls(client, params) {
42
44
  calls: params.calls?.length,
43
45
  hasCapabilities: !!params.capabilities,
44
46
  });
45
- let calls = await prepareCalls(client, params);
47
+ const { chain, ...prepareCallsParams } = params;
48
+ let calls = await prepareCalls(client, {
49
+ ...prepareCallsParams,
50
+ ...(chain != null ? { chainId: chain.id } : {}),
51
+ });
46
52
  if (calls.type === "paymaster-permit") {
47
- if (isWebAuthnAccount(client.owner)) {
48
- throw new BaseError("WebAuthn signer is not currently supported for signing paymaster permit signatures");
49
- }
50
53
  const signature = await signSignatureRequest(client, calls.signatureRequest);
51
54
  const secondCallParams = {
52
- from: calls.modifiedRequest.from,
55
+ account: calls.modifiedRequest.from,
53
56
  calls: calls.modifiedRequest.calls,
54
- capabilities: calls.modifiedRequest.capabilities,
57
+ chainId: calls.modifiedRequest.chainId,
58
+ capabilities: fromRpcCapabilities(calls.modifiedRequest.capabilities),
55
59
  // WebAuthn signatures are not supported for paymaster permits (throws above).
56
60
  paymasterPermitSignature: signature,
57
61
  };