@alchemy/wallet-apis 0.0.0-alpha.13 → 0.0.0-alpha.15

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 (75) hide show
  1. package/dist/esm/actions/grantPermissions.js +9 -2
  2. package/dist/esm/actions/grantPermissions.js.map +1 -1
  3. package/dist/esm/actions/listAccounts.d.ts +10 -2
  4. package/dist/esm/actions/listAccounts.js +23 -2
  5. package/dist/esm/actions/listAccounts.js.map +1 -1
  6. package/dist/esm/actions/requestAccount.d.ts +10 -3
  7. package/dist/esm/actions/requestAccount.js +43 -15
  8. package/dist/esm/actions/requestAccount.js.map +1 -1
  9. package/dist/esm/actions/sendCalls.d.ts +4 -0
  10. package/dist/esm/actions/sendCalls.js +22 -1
  11. package/dist/esm/actions/sendCalls.js.map +1 -1
  12. package/dist/esm/actions/signMessage.js +5 -1
  13. package/dist/esm/actions/signMessage.js.map +1 -1
  14. package/dist/esm/actions/signPreparedCalls.js +6 -1
  15. package/dist/esm/actions/signPreparedCalls.js.map +1 -1
  16. package/dist/esm/actions/signSignatureRequest.d.ts +10 -3
  17. package/dist/esm/actions/signSignatureRequest.js +93 -42
  18. package/dist/esm/actions/signSignatureRequest.js.map +1 -1
  19. package/dist/esm/actions/signTypedData.js +5 -1
  20. package/dist/esm/actions/signTypedData.js.map +1 -1
  21. package/dist/esm/client.d.ts +4 -4
  22. package/dist/esm/client.js +3 -13
  23. package/dist/esm/client.js.map +1 -1
  24. package/dist/esm/types.d.ts +4 -7
  25. package/dist/esm/types.js.map +1 -1
  26. package/dist/esm/utils/assertions.d.ts +6 -2
  27. package/dist/esm/utils/assertions.js +9 -0
  28. package/dist/esm/utils/assertions.js.map +1 -1
  29. package/dist/esm/utils/format.d.ts +3 -1
  30. package/dist/esm/utils/format.js +11 -1
  31. package/dist/esm/utils/format.js.map +1 -1
  32. package/dist/esm/utils/signer.d.ts +10 -0
  33. package/dist/esm/utils/signer.js +28 -0
  34. package/dist/esm/utils/signer.js.map +1 -0
  35. package/dist/esm/version.d.ts +1 -1
  36. package/dist/esm/version.js +1 -1
  37. package/dist/esm/version.js.map +1 -1
  38. package/dist/types/actions/grantPermissions.d.ts.map +1 -1
  39. package/dist/types/actions/listAccounts.d.ts +10 -2
  40. package/dist/types/actions/listAccounts.d.ts.map +1 -1
  41. package/dist/types/actions/requestAccount.d.ts +10 -3
  42. package/dist/types/actions/requestAccount.d.ts.map +1 -1
  43. package/dist/types/actions/sendCalls.d.ts +4 -0
  44. package/dist/types/actions/sendCalls.d.ts.map +1 -1
  45. package/dist/types/actions/signMessage.d.ts.map +1 -1
  46. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
  47. package/dist/types/actions/signSignatureRequest.d.ts +10 -3
  48. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
  49. package/dist/types/actions/signTypedData.d.ts.map +1 -1
  50. package/dist/types/client.d.ts +4 -4
  51. package/dist/types/client.d.ts.map +1 -1
  52. package/dist/types/types.d.ts +4 -7
  53. package/dist/types/types.d.ts.map +1 -1
  54. package/dist/types/utils/assertions.d.ts +6 -2
  55. package/dist/types/utils/assertions.d.ts.map +1 -1
  56. package/dist/types/utils/format.d.ts +3 -1
  57. package/dist/types/utils/format.d.ts.map +1 -1
  58. package/dist/types/utils/signer.d.ts +11 -0
  59. package/dist/types/utils/signer.d.ts.map +1 -0
  60. package/dist/types/version.d.ts +1 -1
  61. package/package.json +6 -5
  62. package/src/actions/grantPermissions.ts +13 -2
  63. package/src/actions/listAccounts.ts +39 -5
  64. package/src/actions/requestAccount.ts +67 -22
  65. package/src/actions/sendCalls.ts +33 -1
  66. package/src/actions/signMessage.ts +8 -0
  67. package/src/actions/signPreparedCalls.ts +14 -1
  68. package/src/actions/signSignatureRequest.ts +165 -54
  69. package/src/actions/signTypedData.ts +8 -0
  70. package/src/client.ts +5 -23
  71. package/src/types.ts +5 -5
  72. package/src/utils/assertions.ts +21 -2
  73. package/src/utils/format.ts +20 -1
  74. package/src/utils/signer.ts +36 -0
  75. package/src/version.ts +1 -1
