@alchemy/wallet-apis 0.0.0-alpha.12

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 (182) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/actions/formatSign.d.ts +35 -0
  3. package/dist/esm/actions/formatSign.js +38 -0
  4. package/dist/esm/actions/formatSign.js.map +1 -0
  5. package/dist/esm/actions/grantPermissions.d.ts +73 -0
  6. package/dist/esm/actions/grantPermissions.js +87 -0
  7. package/dist/esm/actions/grantPermissions.js.map +1 -0
  8. package/dist/esm/actions/listAccounts.d.ts +40 -0
  9. package/dist/esm/actions/listAccounts.js +43 -0
  10. package/dist/esm/actions/listAccounts.js.map +1 -0
  11. package/dist/esm/actions/prepareCalls.d.ts +44 -0
  12. package/dist/esm/actions/prepareCalls.js +58 -0
  13. package/dist/esm/actions/prepareCalls.js.map +1 -0
  14. package/dist/esm/actions/prepareSign.d.ts +33 -0
  15. package/dist/esm/actions/prepareSign.js +41 -0
  16. package/dist/esm/actions/prepareSign.js.map +1 -0
  17. package/dist/esm/actions/requestAccount.d.ts +33 -0
  18. package/dist/esm/actions/requestAccount.js +67 -0
  19. package/dist/esm/actions/requestAccount.js.map +1 -0
  20. package/dist/esm/actions/sendCalls.d.ts +34 -0
  21. package/dist/esm/actions/sendCalls.js +49 -0
  22. package/dist/esm/actions/sendCalls.js.map +1 -0
  23. package/dist/esm/actions/sendPreparedCalls.d.ts +43 -0
  24. package/dist/esm/actions/sendPreparedCalls.js +50 -0
  25. package/dist/esm/actions/sendPreparedCalls.js.map +1 -0
  26. package/dist/esm/actions/signMessage.d.ts +27 -0
  27. package/dist/esm/actions/signMessage.js +51 -0
  28. package/dist/esm/actions/signMessage.js.map +1 -0
  29. package/dist/esm/actions/signPreparedCalls.d.ts +32 -0
  30. package/dist/esm/actions/signPreparedCalls.js +88 -0
  31. package/dist/esm/actions/signPreparedCalls.js.map +1 -0
  32. package/dist/esm/actions/signSignatureRequest.d.ts +41 -0
  33. package/dist/esm/actions/signSignatureRequest.js +97 -0
  34. package/dist/esm/actions/signSignatureRequest.js.map +1 -0
  35. package/dist/esm/actions/signTypedData.d.ts +40 -0
  36. package/dist/esm/actions/signTypedData.js +66 -0
  37. package/dist/esm/actions/signTypedData.js.map +1 -0
  38. package/dist/esm/client.d.ts +34 -0
  39. package/dist/esm/client.js +62 -0
  40. package/dist/esm/client.js.map +1 -0
  41. package/dist/esm/decorators/smartWalletActions.d.ts +36 -0
  42. package/dist/esm/decorators/smartWalletActions.js +37 -0
  43. package/dist/esm/decorators/smartWalletActions.js.map +1 -0
  44. package/dist/esm/experimental/actions/requestQuoteV0.d.ts +54 -0
  45. package/dist/esm/experimental/actions/requestQuoteV0.js +62 -0
  46. package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -0
  47. package/dist/esm/experimental/swapActionsDecorator.d.ts +13 -0
  48. package/dist/esm/experimental/swapActionsDecorator.js +16 -0
  49. package/dist/esm/experimental/swapActionsDecorator.js.map +1 -0
  50. package/dist/esm/exports/experimental.d.ts +4 -0
  51. package/dist/esm/exports/experimental.js +3 -0
  52. package/dist/esm/exports/experimental.js.map +1 -0
  53. package/dist/esm/exports/index.d.ts +31 -0
  54. package/dist/esm/exports/index.js +16 -0
  55. package/dist/esm/exports/index.js.map +1 -0
  56. package/dist/esm/exports/internal.d.ts +6 -0
  57. package/dist/esm/exports/internal.js +4 -0
  58. package/dist/esm/exports/internal.js.map +1 -0
  59. package/dist/esm/internal.d.ts +11 -0
  60. package/dist/esm/internal.js +12 -0
  61. package/dist/esm/internal.js.map +1 -0
  62. package/dist/esm/logger.d.ts +2 -0
  63. package/dist/esm/logger.js +8 -0
  64. package/dist/esm/logger.js.map +1 -0
  65. package/dist/esm/provider.d.ts +26 -0
  66. package/dist/esm/provider.js +191 -0
  67. package/dist/esm/provider.js.map +1 -0
  68. package/dist/esm/testSetup.d.ts +3 -0
  69. package/dist/esm/testSetup.js +18 -0
  70. package/dist/esm/testSetup.js.map +1 -0
  71. package/dist/esm/types.d.ts +34 -0
  72. package/dist/esm/types.js +2 -0
  73. package/dist/esm/types.js.map +1 -0
  74. package/dist/esm/utils/assertions.d.ts +18 -0
  75. package/dist/esm/utils/assertions.js +24 -0
  76. package/dist/esm/utils/assertions.js.map +1 -0
  77. package/dist/esm/utils/capabilities.d.ts +10 -0
  78. package/dist/esm/utils/capabilities.js +19 -0
  79. package/dist/esm/utils/capabilities.js.map +1 -0
  80. package/dist/esm/utils/format.d.ts +7 -0
  81. package/dist/esm/utils/format.js +37 -0
  82. package/dist/esm/utils/format.js.map +1 -0
  83. package/dist/esm/utils/viemDecode.d.ts +8 -0
  84. package/dist/esm/utils/viemDecode.js +231 -0
  85. package/dist/esm/utils/viemDecode.js.map +1 -0
  86. package/dist/esm/utils/viemEncode.d.ts +40 -0
  87. package/dist/esm/utils/viemEncode.js +216 -0
  88. package/dist/esm/utils/viemEncode.js.map +1 -0
  89. package/dist/esm/version.d.ts +1 -0
  90. package/dist/esm/version.js +4 -0
  91. package/dist/esm/version.js.map +1 -0
  92. package/dist/types/actions/formatSign.d.ts +36 -0
  93. package/dist/types/actions/formatSign.d.ts.map +1 -0
  94. package/dist/types/actions/grantPermissions.d.ts +74 -0
  95. package/dist/types/actions/grantPermissions.d.ts.map +1 -0
  96. package/dist/types/actions/listAccounts.d.ts +41 -0
  97. package/dist/types/actions/listAccounts.d.ts.map +1 -0
  98. package/dist/types/actions/prepareCalls.d.ts +45 -0
  99. package/dist/types/actions/prepareCalls.d.ts.map +1 -0
  100. package/dist/types/actions/prepareSign.d.ts +34 -0
  101. package/dist/types/actions/prepareSign.d.ts.map +1 -0
  102. package/dist/types/actions/requestAccount.d.ts +34 -0
  103. package/dist/types/actions/requestAccount.d.ts.map +1 -0
  104. package/dist/types/actions/sendCalls.d.ts +35 -0
  105. package/dist/types/actions/sendCalls.d.ts.map +1 -0
  106. package/dist/types/actions/sendPreparedCalls.d.ts +44 -0
  107. package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -0
  108. package/dist/types/actions/signMessage.d.ts +28 -0
  109. package/dist/types/actions/signMessage.d.ts.map +1 -0
  110. package/dist/types/actions/signPreparedCalls.d.ts +33 -0
  111. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -0
  112. package/dist/types/actions/signSignatureRequest.d.ts +42 -0
  113. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -0
  114. package/dist/types/actions/signTypedData.d.ts +41 -0
  115. package/dist/types/actions/signTypedData.d.ts.map +1 -0
  116. package/dist/types/client.d.ts +35 -0
  117. package/dist/types/client.d.ts.map +1 -0
  118. package/dist/types/decorators/smartWalletActions.d.ts +37 -0
  119. package/dist/types/decorators/smartWalletActions.d.ts.map +1 -0
  120. package/dist/types/experimental/actions/requestQuoteV0.d.ts +55 -0
  121. package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -0
  122. package/dist/types/experimental/swapActionsDecorator.d.ts +14 -0
  123. package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -0
  124. package/dist/types/exports/experimental.d.ts +5 -0
  125. package/dist/types/exports/experimental.d.ts.map +1 -0
  126. package/dist/types/exports/index.d.ts +32 -0
  127. package/dist/types/exports/index.d.ts.map +1 -0
  128. package/dist/types/exports/internal.d.ts +7 -0
  129. package/dist/types/exports/internal.d.ts.map +1 -0
  130. package/dist/types/internal.d.ts +12 -0
  131. package/dist/types/internal.d.ts.map +1 -0
  132. package/dist/types/logger.d.ts +3 -0
  133. package/dist/types/logger.d.ts.map +1 -0
  134. package/dist/types/provider.d.ts +27 -0
  135. package/dist/types/provider.d.ts.map +1 -0
  136. package/dist/types/testSetup.d.ts +4 -0
  137. package/dist/types/testSetup.d.ts.map +1 -0
  138. package/dist/types/types.d.ts +35 -0
  139. package/dist/types/types.d.ts.map +1 -0
  140. package/dist/types/utils/assertions.d.ts +19 -0
  141. package/dist/types/utils/assertions.d.ts.map +1 -0
  142. package/dist/types/utils/capabilities.d.ts +11 -0
  143. package/dist/types/utils/capabilities.d.ts.map +1 -0
  144. package/dist/types/utils/format.d.ts +8 -0
  145. package/dist/types/utils/format.d.ts.map +1 -0
  146. package/dist/types/utils/viemDecode.d.ts +9 -0
  147. package/dist/types/utils/viemDecode.d.ts.map +1 -0
  148. package/dist/types/utils/viemEncode.d.ts +41 -0
  149. package/dist/types/utils/viemEncode.d.ts.map +1 -0
  150. package/dist/types/version.d.ts +2 -0
  151. package/dist/types/version.d.ts.map +1 -0
  152. package/package.json +76 -0
  153. package/src/actions/formatSign.ts +64 -0
  154. package/src/actions/grantPermissions.ts +125 -0
  155. package/src/actions/listAccounts.ts +66 -0
  156. package/src/actions/prepareCalls.ts +85 -0
  157. package/src/actions/prepareSign.ts +67 -0
  158. package/src/actions/requestAccount.ts +100 -0
  159. package/src/actions/sendCalls.ts +67 -0
  160. package/src/actions/sendPreparedCalls.ts +70 -0
  161. package/src/actions/signMessage.ts +74 -0
  162. package/src/actions/signPreparedCalls.ts +120 -0
  163. package/src/actions/signSignatureRequest.ts +135 -0
  164. package/src/actions/signTypedData.ts +90 -0
  165. package/src/client.ts +107 -0
  166. package/src/decorators/smartWalletActions.ts +123 -0
  167. package/src/experimental/actions/requestQuoteV0.ts +95 -0
  168. package/src/experimental/swapActionsDecorator.ts +34 -0
  169. package/src/exports/experimental.ts +7 -0
  170. package/src/exports/index.ts +44 -0
  171. package/src/exports/internal.ts +8 -0
  172. package/src/internal.ts +25 -0
  173. package/src/logger.ts +9 -0
  174. package/src/provider.ts +261 -0
  175. package/src/testSetup.ts +24 -0
  176. package/src/types.ts +61 -0
  177. package/src/utils/assertions.ts +32 -0
  178. package/src/utils/capabilities.ts +24 -0
  179. package/src/utils/format.ts +61 -0
  180. package/src/utils/viemDecode.ts +313 -0
  181. package/src/utils/viemEncode.ts +345 -0
  182. package/src/version.ts +3 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alchemy Insights, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
