@alchemy/wallet-apis 0.0.0-alpha.18 → 0.0.0-alpha.20

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 (142) hide show
  1. package/dist/esm/actions/formatSign.d.ts +12 -10
  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 +12 -14
  8. package/dist/esm/actions/grantPermissions.js +22 -18
  9. package/dist/esm/actions/grantPermissions.js.map +1 -1
  10. package/dist/esm/actions/listAccounts.d.ts +7 -9
  11. package/dist/esm/actions/listAccounts.js +11 -7
  12. package/dist/esm/actions/listAccounts.js.map +1 -1
  13. package/dist/esm/actions/prepareCalls.d.ts +27 -13
  14. package/dist/esm/actions/prepareCalls.js +39 -22
  15. package/dist/esm/actions/prepareCalls.js.map +1 -1
  16. package/dist/esm/actions/prepareSign.d.ts +12 -11
  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 +7 -12
  20. package/dist/esm/actions/requestAccount.js +10 -2
  21. package/dist/esm/actions/requestAccount.js.map +1 -1
  22. package/dist/esm/actions/sendCalls.d.ts +10 -8
  23. package/dist/esm/actions/sendCalls.js +11 -9
  24. package/dist/esm/actions/sendCalls.js.map +1 -1
  25. package/dist/esm/actions/sendPreparedCalls.d.ts +13 -12
  26. package/dist/esm/actions/sendPreparedCalls.js +21 -15
  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 +7 -4
  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 +1 -1
  33. package/dist/esm/actions/signPreparedCalls.js.map +1 -1
  34. package/dist/esm/actions/signSignatureRequest.d.ts +3 -2
  35. package/dist/esm/actions/signSignatureRequest.js +4 -9
  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 +6 -3
  39. package/dist/esm/actions/signTypedData.js.map +1 -1
  40. package/dist/esm/client.d.ts +1 -1
  41. package/dist/esm/client.js +1 -1
  42. package/dist/esm/client.js.map +1 -1
  43. package/dist/esm/decorators/smartWalletActions.d.ts +3 -2
  44. package/dist/esm/decorators/smartWalletActions.js +4 -3
  45. package/dist/esm/decorators/smartWalletActions.js.map +1 -1
  46. package/dist/esm/experimental/actions/requestQuoteV0.d.ts +17 -14
  47. package/dist/esm/experimental/actions/requestQuoteV0.js +25 -22
  48. package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
  49. package/dist/esm/exports/index.d.ts +2 -0
  50. package/dist/esm/exports/index.js +1 -0
  51. package/dist/esm/exports/index.js.map +1 -1
  52. package/dist/esm/types.d.ts +3 -2
  53. package/dist/esm/types.js.map +1 -1
  54. package/dist/esm/utils/capabilities.d.ts +48 -2
  55. package/dist/esm/utils/capabilities.js +58 -11
  56. package/dist/esm/utils/capabilities.js.map +1 -1
  57. package/dist/esm/utils/resolve.d.ts +7 -0
  58. package/dist/esm/utils/resolve.js +4 -0
  59. package/dist/esm/utils/resolve.js.map +1 -0
  60. package/dist/esm/utils/schema.d.ts +24 -0
  61. package/dist/esm/utils/schema.js +7 -0
  62. package/dist/esm/utils/schema.js.map +1 -0
  63. package/dist/esm/version.d.ts +1 -1
  64. package/dist/esm/version.js +1 -1
  65. package/dist/esm/version.js.map +1 -1
  66. package/dist/types/actions/formatSign.d.ts +12 -10
  67. package/dist/types/actions/formatSign.d.ts.map +1 -1
  68. package/dist/types/actions/getCapabilities.d.ts +28 -0
  69. package/dist/types/actions/getCapabilities.d.ts.map +1 -0
  70. package/dist/types/actions/grantPermissions.d.ts +12 -14
  71. package/dist/types/actions/grantPermissions.d.ts.map +1 -1
  72. package/dist/types/actions/listAccounts.d.ts +7 -9
  73. package/dist/types/actions/listAccounts.d.ts.map +1 -1
  74. package/dist/types/actions/prepareCalls.d.ts +27 -13
  75. package/dist/types/actions/prepareCalls.d.ts.map +1 -1
  76. package/dist/types/actions/prepareSign.d.ts +12 -11
  77. package/dist/types/actions/prepareSign.d.ts.map +1 -1
  78. package/dist/types/actions/requestAccount.d.ts +7 -12
  79. package/dist/types/actions/requestAccount.d.ts.map +1 -1
  80. package/dist/types/actions/sendCalls.d.ts +10 -8
  81. package/dist/types/actions/sendCalls.d.ts.map +1 -1
  82. package/dist/types/actions/sendPreparedCalls.d.ts +13 -12
  83. package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
  84. package/dist/types/actions/signMessage.d.ts +4 -3
  85. package/dist/types/actions/signMessage.d.ts.map +1 -1
  86. package/dist/types/actions/signPreparedCalls.d.ts +18 -2
  87. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
  88. package/dist/types/actions/signSignatureRequest.d.ts +3 -2
  89. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
  90. package/dist/types/actions/signTypedData.d.ts +3 -2
  91. package/dist/types/actions/signTypedData.d.ts.map +1 -1
  92. package/dist/types/client.d.ts +1 -1
  93. package/dist/types/decorators/smartWalletActions.d.ts +3 -2
  94. package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
  95. package/dist/types/experimental/actions/requestQuoteV0.d.ts +17 -14
  96. package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
  97. package/dist/types/exports/index.d.ts +2 -0
  98. package/dist/types/exports/index.d.ts.map +1 -1
  99. package/dist/types/types.d.ts +3 -2
  100. package/dist/types/types.d.ts.map +1 -1
  101. package/dist/types/utils/capabilities.d.ts +48 -2
  102. package/dist/types/utils/capabilities.d.ts.map +1 -1
  103. package/dist/types/utils/resolve.d.ts +8 -0
  104. package/dist/types/utils/resolve.d.ts.map +1 -0
  105. package/dist/types/utils/schema.d.ts +25 -0
  106. package/dist/types/utils/schema.d.ts.map +1 -0
  107. package/dist/types/version.d.ts +1 -1
  108. package/package.json +5 -5
  109. package/src/actions/formatSign.ts +34 -28
  110. package/src/actions/getCapabilities.ts +64 -0
  111. package/src/actions/grantPermissions.ts +38 -31
  112. package/src/actions/listAccounts.ts +27 -20
  113. package/src/actions/prepareCalls.ts +82 -38
  114. package/src/actions/prepareSign.ts +36 -35
  115. package/src/actions/requestAccount.ts +21 -16
  116. package/src/actions/sendCalls.ts +18 -12
  117. package/src/actions/sendPreparedCalls.ts +48 -27
  118. package/src/actions/signMessage.ts +9 -11
  119. package/src/actions/signPreparedCalls.ts +32 -12
  120. package/src/actions/signSignatureRequest.ts +9 -14
  121. package/src/actions/signTypedData.ts +8 -10
  122. package/src/client.ts +1 -1
  123. package/src/decorators/smartWalletActions.ts +9 -7
  124. package/src/experimental/actions/requestQuoteV0.ts +51 -39
  125. package/src/exports/index.ts +2 -0
  126. package/src/types.ts +6 -2
  127. package/src/utils/capabilities.ts +118 -17
  128. package/src/utils/resolve.ts +11 -0
  129. package/src/utils/schema.ts +32 -0
  130. package/src/version.ts +1 -1
  131. package/dist/esm/utils/viemDecode.d.ts +0 -8
  132. package/dist/esm/utils/viemDecode.js +0 -231
  133. package/dist/esm/utils/viemDecode.js.map +0 -1
  134. package/dist/esm/utils/viemEncode.d.ts +0 -40
  135. package/dist/esm/utils/viemEncode.js +0 -216
  136. package/dist/esm/utils/viemEncode.js.map +0 -1
  137. package/dist/types/utils/viemDecode.d.ts +0 -9
  138. package/dist/types/utils/viemDecode.d.ts.map +0 -1
  139. package/dist/types/utils/viemEncode.d.ts +0 -41
  140. package/dist/types/utils/viemEncode.d.ts.map +0 -1
  141. package/src/utils/viemDecode.ts +0 -313
  142. package/src/utils/viemEncode.ts +0 -345
