@account-kit/wallet-client 4.76.0 → 4.77.0

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 (79) hide show
  1. package/dist/esm/client/actions/grantPermissions.d.ts +3 -3
  2. package/dist/esm/client/actions/grantPermissions.js +28 -3
  3. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  4. package/dist/esm/client/actions/listAccounts.d.ts +11 -7
  5. package/dist/esm/client/actions/listAccounts.js +27 -4
  6. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  7. package/dist/esm/client/actions/requestAccount.d.ts +8 -4
  8. package/dist/esm/client/actions/requestAccount.js +38 -6
  9. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  10. package/dist/esm/client/actions/sendCalls.d.ts +3 -3
  11. package/dist/esm/client/actions/sendCalls.js +5 -2
  12. package/dist/esm/client/actions/sendCalls.js.map +1 -1
  13. package/dist/esm/client/actions/signMessage.d.ts +3 -3
  14. package/dist/esm/client/actions/signMessage.js +1 -2
  15. package/dist/esm/client/actions/signMessage.js.map +1 -1
  16. package/dist/esm/client/actions/signPreparedCalls.d.ts +3 -3
  17. package/dist/esm/client/actions/signPreparedCalls.js +5 -2
  18. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
  19. package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -37
  20. package/dist/esm/client/actions/signSignatureRequest.js +30 -2
  21. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  22. package/dist/esm/client/actions/signTypedData.d.ts +3 -3
  23. package/dist/esm/client/actions/signTypedData.js +1 -1
  24. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  25. package/dist/esm/client/actions/waitForCallsStatus.d.ts +1 -1
  26. package/dist/esm/client/decorator.d.ts +2 -2
  27. package/dist/esm/client/decorator.js +13 -1
  28. package/dist/esm/client/decorator.js.map +1 -1
  29. package/dist/esm/client/index.d.ts +9 -2
  30. package/dist/esm/client/index.js.map +1 -1
  31. package/dist/esm/internal/account.d.ts +3 -2
  32. package/dist/esm/internal/account.js +28 -3
  33. package/dist/esm/internal/account.js.map +1 -1
  34. package/dist/esm/utils.d.ts +6 -0
  35. package/dist/esm/utils.js +14 -1
  36. package/dist/esm/utils.js.map +1 -1
  37. package/dist/esm/version.d.ts +1 -1
  38. package/dist/esm/version.js +1 -1
  39. package/dist/esm/version.js.map +1 -1
  40. package/dist/types/client/actions/grantPermissions.d.ts +3 -3
  41. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  42. package/dist/types/client/actions/listAccounts.d.ts +11 -7
  43. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  44. package/dist/types/client/actions/requestAccount.d.ts +8 -4
  45. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  46. package/dist/types/client/actions/sendCalls.d.ts +3 -3
  47. package/dist/types/client/actions/sendCalls.d.ts.map +1 -1
  48. package/dist/types/client/actions/signMessage.d.ts +3 -3
  49. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  50. package/dist/types/client/actions/signPreparedCalls.d.ts +3 -3
  51. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
  52. package/dist/types/client/actions/signSignatureRequest.d.ts +8 -37
  53. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  54. package/dist/types/client/actions/signTypedData.d.ts +3 -3
  55. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  56. package/dist/types/client/actions/waitForCallsStatus.d.ts +1 -1
  57. package/dist/types/client/decorator.d.ts +2 -2
  58. package/dist/types/client/decorator.d.ts.map +1 -1
  59. package/dist/types/client/index.d.ts +9 -2
  60. package/dist/types/client/index.d.ts.map +1 -1
  61. package/dist/types/internal/account.d.ts +3 -2
  62. package/dist/types/internal/account.d.ts.map +1 -1
  63. package/dist/types/utils.d.ts +6 -0
  64. package/dist/types/utils.d.ts.map +1 -1
  65. package/dist/types/version.d.ts +1 -1
  66. package/package.json +5 -5
  67. package/src/client/actions/grantPermissions.ts +33 -4
  68. package/src/client/actions/listAccounts.ts +38 -8
  69. package/src/client/actions/requestAccount.ts +59 -12
  70. package/src/client/actions/sendCalls.ts +9 -3
  71. package/src/client/actions/signMessage.ts +3 -3
  72. package/src/client/actions/signPreparedCalls.ts +10 -4
  73. package/src/client/actions/signSignatureRequest.ts +75 -8
  74. package/src/client/actions/signTypedData.ts +3 -3
  75. package/src/client/decorator.ts +21 -3
  76. package/src/client/index.ts +11 -2
  77. package/src/internal/account.ts +38 -5
  78. package/src/utils.ts +25 -1
  79. package/src/version.ts +1 -1
@@ -1,42 +1,13 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import { type Hex } from "viem";
3
- import type { PersonalSignSignatureRequest, TypedDataSignatureRequest, AuthorizationSignatureRequest, Eip7702UnsignedAuth } from "@alchemy/wallet-api-types";
2
+ import type { PersonalSignSignatureRequest, TypedDataSignatureRequest, AuthorizationSignatureRequest, Eip7702UnsignedAuth, UserOpSig, EcdsaSig, WebauthnSig } from "@alchemy/wallet-api-types";
4
3
  import type { WithoutRawPayload } from "../../types.ts";
4
+ import type { WebAuthnSigner } from "../index.js";
5
5
  export type SignSignatureRequestParams = WithoutRawPayload<PersonalSignSignatureRequest | TypedDataSignatureRequest | (AuthorizationSignatureRequest & {
6
6
  data: Eip7702UnsignedAuth;
7
7
  })>;
8
- export type SignSignatureRequestResult = {
9
- type: "secp256k1";
10
- data: Hex;
11
- };
12
- /**
13
- * Signs a signature request using the provided signer.
14
- * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
15
- *
16
- * @param {SmartAccountSigner} signer - The signer to use for signing the request
17
- * @param {SignSignatureRequestParams} params - The signature request parameters
18
- * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
19
- * @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type
20
- * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
21
- *
22
- * @example
23
- * ```ts
24
- * // Sign a personal message
25
- * const result = await client.signSignatureRequest({
26
- * type: 'personal_sign',
27
- * data: 'Hello, world!'
28
- * });
29
- *
30
- * // Sign typed data (EIP-712)
31
- * const result = await client.signSignatureRequest({
32
- * type: 'eth_signTypedData_v4',
33
- * data: {
34
- * domain: { ... },
35
- * types: { ... },
36
- * primaryType: '...',
37
- * message: { ... }
38
- * }
39
- * });
40
- * ```
41
- */
42
- export declare function signSignatureRequest(signer: SmartAccountSigner, params: SignSignatureRequestParams): Promise<SignSignatureRequestResult>;
8
+ export type SignSignatureRequestResult = UserOpSig["signature"];
9
+ export declare function signSignatureRequest(signer: SmartAccountSigner, params: WithoutRawPayload<PersonalSignSignatureRequest | TypedDataSignatureRequest | (AuthorizationSignatureRequest & {
10
+ data: Eip7702UnsignedAuth;
11
+ })>): Promise<EcdsaSig["signature"]>;
12
+ export declare function signSignatureRequest(signer: WebAuthnSigner, params: WithoutRawPayload<PersonalSignSignatureRequest | TypedDataSignatureRequest>): Promise<WebauthnSig["signature"]>;
13
+ export declare function signSignatureRequest(signer: SmartAccountSigner | WebAuthnSigner, params: WithoutRawPayload<PersonalSignSignatureRequest | TypedDataSignatureRequest>): Promise<UserOpSig["signature"]>;
@@ -1,12 +1,13 @@
1
1
  import { hexToNumber, serializeSignature } from "viem";
2
- import { assertNever } from "../../utils.js";
2
+ import { assertNever, isWebAuthnSigner } from "../../utils.js";
3
3
  import { vToYParity } from "ox/Signature";
4
4
  import { metrics } from "../../metrics.js";
