@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.10
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/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/formatSign.d.ts +28 -0
- package/dist/esm/client/actions/formatSign.js +30 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/esm/client/actions/getCallsStatus.js +19 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +63 -6
- package/dist/esm/client/actions/grantPermissions.js +63 -3
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +32 -4
- package/dist/esm/client/actions/listAccounts.js +35 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +32 -6
- package/dist/esm/client/actions/prepareCalls.js +39 -5
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +25 -0
- package/dist/esm/client/actions/prepareSign.js +28 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +24 -6
- package/dist/esm/client/actions/requestAccount.js +38 -7
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/esm/client/actions/sendPreparedCalls.js +37 -1
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +25 -5
- package/dist/esm/client/actions/signMessage.js +22 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +43 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +39 -5
- package/dist/esm/client/actions/signSignatureRequest.js +69 -11
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +37 -4
- package/dist/esm/client/actions/signTypedData.js +34 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +210 -45
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +12 -8
- package/dist/esm/client/decorator.js +5 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +38 -12
- package/dist/esm/client/index.js +0 -3
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +5 -6
- package/dist/esm/exports/index.js +4 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +1 -10
- package/dist/esm/exports/internal.js +0 -12
- 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.d.ts +1 -2
- package/dist/esm/isomorphic/actions/createSession.js +39 -10
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +8 -0
- package/dist/esm/isomorphic/actions/formatSign.js +42 -0
- package/dist/esm/isomorphic/actions/formatSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/esm/isomorphic/actions/getCallsStatus.js +37 -26
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/esm/isomorphic/actions/prepareCalls.js +78 -20
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +7 -0
- package/dist/esm/isomorphic/actions/prepareSign.js +49 -0
- package/dist/esm/isomorphic/actions/prepareSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +138 -25
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +204 -27
- package/dist/esm/isomorphic/client.js +6 -2
- package/dist/esm/isomorphic/client.js.map +1 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +19 -0
- package/dist/esm/isomorphic/utils/7702.js +70 -0
- package/dist/esm/isomorphic/utils/7702.js.map +1 -0
- package/dist/esm/isomorphic/utils/createAccount.d.ts +5 -4
- package/dist/esm/isomorphic/utils/createAccount.js +84 -10
- 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/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +15 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +19 -6
- package/dist/esm/isomorphic/utils/parsePermissionsContext.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/local/client.d.ts +3 -3
- package/dist/esm/local/client.js +11 -4
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +9 -3
- package/dist/esm/remote/client.js +10 -11
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/types.d.ts +27 -13
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js.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/formatSign.d.ts +29 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +63 -6
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +32 -4
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +32 -6
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +26 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +24 -6
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +25 -5
- package/dist/types/client/actions/signMessage.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 +39 -5
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +37 -4
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +12 -8
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +38 -12
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +5 -6
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +1 -10
- 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 +1 -2
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +9 -0
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +8 -0
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +204 -27
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +20 -0
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/createAccount.d.ts +5 -4
- 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/decodeSignature.d.ts +4 -0
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/types/isomorphic/utils/parsePermissionsContext.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/local/client.d.ts +3 -3
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +9 -3
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/types.d.ts +27 -13
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/client/actions/createAccount.ts +27 -2
- package/src/client/actions/formatSign.ts +53 -0
- package/src/client/actions/getCallsStatus.ts +21 -12
- package/src/client/actions/grantPermissions.ts +69 -26
- package/src/client/actions/listAccounts.ts +44 -6
- package/src/client/actions/prepareCalls.ts +46 -26
- package/src/client/actions/prepareSign.ts +46 -0
- package/src/client/actions/requestAccount.ts +60 -41
- package/src/client/actions/sendPreparedCalls.ts +44 -7
- package/src/client/actions/signMessage.ts +26 -21
- package/src/client/actions/signPreparedCalls.ts +67 -0
- package/src/client/actions/signSignatureRequest.ts +84 -20
- package/src/client/actions/signTypedData.ts +40 -19
- package/src/client/client.e2e-test.ts +256 -54
- package/src/client/decorator.ts +28 -26
- package/src/client/index.ts +50 -40
- package/src/exports/index.ts +5 -13
- package/src/exports/internal.ts +2 -10
- package/src/internal/decorator.ts +12 -0
- package/src/isomorphic/actions/createSession.ts +55 -12
- package/src/isomorphic/actions/formatSign.ts +76 -0
- package/src/isomorphic/actions/getCallsStatus.ts +46 -32
- package/src/isomorphic/actions/prepareCalls.ts +95 -23
- package/src/isomorphic/actions/prepareSign.ts +91 -0
- package/src/isomorphic/actions/sendPreparedCalls.ts +181 -42
- package/src/isomorphic/client.ts +10 -2
- package/src/isomorphic/utils/7702.ts +135 -0
- package/src/isomorphic/utils/createAccount.ts +101 -13
- package/src/isomorphic/utils/createDummySigner.ts +3 -2
- package/src/isomorphic/utils/decodeSignature.ts +21 -0
- package/src/isomorphic/utils/parsePermissionsContext.ts +29 -11
- package/src/isomorphic/utils/supportsFeature.ts +34 -0
- package/src/local/client.ts +58 -55
- package/src/remote/client.ts +19 -19
- package/src/types.ts +29 -23
- package/src/utils.ts +2 -0
- package/dist/esm/capabilities/index.d.ts +0 -31
- package/dist/esm/capabilities/index.js +0 -10
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/overrides.d.ts +0 -26
- package/dist/esm/capabilities/overrides.js +0 -14
- package/dist/esm/capabilities/overrides.js.map +0 -1
- package/dist/esm/capabilities/paymaster.d.ts +0 -3
- package/dist/esm/capabilities/paymaster.js +0 -5
- package/dist/esm/capabilities/paymaster.js.map +0 -1
- package/dist/esm/capabilities/permissions/index.d.ts +0 -138
- package/dist/esm/capabilities/permissions/index.js +0 -71
- package/dist/esm/capabilities/permissions/index.js.map +0 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
- package/dist/esm/capabilities/permissions/mav2.js +0 -79
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -352
- package/dist/esm/rpc/request.js +0 -204
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -342
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -216
- package/dist/esm/schemas.js +0 -211
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -32
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/overrides.d.ts +0 -27
- package/dist/types/capabilities/overrides.d.ts.map +0 -1
- package/dist/types/capabilities/paymaster.d.ts +0 -4
- package/dist/types/capabilities/paymaster.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/index.d.ts +0 -139
- package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
- package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -353
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -343
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -217
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/index.ts +0 -13
- package/src/capabilities/overrides.ts +0 -20
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -142
- package/src/capabilities/permissions/mav2.ts +0 -127
- package/src/rpc/request.ts +0 -273
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -257
|
@@ -1,33 +1,69 @@
|
|
|
1
|
-
import { deepHexlify, } from "@aa-sdk/core";
|
|
2
|
-
import { ChainNotFoundError, custom, fromHex,
|
|
1
|
+
import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
|
|
2
|
+
import { ChainNotFoundError, custom, fromHex, hashMessage, toHex, } from "viem";
|
|
3
3
|
import { createAccount } from "../utils/createAccount.js";
|
|
4
4
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
5
|
-
|
|
5
|
+
import { createAuthorizationRequest, isDelegated } from "../utils/7702.js";
|
|
6
|
+
import { InvalidRequestError } from "ox/RpcResponse";
|
|
7
|
+
import { assertNever } from "../../utils.js";
|
|
8
|
+
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
6
9
|
export async function prepareCalls(client, params) {
|
|
7
10
|
if (!client.chain) {
|
|
8
11
|
throw new ChainNotFoundError();
|
|
9
12
|
}
|
|
13
|
+
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
10
14
|
// in local mode, we probably want some kind of caching for this
|
|
11
|
-
const { counterfactualInfo } = await client.request({
|
|
15
|
+
const { counterfactualInfo, delegation } = await client.request({
|
|
12
16
|
method: "wallet_requestAccount",
|
|
13
17
|
params: [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
params.capabilities?.eip7702Auth
|
|
19
|
+
? {
|
|
20
|
+
signerAddress: params.from,
|
|
21
|
+
creationHint: {
|
|
22
|
+
accountType: "7702",
|
|
23
|
+
},
|
|
24
|
+
includeCounterfactualInfo: true,
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
accountAddress: params.from,
|
|
28
|
+
includeCounterfactualInfo: true,
|
|
29
|
+
},
|
|
18
30
|
],
|
|
19
31
|
});
|
|
20
|
-
if (!counterfactualInfo) {
|
|
21
|
-
throw new
|
|
32
|
+
if (!counterfactualInfo && !delegation) {
|
|
33
|
+
throw new InvalidRequestError({
|
|
34
|
+
message: "No counterfactual info or delegated implementation address found.",
|
|
35
|
+
});
|
|
22
36
|
}
|
|
23
37
|
const account = await createAccount({
|
|
24
38
|
chain: client.chain,
|
|
25
39
|
transport: custom(client.transport),
|
|
26
|
-
signer: createDummySigner(
|
|
40
|
+
signer: createDummySigner(params.from),
|
|
27
41
|
accountAddress: params.from,
|
|
28
42
|
counterfactualInfo,
|
|
29
|
-
|
|
43
|
+
permissions: params.capabilities?.permissions,
|
|
44
|
+
delegation,
|
|
30
45
|
});
|
|
46
|
+
const authorizationRequest = delegation &&
|
|
47
|
+
!(await isDelegated(client, {
|
|
48
|
+
address: account.address,
|
|
49
|
+
delegation,
|
|
50
|
+
}))
|
|
51
|
+
? await createAuthorizationRequest(client, {
|
|
52
|
+
address: account.address,
|
|
53
|
+
delegation,
|
|
54
|
+
})
|
|
55
|
+
: undefined;
|
|
56
|
+
if (params.capabilities?.permissions && authorizationRequest) {
|
|
57
|
+
// The user shouldn't see this in most cases since we require
|
|
58
|
+
// the account to be delegated before creating the session.
|
|
59
|
+
throw new InvalidRequestError({
|
|
60
|
+
message: "When using a 7702 account with a session key, the account must be delegated before preparing calls.",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (authorizationRequest) {
|
|
64
|
+
// @ts-expect-error - this is available but not typed as public
|
|
65
|
+
client.middleware.gasEstimator = default7702GasEstimator();
|
|
66
|
+
}
|
|
31
67
|
// TODO: oops we don't actually support setting the policyId as an override here
|
|
32
68
|
// if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
|
|
33
69
|
const builtUo = await client.buildUserOperation({
|
|
@@ -37,22 +73,44 @@ export async function prepareCalls(client, params) {
|
|
|
37
73
|
value: x.value ? fromHex(x.value, "bigint") : undefined,
|
|
38
74
|
})),
|
|
39
75
|
account,
|
|
40
|
-
overrides:
|
|
76
|
+
overrides: {
|
|
77
|
+
...params.capabilities?.gasParamsOverride,
|
|
78
|
+
nonceKey: params.capabilities?.nonceOverride?.nonceKey
|
|
79
|
+
? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
|
|
80
|
+
: undefined,
|
|
81
|
+
},
|
|
41
82
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
// The eip7702Auth field should never be included in the UO sig
|
|
84
|
+
// request. It's handled by a separate authorization request.
|
|
85
|
+
if ("eip7702Auth" in builtUo) {
|
|
86
|
+
builtUo.eip7702Auth = undefined;
|
|
87
|
+
}
|
|
88
|
+
const hexlifiedUo = deepHexlify(builtUo);
|
|
89
|
+
const ep = account.getEntryPoint();
|
|
90
|
+
const uoHash = ep.getUserOperationHash(hexlifiedUo);
|
|
91
|
+
const uoRequest = {
|
|
92
|
+
type: ep.version === "0.7.0"
|
|
46
93
|
? "user-operation-v070"
|
|
47
|
-
: "
|
|
48
|
-
|
|
94
|
+
: ep.version === "0.6.0"
|
|
95
|
+
? "user-operation-v060"
|
|
96
|
+
: assertNever(ep.version, "Unexpected entry point version"),
|
|
97
|
+
data: hexlifiedUo,
|
|
49
98
|
chainId: toHex(client.chain.id),
|
|
50
99
|
signatureRequest: {
|
|
51
100
|
type: "personal_sign",
|
|
52
101
|
data: {
|
|
53
|
-
raw:
|
|
102
|
+
raw: uoHash,
|
|
54
103
|
},
|
|
104
|
+
rawPayload: hashMessage({
|
|
105
|
+
raw: uoHash,
|
|
106
|
+
}),
|
|
55
107
|
},
|
|
56
108
|
};
|
|
109
|
+
return authorizationRequest
|
|
110
|
+
? {
|
|
111
|
+
type: "array",
|
|
112
|
+
data: [authorizationRequest, uoRequest],
|
|
113
|
+
}
|
|
114
|
+
: uoRequest;
|
|
57
115
|
}
|
|
58
116
|
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,GAGN,MAAM,MAAM,CAAC;AAKd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAajE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAMC,EACD,MAA0B;IAE1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAE7E,gEAAgE;IAChE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE;YACN,MAAM,CAAC,YAAY,EAAE,WAAW;gBAC9B,CAAC,CAAC;oBACE,aAAa,EAAE,MAAM,CAAC,IAAI;oBAC1B,YAAY,EAAE;wBACZ,WAAW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IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAwB;YAC9B,IAAI,EAAE;gBACJ,GAAG,EAAE,MAAM;aACZ;YACD,UAAU,EAAE,WAAW,CAAC;gBACtB,GAAG,EAAE,MAAM;aACZ,CAAC;SACH;KACF,CAAC;IAEF,OAAO,oBAAoB;QACzB,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC;SACxC;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n hashMessage,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type {\n wallet_prepareCalls,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorizationRequest, isDelegated } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n params.capabilities?.eip7702Auth\n ? {\n signerAddress: params.from,\n creationHint: {\n accountType: \"7702\",\n },\n includeCounterfactualInfo: true,\n }\n : {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n const authorizationRequest =\n delegation &&\n !(await isDelegated(client, {\n address: account.address,\n delegation,\n }))\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (params.capabilities?.permissions && authorizationRequest) {\n // The user shouldn't see this in most cases since we require\n // the account to be delegated before creating the session.\n throw new InvalidRequestError({\n message:\n \"When using a 7702 account with a session key, the account must be delegated before preparing calls.\",\n });\n }\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: {\n ...params.capabilities?.gasParamsOverride,\n nonceKey: params.capabilities?.nonceOverride?.nonceKey\n ? fromHex(params.capabilities.nonceOverride.nonceKey, \"bigint\")\n : undefined,\n },\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by a separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n\n const hexlifiedUo = deepHexlify(builtUo);\n\n const ep = account.getEntryPoint();\n\n const uoHash = ep.getUserOperationHash(hexlifiedUo);\n\n const uoRequest = {\n type:\n ep.version === \"0.7.0\"\n ? (\"user-operation-v070\" as const)\n : ep.version === \"0.6.0\"\n ? (\"user-operation-v060\" as const)\n : assertNever(ep.version, \"Unexpected entry point version\"),\n data: hexlifiedUo,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: \"personal_sign\" as const,\n data: {\n raw: uoHash,\n },\n rawPayload: hashMessage({\n raw: uoHash,\n }),\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Static } from "@sinclair/typebox";
|
|
2
|
+
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
3
|
+
import { type Chain, type Transport } from "viem";
|
|
4
|
+
import type { wallet_prepareSign, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
+
export type PrepareSignParams = Static<(typeof wallet_prepareSign)["properties"]["Request"]["properties"]["params"]>[0];
|
|
6
|
+
export type PrepareSignResult = Static<(typeof wallet_prepareSign)["properties"]["ReturnType"]>;
|
|
7
|
+
export declare function prepareSign(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: PrepareSignParams): Promise<PrepareSignResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ChainNotFoundError, custom, toHex, } from "viem";
|
|
2
|
+
import { TypeSignableMessage, jsonSafeTypedData, } from "@alchemy/wallet-api-types";
|
|
3
|
+
import { createAccount } from "../utils/createAccount.js";
|
|
4
|
+
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
5
|
+
import { Value } from "@sinclair/typebox/value";
|
|
6
|
+
export async function prepareSign(client, params) {
|
|
7
|
+
if (!client.chain) {
|
|
8
|
+
throw new ChainNotFoundError();
|
|
9
|
+
}
|
|
10
|
+
const { counterfactualInfo, delegation } = await client.request({
|
|
11
|
+
method: "wallet_requestAccount",
|
|
12
|
+
params: [
|
|
13
|
+
{
|
|
14
|
+
accountAddress: params.from,
|
|
15
|
+
includeCounterfactualInfo: true,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
const account = await createAccount({
|
|
20
|
+
chain: client.chain,
|
|
21
|
+
transport: custom(client.transport),
|
|
22
|
+
signer: createDummySigner(params.from),
|
|
23
|
+
accountAddress: params.from,
|
|
24
|
+
counterfactualInfo,
|
|
25
|
+
permissions: params.capabilities?.permissions,
|
|
26
|
+
delegation,
|
|
27
|
+
});
|
|
28
|
+
const signatureRequest = await account.prepareSign(params.signatureRequest);
|
|
29
|
+
if (signatureRequest.type === "personal_sign") {
|
|
30
|
+
return {
|
|
31
|
+
chainId: toHex(client.chain.id),
|
|
32
|
+
signatureRequest: {
|
|
33
|
+
type: signatureRequest.type,
|
|
34
|
+
data: Value.Encode(TypeSignableMessage, signatureRequest.data),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const typedData = signatureRequest.data;
|
|
40
|
+
return {
|
|
41
|
+
chainId: toHex(client.chain.id),
|
|
42
|
+
signatureRequest: {
|
|
43
|
+
type: signatureRequest.type,
|
|
44
|
+
data: jsonSafeTypedData(typedData),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=prepareSign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareSign.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,KAAK,GAGN,MAAM,MAAM,CAAC;AAKd,OAAO,EACL,mBAAmB,EACnB,iBAA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AE,gBAAgB,CAAC,IAAI,CAAC;aAC/D;SACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC;QAExC,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,gBAAgB,EAAE;gBAChB,IAAI,EAAE,gBAAgB,CAAC,IAAI;gBAC3B,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC;aACnC;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { Static } from \"@sinclair/typebox\";\nimport type {\n SignatureRequest,\n SmartAccountClient,\n SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n ChainNotFoundError,\n custom,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type {\n wallet_prepareSign,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport {\n TypeSignableMessage,\n jsonSafeTypedData,\n} from \"@alchemy/wallet-api-types\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { Value } from \"@sinclair/typebox/value\";\n\nexport type PrepareSignParams = Static<\n (typeof wallet_prepareSign)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type PrepareSignResult = Static<\n (typeof wallet_prepareSign)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareSign(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n const signatureRequest = await account.prepareSign(\n params.signatureRequest as SignatureRequest,\n );\n\n if (signatureRequest.type === \"personal_sign\") {\n return {\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: signatureRequest.type,\n data: Value.Encode(TypeSignableMessage, signatureRequest.data),\n },\n };\n } else {\n const typedData = signatureRequest.data;\n\n return {\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: signatureRequest.type,\n data: jsonSafeTypedData(typedData),\n },\n };\n }\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
3
2
|
import { type Chain, type Transport } from "viem";
|
|
4
|
-
import type { wallet_sendPreparedCalls } from "
|
|
5
|
-
import type {
|
|
6
|
-
export type SendPreparedCallsParams =
|
|
3
|
+
import type { wallet_sendPreparedCalls, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import type { Static } from "@sinclair/typebox";
|
|
5
|
+
export type SendPreparedCallsParams = Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0];
|
|
7
6
|
export type SendPreparedCallsResult = Static<(typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]>;
|
|
8
7
|
export declare function sendPreparedCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: SendPreparedCallsParams): Promise<SendPreparedCallsResult>;
|
|
@@ -1,43 +1,156 @@
|
|
|
1
1
|
import { getEntryPoint, } from "@aa-sdk/core";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { ChainNotFoundError, concat, concatHex, toHex, } from "viem";
|
|
4
|
-
import { decodePermissionsContext } from "
|
|
5
|
-
import { TypeCallId } from "
|
|
3
|
+
import { BaseError, ChainNotFoundError, concat, concatHex, numberToHex, parseSignature, toHex, } from "viem";
|
|
4
|
+
import { decodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
|
|
5
|
+
import { TypeCallId } from "@alchemy/wallet-api-types";
|
|
6
|
+
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
7
|
+
import { InvalidRequestError } from "ox/RpcResponse";
|
|
8
|
+
import { assertNever } from "../../utils.js";
|
|
9
|
+
import { decodeSignature } from "../utils/decodeSignature.js";
|
|
6
10
|
// TODO: this only supports MAv2 right now, we need to fix this
|
|
7
11
|
export async function sendPreparedCalls(client, params) {
|
|
8
12
|
if (!client.chain) {
|
|
9
13
|
throw new ChainNotFoundError();
|
|
10
14
|
}
|
|
11
15
|
const deferredAction = (() => {
|
|
12
|
-
if (!params.capabilities?.permissions
|
|
16
|
+
if (!params.capabilities?.permissions) {
|
|
13
17
|
return;
|
|
14
18
|
}
|
|
15
|
-
const decodedContext = decodePermissionsContext(params.capabilities.permissions
|
|
19
|
+
const decodedContext = decodePermissionsContext(params.capabilities.permissions);
|
|
16
20
|
if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
17
|
-
throw new
|
|
21
|
+
throw new InvalidRequestError({
|
|
22
|
+
message: "Remote mode deferred action not supported in isomorphic client",
|
|
23
|
+
});
|
|
18
24
|
}
|
|
19
25
|
return decodedContext.deferredAction;
|
|
20
26
|
})();
|
|
21
|
-
const
|
|
22
|
-
?
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const userOps = params.type === "array"
|
|
28
|
+
? params.data.filter((it) => {
|
|
29
|
+
const isUserOp = it.type === "user-operation-v060" ||
|
|
30
|
+
it.type === "user-operation-v070";
|
|
31
|
+
if (isUserOp && it.chainId !== toHex(client.chain.id)) {
|
|
32
|
+
throw new InvalidRequestError({
|
|
33
|
+
message: "Multiple chain IDs in a single request are not currently supported.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return isUserOp;
|
|
37
|
+
})
|
|
38
|
+
: [params];
|
|
39
|
+
if (!userOps.length) {
|
|
40
|
+
throw new InvalidRequestError({
|
|
41
|
+
message: "Calls must include at least one user operation",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const authorizations = params.type === "array"
|
|
45
|
+
? params.data.filter((it) => it.type === "authorization")
|
|
46
|
+
: [];
|
|
47
|
+
if (authorizations.length > 1) {
|
|
48
|
+
throw new InvalidRequestError({
|
|
49
|
+
message: "Multiple authorizations in a single request are not currently supported",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const [authorization] = authorizations;
|
|
53
|
+
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
54
|
+
if (authorization &&
|
|
55
|
+
!isSupportedDelegationAddress7702(authorization.data.address)) {
|
|
56
|
+
throw new InvalidRequestError({
|
|
57
|
+
message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const hashes = await Promise.all(userOps.map(async (userOp, idx) => {
|
|
61
|
+
const ep = userOp.type === "user-operation-v060"
|
|
62
|
+
? getEntryPoint(client.chain, { version: "0.6.0" })
|
|
63
|
+
: userOp.type === "user-operation-v070"
|
|
64
|
+
? getEntryPoint(client.chain, { version: "0.7.0" })
|
|
65
|
+
: assertNever(userOp, "Unexpected user op type");
|
|
66
|
+
const authSig = authorization
|
|
67
|
+
? parseSignature(decodeSignature(authorization.signature).data)
|
|
68
|
+
: undefined;
|
|
69
|
+
const uoSigHex = decodeSignature(userOp.signature).data;
|
|
70
|
+
const { counterfactualInfo, delegation } = await client.request({
|
|
71
|
+
method: "wallet_requestAccount",
|
|
72
|
+
params: [
|
|
73
|
+
{
|
|
74
|
+
accountAddress: userOp.data.sender,
|
|
75
|
+
includeCounterfactualInfo: true,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
if (!counterfactualInfo && !delegation) {
|
|
80
|
+
throw new InvalidRequestError({
|
|
81
|
+
message: "No counterfactual info or delegated implementation address found.",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const factoryType = counterfactualInfo?.factoryType;
|
|
85
|
+
// build signature based on account type
|
|
86
|
+
const signature = (() => {
|
|
87
|
+
switch (factoryType) {
|
|
88
|
+
// light accounts
|
|
89
|
+
case "LightAccountV1.0.1":
|
|
90
|
+
case "LightAccountV1.0.2":
|
|
91
|
+
case "LightAccountV1.1.0":
|
|
92
|
+
case "MAv1.0.0-MultiOwner":
|
|
93
|
+
// For LAv1 and MAv1-MultiOwner, we always just pass the signature.
|
|
94
|
+
return uoSigHex;
|
|
95
|
+
case "LightAccountV2.0.0":
|
|
96
|
+
// for LAv2, we need to prepend the "SignatureType.EOA" byte.
|
|
97
|
+
// TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
|
|
98
|
+
return concat(["0x00", uoSigHex]);
|
|
99
|
+
case undefined: // undefined defaults to sma-b
|
|
100
|
+
case "MAv2.0.0-sma-b":
|
|
101
|
+
// For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
|
|
102
|
+
// Signature Segment" and "SignatureType.EOA" bytes
|
|
103
|
+
return deferredAction != null
|
|
104
|
+
? concatHex([
|
|
105
|
+
`0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
|
|
106
|
+
"0xFF",
|
|
107
|
+
"0x00",
|
|
108
|
+
uoSigHex,
|
|
109
|
+
])
|
|
110
|
+
: concat(["0xFF", "0x00", uoSigHex]);
|
|
111
|
+
case "LightAccountV2.0.0-MultiOwner":
|
|
112
|
+
// for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
|
|
113
|
+
// TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
|
|
114
|
+
return concat(["0x00", uoSigHex]);
|
|
115
|
+
case "MAv2.0.0-ma-ssv":
|
|
116
|
+
case "MAv2.0.0-ma-webauthn":
|
|
117
|
+
case "MAv1.0.0-MultiSig":
|
|
118
|
+
case "unknown":
|
|
119
|
+
throw new InvalidRequestError({
|
|
120
|
+
message: `Unsupported factory type: ${factoryType}`,
|
|
121
|
+
});
|
|
122
|
+
default:
|
|
123
|
+
return assertNever(factoryType, "Unsupported factory type");
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
return client
|
|
127
|
+
.sendRawUserOperation({
|
|
128
|
+
...userOp.data,
|
|
129
|
+
signature,
|
|
130
|
+
eip7702Auth: idx === 0 && authorization && authSig
|
|
131
|
+
? {
|
|
132
|
+
...authorization.data,
|
|
133
|
+
chainId: authorization.chainId,
|
|
134
|
+
...{
|
|
135
|
+
...authSig,
|
|
136
|
+
yParity: numberToHex(authSig.yParity),
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
: undefined,
|
|
140
|
+
}, ep.address)
|
|
141
|
+
.catch((err) => {
|
|
142
|
+
if (err instanceof BaseError &&
|
|
143
|
+
err.details.endsWith("is not a contract and initCode is empty")) {
|
|
144
|
+
throw new BaseError(`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`);
|
|
145
|
+
}
|
|
146
|
+
throw err;
|
|
147
|
+
});
|
|
148
|
+
}));
|
|
39
149
|
return {
|
|
40
|
-
preparedCallIds:
|
|
150
|
+
preparedCallIds: hashes.map((hash) => Value.Encode(TypeCallId, {
|
|
151
|
+
chainId: toHex(client.chain.id),
|
|
152
|
+
hash,
|
|
153
|
+
})),
|
|
41
154
|
};
|
|
42
155
|
}
|
|
43
156
|
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names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P,cAAc,IAAI,IAAI;YACpB,CAAC,CAAC,SAAS,CAAC;gBACR,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,gFAAgF;gBACjH,MAAM;gBACN,MAAM;gBACN,MAAM,CAAC,SAAS,CAAC,SAAS;aAC3B,CAAC;YACJ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;KAC3D,EACD,UAAU,CAAC,OAAO,CACnB,CAAC;IAEF,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QACtC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,IAAI;KACL,CAAC,CAAC;IAEH,OAAO;QACL,eAAe,EAAE,CAAC,MAAM,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static, StaticDecode } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n concat,\n concatHex,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\n\nexport type SendPreparedCallsParams = Omit<\n StaticDecode<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions?.context) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions.context,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new Error(\n \"Remote mode deferred action not supported in isomorphic client\",\n );\n }\n\n return decodedContext.deferredAction;\n })();\n\n const entryPoint =\n params.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : getEntryPoint(client.chain, { version: \"0.7.0\" });\n\n const hash = await client.sendRawUserOperation(\n {\n ...params.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n params.signature.signature,\n ])\n : concat([\"0xFF\", \"0x00\", params.signature.signature]),\n },\n entryPoint.address,\n );\n\n const callId = Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n });\n\n return {\n preparedCallIds: [callId],\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,WAAW,EACX,cAAc,EACd,KAAK,GAKN,MAAM,MAAM,CAAC;AAKd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gCAAgC,EAAE,MAAM,k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ACzG,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,IAAI;SACL,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n numberToHex,\n parseSignature,\n toHex,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport type {\n wallet_sendPreparedCalls,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { decodePermissionsContext } from \"@alchemy/wallet-api-types/capabilities\";\nimport { TypeCallId } from \"@alchemy/wallet-api-types\";\nimport { isSupportedDelegationAddress7702 } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { decodeSignature } from \"../utils/decodeSignature.js\";\n\nexport type SendPreparedCallsParams = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const userOps =\n params.type === \"array\"\n ? params.data.filter((it) => {\n const isUserOp =\n it.type === \"user-operation-v060\" ||\n it.type === \"user-operation-v070\";\n if (isUserOp && it.chainId !== toHex(client.chain.id)) {\n throw new InvalidRequestError({\n message:\n \"Multiple chain IDs in a single request are not currently supported.\",\n });\n }\n return isUserOp;\n })\n : [params];\n\n if (!userOps.length) {\n throw new InvalidRequestError({\n message: \"Calls must include at least one user operation\",\n });\n }\n\n const authorizations =\n params.type === \"array\"\n ? params.data.filter((it) => it.type === \"authorization\")\n : [];\n\n if (authorizations.length > 1) {\n throw new InvalidRequestError({\n message:\n \"Multiple authorizations in a single request are not currently supported\",\n });\n }\n const [authorization] = authorizations;\n\n // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n authorization &&\n !isSupportedDelegationAddress7702(authorization.data.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${authorization.data.address}`,\n });\n }\n\n const hashes = await Promise.all(\n userOps.map(async (userOp, idx) => {\n const ep: { address: Address } =\n userOp.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : userOp.type === \"user-operation-v070\"\n ? getEntryPoint(client.chain, { version: \"0.7.0\" })\n : assertNever(userOp, \"Unexpected user op type\");\n const authSig = authorization\n ? parseSignature(decodeSignature(authorization.signature).data)\n : undefined;\n const uoSigHex = decodeSignature(userOp.signature).data;\n\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: userOp.data.sender,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const factoryType = counterfactualInfo?.factoryType;\n\n // build signature based on account type\n const signature = (() => {\n switch (factoryType) {\n // light accounts\n case \"LightAccountV1.0.1\":\n case \"LightAccountV1.0.2\":\n case \"LightAccountV1.1.0\":\n case \"MAv1.0.0-MultiOwner\":\n // For LAv1 and MAv1-MultiOwner, we always just pass the signature.\n return uoSigHex;\n case \"LightAccountV2.0.0\":\n // for LAv2, we need to prepend the \"SignatureType.EOA\" byte.\n // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.\n return concat([\"0x00\", uoSigHex]);\n case undefined: // undefined defaults to sma-b\n case \"MAv2.0.0-sma-b\":\n // For sma-b, we need to handle deferred actions if needed and prepend the \"Reserved\n // Signature Segment\" and \"SignatureType.EOA\" bytes\n return deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).\n \"0xFF\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]);\n case \"LightAccountV2.0.0-MultiOwner\":\n // for LAv2-MultiOwner, we need to prepend the \"SignatureType.EOA\" byte\n // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.\n return concat([\"0x00\", uoSigHex]);\n case \"MAv2.0.0-ma-ssv\":\n case \"MAv2.0.0-ma-webauthn\":\n case \"MAv1.0.0-MultiSig\":\n case \"unknown\":\n throw new InvalidRequestError({\n message: `Unsupported factory type: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n })();\n\n return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature,\n eip7702Auth:\n idx === 0 && authorization && authSig\n ? {\n ...authorization.data,\n chainId: authorization.chainId,\n ...{\n ...authSig,\n yParity: numberToHex(authSig.yParity),\n },\n }\n : undefined,\n },\n ep.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,\n );\n }\n throw err;\n });\n }),\n );\n\n return {\n preparedCallIds: hashes.map((hash) =>\n Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n }),\n ),\n };\n}\n"]}
|