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

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 (146) hide show
  1. package/dist/esm/actions/formatSign.d.ts +4 -8
  2. package/dist/esm/actions/formatSign.js.map +1 -1
  3. package/dist/esm/actions/grantPermissions.d.ts +5 -7
  4. package/dist/esm/actions/grantPermissions.js +4 -11
  5. package/dist/esm/actions/grantPermissions.js.map +1 -1
  6. package/dist/esm/actions/listAccounts.d.ts +2 -9
  7. package/dist/esm/actions/listAccounts.js +6 -23
  8. package/dist/esm/actions/listAccounts.js.map +1 -1
  9. package/dist/esm/actions/prepareCalls.d.ts +11 -12
  10. package/dist/esm/actions/prepareCalls.js +7 -4
  11. package/dist/esm/actions/prepareCalls.js.map +1 -1
  12. package/dist/esm/actions/prepareSign.d.ts +4 -8
  13. package/dist/esm/actions/prepareSign.js.map +1 -1
  14. package/dist/esm/actions/requestAccount.d.ts +14 -9
  15. package/dist/esm/actions/requestAccount.js +20 -44
  16. package/dist/esm/actions/requestAccount.js.map +1 -1
  17. package/dist/esm/actions/sendCalls.d.ts +12 -8
  18. package/dist/esm/actions/sendCalls.js +9 -10
  19. package/dist/esm/actions/sendCalls.js.map +1 -1
  20. package/dist/esm/actions/sendPreparedCalls.d.ts +1 -1
  21. package/dist/esm/actions/sendPreparedCalls.js +1 -1
  22. package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
  23. package/dist/esm/actions/signMessage.js +5 -11
  24. package/dist/esm/actions/signMessage.js.map +1 -1
  25. package/dist/esm/actions/signPreparedCalls.js +1 -6
  26. package/dist/esm/actions/signPreparedCalls.js.map +1 -1
  27. package/dist/esm/actions/signSignatureRequest.d.ts +0 -7
  28. package/dist/esm/actions/signSignatureRequest.js +1 -27
  29. package/dist/esm/actions/signSignatureRequest.js.map +1 -1
  30. package/dist/esm/actions/signTypedData.js +5 -11
  31. package/dist/esm/actions/signTypedData.js.map +1 -1
  32. package/dist/esm/client.d.ts +18 -23
  33. package/dist/esm/client.js +20 -31
  34. package/dist/esm/client.js.map +1 -1
  35. package/dist/esm/decorators/smartWalletActions.d.ts +7 -7
  36. package/dist/esm/decorators/smartWalletActions.js +1 -1
  37. package/dist/esm/decorators/smartWalletActions.js.map +1 -1
  38. package/dist/esm/experimental/actions/requestQuoteV0.d.ts +6 -10
  39. package/dist/esm/experimental/actions/requestQuoteV0.js +3 -3
  40. package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
  41. package/dist/esm/experimental/swapActionsDecorator.d.ts +4 -5
  42. package/dist/esm/experimental/swapActionsDecorator.js +1 -1
  43. package/dist/esm/experimental/swapActionsDecorator.js.map +1 -1
  44. package/dist/esm/exports/index.d.ts +4 -4
  45. package/dist/esm/exports/index.js +2 -2
  46. package/dist/esm/exports/index.js.map +1 -1
  47. package/dist/esm/exports/internal.d.ts +0 -4
  48. package/dist/esm/exports/internal.js +0 -2
  49. package/dist/esm/exports/internal.js.map +1 -1
  50. package/dist/esm/transport.d.ts +3 -0
  51. package/dist/esm/transport.js +8 -0
  52. package/dist/esm/transport.js.map +1 -0
  53. package/dist/esm/types.d.ts +9 -9
  54. package/dist/esm/types.js.map +1 -1
  55. package/dist/esm/utils/assertions.d.ts +2 -4
  56. package/dist/esm/utils/assertions.js +0 -3
  57. package/dist/esm/utils/assertions.js.map +1 -1
  58. package/dist/esm/utils/format.d.ts +1 -3
  59. package/dist/esm/utils/format.js +1 -11
  60. package/dist/esm/utils/format.js.map +1 -1
  61. package/dist/esm/version.d.ts +1 -1
  62. package/dist/esm/version.js +1 -1
  63. package/dist/esm/version.js.map +1 -1
  64. package/dist/types/actions/formatSign.d.ts +4 -8
  65. package/dist/types/actions/formatSign.d.ts.map +1 -1
  66. package/dist/types/actions/grantPermissions.d.ts +5 -7
  67. package/dist/types/actions/grantPermissions.d.ts.map +1 -1
  68. package/dist/types/actions/listAccounts.d.ts +2 -9
  69. package/dist/types/actions/listAccounts.d.ts.map +1 -1
  70. package/dist/types/actions/prepareCalls.d.ts +11 -12
  71. package/dist/types/actions/prepareCalls.d.ts.map +1 -1
  72. package/dist/types/actions/prepareSign.d.ts +4 -8
  73. package/dist/types/actions/prepareSign.d.ts.map +1 -1
  74. package/dist/types/actions/requestAccount.d.ts +14 -9
  75. package/dist/types/actions/requestAccount.d.ts.map +1 -1
  76. package/dist/types/actions/sendCalls.d.ts +12 -8
  77. package/dist/types/actions/sendCalls.d.ts.map +1 -1
  78. package/dist/types/actions/sendPreparedCalls.d.ts +1 -1
  79. package/dist/types/actions/signMessage.d.ts.map +1 -1
  80. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
  81. package/dist/types/actions/signSignatureRequest.d.ts +0 -7
  82. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
  83. package/dist/types/actions/signTypedData.d.ts.map +1 -1
  84. package/dist/types/client.d.ts +18 -23
  85. package/dist/types/client.d.ts.map +1 -1
  86. package/dist/types/decorators/smartWalletActions.d.ts +7 -7
  87. package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
  88. package/dist/types/experimental/actions/requestQuoteV0.d.ts +6 -10
  89. package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
  90. package/dist/types/experimental/swapActionsDecorator.d.ts +4 -5
  91. package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -1
  92. package/dist/types/exports/index.d.ts +4 -4
  93. package/dist/types/exports/index.d.ts.map +1 -1
  94. package/dist/types/exports/internal.d.ts +0 -4
  95. package/dist/types/exports/internal.d.ts.map +1 -1
  96. package/dist/types/transport.d.ts +4 -0
  97. package/dist/types/transport.d.ts.map +1 -0
  98. package/dist/types/types.d.ts +9 -9
  99. package/dist/types/types.d.ts.map +1 -1
  100. package/dist/types/utils/assertions.d.ts +2 -4
  101. package/dist/types/utils/assertions.d.ts.map +1 -1
  102. package/dist/types/utils/format.d.ts +1 -3
  103. package/dist/types/utils/format.d.ts.map +1 -1
  104. package/dist/types/version.d.ts +1 -1
  105. package/package.json +5 -6
  106. package/src/actions/formatSign.ts +10 -11
  107. package/src/actions/grantPermissions.ts +10 -32
  108. package/src/actions/listAccounts.ts +14 -37
  109. package/src/actions/prepareCalls.ts +17 -15
  110. package/src/actions/prepareSign.ts +10 -11
  111. package/src/actions/requestAccount.ts +30 -64
  112. package/src/actions/sendCalls.ts +13 -20
  113. package/src/actions/sendPreparedCalls.ts +1 -1
  114. package/src/actions/signMessage.ts +4 -18
  115. package/src/actions/signPreparedCalls.ts +1 -12
  116. package/src/actions/signSignatureRequest.ts +5 -64
  117. package/src/actions/signTypedData.ts +4 -17
  118. package/src/client.ts +34 -60
  119. package/src/decorators/smartWalletActions.ts +8 -14
  120. package/src/experimental/actions/requestQuoteV0.ts +13 -20
  121. package/src/experimental/swapActionsDecorator.ts +6 -11
  122. package/src/exports/index.ts +5 -7
  123. package/src/exports/internal.ts +0 -6
  124. package/src/transport.ts +16 -0
  125. package/src/types.ts +7 -16
  126. package/src/utils/assertions.ts +2 -9
  127. package/src/utils/format.ts +1 -20
  128. package/src/version.ts +1 -1
  129. package/dist/esm/provider.d.ts +0 -26
  130. package/dist/esm/provider.js +0 -191
  131. package/dist/esm/provider.js.map +0 -1
  132. package/dist/esm/testSetup.d.ts +0 -3
  133. package/dist/esm/testSetup.js +0 -18
  134. package/dist/esm/testSetup.js.map +0 -1
  135. package/dist/esm/utils/signer.d.ts +0 -10
  136. package/dist/esm/utils/signer.js +0 -28
  137. package/dist/esm/utils/signer.js.map +0 -1
  138. package/dist/types/provider.d.ts +0 -27
  139. package/dist/types/provider.d.ts.map +0 -1
  140. package/dist/types/testSetup.d.ts +0 -4
  141. package/dist/types/testSetup.d.ts.map +0 -1
  142. package/dist/types/utils/signer.d.ts +0 -11
  143. package/dist/types/utils/signer.d.ts.map +0 -1
  144. package/src/provider.ts +0 -261
  145. package/src/testSetup.ts +0 -24
  146. package/src/utils/signer.ts +0 -36