5
+ import { toWebAuthnAccount } from "viem/account-abstraction";
5
6
  /**
6
7
  * Signs a signature request using the provided signer.
7
8
  * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
8
9
  *
9
- * @param {SmartAccountSigner} signer - The signer to use for signing the request
10
+ * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer to use for signing the request
10
11
  * @param {SignSignatureRequestParams} params - The signature request parameters
11
12
  * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
12
13
  * @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type
@@ -41,18 +42,45 @@ export async function signSignatureRequest(signer, params) {
41
42
  });
42
43
  switch (params.type) {
43
44
  case "personal_sign": {
45
+ if (isWebAuthnSigner(signer)) {
46
+ const webAuthnAccount = toWebAuthnAccount({ ...signer });
47
+ const { signature, webauthn: metadata } = await webAuthnAccount.signMessage({
48
+ message: params.data,
49
+ });
50
+ return {
51
+ type: "webauthn-p256",
52
+ data: {
53
+ signature,
54
+ metadata,
55
+ },
56
+ };
57
+ }
44
58
  return {
45
59
  type: "secp256k1",
46
60
  data: await signer.signMessage(params.data),
47
61
  };
48
62
  }
49
63
  case "eth_signTypedData_v4": {
64
+ if (isWebAuthnSigner(signer)) {
65
+ const webAuthnAccount = toWebAuthnAccount({ ...signer });
66
+ const { signature, webauthn: metadata } = await webAuthnAccount.signTypedData(params.data);
67
+ return {
68
+ type: "webauthn-p256",
69
+ data: {
70
+ signature,
71
+ metadata,
72
+ },
73
+ };
74
+ }
50
75
  return {
51
76
  type: "secp256k1",
52
77
  data: await signer.signTypedData(params.data),
53
78
  };
54
79
  }
55
80
  case "eip7702Auth": {
81
+ if (isWebAuthnSigner(signer)) {
82
+ throw new Error("WebAuthn account cannot sign EIP-7702 authorization requests");
83
+ }
56
84
  if (!signer.signAuthorization) {
57
85
  throw new Error("Signer does not implement signAuthorization");
58
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAe3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO;iBACR,CAAC;aACH,CAAC;QACJ,CAAC;QACD;YACE,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { type Hex, hexToNumber, serializeSignature } from \"viem\";\nimport { assertNever } from \"../../utils.js\";\nimport type {\n PersonalSignSignatureRequest,\n TypedDataSignatureRequest,\n AuthorizationSignatureRequest,\n Eip7702UnsignedAuth,\n} from \"@alchemy/wallet-api-types\";\nimport { vToYParity } from \"ox/Signature\";\nimport type { WithoutRawPayload } from \"../../types.ts\";\nimport { metrics } from \"../../metrics.js\";\n\nexport type SignSignatureRequestParams = WithoutRawPayload<\n | PersonalSignSignatureRequest\n | TypedDataSignatureRequest\n | (AuthorizationSignatureRequest & {\n data: Eip7702UnsignedAuth;\n })\n>;\n\nexport type SignSignatureRequestResult = {\n type: \"secp256k1\";\n data: Hex;\n};\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {SignSignatureRequestParams[\"data\"]} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n *\n * @example\n * ```ts\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n * ```\n */\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n metrics.trackEvent({\n name: \"sign_signature_request\",\n data: {\n type: params.type,\n },\n });\n\n switch (params.type) {\n case \"personal_sign\": {\n return {\n type: \"secp256k1\",\n data: await signer.signMessage(params.data),\n };\n }\n case \"eth_signTypedData_v4\": {\n return {\n type: \"secp256k1\",\n data: await signer.signTypedData(params.data),\n };\n }\n case \"eip7702Auth\": {\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n const {\n r,\n s,\n v,\n yParity: _yParity,\n } = await signer.signAuthorization({\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n const yParity =\n _yParity != null ? Number(_yParity) : vToYParity(Number(v));\n\n return {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity,\n }),\n };\n }\n default:\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
1
+ {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAU/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAwC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAyB,EACzB,MAAkC;IAElC,OAAO,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,wBAAwB;QAC9B,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IAEH,QAAQ,MAAM,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AAK,CACb,8DAA8D,CAC/D,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,EACJ,CAAC,EACD,CAAC,EACD,CAAC,EACD,OAAO,EAAE,QAAQ,GAClB,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;gBACjC,GAAG,MAAM,CAAC,IAAI;gBACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBACzC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtC,CAAC,CAAC;YACH,MAAM,OAAO,GACX,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAE9D,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO;iBACR,CAAC;aACH,CAAC;QACJ,CAAC;QACD;YACE,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { hexToNumber, serializeSignature } from \"viem\";\nimport { assertNever, isWebAuthnSigner } from \"../../utils.js\";\nimport type {\n PersonalSignSignatureRequest,\n TypedDataSignatureRequest,\n AuthorizationSignatureRequest,\n Eip7702UnsignedAuth,\n UserOpSig,\n EcdsaSig,\n WebauthnSig,\n} from \"@alchemy/wallet-api-types\";\nimport { vToYParity } from \"ox/Signature\";\nimport type { WithoutRawPayload } from \"../../types.ts\";\nimport { metrics } from \"../../metrics.js\";\nimport type { SmartWalletSigner, WebAuthnSigner } from \"../index.js\";\nimport { toWebAuthnAccount } from \"viem/account-abstraction\";\n\nexport type SignSignatureRequestParams = WithoutRawPayload<\n | PersonalSignSignatureRequest\n | TypedDataSignatureRequest\n | (AuthorizationSignatureRequest & {\n data: Eip7702UnsignedAuth;\n })\n>;\n\nexport type SignSignatureRequestResult = UserOpSig[\"signature\"];\n\n// Overload: Always an ECDSA signer, can sign any type of request\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: WithoutRawPayload<\n | PersonalSignSignatureRequest\n | TypedDataSignatureRequest\n | (AuthorizationSignatureRequest & {\n data: Eip7702UnsignedAuth;\n })\n >,\n): Promise<EcdsaSig[\"signature\"]>;\n\n// Overload: WebAuthn signer, can only sign personal_sign and eth_signTypedData_v4\nexport async function signSignatureRequest(\n signer: WebAuthnSigner,\n params: WithoutRawPayload<\n PersonalSignSignatureRequest | TypedDataSignatureRequest\n >,\n): Promise<WebauthnSig[\"signature\"]>;\n\n// Overload: Union type of signer, can only sign personal_sign and eth_signTypedData_v4\nexport async function signSignatureRequest(\n signer: SmartAccountSigner | WebAuthnSigner,\n params: WithoutRawPayload<\n PersonalSignSignatureRequest | TypedDataSignatureRequest\n >,\n): Promise<UserOpSig[\"signature\"]>;\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {SignSignatureRequestParams[\"data\"]} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n *\n * @example\n * ```ts\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n * ```\n */\n\nexport async function signSignatureRequest(\n signer: SmartWalletSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n metrics.trackEvent({\n name: \"sign_signature_request\",\n data: {\n type: params.type,\n },\n });\n\n switch (params.type) {\n case \"personal_sign\": {\n if (isWebAuthnSigner(signer)) {\n const webAuthnAccount = toWebAuthnAccount({ ...signer });\n\n const { signature, webauthn: metadata } =\n await webAuthnAccount.signMessage({\n message: params.data,\n });\n\n return {\n type: \"webauthn-p256\",\n data: {\n signature,\n metadata,\n },\n };\n }\n\n return {\n type: \"secp256k1\",\n data: await signer.signMessage(params.data),\n };\n }\n case \"eth_signTypedData_v4\": {\n if (isWebAuthnSigner(signer)) {\n const webAuthnAccount = toWebAuthnAccount({ ...signer });\n\n const { signature, webauthn: metadata } =\n await webAuthnAccount.signTypedData(params.data);\n\n return {\n type: \"webauthn-p256\",\n data: {\n signature,\n metadata,\n },\n };\n }\n return {\n type: \"secp256k1\",\n data: await signer.signTypedData(params.data),\n };\n }\n case \"eip7702Auth\": {\n if (isWebAuthnSigner(signer)) {\n throw new Error(\n \"WebAuthn account cannot sign EIP-7702 authorization requests\",\n );\n }\n\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n const {\n r,\n s,\n v,\n yParity: _yParity,\n } = await signer.signAuthorization({\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n const yParity =\n _yParity != null ? Number(_yParity) : vToYParity(Number(v));\n\n return {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity,\n }),\n };\n }\n default:\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { SmartAccountSigner } from "@aa-sdk/core";
2
1
  import { type Address, type Hex, type TypedDataDefinition } from "viem";
3
2
  import type { InnerWalletApiClient } from "../../types.ts";
3
+ import type { SmartWalletSigner } from "../index.js";
4
4
  export type SignTypedDataParams = TypedDataDefinition & {
5
5
  account?: Address;
6
6
  };
@@ -10,7 +10,7 @@ export type SignTypedDataResult = Hex;
10
10
  * This method requests the account associated with the signer and uses it to sign the typed data.
11
11
  *
12
12
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
13
- * @param {SmartAccountSigner} signer - The signer of the smart account
13
+ * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account
14
14
  * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
15
15
  * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
16
16
  *
@@ -38,4 +38,4 @@ export type SignTypedDataResult = Hex;
38
38
  * });
39
39
  * ```
40
40
  */
41
- export declare function signTypedData(client: InnerWalletApiClient, signer: SmartAccountSigner, params: SignTypedDataParams): Promise<SignTypedDataResult>;
41
+ export declare function signTypedData(client: InnerWalletApiClient, signer: SmartWalletSigner, params: SignTypedDataParams): Promise<SignTypedDataResult>;
@@ -6,7 +6,7 @@ import { metrics } from "../../metrics.js";
6
6
  * This method requests the account associated with the signer and uses it to sign the typed data.
7
7
  *
8
8
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
9
- * @param {SmartAccountSigner} signer - The signer of the smart account
9
+ * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account
10
10
  * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
11
11
  * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
12
12
  *
@@ -1 +1 @@
1
- {"version":3,"file":"signTypedData.js","sourceRoot":"","sources":["../../../../src/client/actions/signTypedData.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,MAAM,MAAM,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAQ3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA4B,EAC5B,MAA0B,EAC1B,MAA2B;IAE3B,OAAO,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,iBAAiB;KACxB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE;QACnD,cAAc,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO;KAC1D,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { type Address, type Hex, type TypedDataDefinition } from \"viem\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\nimport { requestAccount } from \"./requestAccount.js\";\nimport { metrics } from \"../../metrics.js\";\n\nexport type SignTypedDataParams = TypedDataDefinition & {\n account?: Address;\n};\n\nexport type SignTypedDataResult = Hex;\n\n/**\n * Signs typed data (EIP-712) using the smart account.\n * This method requests the account associated with the signer and uses it to sign the typed data.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner} signer - The signer of the smart account\n * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format\n * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string\n *\n * @example\n * ```ts\n * // Sign typed data\n * const signature = await client.signTypedData({\n * domain: {\n * name: 'Example DApp',\n * version: '1',\n * chainId: 1,\n * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'\n * },\n * types: {\n * Person: [\n * { name: 'name', type: 'string' },\n * { name: 'wallet', type: 'address' }\n * ]\n * },\n * primaryType: 'Person',\n * message: {\n * name: 'John Doe',\n * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'\n * }\n * });\n * ```\n */\nexport async function signTypedData(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n params: SignTypedDataParams,\n): Promise<SignTypedDataResult> {\n metrics.trackEvent({\n name: \"sign_typed_data\",\n });\n\n const account = await requestAccount(client, signer, {\n accountAddress: params.account ?? client.account?.address,\n });\n\n return account.signTypedDataWith6492(params);\n}\n"]}
1
+ {"version":3,"file":"signTypedData.js","sourceRoot":"","sources":["../../../../src/client/actions/signTypedData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,MAAM,MAAM,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAS3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA4B,EAC5B,MAAyB,EACzB,MAA2B;IAE3B,OAAO,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,iBAAiB;KACxB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE;QACnD,cAAc,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO;KAC1D,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { type Address, type Hex, type TypedDataDefinition } from \"viem\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\nimport { requestAccount } from \"./requestAccount.js\";\nimport { metrics } from \"../../metrics.js\";\nimport type { SmartWalletSigner } from \"../index.js\";\n\nexport type SignTypedDataParams = TypedDataDefinition & {\n account?: Address;\n};\n\nexport type SignTypedDataResult = Hex;\n\n/**\n * Signs typed data (EIP-712) using the smart account.\n * This method requests the account associated with the signer and uses it to sign the typed data.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account\n * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format\n * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string\n *\n * @example\n * ```ts\n * // Sign typed data\n * const signature = await client.signTypedData({\n * domain: {\n * name: 'Example DApp',\n * version: '1',\n * chainId: 1,\n * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'\n * },\n * types: {\n * Person: [\n * { name: 'name', type: 'string' },\n * { name: 'wallet', type: 'address' }\n * ]\n * },\n * primaryType: 'Person',\n * message: {\n * name: 'John Doe',\n * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'\n * }\n * });\n * ```\n */\nexport async function signTypedData(\n client: InnerWalletApiClient,\n signer: SmartWalletSigner,\n params: SignTypedDataParams,\n): Promise<SignTypedDataResult> {\n metrics.trackEvent({\n name: \"sign_typed_data\",\n });\n\n const account = await requestAccount(client, signer, {\n accountAddress: params.account ?? client.account?.address,\n });\n\n return account.signTypedDataWith6492(params);\n}\n"]}
@@ -15,7 +15,6 @@ import type { InnerWalletApiClient } from "../../types.js";
15
15
  */
16
16
  export declare function waitForCallsStatus(client: InnerWalletApiClient, params: WaitForCallsStatusParameters): Promise<{
17
17
  version: string;
18
- id: string;
19
18
  chainId: number;
20
19
  capabilities?: {
21
20
  [key: string]: any;
@@ -23,6 +22,7 @@ export declare function waitForCallsStatus(client: InnerWalletApiClient, params:
23
22
  [x: string]: any;
24
23
  } | undefined;
25
24
  atomic: boolean;
25
+ id: string;
26
26
  receipts?: import("viem").WalletCallReceipt<bigint, "success" | "reverted">[] | undefined;
27
27
  statusCode: number;
28
28
  status: "pending" | "success" | "failure" | undefined;
@@ -1,4 +1,3 @@
1
- import type { SmartAccountSigner } from "@aa-sdk/core";
2
1
  import type { Address, Hex } from "viem";
3
2
  import { type WaitForCallsStatusParameters, type WaitForCallsStatusReturnType } from "viem/actions";
4
3
  import type { InnerWalletApiClient } from "../types.ts";
@@ -13,6 +12,7 @@ import { type SignSignatureRequestParams, type SignSignatureRequestResult } from
13
12
  import { type SignTypedDataParams } from "./actions/signTypedData.js";
14
13
  import { type SignPreparedCallsParams, type SignPreparedCallsResult } from "./actions/signPreparedCalls.js";
15
14
  import { type SendCallsParams, type SendCallsResult } from "./actions/sendCalls.js";
15
+ import type { SmartWalletSigner } from "./index.js";
16
16
  export type SmartWalletActions<TAccount extends Address | undefined = Address | undefined> = {
17
17
  requestAccount: (params?: RequestAccountParams) => Promise<RequestAccountResult>;
18
18
  prepareCalls: (params: PrepareCallsParams<TAccount>) => Promise<PrepareCallsResult>;
@@ -27,4 +27,4 @@ export type SmartWalletActions<TAccount extends Address | undefined = Address |
27
27
  signTypedData: (params: SignTypedDataParams) => Promise<Hex>;
28
28
  grantPermissions: (params: GrantPermissionsParams<TAccount>) => Promise<GrantPermissionsResult>;
29
29
  };
30
- export declare function smartWalletClientActions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, signer: SmartAccountSigner): SmartWalletActions<TAccount>;
30
+ export declare function smartWalletClientActions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, signer: SmartWalletSigner): SmartWalletActions<TAccount>;
@@ -11,6 +11,18 @@ import { signSignatureRequest, } from "./actions/signSignatureRequest.js";
11
11
  import { signTypedData, } from "./actions/signTypedData.js";
12
12
  import { signPreparedCalls, } from "./actions/signPreparedCalls.js";
13
13
  import { sendCalls, } from "./actions/sendCalls.js";
14
+ import { isWebAuthnSigner } from "../utils.js";
15
+ async function signSignatureRequestSafe(signer, params) {
16
+ if (params.type === "eip7702Auth") {
17
+ if (isWebAuthnSigner(signer)) {
18
+ throw new Error("WebAuthn signer cannot sign EIP-7702 authorization requests");
19
+ }
20
+ // We must split up the call to signSignatureRequest across two conditionals for the TS compiler to
21
+ // correctly infer which overload to use.
22
+ return signSignatureRequest(signer, params);
23
+ }
24
+ return signSignatureRequest(signer, params);
25
+ }
14
26
  export function smartWalletClientActions(client, signer) {
15
27
  return {
16
28
  requestAccount: (params) => requestAccount(client, signer, params),
@@ -20,7 +32,7 @@ export function smartWalletClientActions(client, signer) {
20
32
  sendCalls: (params) => sendCalls(client, signer, params),
21
33
  getCallsStatus: (params) => getCallsStatus(client, params),
22
34
  waitForCallsStatus: (params) => waitForCallsStatus(client, params),
23
- signSignatureRequest: (params) => signSignatureRequest(signer, params),
35
+ signSignatureRequest: (params) => signSignatureRequestSafe(signer, params),
24
36
  signPreparedCalls: (params) => signPreparedCalls(signer, params),
25
37
  signMessage: (params) => signMessage(client, signer, params),
26
38
  signTypedData: (params) => signTypedData(client, signer, params),
@@ -1 +1 @@
1
- {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/client/decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,GAGf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,gBAAgB,GAGjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,YAAY,GAGb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,YAAY,GAGb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,GAGf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,iBAAiB,GAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EACL,oBAAoB,GAGrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,aAAa,GAEd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,GAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,SAAS,GAGV,MAAM,wBAAwB,CAAC;AAmChC,MAAM,UAAU,wBAAwB,CAGtC,MAA4B,EAC5B,MAA0B;IAE1B,OAAO;QACL,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAClE,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;QACtD,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAC9D,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChE,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QACxD,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;QAC1D,kBAAkB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;QAClE,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC;QACtE,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChE,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAC5D,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAChE,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;KACvE,CAAC;AACJ,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Address, Hex } from \"viem\";\nimport {\n type WaitForCallsStatusParameters,\n type WaitForCallsStatusReturnType,\n} from \"viem/actions\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport {\n getCallsStatus,\n type GetCallsStatusParams,\n type GetCallsStatusResult,\n} from \"./actions/getCallsStatus.js\";\nimport {\n grantPermissions,\n type GrantPermissionsParams,\n type GrantPermissionsResult,\n} from \"./actions/grantPermissions.js\";\nimport {\n listAccounts,\n type ListAccountsParams,\n type ListAccountsResult,\n} from \"./actions/listAccounts.js\";\nimport {\n prepareCalls,\n type PrepareCallsParams,\n type PrepareCallsResult,\n} from \"./actions/prepareCalls.js\";\nimport {\n requestAccount,\n type RequestAccountParams,\n type RequestAccountResult,\n} from \"./actions/requestAccount.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsParams,\n type SendPreparedCallsResult,\n} from \"./actions/sendPreparedCalls.js\";\nimport { waitForCallsStatus } from \"./actions/waitForCallsStatus.js\";\nimport { signMessage, type SignMessageParams } from \"./actions/signMessage.js\";\nimport {\n signSignatureRequest,\n type SignSignatureRequestParams,\n type SignSignatureRequestResult,\n} from \"./actions/signSignatureRequest.js\";\nimport {\n signTypedData,\n type SignTypedDataParams,\n} from \"./actions/signTypedData.js\";\nimport {\n signPreparedCalls,\n type SignPreparedCallsParams,\n type SignPreparedCallsResult,\n} from \"./actions/signPreparedCalls.js\";\nimport {\n sendCalls,\n type SendCallsParams,\n type SendCallsResult,\n} from \"./actions/sendCalls.js\";\n\nexport type SmartWalletActions<\n TAccount extends Address | undefined = Address | undefined,\n> = {\n requestAccount: (\n params?: RequestAccountParams,\n ) => Promise<RequestAccountResult>;\n prepareCalls: (\n params: PrepareCallsParams<TAccount>,\n ) => Promise<PrepareCallsResult>;\n sendPreparedCalls: (\n params: SendPreparedCallsParams,\n ) => Promise<SendPreparedCallsResult>;\n sendCalls: (params: SendCallsParams<TAccount>) => Promise<SendCallsResult>;\n listAccounts: (params: ListAccountsParams) => Promise<ListAccountsResult>;\n getCallsStatus: (\n params: GetCallsStatusParams,\n ) => Promise<GetCallsStatusResult>;\n waitForCallsStatus: (\n params: WaitForCallsStatusParameters,\n ) => Promise<WaitForCallsStatusReturnType>;\n signSignatureRequest: (\n params: SignSignatureRequestParams,\n ) => Promise<SignSignatureRequestResult>;\n signPreparedCalls: (\n params: SignPreparedCallsParams,\n ) => Promise<SignPreparedCallsResult>;\n signMessage: (params: SignMessageParams) => Promise<Hex>;\n signTypedData: (params: SignTypedDataParams) => Promise<Hex>;\n grantPermissions: (\n params: GrantPermissionsParams<TAccount>,\n ) => Promise<GrantPermissionsResult>;\n};\n\nexport function smartWalletClientActions<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n signer: SmartAccountSigner,\n): SmartWalletActions<TAccount> {\n return {\n requestAccount: (params) => requestAccount(client, signer, params),\n prepareCalls: (params) => prepareCalls(client, params),\n listAccounts: (params) => listAccounts(client, signer, params),\n sendPreparedCalls: (params) => sendPreparedCalls(client, params),\n sendCalls: (params) => sendCalls(client, signer, params),\n getCallsStatus: (params) => getCallsStatus(client, params),\n waitForCallsStatus: (params) => waitForCallsStatus(client, params),\n signSignatureRequest: (params) => signSignatureRequest(signer, params),\n signPreparedCalls: (params) => signPreparedCalls(signer, params),\n signMessage: (params) => signMessage(client, signer, params),\n signTypedData: (params) => signTypedData(client, signer, params),\n grantPermissions: (params) => grantPermissions(client, signer, params),\n };\n}\n"]}
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/client/decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,GAGf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,gBAAgB,GAGjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,YAAY,GAGb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,YAAY,GAGb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,GAGf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,iBAAiB,GAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,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AAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;QAC1D,kBAAkB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;QAClE,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC;QAC1E,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChE,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAC5D,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAChE,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;KACvE,CAAC;AACJ,CAAC","sourcesContent":["import type { Address, Hex } from \"viem\";\nimport {\n type WaitForCallsStatusParameters,\n type WaitForCallsStatusReturnType,\n} from \"viem/actions\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport {\n getCallsStatus,\n type GetCallsStatusParams,\n type GetCallsStatusResult,\n} from \"./actions/getCallsStatus.js\";\nimport {\n grantPermissions,\n type GrantPermissionsParams,\n type GrantPermissionsResult,\n} from \"./actions/grantPermissions.js\";\nimport {\n listAccounts,\n type ListAccountsParams,\n type ListAccountsResult,\n} from \"./actions/listAccounts.js\";\nimport {\n prepareCalls,\n type PrepareCallsParams,\n type PrepareCallsResult,\n} from \"./actions/prepareCalls.js\";\nimport {\n requestAccount,\n type RequestAccountParams,\n type RequestAccountResult,\n} from \"./actions/requestAccount.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsParams,\n type SendPreparedCallsResult,\n} from \"./actions/sendPreparedCalls.js\";\nimport { waitForCallsStatus } from \"./actions/waitForCallsStatus.js\";\nimport { signMessage, type SignMessageParams } from \"./actions/signMessage.js\";\nimport {\n signSignatureRequest,\n type SignSignatureRequestParams,\n type SignSignatureRequestResult,\n} from \"./actions/signSignatureRequest.js\";\nimport {\n signTypedData,\n type SignTypedDataParams,\n} from \"./actions/signTypedData.js\";\nimport {\n signPreparedCalls,\n type SignPreparedCallsParams,\n type SignPreparedCallsResult,\n} from \"./actions/signPreparedCalls.js\";\nimport {\n sendCalls,\n type SendCallsParams,\n type SendCallsResult,\n} from \"./actions/sendCalls.js\";\nimport type { SmartWalletSigner } from \"./index.js\";\nimport { isWebAuthnSigner } from \"../utils.js\";\n\nasync function signSignatureRequestSafe(\n signer: SmartWalletSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n if (params.type === \"eip7702Auth\") {\n if (isWebAuthnSigner(signer)) {\n throw new Error(\n \"WebAuthn signer cannot sign EIP-7702 authorization requests\",\n );\n }\n // We must split up the call to signSignatureRequest across two conditionals for the TS compiler to\n // correctly infer which overload to use.\n return signSignatureRequest(signer, params);\n }\n return signSignatureRequest(signer, params);\n}\n\nexport type SmartWalletActions<\n TAccount extends Address | undefined = Address | undefined,\n> = {\n requestAccount: (\n params?: RequestAccountParams,\n ) => Promise<RequestAccountResult>;\n prepareCalls: (\n params: PrepareCallsParams<TAccount>,\n ) => Promise<PrepareCallsResult>;\n sendPreparedCalls: (\n params: SendPreparedCallsParams,\n ) => Promise<SendPreparedCallsResult>;\n sendCalls: (params: SendCallsParams<TAccount>) => Promise<SendCallsResult>;\n listAccounts: (params: ListAccountsParams) => Promise<ListAccountsResult>;\n getCallsStatus: (\n params: GetCallsStatusParams,\n ) => Promise<GetCallsStatusResult>;\n waitForCallsStatus: (\n params: WaitForCallsStatusParameters,\n ) => Promise<WaitForCallsStatusReturnType>;\n signSignatureRequest: (\n params: SignSignatureRequestParams,\n ) => Promise<SignSignatureRequestResult>;\n signPreparedCalls: (\n params: SignPreparedCallsParams,\n ) => Promise<SignPreparedCallsResult>;\n signMessage: (params: SignMessageParams) => Promise<Hex>;\n signTypedData: (params: SignTypedDataParams) => Promise<Hex>;\n grantPermissions: (\n params: GrantPermissionsParams<TAccount>,\n ) => Promise<GrantPermissionsResult>;\n};\n\nexport function smartWalletClientActions<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n signer: SmartWalletSigner,\n): SmartWalletActions<TAccount> {\n return {\n requestAccount: (params) => requestAccount(client, signer, params),\n prepareCalls: (params) => prepareCalls(client, params),\n listAccounts: (params) => listAccounts(client, signer, params),\n sendPreparedCalls: (params) => sendPreparedCalls(client, params),\n sendCalls: (params) => sendCalls(client, signer, params),\n getCallsStatus: (params) => getCallsStatus(client, params),\n waitForCallsStatus: (params) => waitForCallsStatus(client, params),\n signSignatureRequest: (params) => signSignatureRequestSafe(signer, params),\n signPreparedCalls: (params) => signPreparedCalls(signer, params),\n signMessage: (params) => signMessage(client, signer, params),\n signTypedData: (params) => signTypedData(client, signer, params),\n grantPermissions: (params) => grantPermissions(client, signer, params),\n };\n}\n"]}
@@ -3,10 +3,17 @@ import type { AlchemyTransport } from "@account-kit/infra";
3
3
  import { type Address, type Chain, type Prettify } from "viem";
