@account-kit/wallet-client 0.1.0-alpha.9 → 4.50.1
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/LICENSE +21 -0
- package/dist/esm/client/actions/formatSign.d.ts +30 -0
- package/dist/esm/client/actions/formatSign.js +32 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/esm/client/actions/getCallsStatus.js +3 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +10 -11
- package/dist/esm/client/actions/grantPermissions.js +26 -12
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +10 -3
- package/dist/esm/client/actions/listAccounts.js +14 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +6 -3
- package/dist/esm/client/actions/prepareCalls.js +12 -8
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +28 -0
- package/dist/esm/client/actions/prepareSign.js +31 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +3 -1
- package/dist/esm/client/actions/requestAccount.js +5 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/esm/client/actions/sendPreparedCalls.js +2 -0
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +5 -2
- package/dist/esm/client/actions/signMessage.js +5 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/esm/client/actions/signPreparedCalls.js +3 -3
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/esm/client/actions/signSignatureRequest.js +4 -7
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +2 -0
- package/dist/esm/client/actions/signTypedData.js +2 -0
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +0 -2
- package/dist/esm/client/decorator.js +1 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +10 -6
- package/dist/esm/client/index.js +18 -21
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +1 -5
- package/dist/esm/exports/index.js +1 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/internal/account.d.ts +33 -0
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +25 -49
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +5 -11
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +13 -1
- package/dist/esm/utils.js +13 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +4 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/client/actions/formatSign.d.ts +31 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +10 -11
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +10 -3
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +6 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +29 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +3 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +5 -2
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +2 -0
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +0 -2
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +10 -6
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +1 -5
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/internal/account.d.ts +34 -0
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +5 -11
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +13 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +32 -28
- package/src/client/actions/formatSign.ts +55 -0
- package/src/client/actions/getCallsStatus.ts +10 -6
- package/src/client/actions/grantPermissions.ts +46 -18
- package/src/client/actions/listAccounts.ts +22 -5
- package/src/client/actions/prepareCalls.ts +22 -16
- package/src/client/actions/prepareSign.ts +51 -0
- package/src/client/actions/requestAccount.ts +6 -4
- package/src/client/actions/sendPreparedCalls.ts +3 -1
- package/src/client/actions/signMessage.ts +5 -2
- package/src/client/actions/signPreparedCalls.ts +8 -12
- package/src/client/actions/signSignatureRequest.ts +12 -15
- package/src/client/actions/signTypedData.ts +2 -0
- package/src/client/decorator.ts +1 -8
- package/src/client/index.ts +41 -33
- package/src/exports/index.ts +1 -13
- package/src/internal/account.ts +120 -0
- package/src/types.ts +7 -18
- package/src/utils.ts +13 -1
- package/src/version.ts +3 -0
- package/dist/esm/capabilities/eip7702Auth.d.ts +0 -4
- package/dist/esm/capabilities/eip7702Auth.js +0 -18
- package/dist/esm/capabilities/eip7702Auth.js.map +0 -1
- package/dist/esm/capabilities/index.d.ts +0 -41
- package/dist/esm/capabilities/index.js +0 -14
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/multiDimensionalNonce.d.ts +0 -3
- package/dist/esm/capabilities/multiDimensionalNonce.js +0 -7
- package/dist/esm/capabilities/multiDimensionalNonce.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 -145
- package/dist/esm/capabilities/permissions/index.js +0 -83
- 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 -88
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/client/actions/createAccount.d.ts +0 -35
- package/dist/esm/client/actions/createAccount.js +0 -32
- package/dist/esm/client/actions/createAccount.js.map +0 -1
- package/dist/esm/client/client.e2e-test.d.ts +0 -1
- package/dist/esm/client/client.e2e-test.js +0 -375
- package/dist/esm/client/client.e2e-test.js.map +0 -1
- package/dist/esm/exports/internal.d.ts +0 -14
- package/dist/esm/exports/internal.js +0 -16
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/esm/isomorphic/actions/createSession.js +0 -95
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -157
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -239
- package/dist/esm/isomorphic/client.js +0 -37
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -23
- package/dist/esm/isomorphic/utils/7702.js +0 -75
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -24
- package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
- package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
- package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
- package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
- package/dist/esm/local/client.d.ts +0 -3
- package/dist/esm/local/client.js +0 -97
- package/dist/esm/local/client.js.map +0 -1
- package/dist/esm/remote/client.d.ts +0 -9
- package/dist/esm/remote/client.js +0 -41
- package/dist/esm/remote/client.js.map +0 -1
- package/dist/esm/rpc/examples.d.ts +0 -230
- package/dist/esm/rpc/examples.js +0 -314
- package/dist/esm/rpc/examples.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -755
- package/dist/esm/rpc/request.js +0 -214
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -703
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -712
- package/dist/esm/schemas.js +0 -463
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
- package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -42
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/multiDimensionalNonce.d.ts +0 -4
- package/dist/types/capabilities/multiDimensionalNonce.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 -146
- 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/client/actions/createAccount.d.ts +0 -36
- package/dist/types/client/actions/createAccount.d.ts.map +0 -1
- package/dist/types/client/client.e2e-test.d.ts +0 -2
- package/dist/types/client/client.e2e-test.d.ts.map +0 -1
- package/dist/types/exports/internal.d.ts +0 -15
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -240
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -24
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts +0 -25
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
- package/dist/types/local/client.d.ts +0 -4
- package/dist/types/local/client.d.ts.map +0 -1
- package/dist/types/remote/client.d.ts +0 -10
- package/dist/types/remote/client.d.ts.map +0 -1
- package/dist/types/rpc/examples.d.ts +0 -231
- package/dist/types/rpc/examples.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -756
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -704
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -713
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/eip7702Auth.ts +0 -26
- package/src/capabilities/index.ts +0 -14
- package/src/capabilities/multiDimensionalNonce.ts +0 -7
- package/src/capabilities/overrides.ts +0 -35
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -163
- package/src/capabilities/permissions/mav2.ts +0 -138
- package/src/client/actions/createAccount.ts +0 -53
- package/src/client/client.e2e-test.ts +0 -463
- package/src/exports/internal.ts +0 -17
- package/src/isomorphic/actions/createSession.ts +0 -159
- package/src/isomorphic/actions/getCallsStatus.ts +0 -170
- package/src/isomorphic/actions/prepareCalls.ts +0 -170
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -232
- package/src/isomorphic/client.ts +0 -94
- package/src/isomorphic/utils/7702.ts +0 -143
- package/src/isomorphic/utils/createAccount.ts +0 -170
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -18
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- package/src/remote/client.ts +0 -67
- package/src/rpc/examples.ts +0 -342
- package/src/rpc/request.ts +0 -300
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -657
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { getEntryPoint, } from "@aa-sdk/core";
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { BaseError, ChainNotFoundError, concat, concatHex, numberToHex, parseSignature, toHex, } from "viem";
|
|
4
|
-
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
5
|
-
import {} from "../../rpc/request.js";
|
|
6
|
-
import { TypeCallId } from "../../schemas.js";
|
|
7
|
-
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
8
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
9
|
-
import { assertNever } from "../../utils.js";
|
|
10
|
-
import { decodeSignature } from "../utils/decodeSignature.js";
|
|
11
|
-
// TODO: this only supports MAv2 right now, we need to fix this
|
|
12
|
-
export async function sendPreparedCalls(client, params) {
|
|
13
|
-
if (!client.chain) {
|
|
14
|
-
throw new ChainNotFoundError();
|
|
15
|
-
}
|
|
16
|
-
const deferredAction = (() => {
|
|
17
|
-
if (!params.capabilities?.permissions) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const decodedContext = decodePermissionsContext(params.capabilities.permissions);
|
|
21
|
-
if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
22
|
-
throw new InvalidRequestError({
|
|
23
|
-
message: "Remote mode deferred action not supported in isomorphic client",
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return decodedContext.deferredAction;
|
|
27
|
-
})();
|
|
28
|
-
const userOps = params.type === "array"
|
|
29
|
-
? params.data.filter((it) => {
|
|
30
|
-
const isUserOp = it.type === "user-operation-v060" ||
|
|
31
|
-
it.type === "user-operation-v070";
|
|
32
|
-
if (isUserOp && it.chainId !== toHex(client.chain.id)) {
|
|
33
|
-
throw new InvalidRequestError({
|
|
34
|
-
message: "Multiple chain IDs in a single request are not currently supported.",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return isUserOp;
|
|
38
|
-
})
|
|
39
|
-
: [params];
|
|
40
|
-
if (!userOps.length) {
|
|
41
|
-
throw new InvalidRequestError({
|
|
42
|
-
message: "Calls must include at least one user operation",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const authorizations = params.type === "array"
|
|
46
|
-
? params.data.filter((it) => it.type === "authorization")
|
|
47
|
-
: [];
|
|
48
|
-
if (authorizations.length > 1) {
|
|
49
|
-
throw new InvalidRequestError({
|
|
50
|
-
message: "Multiple authorizations in a single request are not currently supported",
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
const [authorization] = authorizations;
|
|
54
|
-
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
55
|
-
if (authorization &&
|
|
56
|
-
!isSupportedDelegationAddress7702(authorization.data.address)) {
|
|
57
|
-
throw new InvalidRequestError({
|
|
58
|
-
message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const hashes = await Promise.all(userOps.map(async (userOp, idx) => {
|
|
62
|
-
const ep = userOp.type === "user-operation-v060"
|
|
63
|
-
? getEntryPoint(client.chain, { version: "0.6.0" })
|
|
64
|
-
: userOp.type === "user-operation-v070"
|
|
65
|
-
? getEntryPoint(client.chain, { version: "0.7.0" })
|
|
66
|
-
: assertNever(userOp, "Unexpected user op type");
|
|
67
|
-
const authSig = authorization
|
|
68
|
-
? parseSignature(decodeSignature(authorization.signature).data)
|
|
69
|
-
: undefined;
|
|
70
|
-
const uoSigHex = decodeSignature(userOp.signature).data;
|
|
71
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
72
|
-
method: "wallet_requestAccount",
|
|
73
|
-
params: [
|
|
74
|
-
{
|
|
75
|
-
accountAddress: userOp.data.sender,
|
|
76
|
-
includeCounterfactualInfo: true,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
});
|
|
80
|
-
if (!counterfactualInfo && !delegation) {
|
|
81
|
-
throw new InvalidRequestError({
|
|
82
|
-
message: "No counterfactual info or delegated implementation address found.",
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
const factoryType = counterfactualInfo?.factoryType;
|
|
86
|
-
// build signature based on account type
|
|
87
|
-
const signature = (() => {
|
|
88
|
-
switch (factoryType) {
|
|
89
|
-
// light accounts
|
|
90
|
-
case "LightAccountV1.0.1":
|
|
91
|
-
case "LightAccountV1.0.2":
|
|
92
|
-
case "LightAccountV1.1.0":
|
|
93
|
-
case "MAv1.0.0-MultiOwner":
|
|
94
|
-
// For LAv1 and MAv1-MultiOwner, we always just pass the signature.
|
|
95
|
-
return uoSigHex;
|
|
96
|
-
case "LightAccountV2.0.0":
|
|
97
|
-
// for LAv2, we need to prepend the "SignatureType.EOA" byte.
|
|
98
|
-
// TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
|
|
99
|
-
return concat(["0x00", uoSigHex]);
|
|
100
|
-
case undefined: // undefined defaults to sma-b
|
|
101
|
-
case "MAv2.0.0-sma-b":
|
|
102
|
-
// For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
|
|
103
|
-
// Signature Segment" and "SignatureType.EOA" bytes
|
|
104
|
-
return deferredAction != null
|
|
105
|
-
? concatHex([
|
|
106
|
-
`0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
|
|
107
|
-
"0xFF",
|
|
108
|
-
"0x00",
|
|
109
|
-
uoSigHex,
|
|
110
|
-
])
|
|
111
|
-
: concat(["0xFF", "0x00", uoSigHex]);
|
|
112
|
-
case "LightAccountV2.0.0-MultiOwner":
|
|
113
|
-
// for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
|
|
114
|
-
// TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
|
|
115
|
-
return concat(["0x00", uoSigHex]);
|
|
116
|
-
case "MAv2.0.0-ma-ssv":
|
|
117
|
-
case "MAv2.0.0-ma-webauthn":
|
|
118
|
-
case "MAv1.0.0-MultiSig":
|
|
119
|
-
case "unknown":
|
|
120
|
-
throw new InvalidRequestError({
|
|
121
|
-
message: `Unsupported factory type: ${factoryType}`,
|
|
122
|
-
});
|
|
123
|
-
default:
|
|
124
|
-
return assertNever(factoryType, "Unsupported factory type");
|
|
125
|
-
}
|
|
126
|
-
})();
|
|
127
|
-
return client
|
|
128
|
-
.sendRawUserOperation({
|
|
129
|
-
...userOp.data,
|
|
130
|
-
signature,
|
|
131
|
-
eip7702Auth: idx === 0 && authorization && authSig
|
|
132
|
-
? {
|
|
133
|
-
...authorization.data,
|
|
134
|
-
chainId: authorization.chainId,
|
|
135
|
-
...{
|
|
136
|
-
...authSig,
|
|
137
|
-
yParity: numberToHex(authSig.yParity),
|
|
138
|
-
},
|
|
139
|
-
}
|
|
140
|
-
: undefined,
|
|
141
|
-
}, ep.address)
|
|
142
|
-
.catch((err) => {
|
|
143
|
-
if (err instanceof BaseError &&
|
|
144
|
-
err.details.endsWith("is not a contract and initCode is empty")) {
|
|
145
|
-
throw new BaseError(`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`);
|
|
146
|
-
}
|
|
147
|
-
throw err;
|
|
148
|
-
});
|
|
149
|
-
}));
|
|
150
|
-
return {
|
|
151
|
-
preparedCallIds: hashes.map((hash) => Value.Encode(TypeCallId, {
|
|
152
|
-
chainId: toHex(client.chain.id),
|
|
153
|
-
hash,
|
|
154
|
-
})),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAiC,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAU9D,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAMC,EACD,MAA+B;IAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACj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Content":["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 { 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\";\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"]}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartAccountClientRpcSchema, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import { type Chain, type Transport } from "viem";
|
|
3
|
-
import type { WalletServerViemRpcSchema } from "../rpc/schema.js";
|
|
4
|
-
import { type CreateSessionParams } from "./actions/createSession.js";
|
|
5
|
-
import { type GetCallsStatusParams } from "./actions/getCallsStatus.js";
|
|
6
|
-
import { type PrepareCallsParams } from "./actions/prepareCalls.js";
|
|
7
|
-
import { type SendPreparedCallsParams } from "./actions/sendPreparedCalls.js";
|
|
8
|
-
type ClientParams = {
|
|
9
|
-
chain: Chain;
|
|
10
|
-
transport: Transport;
|
|
11
|
-
policyId?: string;
|
|
12
|
-
useErc7677middleware?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare function isomorphicClientActions(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>): {
|
|
15
|
-
prepareCalls: (params: PrepareCallsParams) => Promise<{
|
|
16
|
-
type: "array";
|
|
17
|
-
data: ({
|
|
18
|
-
type: "user-operation-v060";
|
|
19
|
-
chainId: `0x${string}`;
|
|
20
|
-
data: {
|
|
21
|
-
sender: `0x${string}`;
|
|
22
|
-
nonce: `0x${string}`;
|
|
23
|
-
initCode: `0x${string}`;
|
|
24
|
-
callData: `0x${string}`;
|
|
25
|
-
callGasLimit: `0x${string}`;
|
|
26
|
-
verificationGasLimit: `0x${string}`;
|
|
27
|
-
preVerificationGas: `0x${string}`;
|
|
28
|
-
maxFeePerGas: `0x${string}`;
|
|
29
|
-
maxPriorityFeePerGas: `0x${string}`;
|
|
30
|
-
paymasterAndData: `0x${string}`;
|
|
31
|
-
};
|
|
32
|
-
signatureRequest: {
|
|
33
|
-
type: "eth_signTypedData_v4";
|
|
34
|
-
data: {
|
|
35
|
-
domain?: {
|
|
36
|
-
chainId?: number | undefined;
|
|
37
|
-
salt?: `0x${string}` | undefined;
|
|
38
|
-
name?: string | undefined;
|
|
39
|
-
verifyingContract?: `0x${string}` | undefined;
|
|
40
|
-
version?: string | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
types: {
|
|
43
|
-
[x: string]: {
|
|
44
|
-
type: string;
|
|
45
|
-
name: string;
|
|
46
|
-
}[];
|
|
47
|
-
};
|
|
48
|
-
primaryType: string;
|
|
49
|
-
message: {
|
|
50
|
-
[x: string]: unknown;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
rawPayload: `0x${string}`;
|
|
54
|
-
} | {
|
|
55
|
-
type: "personal_sign";
|
|
56
|
-
data: string | {
|
|
57
|
-
raw: `0x${string}`;
|
|
58
|
-
};
|
|
59
|
-
rawPayload: `0x${string}`;
|
|
60
|
-
};
|
|
61
|
-
} | {
|
|
62
|
-
type: "user-operation-v070";
|
|
63
|
-
chainId: `0x${string}`;
|
|
64
|
-
data: {
|
|
65
|
-
factory?: `0x${string}` | undefined;
|
|
66
|
-
factoryData?: `0x${string}` | undefined;
|
|
67
|
-
paymaster?: `0x${string}` | undefined;
|
|
68
|
-
paymasterData?: `0x${string}` | undefined;
|
|
69
|
-
paymasterVerificationGasLimit?: `0x${string}` | undefined;
|
|
70
|
-
paymasterPostOpGasLimit?: `0x${string}` | undefined;
|
|
71
|
-
sender: `0x${string}`;
|
|
72
|
-
nonce: `0x${string}`;
|
|
73
|
-
callData: `0x${string}`;
|
|
74
|
-
callGasLimit: `0x${string}`;
|
|
75
|
-
verificationGasLimit: `0x${string}`;
|
|
76
|
-
preVerificationGas: `0x${string}`;
|
|
77
|
-
maxFeePerGas: `0x${string}`;
|
|
78
|
-
maxPriorityFeePerGas: `0x${string}`;
|
|
79
|
-
};
|
|
80
|
-
signatureRequest: {
|
|
81
|
-
type: "eth_signTypedData_v4";
|
|
82
|
-
data: {
|
|
83
|
-
domain?: {
|
|
84
|
-
chainId?: number | undefined;
|
|
85
|
-
salt?: `0x${string}` | undefined;
|
|
86
|
-
name?: string | undefined;
|
|
87
|
-
verifyingContract?: `0x${string}` | undefined;
|
|
88
|
-
version?: string | undefined;
|
|
89
|
-
} | undefined;
|
|
90
|
-
types: {
|
|
91
|
-
[x: string]: {
|
|
92
|
-
type: string;
|
|
93
|
-
name: string;
|
|
94
|
-
}[];
|
|
95
|
-
};
|
|
96
|
-
primaryType: string;
|
|
97
|
-
message: {
|
|
98
|
-
[x: string]: unknown;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
rawPayload: `0x${string}`;
|
|
102
|
-
} | {
|
|
103
|
-
type: "personal_sign";
|
|
104
|
-
data: string | {
|
|
105
|
-
raw: `0x${string}`;
|
|
106
|
-
};
|
|
107
|
-
rawPayload: `0x${string}`;
|
|
108
|
-
};
|
|
109
|
-
} | {
|
|
110
|
-
type: "authorization";
|
|
111
|
-
chainId: `0x${string}`;
|
|
112
|
-
data: {
|
|
113
|
-
nonce: `0x${string}`;
|
|
114
|
-
address: `0x${string}`;
|
|
115
|
-
};
|
|
116
|
-
signatureRequest: {
|
|
117
|
-
type: "eip7702Auth";
|
|
118
|
-
rawPayload: `0x${string}`;
|
|
119
|
-
};
|
|
120
|
-
})[];
|
|
121
|
-
} | {
|
|
122
|
-
type: "user-operation-v060";
|
|
123
|
-
chainId: `0x${string}`;
|
|
124
|
-
data: {
|
|
125
|
-
sender: `0x${string}`;
|
|
126
|
-
nonce: `0x${string}`;
|
|
127
|
-
initCode: `0x${string}`;
|
|
128
|
-
callData: `0x${string}`;
|
|
129
|
-
callGasLimit: `0x${string}`;
|
|
130
|
-
verificationGasLimit: `0x${string}`;
|
|
131
|
-
preVerificationGas: `0x${string}`;
|
|
132
|
-
maxFeePerGas: `0x${string}`;
|
|
133
|
-
maxPriorityFeePerGas: `0x${string}`;
|
|
134
|
-
paymasterAndData: `0x${string}`;
|
|
135
|
-
};
|
|
136
|
-
signatureRequest: {
|
|
137
|
-
type: "eth_signTypedData_v4";
|
|
138
|
-
data: {
|
|
139
|
-
domain?: {
|
|
140
|
-
chainId?: number | undefined;
|
|
141
|
-
salt?: `0x${string}` | undefined;
|
|
142
|
-
name?: string | undefined;
|
|
143
|
-
verifyingContract?: `0x${string}` | undefined;
|
|
144
|
-
version?: string | undefined;
|
|
145
|
-
} | undefined;
|
|
146
|
-
types: {
|
|
147
|
-
[x: string]: {
|
|
148
|
-
type: string;
|
|
149
|
-
name: string;
|
|
150
|
-
}[];
|
|
151
|
-
};
|
|
152
|
-
primaryType: string;
|
|
153
|
-
message: {
|
|
154
|
-
[x: string]: unknown;
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
rawPayload: `0x${string}`;
|
|
158
|
-
} | {
|
|
159
|
-
type: "personal_sign";
|
|
160
|
-
data: string | {
|
|
161
|
-
raw: `0x${string}`;
|
|
162
|
-
};
|
|
163
|
-
rawPayload: `0x${string}`;
|
|
164
|
-
};
|
|
165
|
-
} | {
|
|
166
|
-
type: "user-operation-v070";
|
|
167
|
-
chainId: `0x${string}`;
|
|
168
|
-
data: {
|
|
169
|
-
factory?: `0x${string}` | undefined;
|
|
170
|
-
factoryData?: `0x${string}` | undefined;
|
|
171
|
-
paymaster?: `0x${string}` | undefined;
|
|
172
|
-
paymasterData?: `0x${string}` | undefined;
|
|
173
|
-
paymasterVerificationGasLimit?: `0x${string}` | undefined;
|
|
174
|
-
paymasterPostOpGasLimit?: `0x${string}` | undefined;
|
|
175
|
-
sender: `0x${string}`;
|
|
176
|
-
nonce: `0x${string}`;
|
|
177
|
-
callData: `0x${string}`;
|
|
178
|
-
callGasLimit: `0x${string}`;
|
|
179
|
-
verificationGasLimit: `0x${string}`;
|
|
180
|
-
preVerificationGas: `0x${string}`;
|
|
181
|
-
maxFeePerGas: `0x${string}`;
|
|
182
|
-
maxPriorityFeePerGas: `0x${string}`;
|
|
183
|
-
};
|
|
184
|
-
signatureRequest: {
|
|
185
|
-
type: "eth_signTypedData_v4";
|
|
186
|
-
data: {
|
|
187
|
-
domain?: {
|
|
188
|
-
chainId?: number | undefined;
|
|
189
|
-
salt?: `0x${string}` | undefined;
|
|
190
|
-
name?: string | undefined;
|
|
191
|
-
verifyingContract?: `0x${string}` | undefined;
|
|
192
|
-
version?: string | undefined;
|
|
193
|
-
} | undefined;
|
|
194
|
-
types: {
|
|
195
|
-
[x: string]: {
|
|
196
|
-
type: string;
|
|
197
|
-
name: string;
|
|
198
|
-
}[];
|
|
199
|
-
};
|
|
200
|
-
primaryType: string;
|
|
201
|
-
message: {
|
|
202
|
-
[x: string]: unknown;
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
rawPayload: `0x${string}`;
|
|
206
|
-
} | {
|
|
207
|
-
type: "personal_sign";
|
|
208
|
-
data: string | {
|
|
209
|
-
raw: `0x${string}`;
|
|
210
|
-
};
|
|
211
|
-
rawPayload: `0x${string}`;
|
|
212
|
-
};
|
|
213
|
-
}>;
|
|
214
|
-
sendPreparedCalls: (params: SendPreparedCallsParams) => Promise<{
|
|
215
|
-
preparedCallIds: `0x${string}`[];
|
|
216
|
-
}>;
|
|
217
|
-
getCallsStatus: (params: GetCallsStatusParams) => Promise<{
|
|
218
|
-
receipts?: {
|
|
219
|
-
status: `0x${string}`;
|
|
220
|
-
logs: {
|
|
221
|
-
address: `0x${string}`;
|
|
222
|
-
data: `0x${string}`;
|
|
223
|
-
topics: `0x${string}`[];
|
|
224
|
-
}[];
|
|
225
|
-
blockHash: `0x${string}`;
|
|
226
|
-
blockNumber: `0x${string}`;
|
|
227
|
-
gasUsed: `0x${string}`;
|
|
228
|
-
transactionHash: `0x${string}`;
|
|
229
|
-
}[] | undefined;
|
|
230
|
-
chainId: `0x${string}`;
|
|
231
|
-
id: `0x${string}`;
|
|
232
|
-
atomic: boolean;
|
|
233
|
-
status: 200 | 100 | 400 | 500 | 600;
|
|
234
|
-
}>;
|
|
235
|
-
createSession: (params: CreateSessionParams) => Promise<import("./actions/createSession.js").CreateSessionResult>;
|
|
236
|
-
};
|
|
237
|
-
export declare function createIsomorphicClient({ chain, transport, policyId, useErc7677middleware, }: ClientParams): SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, ReturnType<typeof isomorphicClientActions>, WalletServerViemRpcSchema & SmartAccountClientRpcSchema>;
|
|
238
|
-
export type IsomorphicClient = ReturnType<typeof createIsomorphicClient>;
|
|
239
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createSmartAccountClient, } from "@aa-sdk/core";
|
|
2
|
-
import { alchemyFeeEstimator, alchemyGasAndPaymasterAndDataMiddleware, alchemyGasManagerMiddleware, } from "@account-kit/infra";
|
|
3
|
-
import {} from "viem";
|
|
4
|
-
import { createSession, } from "./actions/createSession.js";
|
|
5
|
-
import { getCallsStatus, } from "./actions/getCallsStatus.js";
|
|
6
|
-
import { prepareCalls, } from "./actions/prepareCalls.js";
|
|
7
|
-
import { sendPreparedCalls, } from "./actions/sendPreparedCalls.js";
|
|
8
|
-
export function isomorphicClientActions(client) {
|
|
9
|
-
return {
|
|
10
|
-
prepareCalls: (params) => prepareCalls(client, params),
|
|
11
|
-
sendPreparedCalls: (params) => sendPreparedCalls(client, params),
|
|
12
|
-
getCallsStatus: (params) => getCallsStatus(client, params),
|
|
13
|
-
createSession: (params) => createSession(client, params),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
// the isomorphic client likely won't be exposed directly. This client contains the business logic that can be run on the wallet server or on the client
|
|
17
|
-
// if the dev chooses to run the client in "local" mode.
|
|
18
|
-
export function createIsomorphicClient({ chain, transport, policyId, useErc7677middleware = true, }) {
|
|
19
|
-
// This must be a smart account client since as of now we use it to build UOs under the hood
|
|
20
|
-
const client = createSmartAccountClient({
|
|
21
|
-
transport,
|
|
22
|
-
chain,
|
|
23
|
-
// TODO: we will want to enforce alchemy transport here probably
|
|
24
|
-
feeEstimator: alchemyFeeEstimator(transport),
|
|
25
|
-
...(policyId
|
|
26
|
-
? useErc7677middleware
|
|
27
|
-
? alchemyGasManagerMiddleware(policyId)
|
|
28
|
-
: // NOTE: DO NOT USE THIS MIDDLEWARE in the server, currently we require using the erc7677 middleware
|
|
29
|
-
alchemyGasAndPaymasterAndDataMiddleware({
|
|
30
|
-
policyId,
|
|
31
|
-
transport: transport,
|
|
32
|
-
})
|
|
33
|
-
: {}),
|
|
34
|
-
}).extend(isomorphicClientActions);
|
|
35
|
-
return client;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/isomorphic/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAIzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,uCAAuC,EACvC,2BAA2B,GAE5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA8B,MAAM,MAAM,CAAC;AAElD,OAAO,EACL,aAAa,GAEd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,cAAc,GAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,YAAY,GAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,GAElB,MAAM,gCAAgC,CAAC;AAUxC,MAAM,UAAU,uBAAuB,CACrC,MAMC;IAED,OAAO;QACL,YAAY,EAAE,CAAC,MAA0B,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;QAC1E,iBAAiB,EAAE,CAAC,MAA+B,EAAE,EAAE,CACrD,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC;QACnC,cAAc,EAAE,CAAC,MAA4B,EAAE,EAAE,CAC/C,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;QAChC,aAAa,EAAE,CAAC,MAA2B,EAAE,EAAE,CAC7C,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;KAChC,CAAC;AACJ,CAAC;AAED,wJAAwJ;AACxJ,wDAAwD;AACxD,MAAM,UAAU,sBAAsB,CAAC,EACrC,KAAK,EACL,SAAS,EACT,QAAQ,EACR,oBAAoB,GAAG,IAAI,GACd;IAOb,4FAA4F;IAC5F,MAAM,MAAM,GAAG,wBAAwB,CAAC;QACtC,SAAS;QACT,KAAK;QACL,gEAAgE;QAChE,YAAY,EAAE,mBAAmB,CAAC,SAA6B,CAAC;QAChE,GAAG,CAAC,QAAQ;YACV,CAAC,CAAC,oBAAoB;gBACpB,CAAC,CAAC,2BAA2B,CAAC,QAAQ,CAAC;gBACvC,CAAC,CAAC,oGAAoG;oBACpG,uCAAuC,CAAC;wBACtC,QAAQ;wBACR,SAAS,EAAE,SAA6B;qBACzC,CAAC;YACN,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n createSmartAccountClient,\n type SmartAccountClient,\n type SmartAccountClientRpcSchema,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n alchemyFeeEstimator,\n alchemyGasAndPaymasterAndDataMiddleware,\n alchemyGasManagerMiddleware,\n type AlchemyTransport,\n} from \"@account-kit/infra\";\nimport { type Chain, type Transport } from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../rpc/schema.js\";\nimport {\n createSession,\n type CreateSessionParams,\n} from \"./actions/createSession.js\";\nimport {\n getCallsStatus,\n type GetCallsStatusParams,\n} from \"./actions/getCallsStatus.js\";\nimport {\n prepareCalls,\n type PrepareCallsParams,\n} from \"./actions/prepareCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsParams,\n} from \"./actions/sendPreparedCalls.js\";\n\n// let's start with something that takes in as many params as possible, then we can eliminate them as we don't need them\ntype ClientParams = {\n chain: Chain;\n transport: Transport;\n policyId?: string;\n useErc7677middleware?: boolean;\n};\n\nexport function isomorphicClientActions(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n) {\n return {\n prepareCalls: (params: PrepareCallsParams) => prepareCalls(client, params),\n sendPreparedCalls: (params: SendPreparedCallsParams) =>\n sendPreparedCalls(client, params),\n getCallsStatus: (params: GetCallsStatusParams) =>\n getCallsStatus(client, params),\n createSession: (params: CreateSessionParams) =>\n createSession(client, params),\n };\n}\n\n// the isomorphic client likely won't be exposed directly. This client contains the business logic that can be run on the wallet server or on the client\n// if the dev chooses to run the client in \"local\" mode.\nexport function createIsomorphicClient({\n chain,\n transport,\n policyId,\n useErc7677middleware = true,\n}: ClientParams): SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n ReturnType<typeof isomorphicClientActions>,\n WalletServerViemRpcSchema & SmartAccountClientRpcSchema\n> {\n // This must be a smart account client since as of now we use it to build UOs under the hood\n const client = createSmartAccountClient({\n transport,\n chain,\n // TODO: we will want to enforce alchemy transport here probably\n feeEstimator: alchemyFeeEstimator(transport as AlchemyTransport),\n ...(policyId\n ? useErc7677middleware\n ? alchemyGasManagerMiddleware(policyId)\n : // NOTE: DO NOT USE THIS MIDDLEWARE in the server, currently we require using the erc7677 middleware\n alchemyGasAndPaymasterAndDataMiddleware({\n policyId,\n transport: transport as AlchemyTransport,\n })\n : {}),\n }).extend(isomorphicClientActions);\n\n return client;\n}\n\nexport type IsomorphicClient = ReturnType<typeof createIsomorphicClient>;\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import { type Address, type Chain, type Transport } from "viem";
|
|
3
|
-
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
4
|
-
import { PreparedCall_Authorization } from "../../schemas.js";
|
|
5
|
-
import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
|
|
6
|
-
import type { Static } from "@sinclair/typebox";
|
|
7
|
-
/** Checks if an address is actively delegated on-chain. */
|
|
8
|
-
export declare const isDelegated: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
|
|
9
|
-
address: Address;
|
|
10
|
-
delegation: Address;
|
|
11
|
-
}) => Promise<boolean>;
|
|
12
|
-
export declare const createAuthorizationRequest: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
|
|
13
|
-
address: Address;
|
|
14
|
-
delegation: Address;
|
|
15
|
-
}) => Promise<Static<typeof PreparedCall_Authorization>>;
|
|
16
|
-
export declare const EIP_7702_ACCOUNT_TYPE: readonly ["ModularAccountV2"];
|
|
17
|
-
type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
|
|
18
|
-
export declare const SUPPORTED_DELEGATION_ADDRESSES: "0x69007702764179f14F51cdce752f4f775d74E139"[];
|
|
19
|
-
export declare const isSupportedDelegationAddress7702: (address: Address) => boolean;
|
|
20
|
-
export declare const getAccountTypeForDelegationAddress7702: (address: Address) => Supported7702AccountType | undefined;
|
|
21
|
-
export declare const parseDelegation: (eip7702AuthCapability: Static<typeof Eip7702AuthCapability>) => "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
22
|
-
export declare const assertValid7702AccountAddress: (fromAddress: Address, eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined) => void;
|
|
23
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { concatHex, numberToHex, isAddress, hexToNumber, } from "viem";
|
|
2
|
-
import { PreparedCall_Authorization } from "../../schemas.js";
|
|
3
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
4
|
-
import { hashAuthorization } from "viem/utils";
|
|
5
|
-
/** Checks if an address is actively delegated on-chain. */
|
|
6
|
-
export const isDelegated = async (client, params) => {
|
|
7
|
-
const expectedCode = concatHex(["0xef0100", params.delegation]);
|
|
8
|
-
const code = (await client.getCode({ address: params.address })) ?? "0x";
|
|
9
|
-
return code.toLowerCase() === expectedCode.toLowerCase();
|
|
10
|
-
};
|
|
11
|
-
export const createAuthorizationRequest = async (client, params) => {
|
|
12
|
-
const data = {
|
|
13
|
-
address: params.delegation,
|
|
14
|
-
nonce: numberToHex(await client.getTransactionCount({
|
|
15
|
-
address: params.address,
|
|
16
|
-
})),
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
type: "authorization",
|
|
20
|
-
data,
|
|
21
|
-
chainId: numberToHex(client.chain.id),
|
|
22
|
-
signatureRequest: {
|
|
23
|
-
type: "eip7702Auth",
|
|
24
|
-
rawPayload: hashAuthorization({
|
|
25
|
-
chainId: client.chain.id,
|
|
26
|
-
nonce: hexToNumber(data.nonce),
|
|
27
|
-
address: params.delegation,
|
|
28
|
-
}),
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"];
|
|
33
|
-
const Eip7702AccountTypeToDelegationAddress = {
|
|
34
|
-
ModularAccountV2: "0x69007702764179f14F51cdce752f4f775d74E139",
|
|
35
|
-
};
|
|
36
|
-
const DelegationAddressToAccountType = Object.fromEntries(Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
|
|
37
|
-
value,
|
|
38
|
-
key,
|
|
39
|
-
]));
|
|
40
|
-
export const SUPPORTED_DELEGATION_ADDRESSES = Object.values(Eip7702AccountTypeToDelegationAddress);
|
|
41
|
-
export const isSupportedDelegationAddress7702 = (address) => {
|
|
42
|
-
return SUPPORTED_DELEGATION_ADDRESSES.includes(address);
|
|
43
|
-
};
|
|
44
|
-
export const getAccountTypeForDelegationAddress7702 = (address) => {
|
|
45
|
-
return DelegationAddressToAccountType[address];
|
|
46
|
-
};
|
|
47
|
-
const getDelegationAddressForAccountType7702 = (accountType) => {
|
|
48
|
-
return Eip7702AccountTypeToDelegationAddress[accountType];
|
|
49
|
-
};
|
|
50
|
-
const DEFAULT_7702_DELEGATION_ADDR = Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
|
|
51
|
-
export const parseDelegation = (eip7702AuthCapability) => {
|
|
52
|
-
return eip7702AuthCapability === true
|
|
53
|
-
? DEFAULT_7702_DELEGATION_ADDR
|
|
54
|
-
: isAddress(eip7702AuthCapability.delegation)
|
|
55
|
-
? eip7702AuthCapability.delegation
|
|
56
|
-
: getDelegationAddressForAccountType7702(eip7702AuthCapability.delegation);
|
|
57
|
-
};
|
|
58
|
-
export const assertValid7702AccountAddress = (fromAddress, eip7702AuthCapability) => {
|
|
59
|
-
if (eip7702AuthCapability) {
|
|
60
|
-
if (typeof eip7702AuthCapability === "object" &&
|
|
61
|
-
"account" in eip7702AuthCapability &&
|
|
62
|
-
eip7702AuthCapability?.account !== fromAddress) {
|
|
63
|
-
throw new InvalidRequestError({
|
|
64
|
-
message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const delegation = parseDelegation(eip7702AuthCapability);
|
|
68
|
-
if (!isSupportedDelegationAddress7702(delegation)) {
|
|
69
|
-
throw new InvalidRequestError({
|
|
70
|
-
message: `Unsupported 7702 delegation address: ${delegation}`,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
//# sourceMappingURL=7702.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,WAAW,EAIX,SAAS,EACT,WAAW,GACZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,MAMC,EACD,MAAiD,EAC/B,EAAE;IACpB,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,I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AAI,CAAC,gCAAgC,CAAC,UAAU,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,wCAAwC,UAAU,EAAE;aAC9D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n numberToHex,\n type Address,\n type Chain,\n type Transport,\n isAddress,\n hexToNumber,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { PreparedCall_Authorization } from \"../../schemas.js\";\nimport type { Eip7702AuthCapability } from \"../../capabilities/eip7702Auth.ts\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { hashAuthorization } from \"viem/utils\";\n\n/** Checks if an address is actively delegated on-chain. */\nexport const isDelegated = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<boolean> => {\n const expectedCode = concatHex([\"0xef0100\", params.delegation]);\n const code = (await client.getCode({ address: params.address })) ?? \"0x\";\n return code.toLowerCase() === expectedCode.toLowerCase();\n};\n\nexport const createAuthorizationRequest = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<Static<typeof PreparedCall_Authorization>> => {\n const data = {\n address: params.delegation,\n nonce: numberToHex(\n await client.getTransactionCount({\n address: params.address,\n }),\n ),\n };\n return {\n type: \"authorization\" as const,\n data,\n chainId: numberToHex(client.chain.id),\n signatureRequest: {\n type: \"eip7702Auth\" as const,\n rawPayload: hashAuthorization({\n chainId: client.chain.id,\n nonce: hexToNumber(data.nonce),\n address: params.delegation,\n }),\n },\n };\n};\n\nexport const EIP_7702_ACCOUNT_TYPE = [\"ModularAccountV2\"] as const;\n\ntype Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];\n\nconst Eip7702AccountTypeToDelegationAddress = {\n ModularAccountV2: \"0x69007702764179f14F51cdce752f4f775d74E139\",\n} as const satisfies Record<Supported7702AccountType, Address>;\n\nconst DelegationAddressToAccountType: Record<\n Address,\n Supported7702AccountType\n> = Object.fromEntries(\n Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [\n value,\n key,\n ]),\n) as Record<Address, Supported7702AccountType>;\n\nexport const SUPPORTED_DELEGATION_ADDRESSES = Object.values(\n Eip7702AccountTypeToDelegationAddress,\n);\n\nexport const isSupportedDelegationAddress7702 = (address: Address): boolean => {\n return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);\n};\n\nexport const getAccountTypeForDelegationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return DelegationAddressToAccountType[address];\n};\n\nconst getDelegationAddressForAccountType7702 = (\n accountType: Supported7702AccountType,\n): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {\n return Eip7702AccountTypeToDelegationAddress[accountType];\n};\n\nconst DEFAULT_7702_DELEGATION_ADDR =\n Eip7702AccountTypeToDelegationAddress[\"ModularAccountV2\"];\n\nexport const parseDelegation = (\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,\n) => {\n return eip7702AuthCapability === true\n ? DEFAULT_7702_DELEGATION_ADDR\n : isAddress(eip7702AuthCapability.delegation)\n ? eip7702AuthCapability.delegation\n : getDelegationAddressForAccountType7702(\n eip7702AuthCapability.delegation,\n );\n};\n\nexport const assertValid7702AccountAddress = (\n fromAddress: Address,\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,\n) => {\n if (eip7702AuthCapability) {\n if (\n typeof eip7702AuthCapability === \"object\" &&\n \"account\" in eip7702AuthCapability &&\n eip7702AuthCapability?.account !== fromAddress\n ) {\n throw new InvalidRequestError({\n message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,\n });\n }\n\n const delegation = parseDelegation(eip7702AuthCapability);\n\n if (!isSupportedDelegationAddress7702(delegation)) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${delegation}`,\n });\n }\n }\n};\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import { type ModularAccountV2 } from "@account-kit/smart-contracts";
|
|
3
|
-
import type { StaticDecode } from "@sinclair/typebox";
|
|
4
|
-
import type { Address, Chain, Transport } from "viem";
|
|
5
|
-
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
6
|
-
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
7
|
-
type CreateAccountParams = {
|
|
8
|
-
chain: Chain;
|
|
9
|
-
transport: Transport;
|
|
10
|
-
signer: SmartAccountSigner;
|
|
11
|
-
accountAddress: Address;
|
|
12
|
-
counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>;
|
|
13
|
-
permissions?: StaticDecode<typeof PermissionsCapability>;
|
|
14
|
-
delegation?: Address;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Creates a smart account instance from the given parameters.
|
|
18
|
-
* @param params - The parameters for creating a smart account.
|
|
19
|
-
* @returns A promise that resolves to the created smart account.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createAccount(params: CreateAccountParams): Promise<SmartContractAccount>;
|
|
22
|
-
export declare function isModularAccountV2(account: SmartContractAccount): account is ModularAccountV2;
|
|
23
|
-
export declare function prepareInitialOwners(initialOwners: Address[], signerAddress: Address): Address[];
|
|
24
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,8BAA8B,GA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C1D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createLightAccount,\n createModularAccountV2,\n createMultiOwnerLightAccount,\n createMultiOwnerModularAccount,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToBigInt, hexToNumber, zeroAddress } from \"viem\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\nimport { assertNever } from \"../../utils.js\";\nimport { getAccountTypeForDelegationAddress7702 } from \"./7702.js\";\nimport { PermissionsCapability } from \"../../capabilities/permissions/index.js\";\nimport { InternalError, InvalidRequestError } from \"ox/RpcResponse\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts\n permissions?: StaticDecode<typeof PermissionsCapability>;\n delegation?: Address;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n // This throws if we pass a permission context and the account is not MA-v2\n // TODO: test that this edge case is handled correctly\n const parsedContext = parsePermissionsContext(\n params.permissions,\n ci,\n params.delegation,\n );\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n const mode = params.delegation ? \"7702\" : \"default\";\n\n if (mode === \"7702\") {\n const accountType = getAccountTypeForDelegationAddress7702(\n params.delegation!,\n );\n if (accountType !== \"ModularAccountV2\") {\n throw new Error(\"7702 mode currently only supports ModularAccountV2\");\n }\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n mode,\n });\n }\n\n if (mode !== \"default\") {\n return assertNever(mode, \"Unexpected mode in createAccount\");\n }\n\n // At this point, we are guaranteed to be in default mode, where ci\n // (counterfactualInfo) must be defined\n\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n\n const factoryType = ci.factoryType;\n const commonParams = {\n ...accountParams,\n initCode: concatHex([ci.factoryAddress, ci.factoryData]),\n };\n\n // Return the account created based on the factory type\n switch (factoryType) {\n case \"MAv2.0.0-sma-b\":\n return createModularAccountV2({\n ...commonParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n mode,\n });\n case \"LightAccountV2.0.0\":\n return createLightAccount({\n ...commonParams,\n version: \"v2.0.0\",\n });\n case \"LightAccountV1.0.1\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.0.1\",\n });\n case \"LightAccountV1.0.2\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.0.2\",\n });\n case \"LightAccountV1.1.0\":\n return createLightAccount({\n ...commonParams,\n version: \"v1.1.0\",\n });\n case \"MAv1.0.0-MultiOwner\":\n return createMultiOwnerModularAccount({\n ...commonParams,\n });\n case \"LightAccountV2.0.0-MultiOwner\":\n return createMultiOwnerLightAccount({\n ...commonParams,\n version: \"v2.0.0\",\n });\n case \"MAv1.0.0-MultiSig\":\n case \"MAv2.0.0-ma-ssv\":\n case \"MAv2.0.0-ma-webauthn\":\n case \"unknown\":\n case undefined:\n throw new InvalidRequestError({\n message: `Account type currently unsupported: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n\n// Performs basic checks on the initialOwners array and returns a new array with the signer address added if not present.\n// Pulled from MAv1 support in Account Kit.\nexport function prepareInitialOwners(\n initialOwners: Address[],\n signerAddress: Address,\n): Address[] {\n const preparedOwners = Array.from(\n new Set([...initialOwners, signerAddress]),\n ).sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n if (preparedOwners.some((x) => x === zeroAddress)) {\n throw new InvalidRequestError({\n message: \"Initial owners cannot contain the zero address\",\n });\n }\n\n return preparedOwners;\n}\n"]}
|