@@ -1,16 +1,12 @@
1
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";
2
+ import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
3
+ import { type Prettify } from "viem";
4
4
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
5
  Request: {
6
6
  method: "wallet_formatSign";
7
7
  };
8
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
- })>;
9
+ export type FormatSignParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
14
10
  export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
15
11
  /**
16
12
  * Formats a signature request for signing messages or transactions.
@@ -31,5 +27,5 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
31
27
  * });
32
28
  * ```
33
29
  */
34
- export declare function formatSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: FormatSignParams<TAccount>): Promise<FormatSignResult>;
30
+ export declare function formatSign(client: InnerWalletApiClient, params: FormatSignParams): Promise<FormatSignResult>;
35
31
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAG9B,MAA4B,EAC5B,MAAkC;IAElC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACvE;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_formatSign\";\n };\n }\n>;\n\nexport type FormatSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n Omit<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>, \"from\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type FormatSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * from: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: FormatSignParams<TAccount>,\n): Promise<FormatSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"formatSign:start\");\n const res = await client.request({\n method: \"wallet_formatSign\",\n params: [\n { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },\n ],\n });\n LOGGER.debug(\"formatSign:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4B,EAC5B,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACvE;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { toHex, type Prettify } from \"viem\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_formatSign\";\n };\n }\n>;\n\nexport type FormatSignParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type FormatSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * from: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign(\n client: InnerWalletApiClient,\n params: FormatSignParams,\n): Promise<FormatSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"formatSign:start\");\n const res = await client.request({\n method: \"wallet_formatSign\",\n params: [\n { ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },\n ],\n });\n LOGGER.debug(\"formatSign:done\");\n return res;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type Address, type Hex, type IsUndefined, type Prettify } from "viem";
1
+ import { type Address, type Hex, type Prettify } from "viem";
2
2
  import type { InnerWalletApiClient } from "../types.ts";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