@@ -1,13 +1,15 @@
1
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
2
- import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
3
- import { 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 = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
10
- export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
12
+ export type FormatSignResult = FormatSignResponse;
11
13
  /**
12
14
  * Formats a signature request for signing messages or transactions.
13
15
  *
@@ -19,7 +21,7 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
19
21
  * ```ts
20
22
  * // Formats a signature
21
23
  * const result = await client.formatSign({
22
- * from: "0x1234...",
24
+ * account: "0x1234...",
23
25
  * signature: {
24
26
  * type: "ecdsa",
25
27
  * data: "0xabcd..."
@@ -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":"AAMA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4B,EAC5B,MAAwB;IAExB,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 {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { toHex, 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 = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\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 client: InnerWalletApiClient,\n params: FormatSignParams,\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,14 +1,12 @@
1
- import { type Address, type Hex, 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
- };
9
- }>;
10
- export type GrantPermissionsParams = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & {
11
- account?: Address;
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;
12
10
  }>;
13
11
  export type GrantPermissionsResult = Prettify<{
14
12
  context: Hex;
@@ -19,7 +17,7 @@ export type GrantPermissionsResult = Prettify<{
19
17
  *
20
18
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
21
19
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
22
- * @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.
23
21
  * @param {number} params.expirySec - Unix timestamp when the permissions expire
24
22
  * @param {sessionKeyData} params.key - The session key information
25
23
  * @param {string} params.key.publicKey - The public key of the session key
@@ -45,10 +43,10 @@ export type GrantPermissionsResult = Prettify<{
45
43
  *
46
44
  * // Use the permissions to prepare a call
47
45
  * const preparedCalls = await client.prepareCalls({
48
- * calls: [{ to: zeroAddress, value: "0x0" }],
46
+ * calls: [{ to: zeroAddress, value: 0n }],
49
47
  * from: account.address,
50
48
  * capabilities: {
51
- * paymasterService: {
49
+ * paymaster: {
52
50
  * policyId: "your-paymaster-policy-id",
53
51
  * },
54
52
  * permissions,
@@ -1,14 +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 } from "@alchemy/common";
4
4
  import { LOGGER } from "../logger.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);
5
9
  /**
6
10
  * Grants permissions to a smart account by creating a session.
7
11
  * This allows another key to perform operations on behalf of the account.
8
12
  *
9
13
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
10
14
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
11
- * @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.
12
16
  * @param {number} params.expirySec - Unix timestamp when the permissions expire
13
17
  * @param {sessionKeyData} params.key - The session key information
14
18
  * @param {string} params.key.publicKey - The public key of the session key
@@ -34,10 +38,10 @@ import { LOGGER } from "../logger.js";
34
38
  *
35
39
  * // Use the permissions to prepare a call
36
40
  * const preparedCalls = await client.prepareCalls({
37
- * calls: [{ to: zeroAddress, value: "0x0" }],
41
+ * calls: [{ to: zeroAddress, value: 0n }],
38
42
  * from: account.address,
39
43
  * capabilities: {
40
- * paymasterService: {
44
+ * paymaster: {
41
45
  * policyId: "your-paymaster-policy-id",
42
46
  * },
43
47
  * permissions,
@@ -57,22 +61,22 @@ import { LOGGER } from "../logger.js";
57
61
  * ```
58
62
  */
59
63
  export async function grantPermissions(client, params) {
60
- const account = params.account ?? client.account.address;
61
- if (!account) {
62
- LOGGER.warn("grantPermissions:no-account");
63
- throw new AccountNotFoundError();
64
- }
64
+ const account = params.account
65
+ ? resolveAddress(params.account)
66
+ : client.account.address;
65
67
  LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
66
- 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({
67
76
  method: "wallet_createSession",
68
- params: [
69
- {
70
- ...params,
71
- account,
72
- chainId: params.chainId ?? toHex(client.chain.id),
73
- },
74
- ],
77
+ params: [rpcParams],
75
78
  });
79
+ const { sessionId, signatureRequest } = Value.Decode(schema.response, rpcResp);
76
80
  const signature = await signSignatureRequest(client, signatureRequest);
77
81
  const res = {
78
82
  context: concatHex([
@@ -1 +1 @@
1
- {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAyC,SAAS,EAAE,MAAM,MAAM,CAAC;AAG/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsBtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,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;SACf,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Address, type Hex, type Prettify, concatHex } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport type { OptionalChainId } from \"../types.ts\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_createSession\";\n };\n }\n>;\n\nexport type GrantPermissionsParams = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> & {\n account?: Address;\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 {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 client: InnerWalletApiClient,\n params: GrantPermissionsParams,\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 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.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,16 +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
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_listAccounts";
7
- };
8
- }>;
9
- export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress" | "signerPublicKey"> & {
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"> & {
10
8
  signerAddress?: Address;
11
9
  signerPublicKey?: never;
12
10
  }>;
13
- export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
11
+ export type ListAccountsResult = ListAccountsResponse;
14
12
  /**
15
13
  * Lists all smart accounts for a given signer using the wallet API client.
16
14
  *
@@ -1,5 +1,9 @@
1
1
  import { LOGGER } from "../logger.js";
2
+ import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
2
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
  *
@@ -32,15 +36,15 @@ export async function listAccounts(client, params) {
32
36
  ? client.owner.address
33
37
  : client.owner.account.address);
34
38
  LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
35
- const res = await client.request({
39
+ const rpcParams = Value.Encode(schema.request, {
40
+ ...params,
41
+ signerAddress,
42
+ });
43
+ const rpcResp = await client.request({
36
44
  method: "wallet_listAccounts",
37
- params: [
38
- {
39
- ...params,
40
- signerAddress,
41
- },
42
- ],
45
+ params: [rpcParams],
43
46
  });
47
+ const res = Value.Decode(schema.response, rpcResp);
44
48
  LOGGER.debug("listAccounts:done", { count: res.accounts.length });
45
49
  return res;
46
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,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAuBxD;;;;;;;;;;;;;;;;;;;;;;;;;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;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,aAAa;aACd;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 { isLocalAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<\n RpcSchema[\"Request\"][\"params\"][0],\n \"signerAddress\" | \"signerPublicKey\"\n > & {\n signerAddress?: Address;\n signerPublicKey?: never;\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 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 const res = await client.request({\n method: \"wallet_listAccounts\",\n params: [\n {\n ...params,\n signerAddress,\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,13 +1,27 @@
1
- import { type Prettify } from "viem";
2
- import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } 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
- };
1
+ import type { Address, Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
3
+ import { type PrepareCallsCapabilities, 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
+ /** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
14
+ type ClientModifiedRequest = Prettify<Omit<BasePrepareCallsParams, "from" | "capabilities"> & {
15
+ account: Address;
16
+ capabilities?: PrepareCallsCapabilities;
8
17
  }>;
9
- export type PrepareCallsParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
10
- export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
18
+ export type PrepareCallsResult = Exclude<PrepareCallsResponse, {
19
+ type: "paymaster-permit";
20
+ }> | (Omit<Extract<PrepareCallsResponse, {
21
+ type: "paymaster-permit";
22
+ }>, "modifiedRequest"> & {
23
+ modifiedRequest: ClientModifiedRequest;
24
+ });
11
25
  /**
12
26
  * Prepares a set of contract calls for execution by building a user operation.
13
27
  * Returns the built user operation and a signature request that needs to be signed
@@ -18,8 +32,8 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
18
32
  *
19
33
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
20
34
  * @param {PrepareCallsParams} params - Parameters for preparing calls
21
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
22
- * @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
35
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
36
+ * @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).
23
37
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
24
38
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
25
39
  * the user operation data and signature request
@@ -31,10 +45,10 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
31
45
  * calls: [{
32
46
  * to: "0x1234...",
33
47
  * data: "0xabcdef...",
34
- * value: "0x0"
48
+ * value: 0n
35
49
  * }],
36
50
  * capabilities: {
37
- * paymasterService: { policyId: "your-policy-id" }
51
+ * paymaster: { policyId: "your-policy-id" }
38
52
  * }
39
53
  * });
40
54
  * ```
@@ -1,7 +1,10 @@
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 { fromRpcCapabilities, 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
@@ -12,8 +15,8 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
12
15
  *
13
16
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
17
  * @param {PrepareCallsParams} params - Parameters for preparing calls
15
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
16
- * @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
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).
17
20
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
18
21
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
19
22
  * the user operation data and signature request
@@ -25,37 +28,51 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
25
28
  * calls: [{
26
29
  * to: "0x1234...",
27
30
  * data: "0xabcdef...",
28
- * value: "0x0"
31
+ * value: 0n
29
32
  * }],
30
33
  * capabilities: {
31
- * paymasterService: { policyId: "your-policy-id" }
34
+ * paymaster: { policyId: "your-policy-id" }
32
35
  * }
33
36
  * });
34
37
  * ```
35
38
  */
36
39
  export async function prepareCalls(client, params) {
37
- const from = params.from ?? client.account?.address;
38
- if (!from) {
39
- LOGGER.warn("prepareCalls:no-from", { hasClientAccount: !!client.account });
40
- throw new AccountNotFoundError();
41
- }
40
+ const from = params.account
41
+ ? resolveAddress(params.account)
42
+ : client.account.address;
43
+ const chainId = params.chainId ?? client.chain.id;
42
44
  const capabilities = mergeClientCapabilities(client, params.capabilities);
43
45
  LOGGER.debug("prepareCalls:start", {
44
46
  callsCount: params.calls?.length,
45
47
  hasCapabilities: !!params.capabilities,
46
48
  });
47
- 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({
48
57
  method: "wallet_prepareCalls",
49
- params: [
50
- {
51
- ...params,
52
- chainId: params.chainId ?? toHex(client.chain.id),
53
- from,
54
- capabilities,
55
- },
56
- ],
58
+ params: [rpcParams],
57
59
  });
58
60
  LOGGER.debug("prepareCalls:done");
59
- return res;
61
+ const decoded = Value.Decode(schema.response, rpcResp);
62
+ // Transform paymaster-permit modifiedRequest from RPC format to client format:
63
+ // - `from` (RPC) → `account` (client)
64
+ // - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
65
+ if (decoded.type === "paymaster-permit") {
66
+ const { from, capabilities, ...restModifiedRequest } = decoded.modifiedRequest;
67
+ return {
68
+ ...decoded,
69
+ modifiedRequest: {
70
+ ...restModifiedRequest,
71
+ account: from,
72
+ capabilities: fromRpcCapabilities(capabilities),
73
+ },
74
+ };
75
+ }
76
+ return decoded;
60
77
  }
61
78
  //# sourceMappingURL=prepareCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAM5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAkBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,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 Prettify } from \"viem\";\nimport type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} 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 = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\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 * 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?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from. 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: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { 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.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,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAGlB,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;AA8B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEvD,+EAA+E;IAC/E,sCAAsC;IACtC,8EAA8E;IAC9E,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACxC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,mBAAmB,EAAE,GAClD,OAAO,CAAC,eAAe,CAAC;QAC1B,OAAO;YACL,GAAG,OAAO;YACV,eAAe,EAAE;gBACf,GAAG,mBAAmB;gBACtB,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,mBAAmB,CAAC,YAAY,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Address, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n fromRpcCapabilities,\n mergeClientCapabilities,\n toRpcCapabilities,\n type PrepareCallsCapabilities,\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\n/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */\ntype ClientModifiedRequest = Prettify<\n Omit<BasePrepareCallsParams, \"from\" | \"capabilities\"> & {\n account: Address;\n capabilities?: PrepareCallsCapabilities;\n }\n>;\n\nexport type PrepareCallsResult =\n | Exclude<PrepareCallsResponse, { type: \"paymaster-permit\" }>\n | (Omit<\n Extract<PrepareCallsResponse, { type: \"paymaster-permit\" }>,\n \"modifiedRequest\"\n > & {\n modifiedRequest: ClientModifiedRequest;\n });\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 const decoded = Value.Decode(schema.response, rpcResp);\n\n // Transform paymaster-permit modifiedRequest from RPC format to client format:\n // - `from` (RPC) → `account` (client)\n // - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)\n if (decoded.type === \"paymaster-permit\") {\n const { from, capabilities, ...restModifiedRequest } =\n decoded.modifiedRequest;\n return {\n ...decoded,\n modifiedRequest: {\n ...restModifiedRequest,\n account: from,\n capabilities: fromRpcCapabilities(capabilities),\n },\n };\n }\n\n return decoded;\n}\n"]}