@@ -1,7 +1,8 @@
1
1
  import { toHex, concatHex, } from "viem";
2
2
  import { signSignatureRequest } from "./signSignatureRequest.js";
3
- import { AccountNotFoundError } from "@alchemy/common";
3
+ import { AccountNotFoundError, BaseError } from "@alchemy/common";
4
4
  import { LOGGER } from "../logger.js";
5
+ import { isWebAuthnAccount } from "../utils/assertions.js";
5
6
  /**
6
7
  * Grants permissions to a smart account by creating a session.
7
8
  * This allows another key to perform operations on behalf of the account.
@@ -62,6 +63,10 @@ export async function grantPermissions(client, params) {
62
63
  LOGGER.warn("grantPermissions:no-account");
63
64
  throw new AccountNotFoundError();
64
65
  }
66
+ if (isWebAuthnAccount(client.owner)) {
67
+ LOGGER.warn("grantPermissions:unsupported-account");
68
+ throw new BaseError("WebAuthn signer is not currently supported for grantPermissions");
69
+ }
65
70
  LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
66
71
  const { sessionId, signatureRequest } = await client.request({
67
72
  method: "wallet_createSession",
@@ -78,7 +83,9 @@ export async function grantPermissions(client, params) {
78
83
  context: concatHex([
79
84
  "0x00", // Remote mode.
80
85
  sessionId,
81
- signature.data,
86
+ signature.type === "webauthn-p256"
87
+ ? signature.data.signature
88
+ : signature.data,
82
89
  ]),
83
90
  };
84
91
  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,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"]}
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,14 +1,22 @@
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";
4
5
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
5
6
  Request: {
6
7
  method: "wallet_listAccounts";
7
8
  };
8
9
  }>;
9
- export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & {
10
+ export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress"> & ({
10
11
  signerAddress?: Address;
11
- }>;
12
+ signerPublicKey?: never;
13
+ } | {
14
+ signerPublicKey: WebAuthnPublicKey;
15
+ signerAddress?: never;
16
+ } | {
17
+ signerAddress?: never;
18
+ signerPublicKey?: never;
19
+ })>;
12
20
  export type ListAccountsResult = Prettify<RpcSchema["ReturnType"]>;
13
21
  /**
14
22
  * Lists all smart accounts for a given signer using the wallet API client.
@@ -1,4 +1,5 @@
1
1
  import { LOGGER } from "../logger.js";
2
+ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
2
3
  /**
3
4
  * Lists all smart accounts for a given signer using the wallet API client.
4
5
  *
@@ -26,14 +27,34 @@ import { LOGGER } from "../logger.js";
26
27
  * ```
27
28
  */
28
29
  export async function listAccounts(client, params) {
29
- const signerAddress = params.signerAddress ?? client.owner.account.address;
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
51
  LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
31
52
  const res = await client.request({
32
53
  method: "wallet_listAccounts",
33
54
  params: [
34
55
  {
35
56
  ...params,
36
- signerAddress,
57
+ ...signerParam,
37
58
  },
38
59
  ],
39
60
  });
@@ -1 +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"]}
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,13 +1,20 @@
1
1
  import type { Address } from "abitype";
2
- import type { Prettify, UnionOmit } from "viem";
2
+ import { type Prettify } from "viem";
3
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
- import type { InnerWalletApiClient, OptionalSignerAddress } from "../types";
4
+ import type { InnerWalletApiClient } from "../types";
5
+ import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
5
6
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
7
  Request: {
7
8
  method: "wallet_requestAccount";
8
9
  };
9
10
  }>;
