@account-kit/wallet-client 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (186) hide show
  1. package/dist/esm/capabilities/eip7702Auth.d.ts +4 -0
  2. package/dist/esm/capabilities/eip7702Auth.js +18 -0
  3. package/dist/esm/capabilities/eip7702Auth.js.map +1 -0
  4. package/dist/esm/capabilities/index.d.ts +4 -0
  5. package/dist/esm/capabilities/index.js +2 -0
  6. package/dist/esm/capabilities/index.js.map +1 -1
  7. package/dist/esm/capabilities/overrides.js +8 -8
  8. package/dist/esm/capabilities/overrides.js.map +1 -1
  9. package/dist/esm/capabilities/permissions/index.d.ts +2 -2
  10. package/dist/esm/capabilities/permissions/index.js +6 -3
  11. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  12. package/dist/esm/capabilities/permissions/mav2.js +1 -0
  13. package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
  14. package/dist/esm/client/actions/getCallsStatus.d.ts +1 -2
  15. package/dist/esm/client/actions/getCallsStatus.js +19 -0
  16. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  17. package/dist/esm/client/actions/grantPermissions.d.ts +10 -65
  18. package/dist/esm/client/actions/grantPermissions.js +63 -4
  19. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  20. package/dist/esm/client/actions/prepareCalls.d.ts +4 -4
  21. package/dist/esm/client/actions/prepareCalls.js +38 -5
  22. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  23. package/dist/esm/client/actions/requestAccount.d.ts +3 -4
  24. package/dist/esm/client/actions/requestAccount.js +18 -1
  25. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  26. package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
  27. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  28. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  29. package/dist/esm/client/actions/signMessage.d.ts +3 -3
  30. package/dist/esm/client/actions/signMessage.js +18 -0
  31. package/dist/esm/client/actions/signMessage.js.map +1 -1
  32. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  33. package/dist/esm/client/actions/signPreparedCalls.js +53 -0
  34. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  35. package/dist/esm/client/actions/signSignatureRequest.d.ts +9 -8
  36. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  37. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  38. package/dist/esm/client/actions/signTypedData.d.ts +2 -2
  39. package/dist/esm/client/actions/signTypedData.js +31 -0
  40. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  41. package/dist/esm/client/client.e2e-test.js +47 -44
  42. package/dist/esm/client/client.e2e-test.js.map +1 -1
  43. package/dist/esm/client/decorator.d.ts +7 -5
  44. package/dist/esm/client/decorator.js +3 -1
  45. package/dist/esm/client/decorator.js.map +1 -1
  46. package/dist/esm/client/index.d.ts +35 -10
  47. package/dist/esm/client/index.js +0 -29
  48. package/dist/esm/client/index.js.map +1 -1
  49. package/dist/esm/exports/index.d.ts +2 -1
  50. package/dist/esm/exports/index.js +2 -1
  51. package/dist/esm/exports/index.js.map +1 -1
  52. package/dist/esm/isomorphic/actions/createSession.js +15 -18
  53. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  54. package/dist/esm/isomorphic/actions/getCallsStatus.js +62 -9
  55. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
  56. package/dist/esm/isomorphic/actions/prepareCalls.js +39 -26
  57. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  58. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  59. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +77 -37
  60. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  61. package/dist/esm/isomorphic/client.d.ts +139 -13
  62. package/dist/esm/isomorphic/utils/7702.d.ts +13 -6
  63. package/dist/esm/isomorphic/utils/7702.js +48 -13
  64. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  65. package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -2
  66. package/dist/esm/isomorphic/utils/createAccount.js +4 -3
  67. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  68. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  69. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  70. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  71. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
  72. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +8 -7
  73. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
  74. package/dist/esm/local/client.d.ts +2 -2
  75. package/dist/esm/local/client.js +2 -3
  76. package/dist/esm/local/client.js.map +1 -1
  77. package/dist/esm/remote/client.d.ts +8 -2
  78. package/dist/esm/remote/client.js +3 -13
  79. package/dist/esm/remote/client.js.map +1 -1
  80. package/dist/esm/rpc/examples.d.ts +3 -3
  81. package/dist/esm/rpc/examples.js +3 -3
  82. package/dist/esm/rpc/examples.js.map +1 -1
  83. package/dist/esm/rpc/request.d.ts +362 -44
  84. package/dist/esm/rpc/request.js +26 -56
  85. package/dist/esm/rpc/request.js.map +1 -1
  86. package/dist/esm/rpc/schema.d.ts +325 -49
  87. package/dist/esm/rpc/schema.js.map +1 -1
  88. package/dist/esm/schemas.d.ts +454 -14
  89. package/dist/esm/schemas.js +168 -53
  90. package/dist/esm/schemas.js.map +1 -1
  91. package/dist/esm/types.d.ts +10 -10
  92. package/dist/esm/types.js.map +1 -1
  93. package/dist/types/capabilities/eip7702Auth.d.ts +5 -0
  94. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -0
  95. package/dist/types/capabilities/index.d.ts +4 -0
  96. package/dist/types/capabilities/index.d.ts.map +1 -1
  97. package/dist/types/capabilities/permissions/index.d.ts +2 -2
  98. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  99. package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
  100. package/dist/types/client/actions/getCallsStatus.d.ts +1 -2
  101. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  102. package/dist/types/client/actions/grantPermissions.d.ts +10 -65
  103. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  104. package/dist/types/client/actions/prepareCalls.d.ts +4 -4
  105. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  106. package/dist/types/client/actions/requestAccount.d.ts +3 -4
  107. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  108. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  109. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  110. package/dist/types/client/actions/signMessage.d.ts +3 -3
  111. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  112. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  113. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  114. package/dist/types/client/actions/signSignatureRequest.d.ts +9 -8
  115. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  116. package/dist/types/client/actions/signTypedData.d.ts +2 -2
  117. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  118. package/dist/types/client/decorator.d.ts +7 -5
  119. package/dist/types/client/decorator.d.ts.map +1 -1
  120. package/dist/types/client/index.d.ts +35 -10
  121. package/dist/types/client/index.d.ts.map +1 -1
  122. package/dist/types/exports/index.d.ts +2 -1
  123. package/dist/types/exports/index.d.ts.map +1 -1
  124. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  125. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
  126. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  127. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  128. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  129. package/dist/types/isomorphic/client.d.ts +139 -13
  130. package/dist/types/isomorphic/client.d.ts.map +1 -1
  131. package/dist/types/isomorphic/utils/7702.d.ts +13 -6
  132. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  133. package/dist/types/isomorphic/utils/createAccount.d.ts +2 -2
  134. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  135. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  136. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  137. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
  138. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
  139. package/dist/types/local/client.d.ts +2 -2
  140. package/dist/types/local/client.d.ts.map +1 -1
  141. package/dist/types/remote/client.d.ts +8 -2
  142. package/dist/types/remote/client.d.ts.map +1 -1
  143. package/dist/types/rpc/examples.d.ts +3 -3
  144. package/dist/types/rpc/examples.d.ts.map +1 -1
  145. package/dist/types/rpc/request.d.ts +362 -44
  146. package/dist/types/rpc/request.d.ts.map +1 -1
  147. package/dist/types/rpc/schema.d.ts +325 -49
  148. package/dist/types/rpc/schema.d.ts.map +1 -1
  149. package/dist/types/schemas.d.ts +454 -14
  150. package/dist/types/schemas.d.ts.map +1 -1
  151. package/dist/types/types.d.ts +10 -10
  152. package/dist/types/types.d.ts.map +1 -1
  153. package/package.json +2 -2
  154. package/src/capabilities/eip7702Auth.ts +26 -0
  155. package/src/capabilities/index.ts +2 -0
  156. package/src/capabilities/overrides.ts +8 -8
  157. package/src/capabilities/permissions/index.ts +8 -3
  158. package/src/capabilities/permissions/mav2.ts +1 -0
  159. package/src/client/actions/getCallsStatus.ts +0 -10
  160. package/src/client/actions/grantPermissions.ts +16 -84
  161. package/src/client/actions/prepareCalls.ts +18 -23
  162. package/src/client/actions/requestAccount.ts +9 -26
  163. package/src/client/actions/sendPreparedCalls.ts +17 -17
  164. package/src/client/actions/signMessage.ts +2 -17
  165. package/src/client/actions/signPreparedCalls.ts +71 -0
  166. package/src/client/actions/signSignatureRequest.ts +51 -47
  167. package/src/client/actions/signTypedData.ts +1 -16
  168. package/src/client/client.e2e-test.ts +54 -57
  169. package/src/client/decorator.ts +19 -15
  170. package/src/client/index.ts +16 -39
  171. package/src/exports/index.ts +2 -1
  172. package/src/isomorphic/actions/createSession.ts +17 -20
  173. package/src/isomorphic/actions/getCallsStatus.ts +82 -10
  174. package/src/isomorphic/actions/prepareCalls.ts +43 -27
  175. package/src/isomorphic/actions/sendPreparedCalls.ts +105 -55
  176. package/src/isomorphic/utils/7702.ts +79 -21
  177. package/src/isomorphic/utils/createAccount.ts +5 -5
  178. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  179. package/src/isomorphic/utils/parsePermissionsContext.ts +9 -9
  180. package/src/local/client.ts +5 -11
  181. package/src/remote/client.ts +7 -22
  182. package/src/rpc/examples.ts +3 -4
  183. package/src/rpc/request.ts +41 -64
  184. package/src/rpc/schema.ts +2 -2
  185. package/src/schemas.ts +232 -54
  186. package/src/types.ts +9 -21