4
  import type { OptionalChainId } from "../types.ts";
@@ -7,11 +7,9 @@ type RpcSchema = Extract<WalletServerRpcSchemaType, {
7
7
  method: "wallet_createSession";
8
8
  };
9
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
- })>;
10
+ export type GrantPermissionsParams = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & {
11
+ account?: Address;
12
+ }>;
15
13
  export type GrantPermissionsResult = Prettify<{
16
14
  context: Hex;
17
15
  }>;
@@ -69,5 +67,5 @@ export type GrantPermissionsResult = Prettify<{
69
67
  * });
70
68
  * ```
71
69
  */
72
- export declare function grantPermissions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
70
+ export declare function grantPermissions(client: InnerWalletApiClient, params: GrantPermissionsParams): Promise<GrantPermissionsResult>;
73
71
  export {};
@@ -1,8 +1,7 @@
1
- import { toHex, concatHex, } from "viem";
1
+ import { toHex, concatHex } from "viem";
2
2
  import { signSignatureRequest } from "./signSignatureRequest.js";
3
- import { AccountNotFoundError, BaseError } from "@alchemy/common";
3
+ import { AccountNotFoundError } from "@alchemy/common";
4
4
  import { LOGGER } from "../logger.js";
5
- import { isWebAuthnAccount } from "../utils/assertions.js";
6
5
  /**
7
6
  * Grants permissions to a smart account by creating a session.
8
7
  * This allows another key to perform operations on behalf of the account.
@@ -58,15 +57,11 @@ import { isWebAuthnAccount } from "../utils/assertions.js";
58
57
  * ```
59
58
  */
