@account-kit/wallet-client 0.1.0-alpha.10 → 0.1.0-alpha.12
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/getCallsStatus.d.ts +4 -3
- package/dist/esm/client/actions/getCallsStatus.js +1 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +5 -4
- package/dist/esm/client/actions/grantPermissions.js +21 -5
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +4 -3
- package/dist/esm/client/actions/prepareCalls.js +1 -0
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +4 -3
- package/dist/esm/client/actions/prepareSign.js +1 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.js +3 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +190 -329
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/index.d.ts +1 -4
- package/dist/esm/client/index.js +13 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +3 -7
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +9 -33
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +2 -8
- package/dist/esm/types.js.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +5 -4
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +4 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +4 -3
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +4 -8
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +2 -8
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/client/actions/getCallsStatus.ts +8 -6
- package/src/client/actions/grantPermissions.ts +41 -10
- package/src/client/actions/prepareCalls.ts +11 -6
- package/src/client/actions/prepareSign.ts +9 -6
- package/src/client/actions/requestAccount.ts +3 -3
- package/src/client/actions/signSignatureRequest.ts +8 -8
- package/src/client/client.e2e-test.ts +143 -298
- package/src/client/index.ts +22 -23
- package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +11 -51
- package/src/types.ts +4 -15
- package/dist/esm/exports/internal.d.ts +0 -4
- package/dist/esm/exports/internal.js +0 -3
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
- package/dist/esm/isomorphic/actions/createSession.js +0 -94
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
- package/dist/esm/isomorphic/actions/formatSign.js +0 -42
- package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
- package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -156
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -275
- package/dist/esm/isomorphic/client.js +0 -41
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
- package/dist/esm/isomorphic/utils/7702.js +0 -70
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- 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 -15
- 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/types/exports/internal.d.ts +0 -5
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -276
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -20
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- 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/src/exports/internal.ts +0 -8
- package/src/isomorphic/actions/createSession.ts +0 -163
- package/src/isomorphic/actions/formatSign.ts +0 -76
- package/src/isomorphic/actions/getCallsStatus.ts +0 -112
- package/src/isomorphic/actions/prepareCalls.ts +0 -172
- package/src/isomorphic/actions/prepareSign.ts +0 -91
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -234
- package/src/isomorphic/client.ts +0 -102
- package/src/isomorphic/utils/7702.ts +0 -135
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -21
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- package/src/remote/client.ts +0 -67
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import {
|
|
3
|
-
createLightAccount,
|
|
4
3
|
createModularAccountV2,
|
|
4
|
+
createLightAccount,
|
|
5
5
|
createMultiOwnerLightAccount,
|
|
6
6
|
createMultiOwnerModularAccount,
|
|
7
|
-
type ModularAccountV2,
|
|
8
7
|
} from "@account-kit/smart-contracts";
|
|
8
|
+
import { concatHex, type Chain, type Transport, type Address } from "viem";
|
|
9
9
|
import type { StaticDecode } from "@sinclair/typebox";
|
|
10
|
-
import
|
|
11
|
-
import { concatHex, hexToNumber } from "viem";
|
|
12
|
-
import { parsePermissionsContext } from "./parsePermissionsContext.js";
|
|
13
|
-
import { assertNever } from "../../utils.js";
|
|
14
|
-
import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
|
|
15
|
-
import { TypeSerializedInitcode } from "@alchemy/wallet-api-types";
|
|
16
|
-
import { PermissionsCapability } from "@alchemy/wallet-api-types/capabilities";
|
|
10
|
+
import { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
17
11
|
import { InternalError, InvalidRequestError } from "ox/RpcResponse";
|
|
12
|
+
import { assertNever } from "../utils.js";
|
|
13
|
+
import { getAccountTypeForDelegationAddress7702 } from "@alchemy/wallet-api-types/capabilities";
|
|
18
14
|
|
|
19
15
|
type CreateAccountParams = {
|
|
20
16
|
chain: Chain;
|
|
21
17
|
transport: Transport;
|
|
22
18
|
signer: SmartAccountSigner;
|
|
23
19
|
accountAddress: Address;
|
|
24
|
-
counterfactualInfo?: StaticDecode<typeof
|
|
25
|
-
|
|
26
|
-
delegation?: Address;
|
|
20
|
+
counterfactualInfo?: StaticDecode<typeof SerializedInitcode>; // undefined for 7702 accounts
|
|
21
|
+
delegation?: Address; // for 7702 accounts
|
|
27
22
|
};
|
|
28
23
|
|
|
29
24
|
/**
|
|
@@ -36,46 +31,19 @@ export async function createAccount(
|
|
|
36
31
|
): Promise<SmartContractAccount> {
|
|
37
32
|
const { counterfactualInfo: ci, ...accountParams } = params;
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
// TODO: test that this edge case is handled correctly
|
|
41
|
-
const parsedContext = parsePermissionsContext(
|
|
42
|
-
params.permissions,
|
|
43
|
-
ci,
|
|
44
|
-
params.delegation,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const signerEntity =
|
|
48
|
-
parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
|
|
49
|
-
? {
|
|
50
|
-
entityId: hexToNumber(parsedContext.entityId),
|
|
51
|
-
isGlobalValidation: parsedContext.isGlobalValidation,
|
|
52
|
-
}
|
|
53
|
-
: undefined;
|
|
54
|
-
|
|
55
|
-
const mode = params.delegation ? "7702" : "default";
|
|
56
|
-
|
|
57
|
-
if (mode === "7702") {
|
|
34
|
+
if (params.delegation) {
|
|
58
35
|
const accountType = getAccountTypeForDelegationAddress7702(
|
|
59
|
-
params.delegation
|
|
36
|
+
params.delegation,
|
|
60
37
|
);
|
|
61
38
|
if (accountType !== "ModularAccountV2") {
|
|
62
39
|
throw new Error("7702 mode currently only supports ModularAccountV2");
|
|
63
40
|
}
|
|
64
41
|
return createModularAccountV2({
|
|
65
42
|
...accountParams,
|
|
66
|
-
|
|
67
|
-
deferredAction: parsedContext?.deferredAction,
|
|
68
|
-
mode,
|
|
43
|
+
mode: "7702",
|
|
69
44
|
});
|
|
70
45
|
}
|
|
71
46
|
|
|
72
|
-
if (mode !== "default") {
|
|
73
|
-
return assertNever(mode, "Unexpected mode in createAccount");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// At this point, we are guaranteed to be in default mode, where ci
|
|
77
|
-
// (counterfactualInfo) must be defined
|
|
78
|
-
|
|
79
47
|
if (!ci) {
|
|
80
48
|
throw new InternalError({
|
|
81
49
|
message: "Counterfactual info not found",
|
|
@@ -93,9 +61,7 @@ export async function createAccount(
|
|
|
93
61
|
case "MAv2.0.0-sma-b":
|
|
94
62
|
return createModularAccountV2({
|
|
95
63
|
...commonParams,
|
|
96
|
-
|
|
97
|
-
deferredAction: parsedContext?.deferredAction,
|
|
98
|
-
mode,
|
|
64
|
+
mode: "default",
|
|
99
65
|
});
|
|
100
66
|
case "LightAccountV2.0.0":
|
|
101
67
|
return createLightAccount({
|
|
@@ -138,9 +104,3 @@ export async function createAccount(
|
|
|
138
104
|
return assertNever(factoryType, "Unsupported factory type");
|
|
139
105
|
}
|
|
140
106
|
}
|
|
141
|
-
|
|
142
|
-
export function isModularAccountV2(
|
|
143
|
-
account: SmartContractAccount,
|
|
144
|
-
): account is ModularAccountV2 {
|
|
145
|
-
return account.source === "ModularAccountV2";
|
|
146
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import type { AlchemyTransport } from "@account-kit/infra";
|
|
3
3
|
import type {
|
|
4
4
|
Address,
|
|
@@ -8,10 +8,6 @@ import type {
|
|
|
8
8
|
JsonRpcAccount,
|
|
9
9
|
Transport,
|
|
10
10
|
} from "viem";
|
|
11
|
-
import type {
|
|
12
|
-
GrantPermissionsParams,
|
|
13
|
-
GrantPermissionsResult,
|
|
14
|
-
} from "./client/actions/grantPermissions.ts";
|
|
15
11
|
import type { RequestAccountParams } from "./client/actions/requestAccount.ts";
|
|
16
12
|
import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
17
13
|
|
|
@@ -36,13 +32,6 @@ export type InnerWalletApiClientBase<
|
|
|
36
32
|
{ policyId?: string } & TExtend
|
|
37
33
|
>;
|
|
38
34
|
|
|
39
|
-
export type InnerClientActions = {
|
|
40
|
-
grantPermissions: (
|
|
41
|
-
signer: SmartAccountSigner,
|
|
42
|
-
params: GrantPermissionsParams & { chainId: Hex },
|
|
43
|
-
) => Promise<GrantPermissionsResult>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
35
|
export type CachedAccount = {
|
|
47
36
|
account: SmartContractAccount;
|
|
48
37
|
requestParams: RequestAccountParams;
|
|
@@ -53,9 +42,9 @@ export type InternalState = {
|
|
|
53
42
|
getAccount: () => CachedAccount | undefined;
|
|
54
43
|
};
|
|
55
44
|
|
|
56
|
-
export type InnerWalletApiClient = InnerWalletApiClientBase<
|
|
57
|
-
|
|
58
|
-
>;
|
|
45
|
+
export type InnerWalletApiClient = InnerWalletApiClientBase<{
|
|
46
|
+
internal: InternalState;
|
|
47
|
+
}>;
|
|
59
48
|
|
|
60
49
|
export type WithoutChainId<T> = T extends { chainId: Hex }
|
|
61
50
|
? Omit<T, "chainId">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/exports/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC","sourcesContent":["// exports from this file are meant to be imported by our packages in the monorepo\n// we will expose this in the package.json as a named export like `this-pkg/internal`\n// TODO: name `this-pkg`\nexport type * from \"../isomorphic/client.js\";\nexport { createIsomorphicClient } from \"../isomorphic/client.js\";\nexport { createDummySigner } from \"../isomorphic/utils/createDummySigner.js\";\n\nexport type * from \"../types.ts\";\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
|
-
import { type Chain, type Hex, type Transport } from "viem";
|
|
4
|
-
import type { wallet_createSession, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
-
export type CreateSessionParams = Omit<Static<(typeof wallet_createSession)["properties"]["Request"]["properties"]["params"]>[0], "chainId"> & {
|
|
6
|
-
entityId?: Hex;
|
|
7
|
-
};
|
|
8
|
-
export type CreateSessionResult = Omit<Static<(typeof wallet_createSession)["properties"]["ReturnType"]>, "sessionId"> & {
|
|
9
|
-
sessionId: Hex | null;
|
|
10
|
-
entityId: Hex;
|
|
11
|
-
fullPreSignatureDeferredActionDigest: Hex;
|
|
12
|
-
};
|
|
13
|
-
export declare function createSession(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: CreateSessionParams): Promise<CreateSessionResult>;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createSmartAccountClient, } from "@aa-sdk/core";
|
|
2
|
-
import { deferralActions, PermissionBuilder, } from "@account-kit/smart-contracts/experimental";
|
|
3
|
-
import { Value } from "@sinclair/typebox/value";
|
|
4
|
-
import { ChainNotFoundError, custom, hashTypedData, hexToNumber, toHex, } from "viem";
|
|
5
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
6
|
-
import { TypePermission, isGlobalValidation, } from "@alchemy/wallet-api-types/capabilities";
|
|
7
|
-
import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
|
|
8
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
9
|
-
import { supportsFeature } from "../utils/supportsFeature.js";
|
|
10
|
-
import { isDelegated } from "../utils/7702.js";
|
|
11
|
-
export async function createSession(client, params) {
|
|
12
|
-
if (!client.chain) {
|
|
13
|
-
throw new ChainNotFoundError();
|
|
14
|
-
}
|
|
15
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
16
|
-
method: "wallet_requestAccount",
|
|
17
|
-
params: [
|
|
18
|
-
{
|
|
19
|
-
accountAddress: params.account,
|
|
20
|
-
includeCounterfactualInfo: true,
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
});
|
|
24
|
-
if (delegation &&
|
|
25
|
-
!(await isDelegated(client, {
|
|
26
|
-
address: params.account,
|
|
27
|
-
delegation,
|
|
28
|
-
}))) {
|
|
29
|
-
throw new InvalidRequestError({
|
|
30
|
-
message: "7702 account must be delegated before calling `wallet_createSession`",
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (!delegation && !counterfactualInfo) {
|
|
34
|
-
throw new InvalidRequestError({
|
|
35
|
-
message: "No counterfactual info found.",
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (counterfactualInfo &&
|
|
39
|
-
!supportsFeature(counterfactualInfo, "permissions")) {
|
|
40
|
-
throw new InvalidRequestError({
|
|
41
|
-
message: "Account type does not support createSession",
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
// At this point we know the account supports the permission feature
|
|
45
|
-
const account = await createAccount({
|
|
46
|
-
chain: client.chain,
|
|
47
|
-
transport: custom(client.transport),
|
|
48
|
-
signer: createDummySigner(params.account),
|
|
49
|
-
accountAddress: params.account,
|
|
50
|
-
counterfactualInfo,
|
|
51
|
-
delegation,
|
|
52
|
-
});
|
|
53
|
-
if (!isModularAccountV2(account)) {
|
|
54
|
-
throw new InvalidRequestError({
|
|
55
|
-
message: "Sessions are currently only supported by MAv2 accounts.",
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
const _client = createSmartAccountClient({
|
|
59
|
-
chain: client.chain,
|
|
60
|
-
transport: custom(client.transport),
|
|
61
|
-
account,
|
|
62
|
-
}).extend(deferralActions);
|
|
63
|
-
const { entityId, nonce } = await _client.getEntityIdAndNonce({
|
|
64
|
-
entityId: params.entityId ? hexToNumber(params.entityId) : undefined,
|
|
65
|
-
isGlobalValidation: isGlobalValidation(params),
|
|
66
|
-
});
|
|
67
|
-
const { typedData, fullPreSignatureDeferredActionDigest } = await new PermissionBuilder({
|
|
68
|
-
client: _client,
|
|
69
|
-
key: {
|
|
70
|
-
...params.key,
|
|
71
|
-
// Alias 'ecdsa' to 'secp256k1'
|
|
72
|
-
type: params.key.type === "ecdsa" ? "secp256k1" : params.key.type,
|
|
73
|
-
},
|
|
74
|
-
entityId,
|
|
75
|
-
nonce,
|
|
76
|
-
deadline: params.expirySec,
|
|
77
|
-
})
|
|
78
|
-
.addPermissions({
|
|
79
|
-
permissions: params.permissions.map((permission) => Value.Encode(TypePermission, permission)),
|
|
80
|
-
})
|
|
81
|
-
.compileDeferred();
|
|
82
|
-
return {
|
|
83
|
-
sessionId: null, // In remote mode, the server will set this later.
|
|
84
|
-
chainId: toHex(client.chain.id),
|
|
85
|
-
entityId: toHex(entityId),
|
|
86
|
-
signatureRequest: {
|
|
87
|
-
type: "eth_signTypedData_v4",
|
|
88
|
-
data: typedData,
|
|
89
|
-
rawPayload: hashTypedData(typedData),
|
|
90
|
-
},
|
|
91
|
-
fullPreSignatureDeferredActionDigest,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=createSession.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSession.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/createSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAGzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,aAAa,EACb,WAAW,EACX,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,cAAc,EACd,k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W,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACjD,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CACzC;KACF,CAAC;SACD,eAAe,EAAE,CAAC;IAEvB,OAAO;QACL,SAAS,EAAE,IAAI,EAAE,kDAAkD;QACnE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzB,gBAAgB,EAAE;YAChB,IAAI,EAAE,sBAA+B;YACrC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC;SACrC;QACD,oCAAoC;KACrC,CAAC;AACJ,CAAC","sourcesContent":["import {\n createSmartAccountClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n deferralActions,\n PermissionBuilder,\n} from \"@account-kit/smart-contracts/experimental\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n custom,\n hashTypedData,\n hexToNumber,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport {\n TypePermission,\n isGlobalValidation,\n} from \"@alchemy/wallet-api-types/capabilities\";\nimport type {\n wallet_createSession,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { createAccount, isModularAccountV2 } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { supportsFeature } from \"../utils/supportsFeature.js\";\nimport { isDelegated } from \"../utils/7702.js\";\n\nexport type CreateSessionParams = Omit<\n Static<\n (typeof wallet_createSession)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n> & {\n entityId?: Hex;\n};\n\nexport type CreateSessionResult = Omit<\n Static<(typeof wallet_createSession)[\"properties\"][\"ReturnType\"]>,\n \"sessionId\"\n> & {\n sessionId: Hex | null;\n entityId: Hex;\n fullPreSignatureDeferredActionDigest: Hex;\n};\n\nexport async function createSession(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: CreateSessionParams,\n): Promise<CreateSessionResult> {\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.account,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (\n delegation &&\n !(await isDelegated(client, {\n address: params.account,\n delegation,\n }))\n ) {\n throw new InvalidRequestError({\n message:\n \"7702 account must be delegated before calling `wallet_createSession`\",\n });\n }\n\n if (!delegation && !counterfactualInfo) {\n throw new InvalidRequestError({\n message: \"No counterfactual info found.\",\n });\n }\n\n if (\n counterfactualInfo &&\n !supportsFeature(counterfactualInfo, \"permissions\")\n ) {\n throw new InvalidRequestError({\n message: \"Account type does not support createSession\",\n });\n }\n\n // At this point we know the account supports the permission feature\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.account),\n accountAddress: params.account,\n counterfactualInfo,\n delegation,\n });\n\n if (!isModularAccountV2(account)) {\n throw new InvalidRequestError({\n message: \"Sessions are currently only supported by MAv2 accounts.\",\n });\n }\n\n const _client = createSmartAccountClient({\n chain: client.chain,\n transport: custom(client.transport),\n account,\n }).extend(deferralActions);\n\n const { entityId, nonce } = await _client.getEntityIdAndNonce({\n entityId: params.entityId ? hexToNumber(params.entityId) : undefined,\n isGlobalValidation: isGlobalValidation(params),\n });\n\n const { typedData, fullPreSignatureDeferredActionDigest } =\n await new PermissionBuilder({\n client: _client,\n key: {\n ...params.key,\n // Alias 'ecdsa' to 'secp256k1'\n type: params.key.type === \"ecdsa\" ? \"secp256k1\" : params.key.type,\n },\n entityId,\n nonce,\n deadline: params.expirySec,\n })\n .addPermissions({\n permissions: params.permissions.map((permission) =>\n Value.Encode(TypePermission, permission),\n ),\n })\n .compileDeferred();\n\n return {\n sessionId: null, // In remote mode, the server will set this later.\n chainId: toHex(client.chain.id),\n entityId: toHex(entityId),\n signatureRequest: {\n type: \"eth_signTypedData_v4\" as const,\n data: typedData,\n rawPayload: hashTypedData(typedData),\n },\n fullPreSignatureDeferredActionDigest,\n };\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type { wallet_formatSign } from "@alchemy/wallet-api-types/rpc";
|
|
3
|
-
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
4
|
-
import { type Chain, type Transport } from "viem";
|
|
5
|
-
import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
-
export type FormatSignParams = Static<(typeof wallet_formatSign)["properties"]["Request"]["properties"]["params"]>[0];
|
|
7
|
-
export type FormatSignResult = Static<(typeof wallet_formatSign)["properties"]["ReturnType"]>;
|
|
8
|
-
export declare function formatSign(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: FormatSignParams): Promise<FormatSignResult>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ChainNotFoundError, concat, custom, encodeAbiParameters, parseAbiParameters, } from "viem";
|
|
2
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
3
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
4
|
-
import { magicBytes } from "ox/erc6492/WrappedSignature";
|
|
5
|
-
export async function formatSign(client, params) {
|
|
6
|
-
if (!client.chain) {
|
|
7
|
-
throw new ChainNotFoundError();
|
|
8
|
-
}
|
|
9
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
10
|
-
method: "wallet_requestAccount",
|
|
11
|
-
params: [
|
|
12
|
-
{
|
|
13
|
-
accountAddress: params.from,
|
|
14
|
-
includeCounterfactualInfo: true,
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
});
|
|
18
|
-
const account = await createAccount({
|
|
19
|
-
chain: client.chain,
|
|
20
|
-
transport: custom(client.transport),
|
|
21
|
-
signer: createDummySigner(params.from),
|
|
22
|
-
accountAddress: params.from,
|
|
23
|
-
counterfactualInfo,
|
|
24
|
-
permissions: params.capabilities?.permissions,
|
|
25
|
-
delegation,
|
|
26
|
-
});
|
|
27
|
-
let formattedSignature = await account.formatSign(params.signature.data);
|
|
28
|
-
if (counterfactualInfo && !(await account.isAccountDeployed())) {
|
|
29
|
-
formattedSignature = concat([
|
|
30
|
-
encodeAbiParameters(parseAbiParameters("address, bytes, bytes"), [
|
|
31
|
-
counterfactualInfo.factoryAddress,
|
|
32
|
-
counterfactualInfo.factoryData,
|
|
33
|
-
formattedSignature,
|
|
34
|
-
]),
|
|
35
|
-
magicBytes,
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
signature: formattedSignature,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=formatSign.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/formatSign.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,kBAAkB,GAGnB,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAUzD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAMC,EACD,MAAwB;IAExB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE;YACN;gBACE,cAAc,EAAE,MAAM,CAAC,IAAI;gBAC3B,yBAAyB,EAAE,IAAI;aAChC;SACF;KACF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;QAClC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;QACtC,cAAc,EAAE,MAAM,CAAC,IAAI;QAC3B,kBAAkB;QAClB,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,WAAW;QAC7C,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,kBAAkB,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEzE,IAAI,kBAAkB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC;QAC/D,kBAAkB,GAAG,MAAM,CAAC;YAC1B,mBAAmB,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE;gBAC/D,kBAAkB,CAAC,cAAc;gBACjC,kBAAkB,CAAC,WAAW;gBAC9B,kBAAkB;aACnB,CAAC;YACF,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,SAAS,EAAE,kBAAkB;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { Static } from \"@sinclair/typebox\";\nimport type { wallet_formatSign } from \"@alchemy/wallet-api-types/rpc\";\nimport type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n ChainNotFoundError,\n concat,\n custom,\n encodeAbiParameters,\n parseAbiParameters,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { magicBytes } from \"ox/erc6492/WrappedSignature\";\n\nexport type FormatSignParams = Static<\n (typeof wallet_formatSign)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type FormatSignResult = Static<\n (typeof wallet_formatSign)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function formatSign(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: FormatSignParams,\n): Promise<FormatSignResult> {\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 let formattedSignature = await account.formatSign(params.signature.data);\n\n if (counterfactualInfo && !(await account.isAccountDeployed())) {\n formattedSignature = concat([\n encodeAbiParameters(parseAbiParameters(\"address, bytes, bytes\"), [\n counterfactualInfo.factoryAddress,\n counterfactualInfo.factoryData,\n formattedSignature,\n ]),\n magicBytes,\n ]);\n }\n\n return {\n signature: formattedSignature,\n };\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
|
-
import { type Chain, type Transport } from "viem";
|
|
4
|
-
import { type wallet_getCallsStatus, type WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
-
export type GetCallsStatusParams = Static<(typeof wallet_getCallsStatus)["properties"]["Request"]["properties"]["params"]>[0];
|
|
6
|
-
export type GetCallsStatusResponse = Static<(typeof wallet_getCallsStatus)["properties"]["ReturnType"]>;
|
|
7
|
-
export declare function getCallsStatus(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, callId: GetCallsStatusParams): Promise<GetCallsStatusResponse>;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {} from "@aa-sdk/core";
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { ChainNotFoundError, isHex, } from "viem";
|
|
4
|
-
import { BaseError } from "ox/RpcResponse";
|
|
5
|
-
import { CallStatusCode, CallStatusErrorCode, } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
-
import { TypeCallId } from "@alchemy/wallet-api-types";
|
|
7
|
-
import { castToHex } from "../../utils.js";
|
|
8
|
-
export async function getCallsStatus(client, callId) {
|
|
9
|
-
if (!client.chain) {
|
|
10
|
-
throw new ChainNotFoundError();
|
|
11
|
-
}
|
|
12
|
-
const { chainId, hash } = Value.Decode(TypeCallId, callId);
|
|
13
|
-
const baseResp = {
|
|
14
|
-
id: callId,
|
|
15
|
-
chainId,
|
|
16
|
-
atomic: true,
|
|
17
|
-
};
|
|
18
|
-
const result = await client.getUserOperationByHash(hash);
|
|
19
|
-
if (!result) {
|
|
20
|
-
throw new BaseError({
|
|
21
|
-
message: `callId ${callId} not found`,
|
|
22
|
-
code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (result && !result.transactionHash) {
|
|
26
|
-
// A result but no txn hash means it's valid but pending.
|
|
27
|
-
return {
|
|
28
|
-
...baseResp,
|
|
29
|
-
status: CallStatusCode.PENDING,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const receipt = await client.getUserOperationReceipt(hash);
|
|
33
|
-
if (!receipt) {
|
|
34
|
-
// Handles edge case of hash being retrieved immediately before the 150 block limit falloff.
|
|
35
|
-
throw new BaseError({
|
|
36
|
-
message: `callId ${callId} not found`,
|
|
37
|
-
code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
...baseResp,
|
|
42
|
-
status: receipt.success
|
|
43
|
-
? CallStatusCode.CONFIRMED
|
|
44
|
-
: CallStatusCode.CHAIN_RULES_FAILURE,
|
|
45
|
-
receipts: [transformReceipt(receipt.receipt)],
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const ReceiptStatus = {
|
|
49
|
-
reverted: "0x0",
|
|
50
|
-
success: "0x1",
|
|
51
|
-
};
|
|
52
|
-
function transformReceipt(receipt) {
|
|
53
|
-
return {
|
|
54
|
-
// viem's type for status is "success" | "reverted", but the actual value seems to already be 0x0 or 0x1
|
|
55
|
-
status: isHex(receipt.status)
|
|
56
|
-
? receipt.status
|
|
57
|
-
: ReceiptStatus[receipt.status],
|
|
58
|
-
blockHash: receipt.blockHash,
|
|
59
|
-
// viem's type for blockNumber is bigint, but the actual value seems to already be a hex string
|
|
60
|
-
blockNumber: castToHex(receipt.blockNumber),
|
|
61
|
-
// viem's type for gasUsed is bigint, but the actual value seems to already be a hex string
|
|
62
|
-
gasUsed: castToHex(receipt.gasUsed),
|
|
63
|
-
transactionHash: receipt.transactionHash,
|
|
64
|
-
logs: receipt.logs.map((log) => ({
|
|
65
|
-
address: log.address,
|
|
66
|
-
data: log.data,
|
|
67
|
-
topics: log.topics,
|
|
68
|
-
})),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=getCallsStatus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCallsStatus.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/getCallsStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EA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B,CAAC,iBAAiB;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,GAAG,QAAQ;QACX,MAAM,EAAE,OAAO,CAAC,OAAO;YACrB,CAAC,CAAC,cAAc,CAAC,SAAS;YAC1B,CAAC,CAAC,cAAc,CAAC,mBAAmB;QACtC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KAC9C,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAA8C;IAC/D,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,SAAS,gBAAgB,CACvB,OAA2B;IAE3B,OAAO;QACL,wGAAwG;QACxG,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC3B,CAAC,CAAC,OAAO,CAAC,MAAM;YAChB,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;QACjC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,+FAA+F;QAC/F,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC;QAC3C,2FAA2F;QAC3F,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;QACnC,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC/B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n isHex,\n type Chain,\n type Hex,\n type TransactionReceipt,\n type Transport,\n} from \"viem\";\nimport { BaseError } from \"ox/RpcResponse\";\nimport {\n CallStatusCode,\n CallStatusErrorCode,\n type wallet_getCallsStatus,\n type WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { TypeCallId } from \"@alchemy/wallet-api-types\";\nimport { castToHex } from \"../../utils.js\";\n\nexport type GetCallsStatusParams = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type GetCallsStatusResponse = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function getCallsStatus(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n callId: GetCallsStatusParams,\n): Promise<GetCallsStatusResponse> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n const { chainId, hash } = Value.Decode(TypeCallId, callId);\n\n const baseResp = {\n id: callId,\n chainId,\n atomic: true,\n };\n\n const result = await client.getUserOperationByHash(hash);\n if (!result) {\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n if (result && !result.transactionHash) {\n // A result but no txn hash means it's valid but pending.\n return {\n ...baseResp,\n status: CallStatusCode.PENDING,\n };\n }\n\n const receipt = await client.getUserOperationReceipt(hash);\n if (!receipt) {\n // Handles edge case of hash being retrieved immediately before the 150 block limit falloff.\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n\n return {\n ...baseResp,\n status: receipt.success\n ? CallStatusCode.CONFIRMED\n : CallStatusCode.CHAIN_RULES_FAILURE,\n receipts: [transformReceipt(receipt.receipt)],\n };\n}\n\nconst ReceiptStatus: Record<TransactionReceipt[\"status\"], Hex> = {\n reverted: \"0x0\",\n success: \"0x1\",\n};\n\nfunction transformReceipt(\n receipt: TransactionReceipt,\n): NonNullable<GetCallsStatusResponse[\"receipts\"]>[number] {\n return {\n // viem's type for status is \"success\" | \"reverted\", but the actual value seems to already be 0x0 or 0x1\n status: isHex(receipt.status)\n ? receipt.status\n : ReceiptStatus[receipt.status],\n blockHash: receipt.blockHash,\n // viem's type for blockNumber is bigint, but the actual value seems to already be a hex string\n blockNumber: castToHex(receipt.blockNumber),\n // viem's type for gasUsed is bigint, but the actual value seems to already be a hex string\n gasUsed: castToHex(receipt.gasUsed),\n transactionHash: receipt.transactionHash,\n logs: receipt.logs.map((log) => ({\n address: log.address,\n data: log.data,\n topics: log.topics,\n })),\n };\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
|
-
import { type Chain, type Transport } from "viem";
|
|
4
|
-
import type { wallet_prepareCalls, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
-
export type PrepareCallsParams = Omit<Static<(typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]>[0], "chainId">;
|
|
6
|
-
export type PrepareCallsResult = Static<(typeof wallet_prepareCalls)["properties"]["ReturnType"]>;
|
|
7
|
-
export declare function prepareCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: PrepareCallsParams): Promise<PrepareCallsResult>;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
|
|
2
|
-
import { ChainNotFoundError, custom, fromHex, hashMessage, toHex, } from "viem";
|
|
3
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
4
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
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";
|
|
9
|
-
export async function prepareCalls(client, params) {
|
|
10
|
-
if (!client.chain) {
|
|
11
|
-
throw new ChainNotFoundError();
|
|
12
|
-
}
|
|
13
|
-
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
14
|
-
// in local mode, we probably want some kind of caching for this
|
|
15
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
16
|
-
method: "wallet_requestAccount",
|
|
17
|
-
params: [
|
|
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
|
-
},
|
|
30
|
-
],
|
|
31
|
-
});
|
|
32
|
-
if (!counterfactualInfo && !delegation) {
|
|
33
|
-
throw new InvalidRequestError({
|
|
34
|
-
message: "No counterfactual info or delegated implementation address found.",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const account = await createAccount({
|
|
38
|
-
chain: client.chain,
|
|
39
|
-
transport: custom(client.transport),
|
|
40
|
-
signer: createDummySigner(params.from),
|
|
41
|
-
accountAddress: params.from,
|
|
42
|
-
counterfactualInfo,
|
|
43
|
-
permissions: params.capabilities?.permissions,
|
|
44
|
-
delegation,
|
|
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
|
-
}
|
|
67
|
-
// TODO: oops we don't actually support setting the policyId as an override here
|
|
68
|
-
// if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
|
|
69
|
-
const builtUo = await client.buildUserOperation({
|
|
70
|
-
uo: params.calls.map((x) => ({
|
|
71
|
-
target: x.to,
|
|
72
|
-
data: x.data ?? "0x",
|
|
73
|
-
value: x.value ? fromHex(x.value, "bigint") : undefined,
|
|
74
|
-
})),
|
|
75
|
-
account,
|
|
76
|
-
overrides: {
|
|
77
|
-
...params.capabilities?.gasParamsOverride,
|
|
78
|
-
nonceKey: params.capabilities?.nonceOverride?.nonceKey
|
|
79
|
-
? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
|
|
80
|
-
: undefined,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
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"
|
|
93
|
-
? "user-operation-v070"
|
|
94
|
-
: ep.version === "0.6.0"
|
|
95
|
-
? "user-operation-v060"
|
|
96
|
-
: assertNever(ep.version, "Unexpected entry point version"),
|
|
97
|
-
data: hexlifiedUo,
|
|
98
|
-
chainId: toHex(client.chain.id),
|
|
99
|
-
signatureRequest: {
|
|
100
|
-
type: "personal_sign",
|
|
101
|
-
data: {
|
|
102
|
-
raw: uoHash,
|
|
103
|
-
},
|
|
104
|
-
rawPayload: hashMessage({
|
|
105
|
-
raw: uoHash,
|
|
106
|
-
}),
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
return authorizationRequest
|
|
110
|
-
? {
|
|
111
|
-
type: "array",
|
|
112
|
-
data: [authorizationRequest, uoRequest],
|
|
113
|
-
}
|
|
114
|
-
: uoRequest;
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;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;IAEpD,MAAM,SAAS,GAAG;QAChB,IAAI,EACF,EAAE,CAAC,OAAO,KAAK,OAAO;YACpB,CAAC,CAAE,qBAA+B;YAClC,CAAC,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO;gBACtB,CAAC,CAAE,qBAA+B;gBAClC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,CAAC;QACjE,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"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|