@account-kit/wallet-client 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (67) hide show
  1. package/dist/esm/capabilities/index.d.ts +3 -0
  2. package/dist/esm/capabilities/index.js +2 -0
  3. package/dist/esm/capabilities/index.js.map +1 -1
  4. package/dist/esm/capabilities/multiDimensionalNonce.d.ts +3 -0
  5. package/dist/esm/capabilities/multiDimensionalNonce.js +7 -0
  6. package/dist/esm/capabilities/multiDimensionalNonce.js.map +1 -0
  7. package/dist/esm/client/actions/signPreparedCalls.js +26 -37
  8. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
  9. package/dist/esm/exports/internal.d.ts +1 -0
  10. package/dist/esm/exports/internal.js +1 -0
  11. package/dist/esm/exports/internal.js.map +1 -1
  12. package/dist/esm/isomorphic/actions/createSession.js +9 -3
  13. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  14. package/dist/esm/isomorphic/actions/prepareCalls.js +19 -4
  15. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  16. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +13 -4
  17. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  18. package/dist/esm/isomorphic/utils/7702.d.ts +6 -1
  19. package/dist/esm/isomorphic/utils/7702.js +5 -4
  20. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  21. package/dist/esm/isomorphic/utils/createAccount.d.ts +1 -0
  22. package/dist/esm/isomorphic/utils/createAccount.js +25 -3
  23. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  24. package/dist/esm/rpc/request.d.ts +46 -2
  25. package/dist/esm/rpc/request.js +1 -0
  26. package/dist/esm/rpc/request.js.map +1 -1
  27. package/dist/esm/rpc/schema.d.ts +46 -2
  28. package/dist/esm/schemas.d.ts +23 -4
  29. package/dist/esm/schemas.js +46 -2
  30. package/dist/esm/schemas.js.map +1 -1
  31. package/dist/esm/utils.d.ts +1 -0
  32. package/dist/esm/utils.js.map +1 -1
  33. package/dist/types/capabilities/index.d.ts +3 -0
  34. package/dist/types/capabilities/index.d.ts.map +1 -1
  35. package/dist/types/capabilities/multiDimensionalNonce.d.ts +4 -0
  36. package/dist/types/capabilities/multiDimensionalNonce.d.ts.map +1 -0
  37. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
  38. package/dist/types/exports/internal.d.ts +1 -0
  39. package/dist/types/exports/internal.d.ts.map +1 -1
  40. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  41. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  42. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  43. package/dist/types/isomorphic/utils/7702.d.ts +6 -1
  44. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  45. package/dist/types/isomorphic/utils/createAccount.d.ts +1 -0
  46. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  47. package/dist/types/rpc/request.d.ts +46 -2
  48. package/dist/types/rpc/request.d.ts.map +1 -1
  49. package/dist/types/rpc/schema.d.ts +46 -2
  50. package/dist/types/rpc/schema.d.ts.map +1 -1
  51. package/dist/types/schemas.d.ts +23 -4
  52. package/dist/types/schemas.d.ts.map +1 -1
  53. package/dist/types/utils.d.ts +1 -0
  54. package/dist/types/utils.d.ts.map +1 -1
  55. package/package.json +5 -5
  56. package/src/capabilities/index.ts +2 -0
  57. package/src/capabilities/multiDimensionalNonce.ts +7 -0
  58. package/src/client/actions/signPreparedCalls.ts +42 -43
  59. package/src/exports/internal.ts +1 -0
  60. package/src/isomorphic/actions/createSession.ts +11 -3
  61. package/src/isomorphic/actions/prepareCalls.ts +27 -9
  62. package/src/isomorphic/actions/sendPreparedCalls.ts +14 -4
  63. package/src/isomorphic/utils/7702.ts +16 -5
  64. package/src/isomorphic/utils/createAccount.ts +35 -2
  65. package/src/rpc/request.ts +1 -0
  66. package/src/schemas.ts +77 -5
  67. package/src/utils.ts +2 -0
