@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,17 +1,15 @@
1
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
2
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
3
- import { type Address, type IsUndefined, type Prettify } from "viem";
4
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_formatSign";
7
- };
1
+ import type { Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
3
+ import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import { type AccountParam } from "../utils/resolve.js";
5
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
6
+ type BaseFormatSignParams = MethodParams<typeof MethodSchema>;
7
+ type FormatSignResponse = MethodResponse<typeof MethodSchema>;
8
+ export type FormatSignParams = Prettify<DistributiveOmit<BaseFormatSignParams, "from" | "chainId"> & {
9
+ account?: AccountParam;
10
+ chainId?: number;
8
11
  }>;
9
- export type FormatSignParams<TAccount extends Address | undefined = Address | undefined> = Prettify<Omit<OptionalChainId<RpcSchema["Request"]["params"][0]>, "from"> & (IsUndefined<TAccount> extends true ? {
10
- from: Address;
11
- } : {
12
- from?: never;
13
- })>;
14
- export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
12
+ export type FormatSignResult = FormatSignResponse;
15
13
  /**
16
14
  * Formats a signature request for signing messages or transactions.
17
15
  *
@@ -23,7 +21,7 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
23
21
  * ```ts
24
22
  * // Formats a signature
25
23
  * const result = await client.formatSign({
26
- * from: "0x1234...",
24
+ * account: "0x1234...",
27
25
  * signature: {
28
26
  * type: "ecdsa",
29
27
  * data: "0xabcd..."
@@ -31,5 +29,5 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
31
29
  * });
32
30
  * ```
33
31
  */
34
- export declare function formatSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: FormatSignParams<TAccount>): Promise<FormatSignResult>;
32
+ export declare function formatSign(client: InnerWalletApiClient, params: FormatSignParams): Promise<FormatSignResult>;
35
33
  export {};
