@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.3
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/capabilities/index.d.ts +5 -2
- package/dist/esm/capabilities/index.js +1 -1
- package/dist/esm/capabilities/index.js.map +1 -1
- package/dist/esm/capabilities/overrides.js +8 -8
- package/dist/esm/capabilities/overrides.js.map +1 -1
- package/dist/esm/capabilities/permissions/index.d.ts +10 -3
- package/dist/esm/capabilities/permissions/index.js +11 -2
- package/dist/esm/capabilities/permissions/index.js.map +1 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +3 -3
- package/dist/esm/capabilities/permissions/mav2.js +9 -1
- package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
- package/dist/esm/client/actions/createAccount.d.ts +27 -2
- package/dist/esm/client/actions/createAccount.js +25 -0
- package/dist/esm/client/actions/createAccount.js.map +1 -1
- package/dist/esm/client/actions/getCallsStatus.d.ts +21 -2
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +114 -2
- package/dist/esm/client/actions/grantPermissions.js +1 -0
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +26 -2
- package/dist/esm/client/actions/listAccounts.js +24 -0
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +28 -2
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.d.ts +21 -2
- package/dist/esm/client/actions/requestAccount.js +15 -4
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +39 -2
- package/dist/esm/client/actions/sendPreparedCalls.js +37 -0
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +22 -2
- package/dist/esm/client/actions/signMessage.js +4 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +34 -0
- package/dist/esm/client/actions/signSignatureRequest.js +22 -1
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +35 -2
- package/dist/esm/client/actions/signTypedData.js +3 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +112 -30
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +7 -5
- package/dist/esm/client/decorator.js +1 -1
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +4 -4
- package/dist/esm/client/index.js +29 -3
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +1 -0
- package/dist/esm/exports/index.js +1 -0
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +1 -1
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/internal/decorator.d.ts +2 -0
- package/dist/esm/internal/decorator.js +10 -0
- package/dist/esm/internal/decorator.js.map +1 -0
- package/dist/esm/isomorphic/actions/createSession.js +25 -7
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +35 -12
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +26 -6
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +11 -5
- package/dist/esm/isomorphic/utils/7702.d.ts +11 -0
- package/dist/esm/isomorphic/utils/7702.js +26 -0
- package/dist/esm/isomorphic/utils/7702.js.map +1 -0
- package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -1
- package/dist/esm/isomorphic/utils/createAccount.js +30 -5
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +17 -5
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
- package/dist/esm/local/client.d.ts +1 -1
- package/dist/esm/local/client.js +10 -2
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +1 -1
- package/dist/esm/remote/client.js +12 -3
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/examples.d.ts +230 -0
- package/dist/esm/rpc/examples.js +314 -0
- package/dist/esm/rpc/examples.js.map +1 -0
- package/dist/esm/rpc/request.d.ts +48 -17
- package/dist/esm/rpc/request.js +53 -14
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +43 -12
- package/dist/esm/schemas.d.ts +29 -7
- package/dist/esm/schemas.js +120 -38
- package/dist/esm/schemas.js.map +1 -1
- package/dist/esm/types.d.ts +15 -4
- package/dist/esm/types.js.map +1 -1
- package/dist/types/capabilities/index.d.ts +5 -2
- package/dist/types/capabilities/index.d.ts.map +1 -1
- package/dist/types/capabilities/overrides.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/index.d.ts +10 -3
- package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +3 -3
- package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
- package/dist/types/client/actions/createAccount.d.ts +27 -2
- package/dist/types/client/actions/createAccount.d.ts.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +21 -2
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +114 -2
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +26 -2
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +28 -2
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts +21 -2
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +39 -2
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +22 -2
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +34 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +35 -2
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +7 -5
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +4 -4
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +1 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +1 -1
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/internal/decorator.d.ts +3 -0
- package/dist/types/internal/decorator.d.ts.map +1 -0
- 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 +11 -5
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +12 -0
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/createAccount.d.ts +2 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
- package/dist/types/local/client.d.ts +1 -1
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +1 -1
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/examples.d.ts +231 -0
- package/dist/types/rpc/examples.d.ts.map +1 -0
- package/dist/types/rpc/request.d.ts +48 -17
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +43 -12
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +29 -7
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/types.d.ts +15 -4
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/capabilities/index.ts +5 -8
- package/src/capabilities/overrides.ts +23 -8
- package/src/capabilities/permissions/index.ts +21 -5
- package/src/capabilities/permissions/mav2.ts +13 -3
- package/src/client/actions/createAccount.ts +27 -2
- package/src/client/actions/getCallsStatus.ts +21 -2
- package/src/client/actions/grantPermissions.ts +114 -2
- package/src/client/actions/listAccounts.ts +26 -2
- package/src/client/actions/prepareCalls.ts +28 -2
- package/src/client/actions/requestAccount.ts +41 -7
- package/src/client/actions/sendPreparedCalls.ts +39 -2
- package/src/client/actions/signMessage.ts +24 -4
- package/src/client/actions/signSignatureRequest.ts +61 -2
- package/src/client/actions/signTypedData.ts +39 -3
- package/src/client/client.e2e-test.ts +134 -32
- package/src/client/decorator.ts +10 -12
- package/src/client/index.ts +41 -10
- package/src/exports/index.ts +1 -0
- package/src/exports/internal.ts +1 -1
- package/src/internal/decorator.ts +12 -0
- package/src/isomorphic/actions/createSession.ts +28 -7
- package/src/isomorphic/actions/prepareCalls.ts +38 -11
- package/src/isomorphic/actions/sendPreparedCalls.ts +47 -20
- package/src/isomorphic/utils/7702.ts +58 -0
- package/src/isomorphic/utils/createAccount.ts +38 -6
- package/src/isomorphic/utils/createDummySigner.ts +3 -2
- package/src/isomorphic/utils/parsePermissionsContext.ts +23 -7
- package/src/local/client.ts +54 -45
- package/src/remote/client.ts +22 -7
- package/src/rpc/examples.ts +343 -0
- package/src/rpc/request.ts +75 -26
- package/src/schemas.ts +218 -87
- package/src/types.ts +18 -4
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
7
7
|
import { Value } from "@sinclair/typebox/value";
|
|
8
8
|
import {
|
|
9
|
+
BaseError,
|
|
9
10
|
ChainNotFoundError,
|
|
10
11
|
concat,
|
|
11
12
|
concatHex,
|
|
@@ -18,6 +19,8 @@ import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js
|
|
|
18
19
|
import type { wallet_sendPreparedCalls } from "../../rpc/request.js";
|
|
19
20
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
20
21
|
import { TypeCallId } from "../../schemas.js";
|
|
22
|
+
import { isSupportedImplementationAddress7702 } from "../utils/7702.js";
|
|
23
|
+
import { InvalidRequestError } from "ox/RpcResponse";
|
|
21
24
|
|
|
22
25
|
export type SendPreparedCallsParams = Omit<
|
|
23
26
|
StaticDecode<
|
|
@@ -45,19 +48,30 @@ export async function sendPreparedCalls(
|
|
|
45
48
|
throw new ChainNotFoundError();
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
52
|
+
if (
|
|
53
|
+
params.signedAuthorization &&
|
|
54
|
+
!isSupportedImplementationAddress7702(params.signedAuthorization.address)
|
|
55
|
+
) {
|
|
56
|
+
throw new InvalidRequestError({
|
|
57
|
+
message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
48
61
|
const deferredAction: Hex | undefined = (() => {
|
|
49
|
-
if (!params.capabilities?.permissions
|
|
62
|
+
if (!params.capabilities?.permissions) {
|
|
50
63
|
return;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
const decodedContext = decodePermissionsContext(
|
|
54
|
-
params.capabilities.permissions
|
|
67
|
+
params.capabilities.permissions,
|
|
55
68
|
);
|
|
56
69
|
|
|
57
70
|
if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
58
|
-
throw new
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
throw new InvalidRequestError({
|
|
72
|
+
message:
|
|
73
|
+
"Remote mode deferred action not supported in isomorphic client",
|
|
74
|
+
});
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
return decodedContext.deferredAction;
|
|
@@ -68,21 +82,34 @@ export async function sendPreparedCalls(
|
|
|
68
82
|
? getEntryPoint(client.chain, { version: "0.6.0" })
|
|
69
83
|
: getEntryPoint(client.chain, { version: "0.7.0" });
|
|
70
84
|
|
|
71
|
-
const hash = await client
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
const hash = await client
|
|
86
|
+
.sendRawUserOperation(
|
|
87
|
+
{
|
|
88
|
+
...params.data,
|
|
89
|
+
signature:
|
|
90
|
+
deferredAction != null
|
|
91
|
+
? concatHex([
|
|
92
|
+
`0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).
|
|
93
|
+
"0xff",
|
|
94
|
+
"0x00",
|
|
95
|
+
params.signature.signature,
|
|
96
|
+
])
|
|
97
|
+
: concat(["0xFF", "0x00", params.signature.signature]),
|
|
98
|
+
eip7702Auth: params.signedAuthorization,
|
|
99
|
+
},
|
|
100
|
+
entryPoint.address,
|
|
101
|
+
)
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
if (
|
|
104
|
+
err instanceof BaseError &&
|
|
105
|
+
err.details.endsWith("is not a contract and initCode is empty")
|
|
106
|
+
) {
|
|
107
|
+
throw new BaseError(
|
|
108
|
+
`${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
throw err;
|
|
112
|
+
});
|
|
86
113
|
|
|
87
114
|
const callId = Value.Encode(TypeCallId, {
|
|
88
115
|
chainId: toHex(client.chain.id),
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import {
|
|
3
|
+
concatHex,
|
|
4
|
+
type Authorization,
|
|
5
|
+
type Address,
|
|
6
|
+
type Chain,
|
|
7
|
+
type Transport,
|
|
8
|
+
} from "viem";
|
|
9
|
+
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
10
|
+
|
|
11
|
+
export const createAuthorization = async (
|
|
12
|
+
client: SmartAccountClient<
|
|
13
|
+
Transport,
|
|
14
|
+
Chain,
|
|
15
|
+
SmartContractAccount | undefined,
|
|
16
|
+
Record<string, unknown>,
|
|
17
|
+
WalletServerViemRpcSchema
|
|
18
|
+
>,
|
|
19
|
+
params: { address: Address; delegation: Address },
|
|
20
|
+
): Promise<Authorization<number, false> | undefined> => {
|
|
21
|
+
const expectedCode = concatHex(["0xef0100", params.delegation]);
|
|
22
|
+
const code = (await client.getCode({ address: params.address })) ?? "0x";
|
|
23
|
+
if (code.toLowerCase() === expectedCode.toLowerCase()) {
|
|
24
|
+
return undefined; // Already authorized.
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
chainId: client.chain.id,
|
|
28
|
+
address: params.delegation,
|
|
29
|
+
nonce: await client.getTransactionCount({
|
|
30
|
+
address: params.address,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Supported7702AccountType = "ModularAccountV2";
|
|
36
|
+
|
|
37
|
+
const IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE: Record<
|
|
38
|
+
Address,
|
|
39
|
+
Supported7702AccountType
|
|
40
|
+
> = {
|
|
41
|
+
"0x69007702764179f14F51cdce752f4f775d74E139": "ModularAccountV2",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getAccountTypeForImplementationAddress7702 = (
|
|
45
|
+
address: Address,
|
|
46
|
+
): Supported7702AccountType | undefined => {
|
|
47
|
+
return IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE[address];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const SUPPORTED_IMPLEMENTATION_ADDRESSES = Object.keys(
|
|
51
|
+
IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const isSupportedImplementationAddress7702 = (
|
|
55
|
+
address: string,
|
|
56
|
+
): boolean => {
|
|
57
|
+
return SUPPORTED_IMPLEMENTATION_ADDRESSES.includes(address);
|
|
58
|
+
};
|
|
@@ -9,13 +9,17 @@ import { concatHex, hexToNumber } from "viem";
|
|
|
9
9
|
import type { Capabilities } from "../../capabilities/index.js";
|
|
10
10
|
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
11
11
|
import { parsePermissionsContext } from "./parsePermissionsContext.js";
|
|
12
|
+
import { assertNever } from "../../utils.js";
|
|
13
|
+
import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
|
|
14
|
+
import { InternalError } from "ox/RpcResponse";
|
|
12
15
|
|
|
13
16
|
type CreateAccountParams = {
|
|
14
17
|
chain: Chain;
|
|
15
18
|
transport: Transport;
|
|
16
19
|
signer: SmartAccountSigner;
|
|
17
20
|
accountAddress: Address;
|
|
18
|
-
counterfactualInfo
|
|
21
|
+
counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts
|
|
22
|
+
delegation?: Address;
|
|
19
23
|
capabilities?: StaticDecode<typeof Capabilities>;
|
|
20
24
|
};
|
|
21
25
|
|
|
@@ -28,12 +32,38 @@ export async function createAccount(
|
|
|
28
32
|
params: CreateAccountParams,
|
|
29
33
|
): Promise<SmartContractAccount> {
|
|
30
34
|
const { counterfactualInfo: ci, ...accountParams } = params;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
|
|
36
|
+
const mode = params.delegation ? "7702" : "default";
|
|
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 = getAccountTypeForImplementationAddress7702(
|
|
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");
|
|
34
60
|
}
|
|
35
61
|
|
|
36
|
-
const parsedContext = parsePermissionsContext(
|
|
62
|
+
const parsedContext = parsePermissionsContext(
|
|
63
|
+
params.capabilities,
|
|
64
|
+
ci,
|
|
65
|
+
params.delegation,
|
|
66
|
+
);
|
|
37
67
|
|
|
38
68
|
const signerEntity =
|
|
39
69
|
parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
|
|
@@ -43,11 +73,13 @@ export async function createAccount(
|
|
|
43
73
|
}
|
|
44
74
|
: undefined;
|
|
45
75
|
|
|
76
|
+
// TODO: clean this up to support different account types.
|
|
46
77
|
return createModularAccountV2({
|
|
47
78
|
...accountParams,
|
|
48
79
|
signerEntity,
|
|
49
80
|
deferredAction: parsedContext?.deferredAction,
|
|
50
|
-
initCode: concatHex([ci.factoryAddress, ci.factoryData]),
|
|
81
|
+
initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,
|
|
82
|
+
mode,
|
|
51
83
|
});
|
|
52
84
|
}
|
|
53
85
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { TypedData } from "abitype";
|
|
3
3
|
import {
|
|
4
|
+
BaseError,
|
|
4
5
|
type Address,
|
|
5
6
|
type Hex,
|
|
6
7
|
type SignableMessage,
|
|
@@ -15,12 +16,12 @@ export const createDummySigner = (address: Address): SmartAccountSigner => ({
|
|
|
15
16
|
},
|
|
16
17
|
// Not supported on the server
|
|
17
18
|
signMessage: function (_message: SignableMessage): Promise<Hex> {
|
|
18
|
-
throw new
|
|
19
|
+
throw new BaseError("signMessage not implemented by dummy signer.");
|
|
19
20
|
},
|
|
20
21
|
signTypedData: function <
|
|
21
22
|
const TTypedData extends TypedData | Record<string, unknown>,
|
|
22
23
|
TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData,
|
|
23
24
|
>(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {
|
|
24
|
-
throw new
|
|
25
|
+
throw new BaseError("signTypedData not implemented by dummy signer.");
|
|
25
26
|
},
|
|
26
27
|
});
|
|
@@ -3,25 +3,41 @@ import { InvalidRequestError } from "ox/RpcResponse";
|
|
|
3
3
|
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
4
4
|
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
5
5
|
import type { PrepareCallsParams } from "../actions/prepareCalls.js";
|
|
6
|
+
import type { Address } from "viem";
|
|
7
|
+
import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
|
|
6
8
|
|
|
7
9
|
export function parsePermissionsContext(
|
|
8
10
|
capabilities: PrepareCallsParams["capabilities"],
|
|
9
|
-
parsedCi: StaticDecode<typeof TypeSerializedInitcode
|
|
11
|
+
parsedCi: StaticDecode<typeof TypeSerializedInitcode> | undefined,
|
|
12
|
+
delegation7702?: Address,
|
|
10
13
|
) {
|
|
11
|
-
if (!capabilities?.permissions
|
|
14
|
+
if (!capabilities?.permissions) {
|
|
12
15
|
return undefined;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
if ("sessionId" in capabilities.permissions) {
|
|
19
|
+
throw new InvalidRequestError({
|
|
20
|
+
message: "Remote permissions are not supported in isomorphic client",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!("context" in capabilities.permissions)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isMAV2 =
|
|
29
|
+
(parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
|
|
30
|
+
(delegation7702 &&
|
|
31
|
+
getAccountTypeForImplementationAddress7702(delegation7702) ===
|
|
32
|
+
"ModularAccountV2");
|
|
33
|
+
|
|
34
|
+
if (!isMAV2) {
|
|
19
35
|
throw new InvalidRequestError({
|
|
20
36
|
message: "Permissions are currently only supported by MAv2 accounts",
|
|
21
37
|
});
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
const context = decodePermissionsContext(capabilities.permissions
|
|
40
|
+
const context = decodePermissionsContext(capabilities.permissions);
|
|
25
41
|
|
|
26
42
|
if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
27
43
|
throw new InvalidRequestError({
|
package/src/local/client.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
prefixSignatureKeyType,
|
|
7
7
|
} from "../capabilities/permissions/mav2.js";
|
|
8
8
|
import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
9
|
-
import
|
|
9
|
+
import { internalStateDecorator } from "../internal/decorator.js";
|
|
10
|
+
import type { PrepareCallsParams } from "../isomorphic/actions/prepareCalls.ts";
|
|
10
11
|
import {
|
|
11
12
|
createIsomorphicClient,
|
|
12
13
|
type IsomorphicClient,
|
|
@@ -15,7 +16,7 @@ import type {
|
|
|
15
16
|
CreateInnerClientParams,
|
|
16
17
|
InnerClientActions,
|
|
17
18
|
InnerWalletApiClient,
|
|
18
|
-
} from "../types";
|
|
19
|
+
} from "../types.ts";
|
|
19
20
|
import { assertNever } from "../utils.js";
|
|
20
21
|
|
|
21
22
|
const localMethods = [
|
|
@@ -51,46 +52,51 @@ export function createLocalClient(
|
|
|
51
52
|
overrides: [
|
|
52
53
|
{
|
|
53
54
|
methods: localMethods,
|
|
54
|
-
transport: custom(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
transport: custom(
|
|
56
|
+
{
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
async request(args: { method: LocalMethod; params: any }) {
|
|
59
|
+
switch (args.method) {
|
|
60
|
+
case "wallet_prepareCalls": {
|
|
61
|
+
const params = args.params[0] as PrepareCallsParams;
|
|
62
|
+
const capabilityPolicyId =
|
|
63
|
+
params.capabilities?.paymasterService?.policyId;
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
if (
|
|
66
|
+
capabilityPolicyId != null &&
|
|
67
|
+
policyId !== capabilityPolicyId &&
|
|
68
|
+
!clientMap[capabilityPolicyId]
|
|
69
|
+
) {
|
|
70
|
+
clientMap[capabilityPolicyId] = createIsomorphicClient({
|
|
71
|
+
transport,
|
|
72
|
+
chain,
|
|
73
|
+
policyId: capabilityPolicyId,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
const client =
|
|
78
|
+
clientMap[capabilityPolicyId ?? policyId ?? "default"];
|
|
79
|
+
return client.prepareCalls(params);
|
|
80
|
+
}
|
|
81
|
+
case "wallet_sendPreparedCalls":
|
|
82
|
+
return isomorphicClient.sendPreparedCalls(args.params[0]);
|
|
83
|
+
case "wallet_getCallsStatus":
|
|
84
|
+
return isomorphicClient.getCallsStatus(args.params[0]);
|
|
85
|
+
case "wallet_createSession": {
|
|
86
|
+
return isomorphicClient.createSession(args.params[0]);
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return assertNever(
|
|
90
|
+
args.method,
|
|
91
|
+
`Unexpected method: ${args.method}`,
|
|
92
|
+
);
|
|
85
93
|
}
|
|
86
|
-
|
|
87
|
-
return assertNever(
|
|
88
|
-
args.method,
|
|
89
|
-
`Unexpected method: ${args.method}`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
94
|
+
},
|
|
92
95
|
},
|
|
93
|
-
|
|
96
|
+
{
|
|
97
|
+
retryCount: 0,
|
|
98
|
+
},
|
|
99
|
+
),
|
|
94
100
|
},
|
|
95
101
|
],
|
|
96
102
|
fallback: transport,
|
|
@@ -100,10 +106,14 @@ export function createLocalClient(
|
|
|
100
106
|
transport: innerTransport,
|
|
101
107
|
chain,
|
|
102
108
|
account,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
})
|
|
110
|
+
.extend(() => ({
|
|
111
|
+
policyId,
|
|
112
|
+
...innerClientActions(isomorphicClient),
|
|
113
|
+
}))
|
|
114
|
+
.extend(() => ({
|
|
115
|
+
internal: internalStateDecorator(),
|
|
116
|
+
}));
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
const innerClientActions = (
|
|
@@ -113,12 +123,10 @@ const innerClientActions = (
|
|
|
113
123
|
grantPermissions: async (signer, params) => {
|
|
114
124
|
const { signatureRequest, fullPreSignatureDeferredActionDigest } =
|
|
115
125
|
await isomorphicClient.createSession(params);
|
|
116
|
-
|
|
117
|
-
const { signature } = await signSignatureRequest(
|
|
126
|
+
const { signedAuthorization, signature } = await signSignatureRequest(
|
|
118
127
|
signer,
|
|
119
128
|
signatureRequest,
|
|
120
129
|
);
|
|
121
|
-
|
|
122
130
|
return {
|
|
123
131
|
context: encodePermissionsContext({
|
|
124
132
|
contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
|
|
@@ -127,6 +135,7 @@ const innerClientActions = (
|
|
|
127
135
|
sig: prefixSignatureKeyType(signature, "secp256k1"),
|
|
128
136
|
}),
|
|
129
137
|
}),
|
|
138
|
+
signedAuthorization,
|
|
130
139
|
};
|
|
131
140
|
},
|
|
132
141
|
};
|
package/src/remote/client.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { Provider } from "ox";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BaseError,
|
|
4
|
+
createClient,
|
|
5
|
+
custom,
|
|
6
|
+
type Address,
|
|
7
|
+
type JsonRpcAccount,
|
|
8
|
+
} from "viem";
|
|
3
9
|
import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
|
|
4
10
|
import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
11
|
+
import { internalStateDecorator } from "../internal/decorator.js";
|
|
5
12
|
import { WalletServerRpcSchema } from "../rpc/schema.js";
|
|
6
13
|
import type {
|
|
7
14
|
CreateInnerClientParams,
|
|
8
15
|
InnerClientActions,
|
|
9
16
|
InnerWalletApiClient,
|
|
10
17
|
InnerWalletApiClientBase,
|
|
11
|
-
} from "../types";
|
|
18
|
+
} from "../types.ts";
|
|
12
19
|
|
|
13
20
|
export function createRemoteClient<
|
|
14
21
|
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
@@ -34,10 +41,14 @@ export function createRemoteClient(
|
|
|
34
41
|
),
|
|
35
42
|
chain,
|
|
36
43
|
account,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
})
|
|
45
|
+
.extend((_client) => ({
|
|
46
|
+
policyId: params.policyId,
|
|
47
|
+
...innerClientActions(_client),
|
|
48
|
+
}))
|
|
49
|
+
.extend(() => ({
|
|
50
|
+
internal: internalStateDecorator(),
|
|
51
|
+
}));
|
|
41
52
|
|
|
42
53
|
return client;
|
|
43
54
|
}
|
|
@@ -51,7 +62,10 @@ const innerClientActions = (
|
|
|
51
62
|
method: "wallet_createSession",
|
|
52
63
|
params: [params],
|
|
53
64
|
});
|
|
54
|
-
|
|
65
|
+
if (signatureRequest.type !== "eth_signTypedData_v4") {
|
|
66
|
+
throw new BaseError("Unexpected signature request type");
|
|
67
|
+
}
|
|
68
|
+
const { signedAuthorization, signature } = await signSignatureRequest(
|
|
55
69
|
signer,
|
|
56
70
|
signatureRequest,
|
|
57
71
|
);
|
|
@@ -61,6 +75,7 @@ const innerClientActions = (
|
|
|
61
75
|
sessionId,
|
|
62
76
|
signature,
|
|
63
77
|
}),
|
|
78
|
+
signedAuthorization,
|
|
64
79
|
};
|
|
65
80
|
},
|
|
66
81
|
};
|