@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,14 @@
1
- import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
2
- import { type Prettify } from "viem";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_prepareSign";
7
- };
8
- }>;
9
- export type PrepareSignParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
10
- export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
1
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
2
+ import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
3
+ import { type AccountParam } from "../utils/resolve.js";
4
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
5
+ type BasePrepareSignParams = MethodParams<typeof MethodSchema>;
6
+ type PrepareSignResponse = MethodResponse<typeof MethodSchema>;
7
+ export type PrepareSignParams = DistributiveOmit<BasePrepareSignParams, "from" | "chainId"> & {
8
+ account?: AccountParam;
9
+ chainId?: number;
10
+ };
11
+ export type PrepareSignResult = PrepareSignResponse;
11
12
  /**
12
13
  * Prepares a signature request for signing messages or transactions.
13
14
  *
@@ -19,7 +20,7 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
19
20
  * ```ts
20
21
  * // Prepare a message to be signed
21
22
  * const result = await client.prepareSign({
22
- * from: "0x1234...",
23
+ * account: "0x1234...",
23
24
  * type: "personal_sign",
24
25
  * data: "Hello, world!",
25
26
  * });
@@ -1,6 +1,9 @@
1
- import { toHex } from "viem";
2
- import { AccountNotFoundError } from "@alchemy/common";
1
+ import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
3
2
  import { LOGGER } from "../logger.js";
3
+ import { resolveAddress } from "../utils/resolve.js";
4
+ import { Value } from "typebox/value";
5
+ import { methodSchema, } from "../utils/schema.js";
6
+ const schema = methodSchema(MethodSchema);
4
7
  /**
5
8
  * Prepares a signature request for signing messages or transactions.
6
9
  *
@@ -12,30 +15,28 @@ import { LOGGER } from "../logger.js";
12
15
  * ```ts
13
16
  * // Prepare a message to be signed
14
17
  * const result = await client.prepareSign({
15
- * from: "0x1234...",
18
+ * account: "0x1234...",
16
19
  * type: "personal_sign",
17
20
  * data: "Hello, world!",
18
21
  * });
19
22
  * ```
20
23
  */