@@ -85,6 +85,12 @@ export async function sendPreparedCalls(
85
85
  })
86
86
  : [params];
87
87
 
88
+ if (!userOps.length) {
89
+ throw new InvalidRequestError({
90
+ message: "Calls must include at least one user operation",
91
+ });
92
+ }
93
+
88
94
  const authorizations =
89
95
  params.type === "array"
90
96
  ? params.data.filter((it) => it.type === "authorization")
@@ -147,10 +153,12 @@ export async function sendPreparedCalls(
147
153
  case "LightAccountV1.0.1":
148
154
  case "LightAccountV1.0.2":
149
155
  case "LightAccountV1.1.0":
150
- // For LAv1, we always just pass the signature.
156
+ case "MAv1.0.0-MultiOwner":
157
+ // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
151
158
  return uoSigHex;
152
159
  case "LightAccountV2.0.0":
153
- // for LAv2, we need to prepend the "SignatureType.EOA" byte
160
+ // for LAv2, we need to prepend the "SignatureType.EOA" byte.
161
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
154
162
  return concat(["0x00", uoSigHex]);
155
163
  case undefined: // undefined defaults to sma-b
156
164
  case "MAv2.0.0-sma-b":
@@ -164,10 +172,12 @@ export async function sendPreparedCalls(
164
172
  uoSigHex,
165
173
  ])
166
174
  : concat(["0xFF", "0x00", uoSigHex]);
175
+ case "LightAccountV2.0.0-MultiOwner":
176
+ // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
177
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
178
+ return concat(["0x00", uoSigHex]);
167
179
  case "MAv2.0.0-ma-ssv":
168
180
  case "MAv2.0.0-ma-webauthn":
169
- case "LightAccountV2.0.0-MultiOwner":
170
- case "MAv1.0.0-MultiOwner":
171
181
  case "MAv1.0.0-MultiSig":
172
182
  case "unknown":