4
4
  import type { InnerWalletApiClientBase } from "../types.ts";
5
5
  import { type SmartWalletActions } from "./decorator.js";
6
+ import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
7
+ export type WebAuthnSigner = {
8
+ credential: ToWebAuthnAccountParameters["credential"];
9
+ getFn?: ToWebAuthnAccountParameters["getFn"] | undefined;
10
+ rpId?: ToWebAuthnAccountParameters["rpId"] | undefined;
11
+ };
12
+ export type SmartWalletSigner = SmartAccountSigner<any> | WebAuthnSigner;
6
13
  export type SmartWalletClientParams<TAccount extends Address | undefined = Address | undefined> = Prettify<{
7
14
  transport: AlchemyTransport;
8
15
  chain: Chain;
9
- signer: SmartAccountSigner;
16
+ signer: SmartWalletSigner;
10
17
  account?: TAccount | Address | undefined;
11
18
  } & ({
12
19
  policyId?: string;
@@ -22,7 +29,7 @@ export type SmartWalletClient<TAccount extends Address | undefined = Address | u
22
29
  * @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client
23
30
  * @param {AlchemyTransport} params.transport - The Alchemy transport to use
24
31
  * @param {Chain} params.chain - The chain to use
25
- * @param {SmartAccountSigner} params.signer - The signer to use for the smart account
32
+ * @param {SmartAccountSigner | WebAuthnSigner} params.signer - The signer to use for the smart account
26
33
  * @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
27
34
  * @param {Address} [params.account] - The smart account address to use (optional)
28
35
  * @returns {SmartWalletClient} - A viem-compatible client
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,YAAY,EACZ,MAAM,GAEP,MAAM,MAAM,CAAC;AAEd,OAAO,EACL,wBAAwB,GAEzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAKzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAqDxC,MAAM,UAAU,uBAAuB,CACrC,MAA+B;IAE/B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAErD,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ;QAC/B,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,SAAS;YAChB,CAAC,CAAC,MAAM,CAAC,SAAS;YAClB,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,WAAW,GAAG,YAAY,CAK9B;QACA,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,MAAM,CACJ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC7B,MAAM,EAAE,SAAS,CAAC,IAAI,EAA6B;SACpD,CAAC,CACH,CAAC,IAAI,CAAC;QACT,KAAK;QACL,OAAO;KACR,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACf,SAAS;QACT,QAAQ,EAAE,sBAAsB,EAAE;KACnC,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;SACzB;KACF,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CACnC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CACzC,CAAC;AACJ,CAAC;AAED,iBAAiB;AACjB,yDAAyD;AACzD,2CAA2C;AAC3C,wBAAwB;AACxB,4CAA4C;AAC5C,MAAM;AAEN,gEAAgE;AAEhE,sDAAsD;AACtD,2CAA2C;AAC3C,wBAAwB;AACxB,4CAA4C;AAC5C,0BAA0B;AAC1B,MAAM;AAEN,6DAA6D","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { AlchemyTransport } from \"@account-kit/infra\";\nimport {\n type Address,\n type Chain,\n type Prettify,\n type Transport,\n createClient,\n custom,\n type JsonRpcAccount,\n} from \"viem\";\nimport type { InnerWalletApiClientBase } from \"../types.ts\";\nimport {\n smartWalletClientActions,\n type SmartWalletActions,\n} from \"./decorator.js\";\nimport { Provider, RpcSchema } from \"ox\";\nimport type {\n WalletServerRpcSchemaType,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport { metrics } from \"../metrics.js\";\n\nexport type SmartWalletClientParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n {\n transport: AlchemyTransport;\n chain: Chain;\n signer: SmartAccountSigner;\n account?: TAccount | Address | undefined;\n } & (\n | { policyId?: string; policyIds?: never }\n | { policyIds?: string[]; policyId?: never }\n )\n>;\n\nexport type SmartWalletClient<\n TAccount extends Address | undefined = Address | undefined,\n> = InnerWalletApiClientBase<SmartWalletActions<TAccount>>;\n\n/**\n * Creates a smart wallet client that can be used to interact with a smart account.\n *\n * @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client\n * @param {AlchemyTransport} params.transport - The Alchemy transport to use\n * @param {Chain} params.chain - The chain to use\n * @param {SmartAccountSigner} params.signer - The signer to use for the smart account\n * @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)\n * @param {Address} [params.account] - The smart account address to use (optional)\n * @returns {SmartWalletClient} - A viem-compatible client\n *\n * @example\n * ```ts\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { alchemy, arbitrumSepolia } from \"@account-kit/infra\";\n * import { generatePrivateKey } from \"viem/accounts\";\n * import { createSmartWalletClient } from \"@account-kit/wallet-client\";\n *\n * const signer = LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey());\n * const transport = alchemy({\n * apiKey: \"your-alchemy-api-key\",\n * });\n * const client = createSmartWalletClient({\n * transport,\n * chain: arbitrumSepolia,\n * signer,\n * });\n * ```\n */\nexport function createSmartWalletClient<\n TAccount extends Address | undefined = undefined,\n>(params: SmartWalletClientParams<TAccount>): SmartWalletClient<TAccount>;\n\nexport function createSmartWalletClient(\n params: SmartWalletClientParams,\n): SmartWalletClient {\n const { transport, chain, account, signer } = params;\n\n const policyIds = params.policyId\n ? [params.policyId]\n : params.policyIds\n ? params.policyIds\n : undefined;\n\n const innerClient = createClient<\n Transport,\n Chain,\n JsonRpcAccount<Address> | undefined,\n WalletServerViemRpcSchema\n >({\n transport: (opts) =>\n custom(\n Provider.from(transport(opts), {\n schema: RpcSchema.from<WalletServerRpcSchemaType>(),\n }),\n )(opts),\n chain,\n account,\n }).extend(() => ({\n policyIds,\n internal: internalStateDecorator(),\n }));\n\n metrics.trackEvent({\n name: \"client_created\",\n data: {\n chainId: params.chain.id,\n },\n });\n\n return innerClient.extend((client) =>\n smartWalletClientActions(client, signer),\n );\n}\n\n// Example usage:\n// const clientWithoutAccount = createSmartWalletClient({\n// transport: alchemy({ apiKey: \"123\" }),\n// chain: baseSepolia,\n// signer: createDummySigner(zeroAddress),\n// });\n\n// const account1 = await clientWithoutAccount.requestAccount();\n\n// const clientWithAccount = createSmartWalletClient({\n// transport: alchemy({ apiKey: \"123\" }),\n// chain: baseSepolia,\n// signer: createDummySigner(zeroAddress),\n// account: zeroAddress,\n// });\n\n// const account2 = await clientWithAccount.requestAccount();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,YAAY,EACZ,MAAM,GAEP,MAAM,MAAM,CAAC;AAEd,OAAO,EACL,wBAAwB,GAEzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAKzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA8DxC,MAAM,UAAU,uBAAuB,CACrC,MAA+B;IAE/B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAErD,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ;QAC/B,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,SAAS;YAChB,CAAC,CAAC,MAAM,CAAC,SAAS;YAClB,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,WAAW,GAAG,YAAY,CAK9B;QACA,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,MAAM,CACJ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC7B,MAAM,EAAE,SAAS,CAAC,IAAI,EAA6B;SACpD,CAAC,CACH,CAAC,IAAI,CAAC;QACT,KAAK;QACL,OAAO;KACR,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACf,SAAS;QACT,QAAQ,EAAE,sBAAsB,EAAE;KACnC,CAAC,CAAC,CAAC;IAEJ,OAAO,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;SACzB;KACF,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CACnC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CACzC,CAAC;AACJ,CAAC;AAED,iBAAiB;AACjB,yDAAyD;AACzD,2CAA2C;AAC3C,wBAAwB;AACxB,4CAA4C;AAC5C,MAAM;AAEN,gEAAgE;AAEhE,sDAAsD;AACtD,2CAA2C;AAC3C,wBAAwB;AACxB,4CAA4C;AAC5C,0BAA0B;AAC1B,MAAM;AAEN,6DAA6D","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { AlchemyTransport } from \"@account-kit/infra\";\nimport {\n type Address,\n type Chain,\n type Prettify,\n type Transport,\n createClient,\n custom,\n type JsonRpcAccount,\n} from \"viem\";\nimport type { InnerWalletApiClientBase } from \"../types.ts\";\nimport {\n smartWalletClientActions,\n type SmartWalletActions,\n} from \"./decorator.js\";\nimport { Provider, RpcSchema } from \"ox\";\nimport type {\n WalletServerRpcSchemaType,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport { metrics } from \"../metrics.js\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\n\nexport type WebAuthnSigner = {\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n};\n\nexport type SmartWalletSigner = SmartAccountSigner<any> | WebAuthnSigner;\n\nexport type SmartWalletClientParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Prettify<\n {\n transport: AlchemyTransport;\n chain: Chain;\n signer: SmartWalletSigner;\n account?: TAccount | Address | undefined;\n } & (\n | { policyId?: string; policyIds?: never }\n | { policyIds?: string[]; policyId?: never }\n )\n>;\n\nexport type SmartWalletClient<\n TAccount extends Address | undefined = Address | undefined,\n> = InnerWalletApiClientBase<SmartWalletActions<TAccount>>;\n\n/**\n * Creates a smart wallet client that can be used to interact with a smart account.\n *\n * @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client\n * @param {AlchemyTransport} params.transport - The Alchemy transport to use\n * @param {Chain} params.chain - The chain to use\n * @param {SmartAccountSigner | WebAuthnSigner} params.signer - The signer to use for the smart account\n * @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)\n * @param {Address} [params.account] - The smart account address to use (optional)\n * @returns {SmartWalletClient} - A viem-compatible client\n *\n * @example\n * ```ts\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { alchemy, arbitrumSepolia } from \"@account-kit/infra\";\n * import { generatePrivateKey } from \"viem/accounts\";\n * import { createSmartWalletClient } from \"@account-kit/wallet-client\";\n *\n * const signer = LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey());\n * const transport = alchemy({\n * apiKey: \"your-alchemy-api-key\",\n * });\n * const client = createSmartWalletClient({\n * transport,\n * chain: arbitrumSepolia,\n * signer,\n * });\n * ```\n */\nexport function createSmartWalletClient<\n TAccount extends Address | undefined = undefined,\n>(params: SmartWalletClientParams<TAccount>): SmartWalletClient<TAccount>;\n\nexport function createSmartWalletClient(\n params: SmartWalletClientParams,\n): SmartWalletClient {\n const { transport, chain, account, signer } = params;\n\n const policyIds = params.policyId\n ? [params.policyId]\n : params.policyIds\n ? params.policyIds\n : undefined;\n\n const innerClient = createClient<\n Transport,\n Chain,\n JsonRpcAccount<Address> | undefined,\n WalletServerViemRpcSchema\n >({\n transport: (opts) =>\n custom(\n Provider.from(transport(opts), {\n schema: RpcSchema.from<WalletServerRpcSchemaType>(),\n }),\n )(opts),\n chain,\n account,\n }).extend(() => ({\n policyIds,\n internal: internalStateDecorator(),\n }));\n\n metrics.trackEvent({\n name: \"client_created\",\n data: {\n chainId: params.chain.id,\n },\n });\n\n return innerClient.extend((client) =>\n smartWalletClientActions(client, signer),\n );\n}\n\n// Example usage:\n// const clientWithoutAccount = createSmartWalletClient({\n// transport: alchemy({ apiKey: \"123\" }),\n// chain: baseSepolia,\n// signer: createDummySigner(zeroAddress),\n// });\n\n// const account1 = await clientWithoutAccount.requestAccount();\n\n// const clientWithAccount = createSmartWalletClient({\n// transport: alchemy({ apiKey: \"123\" }),\n// chain: baseSepolia,\n// signer: createDummySigner(zeroAddress),\n// account: zeroAddress,\n// });\n\n// const account2 = await clientWithAccount.requestAccount();\n"]}
@@ -1,10 +1,11 @@
1
- import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
1
+ import { type SmartContractAccount } from "@aa-sdk/core";
2
2
  import { type Chain, type Transport, type Address } from "viem";