@@ -0,0 +1,26 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { TypeAddress } from "../schemas.js";
3
+ import {
4
+ EIP_7702_ACCOUNT_TYPE,
5
+ SUPPORTED_DELEGATION_ADDRESSES,
6
+ } from "../isomorphic/utils/7702.js";
7
+
8
+ export const Eip7702AuthCapability = Type.Union([
9
+ Type.Object(
10
+ {
11
+ account: Type.Optional(TypeAddress),
12
+ // Wallet applications must maintain a strict shortlist of well-known accounts.
13
+ // https://github.com/ethereum/ERCs/pull/947/files#diff-dab085f963ca621595044bcbc0922705aa38b69f5bf8770dcb3d0496a633efcfR189
14
+ delegation: Type.Union([
15
+ ...SUPPORTED_DELEGATION_ADDRESSES.map((address) =>
16
+ Type.Literal(address),
17
+ ),
18
+ ...EIP_7702_ACCOUNT_TYPE.map((it) => Type.Literal(it)),
19
+ ]),
20
+ },
21
+ {
22
+ description: "Specify EIP-7702 delegation",
23
+ },
24
+ ),
25
+ Type.Literal(true, { description: "Default EIP-7702 delegation" }),
26
+ ]);
@@ -2,9 +2,11 @@ import { Type } from "@sinclair/typebox";
2
2
  import { GasParamsOverrideCapability } from "./overrides.js";
