@account-kit/wallet-client 0.1.0-alpha.5 → 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.
- package/dist/esm/capabilities/eip7702Auth.js +3 -1
- package/dist/esm/capabilities/eip7702Auth.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 +1 -1
- package/dist/esm/capabilities/permissions/index.js +6 -3
- package/dist/esm/capabilities/permissions/index.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +5 -60
- package/dist/esm/client/actions/grantPermissions.js +5 -58
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
- package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +53 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
- package/dist/esm/client/actions/signSignatureRequest.js +69 -31
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +28 -25
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +3 -1
- package/dist/esm/client/decorator.js +3 -1
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/exports/index.d.ts +2 -1
- package/dist/esm/exports/index.js +2 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +18 -32
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +139 -13
- package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
- package/dist/esm/isomorphic/utils/7702.js +14 -6
- package/dist/esm/isomorphic/utils/7702.js.map +1 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- package/dist/esm/local/client.js +2 -3
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.js +3 -7
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/examples.d.ts +3 -3
- package/dist/esm/rpc/examples.js +3 -3
- package/dist/esm/rpc/examples.js.map +1 -1
- package/dist/esm/rpc/request.d.ts +357 -49
- package/dist/esm/rpc/request.js +26 -53
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +323 -57
- package/dist/esm/rpc/schema.js.map +1 -1
- package/dist/esm/schemas.d.ts +451 -13
- package/dist/esm/schemas.js +165 -52
- 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/capabilities/eip7702Auth.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/index.d.ts +1 -1
- package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +5 -60
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts +8 -7
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +3 -1
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +2 -1
- package/dist/types/exports/index.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 +3 -3
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +139 -13
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +4 -3
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/examples.d.ts +3 -3
- package/dist/types/rpc/examples.d.ts.map +1 -1
- package/dist/types/rpc/request.d.ts +357 -49
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +323 -57
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +451 -13
- 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 +2 -2
- package/src/capabilities/eip7702Auth.ts +17 -10
- package/src/capabilities/overrides.ts +8 -8
- package/src/capabilities/permissions/index.ts +8 -3
- package/src/client/actions/grantPermissions.ts +5 -60
- package/src/client/actions/sendPreparedCalls.ts +17 -17
- package/src/client/actions/signPreparedCalls.ts +71 -0
- package/src/client/actions/signSignatureRequest.ts +50 -46
- package/src/client/client.e2e-test.ts +32 -35
- package/src/client/decorator.ts +14 -5
- package/src/exports/index.ts +2 -1
- package/src/isomorphic/actions/createSession.ts +20 -42
- package/src/isomorphic/actions/prepareCalls.ts +25 -17
- package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
- package/src/isomorphic/utils/7702.ts +18 -8
- package/src/isomorphic/utils/decodeSignature.ts +18 -0
- package/src/local/client.ts +2 -6
- package/src/remote/client.ts +3 -10
- package/src/rpc/examples.ts +3 -4
- package/src/rpc/request.ts +41 -63
- package/src/rpc/schema.ts +2 -2
- package/src/schemas.ts +227 -53
- package/src/types.ts +4 -0
|
@@ -24,12 +24,7 @@ import type { wallet_createSession } from "../../rpc/request.js";
|
|
|
24
24
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
25
25
|
import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
|
|
26
26
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
27
|
-
import { createAuthorization } from "../utils/7702.js";
|
|
28
27
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
29
|
-
import {
|
|
30
|
-
parseDelegation,
|
|
31
|
-
assertValid7702AccountAddress,
|
|
32
|
-
} from "../utils/7702.js";
|
|
33
28
|
|
|
34
29
|
export type CreateSessionParams = Omit<
|
|
35
30
|
Static<
|
|
@@ -63,30 +58,26 @@ export async function createSession(
|
|
|
63
58
|
throw new ChainNotFoundError();
|
|
64
59
|
}
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
params
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
: await client.request({
|
|
77
|
-
method: "wallet_requestAccount",
|
|
78
|
-
params: [
|
|
79
|
-
{
|
|
80
|
-
accountAddress: params.account,
|
|
81
|
-
includeCounterfactualInfo: true,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
61
|
+
const { counterfactualInfo, delegation } = await client.request({
|
|
62
|
+
method: "wallet_requestAccount",
|
|
63
|
+
params: [
|
|
64
|
+
{
|
|
65
|
+
accountAddress: params.account,
|
|
66
|
+
includeCounterfactualInfo: true,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
});
|
|
85
70
|
|
|
86
|
-
if (
|
|
71
|
+
if (delegation) {
|
|
87
72
|
throw new InvalidRequestError({
|
|
88
73
|
message:
|
|
89
|
-
"
|
|
74
|
+
"'wallet_createSession' does not currently support 7702 accounts.",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!counterfactualInfo) {
|
|
79
|
+
throw new InvalidRequestError({
|
|
80
|
+
message: "No counterfactual info found.",
|
|
90
81
|
});
|
|
91
82
|
}
|
|
92
83
|
|
|
@@ -126,7 +117,7 @@ export async function createSession(
|
|
|
126
117
|
},
|
|
127
118
|
entityId,
|
|
128
119
|
nonce,
|
|
129
|
-
deadline: params.
|
|
120
|
+
deadline: params.expirySec,
|
|
130
121
|
})
|
|
131
122
|
.addPermissions({
|
|
132
123
|
permissions: params.permissions.map((permission) =>
|
|
@@ -135,25 +126,12 @@ export async function createSession(
|
|
|
135
126
|
})
|
|
136
127
|
.compileDeferred();
|
|
137
128
|
|
|
138
|
-
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
139
|
-
const authorizationRequest = delegation
|
|
140
|
-
? await createAuthorization(client, {
|
|
141
|
-
address: account.address,
|
|
142
|
-
delegation,
|
|
143
|
-
})
|
|
144
|
-
: undefined;
|
|
145
|
-
|
|
146
|
-
const signatureRequest = {
|
|
147
|
-
type: "eth_signTypedData_v4" as const,
|
|
148
|
-
data: typedData,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
129
|
return {
|
|
152
130
|
sessionId: null, // In remote mode, the server will set this later.
|
|
153
131
|
entityId: toHex(entityId),
|
|
154
132
|
signatureRequest: {
|
|
155
|
-
|
|
156
|
-
|
|
133
|
+
type: "eth_signTypedData_v4" as const,
|
|
134
|
+
data: typedData,
|
|
157
135
|
},
|
|
158
136
|
fullPreSignatureDeferredActionDigest,
|
|
159
137
|
};
|
|
@@ -17,8 +17,9 @@ import type { wallet_prepareCalls } from "../../rpc/request.js";
|
|
|
17
17
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
18
18
|
import { createAccount } from "../utils/createAccount.js";
|
|
19
19
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
20
|
-
import {
|
|
20
|
+
import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
|
|
21
21
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
22
|
+
import { assertNever } from "../../utils.js";
|
|
22
23
|
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
23
24
|
|
|
24
25
|
export type PrepareCallsParams = Omit<
|
|
@@ -83,7 +84,7 @@ export async function prepareCalls(
|
|
|
83
84
|
|
|
84
85
|
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
85
86
|
const authorizationRequest = delegation
|
|
86
|
-
? await
|
|
87
|
+
? await createAuthorizationRequest(client, {
|
|
87
88
|
address: account.address,
|
|
88
89
|
delegation,
|
|
89
90
|
})
|
|
@@ -107,29 +108,36 @@ export async function prepareCalls(
|
|
|
107
108
|
});
|
|
108
109
|
|
|
109
110
|
// The eip7702Auth field should never be included in the UO sig
|
|
110
|
-
// request. It's handled by
|
|
111
|
+
// request. It's handled by a separate authorization request.
|
|
111
112
|
if ("eip7702Auth" in builtUo) {
|
|
112
113
|
builtUo.eip7702Auth = undefined;
|
|
113
114
|
}
|
|
114
|
-
const uoRequest = deepHexlify(builtUo);
|
|
115
115
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
raw: account.getEntryPoint().getUserOperationHash(uoRequest),
|
|
120
|
-
},
|
|
121
|
-
};
|
|
116
|
+
const hexlifiedUo = deepHexlify(builtUo);
|
|
117
|
+
|
|
118
|
+
const ep = account.getEntryPoint();
|
|
122
119
|
|
|
123
|
-
|
|
120
|
+
const uoRequest = {
|
|
124
121
|
type:
|
|
125
|
-
|
|
126
|
-
? "user-operation-v070"
|
|
127
|
-
: "
|
|
128
|
-
|
|
122
|
+
ep.version === "0.7.0"
|
|
123
|
+
? ("user-operation-v070" as const)
|
|
124
|
+
: ep.version === "0.6.0"
|
|
125
|
+
? ("user-operation-v060" as const)
|
|
126
|
+
: assertNever(ep.version, "Unexpected entry point version"),
|
|
127
|
+
data: hexlifiedUo,
|
|
129
128
|
chainId: toHex(client.chain.id),
|
|
130
129
|
signatureRequest: {
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
type: "personal_sign" as const,
|
|
131
|
+
data: {
|
|
132
|
+
raw: ep.getUserOperationHash(hexlifiedUo),
|
|
133
|
+
},
|
|
133
134
|
},
|
|
134
135
|
};
|
|
136
|
+
|
|
137
|
+
return authorizationRequest
|
|
138
|
+
? {
|
|
139
|
+
type: "array" as const,
|
|
140
|
+
data: [authorizationRequest, uoRequest],
|
|
141
|
+
}
|
|
142
|
+
: uoRequest;
|
|
135
143
|
}
|
|
@@ -3,31 +3,33 @@ import {
|
|
|
3
3
|
type SmartAccountClient,
|
|
4
4
|
type SmartContractAccount,
|
|
5
5
|
} from "@aa-sdk/core";
|
|
6
|
-
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
7
6
|
import { Value } from "@sinclair/typebox/value";
|
|
8
7
|
import {
|
|
9
8
|
BaseError,
|
|
10
9
|
ChainNotFoundError,
|
|
11
10
|
concat,
|
|
12
11
|
concatHex,
|
|
12
|
+
numberToHex,
|
|
13
|
+
parseSignature,
|
|
13
14
|
toHex,
|
|
15
|
+
type Address,
|
|
14
16
|
type Chain,
|
|
15
17
|
type Hex,
|
|
16
18
|
type Transport,
|
|
17
19
|
} from "viem";
|
|
18
20
|
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
19
|
-
import type
|
|
21
|
+
import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
|
|
20
22
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
21
23
|
import { TypeCallId } from "../../schemas.js";
|
|
22
24
|
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
23
25
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
26
|
+
import { assertNever } from "../../utils.js";
|
|
27
|
+
import type { Static } from "@sinclair/typebox";
|
|
28
|
+
import { decodeSignature } from "../utils/decodeSignature.js";
|
|
24
29
|
|
|
25
|
-
export type SendPreparedCallsParams =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
>[0],
|
|
29
|
-
"chainId"
|
|
30
|
-
>;
|
|
30
|
+
export type SendPreparedCallsParams = Static<
|
|
31
|
+
(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
|
|
32
|
+
>[0];
|
|
31
33
|
|
|
32
34
|
export type SendPreparedCallsResult = Static<
|
|
33
35
|
(typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
|
|
@@ -48,16 +50,6 @@ export async function sendPreparedCalls(
|
|
|
48
50
|
throw new ChainNotFoundError();
|
|
49
51
|
}
|
|
50
52
|
|
|
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
|
-
!isSupportedDelegationAddress7702(params.signedAuthorization.address)
|
|
55
|
-
) {
|
|
56
|
-
throw new InvalidRequestError({
|
|
57
|
-
message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
53
|
const deferredAction: Hex | undefined = (() => {
|
|
62
54
|
if (!params.capabilities?.permissions) {
|
|
63
55
|
return;
|
|
@@ -77,46 +69,104 @@ export async function sendPreparedCalls(
|
|
|
77
69
|
return decodedContext.deferredAction;
|
|
78
70
|
})();
|
|
79
71
|
|
|
80
|
-
const
|
|
81
|
-
params.type === "
|
|
82
|
-
?
|
|
83
|
-
|
|
72
|
+
const userOps =
|
|
73
|
+
params.type === "array"
|
|
74
|
+
? params.data.filter((it) => {
|
|
75
|
+
const isUserOp =
|
|
76
|
+
it.type === "user-operation-v060" ||
|
|
77
|
+
it.type === "user-operation-v070";
|
|
78
|
+
if (isUserOp && it.chainId !== toHex(client.chain.id)) {
|
|
79
|
+
throw new InvalidRequestError({
|
|
80
|
+
message:
|
|
81
|
+
"Multiple chain IDs in a single request are not currently supported.",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return isUserOp;
|
|
85
|
+
})
|
|
86
|
+
: [params];
|
|
87
|
+
|
|
88
|
+
const authorizations =
|
|
89
|
+
params.type === "array"
|
|
90
|
+
? params.data.filter((it) => it.type === "authorization")
|
|
91
|
+
: [];
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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;
|
|
93
|
+
if (authorizations.length > 1) {
|
|
94
|
+
throw new InvalidRequestError({
|
|
95
|
+
message:
|
|
96
|
+
"Multiple authorizations in a single request are not currently supported",
|
|
112
97
|
});
|
|
98
|
+
}
|
|
99
|
+
const [authorization] = authorizations;
|
|
100
|
+
|
|
101
|
+
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
102
|
+
if (
|
|
103
|
+
authorization &&
|
|
104
|
+
!isSupportedDelegationAddress7702(authorization.data.address)
|
|
105
|
+
) {
|
|
106
|
+
throw new InvalidRequestError({
|
|
107
|
+
message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
113
110
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
const hashes = await Promise.all(
|
|
112
|
+
userOps.map(async (userOp, idx) => {
|
|
113
|
+
const ep: { address: Address } =
|
|
114
|
+
userOp.type === "user-operation-v060"
|
|
115
|
+
? getEntryPoint(client.chain, { version: "0.6.0" })
|
|
116
|
+
: userOp.type === "user-operation-v070"
|
|
117
|
+
? getEntryPoint(client.chain, { version: "0.7.0" })
|
|
118
|
+
: assertNever(userOp, "Unexpected user op type");
|
|
119
|
+
const authSig = authorization
|
|
120
|
+
? parseSignature(decodeSignature(authorization.signature).data)
|
|
121
|
+
: undefined;
|
|
122
|
+
const uoSigHex = decodeSignature(userOp.signature).data;
|
|
123
|
+
return client
|
|
124
|
+
.sendRawUserOperation(
|
|
125
|
+
{
|
|
126
|
+
...userOp.data,
|
|
127
|
+
signature:
|
|
128
|
+
deferredAction != null
|
|
129
|
+
? concatHex([
|
|
130
|
+
`0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).
|
|
131
|
+
"0xff",
|
|
132
|
+
"0x00",
|
|
133
|
+
uoSigHex,
|
|
134
|
+
])
|
|
135
|
+
: concat(["0xFF", "0x00", uoSigHex]),
|
|
136
|
+
eip7702Auth:
|
|
137
|
+
idx === 0 && authorization && authSig
|
|
138
|
+
? {
|
|
139
|
+
...authorization.data,
|
|
140
|
+
chainId: authorization.chainId,
|
|
141
|
+
...{
|
|
142
|
+
...authSig,
|
|
143
|
+
yParity: numberToHex(authSig.yParity),
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: undefined,
|
|
147
|
+
},
|
|
148
|
+
ep.address,
|
|
149
|
+
)
|
|
150
|
+
.catch((err) => {
|
|
151
|
+
if (
|
|
152
|
+
err instanceof BaseError &&
|
|
153
|
+
err.details.endsWith("is not a contract and initCode is empty")
|
|
154
|
+
) {
|
|
155
|
+
throw new BaseError(
|
|
156
|
+
`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
throw err;
|
|
160
|
+
});
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
118
163
|
|
|
119
164
|
return {
|
|
120
|
-
preparedCallIds:
|
|
165
|
+
preparedCallIds: hashes.map((hash) =>
|
|
166
|
+
Value.Encode(TypeCallId, {
|
|
167
|
+
chainId: toHex(client.chain.id),
|
|
168
|
+
hash,
|
|
169
|
+
}),
|
|
170
|
+
),
|
|
121
171
|
};
|
|
122
172
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import {
|
|
3
3
|
concatHex,
|
|
4
|
-
|
|
4
|
+
numberToHex,
|
|
5
5
|
type Address,
|
|
6
6
|
type Chain,
|
|
7
7
|
type Transport,
|
|
8
8
|
isAddress,
|
|
9
9
|
} from "viem";
|
|
10
10
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
11
|
+
import { PreparedCall_Authorization } from "../../schemas.js";
|
|
11
12
|
import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
|
|
12
13
|
import type { Static } from "@sinclair/typebox";
|
|
13
14
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
14
15
|
|
|
15
|
-
export const
|
|
16
|
+
export const createAuthorizationRequest = async (
|
|
16
17
|
client: SmartAccountClient<
|
|
17
18
|
Transport,
|
|
18
19
|
Chain,
|
|
@@ -21,18 +22,27 @@ export const createAuthorization = async (
|
|
|
21
22
|
WalletServerViemRpcSchema
|
|
22
23
|
>,
|
|
23
24
|
params: { address: Address; delegation: Address },
|
|
24
|
-
): Promise<
|
|
25
|
+
): Promise<Static<typeof PreparedCall_Authorization> | undefined> => {
|
|
25
26
|
const expectedCode = concatHex(["0xef0100", params.delegation]);
|
|
26
27
|
const code = (await client.getCode({ address: params.address })) ?? "0x";
|
|
27
28
|
if (code.toLowerCase() === expectedCode.toLowerCase()) {
|
|
28
29
|
return undefined; // Already authorized.
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
chainId: client.chain.id,
|
|
31
|
+
const data = {
|
|
32
32
|
address: params.delegation,
|
|
33
|
-
nonce:
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
nonce: numberToHex(
|
|
34
|
+
await client.getTransactionCount({
|
|
35
|
+
address: params.address,
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
type: "authorization" as const,
|
|
41
|
+
data,
|
|
42
|
+
chainId: numberToHex(client.chain.id),
|
|
43
|
+
signatureRequest: {
|
|
44
|
+
type: "eip7702Auth" as const,
|
|
45
|
+
},
|
|
36
46
|
};
|
|
37
47
|
};
|
|
38
48
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Value } from "@sinclair/typebox/value";
|
|
2
|
+
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
3
|
+
import { TypeEcdsaSig } from "../../schemas.js";
|
|
4
|
+
import { assertNever } from "../../utils.js";
|
|
5
|
+
|
|
6
|
+
export const decodeSignature = (
|
|
7
|
+
signature: Static<typeof TypeEcdsaSig>["signature"],
|
|
8
|
+
): StaticDecode<typeof TypeEcdsaSig>["signature"] => {
|
|
9
|
+
switch (signature.type) {
|
|
10
|
+
case "ecdsa":
|
|
11
|
+
case "secp256k1":
|
|
12
|
+
return Value.Decode(TypeEcdsaSig, { signature } satisfies Static<
|
|
13
|
+
typeof TypeEcdsaSig
|
|
14
|
+
>).signature;
|
|
15
|
+
default:
|
|
16
|
+
return assertNever(signature, "Unexpected signature type");
|
|
17
|
+
}
|
|
18
|
+
};
|
package/src/local/client.ts
CHANGED
|
@@ -121,19 +121,15 @@ const innerClientActions = (
|
|
|
121
121
|
grantPermissions: async (signer, params) => {
|
|
122
122
|
const { signatureRequest, fullPreSignatureDeferredActionDigest } =
|
|
123
123
|
await isomorphicClient.createSession(params);
|
|
124
|
-
const
|
|
125
|
-
signer,
|
|
126
|
-
signatureRequest,
|
|
127
|
-
);
|
|
124
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
128
125
|
return {
|
|
129
126
|
context: encodePermissionsContext({
|
|
130
127
|
contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
|
|
131
128
|
deferredAction: buildDeferredActionDigest({
|
|
132
129
|
fullPreSignatureDeferredActionDigest,
|
|
133
|
-
sig: prefixSignatureKeyType(signature,
|
|
130
|
+
sig: prefixSignatureKeyType(signature.data, signature.type),
|
|
134
131
|
}),
|
|
135
132
|
}),
|
|
136
|
-
signedAuthorization,
|
|
137
133
|
};
|
|
138
134
|
},
|
|
139
135
|
};
|
package/src/remote/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from "ox";
|
|
2
|
-
import {
|
|
2
|
+
import { createClient, custom, type Address } from "viem";
|
|
3
3
|
import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
|
|
4
4
|
import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
5
5
|
import { internalStateDecorator } from "../internal/decorator.js";
|
|
@@ -54,20 +54,13 @@ const innerClientActions = (
|
|
|
54
54
|
method: "wallet_createSession",
|
|
55
55
|
params: [params],
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
throw new BaseError("Unexpected signature request type");
|
|
59
|
-
}
|
|
60
|
-
const { signedAuthorization, signature } = await signSignatureRequest(
|
|
61
|
-
signer,
|
|
62
|
-
signatureRequest,
|
|
63
|
-
);
|
|
57
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
64
58
|
return {
|
|
65
59
|
context: encodePermissionsContext({
|
|
66
60
|
contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
|
|
67
61
|
sessionId,
|
|
68
|
-
signature,
|
|
62
|
+
signature: signature.data,
|
|
69
63
|
}),
|
|
70
|
-
signedAuthorization,
|
|
71
64
|
};
|
|
72
65
|
},
|
|
73
66
|
};
|
package/src/rpc/examples.ts
CHANGED
|
@@ -82,9 +82,8 @@ const SendPreparedCalls = [
|
|
|
82
82
|
},
|
|
83
83
|
chainId: "0x66eee",
|
|
84
84
|
signature: {
|
|
85
|
-
type: "
|
|
86
|
-
|
|
87
|
-
"0xb1a055089b1ba8387ed435f2bd0afe7ff69f22b928cdfdea1b5323c64d6af387164de3fa6febf031b544de46a84d6fb7f084b9798ddfaba820950c257139a7321b",
|
|
85
|
+
type: "secp256k1",
|
|
86
|
+
data: "0xb1a055089b1ba8387ed435f2bd0afe7ff69f22b928cdfdea1b5323c64d6af387164de3fa6febf031b544de46a84d6fb7f084b9798ddfaba820950c257139a7321b",
|
|
88
87
|
},
|
|
89
88
|
},
|
|
90
89
|
],
|
|
@@ -200,7 +199,7 @@ const CreateSession = [
|
|
|
200
199
|
type: "root",
|
|
201
200
|
},
|
|
202
201
|
],
|
|
203
|
-
|
|
202
|
+
expirySec: 1747969653,
|
|
204
203
|
},
|
|
205
204
|
],
|
|
206
205
|
},
|
package/src/rpc/request.ts
CHANGED
|
@@ -6,57 +6,43 @@ import {
|
|
|
6
6
|
RemotePermission,
|
|
7
7
|
} from "../capabilities/permissions/index.js";
|
|
8
8
|
import {
|
|
9
|
+
TypeCallArray,
|
|
10
|
+
TypePrepareCall_UserOpV060_Signed,
|
|
11
|
+
TypePrepareCall_UserOpV070_Signed,
|
|
12
|
+
PreparedCall_Authorization,
|
|
13
|
+
PreparedCall_UserOpV060,
|
|
14
|
+
PreparedCall_UserOpV070,
|
|
9
15
|
TypeAddress,
|
|
10
16
|
TypeBase64UrlEncodedString,
|
|
11
17
|
TypeCreationOptions,
|
|
12
|
-
TypeEip7702AuthExtendedFields,
|
|
13
18
|
TypeHex,
|
|
14
19
|
TypeSerializedInitcode,
|
|
15
|
-
|
|
16
|
-
TypeUserOperationRequest_v6,
|
|
17
|
-
TypeUserOperationRequest_v7,
|
|
20
|
+
TypeTypedDataSignatureRequest,
|
|
18
21
|
TypeUuid,
|
|
19
|
-
TypeSignatureType,
|
|
20
22
|
} from "../schemas.js";
|
|
21
23
|
import { Examples } from "./examples.js";
|
|
22
|
-
import { Eip7702AuthCapability } from "../capabilities/eip7702Auth.js";
|
|
23
24
|
|
|
24
25
|
export const wallet_sendPreparedCalls = Type.Object(
|
|
25
26
|
{
|
|
26
27
|
Request: Type.Object({
|
|
27
28
|
method: Type.Literal("wallet_sendPreparedCalls"),
|
|
28
29
|
params: Type.Tuple([
|
|
29
|
-
Type.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Type.Literal("user-operation-v070", {
|
|
35
|
-
title: "User Operation (Entrypoint v0.7.0)",
|
|
36
|
-
}),
|
|
37
|
-
]),
|
|
38
|
-
data: Type.Union([
|
|
39
|
-
Type.Omit(TypeUserOperationRequest_v6, ["signature"], {
|
|
40
|
-
title: "Unsigned User Operation (Entrypoint v0.6.0)",
|
|
41
|
-
}),
|
|
42
|
-
Type.Omit(TypeUserOperationRequest_v7, ["signature"], {
|
|
43
|
-
title: "Unsigned User Operation (Entrypoint v0.7.0)",
|
|
44
|
-
}),
|
|
30
|
+
Type.Intersect([
|
|
31
|
+
Type.Union([
|
|
32
|
+
TypeCallArray,
|
|
33
|
+
TypePrepareCall_UserOpV060_Signed,
|
|
34
|
+
TypePrepareCall_UserOpV070_Signed,
|
|
45
35
|
]),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
Type.Object({
|
|
37
|
+
capabilities: Type.Optional(
|
|
38
|
+
Type.Object({
|
|
39
|
+
permissions: Type.Optional(
|
|
40
|
+
Type.Union([PermissionsContext, RemotePermission]),
|
|
41
|
+
),
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
50
44
|
}),
|
|
51
|
-
|
|
52
|
-
capabilities: Type.Optional(
|
|
53
|
-
Type.Object({
|
|
54
|
-
permissions: Type.Optional(
|
|
55
|
-
Type.Union([PermissionsContext, RemotePermission]),
|
|
56
|
-
),
|
|
57
|
-
}),
|
|
58
|
-
),
|
|
59
|
-
}),
|
|
45
|
+
]),
|
|
60
46
|
]),
|
|
61
47
|
}),
|
|
62
48
|
ReturnType: Type.Object({
|
|
@@ -89,26 +75,23 @@ export const wallet_prepareCalls = Type.Object(
|
|
|
89
75
|
}),
|
|
90
76
|
]),
|
|
91
77
|
}),
|
|
92
|
-
ReturnType: Type.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
chainId: TypeHex(),
|
|
110
|
-
signatureRequest: TypeSignatureRequest,
|
|
111
|
-
}),
|
|
78
|
+
ReturnType: Type.Union([
|
|
79
|
+
Type.Object(
|
|
80
|
+
{
|
|
81
|
+
type: Type.Literal("array"),
|
|
82
|
+
data: Type.Array(
|
|
83
|
+
Type.Union([
|
|
84
|
+
PreparedCall_UserOpV060,
|
|
85
|
+
PreparedCall_UserOpV070,
|
|
86
|
+
PreparedCall_Authorization,
|
|
87
|
+
]),
|
|
88
|
+
),
|
|
89
|
+
},
|
|
90
|
+
{ description: "Array of prepared calls" },
|
|
91
|
+
),
|
|
92
|
+
PreparedCall_UserOpV060,
|
|
93
|
+
PreparedCall_UserOpV070,
|
|
94
|
+
]),
|
|
112
95
|
},
|
|
113
96
|
{
|
|
114
97
|
description:
|
|
@@ -133,7 +116,7 @@ export const wallet_requestAccount = Type.Object(
|
|
|
133
116
|
),
|
|
134
117
|
},
|
|
135
118
|
{
|
|
136
|
-
|
|
119
|
+
description: "Using signer address",
|
|
137
120
|
},
|
|
138
121
|
),
|
|
139
122
|
Type.Object(
|
|
@@ -144,7 +127,7 @@ export const wallet_requestAccount = Type.Object(
|
|
|
144
127
|
),
|
|
145
128
|
},
|
|
146
129
|
{
|
|
147
|
-
|
|
130
|
+
description: "Using smart contract account address",
|
|
148
131
|
},
|
|
149
132
|
),
|
|
150
133
|
]),
|
|
@@ -229,18 +212,13 @@ export const wallet_createSession = Type.Object(
|
|
|
229
212
|
PermissionsData,
|
|
230
213
|
Type.Object({
|
|
231
214
|
account: TypeAddress,
|
|
232
|
-
capabilities: Type.Optional(
|
|
233
|
-
Type.Object({
|
|
234
|
-
eip7702Auth: Type.Optional(Eip7702AuthCapability),
|
|
235
|
-
}),
|
|
236
|
-
),
|
|
237
215
|
}),
|
|
238
216
|
]),
|
|
239
217
|
]),
|
|
240
218
|
}),
|
|
241
219
|
ReturnType: Type.Object({
|
|
242
220
|
sessionId: TypeHex(),
|
|
243
|
-
signatureRequest:
|
|
221
|
+
signatureRequest: TypeTypedDataSignatureRequest,
|
|
244
222
|
}),
|
|
245
223
|
},
|
|
246
224
|
{
|