3
3
  import type { SerializedInitcode } from "@alchemy/wallet-api-types";
4
+ import type { SmartWalletSigner } from "../client/index.js";
4
5
  type CreateAccountParams = {
5
6
  chain: Chain;
6
7
  transport: Transport;
7
- signer: SmartAccountSigner;
8
+ signer: SmartWalletSigner;
8
9
  accountAddress: Address;
9
10
  counterfactualInfo?: SerializedInitcode;
10
11
  delegation?: Address;
@@ -1,7 +1,8 @@
1
+ import { InvalidSignerTypeError, } from "@aa-sdk/core";
1
2
  import { createModularAccountV2, createLightAccount, createMultiOwnerLightAccount, createMultiOwnerModularAccount, } from "@account-kit/smart-contracts";
2
3
  import { concatHex, isAddressEqual, } from "viem";
3
4
  import { InternalError, InvalidRequestError } from "ox/RpcResponse";
4
- import { assertNever } from "../utils.js";
5
+ import { assertNever, isWebAuthnSigner } from "../utils.js";
5
6
  import { metrics } from "../metrics.js";
6
7
  /**
7
8
  * Creates a smart account instance from the given parameters.
@@ -23,13 +24,17 @@ import { metrics } from "../metrics.js";
23
24
  * ```
24
25
  */
25
26
  export async function createAccount(params) {
26
- const { counterfactualInfo: ci, ...accountParams } = params;
27
+ const { counterfactualInfo: ci, signer, ...accountParams } = params;
27
28
  if (params.delegation) {
28
29
  if (!isAddressEqual(params.delegation, MAV2_7702_DELEGATION_ADDRESS)) {
29
30
  throw new Error("7702 mode currently only supports ModularAccountV2");
30
31
  }
32
+ if (isWebAuthnSigner(signer)) {
33
+ throw new InvalidSignerTypeError("WebAuthn");
34
+ }
31
35
  return createModularAccountV2({
32
36
  ...accountParams,
37
+ signer,
33
38
  mode: "7702",
34
39
  });
35
40
  }
@@ -52,45 +57,65 @@ export async function createAccount(params) {
52
57
  : (params.counterfactualInfo?.factoryType ?? "unknown"),
53
58
  },
54
59
  });