60
59
  export async function grantPermissions(client, params) {
61
- const account = params.account ?? client.account?.address;
60
+ const account = params.account ?? client.account.address;
62
61
  if (!account) {
63
62
  LOGGER.warn("grantPermissions:no-account");
64
63
  throw new AccountNotFoundError();
65
64
  }
66
- if (isWebAuthnAccount(client.owner)) {
67
- LOGGER.warn("grantPermissions:unsupported-account");
68
- throw new BaseError("WebAuthn signer is not currently supported for grantPermissions");
69
- }
70
65
  LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
71
66
  const { sessionId, signatureRequest } = await client.request({
72
67
  method: "wallet_createSession",
@@ -83,9 +78,7 @@ export async function grantPermissions(client, params) {
83
78
  context: concatHex([
84
79
  "0x00", // Remote mode.
85
80
  sessionId,
86
- signature.type === "webauthn-p256"
87
- ? signature.data.signature
88
- : signature.data,
81
+ signature.data,
89
82
  ]),
90
83
  };
91
84
  LOGGER.debug("grantPermissions:done");
@@ -1 +1 @@
1
- {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAKL,SAAS,GACV,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAGpC,MAA4B,EAC5B,MAAwC;IAExC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACpD,MAAM,IAAI,SAAS,CACjB,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC3D,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO;gBACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAEvE,MAAM,GAAG,GAAG;QACV,OAAO,EAAE,SAAS,CAAC;YACjB,MAAM,EAAE,eAAe;YACvB,SAAS;YACT,SAAS,CAAC,IAAI,KAAK,eAAe;gBAChC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;gBAC1B,CAAC,CAAC,SAAS,CAAC,IAAI;SACnB,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {\n toHex,\n type Address,\n type Hex,\n type IsUndefined,\n type Prettify,\n concatHex,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport type { OptionalChainId } from \"../types.ts\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_createSession\";\n };\n }\n>;\n\nexport type GrantPermissionsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> &\n (IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: never })\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {Address} [params.account] - The account address (required if client was not initialized with an account)\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams<TAccount>,\n): Promise<GrantPermissionsResult> {\n const account = params.account ?? client.account?.address;\n if (!account) {\n LOGGER.warn(\"grantPermissions:no-account\");\n throw new AccountNotFoundError();\n }\n if (isWebAuthnAccount(client.owner)) {\n LOGGER.warn(\"grantPermissions:unsupported-account\");\n throw new BaseError(\n \"WebAuthn signer is not currently supported for grantPermissions\",\n );\n }\n\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n const { sessionId, signatureRequest } = await client.request({\n method: \"wallet_createSession\",\n params: [\n {\n ...params,\n account,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.type === \"webauthn-p256\"\n ? signature.data.signature\n : signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAyC,SAAS,EAAE,MAAM,MAAM,CAAC;AAG/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsBtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC3D,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO;gBACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAEvE,MAAM,GAAG,GAAG;QACV,OAAO,EAAE,SAAS,CAAC;YACjB,MAAM,EAAE,eAAe;YACvB,SAAS;YACT,SAAS,CAAC,IAAI;SACf,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Address, type Hex, type Prettify, concatHex } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport type { OptionalChainId } from \"../types.ts\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_createSession\";\n };\n }\n>;\n\nexport type GrantPermissionsParams = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"account\">> & {\n account?: Address;\n }\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {Address} [params.account] - The account address (required if client was not initialized with an account)\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: \"0x0\" }],\n * from: account.address,\n * capabilities: {\n * paymasterService: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams,\n): Promise<GrantPermissionsResult> {\n const account = params.account ?? client.account.address;\n if (!account) {\n LOGGER.warn(\"grantPermissions:no-account\");\n throw new AccountNotFoundError();\n }\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n const { sessionId, signatureRequest } = await client.request({\n method: \"wallet_createSession\",\n params: [\n {\n ...params,\n account,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
@@ -1,22 +1,15 @@
1
1
  import type { InnerWalletApiClient } from "../types.ts";
2
2
  import type { Address, Prettify } from "viem";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
5
4
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
5
  Request: {
7
6
  method: "wallet_listAccounts";
8
7
  };
9
8
  }>;
10
- export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & ({
9
+ export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress" | "signerPublicKey"> & {
11
10
  signerAddress?: Address;
12
11
  signerPublicKey?: never;
13
- } | {
14
- signerPublicKey: WebAuthnPublicKey;
15
- signerAddress?: never;
16
- } | {
17
- signerAddress?: never;
18
- signerPublicKey?: never;
19
- })>;
12
+ }>;
20
13
  export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
21
14
  /**
22
15
  * Lists all smart accounts for a given signer using the wallet API client.
@@ -1,5 +1,5 @@
1
1
  import { LOGGER } from "../logger.js";
2
- import { getSignerAddressOrPublicKey } from "../utils/signer.js";
2
+ import { isLocalAccount } from "../utils/assertions.js";
3
3
  /**
4
4
  * Lists all smart accounts for a given signer using the wallet API client.
5
5
  *
@@ -27,34 +27,17 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
27
27
  * ```
28
28
  */
29
29
  export async function listAccounts(client, params) {
30
- const owner = getSignerAddressOrPublicKey(client.owner);
31
- // Coalesce:
32
- // signerAddress or signerPublicKey in params takes priority.
33
- // if not present, then fallback to client's attached signer.
34
- const signerParam = params.signerAddress
35
- ? { signerAddress: params.signerAddress }
36
- : params.signerPublicKey
37
- ? {
38
- signerPublicKey: {
39
- type: "webauthn-p256",
40
- ...params.signerPublicKey,
41
- },
42
- }
43
- : owner.type === "webauthn-p256"
44
- ? {
45
- signerPublicKey: {
46
- type: "webauthn-p256",
47
- ...owner.publicKey,
48
- },
49
- }
50
- : { signerAddress: owner.address };
30
+ const signerAddress = params.signerAddress ??
31
+ (isLocalAccount(client.owner)
32
+ ? client.owner.address
33
+ : client.owner.account.address);
51
34
  LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
52
35
  const res = await client.request({
53
36
  method: "wallet_listAccounts",
54
37
  params: [
55
38
  {
56
39
  ...params,
57
- ...signerParam,
40
+ signerAddress,
58
41
  },
59
42
  ],
60
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AA6BjE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,KAAK,GAAG,2BAA2B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExD,YAAY;IACZ,6DAA6D;IAC7D,6DAA6D;IAC7D,MAAM,WAAW,GAAsC,MAAM,CAAC,aAAa;QACzE,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE;QACzC,CAAC,CAAC,MAAM,CAAC,eAAe;YACtB,CAAC,CAAC;gBACE,eAAe,EAAE;oBACf,IAAI,EAAE,eAAe;oBACrB,GAAG,MAAM,CAAC,eAAe;iBAC1B;aACF;YACH,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe;gBAC9B,CAAC,CAAC;oBACE,eAAe,EAAE;wBACf,IAAI,EAAE,eAAe;wBACrB,GAAG,KAAK,CAAC,SAAS;qBACnB;iBACF;gBACH,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAEzC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,GAAG,WAAW;aACf;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { getSignerAddressOrPublicKey } from \"../utils/signer.js\";\nimport type { WebAuthnPublicKey } from \"@alchemy/wallet-api-types\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<RpcSchema[\"Request\"][\"params\"][0], \"signerAddress\"> &\n (\n | {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n | { signerPublicKey: WebAuthnPublicKey; signerAddress?: never }\n | {\n signerAddress?: never;\n signerPublicKey?: never;\n }\n )\n>;\n\nexport type ListAccountsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Lists all smart accounts for a given signer using the wallet API client.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {ListAccountsParams} params - Parameters for listing accounts\n * @param {string} params.signerAddress - The address of the signer to list accounts for\n * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)\n * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages\n * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata\n *\n * @example\n * ```ts\n * // Fetch the first page of accounts\n * const firstPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10\n * });\n *\n * // If an 'after' cursor exists, use it to fetch the next page\n * const nextPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10,\n * after: firstPage.meta.after\n * });\n * ```\n */\nexport async function listAccounts(\n client: InnerWalletApiClient,\n params: ListAccountsParams,\n): Promise<ListAccountsResult> {\n const owner = getSignerAddressOrPublicKey(client.owner);\n\n // Coalesce:\n // signerAddress or signerPublicKey in params takes priority.\n // if not present, then fallback to client's attached signer.\n const signerParam: RpcSchema[\"Request\"][\"params\"][0] = params.signerAddress\n ? { signerAddress: params.signerAddress }\n : params.signerPublicKey\n ? {\n signerPublicKey: {\n type: \"webauthn-p256\",\n ...params.signerPublicKey,\n },\n }\n : owner.type === \"webauthn-p256\"\n ? {\n signerPublicKey: {\n type: \"webauthn-p256\",\n ...owner.publicKey,\n },\n }\n : { signerAddress: owner.address };\n\n LOGGER.debug(\"listAccounts:start\", { hasAfter: !!params.after });\n const res = await client.request({\n method: \"wallet_listAccounts\",\n params: [\n {\n ...params,\n ...signerParam,\n },\n ],\n });\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
1
+ {"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAuBxD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa;QACpB,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,aAAa;aACd;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_listAccounts\";\n };\n }\n>;\n\nexport type ListAccountsParams = Prettify<\n Omit<\n RpcSchema[\"Request\"][\"params\"][0],\n \"signerAddress\" | \"signerPublicKey\"\n > & {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n>;\n\nexport type ListAccountsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Lists all smart accounts for a given signer using the wallet API client.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {ListAccountsParams} params - Parameters for listing accounts\n * @param {string} params.signerAddress - The address of the signer to list accounts for\n * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)\n * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages\n * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata\n *\n * @example\n * ```ts\n * // Fetch the first page of accounts\n * const firstPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10\n * });\n *\n * // If an 'after' cursor exists, use it to fetch the next page\n * const nextPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10,\n * after: firstPage.meta.after\n * });\n * ```\n */\nexport async function listAccounts(\n client: InnerWalletApiClient,\n params: ListAccountsParams,\n): Promise<ListAccountsResult> {\n const signerAddress =\n params.signerAddress ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n LOGGER.debug(\"listAccounts:start\", { hasAfter: !!params.after });\n const res = await client.request({\n method: \"wallet_listAccounts\",\n params: [\n {\n ...params,\n signerAddress,\n },\n ],\n });\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
@@ -1,33 +1,32 @@
1
- import { type Address, type IsUndefined, type Prettify } from "viem";
2
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
1
+ import { type Prettify } from "viem";
2
+ import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
4
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
5
  Request: {
6
6
  method: "wallet_prepareCalls";
7
7
  };
8
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
- })>;
9
+ export type PrepareCallsParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
14
10
  export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
15
11
  /**
16
12
  * Prepares a set of contract calls for execution by building a user operation.
17
13
  * Returns the built user operation and a signature request that needs to be signed
18
14
  * before submitting to sendPreparedCalls.
19
15
  *
20
- * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
21
- * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
16
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
17
+ * this directly without first calling `requestAccount`.
18
+ *
19
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
20
+ * @param {PrepareCallsParams} params - Parameters for preparing calls
22
21
  * @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)
22
+ * @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
24
23
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
25
24
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
26
25
  * the user operation data and signature request
27
26
  *
28
27
  * @example
29
28
  * ```ts
30
- * // Prepare a sponsored user operation call
29
+ * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
31
30
  * const result = await client.prepareCalls({
32
31
  * calls: [{
33
32
  * to: "0x1234...",
@@ -40,5 +39,5 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
40
39
  * });
41
40
  * ```
42
41
  */
43
- export declare function prepareCalls<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareCallsParams<TAccount>): Promise<PrepareCallsResult>;
42
+ export declare function prepareCalls(client: InnerWalletApiClient, params: PrepareCallsParams): Promise<PrepareCallsResult>;
44
43
  export {};
@@ -7,17 +7,20 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
7
7
  * Returns the built user operation and a signature request that needs to be signed
8
8
  * before submitting to sendPreparedCalls.
9
9
  *
10
- * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request
11
- * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls
10
+ * The client defaults to using EIP-7702 with the signer's address, so you can call
11
+ * this directly without first calling `requestAccount`.
12
+ *
13
+ * @param {InnerWalletApiClient} client - The wallet API client to use for the request
14
+ * @param {PrepareCallsParams} params - Parameters for preparing calls
12
15
  * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute
13
- * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)
16
+ * @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).
14
17
  * @param {object} [params.capabilities] - Optional capabilities to include with the request
15
18
  * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
16
19
  * the user operation data and signature request
17
20
  *
18
21
  * @example
19
22
  * ```ts
20
- * // Prepare a sponsored user operation call
23
+ * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
21
24
  * const result = await client.prepareCalls({
22
25
  * calls: [{
23
26
  * to: "0x1234...",
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAqBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,MAA4B,EAC5B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI;gBACJ,YAAY;aACb;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareCalls\";\n };\n }\n>;\n\nexport type PrepareCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareCallsParams<TAccount>,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareCalls:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const res = await client.request({\n method: \"wallet_prepareCalls\",\n params: [\n {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n from,\n capabilities,\n },\n ],\n });\n LOGGER.debug(\"prepareCalls:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,MAAM,CAAC;AAM5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAkBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI;gBACJ,YAAY;aACb;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { toHex, type Prettify } from \"viem\";\nimport type {\n InnerWalletApiClient,\n OptionalChainId,\n OptionalFrom,\n} from \"../types.ts\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\nimport { mergeClientCapabilities } from \"../utils/capabilities.js\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareCalls\";\n };\n }\n>;\n\nexport type PrepareCallsParams = Prettify<\n OptionalFrom<OptionalChainId<RpcSchema[\"Request\"][\"params\"][0]>>\n>;\n\nexport type PrepareCallsResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * The client defaults to using EIP-7702 with the signer's address, so you can call\n * this directly without first calling `requestAccount`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from. Defaults to the client's account (signer address via EIP-7702).\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls(\n client: InnerWalletApiClient,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareCalls:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const res = await client.request({\n method: \"wallet_prepareCalls\",\n params: [\n {\n ...params,\n chainId: params.chainId ?? toHex(client.chain.id),\n from,\n capabilities,\n },\n ],\n });\n LOGGER.debug(\"prepareCalls:done\");\n return res;\n}\n"]}
@@ -1,16 +1,12 @@
1
- import type { InnerWalletApiClient, OptionalChainId } from "../types.ts";
2
- import { type Address, type IsUndefined, type Prettify } from "viem";
1
+ import type { InnerWalletApiClient, OptionalChainId, OptionalFrom } from "../types.ts";
2
+ import { type Prettify } from "viem";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
4
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
5
  Request: {
6
6
  method: "wallet_prepareSign";
7
7
  };
8
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
- })>;
9
+ export type PrepareSignParams = Prettify<OptionalFrom<OptionalChainId<RpcSchema["Request"]["params"][0]>>>;
14
10
  export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
15
11
  /**
16
12
  * Prepares a signature request for signing messages or transactions.
@@ -29,5 +25,5 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
29
25
  * });
30
26
  * ```
31
27
  */
32
- export declare function prepareSign<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: PrepareSignParams<TAccount>): Promise<PrepareSignResult>;
28
+ export declare function prepareSign(client: InnerWalletApiClient, params: PrepareSignParams): Promise<PrepareSignResult>;
33
29
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAiD,MAAM,MAAM,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBtC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAG/B,MAA4B,EAC5B,MAAmC;IAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC/B,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE;YACN;gBACE,GAAG,MAAM;gBACT,IAAI;gBACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;aAClD;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { InnerWalletApiClient, OptionalChainId } from \"../types.ts\";\nimport { toHex, type Address, type IsUndefined, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_prepareSign\";\n };\n }\n>;\n\nexport type PrepareSignParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n OptionalChainId<Omit<RpcSchema[\"Request\"][\"params\"][0], \"from\">> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never })\n>;\n\nexport type PrepareSignResult = Prettify<RpcSchema[\"ReturnType\"]>;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * from: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareSignParams<TAccount>,\n): Promise<PrepareSignResult> {\n const from = params.from ?? client.account?.address;\n if (!from) {\n LOGGER.warn(\"prepareSign:no-from\", { hasClientAccount: !!client.account });\n throw new AccountNotFoundError();\n }\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\n const res = await client.request({\n method: \"wallet_prepareSign\",\n params: [\n {\n ...params,\n from,\n chainId: params.chainId ?? toHex(client.chain.id),\n },\n ],\n });\n LOGGER.debug(\"prepareSign:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"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"]}
@@ -2,7 +2,6 @@ import type { Address } from "abitype";
2
2
  import { type Prettify } from "viem";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
4
  import type { InnerWalletApiClient } from "../types";
5
- import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
6
5
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
7
6
  Request: {
8
7
  method: "wallet_requestAccount";
@@ -10,16 +9,23 @@ type RpcSchema = Extract<WalletServerRpcSchemaType, {
10
9
  }>;
11
10
  export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
12
11
  signerAddress: Address;
12
+ }>, "signerAddress" | "includeCounterfactualInfo"> & ({
13
+ signerAddress?: Address;
14
+ accountAddress?: never;
13
15
  } | {
14
- signerPublicKey: WebAuthnPublicKey;
15
- }>, "signerAddress" | "signerPublicKey" | "includeCounterfactualInfo"> & {
16
- accountAddress?: Address;
17
- }>;
16
+ signerAddress?: never;
17
+ accountAddress: Address;
18
+ })>;
18
19
  export type RequestAccountResult = Prettify<{
19
20
  address: Address;
20
21
  }>;