173
183
  throw new InvalidRequestError({
@@ -15,7 +15,8 @@ import type { Static } from "@sinclair/typebox";
15
15
  import { InvalidRequestError } from "ox/RpcResponse";
16
16
  import { hashAuthorization } from "viem/utils";
17
17
 
18
- export const createAuthorizationRequest = async (
18
+ /** Checks if an address is actively delegated on-chain. */
19
+ export const isDelegated = async (
19
20
  client: SmartAccountClient<
20
21
  Transport,
21
22
  Chain,
@@ -24,12 +25,22 @@ export const createAuthorizationRequest = async (
24
25
  WalletServerViemRpcSchema
25
26
  >,
26
27
  params: { address: Address; delegation: Address },
27
- ): Promise<Static<typeof PreparedCall_Authorization> | undefined> => {
28
+ ): Promise<boolean> => {
28
29
  const expectedCode = concatHex(["0xef0100", params.delegation]);
29
30
  const code = (await client.getCode({ address: params.address })) ?? "0x";
30
- if (code.toLowerCase() === expectedCode.toLowerCase()) {
31
- return undefined; // Already authorized.
32
- }
31
+ return code.toLowerCase() === expectedCode.toLowerCase();
32
+ };
33
+
34
+ export const createAuthorizationRequest = async (
35
+ client: SmartAccountClient<
36
+ Transport,
37
+ Chain,
38
+ SmartContractAccount | undefined,
39
+ Record<string, unknown>,
40
+ WalletServerViemRpcSchema
41
+ >,
42
+ params: { address: Address; delegation: Address },
43
+ ): Promise<Static<typeof PreparedCall_Authorization>> => {
33
44
  const data = {
34
45
  address: params.delegation,
35
46
  nonce: numberToHex(
@@ -2,11 +2,13 @@ import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
2
2
  import {
3
3
  createLightAccount,
4
4
  createModularAccountV2,
5
+ createMultiOwnerLightAccount,
6
+ createMultiOwnerModularAccount,
5
7
  type ModularAccountV2,
6
8
  } from "@account-kit/smart-contracts";
7
9
  import type { StaticDecode } from "@sinclair/typebox";
8
10
  import type { Address, Chain, Transport } from "viem";
9
- import { concatHex, hexToNumber } from "viem";
11
+ import { concatHex, hexToBigInt, hexToNumber, zeroAddress } from "viem";
10
12
  import type { TypeSerializedInitcode } from "../../schemas.js";
11
13
  import { parsePermissionsContext } from "./parsePermissionsContext.js";
12
14
  import { assertNever } from "../../utils.js";
@@ -115,8 +117,15 @@ export async function createAccount(
115
117
  ...commonParams,
116
118
  version: "v1.1.0",
117
119
  });
118
- case "LightAccountV2.0.0-MultiOwner":
119
120
  case "MAv1.0.0-MultiOwner":
121
+ return createMultiOwnerModularAccount({
122
+ ...commonParams,
123
+ });
124
+ case "LightAccountV2.0.0-MultiOwner":
125
+ return createMultiOwnerLightAccount({
126
+ ...commonParams,
127
+ version: "v2.0.0",
128
+ });
120
129
  case "MAv1.0.0-MultiSig":
121
130
  case "MAv2.0.0-ma-ssv":
122
131
  case "MAv2.0.0-ma-webauthn":
@@ -135,3 +144,27 @@ export function isModularAccountV2(
135
144
  ): account is ModularAccountV2 {
136
145
  return account.source === "ModularAccountV2";
137
146
  }
147
+
148
+ // Performs basic checks on the initialOwners array and returns a new array with the signer address added if not present.
149
+ // Pulled from MAv1 support in Account Kit.
150
+ export function prepareInitialOwners(
151
+ initialOwners: Address[],
152
+ signerAddress: Address,
153
+ ): Address[] {
154
+ const preparedOwners = Array.from(
155
+ new Set([...initialOwners, signerAddress]),
156
+ ).sort((a, b) => {
157
+ const bigintA = hexToBigInt(a);
158
+ const bigintB = hexToBigInt(b);
159
+
160
+ return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;
161
+ });
162
+
163
+ if (preparedOwners.some((x) => x === zeroAddress)) {
164
+ throw new InvalidRequestError({
165
+ message: "Initial owners cannot contain the zero address",
166
+ });
167
+ }
168
+
169
+ return preparedOwners;
170
+ }
@@ -218,6 +218,7 @@ export const wallet_createSession = Type.Object(
218
218
  }),
219
219
  ReturnType: Type.Object({
220
220
  sessionId: TypeHex(),
221
+ chainId: TypeHex(),
221
222
  signatureRequest: TypeTypedDataSignatureRequest,
222
223
  }),
223
224
  },
package/src/schemas.ts CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  parseSignature,
17
17
  numberToHex,
18
18
  } from "viem";
19
+ import type { Expect } from "./utils.ts";
19
20
 
20
21
  const UUID_V4_REGEX =
21
22
  /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
@@ -27,9 +28,11 @@ FormatRegistry.Set("base64url", (value) => BASE_64_URL_REGEX.test(value));
27
28
  export const baseAccountTypes = [
28
29
  "sma-b",
29
30
  "la-v2",
31
+ "la-v2-multi-owner",
30
32
  "la-v1.0.1",
31
33
  "la-v1.0.2",
32
34
  "la-v1.1.0",
35
+ "ma-v1-multi-owner",
33
36
  ] as const;
34
37
 
35
38
  export type BaseAccountType = (typeof baseAccountTypes)[number];
@@ -285,13 +288,77 @@ export const TypeCreationOptions = Type.Optional(
285
288
  Type.Object(
286
289
  {
287
290
  // Optional b/c `sma-b` is the default if no accountType is specified.
288
- accountType: Type.Optional(
289
- Type.Union(baseAccountTypes.map((lit) => Type.Literal(lit))),
291
+ accountType: Type.Optional(Type.Literal("sma-b")),
292
+ salt: Type.Optional(TypeHex()),
293
+ },
294
+ {
295
+ description: "Modular Account V2 SMA-B account type",
296
+ },
297
+ ),
298
+ Type.Object(
299
+ {
300
+ accountType: Type.Literal("la-v2"),
301
+ salt: Type.Optional(TypeHex()),
302
+ },
303
+ {
304
+ description: "Light Account V2 account type",
305
+ },
306
+ ),
307
+ Type.Object(
308
+ {
309
+ accountType: Type.Literal("la-v2-multi-owner"),
310
+ salt: Type.Optional(TypeHex()),
311
+ initialOwners: Type.Optional(
312
+ Type.Array(TypeAddress, {
313
+ description:
314
+ "The initial owners of the account. The signer address will be implicitly added if not specified in this list.",
315
+ }),
290
316
  ),
317
+ },
318
+ {
319
+ description: "Light Account V2 Multi-Owner account type",
320
+ },
321
+ ),
322
+ Type.Object(
323
+ {
324
+ accountType: Type.Literal("la-v1.0.1"),
325
+ salt: Type.Optional(TypeHex()),
326
+ },
327
+ {
328
+ description: "Light Account V1.0.1 account type",
329
+ },
330
+ ),
331
+ Type.Object(
332
+ {
333
+ accountType: Type.Literal("la-v1.0.2"),
334
+ salt: Type.Optional(TypeHex()),
335
+ },
336
+ {
337
+ description: "Light Account V1.0.2 account type",
338
+ },
339
+ ),
340
+ Type.Object(
341
+ {
342
+ accountType: Type.Literal("la-v1.1.0"),
291
343
  salt: Type.Optional(TypeHex()),
292
344
  },
293
345
  {
294
- description: "SMA-B account type",
346
+ description: "Light Account V1.1.0 account type",
347
+ },
348
+ ),
349
+ Type.Object(
350
+ {
351
+ accountType: Type.Literal("ma-v1-multi-owner"),
352
+ salt: Type.Optional(TypeHex()),
353
+ initialOwners: Type.Optional(
354
+ Type.Array(TypeAddress, {
355
+ description:
356
+ "The initial owners of the account. The signer address will be implicitly added if not specified in this list.",
357
+ }),
358
+ ),
359
+ },
360
+ {
361
+ description: "Modular Account V1 Multi-Owner account type",
295
362
  },
296
363
  ),
297
364
  Type.Object(
@@ -311,10 +378,15 @@ export const TypeCreationOptions = Type.Optional(
311
378
  );
312
379
  export type TypeCreationOptions = Static<typeof TypeCreationOptions>;
313
380
 
314
- export type TypeAccountType = Exclude<
381
+ type BaseAccountTypeExhaustive = BaseAccountType extends Exclude<
315
382
  Static<typeof TypeCreationOptions>,
316
383
  undefined
317
- >["accountType"];
384
+ >["accountType"]
385
+ ? true
386
+ : "BaseAccountType values not fully covered in TypeCreationOptions";
387
+
388
+ // Compile-time assertion that TypeCreationOptions covers all BaseAccountType values.
389
+ type _AssertBaseAccountTypeExhaustive = Expect<BaseAccountTypeExhaustive>;
318
390
 
319
391
  export const TypeSignatureType = Type.Union([
320
392
  Type.Literal("secp256k1", { description: "Secp256k1" }),
package/src/utils.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { isHex, toHex, type Hex } from "viem";
2
2
 
3
+ export type Expect<T extends true> = T;
4
+
3
5
  export const assertNever = (_val: never, msg: string): never => {
4
6
  throw new Error(msg);
5
7
  };