21
24
  export async function prepareSign(client, params) {
22
- const from = params.from ?? client.account?.address;
23
- if (!from) {
24
- LOGGER.warn("prepareSign:no-from", { hasClientAccount: !!client.account });
25
- throw new AccountNotFoundError();
26
- }
25
+ const from = params.account
26
+ ? resolveAddress(params.account)
27
+ : client.account.address;
27
28
  LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
28
- const res = await client.request({
29
+ const { account: _, chainId: __, ...rest } = params;
30
+ const rpcParams = Value.Encode(schema.request, {
31
+ ...rest,
32
+ from,
33
+ chainId: params.chainId ?? client.chain.id,
34
+ });
35
+ const rpcResp = await client.request({
29
36
  method: "wallet_prepareSign",
30
- params: [
31
- {
32
- ...params,
33
- from,
34
- chainId: params.chainId ?? toHex(client.chain.id),
35
- },
36
- ],
37
+ params: [rpcParams],
37
38
  });
38
39
  LOGGER.debug("prepareSign:done");
39
- return res;
40
+ return Value.Decode(schema.response, rpcResp);
40
41
  }
41
42
  //# sourceMappingURL=prepareSign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,IAAI;gBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { toHex, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareSign\";\n };\n }\n>;\n\nexport type PrepareSignParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type PrepareSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * from: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign(\n client: InnerWalletApiClient,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareSign:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n const res = await client.request({\n method: \"wallet_prepareSign\",\n params: [\n {\n ...params,\n from,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"prepareSign:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1E,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;KACX,CAAC,CAAC;IAEnC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_prepareSign as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareSignParams = MethodParams<typeof MethodSchema>;\ntype PrepareSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareSignParams = DistributiveOmit<\n BasePrepareSignParams,\n \"from\" | \"chainId\"\n> & {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type PrepareSignResult = PrepareSignResponse;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * account: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign(\n client: InnerWalletApiClient,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n } satisfies BasePrepareSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
@@ -1,13 +1,10 @@
1
1
  import type { Address } from "abitype";
2
- import { type Prettify } from "viem";
3
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { InnerWalletApiClient } from "../types";
5
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
- Request: {
7
- method: "wallet_requestAccount";
8
- };
9
- }>;
10
- export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
2
+ import { type JsonRpcAccount, type Prettify } from "viem";
3
+ import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types";
5
+ import { type MethodParams } from "../utils/schema.js";
6
+ type BaseRequestAccountParams = MethodParams<typeof MethodSchema>;
7
+ export type RequestAccountParams = Prettify<DistributiveOmit<Extract<BaseRequestAccountParams, {
11
8
  signerAddress: Address;
12
9
  }>, "signerAddress" | "includeCounterfactualInfo"> & ({
13
10
  signerAddress?: Address;
@@ -16,9 +13,7 @@ export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["p
16
13
  signerAddress?: never;
17
14
  accountAddress: Address;
18
15
  })>;
19
- export type RequestAccountResult = Prettify<{
20
- address: Address;
21
- }>;
16
+ export type RequestAccountResult = JsonRpcAccount<Address>;
22
17
  /**
23
18
  * Requests a smart account address for the provided signer using the wallet API client.
24
19
  *
@@ -1,7 +1,11 @@
1
1
  import { isAddressEqual } from "viem";
2
+ import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
2
3
  import deepEqual from "deep-equal";
3
4
  import { LOGGER } from "../logger.js";
4
5
  import { isLocalAccount } from "../utils/assertions.js";
6
+ import { Value } from "typebox/value";
7
+ import { methodSchema } from "../utils/schema.js";
8
+ const schema = methodSchema(MethodSchema);
5
9
  /**
6
10
  * Requests a smart account address for the provided signer using the wallet API client.
7
11
  *
@@ -53,12 +57,15 @@ export async function requestAccount(client, params) {
53
57
  });
54
58
  return {
55
59
  address: cachedAccount.address,
60
+ type: "json-rpc",
56
61
  };
57
62
  }
58
- const resp = await client.request({
63
+ const rpcParams = Value.Encode(schema.request, args);
64
+ const rpcResp = await client.request({
59
65
  method: "wallet_requestAccount",
60
- params: [args],
66
+ params: [rpcParams],
61
67
  });
68
+ const resp = Value.Decode(schema.response, rpcResp);
62
69
  client.internal?.setAccount({
63
70
  address: resp.accountAddress,
64
71
  requestParams: args,
@@ -66,6 +73,7 @@ export async function requestAccount(client, params) {
66
73
  LOGGER.debug("requestAccount:done", { address: resp.accountAddress });
67
74
  return {
68
75
  address: resp.accountAddress,
76
+ type: "json-rpc",
69
77
  };
70
78
  }
71
79
  //# sourceMappingURL=requestAccount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAiB,MAAM,MAAM,CAAC;AAErD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAwBxD;;;;;;;;;;;;;;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IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAEtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_requestAccount\";\n };\n }\n>;\n\nexport type RequestAccountParams = Prettify<\n Omit<\n Extract<RpcSchema[\"Request\"][\"params\"][0], { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = Prettify<{ address: Address }>;\n\n/**\n * Requests a smart account address for the provided signer using the wallet API client.\n *\n * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using\n * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`\n * directly without first calling `requestAccount`.\n *\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request a non-7702 smart account\n * const account = await client.requestAccount();\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const signerAddress =\n (params && \"signerAddress\" in params ? params.signerAddress : undefined) ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n const args =\n params && \"accountAddress\" in params && params.accountAddress\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n isAddressEqual(cachedAccount.address, args.accountAddress)) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n };\n }\n\n const resp = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n\n return {\n address: resp.accountAddress,\n };\n}\n"]}
1
+ {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsC,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAA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YAC3D,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,IAAI,EAAE,UAAU;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAC5B,MAAM,CAAC,OAAO,EACd,IAAuC,CACxC,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAEtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type JsonRpcAccount, type Prettify } from \"viem\";\nimport { wallet_requestAccount as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\nimport { Value } from \"typebox/value\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseRequestAccountParams = MethodParams<typeof MethodSchema>;\n\nexport type RequestAccountParams = Prettify<\n DistributiveOmit<\n Extract<BaseRequestAccountParams, { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = JsonRpcAccount<Address>;\n\n/**\n * Requests a smart account address for the provided signer using the wallet API client.\n *\n * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using\n * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`\n * directly without first calling `requestAccount`.\n *\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request a non-7702 smart account\n * const account = await client.requestAccount();\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const signerAddress =\n (params && \"signerAddress\" in params ? params.signerAddress : undefined) ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n const args =\n params && \"accountAddress\" in params && params.accountAddress\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n isAddressEqual(cachedAccount.address, args.accountAddress)) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n type: \"json-rpc\",\n };\n }\n\n const rpcParams = Value.Encode(\n schema.request,\n args satisfies BaseRequestAccountParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_requestAccount\",\n params: [rpcParams],\n });\n\n const resp = Value.Decode(schema.response, rpcResp);\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n\n return {\n address: resp.accountAddress,\n type: \"json-rpc\",\n };\n}\n"]}
@@ -1,8 +1,10 @@
1
- import type { Prettify } from "viem";
2
- import type { InnerWalletApiClient } from "../types.js";
1
+ import type { Chain, Prettify } from "viem";
2
+ import type { DistributiveOmit, InnerWalletApiClient } from "../types.js";
3
3
  import { type PrepareCallsParams } from "./prepareCalls.js";
4
4
  import { type SendPreparedCallsResult } from "./sendPreparedCalls.js";
5
- export type SendCallsParams = Prettify<PrepareCallsParams>;
5
+ export type SendCallsParams = Prettify<DistributiveOmit<PrepareCallsParams, "chainId"> & {
6
+ chain?: Pick<Chain, "id">;
7
+ }>;
6
8
  export type SendCallsResult = Prettify<SendPreparedCallsResult>;
7
9
  /**
8
10
  * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
@@ -11,9 +13,9 @@ export type SendCallsResult = Prettify<SendPreparedCallsResult>;
11
13
  * this directly without first calling `requestAccount`.
12
14
  *
13
15
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
- * @param {PrepareCallsParams} params - Parameters for sending 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).
16
+ * @param {SendCallsParams} params - Parameters for sending calls
17
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
18
+ * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
17
19
  * @param {object} [params.capabilities] - Optional capabilities to include with the request.
18
20
  * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
19
21
  *
@@ -24,10 +26,10 @@ export type SendCallsResult = Prettify<SendPreparedCallsResult>;
24
26
  * calls: [{
25
27
  * to: "0x1234...",
26
28
  * data: "0xabcdef...",
27
- * value: "0x0"
29
+ * value: 0n
28
30
  * }],
29
31
  * capabilities: {
30
- * paymasterService: { policyId: "your-policy-id" }
32
+ * paymaster: { policyId: "your-policy-id" }
31
33
  * }
32
34
  * });
33
35
  *
@@ -11,9 +11,9 @@ import { extractCapabilitiesForSending } from "../utils/capabilities.js";
11
11
  * this directly without first calling `requestAccount`.
12
12
  *
13
13
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
- * @param {PrepareCallsParams} params - Parameters for sending 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).
14
+ * @param {SendCallsParams} params - Parameters for sending calls
15
+ * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
16
+ * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
17
17
  * @param {object} [params.capabilities] - Optional capabilities to include with the request.
18
18
  * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
19
19
  *
@@ -24,10 +24,10 @@ import { extractCapabilitiesForSending } from "../utils/capabilities.js";
24
24
  * calls: [{
25
25
  * to: "0x1234...",
26
26
  * data: "0xabcdef...",
27
- * value: "0x0"
27
+ * value: 0n
28
28
  * }],
29
29
  * capabilities: {
30
- * paymasterService: { policyId: "your-policy-id" }
30
+ * paymaster: { policyId: "your-policy-id" }
31
31
  * }
32
32
  * });
33
33
  *
@@ -44,13 +44,15 @@ export async function sendCalls(client, params) {
44
44
  calls: params.calls?.length,
45
45
  hasCapabilities: !!params.capabilities,
46
46
  });
47
- let calls = await prepareCalls(client, params);
47
+ const { chain, ...prepareCallsParams } = params;
48
+ let calls = await prepareCalls(client, {
49
+ ...prepareCallsParams,
50
+ ...(chain != null ? { chainId: chain.id } : {}),
51
+ });
48
52
  if (calls.type === "paymaster-permit") {
49
53
  const signature = await signSignatureRequest(client, calls.signatureRequest);
50
54
  const secondCallParams = {
51
- from: calls.modifiedRequest.from,
52
- calls: calls.modifiedRequest.calls,
53
- capabilities: calls.modifiedRequest.capabilities,
55
+ ...calls.modifiedRequest,
54
56
  // WebAuthn signatures are not supported for paymaster permits (throws above).
55
57
  paymasterPermitSignature: signature,
56
58
  };
@@ -1 +1 @@
1
- {"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAMzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAA4B,EAC5B,MAAuB;IAEvB,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAC3B,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,IAAI,KAAK,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/C,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAC1C,MAAM,EACN,KAAK,CAAC,gBAAgB,CACvB,CAAC;QAEF,MAAM,gBAAgB,GAAG;YACvB,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI;YAChC,KAAK,EAAE,KAAK,CAAC,eAAe,CAAC,KAAK;YAClC,YAAY,EAAE,KAAK,CAAC,eAAe,CAAC,YAAY;YAChD,8EAA8E;YAC9E,wBAAwB,EAAE,SAGzB;SACF,CAAC;QAEF,KAAK,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE3D,MAAM,6BAA6B,GAAG,6BAA6B,CACjE,MAAM,CAAC,YAAY,CACpB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE;QAC1C,GAAG,WAAW;QACd,GAAG,CAAC,6BAA6B,IAAI,IAAI;YACvC,CAAC,CAAC,EAAE,YAAY,EAAE,6BAA6B,EAAE;YACjD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { extractCapabilitiesForSending } from \"../utils/capabilities.js\";\n\nexport type SendCallsParams = Prettify<PrepareCallsParams>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `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 sending 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<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.\n *\n * @example\n * ```ts\n * // Send calls (uses signer address via EIP-7702 by default)\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the call ID\n * console.log(result.id);\n * ```\n * <Note>\n * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden\n * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.\n * </Note>\n */\nexport async function sendCalls(\n client: InnerWalletApiClient,\n params: SendCallsParams,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n let calls = await prepareCalls(client, params);\n\n if (calls.type === \"paymaster-permit\") {\n const signature = await signSignatureRequest(\n client,\n calls.signatureRequest,\n );\n\n const secondCallParams = {\n from: calls.modifiedRequest.from,\n calls: calls.modifiedRequest.calls,\n capabilities: calls.modifiedRequest.capabilities,\n // WebAuthn signatures are not supported for paymaster permits (throws above).\n paymasterPermitSignature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n\n calls = await prepareCalls(client, secondCallParams);\n }\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const sendPreparedCallsCapabilities = extractCapabilitiesForSending(\n params.capabilities,\n );\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n ...(sendPreparedCallsCapabilities != null\n ? { capabilities: sendPreparedCallsCapabilities }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAUzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAA4B,EAC5B,MAAuB;IAEvB,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAC3B,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,EAAE,GAAG,MAAM,CAAC;IAChD,IAAI,KAAK,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE;QACrC,GAAG,kBAAkB;QACrB,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAC1C,MAAM,EACN,KAAK,CAAC,gBAAgB,CACvB,CAAC;QAEF,MAAM,gBAAgB,GAAG;YACvB,GAAG,KAAK,CAAC,eAAe;YACxB,8EAA8E;YAC9E,wBAAwB,EAAE,SAGzB;SACF,CAAC;QAEF,KAAK,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE3D,MAAM,6BAA6B,GAAG,6BAA6B,CACjE,MAAM,CAAC,YAAY,CACpB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE;QAC1C,GAAG,WAAW;QACd,GAAG,CAAC,6BAA6B,IAAI,IAAI;YACvC,CAAC,CAAC,EAAE,YAAY,EAAE,6BAA6B,EAAE;YACjD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Chain, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { extractCapabilitiesForSending } from \"../utils/capabilities.js\";\n\nexport type SendCallsParams = Prettify<\n DistributiveOmit<PrepareCallsParams, \"chainId\"> & {\n chain?: Pick<Chain, \"id\">;\n }\n>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `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 {SendCallsParams} params - Parameters for sending 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<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.\n *\n * @example\n * ```ts\n * // Send calls (uses signer address via EIP-7702 by default)\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the call ID\n * console.log(result.id);\n * ```\n * <Note>\n * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden\n * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.\n * </Note>\n */\nexport async function sendCalls(\n client: InnerWalletApiClient,\n params: SendCallsParams,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const { chain, ...prepareCallsParams } = params;\n let calls = await prepareCalls(client, {\n ...prepareCallsParams,\n ...(chain != null ? { chainId: chain.id } : {}),\n });\n\n if (calls.type === \"paymaster-permit\") {\n const signature = await signSignatureRequest(\n client,\n calls.signatureRequest,\n );\n\n const secondCallParams = {\n ...calls.modifiedRequest,\n // WebAuthn signatures are not supported for paymaster permits (throws above).\n paymasterPermitSignature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n\n calls = await prepareCalls(client, secondCallParams);\n }\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const sendPreparedCallsCapabilities = extractCapabilitiesForSending(\n params.capabilities,\n );\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n ...(sendPreparedCallsCapabilities != null\n ? { capabilities: sendPreparedCallsCapabilities }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
@@ -1,13 +1,14 @@
1
- import { type Prettify } from "viem";
2
- import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
3
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
4
- type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
- Request: {
6
- method: "wallet_sendPreparedCalls";
7
- };
8
- }>;
9
- export type SendPreparedCallsParams = Prettify<OptionalChainId<RpcSchema["Request"]["params"][0]>>;
10
- export type SendPreparedCallsResult = 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 { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
5
+ import { type MethodParams, type MethodResponse } from "../utils/schema.js";
6
+ type BaseSendPreparedCallsParams = MethodParams<typeof MethodSchema>;
7
+ type SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;
8
+ export type SendPreparedCallsParams = Prettify<WithCapabilities<DistributiveOmit<BaseSendPreparedCallsParams, "chainId"> & {
9
+ chainId?: number;
10
+ }>>;
11
+ export type SendPreparedCallsResult = SendPreparedCallsResponse;
11
12
  /**
12
13
  * Sends prepared calls by submitting a signed user operation.
13
14
  * This method is used after signing the signature request returned from prepareCalls.
@@ -23,10 +24,10 @@ export type SendPreparedCallsResult = Prettify<RpcSchema["ReturnType"]>;
23
24
  * calls: [{
24
25
  * to: "0x1234...",
25
26
  * data: "0xabcdef...",
26
- * value: "0x0"
27
+ * value: 0n
27
28
  * }],
28
29
  * capabilities: {
29
- * paymasterService: { policyId: "your-policy-id" }
30
+ * paymaster: { policyId: "your-policy-id" }
30
31
  * }
31
32
  * });
32
33
  *
@@ -1,6 +1,9 @@
1
- import { toHex } from "viem";
2
1
  import { LOGGER } from "../logger.js";
3
- import { mergeClientCapabilities } from "../utils/capabilities.js";
2
+ import { mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
3
+ import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
4
+ import { Value } from "typebox/value";
5
+ import { methodSchema, } from "../utils/schema.js";
6
+ const schema = methodSchema(MethodSchema);
4
7
  /**
5
8
  * Sends prepared calls by submitting a signed user operation.
6
9
  * This method is used after signing the signature request returned from prepareCalls.
@@ -16,10 +19,10 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
16
19
  * calls: [{
17
20
  * to: "0x1234...",
18
21
  * data: "0xabcdef...",
19
- * value: "0x0"
22
+ * value: 0n
20
23
  * }],
21
24
  * capabilities: {
22
- * paymasterService: { policyId: "your-policy-id" }
25
+ * paymaster: { policyId: "your-policy-id" }
23
26
  * }
24
27
  * });
25
28
  *
@@ -33,20 +36,23 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
33
36
  * ```
34
37
  */
35
38
  export async function sendPreparedCalls(client, params) {
36
- params.capabilities = mergeClientCapabilities(client, params.capabilities);
39
+ const capabilities = mergeClientCapabilities(client, params.capabilities);
37
40
  LOGGER.debug("sendPreparedCalls:start", { type: params.type });
38
- const res = await client.request({
41
+ const { chainId: rawChainId, ...restParams } = params;
42
+ const chainId = rawChainId ?? client.chain.id;
43
+ const fullParams = restParams.type === "array"
44
+ ? { ...restParams, capabilities: toRpcCapabilities(capabilities) }
45
+ : {
46
+ ...restParams,
47
+ chainId,
48
+ capabilities: toRpcCapabilities(capabilities),
49
+ };
50
+ const rpcParams = Value.Encode(schema.request, fullParams);
51
+ const rpcResp = await client.request({
39
52
  method: "wallet_sendPreparedCalls",
40
- params: [
41
- params.type === "array"
42
- ? params
43
- : {
44
- ...params,
45
- chainId: params.chainId ?? toHex(client.chain.id),
46
- },
47
- ],
53
+ params: [rpcParams],
48
54
  });
49
55
  LOGGER.debug("sendPreparedCalls:done");
50
- return res;
56
+ return Value.Decode(schema.response, rpcResp);
51
57
  }
52
58
  //# sourceMappingURL=sendPreparedCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAiBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,MAA+B;IAE/B,MAAM,CAAC,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE3E,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE;YACN,MAAM,CAAC,IAAI,KAAK,OAAO;gBACrB,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC;oBACE,GAAG,MAAM;oBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;iBAClD;SACN;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACvC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_sendPreparedCalls\";\n };\n }\n>;\n\nexport type SendPreparedCallsParams = Prettify<\n OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>\n>;\n\nexport type SendPreparedCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Sends prepared calls by submitting a signed user operation.\n * This method is used after signing the signature request returned from prepareCalls.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls\n * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID\n *\n * @example\n * ```ts\n * // First prepare the calls\n * const preparedCalls = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // Then sign the calls\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Then send the prepared calls with the signature\n * const result = await client.sendPreparedCalls({\n * signedCalls,\n * });\n * ```\n */\nexport async function sendPreparedCalls(\n client: InnerWalletApiClient,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n params.capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"sendPreparedCalls:start\", { type: params.type });\n const res = await client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [\n params.type === \"array\"\n ? params\n : {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"sendPreparedCalls:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/send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,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n mergeClientCapabilities,\n toRpcCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { wallet_sendPreparedCalls 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 BaseSendPreparedCallsParams = MethodParams<typeof MethodSchema>;\ntype SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type SendPreparedCallsParams = Prettify<\n WithCapabilities<\n DistributiveOmit<BaseSendPreparedCallsParams, \"chainId\"> & {\n chainId?: number;\n }\n >\n>;\n\nexport type SendPreparedCallsResult = SendPreparedCallsResponse;\n\n/**\n * Sends prepared calls by submitting a signed user operation.\n * This method is used after signing the signature request returned from prepareCalls.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls\n * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID\n *\n * @example\n * ```ts\n * // First prepare the calls\n * const preparedCalls = 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 * // Then sign the calls\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Then send the prepared calls with the signature\n * const result = await client.sendPreparedCalls({\n * signedCalls,\n * });\n * ```\n */\nexport async function sendPreparedCalls(\n client: InnerWalletApiClient,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"sendPreparedCalls:start\", { type: params.type });\n\n const { chainId: rawChainId, ...restParams } = params;\n const chainId = rawChainId ?? client.chain.id;\n\n const fullParams =\n restParams.type === \"array\"\n ? { ...restParams, capabilities: toRpcCapabilities(capabilities) }\n : {\n ...restParams,\n chainId,\n capabilities: toRpcCapabilities(capabilities),\n };\n\n const rpcParams = Value.Encode(\n schema.request,\n fullParams satisfies BaseSendPreparedCallsParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"sendPreparedCalls:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
@@ -1,8 +1,9 @@
1
- import { type Address, type Hex, type Prettify, type SignableMessage } from "viem";
1
+ import { type Hex, type Prettify, type SignableMessage } from "viem";
2
2
  import type { InnerWalletApiClient } from "../types.js";
3
+ import { type AccountParam } from "../utils/resolve.js";
3
4
  export type SignMessageParams = Prettify<{
4
5
  message: SignableMessage;
5
- account?: Address;
6
+ account?: AccountParam;
6
7
  }>;
7
8
  export type SignMessageResult = Prettify<Hex>;
8
9
  /**
@@ -12,7 +13,7 @@ export type SignMessageResult = Prettify<Hex>;
12
13
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
13
14
  * @param {SignMessageParams} params - Parameters for signing the message
14
15
  * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
15
- * @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.
16
+ * @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.
16
17
  * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
17
18
  *
18
19
  * @example
@@ -4,6 +4,7 @@ import { signSignatureRequest } from "./signSignatureRequest.js";
4
4
  import { formatSign } from "./formatSign.js";
5
5
  import { signableMessageToJsonSafe } from "../utils/format.js";
6
6
  import { LOGGER } from "../logger.js";
7
+ import { resolveAddress } from "../utils/resolve.js";
7
8
  /**
8
9
  * Signs a message using the smart account.
9
10
  * This method requests the account associated with the signer and uses it to sign the message.
@@ -11,7 +12,7 @@ import { LOGGER } from "../logger.js";
11
12
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
12
13
  * @param {SignMessageParams} params - Parameters for signing the message
13
14
  * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
14
- * @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.
15
+ * @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.
15
16
  * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
16
17
  *
17
18
  * @example
@@ -24,12 +25,14 @@ import { LOGGER } from "../logger.js";
24
25
  * ```
25
26
  */
26
27
  export async function signMessage(client, params) {
27
- const accountAddress = params.account ?? client.account.address;
28
+ const accountAddress = params.account
29
+ ? resolveAddress(params.account)
30
+ : client.account.address;
28
31
  LOGGER.debug("signMessage:start", {
29
32
  hasExplicitAccount: params.account != null,
30
33
  });
31
34
  const prepared = await prepareSign(client, {
32
- from: accountAddress,
35
+ account: accountAddress,
33
36
  signatureRequest: {
34
37
  type: "personal_sign",
35
38
  data: signableMessageToJsonSafe(params.message),
@@ -37,7 +40,7 @@ export async function signMessage(client, params) {
37
40
  });
38
41
  const signed = await signSignatureRequest(client, prepared.signatureRequest);
39
42
  const formatted = await formatSign(client, {
40
- from: accountAddress,
43
+ account: accountAddress,
41
44
  signature: {
42
45
  type: "ecdsa",
43
46
  data: signed.data,
@@ -1 +1 @@
1
- {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAStC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAChE,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE;QAChC,kBAAkB,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;KAC3C,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE;QACzC,IAAI,EAAE,cAAc;QACpB,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC;SAChD;KACF,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACzC,IAAI,EAAE,cAAc;QACpB,SAAS,EAAE;YACT,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Prettify,\n type SignableMessage,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { signableMessageToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SignMessageParams = Prettify<{\n message: SignableMessage;\n account?: Address;\n}>;\n\nexport type SignMessageResult = Prettify<Hex>;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignMessageParams} params - Parameters for signing the message\n * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.\n * @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * ```ts\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n * ```\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const accountAddress = params.account ?? client.account.address;\n LOGGER.debug(\"signMessage:start\", {\n hasExplicitAccount: params.account != null,\n });\n\n const prepared = await prepareSign(client, {\n from: accountAddress,\n signatureRequest: {\n type: \"personal_sign\",\n data: signableMessageToJsonSafe(params.message),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n const formatted = await formatSign(client, {\n from: accountAddress,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signMessage:done\", { from: accountAddress });\n return formatted.signature;\n}\n"]}
1
+ {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,MAAM,MAAM,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAA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, type Prettify, type SignableMessage } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { signableMessageToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\n\nexport type SignMessageParams = Prettify<{\n message: SignableMessage;\n account?: AccountParam;\n}>;\n\nexport type SignMessageResult = Prettify<Hex>;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignMessageParams} params - Parameters for signing the message\n * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.\n * @param {AccountParam} [params.account] - Optional account to use for signing. Can be an address string or an object with an `address` property. If not provided, uses the client's current account.\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * ```ts\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n * ```\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const accountAddress = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n LOGGER.debug(\"signMessage:start\", {\n hasExplicitAccount: params.account != null,\n });\n\n const prepared = await prepareSign(client, {\n account: accountAddress,\n signatureRequest: {\n type: \"personal_sign\",\n data: signableMessageToJsonSafe(params.message),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n const formatted = await formatSign(client, {\n account: accountAddress,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signMessage:done\", { from: accountAddress });\n return formatted.signature;\n}\n"]}
@@ -1,9 +1,24 @@
1
1
  import type { PrepareCallsResult } from "./prepareCalls.ts";
2
+ import { type SignSignatureRequestResult } from "./signSignatureRequest.js";
2
3
  import type { Prettify } from "viem";
3
4
  import type { InnerWalletApiClient } from "../types.js";
4
- import type { SendPreparedCallsParams } from "./sendPreparedCalls.js";
5
5
  export type SignPreparedCallsParams = Prettify<PrepareCallsResult>;
6
- export type SignPreparedCallsResult = SendPreparedCallsParams;
6
+ /** Replace signatureRequest/feePayment with the actual signature produced by signPreparedCalls. */
7
+ type Signed<T> = T extends {
8
+ signatureRequest?: unknown;
9
+ } ? Prettify<Omit<T, "signatureRequest" | "feePayment"> & {
10
+ signature: SignSignatureRequestResult;
11
+ }> : never;
12
+ export type SignPreparedCallsResult = {
13
+ type: "array";
14
+ data: Signed<Extract<PrepareCallsResult, {
15
+ type: "array";
16
+ }>["data"][number]>[];
17
+ } | Signed<Extract<PrepareCallsResult, {
18
+ type: "user-operation-v060";
19
+ }>> | Signed<Extract<PrepareCallsResult, {
20
+ type: "user-operation-v070";
21
+ }>>;
7
22
  /**
8
23
  * Signs prepared calls using the provided signer.
9
24
  *
@@ -30,3 +45,4 @@ export type SignPreparedCallsResult = SendPreparedCallsParams;
30
45
  * ```
31
46
  */
32
47
  export declare function signPreparedCalls(client: InnerWalletApiClient, params: SignPreparedCallsParams): Promise<SignPreparedCallsResult>;
48
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { assertNever, BaseError } from "@alchemy/common";
2
- import { signSignatureRequest } from "./signSignatureRequest.js";
2
+ import { signSignatureRequest, } from "./signSignatureRequest.js";
3
3
  import { LOGGER } from "../logger.js";
4
4
  /**
5
5
  * Signs prepared calls using the provided signer.