21
22
  /**
22
- * Requests an account for the provided signer using the wallet API client.
23
+ * Requests a smart account address for the provided signer using the wallet API client.
24
+ *
25
+ * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
26
+ * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
27
+ * directly without first calling `requestAccount`.
28
+ *
23
29
  * If an account already exists for the signer, it will always return that account unless a new ID is specified.
24
30
  * If an account already exists, the creationHint will be ignored.
25
31
  *
@@ -31,9 +37,8 @@ export type RequestAccountResult = Prettify<{
31
37
  *
32
38
  * @example
33
39
  * ```ts
34
- * // Request an account with default parameters using a local signer
35
- * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
36
- * const account = await client.requestAccount(signer);
40
+ * // Request a non-7702 smart account
41
+ * const account = await client.requestAccount();
37
42
  * ```
38
43
  */
39
44
  export declare function requestAccount(client: InnerWalletApiClient, params?: RequestAccountParams): Promise<RequestAccountResult>;
@@ -1,10 +1,14 @@
1
- import { BaseError } from "viem";
1
+ import { isAddressEqual } from "viem";
2
2
  import deepEqual from "deep-equal";
3
3
  import { LOGGER } from "../logger.js";
4
- import { isWebAuthnAccount } from "../utils/assertions.js";
5
- import { getSignerAddressOrPublicKey } from "../utils/signer.js";
4
+ import { isLocalAccount } from "../utils/assertions.js";
6
5
  /**
7
- * Requests an account for the provided signer using the wallet API client.
6
+ * Requests a smart account address for the provided signer using the wallet API client.
7
+ *
8
+ * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
9
+ * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
10
+ * directly without first calling `requestAccount`.
11
+ *
8
12
  * If an account already exists for the signer, it will always return that account unless a new ID is specified.
9
13
  * If an account already exists, the creationHint will be ignored.
10
14
  *
@@ -16,9 +20,8 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
16
20
  *
17
21
  * @example
18
22
  * ```ts
19
- * // Request an account with default parameters using a local signer
20
- * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
21
- * const account = await client.requestAccount(signer);
23
+ * // Request a non-7702 smart account
24
+ * const account = await client.requestAccount();
22
25
  * ```
23
26
  */