3
3
  import { PaymasterCapability } from "./paymaster.js";
4
4
  import { PermissionsCapability } from "./permissions/index.js";
5
+ import { Eip7702AuthCapability } from "./eip7702Auth.js";
5
6
 
6
7
  export const Capabilities = Type.Object({
7
8
  permissions: Type.Optional(PermissionsCapability),
8
9
  paymasterService: Type.Optional(PaymasterCapability),
9
10
  gasParamsOverride: Type.Optional(GasParamsOverrideCapability),
11
+ eip7702Auth: Type.Optional(Eip7702AuthCapability),
10
12
  });
@@ -3,32 +3,32 @@ import { TypeHex } from "../schemas.js";
3
3
 
4
4
  export const Mutliplier = Type.Object(
5
5
  { multiplier: Type.Number() },
6
- { title: "Multiplier" },
6
+ { description: "Multiplier" },
7
7
  );
8
8
 
9
9
  // This is still being defined in https://github.com/ethereum/ERCs/pull/947/files#diff-dab085f963ca621595044bcbc0922705aa38b69f5bf8770dcb3d0496a633efcfR158
10
10
  export const GasParamsOverrideCapability = Type.Object(
11
11
  {
12
12
  preVerificationGas: Type.Optional(
13
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
13
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
14
14
  ),
15
15
  verificationGasLimit: Type.Optional(
16
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
16
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
17
17
  ),
18
18
  callGasLimit: Type.Optional(
19
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
19
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
20
20
  ),
21
21
  paymasterVerificationGasLimit: Type.Optional(
22
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
22
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
23
23
  ),
24
24
  paymasterPostOpGasLimit: Type.Optional(
25
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
25
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
26
26
  ),
27
27
  maxFeePerGas: Type.Optional(
28
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
28
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
29
29
  ),
30
30
  maxPriorityFeePerGas: Type.Optional(
31
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
31
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
32
32
  ),
33
33
  },
34
34
  { minProperties: 1 },
@@ -129,7 +129,7 @@ export const PermissionsContext = Type.Object(
129
129
  context: TypeHex(),
130
130
  },
131
131
  {
132
- title: "Permissions context",
132
+ description: "Permissions context",
133
133
  },
134
134
  );
