@account-kit/wallet-client 0.1.0-alpha.6 → 0.1.0-alpha.8
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.
- package/dist/esm/client/actions/prepareCalls.d.ts +1 -1
- package/dist/esm/client/actions/prepareCalls.js +1 -1
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.js +5 -2
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.js +2 -1
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -2
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +53 -0
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +11 -2
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +21 -14
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +53 -8
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +9 -0
- package/dist/esm/isomorphic/utils/7702.js +21 -8
- package/dist/esm/isomorphic/utils/7702.js.map +1 -1
- package/dist/esm/isomorphic/utils/createAccount.js +73 -33
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
- package/dist/esm/rpc/request.d.ts +12 -2
- package/dist/esm/rpc/schema.d.ts +12 -2
- package/dist/esm/schemas.d.ts +16 -1
- package/dist/esm/schemas.js +12 -1
- package/dist/esm/schemas.js.map +1 -1
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +1 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +3 -2
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +9 -0
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
- package/dist/types/rpc/request.d.ts +12 -2
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +12 -2
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +16 -1
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/client/actions/prepareCalls.ts +1 -1
- package/src/client/actions/requestAccount.ts +10 -8
- package/src/client/actions/signPreparedCalls.ts +2 -1
- package/src/client/actions/signSignatureRequest.ts +4 -2
- package/src/client/client.e2e-test.ts +71 -0
- package/src/isomorphic/actions/createSession.ts +14 -1
- package/src/isomorphic/actions/prepareCalls.ts +22 -13
- package/src/isomorphic/actions/sendPreparedCalls.ts +59 -9
- package/src/isomorphic/utils/7702.ts +25 -9
- package/src/isomorphic/utils/createAccount.ts +81 -34
- package/src/isomorphic/utils/supportsFeature.ts +34 -0
- package/src/schemas.ts +20 -1
- package/src/types.ts +4 -0
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
type Chain,
|
|
7
7
|
type Transport,
|
|
8
8
|
isAddress,
|
|
9
|
+
hexToNumber,
|
|
9
10
|
} from "viem";
|
|
10
11
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
11
12
|
import { PreparedCall_Authorization } from "../../schemas.js";
|
|
12
13
|
import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
|
|
13
14
|
import type { Static } from "@sinclair/typebox";
|
|
14
15
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
16
|
+
import { hashAuthorization } from "viem/utils";
|
|
15
17
|
|
|
16
18
|
export const createAuthorizationRequest = async (
|
|
17
19
|
client: SmartAccountClient<
|
|
@@ -42,6 +44,11 @@ export const createAuthorizationRequest = async (
|
|
|
42
44
|
chainId: numberToHex(client.chain.id),
|
|
43
45
|
signatureRequest: {
|
|
44
46
|
type: "eip7702Auth" as const,
|
|
47
|
+
rawPayload: hashAuthorization({
|
|
48
|
+
chainId: client.chain.id,
|
|
49
|
+
nonce: hexToNumber(data.nonce),
|
|
50
|
+
address: params.delegation,
|
|
51
|
+
}),
|
|
45
52
|
},
|
|
46
53
|
};
|
|
47
54
|
};
|
|
@@ -103,14 +110,23 @@ export const assertValid7702AccountAddress = (
|
|
|
103
110
|
fromAddress: Address,
|
|
104
111
|
eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,
|
|
105
112
|
) => {
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
if (eip7702AuthCapability) {
|
|
114
|
+
if (
|
|
115
|
+
typeof eip7702AuthCapability === "object" &&
|
|
116
|
+
"account" in eip7702AuthCapability &&
|
|
117
|
+
eip7702AuthCapability?.account !== fromAddress
|
|
118
|
+
) {
|
|
119
|
+
throw new InvalidRequestError({
|
|
120
|
+
message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const delegation = parseDelegation(eip7702AuthCapability);
|
|
125
|
+
|
|
126
|
+
if (!isSupportedDelegationAddress7702(delegation)) {
|
|
127
|
+
throw new InvalidRequestError({
|
|
128
|
+
message: `Unsupported 7702 delegation address: ${delegation}`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
115
131
|
}
|
|
116
132
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import {
|
|
3
|
+
createLightAccount,
|
|
3
4
|
createModularAccountV2,
|
|
4
5
|
type ModularAccountV2,
|
|
5
6
|
} from "@account-kit/smart-contracts";
|
|
@@ -10,8 +11,8 @@ import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
|
10
11
|
import { parsePermissionsContext } from "./parsePermissionsContext.js";
|
|
11
12
|
import { assertNever } from "../../utils.js";
|
|
12
13
|
import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
|
|
13
|
-
import { InternalError } from "ox/RpcResponse";
|
|
14
14
|
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
15
|
+
import { InternalError, InvalidRequestError } from "ox/RpcResponse";
|
|
15
16
|
|
|
16
17
|
type CreateAccountParams = {
|
|
17
18
|
chain: Chain;
|
|
@@ -33,32 +34,8 @@ export async function createAccount(
|
|
|
33
34
|
): Promise<SmartContractAccount> {
|
|
34
35
|
const { counterfactualInfo: ci, ...accountParams } = params;
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (mode === "default") {
|
|
39
|
-
if (!ci) {
|
|
40
|
-
throw new InternalError({
|
|
41
|
-
message: "Counterfactual info not found",
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (ci.factoryType !== "MAv2.0.0-sma-b") {
|
|
45
|
-
throw new InternalError({
|
|
46
|
-
message: `Factory type ${ci.factoryType} is not currently supported.`,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
} else if (mode === "7702") {
|
|
50
|
-
const accountType = getAccountTypeForDelegationAddress7702(
|
|
51
|
-
params.delegation!,
|
|
52
|
-
);
|
|
53
|
-
if (accountType !== "ModularAccountV2") {
|
|
54
|
-
throw new InternalError({
|
|
55
|
-
message: "7702 mode currently only supports ModularAccountV2",
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
assertNever(mode, "Unexpected mode in createAccount");
|
|
60
|
-
}
|
|
61
|
-
|
|
37
|
+
// This throws if we pass a permission context and the account is not MA-v2
|
|
38
|
+
// TODO: test that this edge case is handled correctly
|
|
62
39
|
const parsedContext = parsePermissionsContext(
|
|
63
40
|
params.permissions,
|
|
64
41
|
ci,
|
|
@@ -73,14 +50,84 @@ export async function createAccount(
|
|
|
73
50
|
}
|
|
74
51
|
: undefined;
|
|
75
52
|
|
|
76
|
-
|
|
77
|
-
|
|
53
|
+
const mode = params.delegation ? "7702" : "default";
|
|
54
|
+
|
|
55
|
+
if (mode === "7702") {
|
|
56
|
+
const accountType = getAccountTypeForDelegationAddress7702(
|
|
57
|
+
params.delegation!,
|
|
58
|
+
);
|
|
59
|
+
if (accountType !== "ModularAccountV2") {
|
|
60
|
+
throw new Error("7702 mode currently only supports ModularAccountV2");
|
|
61
|
+
}
|
|
62
|
+
return createModularAccountV2({
|
|
63
|
+
...accountParams,
|
|
64
|
+
signerEntity,
|
|
65
|
+
deferredAction: parsedContext?.deferredAction,
|
|
66
|
+
mode,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (mode !== "default") {
|
|
71
|
+
return assertNever(mode, "Unexpected mode in createAccount");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// At this point, we are guaranteed to be in default mode, where ci
|
|
75
|
+
// (counterfactualInfo) must be defined
|
|
76
|
+
|
|
77
|
+
if (!ci) {
|
|
78
|
+
throw new InternalError({
|
|
79
|
+
message: "Counterfactual info not found",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const factoryType = ci.factoryType;
|
|
84
|
+
const commonParams = {
|
|
78
85
|
...accountParams,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
initCode: concatHex([ci.factoryAddress, ci.factoryData]),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Return the account created based on the factory type
|
|
90
|
+
switch (factoryType) {
|
|
91
|
+
case "MAv2.0.0-sma-b":
|
|
92
|
+
return createModularAccountV2({
|
|
93
|
+
...commonParams,
|
|
94
|
+
signerEntity,
|
|
95
|
+
deferredAction: parsedContext?.deferredAction,
|
|
96
|
+
mode,
|
|
97
|
+
});
|
|
98
|
+
case "LightAccountV2.0.0":
|
|
99
|
+
return createLightAccount({
|
|
100
|
+
...commonParams,
|
|
101
|
+
version: "v2.0.0",
|
|
102
|
+
});
|
|
103
|
+
case "LightAccountV1.0.1":
|
|
104
|
+
return createLightAccount({
|
|
105
|
+
...commonParams,
|
|
106
|
+
version: "v1.0.1",
|
|
107
|
+
});
|
|
108
|
+
case "LightAccountV1.0.2":
|
|
109
|
+
return createLightAccount({
|
|
110
|
+
...commonParams,
|
|
111
|
+
version: "v1.0.2",
|
|
112
|
+
});
|
|
113
|
+
case "LightAccountV1.1.0":
|
|
114
|
+
return createLightAccount({
|
|
115
|
+
...commonParams,
|
|
116
|
+
version: "v1.1.0",
|
|
117
|
+
});
|
|
118
|
+
case "LightAccountV2.0.0-MultiOwner":
|
|
119
|
+
case "MAv1.0.0-MultiOwner":
|
|
120
|
+
case "MAv1.0.0-MultiSig":
|
|
121
|
+
case "MAv2.0.0-ma-ssv":
|
|
122
|
+
case "MAv2.0.0-ma-webauthn":
|
|
123
|
+
case "unknown":
|
|
124
|
+
case undefined:
|
|
125
|
+
throw new InvalidRequestError({
|
|
126
|
+
message: `Account type currently unsupported: ${factoryType}`,
|
|
127
|
+
});
|
|
128
|
+
default:
|
|
129
|
+
return assertNever(factoryType, "Unsupported factory type");
|
|
130
|
+
}
|
|
84
131
|
}
|
|
85
132
|
|
|
86
133
|
export function isModularAccountV2(
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
|
+
import type { TypeSerializedInitcode } from "../../schemas.ts";
|
|
3
|
+
|
|
4
|
+
export type Feature = "permissions";
|
|
5
|
+
|
|
6
|
+
type FactoryType = StaticDecode<typeof TypeSerializedInitcode>["factoryType"];
|
|
7
|
+
|
|
8
|
+
const supportedFeatures: Record<FactoryType, Feature[]> = {
|
|
9
|
+
"LightAccountV1.0.1": [],
|
|
10
|
+
"LightAccountV1.0.2": [],
|
|
11
|
+
"LightAccountV1.1.0": [],
|
|
12
|
+
"LightAccountV2.0.0": [],
|
|
13
|
+
"LightAccountV2.0.0-MultiOwner": [],
|
|
14
|
+
"MAv1.0.0-MultiOwner": [],
|
|
15
|
+
"MAv1.0.0-MultiSig": [],
|
|
16
|
+
"MAv2.0.0-sma-b": ["permissions"],
|
|
17
|
+
"MAv2.0.0-ma-ssv": ["permissions"],
|
|
18
|
+
"MAv2.0.0-ma-webauthn": [],
|
|
19
|
+
unknown: [],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function supportsFeature(
|
|
23
|
+
counterfactualInfo: StaticDecode<typeof TypeSerializedInitcode>,
|
|
24
|
+
feature: Feature,
|
|
25
|
+
): boolean {
|
|
26
|
+
const factorySupportedFeatures =
|
|
27
|
+
supportedFeatures[counterfactualInfo.factoryType];
|
|
28
|
+
if (factorySupportedFeatures === undefined) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Unsupported FactoryType: " + counterfactualInfo.factoryType,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return factorySupportedFeatures.includes(feature);
|
|
34
|
+
}
|
package/src/schemas.ts
CHANGED
|
@@ -24,6 +24,20 @@ FormatRegistry.Set("uuid", (value) => UUID_V4_REGEX.test(value));
|
|
|
24
24
|
const BASE_64_URL_REGEX = /^[A-Za-z0-9_-]+$/; // Matches base64url encoded strings (without padding)
|
|
25
25
|
FormatRegistry.Set("base64url", (value) => BASE_64_URL_REGEX.test(value));
|
|
26
26
|
|
|
27
|
+
export const baseAccountTypes = [
|
|
28
|
+
"sma-b",
|
|
29
|
+
"la-v2",
|
|
30
|
+
"la-v1.0.1",
|
|
31
|
+
"la-v1.0.2",
|
|
32
|
+
"la-v1.1.0",
|
|
33
|
+
] as const;
|
|
34
|
+
|
|
35
|
+
export type BaseAccountType = (typeof baseAccountTypes)[number];
|
|
36
|
+
|
|
37
|
+
export const accountTypes = [...baseAccountTypes, "7702"] as const;
|
|
38
|
+
|
|
39
|
+
export type AccountType = (typeof accountTypes)[number];
|
|
40
|
+
|
|
27
41
|
export const TypeHex = (options?: SchemaOptions) =>
|
|
28
42
|
Type.TemplateLiteral("0x${string}", {
|
|
29
43
|
...options,
|
|
@@ -271,7 +285,9 @@ export const TypeCreationOptions = Type.Optional(
|
|
|
271
285
|
Type.Object(
|
|
272
286
|
{
|
|
273
287
|
// Optional b/c `sma-b` is the default if no accountType is specified.
|
|
274
|
-
accountType: Type.Optional(
|
|
288
|
+
accountType: Type.Optional(
|
|
289
|
+
Type.Union(baseAccountTypes.map((lit) => Type.Literal(lit))),
|
|
290
|
+
),
|
|
275
291
|
salt: Type.Optional(TypeHex()),
|
|
276
292
|
},
|
|
277
293
|
{
|
|
@@ -371,6 +387,7 @@ export const TypePersonalSignSignatureRequest = Type.Object(
|
|
|
371
387
|
{ description: "Raw message" },
|
|
372
388
|
),
|
|
373
389
|
]),
|
|
390
|
+
rawPayload: TypeHex(),
|
|
374
391
|
},
|
|
375
392
|
{ description: "Personal sign" },
|
|
376
393
|
);
|
|
@@ -379,6 +396,7 @@ export const TypeTypedDataSignatureRequest = Type.Object(
|
|
|
379
396
|
{
|
|
380
397
|
type: Type.Literal("eth_signTypedData_v4"),
|
|
381
398
|
data: TTypedDataDefinition,
|
|
399
|
+
rawPayload: TypeHex(),
|
|
382
400
|
},
|
|
383
401
|
{
|
|
384
402
|
description: "Typed data",
|
|
@@ -387,6 +405,7 @@ export const TypeTypedDataSignatureRequest = Type.Object(
|
|
|
387
405
|
|
|
388
406
|
export const TypeAuthorizationSignatureRequest = Type.Object({
|
|
389
407
|
type: Type.Literal("eip7702Auth"),
|
|
408
|
+
rawPayload: TypeHex(),
|
|
390
409
|
});
|
|
391
410
|
|
|
392
411
|
export const TypeSignatureRequest = Type.Union([
|
package/src/types.ts
CHANGED