2
+ import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
3
+ import { type Address, type IsUndefined, type Prettify } from "viem";
4
+ type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
+ Request: {
6
+ method: "wallet_formatSign";
7
+ };
8
+ }>;
9
+ export type FormatSignParams<TAccount extends Address | undefined = Address | undefined> = Prettify<Omit<OptionalChainId<RpcSchema["Request"]["params"][0]>, "from"> & (IsUndefined<TAccount> extends true ? {
10
+ from: Address;
11
+ } : {
12
+ from?: never;
13
+ })>;
14
+ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
15
+ /**
16
+ * Formats a signature request for signing messages or transactions.
17
+ *
18
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
19
+ * @param {FormatSignParams} params - Parameters for formatting the signature
20
+ * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // Formats a signature
25
+ * const result = await client.formatSign({
26
+ * from: "0x1234...",
27
+ * signature: {
28
+ * type: "ecdsa",
29
+ * data: "0xabcd..."
30
+ * },
31
+ * });
32
+ * ```
33
+ */
34
+ export declare function formatSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: FormatSignParams<TAccount>): Promise<FormatSignResult>;
35
+ export {};
@@ -0,0 +1,38 @@
1
+ import { toHex } from "viem";
2
+ import { AccountNotFoundError } from "@alchemy/common";
3
+ import { LOGGER } from "../logger.js";
4
+ /**
5
+ * Formats a signature request for signing messages or transactions.
6
+ *
7
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
8
+ * @param {FormatSignParams} params - Parameters for formatting the signature
9
+ * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Formats a signature
14
+ * const result = await client.formatSign({
15
+ * from: "0x1234...",
16
+ * signature: {
17
+ * type: "ecdsa",
18
+ * data: "0xabcd..."
19
+ * },
20
+ * });
21
+ * ```
22
+ */
23
+ export async function formatSign(client, params) {
24
+ const from = params.from ?? client.account?.address;
25
+ if (!from) {
26
+ throw new AccountNotFoundError();
27
+ }
28
+ LOGGER.debug("formatSign:start");
29
+ const res = await client.request({
30
+ method: "wallet_formatSign",
31
+ params: [
32
+ { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },
33
+ ],
34
+ });
35
+ LOGGER.debug("formatSign:done");
36
+ return res;
37
+ }
38
+ //# sourceMappingURL=formatSign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAG9B,MAA4B,EAC5B,MAAkC;IAElC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACvE;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_formatSign\";\n };\n }\n>;\n\nexport type FormatSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n Omit<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>, \"from\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type FormatSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * from: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: FormatSignParams<TAccount>,\n): Promise<FormatSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"formatSign:start\");\n const res = await client.request({\n method: \"wallet_formatSign\",\n params: [\n { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },\n ],\n });\n LOGGER.debug(\"formatSign:done\");\n return res;\n}\n"]}
@@ -0,0 +1,73 @@
1
+ import { type Address, type Hex, type IsUndefined, type Prettify } from "viem";
2
+ import type { InnerWalletApiClient } from "../types.ts";
3
+ import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
+ import type { OptionalChainId } from "../types.ts";
5
+ type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
+ Request: {
7
+ method: "wallet_createSession";
8
+ };
9
+ }>;
10
+ export type GrantPermissionsParams<TAccount extends Address | undefined = Address | undefined> = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & (IsUndefined<TAccount> extends true ? {
11
+ account: Address;
12
+ } : {
13
+ account?: never;
14
+ })>;
15
+ export type GrantPermissionsResult = Prettify<{
16
+ context: Hex;
17
+ }>;
18
+ /**
19
+ * Grants permissions to a smart account by creating a session.
20
+ * This allows another key to perform operations on behalf of the account.
21
+ *
22
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
23
+ * @param {GrantPermissionsParams} params - The parameters for granting permissions
24
+ * @param {Address} [params.account] - The account address (required if client was not initialized with an account)
25
+ * @param {number} params.expirySec - Unix timestamp when the permissions expire
26
+ * @param {sessionKeyData} params.key - The session key information
27
+ * @param {string} params.key.publicKey - The public key of the session key
28
+ * @param {string} params.key.type - The type of the key (e.g., "secp256k1")
29
+ * @param {Array} params.permissions - Array of permission objects defining what the session key can do
30
+ * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // Create a session key and grant root permissions
35
+ * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
36
+ * const account = await client.requestAccount();
37
+ *
38
+ * const permissions = await client.grantPermissions({
39
+ * account: account.address,
40
+ * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
41
+ * key: {
42
+ * publicKey: await sessionKey.getAddress(),
43
+ * type: "secp256k1",
44
+ * },
45
+ * permissions: [{ type: "root" }],
46
+ * });
47
+ *
48
+ * // Use the permissions to prepare a call
49
+ * const preparedCalls = await client.prepareCalls({
50
+ * calls: [{ to: zeroAddress, value: "0x0" }],
51
+ * from: account.address,
52
+ * capabilities: {
53
+ * paymasterService: {
54
+ * policyId: "your-paymaster-policy-id",
55
+ * },
56
+ * permissions,
57
+ * },
58
+ * });
59
+ *
60
+ * // Sign with the session key
61
+ * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
62
+ *
63
+ * // Send the prepared call using the session key
64
+ * const result = await client.sendPreparedCalls({
65
+ * ...signedCalls,
66
+ * capabilities: {
67
+ * permissions,
68
+ * },
69
+ * });
70
+ * ```
71
+ */
72
+ export declare function grantPermissions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
73
+ export {};
@@ -0,0 +1,87 @@
1
+ import { toHex, concatHex, } from "viem";
2
+ import { signSignatureRequest } from "./signSignatureRequest.js";
3
+ import { AccountNotFoundError } from "@alchemy/common";
4
+ import { LOGGER } from "../logger.js";
5
+ /**
6
+ * Grants permissions to a smart account by creating a session.
7
+ * This allows another key to perform operations on behalf of the account.
8
+ *
9
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
10
+ * @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)
12
+ * @param {number} params.expirySec - Unix timestamp when the permissions expire
13
+ * @param {sessionKeyData} params.key - The session key information
14
+ * @param {string} params.key.publicKey - The public key of the session key
15
+ * @param {string} params.key.type - The type of the key (e.g., "secp256k1")
16
+ * @param {Array} params.permissions - Array of permission objects defining what the session key can do
17
+ * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Create a session key and grant root permissions
22
+ * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
23
+ * const account = await client.requestAccount();
24
+ *
25
+ * const permissions = await client.grantPermissions({
26
+ * account: account.address,
27
+ * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
28
+ * key: {
29
+ * publicKey: await sessionKey.getAddress(),
30
+ * type: "secp256k1",
31
+ * },
32
+ * permissions: [{ type: "root" }],
33
+ * });
34
+ *
35
+ * // Use the permissions to prepare a call
36
+ * const preparedCalls = await client.prepareCalls({
37
+ * calls: [{ to: zeroAddress, value: "0x0" }],
38
+ * from: account.address,
39
+ * capabilities: {
40
+ * paymasterService: {
41
+ * policyId: "your-paymaster-policy-id",
42
+ * },
43
+ * permissions,
44
+ * },
45
+ * });
46
+ *
47
+ * // Sign with the session key
48
+ * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
49
+ *
50
+ * // Send the prepared call using the session key
51
+ * const result = await client.sendPreparedCalls({
52
+ * ...signedCalls,
53
+ * capabilities: {
54
+ * permissions,
55
+ * },
56
+ * });
57
+ * ```
58
+ */
59
+ 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
+ }
65
+ LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
66
+ const { sessionId, signatureRequest } = await client.request({
67
+ method: "wallet_createSession",
68
+ params: [
69
+ {
70
+ ...params,
71
+ account,
72
+ chainId: params.chainId ?? toHex(client.chain.id),
73
+ },
74
+ ],
75
+ });
76
+ const signature = await signSignatureRequest(client, signatureRequest);
77
+ const res = {
78
+ context: concatHex([
79
+ "0x00", // Remote mode.
80
+ sessionId,
81
+ signature.data,
82
+ ]),
83
+ };
84
+ LOGGER.debug("grantPermissions:done");
85
+ return res;
86
+ }
87
+ //# sourceMappingURL=grantPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAKL,SAAS,GACV,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAyBtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAGpC,MAA4B,EAC5B,MAAwC;IAExC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,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;IACvE,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 {\n toHex,\n type Address,\n type Hex,\n type IsUndefined,\n type Prettify,\n concatHex,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError } 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<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> &\n (IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: never })\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {Address} [params.account] - The account address (required if client was not initialized with an account)\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams<TAccount>,\n): Promise<GrantPermissionsResult> {\n const account = params.account ?? client.account?.address;\n if (!account) {\n LOGGER.warn(\"grantPermissions:no-account\");\n throw new AccountNotFoundError();\n }\n 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 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"]}
@@ -0,0 +1,40 @@
1
+ import type { InnerWalletApiClient } from "../types.ts";
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"> & {
10
+ signerAddress?: Address;
11
+ }>;
12
+ export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
13
+ /**
14
+ * Lists all smart accounts for a given signer using the wallet API client.
15
+ *
16
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
17
+ * @param {ListAccountsParams} params - Parameters for listing accounts
18
+ * @param {string} params.signerAddress - The address of the signer to list accounts for
19
+ * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)
20
+ * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages
21
+ * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Fetch the first page of accounts
26
+ * const firstPage = await client.listAccounts({
27
+ * signerAddress: "0x123...",
28
+ * limit: 10
29
+ * });
30
+ *
31
+ * // If an 'after' cursor exists, use it to fetch the next page
32
+ * const nextPage = await client.listAccounts({
33
+ * signerAddress: "0x123...",
34
+ * limit: 10,
35
+ * after: firstPage.meta.after
36
+ * });
37
+ * ```
38
+ */
39
+ export declare function listAccounts(client: InnerWalletApiClient, params: ListAccountsParams): Promise<ListAccountsResult>;
40
+ export {};
@@ -0,0 +1,43 @@
1
+ import { LOGGER } from "../logger.js";
2
+ /**
3
+ * Lists all smart accounts for a given signer using the wallet API client.
4
+ *
5
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
6
+ * @param {ListAccountsParams} params - Parameters for listing accounts
7
+ * @param {string} params.signerAddress - The address of the signer to list accounts for
8
+ * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)
9
+ * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages
10
+ * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Fetch the first page of accounts
15
+ * const firstPage = await client.listAccounts({
16
+ * signerAddress: "0x123...",
17
+ * limit: 10
18
+ * });
19
+ *
20
+ * // If an 'after' cursor exists, use it to fetch the next page
21
+ * const nextPage = await client.listAccounts({
22
+ * signerAddress: "0x123...",
23
+ * limit: 10,
24
+ * after: firstPage.meta.after
25
+ * });
26
+ * ```
27
+ */
28
+ export async function listAccounts(client, params) {
29
+ const signerAddress = params.signerAddress ?? client.owner.account.address;
30
+ LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
31
+ const res = await client.request({
32
+ method: "wallet_listAccounts",
33
+ params: [
34
+ {
35
+ ...params,
36
+ signerAddress,
37
+ },
38
+ ],
39
+ });
40
+ LOGGER.debug("listAccounts:done", { count: res.accounts.length });
41
+ return res;
42
+ }
43
+ //# sourceMappingURL=listAccounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAqBtC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;IAC3E,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;IAClE,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\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<RpcSchema[\"Request\"][\"params\"][0], \"signerAddress\"> & {\n signerAddress?: Address;\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 = params.signerAddress ?? client.owner.account.address;\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 return res;\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import { type Address, type IsUndefined, type Prettify } from "viem";
2
+ import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
3
+ import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
+ type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
+ Request: {
6
+ method: "wallet_prepareCalls";
7
+ };
8
+ }>;
9
+ export type PrepareCallsParams<TAccount extends Address | undefined = Address | undefined> = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "from">> & (IsUndefined<TAccount> extends true ? {
10
+ from: Address;
11
+ } : {
12
+ from?: never;
13
+ })>;
14
+ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
15
+ /**
16
+ * Prepares a set of contract calls for execution by building a user operation.
17
+ * Returns the built user operation and a signature request that needs to be signed
18
+ * before submitting to sendPreparedCalls.
19
+ *
20
+ * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
21
+ * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
22
+ * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
23
+ * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
24
+ * @param {object} [params.capabilities] - Optional capabilities to include with the request
25
+ * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
26
+ * the user operation data and signature request
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * // Prepare a sponsored user operation call
31
+ * const result = await client.prepareCalls({
32
+ * calls: [{
33
+ * to: "0x1234...",
34
+ * data: "0xabcdef...",
35
+ * value: "0x0"
36
+ * }],
37
+ * capabilities: {
38
+ * paymasterService: { policyId: "your-policy-id" }
39
+ * }
40
+ * });
41
+ * ```
42
+ */
43
+ export declare function prepareCalls<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareCallsParams<TAccount>): Promise<PrepareCallsResult>;
44
+ export {};
@@ -0,0 +1,58 @@
1
+ import { toHex } from "viem";
2
+ import { AccountNotFoundError } from "@alchemy/common";
3
+ import { LOGGER } from "../logger.js";
4
+ import { mergeClientCapabilities } from "../utils/capabilities.js";
5
+ /**
6
+ * Prepares a set of contract calls for execution by building a user operation.
7
+ * Returns the built user operation and a signature request that needs to be signed
8
+ * before submitting to sendPreparedCalls.
9
+ *
10
+ * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
11
+ * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
12
+ * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
13
+ * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
14
+ * @param {object} [params.capabilities] - Optional capabilities to include with the request
15
+ * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
16
+ * the user operation data and signature request
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // Prepare a sponsored user operation call
21
+ * const result = await client.prepareCalls({
22
+ * calls: [{
23
+ * to: "0x1234...",
24
+ * data: "0xabcdef...",
25
+ * value: "0x0"
26
+ * }],
27
+ * capabilities: {
28
+ * paymasterService: { policyId: "your-policy-id" }
29
+ * }
30
+ * });
31
+ * ```
32
+ */
33
+ export async function prepareCalls(client, params) {
34
+ const from = params.from ?? client.account?.address;
35
+ if (!from) {
36
+ LOGGER.warn("prepareCalls:no-from", { hasClientAccount: !!client.account });
37
+ throw new AccountNotFoundError();
38
+ }
39
+ const capabilities = mergeClientCapabilities(client, params.capabilities);
40
+ LOGGER.debug("prepareCalls:start", {
41
+ callsCount: params.calls?.length,
42
+ hasCapabilities: !!params.capabilities,
43
+ });
44
+ const res = await client.request({
45
+ method: "wallet_prepareCalls",
46
+ params: [
47
+ {
48
+ ...params,
49
+ chainId: params.chainId ?? toHex(client.chain.id),
50
+ from,
51
+ capabilities,
52
+ },
53
+ ],
54
+ });
55
+ LOGGER.debug("prepareCalls:done");
56
+ return res;
57
+ }
58
+ //# sourceMappingURL=prepareCalls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAqBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,MAA4B,EAC5B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI;gBACJ,YAAY;aACb;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareCalls\";\n };\n }\n>;\n\nexport type PrepareCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareCallsParams<TAccount>,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareCalls:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const res = await client.request({\n method: \"wallet_prepareCalls\",\n params: [\n {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n from,\n capabilities,\n },\n ],\n });\n LOGGER.debug(\"prepareCalls:done\");\n return res;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
2
+ import { type Address, type IsUndefined, type Prettify } from "viem";
3
+ import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
+ type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
+ Request: {
6
+ method: "wallet_prepareSign";
7
+ };
8
+ }>;
9
+ export type PrepareSignParams<TAccount extends Address | undefined = Address | undefined> = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "from">> & (IsUndefined<TAccount> extends true ? {
10
+ from: Address;
11
+ } : {
12
+ from?: never;
13
+ })>;
14
+ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
15
+ /**
16
+ * Prepares a signature request for signing messages or transactions.
17
+ *
18
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
19
+ * @param {PrepareSignParams} params - Parameters for preparing the signature request
20
+ * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // Prepare a message to be signed
25
+ * const result = await client.prepareSign({
26
+ * from: "0x1234...",
27
+ * type: "personal_sign",
28
+ * data: "Hello, world!",
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function prepareSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareSignParams<TAccount>): Promise<PrepareSignResult>;
33
+ export {};
@@ -0,0 +1,41 @@
1
+ import { toHex } from "viem";
2
+ import { AccountNotFoundError } from "@alchemy/common";
3
+ import { LOGGER } from "../logger.js";
4
+ /**
5
+ * Prepares a signature request for signing messages or transactions.
6
+ *
7
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
8
+ * @param {PrepareSignParams} params - Parameters for preparing the signature request
9
+ * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Prepare a message to be signed
14
+ * const result = await client.prepareSign({
15
+ * from: "0x1234...",
16
+ * type: "personal_sign",
17
+ * data: "Hello, world!",
18
+ * });
19
+ * ```
20
+ */
21
+ 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
+ }
27
+ LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
28
+ const res = await client.request({
29
+ method: "wallet_prepareSign",
30
+ params: [
31
+ {
32
+ ...params,
33
+ from,
34
+ chainId: params.chainId ?? toHex(client.chain.id),
35
+ },
36
+ ],
37
+ });
38
+ LOGGER.debug("prepareSign:done");
39
+ return res;
40
+ }
41
+ //# sourceMappingURL=prepareSign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAG/B,MAA4B,EAC5B,MAAmC;IAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,IAAI;gBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareSign\";\n };\n }\n>;\n\nexport type PrepareSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * from: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareSignParams<TAccount>,\n): Promise<PrepareSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareSign:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n const res = await client.request({\n method: \"wallet_prepareSign\",\n params: [\n {\n ...params,\n from,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"prepareSign:done\");\n return res;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import type { Address } from "abitype";
2
+ import type { Prettify, UnionOmit } from "viem";
3
+ import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
+ import type { InnerWalletApiClient, OptionalSignerAddress } from "../types";
5
+ type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
+ Request: {
7
+ method: "wallet_requestAccount";
8
+ };
9
+ }>;
10
+ export type RequestAccountParams = Prettify<OptionalSignerAddress<UnionOmit<RpcSchema["Request"]["params"][0], "includeCounterfactualInfo">>>;
11
+ export type RequestAccountResult = Prettify<{
12
+ address: Address;
13
+ }>;
14
+ /**
15
+ * Requests an account for the provided signer using the wallet API client.
16
+ * If an account already exists for the signer, it will always return that account unless a new ID is specified.
17
+ * If an account already exists, the creationHint will be ignored.
18
+ *
19
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
20
+ * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
21
+ * @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
22
+ * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
23
+ * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // Request an account with default parameters using a local signer
28
+ * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
29
+ * const account = await client.requestAccount(signer);
30
+ * ```
31
+ */
32
+ export declare function requestAccount(client: InnerWalletApiClient, params?: RequestAccountParams): Promise<RequestAccountResult>;
33
+ export {};