135
135
 
@@ -139,13 +139,18 @@ export const RemotePermission = Type.Object(
139
139
  signature: TypeHex(),
140
140
  },
141
141
  {
142
- title: "Remote permission",
142
+ description: "Remote permission",
143
143
  },
144
144
  );
145
145
 
146
146
  export const PermissionsData = Type.Object({
147
147
  chainId: TypeHex(),
148
- expiry: Type.Optional(Type.Integer()),
148
+ expirySec: Type.Optional(
149
+ Type.Integer({
150
+ maximum: 9999999999, // This is valid until November 20, 2286.
151
+ description: "Unix timestamp in seconds (0 for no expiry)",
152
+ }),
153
+ ),
149
154
  key: KeySigner,
150
155
  permissions: PermissionsArray,
151
156
  });
@@ -121,6 +121,7 @@ export const prefixSignatureKeyType = (
121
121
  type: KeySigner["type"],
122
122
  ): Hex => {
123
123
  switch (type) {
124
+ case "ecdsa":
124
125
  case "secp256k1":
125
126
  return concatHex(["0x00", sig]);
126
127
  case "contract":
@@ -1,4 +1,3 @@
1
- import type { Address, JsonRpcAccount } from "viem";
2
1
  import type {
3
2
  GetCallsStatusParams as IsomorphicGetCallsStatusParams,
4
3
  GetCallsStatusResponse as IsomorphicGetCallsStatusResult,
@@ -28,15 +27,6 @@ export type GetCallsStatusResult = IsomorphicGetCallsStatusResult;
28
27
  * // Check the status of the first call ID
29
28
  * const status = await client.getCallsStatus(sendResult.preparedCallIds[0]);
30
29
  */
31
- export async function getCallsStatus<
32
- TAccount extends JsonRpcAccount<Address> | undefined =
33
- | JsonRpcAccount<Address>
34
- | undefined,
35
- >(
36
- client: InnerWalletApiClient<TAccount>,
37
- params: GetCallsStatusParams,
38
- ): Promise<GetCallsStatusResult>;
39
-
40
30
  export async function getCallsStatus(
41
31
  client: InnerWalletApiClient,
42
32
  params: GetCallsStatusParams,
@@ -1,20 +1,10 @@
1
- import {
2
- type Address,
3
- type Hex,
4
- type IsUndefined,
5
- type JsonRpcAccount,
6
- toHex,
7
- } from "viem";
8
- import type { InnerWalletApiClient } from "../../types.ts";
9
- import type { SmartAccountSigner } from "@aa-sdk/core";
1
+ import { AccountNotFoundError, type SmartAccountSigner } from "@aa-sdk/core";
2
+ import { type Address, type Hex, type IsUndefined, toHex } from "viem";
10
3
  import type { CreateSessionParams } from "../../isomorphic/actions/createSession.ts";
11
- import { TypeEip7702AuthExtendedFields } from "../../schemas.js";
12
- import type { Static } from "@sinclair/typebox";
4
+ import type { InnerWalletApiClient } from "../../types.ts";
13
5
 
14
6
  export type GrantPermissionsParams<
15
- TAccount extends JsonRpcAccount<Address> | undefined =
16
- | JsonRpcAccount<Address>
17
- | undefined,
7
+ TAccount extends Address | undefined = Address | undefined,
18
8
  > = Omit<CreateSessionParams, "account" | "chainId"> &
19
9
  (IsUndefined<TAccount> extends true
20
10
  ? { account: Address }
@@ -22,7 +12,6 @@ export type GrantPermissionsParams<
22
12
 
23
13
  export type GrantPermissionsResult = {
24
14
  context: Hex;
25
- signedAuthorization?: Static<typeof TypeEip7702AuthExtendedFields>;
26
15
  };
27
16
 
28
17
  /**
@@ -33,14 +22,13 @@ export type GrantPermissionsResult = {
33
22
  * @param {SmartAccountSigner} signer - The signer of the smart account
34
23
  * @param {GrantPermissionsParams} params - The parameters for granting permissions
35
24
  * @param {Address} [params.account] - The account address (required if client was not initialized with an account)
36
- * @param {number} params.expiry - Unix timestamp when the permissions expire
25
+ * @param {number} params.expirySec - Unix timestamp when the permissions expire
37
26
  * @param {object} params.key - The session key information
38
27
  * @param {string} params.key.publicKey - The public key of the session key
39
28
  * @param {string} params.key.type - The type of the key (e.g., "secp256k1")
40
29
  * @param {Array} params.permissions - Array of permission objects defining what the session key can do
41
30
  * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
42
31
  * @returns {Hex} result.context - A hex identifier for the granted permissions context
43
- * @returns {Static<typeof TypeEip7702AuthExtendedFields>} result.signedAuthorization - The EIP-7702 authorization fields, if applicable
44
32
  *
45
33
  * @example
46
34
  * // Create a session key and grant root permissions
@@ -58,7 +46,7 @@ export type GrantPermissionsResult = {
58
46
  * });
59
47
  *
60
48
  * // Use the permissions to prepare a call
61
- * const preparedCall = await client.prepareCalls({
49
+ * const preparedCalls = await client.prepareCalls({
62
50
  * calls: [{ to: zeroAddress, value: "0x0" }],
63
51
  * from: account.address,
64
52
  * capabilities: {
@@ -70,91 +58,35 @@ export type GrantPermissionsResult = {
70
58
  * });
71
59
  *
72
60
  * // Sign with the session key
73
- * const signature = await signSignatureRequest(
61
+ * const signedCalls = await client.signPreparedCalls(
74
62
  * sessionKey,
75
- * preparedCall.signatureRequest,
63
+ * preparedCalls,
76
64
  * );
77
65
  *
78
66
  * // Send the prepared call using the session key
79
67
  * const result = await client.sendPreparedCalls({
80
- * ...preparedCall,
81
- * signature,
82
- * capabilities: {
83
- * permissions,
84
- * },
85
- * });
86
- *
87
- * @example
88
- * // Create a session key and grant root permissions using a 7702 account
89
- * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
90
- * const account = await client.requestAccount({
91
- * creationHint: {
92
- * accountType: "7702",
93
- * }
94
- * });
95
- *
96
- * const permissions = await client.grantPermissions({
97
- * account: account.address,
98
- * expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
99
- * key: {
100
- * publicKey: await sessionKey.getAddress(),
101
- * type: "secp256k1",
102
- * },
103
- * permissions: [{ type: "root" }],
104
- * });
105
- *
106
- * // Use the permissions to prepare a call
107
- * const preparedCall = await client.prepareCalls({
108
- * calls: [{ to: zeroAddress, value: "0x0" }],
109
- * from: account.address,
110
- * capabilities: {
111
- * paymasterService: {
112
- * policyId: "your-paymaster-policy-id",
113
- * },
114
- * permissions,
115
- * },
116
- * });
117
- *
118
- * // Sign with the session key
119
- * // If the 7702 account delegation is not yet installed, the result
120
- * // here will include a `signedAuthorization` field that that
121
- * // must be included when sending the account's first call.
122
- * const { signedAuthorization, ...signature} = await signSignatureRequest(
123
- * sessionKey,
124
- * preparedCall.signatureRequest,
125
- * );
126
- *
127
- * // Send the prepared call using the session key
128
- * const result = await client.sendPreparedCalls({
129
- * ...preparedCall,
130
- * signature,
131
- * signedAuthorization,
68
+ * ...signedCalls,
132
69
  * capabilities: {
133
70
  * permissions,
134
71
  * },
135
72
  * });
136
73
  */
137
74
  export async function grantPermissions<
138
- TAccount extends JsonRpcAccount<Address> | undefined =
139
- | JsonRpcAccount<Address>
140
- | undefined,
75
+ TAccount extends Address | undefined = Address | undefined,
141
76
  >(
142
- client: InnerWalletApiClient<TAccount>,
143
- signer: SmartAccountSigner,
144
- params: GrantPermissionsParams<TAccount>,
145
- ): Promise<GrantPermissionsResult>;
146
-
147
- export async function grantPermissions(
148
77
  client: InnerWalletApiClient,
149
78
  signer: SmartAccountSigner,
150
- params: GrantPermissionsParams,
79
+ params: GrantPermissionsParams<TAccount>,
151
80
  ): Promise<GrantPermissionsResult> {
152
- if (client.account && !params.account) {
153
- params.account = client.account.address;
81
+ const account = params.account ?? client.account?.address;
82
+
83
+ if (!account) {
84
+ throw new AccountNotFoundError();
154
85
  }
155
86
 
156
87
  return client.grantPermissions(signer, {
157
88
  ...params,
89
+ account,
158
90
  chainId: toHex(client.chain.id),
159
91
  });
160
92
  }
@@ -1,9 +1,5 @@
1
- import {
2
- toHex,
3
- type Address,
4
- type IsUndefined,
5
- type JsonRpcAccount,
6
- } from "viem";
1
+ import { AccountNotFoundError } from "@aa-sdk/core";
2
+ import { toHex, type Address, type IsUndefined } from "viem";
7
3
  import type {
8
4
  PrepareCallsParams as IsomorphicPrepareCallsParams,
9
5
  PrepareCallsResult as IsomorphicPrepareCallsResult,
@@ -13,12 +9,10 @@ import type { InnerWalletApiClient } from "../../types.ts";
13
9
  export type GetAccountParam<TAccount> =
14
10
  IsUndefined<TAccount> extends true
15
11
  ? { account: Address }
16
- : { account?: never };
12
+ : { account?: Address };
17
13
 
18
14
  export type PrepareCallsParams<
19
- TAccount extends JsonRpcAccount<Address> | undefined =
20
- | JsonRpcAccount<Address>
21
- | undefined,
15
+ TAccount extends Address | undefined = Address | undefined,
22
16
  > = Omit<IsomorphicPrepareCallsParams, "from" | "chainId"> &
23
17
  (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });
24
18
 
@@ -51,18 +45,17 @@ export type PrepareCallsResult = IsomorphicPrepareCallsResult;
51
45
  * });
52
46
  */
53
47
  export async function prepareCalls<
54
- TAccount extends JsonRpcAccount<Address> | undefined =
55
- | JsonRpcAccount<Address>
56
- | undefined,
48
+ TAccount extends Address | undefined = Address | undefined,
57
49
  >(
58
- client: InnerWalletApiClient<TAccount>,
59
- params: PrepareCallsParams<TAccount>,
60
- ): Promise<PrepareCallsResult>;
61
-
62
- export async function prepareCalls(
63
50
  client: InnerWalletApiClient,
64
- params: PrepareCallsParams,
51
+ params: PrepareCallsParams<TAccount>,
65
52
  ): Promise<PrepareCallsResult> {
53
+ const from = params.from ?? client.account?.address;
54
+
55
+ if (!from) {
56
+ throw new AccountNotFoundError();
57
+ }
58
+
66
59
  if (client.policyId && !params.capabilities?.paymasterService) {
67
60
  params.capabilities = {
68
61
  ...params.capabilities,
@@ -70,12 +63,14 @@ export async function prepareCalls(
70
63
  };
71
64
  }
72
65
 
73
- if (client.account && !params.from) {
74
- params.from = client.account.address;
75
- }
66
+ const params_ = {
67
+ ...params,
68
+ chainId: toHex(client.chain.id),
69
+ from,
70
+ };
76
71
 
77
72
  return await client.request({
78
73
  method: "wallet_prepareCalls",
79
- params: [{ ...params, chainId: toHex(client.chain.id) }],
74
+ params: [params_],
80
75
  });
81
76
  }
@@ -5,27 +5,20 @@ import {
5
5
  import type { Static } from "@sinclair/typebox";
6
6
  import { Value } from "@sinclair/typebox/value";
7
7
  import type { Address } from "abitype";
8
- import { custom, type IsUndefined, type JsonRpcAccount } from "viem";
8
+ import deepEqual from "deep-equal";
9
+ import { custom } from "viem";
9
10
  import { createAccount } from "../../isomorphic/utils/createAccount.js";
10
11
  import type { wallet_requestAccount } from "../../rpc/request.js";
11
12
  import { TypeSerializedInitcode } from "../../schemas.js";
12
13
  import type { InnerWalletApiClient } from "../../types.js";
13
- import deepEqual from "deep-equal";
14
14
 
15
- export type RequestAccountParams<
16
- TAccount extends JsonRpcAccount<Address> | undefined =
17
- | JsonRpcAccount<Address>
18
- | undefined,
19
- > =
20
- IsUndefined<TAccount> extends true
21
- ? Omit<
22
- Extract<
23
- Static<typeof wallet_requestAccount>["Request"]["params"][0],
24
- { signerAddress: Address }
25
- >,
26
- "signerAddress" | "includeCounterfactualInfo"
27
- > & { accountAddress?: Address }
28
- : never;
15
+ export type RequestAccountParams = Omit<
16
+ Extract<
17
+ Static<typeof wallet_requestAccount>["Request"]["params"][0],
18
+ { signerAddress: Address }
19
+ >,
20
+ "signerAddress" | "includeCounterfactualInfo"
21
+ > & { accountAddress?: Address };
29
22
 
30
23
  export type RequestAccountResult = SmartContractAccount;
31
24
 
@@ -46,16 +39,6 @@ export type RequestAccountResult = SmartContractAccount;
46
39
  * const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
47
40
  * const account = await client.requestAccount(signer);
48
41
  */
49
- export function requestAccount<
50
- TAccount extends JsonRpcAccount<Address> | undefined =
51
- | JsonRpcAccount<Address>
52
- | undefined,
53
- >(
54
- client: InnerWalletApiClient<TAccount>,
55
- signer: SmartAccountSigner,
56
- params?: RequestAccountParams<TAccount>,
57
- ): Promise<RequestAccountResult>;
58
-
59
42
  export async function requestAccount(
60
43
  client: InnerWalletApiClient,
61
44
  signer: SmartAccountSigner,
@@ -1,11 +1,12 @@
1
- import type { Static, StaticDecode } from "@sinclair/typebox";
1
+ import type { Static } from "@sinclair/typebox";
2
2
  import { toHex } from "viem";
3
3
  import type { wallet_sendPreparedCalls } from "../../rpc/request.ts";
4
- import type { InnerWalletApiClient } from "../../types.ts";
4
+ import type { InnerWalletApiClient, WithoutChainId } from "../../types.ts";
5
5
 
6
- export type SendPreparedCallsParams = Omit<
7
- StaticDecode<typeof wallet_sendPreparedCalls>["Request"]["params"][0],
8
- "chainId"
6
+ export type SendPreparedCallsParams = WithoutChainId<
7
+ Static<
8
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
9
+ >[0]
9
10
  >;
10
11
 
11
12
  export type SendPreparedCallsResult = Static<
@@ -18,13 +19,6 @@ export type SendPreparedCallsResult = Static<
18
19
  *
19
20
  * @param {InnerWalletApiClient} client - The wallet API client to use for the request
20
21
  * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
21
- * @param {string} params.type - The user operation type ('user-operation-v060' or 'user-operation-v070')
22
- * @param {object} params.data - The user operation data without signature
23
- * @param {string} params.chainId - The chain ID in hex format
24
- * @param {object} params.signature - The signature object
25
- * @param {string} params.signature.type - The signature type (must be 'ecdsa')
26
- * @param {string} params.signature.signature - The hex-encoded signature value
27
- * @param {object} [params.capabilities] - Optional capabilities to include with the request
28
22
  * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
29
23
  *
30
24
  * @example
@@ -40,13 +34,12 @@ export type SendPreparedCallsResult = Static<
40
34
  * }
41
35
  * });
42
36
  *
43
- * // Sign the signature request using signSignatureRequest with your signer
44
- * const signedRequest = await client.signSignatureRequest(preparedCalls.signatureRequest);
37
+ * // Then sign the calls
38
+ * const signedCalls = await client.signPreparedCalls(preparedCalls);
45
39
  *
46
40
  * // Then send the prepared calls with the signature
47
41
  * const result = await client.sendPreparedCalls({
48
- * ...preparedCalls,
49
- * signature: signedRequest.signature,
42
+ * signedCalls,
50
43
  * });
51
44
  */
52
45
  export async function sendPreparedCalls(
@@ -55,6 +48,13 @@ export async function sendPreparedCalls(
55
48
  ): Promise<SendPreparedCallsResult> {
56
49
  return client.request({
57
50
  method: "wallet_sendPreparedCalls",
58
- params: [{ ...params, chainId: toHex(client.chain.id) }],
51
+ params: [
52
+ params.type === "array"
53
+ ? params
54
+ : {
55
+ ...params,
56
+ chainId: toHex(client.chain.id),
57
+ },
58
+ ],
59
59
  });
60
60
  }
@@ -1,10 +1,5 @@
1
- import type { SmartAccountSigner } from "@aa-sdk/core";
2
- import {
3
- type Address,
4
- type Hex,
5
- type JsonRpcAccount,
6
- type SignableMessage,
7
- } from "viem";
1
+ import { type SmartAccountSigner } from "@aa-sdk/core";
2
+ import { type Address, type Hex, type SignableMessage } from "viem";
8
3
  import type { InnerWalletApiClient } from "../../types.ts";
9
4
  import { requestAccount } from "./requestAccount.js";
10
5
 
@@ -29,16 +24,6 @@ export type SignMessageResult = Hex;
29
24
  * // Sign a raw hex message
30
25
  * const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
31
26
  */
32
- export async function signMessage<
33
- TAccount extends JsonRpcAccount<Address> | undefined =
34
- | JsonRpcAccount<Address>
35
- | undefined,
36
- >(
37
- client: InnerWalletApiClient<TAccount>,
38
- signer: SmartAccountSigner,
39
- params: SignMessageParams,
40
- ): Promise<SignMessageResult>;
41
-
42
27
  export async function signMessage(
43
28
  client: InnerWalletApiClient,
44
29
  signer: SmartAccountSigner,
@@ -0,0 +1,71 @@
1
+ import type { PrepareCallsResult } from "./prepareCalls.ts";
2
+ import type { SmartAccountSigner } from "@aa-sdk/core";
3
+ import { signSignatureRequest } from "./signSignatureRequest.js";
4
+ import type { Static } from "@sinclair/typebox";
5
+ import { wallet_sendPreparedCalls } from "../../rpc/request.js";
6
+ import { assertNever } from "../../utils.js";
7
+
8
+ export type SignPreparedCallsParams = PrepareCallsResult;
9
+
10
+ export type SignPreparedCallsResult = Static<
11
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
12
+ >[0];
13
+
14
+ /**
15
+ * Signs prepared calls using the provided signer.
16
+ *
17
+ * @param {SmartAccountSigner} signer - The signer to use
18
+ * @param {SignPreparedCallsParams} params - The prepared calls with signature requests
19
+ * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
20
+ **/
21
+ export async function signPreparedCalls(
22
+ signer: SmartAccountSigner,
23
+ params: SignPreparedCallsParams,
24
+ ): Promise<SignPreparedCallsResult> {
25
+ if (params.type !== "array") {
26
+ const { signatureRequest, ...call } = params;
27
+ const signature = await signSignatureRequest(signer, signatureRequest);
28
+ return {
29
+ ...call,
30
+ signature,
31
+ };
32
+ }
33
+
34
+ return {
35
+ type: "array" as const,
36
+ data: await Promise.all(
37
+ params.data.map(async (call) => {
38
+ switch (call.type) {
39
+ case "authorization": {
40
+ const signature = await signSignatureRequest(signer, {
41
+ type: "eip7702Auth",
42
+ data: {
43
+ ...call.data,
44
+ chainId: call.chainId,
45
+ },
46
+ });
47
+ return {
48
+ ...call,
49
+ signature,
50
+ };
51
+ }
52
+ case "user-operation-v060":
53
+ case "user-operation-v070": {
54
+ const { signatureRequest, ...rest } = call;
55
+ const signature = await signSignatureRequest(
56
+ signer,
57
+ signatureRequest,
58
+ );
59
+ return {
60
+ ...rest,
61
+ signature,
62
+ };
63
+ }
64
+ default: {
65
+ return assertNever(call, "Unexpected call type");
66
+ }
67
+ }
68
+ }),
69
+ ),
70
+ };
71
+ }