60
+ // WebAuthn accounts must use a different signer type, so they are handled separately.
61
+ if (factoryType === "MAv2.0.0-ma-webauthn") {
62
+ if (!isWebAuthnSigner(signer)) {
63
+ throw new InvalidSignerTypeError(signer.signerType);
64
+ }
65
+ return createModularAccountV2({
66
+ ...commonParams,
67
+ ...signer,
68
+ mode: "webauthn",
69
+ });
70
+ }
71
+ if (isWebAuthnSigner(signer)) {
72
+ throw new InvalidSignerTypeError("WebAuthn");
73
+ }
55
74
  // Return the account created based on the factory type
56
75
  switch (factoryType) {
57
76
  case "MAv2.0.0-sma-b":
58
77
  return createModularAccountV2({
59
78
  ...commonParams,
79
+ signer,
60
80
  mode: "default",
61
81
  });
62
82
  case "LightAccountV2.0.0":
63
83
  return createLightAccount({
64
84
  ...commonParams,
85
+ signer,
65
86
  version: "v2.0.0",
66
87
  });
67
88
  case "LightAccountV1.0.1":
68
89
  return createLightAccount({
69
90
  ...commonParams,
91
+ signer,
70
92
  version: "v1.0.1",
71
93
  });
72
94
  case "LightAccountV1.0.2":
73
95
  return createLightAccount({
74
96
  ...commonParams,
97
+ signer,
75
98
  version: "v1.0.2",
76
99
  });
77
100
  case "LightAccountV1.1.0":
78
101
  return createLightAccount({
79
102
  ...commonParams,
103
+ signer,
80
104
  version: "v1.1.0",
81
105
  });
82
106
  case "MAv1.0.0-MultiOwner":
83
107
  return createMultiOwnerModularAccount({
84
108
  ...commonParams,
109
+ signer,
85
110
  });
86
111
  case "LightAccountV2.0.0-MultiOwner":
87
112
  return createMultiOwnerLightAccount({
88
113
  ...commonParams,
89
114
  version: "v2.0.0",
115
+ signer,
90
116
  });
91
117
  case "MAv1.0.0-MultiSig":
92
118
  case "MAv2.0.0-ma-ssv":
93
- case "MAv2.0.0-ma-webauthn":
94
119
  case "unknown":
95
120
  case undefined:
96
121
  throw new InvalidRequestError({
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/internal/account.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,SAAS,EAIT,cAAc,GACf,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAWxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA2B;IAE3B,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IAE5D,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,4BAA4B,CAAC,EAAE,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,sBAAsB,CAAC;YA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;aAClB,CAAC,CAAC;QACL,KAAK,qBAAqB;YACxB,OAAO,8BAA8B,CAAC;gBACpC,GAAG,YAAY;aAChB,CAAC,CAAC;QACL,KAAK,+BAA+B;YAClC,OAAO,4BAA4B,CAAC;gBAClC,GAAG,YAAY;gBACf,OAAO,EAAE,QAAQ;aAClB,CAAC,CAAC;QACL,KAAK,mBAAmB,CAAC;QACzB,KAAK,iBAAiB,CAAC;QACvB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,SAAS,CAAC;QACf,KAAK,SAAS;YACZ,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,uCAAuC,WAAW,EAAE;aAC9D,CAAC,CAAC;QACL;YACE,OAAO,WAAW,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,MAAM,4BAA4B,GAChC,4CAA4C,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n createLightAccount,\n createMultiOwnerLightAccount,\n createMultiOwnerModularAccount,\n} from \"@account-kit/smart-contracts\";\nimport {\n concatHex,\n type Chain,\n type Transport,\n type Address,\n isAddressEqual,\n} from \"viem\";\nimport type { SerializedInitcode } from \"@alchemy/wallet-api-types\";\nimport { InternalError, InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../utils.js\";\nimport { metrics } from \"../metrics.js\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: SerializedInitcode; // undefined for 7702 accounts\n delegation?: Address; // for 7702 accounts\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n *\n * @param {CreateAccountParams} params - The parameters for creating a smart account.\n * @returns {Promise<SmartContractAccount>} A promise that resolves to the created smart account.\n *\n * @example\n * ```ts\n * // Create a smart account\n * const account = await createAccount({\n * chain: arbitrumSepolia,\n * transport: alchemy({\n * apiKey: \"your-alchemy-api-key\",\n * }),\n * signer: signer,\n * accountAddress: \"0x1234...\",\n * });\n * ```\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n if (params.delegation) {\n if (!isAddressEqual(params.delegation, MAV2_7702_DELEGATION_ADDRESS)) {\n throw new Error(\"7702 mode currently only supports ModularAccountV2\");\n }\n return createModularAccountV2({\n ...accountParams,\n mode: \"7702\",\n });\n }\n\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n\n const factoryType = ci.factoryType;\n const commonParams = {\n ...accountParams,\n initCode: concatHex([ci.factoryAddress, ci.factoryData]),\n };\n\n metrics.trackEvent({\n name: \"account_initialized\",\n data: {\n chainId: params.chain.id,\n factory: params.delegation\n ? \"7702\"\n : (params.counterfactualInfo?.factoryType ?? \"unknown\"),\n },\n });\n\n // Return the account created based on the factory type\n switch (factoryType) {\n case \"MAv2.0.0-sma-b\":\n return createModularAccountV2({\n ...commonParams,\n mode: \"default\",\n });\n case \"LightAccountV2.0.0\":\n return createLightAccount({\n ...commonParams,\n version: \"v2.0.0\",\n });\n case \"LightAccountV1.0.1\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.0.1\",\n });\n case \"LightAccountV1.0.2\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.0.2\",\n });\n case \"LightAccountV1.1.0\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.1.0\",\n });\n case \"MAv1.0.0-MultiOwner\":\n return createMultiOwnerModularAccount({\n ...commonParams,\n });\n case \"LightAccountV2.0.0-MultiOwner\":\n return createMultiOwnerLightAccount({\n ...commonParams,\n version: \"v2.0.0\",\n });\n case \"MAv1.0.0-MultiSig\":\n case \"MAv2.0.0-ma-ssv\":\n case \"MAv2.0.0-ma-webauthn\":\n case \"unknown\":\n case undefined:\n throw new InvalidRequestError({\n message: `Account type currently unsupported: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n}\n\nconst MAV2_7702_DELEGATION_ADDRESS =\n \"0x69007702764179f14F51cdce752f4f775d74E139\";\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/internal/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,SAAS,EAIT,cAAc,GACf,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA2B;IAE3B,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IAEpE,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,4BAA4B,CAAC,EAAE,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,sBAAsB,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,sBAAsB,CAAC;YAC5B,GAAG,aAAa;YAChB,MAAM;YACN,IAAI,EAAE,MAAM;SACb,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EAAE,+BAA+B;SACzC,CAAC,CAAC;IACL,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C;gBACxB,GAAG,YAAY;gBACf,MAAM;gBACN,OAAO,EAAE,QAAQ;aAClB,CAAC,CAAC;QACL,KAAK,oBAAoB;YACvB,OAAO,kBAAkB,CAAC;gBACxB,GAAG,YAAY;gBACf,MAAM;gBACN,OAAO,EAAE,QAAQ;aAClB,CAAC,CAAC;QACL,KAAK,oBAAoB;YACvB,OAAO,kBAAkB,CAAC;gBACxB,GAAG,YAAY;gBACf,MAAM;gBACN,OAAO,EAAE,QAAQ;aAClB,CAAC,CAAC;QACL,KAAK,qBAAqB;YACxB,OAAO,8BAA8B,CAAC;gBACpC,GAAG,YAAY;gBACf,MAAM;aACP,CAAC,CAAC;QACL,KAAK,+BAA+B;YAClC,OAAO,4BAA4B,CAAC;gBAClC,GAAG,YAAY;gBACf,OAAO,EAAE,QAAQ;gBACjB,MAAM;aACP,CAAC,CAAC;QACL,KAAK,mBAAmB,CAAC;QACzB,KAAK,iBAAiB,CAAC;QACvB,KAAK,SAAS,CAAC;QACf,KAAK,SAAS;YACZ,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,uCAAuC,WAAW,EAAE;aAC9D,CAAC,CAAC;QACL;YACE,OAAO,WAAW,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,MAAM,4BAA4B,GAChC,4CAA4C,CAAC","sourcesContent":["import {\n InvalidSignerTypeError,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n createLightAccount,\n createMultiOwnerLightAccount,\n createMultiOwnerModularAccount,\n} from \"@account-kit/smart-contracts\";\nimport {\n concatHex,\n type Chain,\n type Transport,\n type Address,\n isAddressEqual,\n} from \"viem\";\nimport type { SerializedInitcode } from \"@alchemy/wallet-api-types\";\nimport { InternalError, InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever, isWebAuthnSigner } from \"../utils.js\";\nimport { metrics } from \"../metrics.js\";\nimport type { SmartWalletSigner } from \"../client/index.js\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartWalletSigner;\n accountAddress: Address;\n counterfactualInfo?: SerializedInitcode; // undefined for 7702 accounts\n delegation?: Address; // for 7702 accounts\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n *\n * @param {CreateAccountParams} params - The parameters for creating a smart account.\n * @returns {Promise<SmartContractAccount>} A promise that resolves to the created smart account.\n *\n * @example\n * ```ts\n * // Create a smart account\n * const account = await createAccount({\n * chain: arbitrumSepolia,\n * transport: alchemy({\n * apiKey: \"your-alchemy-api-key\",\n * }),\n * signer: signer,\n * accountAddress: \"0x1234...\",\n * });\n * ```\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, signer, ...accountParams } = params;\n\n if (params.delegation) {\n if (!isAddressEqual(params.delegation, MAV2_7702_DELEGATION_ADDRESS)) {\n throw new Error(\"7702 mode currently only supports ModularAccountV2\");\n }\n\n if (isWebAuthnSigner(signer)) {\n throw new InvalidSignerTypeError(\"WebAuthn\");\n }\n\n return createModularAccountV2({\n ...accountParams,\n signer,\n mode: \"7702\",\n });\n }\n\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n\n const factoryType = ci.factoryType;\n const commonParams = {\n ...accountParams,\n initCode: concatHex([ci.factoryAddress, ci.factoryData]),\n };\n\n metrics.trackEvent({\n name: \"account_initialized\",\n data: {\n chainId: params.chain.id,\n factory: params.delegation\n ? \"7702\"\n : (params.counterfactualInfo?.factoryType ?? \"unknown\"),\n },\n });\n\n // WebAuthn accounts must use a different signer type, so they are handled separately.\n if (factoryType === \"MAv2.0.0-ma-webauthn\") {\n if (!isWebAuthnSigner(signer)) {\n throw new InvalidSignerTypeError(signer.signerType);\n }\n\n return createModularAccountV2({\n ...commonParams,\n ...signer,\n mode: \"webauthn\",\n });\n }\n\n if (isWebAuthnSigner(signer)) {\n throw new InvalidSignerTypeError(\"WebAuthn\");\n }\n\n // Return the account created based on the factory type\n switch (factoryType) {\n case \"MAv2.0.0-sma-b\":\n return createModularAccountV2({\n ...commonParams,\n signer,\n mode: \"default\",\n });\n case \"LightAccountV2.0.0\":\n return createLightAccount({\n ...commonParams,\n signer,\n version: \"v2.0.0\",\n });\n case \"LightAccountV1.0.1\":\n return createLightAccount({\n ...commonParams,\n signer,\n version: \"v1.0.1\",\n });\n case \"LightAccountV1.0.2\":\n return createLightAccount({\n ...commonParams,\n signer,\n version: \"v1.0.2\",\n });\n case \"LightAccountV1.1.0\":\n return createLightAccount({\n ...commonParams,\n signer,\n version: \"v1.1.0\",\n });\n case \"MAv1.0.0-MultiOwner\":\n return createMultiOwnerModularAccount({\n ...commonParams,\n signer,\n });\n case \"LightAccountV2.0.0-MultiOwner\":\n return createMultiOwnerLightAccount({\n ...commonParams,\n version: \"v2.0.0\",\n signer,\n });\n case \"MAv1.0.0-MultiSig\":\n case \"MAv2.0.0-ma-ssv\":\n case \"unknown\":\n case undefined:\n throw new InvalidRequestError({\n message: `Account type currently unsupported: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n}\n\nconst MAV2_7702_DELEGATION_ADDRESS =\n \"0x69007702764179f14F51cdce752f4f775d74E139\";\n"]}
@@ -1,4 +1,8 @@
1
1
  import { type Hex } from "viem";
2
+ import type { SmartAccountSigner } from "@aa-sdk/core";
3
+ import type { WebAuthnPublicKey } from "@alchemy/wallet-api-types";
4
+ import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
5
+ import type { WebAuthnSigner } from "./client";
2
6
  export type Expect<T extends true> = T;
3
7
  export declare const assertNever: (_val: never, msg: string) => never;
4
8
  /**
@@ -15,3 +19,5 @@ export declare const assertNever: (_val: never, msg: string) => never;
15
19
  * ```
16
20
  */
17
21
  export declare const castToHex: (val: string | number | bigint | Hex) => Hex;
22
+ export declare function isWebAuthnSigner(signer: SmartAccountSigner | WebAuthnSigner): signer is WebAuthnSigner;
23
+ export declare function credentialToWebAuthnPublicKey(credential: ToWebAuthnAccountParameters["credential"]): WebAuthnPublicKey;
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isHex, toHex } from "viem";
1
+ import { isHex, sliceHex, toHex } from "viem";
2
2
  export const assertNever = (_val, msg) => {
3
3
  throw new Error(msg);
4
4
  };