10
- export type RequestAccountParams = Prettify<OptionalSignerAddress<UnionOmit<RpcSchema["Request"]["params"][0], "includeCounterfactualInfo">>>;
11
+ export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
12
+ signerAddress: Address;
13
+ } | {
14
+ signerPublicKey: WebAuthnPublicKey;
15
+ }>, "signerAddress" | "signerPublicKey" | "includeCounterfactualInfo"> & {
16
+ accountAddress?: Address;
17
+ }>;
11
18
  export type RequestAccountResult = Prettify<{
12
19
  address: Address;
13
20
  }>;
@@ -1,5 +1,8 @@
1
+ import { BaseError } from "viem";
1
2
  import deepEqual from "deep-equal";
2
3
  import { LOGGER } from "../logger.js";
4
+ import { isWebAuthnAccount } from "../utils/assertions.js";
5
+ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
3
6
  /**
4
7
  * Requests an account for the provided signer using the wallet API client.
5
8
  * If an account already exists for the signer, it will always return that account unless a new ID is specified.
@@ -23,26 +26,51 @@ export async function requestAccount(client, params) {
23
26
  hasParams: !!params,
24
27
  hasAccountOnClient: !!client.account,
25
28
  });
26
- const args = client.account && !params
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
27
44
  ? {
28
- accountAddress: client.account.address,
45
+ accountAddress: params?.accountAddress ?? client.account.address,
29
46
  includeCounterfactualInfo: true,
30
47
  }
31
- : params != null && "accountAddress" in params
32
- ? {
33
- accountAddress: params.accountAddress,
34
- includeCounterfactualInfo: true,
35
- }
36
- : {
37
- ...params,
38
- signerAddress: (params && "signerAddress" in params
39
- ? params.signerAddress
40
- : undefined) ?? client.owner.account.address,
41
- includeCounterfactualInfo: true,
42
- };
48
+ : {
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
+ }),
68
+ includeCounterfactualInfo: true,
69
+ };
43
70
  const cachedAccount = client.internal?.getAccount();
44
71
  if (cachedAccount &&
45
- ((args.accountAddress && cachedAccount.address === args.accountAddress) ||
72
+ ((params?.accountAddress &&
73
+ cachedAccount.address === params.accountAddress) ||
46
74
  deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
47
75
  LOGGER.debug("requestAccount:cache-hit", {
48
76
  address: cachedAccount.address,
@@ -1 +1 @@
1
- {"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAmBtC;;;;;;;;;;;;;;;;;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;IACH,MAAM,IAAI,GACR,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM;QACvB,CAAC,CAAC;YACE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;YACtC,yBAAyB,EAAE,IAAI;SAChC;QACH,CAAC,CAAC,MAAM,IAAI,IAAI,IAAI,gBAAgB,IAAI,MAAM;YAC5C,CAAC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port type { Prettify, UnionOmit } from \"viem\";\nimport type { WalletServerRpcSchemaType } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { InnerWalletApiClient, OptionalSignerAddress } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\n\ntype RpcSchema = Extract<\n WalletServerRpcSchemaType,\n {\n Request: {\n method: \"wallet_requestAccount\";\n };\n }\n>;\n\nexport type RequestAccountParams = Prettify<\n OptionalSignerAddress<\n UnionOmit<RpcSchema[\"Request\"][\"params\"][0], \"includeCounterfactualInfo\">\n >\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 const args =\n client.account && !params\n ? {\n accountAddress: client.account.address,\n includeCounterfactualInfo: true,\n }\n : params != null && \"accountAddress\" in params\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress:\n (params && \"signerAddress\" in params\n ? params.signerAddress\n : undefined) ?? client.owner.account.address,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress && 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 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,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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AE;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"]}
@@ -30,5 +30,9 @@ export type SendCallsResult = Prettify<SendPreparedCallsResult>;
30
30
  * // The result contains the prepared call IDs
31
31
  * console.log(result.preparedCallIds);
32
32
  * ```
33
+ * <Note>
34
+ * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
35
+ * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.
36
+ * </Note>
33
37
  */