@@ -1,6 +1,9 @@
1
- import { toHex } from "viem";
2
- import { AccountNotFoundError } from "@alchemy/common";
1
+ import { wallet_formatSign 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
  * Formats a signature request for signing messages or transactions.
6
9
  *
@@ -12,7 +15,7 @@ import { LOGGER } from "../logger.js";
12
15
  * ```ts
13
16
  * // Formats a signature
14
17
  * const result = await client.formatSign({
15
- * from: "0x1234...",
18
+ * account: "0x1234...",
16
19
  * signature: {
17
20
  * type: "ecdsa",
18
21
  * data: "0xabcd..."
@@ -21,18 +24,21 @@ import { LOGGER } from "../logger.js";
21
24
  * ```
22
25
  */
23
26
  export async function formatSign(client, params) {
24
- const from = params.from ?? client.account?.address;
25
- if (!from) {
26
- throw new AccountNotFoundError();
27
- }
27
+ const from = params.account
28
+ ? resolveAddress(params.account)
29
+ : client.account.address;
28
30
  LOGGER.debug("formatSign:start");
29
- const res = await client.request({
31
+ const { account: _, chainId: __, ...rest } = params;
32
+ const rpcParams = Value.Encode(schema.request, {
33
+ ...rest,
34
+ from,
35
+ chainId: params.chainId ?? client.chain.id,
36
+ });
37
+ const rpcResp = await client.request({
30
38
  method: "wallet_formatSign",
31
- params: [
32
- { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },
33
- ],
39
+ params: [rpcParams],
34
40
  });
35
41
  LOGGER.debug("formatSign:done");
36
- return res;
42
+ return Value.Decode(schema.response, rpcResp);
37
43
  }
38
44
  //# sourceMappingURL=formatSign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAG9B,MAA4B,EAC5B,MAAkC;IAElC,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,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACvE;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_formatSign\";\n };\n }\n>;\n\nexport type FormatSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n Omit<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>, \"from\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type FormatSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * from: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: FormatSignParams<TAccount>,\n): Promise<FormatSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"formatSign:start\");\n const res = await client.request({\n method: \"wallet_formatSign\",\n params: [\n { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },\n ],\n });\n LOGGER.debug(\"formatSign:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClF,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;AAa1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4B,EAC5B,MAAwB;IAExB,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,kBAAkB,CAAC,CAAC;IAEjC,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;KACZ,CAAC,CAAC;IAElC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,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 { wallet_formatSign 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 BaseFormatSignParams = MethodParams<typeof MethodSchema>;\ntype FormatSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type FormatSignParams = Prettify<\n DistributiveOmit<BaseFormatSignParams, \"from\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n>;\n\nexport type FormatSignResult = FormatSignResponse;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * account: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign(\n client: InnerWalletApiClient,\n params: FormatSignParams,\n): Promise<FormatSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"formatSign:start\");\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 BaseFormatSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_formatSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"formatSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { InnerWalletApiClient } from "../types.js";
2
+ import { type AccountParam } from "../utils/resolve.js";
3
+ export type GetCapabilitiesParams = {
4
+ account?: AccountParam;
5
+ chainId?: number;
6
+ };
7
+ export type GetCapabilitiesResult = Record<string, unknown>;
8
+ /**
9
+ * Gets the capabilities supported by the wallet for the given account.
10
+ * Delegates to viem's `getCapabilities` and renames `paymasterService`
11
+ * to `paymaster` for consistency with the SDK's public API.
12
+ *
13
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
+ * @param {GetCapabilitiesParams} [params] - Optional parameters
15
+ * @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.
16
+ * @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.
17
+ * @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const capabilities = await client.getCapabilities({
22
+ * account: "0x1234...",
23
+ * });
24
+ * // { paymaster: { supported: true }, atomic: { status: "supported" } }
25
+ * ```
26
+ */
27
+ export declare function getCapabilities(client: InnerWalletApiClient, params?: GetCapabilitiesParams): Promise<GetCapabilitiesResult>;
@@ -0,0 +1,49 @@
1
+ import { getCapabilities as viemGetCapabilities } from "viem/actions";
2
+ import { resolveAddress } from "../utils/resolve.js";
3
+ /**
4
+ * Gets the capabilities supported by the wallet for the given account.
5
+ * Delegates to viem's `getCapabilities` and renames `paymasterService`
6
+ * to `paymaster` for consistency with the SDK's public API.
7
+ *
8
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
9
+ * @param {GetCapabilitiesParams} [params] - Optional parameters
10
+ * @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.
11
+ * @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.
12
+ * @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const capabilities = await client.getCapabilities({
17
+ * account: "0x1234...",
18
+ * });
19
+ * // { paymaster: { supported: true }, atomic: { status: "supported" } }
20
+ * ```
21
+ */
22
+ export async function getCapabilities(client, params) {
23
+ const account = params?.account
24
+ ? resolveAddress(params.account)
25
+ : client.account.address;
26
+ const chainId = params?.chainId ?? client.chain.id;
27
+ // Don't pass chainId to viem — the Alchemy API keys capabilities by a
28
+ // generic identifier (0) rather than the actual chain ID, so viem's
29
+ // chainId-based lookup would return undefined.
30
+ const viemResult = await viemGetCapabilities(client, { account });
31
+ // Look for capabilities matching the requested chainId, falling back to
32
+ // the generic "0" key that the Alchemy API uses.
33
+ const chainCaps = viemResult[chainId] ?? viemResult[0];
34
+ if (!chainCaps)
35
+ return {};
36
+ const result = {};
37
+ for (const [key, value] of Object.entries(chainCaps)) {
38
+ // Our paymaster capability interface is non-standard, so we rename it
39
+ // from `paymasterService` to `paymaster` when used in our SDK client.
40
+ if (key === "paymasterService") {
41
+ result["paymaster"] = value;
42
+ }
43
+ else {
44
+ result[key] = value;
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+ //# sourceMappingURL=getCapabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCapabilities.js","sourceRoot":"","sources":["../../../src/actions/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AASxE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO;QAC7B,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAEnD,sEAAsE;IACtE,oEAAoE;IACpE,+CAA+C;IAC/C,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAElE,wEAAwE;IACxE,iDAAiD;IACjD,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAEvD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAE1B,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrD,sEAAsE;QACtE,sEAAsE;QACtE,IAAI,GAAG,KAAK,kBAAkB,EAAE,CAAC;YAC/B,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { getCapabilities as viemGetCapabilities } from \"viem/actions\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\n\nexport type GetCapabilitiesParams = {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type GetCapabilitiesResult = Record<string, unknown>;\n\n/**\n * Gets the capabilities supported by the wallet for the given account.\n * Delegates to viem's `getCapabilities` and renames `paymasterService`\n * to `paymaster` for consistency with the SDK's public API.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GetCapabilitiesParams} [params] - Optional parameters\n * @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.\n * @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.\n * @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain\n *\n * @example\n * ```ts\n * const capabilities = await client.getCapabilities({\n * account: \"0x1234...\",\n * });\n * // { paymaster: { supported: true }, atomic: { status: \"supported\" } }\n * ```\n */\nexport async function getCapabilities(\n client: InnerWalletApiClient,\n params?: GetCapabilitiesParams,\n): Promise<GetCapabilitiesResult> {\n const account = params?.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const chainId = params?.chainId ?? client.chain.id;\n\n // Don't pass chainId to viem — the Alchemy API keys capabilities by a\n // generic identifier (0) rather than the actual chain ID, so viem's\n // chainId-based lookup would return undefined.\n const viemResult = await viemGetCapabilities(client, { account });\n\n // Look for capabilities matching the requested chainId, falling back to\n // the generic \"0\" key that the Alchemy API uses.\n const chainCaps = viemResult[chainId] ?? viemResult[0];\n\n if (!chainCaps) return {};\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(chainCaps)) {\n // Our paymaster capability interface is non-standard, so we rename it\n // from `paymasterService` to `paymaster` when used in our SDK client.\n if (key === \"paymasterService\") {\n result[\"paymaster\"] = value;\n } else {\n result[key] = value;\n }\n }\n\n return result;\n}\n"]}
@@ -1,17 +1,13 @@
1
- import { type Address, type Hex, type IsUndefined, type Prettify } from "viem";
2
- import type { InnerWalletApiClient } from "../types.ts";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { OptionalChainId } from "../types.ts";
5
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
- Request: {
7
- method: "wallet_createSession";
8
- };
1
+ import { type Hex, type Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
3
+ import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import { type AccountParam } from "../utils/resolve.js";
5
+ import { type MethodParams } from "../utils/schema.js";
6
+ type BaseCreateSessionParams = MethodParams<typeof MethodSchema>;
7
+ export type GrantPermissionsParams = Prettify<DistributiveOmit<BaseCreateSessionParams, "account" | "chainId"> & {
8
+ account?: AccountParam;
9
+ chainId?: number;
9
10
  }>;
10
- export type GrantPermissionsParams<TAccount extends Address | undefined = Address | undefined> = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & (IsUndefined<TAccount> extends true ? {
11
- account: Address;
12
- } : {
13
- account?: never;
14
- })>;
15
11
  export type GrantPermissionsResult = Prettify<{
16
12
  context: Hex;
17
13
  }>;
@@ -21,7 +17,7 @@ export type GrantPermissionsResult = Prettify<{
21
17
  *
22
18
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
23
19
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
24
- * @param {Address} [params.account] - The account address (required if client was not initialized with an account)
20
+ * @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.
25
21
  * @param {number} params.expirySec - Unix timestamp when the permissions expire
26
22
  * @param {sessionKeyData} params.key - The session key information
27
23
  * @param {string} params.key.publicKey - The public key of the session key
@@ -47,10 +43,10 @@ export type GrantPermissionsResult = Prettify<{
47
43
  *
48
44
  * // Use the permissions to prepare a call
49
45
  * const preparedCalls = await client.prepareCalls({
50
- * calls: [{ to: zeroAddress, value: "0x0" }],
46
+ * calls: [{ to: zeroAddress, value: 0n }],
51
47
  * from: account.address,
52
48
  * capabilities: {
53
- * paymasterService: {
49
+ * paymaster: {
54
50
  * policyId: "your-paymaster-policy-id",
55
51
  * },
56
52
  * permissions,
@@ -69,5 +65,5 @@ export type GrantPermissionsResult = Prettify<{
69
65
  * });
70
66
  * ```
71
67
  */
72
- export declare function grantPermissions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
68
+ export declare function grantPermissions(client: InnerWalletApiClient, params: GrantPermissionsParams): Promise<GrantPermissionsResult>;
73
69
  export {};
@@ -1,15 +1,18 @@
1
- import { toHex, concatHex, } from "viem";
1
+ import { concatHex } from "viem";
2
+ import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
2
3
  import { signSignatureRequest } from "./signSignatureRequest.js";
3
- import { AccountNotFoundError, BaseError } from "@alchemy/common";
4
4
  import { LOGGER } from "../logger.js";
5
- import { isWebAuthnAccount } from "../utils/assertions.js";
5
+ import { Value } from "typebox/value";
6
+ import { resolveAddress } from "../utils/resolve.js";
7
+ import { methodSchema } from "../utils/schema.js";
8
+ const schema = methodSchema(MethodSchema);
6
9
  /**
7
10
  * Grants permissions to a smart account by creating a session.
8
11
  * This allows another key to perform operations on behalf of the account.
9
12
  *
10
13
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
11
14
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
12
- * @param {Address} [params.account] - The account address (required if client was not initialized with an account)
15
+ * @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.
13
16
  * @param {number} params.expirySec - Unix timestamp when the permissions expire
14
17
  * @param {sessionKeyData} params.key - The session key information
15
18
  * @param {string} params.key.publicKey - The public key of the session key
@@ -35,10 +38,10 @@ import { isWebAuthnAccount } from "../utils/assertions.js";
35
38
  *
36
39
  * // Use the permissions to prepare a call
37
40
  * const preparedCalls = await client.prepareCalls({
38
- * calls: [{ to: zeroAddress, value: "0x0" }],
41
+ * calls: [{ to: zeroAddress, value: 0n }],
39
42
  * from: account.address,
40
43
  * capabilities: {
41
- * paymasterService: {
44
+ * paymaster: {
42
45
  * policyId: "your-paymaster-policy-id",
43
46
  * },
44
47
  * permissions,
@@ -58,34 +61,28 @@ import { isWebAuthnAccount } from "../utils/assertions.js";
58
61
  * ```
59
62
  */
60
63
  export async function grantPermissions(client, params) {
61
- const account = params.account ?? client.account?.address;
62
- if (!account) {
63
- LOGGER.warn("grantPermissions:no-account");
64
- throw new AccountNotFoundError();
65
- }
66
- if (isWebAuthnAccount(client.owner)) {
67
- LOGGER.warn("grantPermissions:unsupported-account");
68
- throw new BaseError("WebAuthn signer is not currently supported for grantPermissions");
69
- }
64
+ const account = params.account
65
+ ? resolveAddress(params.account)
66
+ : client.account.address;
70
67
  LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
71
- const { sessionId, signatureRequest } = await client.request({
68
+ const chainId = params.chainId ?? client.chain.id;
69
+ const { account: _, chainId: __, ...rest } = params;
70
+ const rpcParams = Value.Encode(schema.request, {
71
+ ...rest,
72
+ account,
73
+ chainId,
74
+ });
75
+ const rpcResp = await client.request({
72
76
  method: "wallet_createSession",
73
- params: [
74
- {
75
- ...params,
76
- account,
77
- chainId: params.chainId ?? toHex(client.chain.id),
78
- },
79
- ],
77
+ params: [rpcParams],
80
78
  });
79
+ const { sessionId, signatureRequest } = Value.Decode(schema.response, rpcResp);
81
80
  const signature = await signSignatureRequest(client, signatureRequest);
82
81
  const res = {
83
82
  context: concatHex([
84
83
  "0x00", // Remote mode.
85
84
  sessionId,
86
- signature.type === "webauthn-p256"
87
- ? signature.data.signature
88
- : signature.data,
85
+ signature.data,
89
86
  ]),
90
87
  };
91
88
  LOGGER.debug("grantPermissions:done");
@@ -1 +1 @@
1
- {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAKL,SAAS,GACV,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAGpC,MAA4B,EAC5B,MAAwC;IAExC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACpD,MAAM,IAAI,SAAS,CACjB,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC3D,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO;gBACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAEvE,MAAM,GAAG,GAAG;QACV,OAAO,EAAE,SAAS,CAAC;YACjB,MAAM,EAAE,eAAe;YACvB,SAAS;YACT,SAAS,CAAC,IAAI,KAAK,eAAe;gBAChC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;gBAC1B,CAAC,CAAC,SAAS,CAAC,IAAI;SACnB,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {\n toHex,\n type Address,\n type Hex,\n type IsUndefined,\n type Prettify,\n concatHex,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport type { OptionalChainId } from \"../types.ts\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_createSession\";\n };\n }\n>;\n\nexport type GrantPermissionsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> &\n (IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: never })\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {Address} [params.account] - The account address (required if client was not initialized with an account)\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams<TAccount>,\n): Promise<GrantPermissionsResult> {\n const account = params.account ?? client.account?.address;\n if (!account) {\n LOGGER.warn(\"grantPermissions:no-account\");\n throw new AccountNotFoundError();\n }\n if (isWebAuthnAccount(client.owner)) {\n LOGGER.warn(\"grantPermissions:unsupported-account\");\n throw new BaseError(\n \"WebAuthn signer is not currently supported for grantPermissions\",\n );\n }\n\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n const { sessionId, signatureRequest } = await client.request({\n method: \"wallet_createSession\",\n params: [\n {\n ...params,\n account,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.type === \"webauthn-p256\"\n ? signature.data.signature\n : signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1D,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAErE,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO;QAC5B,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAExE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAElD,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,OAAO;KAC0B,CAAC,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC,MAAM,CAClD,MAAM,CAAC,QAAQ,EACf,OAAO,CAIR,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAEvE,MAAM,GAAG,GAAG;QACV,OAAO,EAAE,SAAS,CAAC;YACjB,MAAM,EAAE,eAAe;YACvB,SAAS;YACT,SAAS,CAAC,IAAI;SACf,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { type Hex, type Prettify, concatHex } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_createSession as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { Value } from \"typebox/value\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseCreateSessionParams = MethodParams<typeof MethodSchema>;\n\nexport type GrantPermissionsParams = Prettify<\n DistributiveOmit<BaseCreateSessionParams, \"account\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: 0n }],\n * from: account.address,\n * capabilities: {\n * paymaster: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams,\n): Promise<GrantPermissionsResult> {\n const account = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n\n const chainId = params.chainId ?? client.chain.id;\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n account,\n chainId,\n } satisfies BaseCreateSessionParams);\n\n const rpcResp = await client.request({\n method: \"wallet_createSession\",\n params: [rpcParams],\n });\n\n const { sessionId, signatureRequest } = Value.Decode(\n schema.response,\n rpcResp,\n ) satisfies {\n sessionId: Hex;\n signatureRequest: Parameters<typeof signSignatureRequest>[1];\n };\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
@@ -1,23 +1,14 @@
1
- import type { InnerWalletApiClient } from "../types.ts";
1
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
2
2
  import type { Address, Prettify } from "viem";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
5
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
- Request: {
7
- method: "wallet_listAccounts";
8
- };
9
- }>;
10
- export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & ({
3
+ import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
5
+ type BaseListAccountsParams = MethodParams<typeof MethodSchema>;
6
+ type ListAccountsResponse = MethodResponse<typeof MethodSchema>;
7
+ export type ListAccountsParams = Prettify<DistributiveOmit<BaseListAccountsParams, "signerAddress" | "signerPublicKey"> & {
11
8
  signerAddress?: Address;
12
9
  signerPublicKey?: never;
13
- } | {
14
- signerPublicKey: WebAuthnPublicKey;
15
- signerAddress?: never;
16
- } | {
17
- signerAddress?: never;
18
- signerPublicKey?: never;
19
- })>;
20
- export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
10
+ }>;
11
+ export type ListAccountsResult = ListAccountsResponse;
21
12
  /**
22
13
  * Lists all smart accounts for a given signer using the wallet API client.
23
14
  *
@@ -1,5 +1,9 @@
1
1
  import { LOGGER } from "../logger.js";
2
- import { getSignerAddressOrPublicKey } from "../utils/signer.js";
2
+ import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
3
+ import { isLocalAccount } from "../utils/assertions.js";
4
+ import { Value } from "typebox/value";
5
+ import { methodSchema, } from "../utils/schema.js";
6
+ const schema = methodSchema(MethodSchema);
3
7
  /**
4
8
  * Lists all smart accounts for a given signer using the wallet API client.
5
9
  *
@@ -27,37 +31,20 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
27
31
  * ```
28
32
  */
29
33
  export async function listAccounts(client, params) {
30
- const owner = getSignerAddressOrPublicKey(client.owner);
31
- // Coalesce:
32
- // signerAddress or signerPublicKey in params takes priority.
33
- // if not present, then fallback to client's attached signer.
34
- const signerParam = params.signerAddress
35
- ? { signerAddress: params.signerAddress }
36
- : params.signerPublicKey
37
- ? {
38
- signerPublicKey: {
39
- type: "webauthn-p256",
40
- ...params.signerPublicKey,
41
- },
42
- }
43
- : owner.type === "webauthn-p256"
44
- ? {
45
- signerPublicKey: {
46
- type: "webauthn-p256",
47
- ...owner.publicKey,
48
- },
49
- }
50
- : { signerAddress: owner.address };
34
+ const signerAddress = params.signerAddress ??
35
+ (isLocalAccount(client.owner)
36
+ ? client.owner.address
37
+ : client.owner.account.address);
51
38
  LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
52
- const res = await client.request({
39
+ const rpcParams = Value.Encode(schema.request, {
40
+ ...params,
41
+ signerAddress,
42
+ });
43
+ const rpcResp = await client.request({
53
44
  method: "wallet_listAccounts",
54
- params: [
55
- {
56
- ...params,
57
- ...signerParam,
58
- },
59
- ],
45
+ params: [rpcParams],
60
46
  });
47
+ const res = Value.Decode(schema.response, rpcResp);
61
48
  LOGGER.debug("listAccounts:done", { count: res.accounts.length });
62
49
  return res;
63
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AA6BjE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,KAAK,GAAG,2BAA2B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExD,YAAY;IACZ,6DAA6D;IAC7D,6DAA6D;IAC7D,MAAM,WAAW,GAAsC,MAAM,CAAC,aAAa;QACzE,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE;QACzC,CAAC,CAAC,MAAM,CAAC,eAAe;YACtB,CAAC,CAAC;gBACE,eAAe,EAAE;oBACf,IAAI,EAAE,eAAe;oBACrB,GAAG,MAAM,CAAC,eAAe;iBAC1B;aACF;YACH,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe;gBAC9B,CAAC,CAAC;oBACE,eAAe,EAAE;wBACf,IAAI,EAAE,eAAe;wBACrB,GAAG,KAAK,CAAC,SAAS;qBACnB;iBACF;gBACH,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAEzC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,GAAG,WAAW;aACf;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { getSignerAddressOrPublicKey } from \"../utils/signer.js\";\nimport type { WebAuthnPublicKey } from \"@alchemy/wallet-api-types\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<RpcSchema[\"Request\"][\"params\"][0], \"signerAddress\"> &\n (\n | {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n | { signerPublicKey: WebAuthnPublicKey; signerAddress?: never }\n | {\n signerAddress?: never;\n signerPublicKey?: never;\n }\n )\n>;\n\nexport type ListAccountsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Lists all smart accounts for a given signer using the wallet API client.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {ListAccountsParams} params - Parameters for listing accounts\n * @param {string} params.signerAddress - The address of the signer to list accounts for\n * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)\n * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages\n * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata\n *\n * @example\n * ```ts\n * // Fetch the first page of accounts\n * const firstPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10\n * });\n *\n * // If an 'after' cursor exists, use it to fetch the next page\n * const nextPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10,\n * after: firstPage.meta.after\n * });\n * ```\n */\nexport async function listAccounts(\n client: InnerWalletApiClient,\n params: ListAccountsParams,\n): Promise<ListAccountsResult> {\n const owner = getSignerAddressOrPublicKey(client.owner);\n\n // Coalesce:\n // signerAddress or signerPublicKey in params takes priority.\n // if not present, then fallback to client's attached signer.\n const signerParam: RpcSchema[\"Request\"][\"params\"][0] = params.signerAddress\n ? { signerAddress: params.signerAddress }\n : params.signerPublicKey\n ? {\n signerPublicKey: {\n type: \"webauthn-p256\",\n ...params.signerPublicKey,\n },\n }\n : owner.type === \"webauthn-p256\"\n ? {\n signerPublicKey: {\n type: \"webauthn-p256\",\n ...owner.publicKey,\n },\n }\n : { signerAddress: owner.address };\n\n LOGGER.debug(\"listAccounts:start\", { hasAfter: !!params.after });\n const res = await client.request({\n method: \"wallet_listAccounts\",\n params: [\n {\n ...params,\n ...signerParam,\n },\n ],\n });\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
1
+ {"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa;QACpB,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,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAEjE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,MAAM;QACT,aAAa;KACmB,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,GAAG,GAAG,KAAK,CAAC,MAAM,CACtB,MAAM,CAAC,QAAQ,EACf,OAAO,CACqB,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport { wallet_listAccounts as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { isLocalAccount } from \"../utils/assertions.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 BaseListAccountsParams = MethodParams<typeof MethodSchema>;\ntype ListAccountsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type ListAccountsParams = Prettify<\n DistributiveOmit<\n BaseListAccountsParams,\n \"signerAddress\" | \"signerPublicKey\"\n > & {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n>;\n\nexport type ListAccountsResult = ListAccountsResponse;\n\n/**\n * Lists all smart accounts for a given signer using the wallet API client.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {ListAccountsParams} params - Parameters for listing accounts\n * @param {string} params.signerAddress - The address of the signer to list accounts for\n * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)\n * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages\n * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata\n *\n * @example\n * ```ts\n * // Fetch the first page of accounts\n * const firstPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10\n * });\n *\n * // If an 'after' cursor exists, use it to fetch the next page\n * const nextPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10,\n * after: firstPage.meta.after\n * });\n * ```\n */\nexport async function listAccounts(\n client: InnerWalletApiClient,\n params: ListAccountsParams,\n): Promise<ListAccountsResult> {\n const signerAddress =\n params.signerAddress ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n LOGGER.debug(\"listAccounts:start\", { hasAfter: !!params.after });\n\n const rpcParams = Value.Encode(schema.request, {\n ...params,\n signerAddress,\n } satisfies BaseListAccountsParams);\n\n const rpcResp = await client.request({\n method: \"wallet_listAccounts\",\n params: [rpcParams],\n });\n\n const res = Value.Decode(\n schema.response,\n rpcResp,\n ) satisfies ListAccountsResult;\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
@@ -1,44 +1,46 @@
1
- import { type Address, type IsUndefined, type Prettify } from "viem";
2
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_prepareCalls";
7
- };
8
- }>;
9
- export type PrepareCallsParams<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 PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
1
+ import type { Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
3
+ import { type WithCapabilities } from "../utils/capabilities.js";
4
+ import { type AccountParam } from "../utils/resolve.js";
5
+ import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
6
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
7
+ type BasePrepareCallsParams = MethodParams<typeof MethodSchema>;
8
+ type PrepareCallsResponse = MethodResponse<typeof MethodSchema>;
9
+ export type PrepareCallsParams = Prettify<WithCapabilities<DistributiveOmit<BasePrepareCallsParams, "from" | "chainId"> & {
10
+ account?: AccountParam;
11
+ chainId?: number;
12
+ }>>;
13
+ export type PrepareCallsResult = PrepareCallsResponse;
15
14
  /**
16
15
  * Prepares a set of contract calls for execution by building a user operation.
17
16
  * Returns the built user operation and a signature request that needs to be signed
18
17
  * before submitting to sendPreparedCalls.
19
18
  *
20
- * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
21
- * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
22
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
23
- * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
19
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
20
+ * this directly without first calling `requestAccount`.
21
+ *
22
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
23
+ * @param {PrepareCallsParams} params - Parameters for preparing calls
24
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
25
+ * @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).
24
26
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
25
27
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
26
28
  * the user operation data and signature request
27
29
  *
28
30
  * @example
29
31
  * ```ts
30
- * // Prepare a sponsored user operation call
32
+ * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
31
33
  * const result = await client.prepareCalls({
32
34
  * calls: [{
33
35
  * to: "0x1234...",
34
36
  * data: "0xabcdef...",
35
- * value: "0x0"
37
+ * value: 0n
36
38
  * }],
37
39
  * capabilities: {
38
- * paymasterService: { policyId: "your-policy-id" }
40
+ * paymaster: { policyId: "your-policy-id" }
39
41
  * }
40
42
  * });
41
43
  * ```
42
44
  */
43
- export declare function prepareCalls<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareCallsParams<TAccount>): Promise<PrepareCallsResult>;
45
+ export declare function prepareCalls(client: InnerWalletApiClient, params: PrepareCallsParams): Promise<PrepareCallsResult>;
44
46
  export {};