@@ -21,4 +21,17 @@ export const castToHex = (val) => {
21
21
  }
22
22
  return toHex(val);
23
23
  };
24
+ export function isWebAuthnSigner(signer) {
25
+ return "credential" in signer;
26
+ }
27
+ export function credentialToWebAuthnPublicKey(credential) {
28
+ const { x, y } = {
29
+ x: sliceHex(credential.publicKey, 0, 32, { strict: true }),
30
+ y: sliceHex(credential.publicKey, 32, 64, { strict: true }),
31
+ };
32
+ return {
33
+ x,
34
+ y,
35
+ };
36
+ }
24
37
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAY,MAAM,MAAM,CAAC;AAI9C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAW,EAAE,GAAW,EAAS,EAAE;IAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAmC,EAAO,EAAE;IACpE,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import { isHex, toHex, type Hex } from \"viem\";\n\nexport type Expect<T extends true> = T;\n\nexport const assertNever = (_val: never, msg: string): never => {\n throw new Error(msg);\n};\n\n/**\n * If the value is already Hex, it is returned unchanged. If it's a string, number or bigint, it's converted.\n *\n * @param {string | number | bigint | Hex} val - The value to convert to Hex.\n * @returns {Hex} The Hex value.\n *\n * @example\n * ```ts\n * const hex = castToHex(\"0x1234\");\n * const hex2 = castToHex(1234);\n * const hex3 = castToHex(BigInt(1234));\n * ```\n */\nexport const castToHex = (val: string | number | bigint | Hex): Hex => {\n if (isHex(val)) {\n return val;\n }\n return toHex(val);\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAY,MAAM,MAAM,CAAC;AAQxD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAW,EAAE,GAAW,EAAS,EAAE;IAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAmC,EAAO,EAAE;IACpE,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAC9B,MAA2C;IAE3C,OAAO,YAAY,IAAI,MAAM,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,UAAqD;IAErD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;QACf,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC1D,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KAC5D,CAAC;IAEF,OAAO;QACL,CAAC;QACD,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { isHex, sliceHex, toHex, type Hex } from \"viem\";\nimport type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { WebAuthnPublicKey } from \"@alchemy/wallet-api-types\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport type { WebAuthnSigner } from \"./client\";\n\nexport type Expect<T extends true> = T;\n\nexport const assertNever = (_val: never, msg: string): never => {\n throw new Error(msg);\n};\n\n/**\n * If the value is already Hex, it is returned unchanged. If it's a string, number or bigint, it's converted.\n *\n * @param {string | number | bigint | Hex} val - The value to convert to Hex.\n * @returns {Hex} The Hex value.\n *\n * @example\n * ```ts\n * const hex = castToHex(\"0x1234\");\n * const hex2 = castToHex(1234);\n * const hex3 = castToHex(BigInt(1234));\n * ```\n */\nexport const castToHex = (val: string | number | bigint | Hex): Hex => {\n if (isHex(val)) {\n return val;\n }\n return toHex(val);\n};\n\nexport function isWebAuthnSigner(\n signer: SmartAccountSigner | WebAuthnSigner,\n): signer is WebAuthnSigner {\n return \"credential\" in signer;\n}\n\nexport function credentialToWebAuthnPublicKey(\n credential: ToWebAuthnAccountParameters[\"credential\"],\n): WebAuthnPublicKey {\n const { x, y } = {\n x: sliceHex(credential.publicKey, 0, 32, { strict: true }),\n y: sliceHex(credential.publicKey, 32, 64, { strict: true }),\n };\n\n return {\n x,\n y,\n };\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.76.0";
1
+ export declare const VERSION = "4.77.0";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.76.0";
3
+ export const VERSION = "4.77.0";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.76.0\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.77.0\";\n"]}
@@ -1,7 +1,7 @@
1
- import { type SmartAccountSigner } from "@aa-sdk/core";
2
1
  import { type Address, type Hex, type IsUndefined, type Prettify } from "viem";