24
27
  export async function requestAccount(client, params) {
@@ -26,51 +29,24 @@ export async function requestAccount(client, params) {
26
29
  hasParams: !!params,
27
30
  hasAccountOnClient: !!client.account,
28
31
  });
29
- const { creationHint = {} } = params ?? {};
30
- if (isWebAuthnAccount(client.owner)) {
31
- if (creationHint.accountType &&
32
- creationHint.accountType !== "mav2-webauthn") {
33
- throw new BaseError("WebAuthn signers are only supported with mav2-webauthn account type");
34
- }
35
- }
36
- else {
37
- // Non-webauthn signers do not support the "mav2-webauthn" account type.
38
- if (creationHint.accountType === "mav2-webauthn") {
39
- throw new BaseError("ECDSA (secp256k1) signers are not supported with mav2-webauthn account type");
40
- }
41
- }
42
- const owner = getSignerAddressOrPublicKey(client.owner);
43
- const args = (client.account && !params) || params?.accountAddress
32
+ const signerAddress = (params && "signerAddress" in params ? params.signerAddress : undefined) ??
33
+ (isLocalAccount(client.owner)
34
+ ? client.owner.address
35
+ : client.owner.account.address);
36
+ const args = params && "accountAddress" in params && params.accountAddress
44
37
  ? {
45
- accountAddress: params?.accountAddress ?? client.account.address,
38
+ accountAddress: params.accountAddress,
46
39
  includeCounterfactualInfo: true,
47
40
  }