34
38
  export declare function sendCalls<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, params: SendCallsParams<TAccount>): Promise<SendCallsResult>;
@@ -2,6 +2,9 @@ import { prepareCalls } from "./prepareCalls.js";
2
2
  import { signPreparedCalls } from "./signPreparedCalls.js";
3
3
  import { sendPreparedCalls, } from "./sendPreparedCalls.js";
4
4
  import { LOGGER } from "../logger.js";
5
+ import { signSignatureRequest } from "./signSignatureRequest.js";
6
+ import { isWebAuthnAccount } from "../utils/assertions.js";
7
+ import { BaseError } from "@alchemy/common";
5
8
  /**
6
9
  * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
7
10
  *
@@ -28,13 +31,31 @@ import { LOGGER } from "../logger.js";
28
31
  * // The result contains the prepared call IDs
29
32
  * console.log(result.preparedCallIds);
30
33
  * ```
34
+ * <Note>
35
+ * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
36
+ * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.
37
+ * </Note>
31
38
  */
32
39
  export async function sendCalls(client, params) {
33
40
  LOGGER.info("sendCalls:start", {
34
41
  calls: params.calls?.length,
35
42
  hasCapabilities: !!params.capabilities,
36
43
  });
37
- const calls = await prepareCalls(client, params);
44
+ let calls = await prepareCalls(client, params);
45
+ if (calls.type === "paymaster-permit") {
46
+ if (isWebAuthnAccount(client.owner)) {
47
+ throw new BaseError("WebAuthn signer is not currently supported for signing paymaster permit signatures");
48
+ }
49
+ const signature = await signSignatureRequest(client, calls.signatureRequest);
50
+ const secondCallParams = {
51
+ from: calls.modifiedRequest.from,
52
+ calls: calls.modifiedRequest.calls,
53
+ capabilities: calls.modifiedRequest.capabilities,
54
+ // WebAuthn signatures are not supported for paymaster permits (throws above).
55
+ paymasterPermitSignature: signature,
56
+ };
57
+ calls = await prepareCalls(client, secondCallParams);
58
+ }
38
59
  const signedCalls = await signPreparedCalls(client, calls);
39
60
  const res = await sendPreparedCalls(client, {
40
61
  ...signedCalls,
@@ -1 +1 @@
1
- {"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAQtC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAG7B,MAA4B,EAC5B,MAAiC;IAEjC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAC3B,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE3D,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE;QAC1C,GAAG,WAAW;QACd,6EAA6E;QAC7E,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,IAAI;YAC1C,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE;YACpE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Address, Prettify } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SendCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<PrepareCallsParams<TAccount>>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for sending calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (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<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs.\n *\n * @example\n * ```ts\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the prepared call IDs\n * console.log(result.preparedCallIds);\n * ```\n */\nexport async function sendCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: SendCallsParams<TAccount>,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const calls = await prepareCalls(client, params);\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n // The only capability that is supported in sendPreparedCalls is permissions.\n ...(params.capabilities?.permissions != null\n ? { capabilities: { permissions: params.capabilities.permissions } }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
1
+ {"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAG7B,MAA4B,EAC5B,MAAiC;IAEjC,MAAM,CAAC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AC;AACb,CAAC","sourcesContent":["import type { Address, Prettify } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\nimport { BaseError } from \"@alchemy/common\";\n\nexport type SendCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<PrepareCallsParams<TAccount>>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for sending calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (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<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs.\n *\n * @example\n * ```ts\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the prepared call IDs\n * console.log(result.preparedCallIds);\n * ```\n * <Note>\n * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden\n * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.\n * </Note>\n */\nexport async function sendCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: SendCallsParams<TAccount>,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n let calls = await prepareCalls(client, params);\n\n if (calls.type === \"paymaster-permit\") {\n if (isWebAuthnAccount(client.owner)) {\n throw new BaseError(\n \"WebAuthn signer is not currently supported for signing paymaster permit signatures\",\n );\n }\n const signature = await signSignatureRequest(\n client,\n calls.signatureRequest,\n );\n\n const secondCallParams = {\n from: calls.modifiedRequest.from,\n calls: calls.modifiedRequest.calls,\n capabilities: calls.modifiedRequest.capabilities,\n // WebAuthn signatures are not supported for paymaster permits (throws above).\n paymasterPermitSignature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n\n calls = await prepareCalls(client, secondCallParams);\n }\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n // The only capability that is supported in sendPreparedCalls is permissions.\n ...(params.capabilities?.permissions != null\n ? { capabilities: { permissions: params.capabilities.permissions } }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import {} from "viem";
1
+ import { BaseError, } from "viem";
2
2
  import { requestAccount } from "./requestAccount.js";
3
3
  import { prepareSign } from "./prepareSign.js";
4
4
  import { signSignatureRequest } from "./signSignatureRequest.js";
@@ -38,6 +38,10 @@ export async function signMessage(client, params) {
38
38
  },
39
39
  });
40
40
  const signed = await signSignatureRequest(client, prepared.signatureRequest);
41
+ // TODO: Wallet server needs to be updated to support webauthn here.
42
+ if (signed.type === "webauthn-p256") {
43
+ throw new BaseError("WebAuthn account is currently unsupported by wallet_formatSign");
44
+ }
41
45
  const formatted = await formatSign(client, {
42
46
  from: account.address,
43
47
  signature: {
@@ -1 +1 @@
1
- {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,cAAc,E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AAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Prettify,\n type SignableMessage,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { requestAccount } from \"./requestAccount.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { signableMessageToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SignMessageParams = Prettify<{\n message: SignableMessage;\n account?: Address;\n}>;\n\nexport type SignMessageResult = Prettify<Hex>;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignMessageParams} params - Parameters for signing the message\n * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.\n * @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * ```ts\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n * ```\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const accountAddress = params.account ?? client.account?.address;\n LOGGER.debug(\"signMessage:start\", {\n hasExplicitAccount: params.account != null,\n });\n\n const account = await requestAccount(\n client,\n accountAddress != null ? { accountAddress } : undefined,\n );\n\n const prepared = await prepareSign(client, {\n from: account.address,\n signatureRequest: {\n type: \"personal_sign\",\n data: signableMessageToJsonSafe(params.message),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n const formatted = await formatSign(client, {\n from: account.address,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signMessage:done\", { from: account.address });\n return formatted.signature;\n}\n"]}
1
+ {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../../src/actions/signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAStC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IACjE,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE;QAChC,kBAAkB,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;KAC3C,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,cAAc,CAClC,MAAM,EACN,cAAc,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS,CACxD,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE;QACzC,IAAI,EAAE,OAAO,CAAC,OAAO;QACrB,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC;SAChD;KACF,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAE7E,oEAAoE;IACpE,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QACpC,MAAM,IAAI,SAAS,CACjB,gEAAgE,CACjE,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACzC,IAAI,EAAE,OAAO,CAAC,OAAO;QACrB,SAAS,EAAE;YACT,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Prettify,\n type SignableMessage,\n BaseError,\n} from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { requestAccount } from \"./requestAccount.js\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { signableMessageToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\n\nexport type SignMessageParams = Prettify<{\n message: SignableMessage;\n account?: Address;\n}>;\n\nexport type SignMessageResult = Prettify<Hex>;\n\n/**\n * Signs a message using the smart account.\n * This method requests the account associated with the signer and uses it to sign the message.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SignMessageParams} params - Parameters for signing the message\n * @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.\n * @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.\n * @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string\n *\n * @example\n * ```ts\n * // Sign a simple text message\n * const signature = await client.signMessage(\"Hello, world!\");\n *\n * // Sign a raw hex message\n * const signature = await client.signMessage({ raw: \"0x48656c6c6f2c20776f726c6421\" });\n * ```\n */\nexport async function signMessage(\n client: InnerWalletApiClient,\n params: SignMessageParams,\n): Promise<SignMessageResult> {\n const accountAddress = params.account ?? client.account?.address;\n LOGGER.debug(\"signMessage:start\", {\n hasExplicitAccount: params.account != null,\n });\n\n const account = await requestAccount(\n client,\n accountAddress != null ? { accountAddress } : undefined,\n );\n\n const prepared = await prepareSign(client, {\n from: account.address,\n signatureRequest: {\n type: \"personal_sign\",\n data: signableMessageToJsonSafe(params.message),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n // TODO: Wallet server needs to be updated to support webauthn here.\n if (signed.type === \"webauthn-p256\") {\n throw new BaseError(\n \"WebAuthn account is currently unsupported by wallet_formatSign\",\n );\n }\n\n const formatted = await formatSign(client, {\n from: account.address,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signMessage:done\", { from: account.address });\n return formatted.signature;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { assertNever, BaseError } from "@alchemy/common";
2
2
  import { signSignatureRequest } from "./signSignatureRequest.js";
3
3
  import { LOGGER } from "../logger.js";
4
+ import { isWebAuthnAccount } from "../utils/assertions.js";
4
5
  /**
5
6
  * Signs prepared calls using the provided signer.
6
7
  *
@@ -30,6 +31,9 @@ export async function signPreparedCalls(client, params) {
30
31
  LOGGER.debug("signPreparedCalls:start", { type: params.type });
31
32
  const signAuthorizationCall = async (call) => {
32
33
  const { signatureRequest: _signatureRequest, ...rest } = call;
34
+ if (isWebAuthnAccount(client.owner)) {
35
+ throw new BaseError("WebAuthn account cannot sign EIP-7702 authorization requests");
36
+ }
33
37
  const signature = await signSignatureRequest(client, {
34
38
  type: "eip7702Auth",
35
39
  data: {
@@ -37,9 +41,10 @@ export async function signPreparedCalls(client, params) {
37
41
  chainId: call.chainId,
38
42
  },
39
43
  });
44
+ // Authorization signatures are never webauthn-256 (throws above).
40
45
  return {
41
46
  ...rest,
42
- signature,
47
+ signature: signature,
43
48
  };
44
49
  };
45
50
  const signUserOperationCall = async (call) => {
@@ -1 +1 @@
1
- {"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/signPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAQjE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAOtC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,MAA+B;IAE/B,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,qBAAqB,GAAG,KAAK,EAAE,IAAgC,EAAE,EAAE;QACvE,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE;YACnD,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE;gBACJ,GAAG,IAAI,CAAC,IAAI;gBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC,CAAC;QACH,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,KAAK,EACjC,IAAuD,EACvD,EAAE;QACF,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAE3C,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,4CAA4C,EAAE;gBACxD,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CA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ACjB,qBAAqB,MAAM,CAAC,IAAI,6BAA6B,CAC9D,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE;YACpD,IAAI,EAAG,MAA6B,CAAC,IAAI;SAC1C,CAAC,CAAC;QACH,OAAO,WAAW,CAChB,MAAM,EACN,2BAA2B,MAAM,6BAA6B,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { assertNever, BaseError } from \"@alchemy/common\";\nimport type { PrepareCallsResult } from \"./prepareCalls.ts\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport type { Prettify } from \"viem\";\nimport type {\n PreparedCall_Authorization,\n PreparedCall_UserOpV060,\n PreparedCall_UserOpV070,\n} from \"@alchemy/wallet-api-types\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { LOGGER } from \"../logger.js\";\nimport type { SendPreparedCallsParams } from \"./sendPreparedCalls.js\";\n\nexport type SignPreparedCallsParams = Prettify<PrepareCallsResult>;\n\nexport type SignPreparedCallsResult = SendPreparedCallsParams;\n\n/**\n * Signs prepared calls using the provided signer.\n *\n * @param {InnerWalletApiClient} client - The wallet client to use for signing\n * @param {SignPreparedCallsParams} params - The prepared calls with signature requests\n * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls\n *\n * @example\n * ```ts\n * // Prepare a user operation call.\n * const preparedCalls = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * });\n *\n * // Sign the prepared calls.\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Send the signed calls.\n * const result = await client.sendPreparedCalls(signedCalls);\n * ```\n */\nexport async function signPreparedCalls(\n client: InnerWalletApiClient,\n params: SignPreparedCallsParams,\n): Promise<SignPreparedCallsResult> {\n LOGGER.debug(\"signPreparedCalls:start\", { type: params.type });\n const signAuthorizationCall = async (call: PreparedCall_Authorization) => {\n const { signatureRequest: _signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(client, {\n type: \"eip7702Auth\",\n data: {\n ...rest.data,\n chainId: call.chainId,\n },\n });\n return {\n ...rest,\n signature,\n };\n };\n\n const signUserOperationCall = async (\n call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,\n ) => {\n const { signatureRequest, ...rest } = call;\n\n if (!signatureRequest) {\n LOGGER.warn(\"signPreparedCalls:missing-signatureRequest\", {\n type: call.type,\n });\n throw new BaseError(\n \"Signature request is required for signing user operation calls. Ensure `onlyEstimation` is set to `false` when calling `prepareCalls`.\",\n );\n }\n\n const signature = await signSignatureRequest(client, signatureRequest);\n const res = {\n ...rest,\n signature,\n } as const;\n LOGGER.debug(\"signPreparedCalls:userOp:ok\");\n return res;\n };\n\n if (params.type === \"array\") {\n const res = {\n type: \"array\" as const,\n data: await Promise.all(\n params.data.map((call) =>\n call.type === \"authorization\"\n ? signAuthorizationCall(call)\n : signUserOperationCall(call),\n ),\n ),\n };\n LOGGER.debug(\"signPreparedCalls:array:ok\", { count: res.data.length });\n return res;\n } else if (\n params.type === \"user-operation-v060\" ||\n params.type === \"user-operation-v070\"\n ) {\n const res = await signUserOperationCall(params);\n LOGGER.debug(\"signPreparedCalls:single-userOp:ok\");\n return res;\n } else if (params.type === \"paymaster-permit\") {\n LOGGER.warn(\"signPreparedCalls:invalid-call-type\", { type: params.type });\n throw new BaseError(\n `Invalid call type ${params.type} for signing prepared calls`,\n );\n } else {\n LOGGER.warn(\"signPreparedCalls:unexpected-call-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(\n params,\n `Unexpected call type in ${params} for signing prepared calls`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/signPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC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,EAAE;YACpD,IAAI,EAAG,MAA6B,CAAC,IAAI;SAC1C,CAAC,CAAC;QACH,OAAO,WAAW,CAChB,MAAM,EACN,2BAA2B,MAAM,6BAA6B,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { assertNever, BaseError } from \"@alchemy/common\";\nimport type { PrepareCallsResult } from \"./prepareCalls.ts\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport type { Prettify } from \"viem\";\nimport type {\n PreparedCall_Authorization,\n PreparedCall_UserOpV060,\n PreparedCall_UserOpV070,\n} from \"@alchemy/wallet-api-types\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { LOGGER } from \"../logger.js\";\nimport type { SendPreparedCallsParams } from \"./sendPreparedCalls.js\";\nimport { isWebAuthnAccount } from \"../utils/assertions.js\";\n\nexport type SignPreparedCallsParams = Prettify<PrepareCallsResult>;\n\nexport type SignPreparedCallsResult = SendPreparedCallsParams;\n\n/**\n * Signs prepared calls using the provided signer.\n *\n * @param {InnerWalletApiClient} client - The wallet client to use for signing\n * @param {SignPreparedCallsParams} params - The prepared calls with signature requests\n * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls\n *\n * @example\n * ```ts\n * // Prepare a user operation call.\n * const preparedCalls = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * });\n *\n * // Sign the prepared calls.\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Send the signed calls.\n * const result = await client.sendPreparedCalls(signedCalls);\n * ```\n */\nexport async function signPreparedCalls(\n client: InnerWalletApiClient,\n params: SignPreparedCallsParams,\n): Promise<SignPreparedCallsResult> {\n LOGGER.debug(\"signPreparedCalls:start\", { type: params.type });\n\n const signAuthorizationCall = async (call: PreparedCall_Authorization) => {\n const { signatureRequest: _signatureRequest, ...rest } = call;\n\n if (isWebAuthnAccount(client.owner)) {\n throw new BaseError(\n \"WebAuthn account cannot sign EIP-7702 authorization requests\",\n );\n }\n\n const signature = await signSignatureRequest(client, {\n type: \"eip7702Auth\",\n data: {\n ...rest.data,\n chainId: call.chainId,\n },\n });\n // Authorization signatures are never webauthn-256 (throws above).\n return {\n ...rest,\n signature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n };\n\n const signUserOperationCall = async (\n call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,\n ) => {\n const { signatureRequest, ...rest } = call;\n\n if (!signatureRequest) {\n LOGGER.warn(\"signPreparedCalls:missing-signatureRequest\", {\n type: call.type,\n });\n throw new BaseError(\n \"Signature request is required for signing user operation calls. Ensure `onlyEstimation` is set to `false` when calling `prepareCalls`.\",\n );\n }\n\n const signature = await signSignatureRequest(client, signatureRequest);\n const res = {\n ...rest,\n signature,\n } as const;\n LOGGER.debug(\"signPreparedCalls:userOp:ok\");\n return res;\n };\n\n if (params.type === \"array\") {\n const res = {\n type: \"array\" as const,\n data: await Promise.all(\n params.data.map((call) =>\n call.type === \"authorization\"\n ? signAuthorizationCall(call)\n : signUserOperationCall(call),\n ),\n ),\n };\n LOGGER.debug(\"signPreparedCalls:array:ok\", { count: res.data.length });\n return res;\n } else if (\n params.type === \"user-operation-v060\" ||\n params.type === \"user-operation-v070\"\n ) {\n const res = await signUserOperationCall(params);\n LOGGER.debug(\"signPreparedCalls:single-userOp:ok\");\n return res;\n } else if (params.type === \"paymaster-permit\") {\n LOGGER.warn(\"signPreparedCalls:invalid-call-type\", { type: params.type });\n throw new BaseError(\n `Invalid call type ${params.type} for signing prepared calls`,\n );\n } else {\n LOGGER.warn(\"signPreparedCalls:unexpected-call-type\", {\n type: (params as { type?: unknown }).type,\n });\n return assertNever(\n params,\n `Unexpected call type in ${params} for signing prepared calls`,\n );\n }\n}\n"]}
@@ -1,18 +1,25 @@
1
1
  import { type Hex, type Prettify } from "viem";
2
2
  import type { PersonalSignSignatureRequest, TypedDataSignatureRequest, AuthorizationSignatureRequest, Eip7702UnsignedAuth } from "@alchemy/wallet-api-types";
3
3
  import type { InnerWalletApiClient, WithoutRawPayload } from "../types";
4
+ import type { WebAuthnSignReturnType } from "viem/account-abstraction";
4
5
  export type SignSignatureRequestParams = Prettify<WithoutRawPayload<PersonalSignSignatureRequest | TypedDataSignatureRequest | (AuthorizationSignatureRequest & {
5
6
  data: Eip7702UnsignedAuth;
6
7
  })>>;
7
- export type SignSignatureRequestResult = Prettify<{
8
+ export type SignSignatureRequestResult = {
8
9
  type: "secp256k1";
9
10
  data: Hex;
10
- }>;
11
+ } | {
12
+ type: "webauthn-p256";
13
+ data: {
14
+ signature: Hex;
15
+ metadata: Pick<WebAuthnSignReturnType["webauthn"], "clientDataJSON" | "authenticatorData">;
16
+ };
17
+ };
11
18
  /**
12
19
  * Signs a signature request using the provided signer.
13
20
  * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
14
21
  *
15
- * @param {SmartAccountSigner} signer - The signer to use for signing the request
22
+ * @param {InnerWalletApiClient} client - The wallet client to use for signing
16
23
  * @param {SignSignatureRequestParams} params - The signature request parameters
17
24
  * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
18
25
  * @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type