3
2
  import type { InnerWalletApiClient } from "../../types.ts";
4
3
  import type { WalletServerRpcSchemaType } from "@alchemy/wallet-api-types/rpc";
4
+ import type { SmartWalletSigner } from "../index.js";
5
5
  type RpcSchema = Extract<WalletServerRpcSchemaType, {
6
6
  Request: {
7
7
  method: "wallet_createSession";
@@ -20,7 +20,7 @@ export type GrantPermissionsResult = {
20
20
  * This allows another key to perform operations on behalf of the account.
21
21
  *
22
22
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
23
- * @param {SmartAccountSigner} signer - The signer of the smart account
23
+ * @param {SmartAccountSigner | WebAuthnSigner} signer - The signer of the smart account
24
24
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
25
25
  * @param {Address} [params.account] - The account address (required if client was not initialized with an account)
26
26
  * @param {number} params.expirySec - Unix timestamp when the permissions expire
@@ -70,6 +70,6 @@ export type GrantPermissionsResult = {
70
70
  * });
71
71
  * ```
72
72
  */
73
- export declare function grantPermissions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, signer: SmartAccountSigner, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
73
+ export declare function grantPermissions<TAccount extends Address | undefined = Address | undefined>(client: InnerWalletApiClient, signer: SmartWalletSigner, params: GrantPermissionsParams<TAccount>): Promise<GrantPermissionsResult>;
74
74
  export {};
75
75
  //# sourceMappingURL=grantPermissions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grantPermissions.d.ts","sourceRoot":"","s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