48
41
  : {
49
- ...(owner.type === "webauthn-p256"
50
- ? {
51
- signerPublicKey: {
52
- ...owner.publicKey,
53
- type: "webauthn-p256",
54
- },
55
- // Casts here are safe due to our checks above.
56
- ...(creationHint
57
- ? { creationHint: creationHint }
58
- : {}),
59
- }
60
- : {
61
- signerAddress: owner.address,
62
- ...(creationHint
63
- ? {
64
- creationHint: creationHint,
65
- }
66
- : {}),
67
- }),
42
+ ...params,
43
+ signerAddress,
68
44
  includeCounterfactualInfo: true,
69
45
  };
70
46
  const cachedAccount = client.internal?.getAccount();
71
47
  if (cachedAccount &&
72
- ((params?.accountAddress &&
73
- cachedAccount.address === params.accountAddress) ||
48
+ ((args.accountAddress &&
49
+ isAddressEqual(cachedAccount.address, args.accountAddress)) ||
74
50
  deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
75
51
  LOGGER.debug("requestAccount:cache-hit", {
76
52
  address: cachedAccount.address,
@@ -1 +1 @@
1
- {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiB,MAAM,MAAM,CAAC;AAEhD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAMtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAuBjE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA6B;IAE7B,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;QACnC,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;KACrC,CAAC,CAAC;IAEH,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;IAE3C,IAAI,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,IACE,YAAY,CAAC,WAAW;YACxB,YAAY,CAAC,WAAW,KAAK,eAAe,EAC5C,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,qEAAqE,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,wEAAwE;QACxE,IAAI,YAAY,CAAC,WAAW,KAAK,eAAe,EAAE,CAAC;YACjD,MAAM,IAAI,SAAS,CACjB,6EAA6E,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,2BAA2B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAExD,MAAM,IAAI,GACR,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,cAAc;QACnD,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,MAAM,CAAC,OAAQ,CAAC,OAAO;YACjE,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe;gBAChC,CAAC,CAAC;oBACE,eAAe,EAAE;wBACf,GAAG,KAAK,CAAC,SAAS;wBAClB,IAAI,EAAE,eAAe;qBACtB;oBACD,+CAA+C;oBAC/C,GAAG,CAAC,YAAY;wBACd,CAAC,CAAC,EAAE,YAAY,EAAE,YAA0C,EAAE;wBAC9D,CAAC,CAAC,EAAE,CAAC;iBACR;gBACH,CAAC,CAAC;oBACE,aAAa,EAAE,KAAK,CAAC,OAAO;oBAC5B,GAAG,CAAC,YAAY;wBACd,CAAC,CAAC;4BACE,YAAY,EACV,YAA8C;yBACjD;wBACH,CAAC,CAAC,EAAE,CAAC;iBACR,CAAC;YACN,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEpD,IACE,aAAa;QACb,CAAC,CAAC,MAAM,EAAE,cAAc;YACtB,aAAa,CAAC,OAAO,KAAK,MAAM,CAAC,cAAc,CAAC;YAChD,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { BaseError, type Prettify } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport type {\n CreationOptionsByPublicKey,\n CreationOptionsBySignerAddress,\n WebAuthnPublicKey,\n} from \"@alchemy/wallet-api-types\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\nimport { getSignerAddressOrPublicKey } from \"../utils/signer.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_requestAccount\";\n };\n }\n>;\n\nexport type RequestAccountParams = Prettify<\n Omit<\n Extract<\n RpcSchema[\"Request\"][\"params\"][0],\n { signerAddress: Address } | { signerPublicKey: WebAuthnPublicKey }\n >,\n \"signerAddress\" | \"signerPublicKey\" | \"includeCounterfactualInfo\"\n > & { accountAddress?: Address }\n>;\n\nexport type RequestAccountResult = Prettify<{ address: Address }>;\n\n/**\n * Requests an account for the provided signer using the wallet API client.\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request an account with default parameters using a local signer\n * const signer = LocalAccountSigner.privateKeyToAccountSigner(\"0x...\");\n * const account = await client.requestAccount(signer);\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const { creationHint = {} } = params ?? {};\n\n if (isWebAuthnAccount(client.owner)) {\n if (\n creationHint.accountType &&\n creationHint.accountType !== \"mav2-webauthn\"\n ) {\n throw new BaseError(\n \"WebAuthn signers are only supported with mav2-webauthn account type\",\n );\n }\n } else {\n // Non-webauthn signers do not support the \"mav2-webauthn\" account type.\n if (creationHint.accountType === \"mav2-webauthn\") {\n throw new BaseError(\n \"ECDSA (secp256k1) signers are not supported with mav2-webauthn account type\",\n );\n }\n }\n\n const owner = getSignerAddressOrPublicKey(client.owner);\n\n const args: RpcSchema[\"Request\"][\"params\"][0] =\n (client.account && !params) || params?.accountAddress\n ? {\n accountAddress: params?.accountAddress ?? client.account!.address,\n includeCounterfactualInfo: true,\n }\n : {\n ...(owner.type === \"webauthn-p256\"\n ? {\n signerPublicKey: {\n ...owner.publicKey,\n type: \"webauthn-p256\",\n },\n // Casts here are safe due to our checks above.\n ...(creationHint\n ? { creationHint: creationHint as CreationOptionsByPublicKey }\n : {}),\n }\n : {\n signerAddress: owner.address,\n ...(creationHint\n ? {\n creationHint:\n creationHint as CreationOptionsBySignerAddress,\n }\n : {}),\n }),\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((params?.accountAddress &&\n cachedAccount.address === params.accountAddress) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n };\n }\n\n const resp = await client.request({\n method: \"wallet_requestAccount\",\n params: [args],\n });\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n return {\n address: resp.accountAddress,\n };\n}\n"]}
1
+ {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA6B;IAE7B,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;QACnC,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;KACrC,CAAC,CAAC;IAEH,MAAM,aAAa,GACjB,CAAC,MAAM,IAAI,eAAe,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,IAAI,GACR,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc;QAC3D,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC;YACE,GAAG,MAAM;YACT,aAAa;YACb,yBAAyB,EAAE,IAAI;SAChC,CAAC;IAER,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEpD,IACE,aAAa;QACb,CAAC,CAAC,IAAI,CAAC,cAAc;YACnB,cAAc,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3D,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;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"]}