@account-kit/wallet-client 0.1.0-alpha.11 → 0.1.0-alpha.13
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 +3 -2
- 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 +1 -1
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +171 -349
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/index.d.ts +8 -6
- package/dist/esm/client/index.js +18 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +1 -5
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +8 -32
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +4 -10
- 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/index.d.ts +8 -6
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +2 -6
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +4 -10
- 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 +13 -8
- package/src/client/actions/prepareSign.ts +9 -6
- package/src/client/actions/requestAccount.ts +1 -1
- package/src/client/client.e2e-test.ts +208 -442
- package/src/client/index.ts +39 -30
- package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +9 -49
- package/src/types.ts +6 -17
- 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 -183
- 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 -88
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -271
- 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,22 +0,0 @@
|
|
|
1
|
-
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
|
-
import type { Address } from "viem";
|
|
3
|
-
import { PermissionsCapability } from "@alchemy/wallet-api-types/capabilities";
|
|
4
|
-
import { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
5
|
-
export declare function parsePermissionsContext(permissions?: StaticDecode<typeof PermissionsCapability>, parsedCi?: StaticDecode<typeof SerializedInitcode> | undefined, delegation7702?: Address): ({
|
|
6
|
-
contextVersion: keyof typeof import("@alchemy/wallet-api-types/capabilities").PermissionsContextVersion;
|
|
7
|
-
} & {
|
|
8
|
-
contextVersion: "LOCAL_MODE_DEFERRED_ACTION";
|
|
9
|
-
deferredAction: import("viem").Hex;
|
|
10
|
-
sessionId?: never;
|
|
11
|
-
signature?: never;
|
|
12
|
-
}) | ({
|
|
13
|
-
contextVersion: keyof typeof import("@alchemy/wallet-api-types/capabilities").PermissionsContextVersion;
|
|
14
|
-
} & {
|
|
15
|
-
contextVersion: "NON_DEFERRED_ACTION";
|
|
16
|
-
deferredAction?: never;
|
|
17
|
-
sessionId?: never;
|
|
18
|
-
signature?: never;
|
|
19
|
-
entityId: import("viem").Hex;
|
|
20
|
-
isGlobalValidation: boolean;
|
|
21
|
-
}) | undefined;
|
|
22
|
-
//# sourceMappingURL=parsePermissionsContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsePermissionsContext.d.ts","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAEL,qBAAqB,EACtB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,uBAAuB,CACrC,WAAW,CAAC,EAAE,YAAY,CAAC,OAAO,qBAAqB,CAAC,EACxD,QAAQ,CAAC,EAAE,YAAY,CAAC,OAAO,kBAAkB,CAAC,GAAG,SAAS,EAC9D,cAAc,CAAC,EAAE,OAAO;;;;;;;;;;;;;;;;eAqCzB"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
|
-
import type { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
3
|
-
export type Feature = "permissions";
|
|
4
|
-
export declare function supportsFeature(counterfactualInfo: StaticDecode<typeof SerializedInitcode>, feature: Feature): boolean;
|
|
5
|
-
//# sourceMappingURL=supportsFeature.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supportsFeature.d.ts","sourceRoot":"","sources":["../../../../src/isomorphic/utils/supportsFeature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC;AAkBpC,wBAAgB,eAAe,CAC7B,kBAAkB,EAAE,YAAY,CAAC,OAAO,kBAAkB,CAAC,EAC3D,OAAO,EAAE,OAAO,GACf,OAAO,CAST"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Address } from "viem";
|
|
2
|
-
import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
|
|
3
|
-
export declare function createLocalClient<TAccount extends Address | undefined = Address | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
|
|
4
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/local/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAY1D,OAAO,KAAK,EACV,uBAAuB,EAEvB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAWrB,wBAAgB,iBAAiB,CAC/B,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAC1D,MAAM,EAAE,uBAAuB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Address } from "viem";
|
|
2
|
-
import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
|
|
3
|
-
/**
|
|
4
|
-
* This is a low-level client just used to make RPC requests in remote mode
|
|
5
|
-
* This should be wrapped by a higher-level smart account client that provides actions
|
|
6
|
-
* that uses this client under the hood
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare function createRemoteClient<TAccount extends Address | undefined = Address | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
|
|
10
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/remote/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAK1D,OAAO,KAAK,EACV,uBAAuB,EAEvB,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAC1D,MAAM,EAAE,uBAAuB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAAC"}
|
package/src/exports/internal.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// exports from this file are meant to be imported by our packages in the monorepo
|
|
2
|
-
// we will expose this in the package.json as a named export like `this-pkg/internal`
|
|
3
|
-
// TODO: name `this-pkg`
|
|
4
|
-
export type * from "../isomorphic/client.js";
|
|
5
|
-
export { createIsomorphicClient } from "../isomorphic/client.js";
|
|
6
|
-
export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
|
|
7
|
-
|
|
8
|
-
export type * from "../types.ts";
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createSmartAccountClient,
|
|
3
|
-
type SmartAccountClient,
|
|
4
|
-
type SmartContractAccount,
|
|
5
|
-
} from "@aa-sdk/core";
|
|
6
|
-
import {
|
|
7
|
-
deferralActions,
|
|
8
|
-
PermissionBuilder,
|
|
9
|
-
} from "@account-kit/smart-contracts/experimental";
|
|
10
|
-
import type { Static } from "@sinclair/typebox";
|
|
11
|
-
import { Value } from "@sinclair/typebox/value";
|
|
12
|
-
import {
|
|
13
|
-
ChainNotFoundError,
|
|
14
|
-
custom,
|
|
15
|
-
hashTypedData,
|
|
16
|
-
hexToNumber,
|
|
17
|
-
toHex,
|
|
18
|
-
type Chain,
|
|
19
|
-
type Hex,
|
|
20
|
-
type Transport,
|
|
21
|
-
} from "viem";
|
|
22
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
23
|
-
import {
|
|
24
|
-
Permission,
|
|
25
|
-
isGlobalValidation,
|
|
26
|
-
} from "@alchemy/wallet-api-types/capabilities";
|
|
27
|
-
import type {
|
|
28
|
-
wallet_createSession,
|
|
29
|
-
WalletServerViemRpcSchema,
|
|
30
|
-
} from "@alchemy/wallet-api-types/rpc";
|
|
31
|
-
import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
|
|
32
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
33
|
-
import { supportsFeature } from "../utils/supportsFeature.js";
|
|
34
|
-
import { isDelegated } from "../utils/7702.js";
|
|
35
|
-
|
|
36
|
-
export type CreateSessionParams = Omit<
|
|
37
|
-
Static<
|
|
38
|
-
(typeof wallet_createSession)["properties"]["Request"]["properties"]["params"]
|
|
39
|
-
>[0],
|
|
40
|
-
"chainId"
|
|
41
|
-
> & {
|
|
42
|
-
entityId?: Hex;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type CreateSessionResult = Omit<
|
|
46
|
-
Static<(typeof wallet_createSession)["properties"]["ReturnType"]>,
|
|
47
|
-
"sessionId"
|
|
48
|
-
> & {
|
|
49
|
-
sessionId: Hex | null;
|
|
50
|
-
entityId: Hex;
|
|
51
|
-
fullPreSignatureDeferredActionDigest: Hex;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export async function createSession(
|
|
55
|
-
client: SmartAccountClient<
|
|
56
|
-
Transport,
|
|
57
|
-
Chain,
|
|
58
|
-
SmartContractAccount | undefined,
|
|
59
|
-
Record<string, unknown>,
|
|
60
|
-
WalletServerViemRpcSchema
|
|
61
|
-
>,
|
|
62
|
-
params: CreateSessionParams,
|
|
63
|
-
): Promise<CreateSessionResult> {
|
|
64
|
-
if (!client.chain) {
|
|
65
|
-
throw new ChainNotFoundError();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
69
|
-
method: "wallet_requestAccount",
|
|
70
|
-
params: [
|
|
71
|
-
{
|
|
72
|
-
accountAddress: params.account,
|
|
73
|
-
includeCounterfactualInfo: true,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
delegation &&
|
|
80
|
-
!(await isDelegated(client, {
|
|
81
|
-
address: params.account,
|
|
82
|
-
delegation,
|
|
83
|
-
}))
|
|
84
|
-
) {
|
|
85
|
-
throw new InvalidRequestError({
|
|
86
|
-
message:
|
|
87
|
-
"7702 account must be delegated before calling `wallet_createSession`",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!delegation && !counterfactualInfo) {
|
|
92
|
-
throw new InvalidRequestError({
|
|
93
|
-
message: "No counterfactual info found.",
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
counterfactualInfo &&
|
|
99
|
-
!supportsFeature(counterfactualInfo, "permissions")
|
|
100
|
-
) {
|
|
101
|
-
throw new InvalidRequestError({
|
|
102
|
-
message: "Account type does not support createSession",
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// At this point we know the account supports the permission feature
|
|
107
|
-
const account = await createAccount({
|
|
108
|
-
chain: client.chain,
|
|
109
|
-
transport: custom(client.transport),
|
|
110
|
-
signer: createDummySigner(params.account),
|
|
111
|
-
accountAddress: params.account,
|
|
112
|
-
counterfactualInfo,
|
|
113
|
-
delegation,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (!isModularAccountV2(account)) {
|
|
117
|
-
throw new InvalidRequestError({
|
|
118
|
-
message: "Sessions are currently only supported by MAv2 accounts.",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const _client = createSmartAccountClient({
|
|
123
|
-
chain: client.chain,
|
|
124
|
-
transport: custom(client.transport),
|
|
125
|
-
account,
|
|
126
|
-
}).extend(deferralActions);
|
|
127
|
-
|
|
128
|
-
const { entityId, nonce } = await _client.getEntityIdAndNonce({
|
|
129
|
-
entityId: params.entityId ? hexToNumber(params.entityId) : undefined,
|
|
130
|
-
isGlobalValidation: isGlobalValidation(params),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const { typedData, fullPreSignatureDeferredActionDigest } =
|
|
134
|
-
await new PermissionBuilder({
|
|
135
|
-
client: _client,
|
|
136
|
-
key: {
|
|
137
|
-
...params.key,
|
|
138
|
-
// Alias 'ecdsa' to 'secp256k1'
|
|
139
|
-
type: params.key.type === "ecdsa" ? "secp256k1" : params.key.type,
|
|
140
|
-
},
|
|
141
|
-
entityId,
|
|
142
|
-
nonce,
|
|
143
|
-
deadline: params.expirySec,
|
|
144
|
-
})
|
|
145
|
-
.addPermissions({
|
|
146
|
-
permissions: params.permissions.map((permission) =>
|
|
147
|
-
Value.Encode(Permission, permission),
|
|
148
|
-
),
|
|
149
|
-
})
|
|
150
|
-
.compileDeferred();
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
sessionId: null, // In remote mode, the server will set this later.
|
|
154
|
-
chainId: toHex(client.chain.id),
|
|
155
|
-
entityId: toHex(entityId),
|
|
156
|
-
signatureRequest: {
|
|
157
|
-
type: "eth_signTypedData_v4" as const,
|
|
158
|
-
data: typedData,
|
|
159
|
-
rawPayload: hashTypedData(typedData),
|
|
160
|
-
},
|
|
161
|
-
fullPreSignatureDeferredActionDigest,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
@@ -1,76 +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 {
|
|
5
|
-
ChainNotFoundError,
|
|
6
|
-
concat,
|
|
7
|
-
custom,
|
|
8
|
-
encodeAbiParameters,
|
|
9
|
-
parseAbiParameters,
|
|
10
|
-
type Chain,
|
|
11
|
-
type Transport,
|
|
12
|
-
} from "viem";
|
|
13
|
-
import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
14
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
15
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
16
|
-
import { magicBytes } from "ox/erc6492/WrappedSignature";
|
|
17
|
-
|
|
18
|
-
export type FormatSignParams = Static<
|
|
19
|
-
(typeof wallet_formatSign)["properties"]["Request"]["properties"]["params"]
|
|
20
|
-
>[0];
|
|
21
|
-
|
|
22
|
-
export type FormatSignResult = Static<
|
|
23
|
-
(typeof wallet_formatSign)["properties"]["ReturnType"]
|
|
24
|
-
>;
|
|
25
|
-
|
|
26
|
-
export async function formatSign(
|
|
27
|
-
client: SmartAccountClient<
|
|
28
|
-
Transport,
|
|
29
|
-
Chain,
|
|
30
|
-
SmartContractAccount | undefined,
|
|
31
|
-
Record<string, unknown>,
|
|
32
|
-
WalletServerViemRpcSchema
|
|
33
|
-
>,
|
|
34
|
-
params: FormatSignParams,
|
|
35
|
-
): Promise<FormatSignResult> {
|
|
36
|
-
if (!client.chain) {
|
|
37
|
-
throw new ChainNotFoundError();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
41
|
-
method: "wallet_requestAccount",
|
|
42
|
-
params: [
|
|
43
|
-
{
|
|
44
|
-
accountAddress: params.from,
|
|
45
|
-
includeCounterfactualInfo: true,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const account = await createAccount({
|
|
51
|
-
chain: client.chain,
|
|
52
|
-
transport: custom(client.transport),
|
|
53
|
-
signer: createDummySigner(params.from),
|
|
54
|
-
accountAddress: params.from,
|
|
55
|
-
counterfactualInfo,
|
|
56
|
-
permissions: params.capabilities?.permissions,
|
|
57
|
-
delegation,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
let formattedSignature = await account.formatSign(params.signature.data);
|
|
61
|
-
|
|
62
|
-
if (counterfactualInfo && !(await account.isAccountDeployed())) {
|
|
63
|
-
formattedSignature = concat([
|
|
64
|
-
encodeAbiParameters(parseAbiParameters("address, bytes, bytes"), [
|
|
65
|
-
counterfactualInfo.factoryAddress,
|
|
66
|
-
counterfactualInfo.factoryData,
|
|
67
|
-
formattedSignature,
|
|
68
|
-
]),
|
|
69
|
-
magicBytes,
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
signature: formattedSignature,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SmartAccountClient,
|
|
3
|
-
type SmartContractAccount,
|
|
4
|
-
} from "@aa-sdk/core";
|
|
5
|
-
import type { Static } from "@sinclair/typebox";
|
|
6
|
-
import { Value } from "@sinclair/typebox/value";
|
|
7
|
-
import {
|
|
8
|
-
ChainNotFoundError,
|
|
9
|
-
isHex,
|
|
10
|
-
type Chain,
|
|
11
|
-
type Hex,
|
|
12
|
-
type TransactionReceipt,
|
|
13
|
-
type Transport,
|
|
14
|
-
} from "viem";
|
|
15
|
-
import { BaseError } from "ox/RpcResponse";
|
|
16
|
-
import {
|
|
17
|
-
CallStatusCode,
|
|
18
|
-
CallStatusErrorCode,
|
|
19
|
-
type wallet_getCallsStatus,
|
|
20
|
-
type WalletServerViemRpcSchema,
|
|
21
|
-
} from "@alchemy/wallet-api-types/rpc";
|
|
22
|
-
import { CallId } from "@alchemy/wallet-api-types";
|
|
23
|
-
import { castToHex } from "../../utils.js";
|
|
24
|
-
|
|
25
|
-
export type GetCallsStatusParams = Static<
|
|
26
|
-
(typeof wallet_getCallsStatus)["properties"]["Request"]["properties"]["params"]
|
|
27
|
-
>[0];
|
|
28
|
-
|
|
29
|
-
export type GetCallsStatusResponse = Static<
|
|
30
|
-
(typeof wallet_getCallsStatus)["properties"]["ReturnType"]
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export async function getCallsStatus(
|
|
34
|
-
client: SmartAccountClient<
|
|
35
|
-
Transport,
|
|
36
|
-
Chain,
|
|
37
|
-
SmartContractAccount | undefined,
|
|
38
|
-
Record<string, unknown>,
|
|
39
|
-
WalletServerViemRpcSchema
|
|
40
|
-
>,
|
|
41
|
-
callId: GetCallsStatusParams,
|
|
42
|
-
): Promise<GetCallsStatusResponse> {
|
|
43
|
-
if (!client.chain) {
|
|
44
|
-
throw new ChainNotFoundError();
|
|
45
|
-
}
|
|
46
|
-
const { chainId, hash } = Value.Decode(CallId, callId);
|
|
47
|
-
|
|
48
|
-
const baseResp = {
|
|
49
|
-
id: callId,
|
|
50
|
-
chainId,
|
|
51
|
-
atomic: true,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const result = await client.getUserOperationByHash(hash);
|
|
55
|
-
if (!result) {
|
|
56
|
-
throw new BaseError({
|
|
57
|
-
message: `callId ${callId} not found`,
|
|
58
|
-
code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (result && !result.transactionHash) {
|
|
62
|
-
// A result but no txn hash means it's valid but pending.
|
|
63
|
-
return {
|
|
64
|
-
...baseResp,
|
|
65
|
-
status: CallStatusCode.PENDING,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const receipt = await client.getUserOperationReceipt(hash);
|
|
70
|
-
if (!receipt) {
|
|
71
|
-
// Handles edge case of hash being retrieved immediately before the 150 block limit falloff.
|
|
72
|
-
throw new BaseError({
|
|
73
|
-
message: `callId ${callId} not found`,
|
|
74
|
-
code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
...baseResp,
|
|
80
|
-
status: receipt.success
|
|
81
|
-
? CallStatusCode.CONFIRMED
|
|
82
|
-
: CallStatusCode.CHAIN_RULES_FAILURE,
|
|
83
|
-
receipts: [transformReceipt(receipt.receipt)],
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const ReceiptStatus: Record<TransactionReceipt["status"], Hex> = {
|
|
88
|
-
reverted: "0x0",
|
|
89
|
-
success: "0x1",
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
function transformReceipt(
|
|
93
|
-
receipt: TransactionReceipt,
|
|
94
|
-
): NonNullable<GetCallsStatusResponse["receipts"]>[number] {
|
|
95
|
-
return {
|
|
96
|
-
// viem's type for status is "success" | "reverted", but the actual value seems to already be 0x0 or 0x1
|
|
97
|
-
status: isHex(receipt.status)
|
|
98
|
-
? receipt.status
|
|
99
|
-
: ReceiptStatus[receipt.status],
|
|
100
|
-
blockHash: receipt.blockHash,
|
|
101
|
-
// viem's type for blockNumber is bigint, but the actual value seems to already be a hex string
|
|
102
|
-
blockNumber: castToHex(receipt.blockNumber),
|
|
103
|
-
// viem's type for gasUsed is bigint, but the actual value seems to already be a hex string
|
|
104
|
-
gasUsed: castToHex(receipt.gasUsed),
|
|
105
|
-
transactionHash: receipt.transactionHash,
|
|
106
|
-
logs: receipt.logs.map((log) => ({
|
|
107
|
-
address: log.address,
|
|
108
|
-
data: log.data,
|
|
109
|
-
topics: log.topics,
|
|
110
|
-
})),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
deepHexlify,
|
|
3
|
-
default7702GasEstimator,
|
|
4
|
-
type SmartAccountClient,
|
|
5
|
-
type SmartContractAccount,
|
|
6
|
-
} from "@aa-sdk/core";
|
|
7
|
-
import type { Static } from "@sinclair/typebox";
|
|
8
|
-
import {
|
|
9
|
-
ChainNotFoundError,
|
|
10
|
-
custom,
|
|
11
|
-
fromHex,
|
|
12
|
-
hashMessage,
|
|
13
|
-
toHex,
|
|
14
|
-
type Chain,
|
|
15
|
-
type Transport,
|
|
16
|
-
} from "viem";
|
|
17
|
-
import type {
|
|
18
|
-
wallet_prepareCalls,
|
|
19
|
-
WalletServerViemRpcSchema,
|
|
20
|
-
} from "@alchemy/wallet-api-types/rpc";
|
|
21
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
22
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
23
|
-
import { createAuthorizationRequest, isDelegated } from "../utils/7702.js";
|
|
24
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
25
|
-
import { assertNever } from "../../utils.js";
|
|
26
|
-
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
27
|
-
|
|
28
|
-
export type PrepareCallsParams = Omit<
|
|
29
|
-
Static<
|
|
30
|
-
(typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]
|
|
31
|
-
>[0],
|
|
32
|
-
"chainId"
|
|
33
|
-
>;
|
|
34
|
-
|
|
35
|
-
export type PrepareCallsResult = Static<
|
|
36
|
-
(typeof wallet_prepareCalls)["properties"]["ReturnType"]
|
|
37
|
-
>;
|
|
38
|
-
|
|
39
|
-
export async function prepareCalls(
|
|
40
|
-
client: SmartAccountClient<
|
|
41
|
-
Transport,
|
|
42
|
-
Chain,
|
|
43
|
-
SmartContractAccount | undefined,
|
|
44
|
-
Record<string, unknown>,
|
|
45
|
-
WalletServerViemRpcSchema
|
|
46
|
-
>,
|
|
47
|
-
params: PrepareCallsParams,
|
|
48
|
-
): Promise<PrepareCallsResult> {
|
|
49
|
-
if (!client.chain) {
|
|
50
|
-
throw new ChainNotFoundError();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
54
|
-
|
|
55
|
-
// in local mode, we probably want some kind of caching for this
|
|
56
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
57
|
-
method: "wallet_requestAccount",
|
|
58
|
-
params: [
|
|
59
|
-
params.capabilities?.eip7702Auth
|
|
60
|
-
? {
|
|
61
|
-
signerAddress: params.from,
|
|
62
|
-
creationHint: {
|
|
63
|
-
accountType: "7702",
|
|
64
|
-
},
|
|
65
|
-
includeCounterfactualInfo: true,
|
|
66
|
-
}
|
|
67
|
-
: {
|
|
68
|
-
accountAddress: params.from,
|
|
69
|
-
includeCounterfactualInfo: true,
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (!counterfactualInfo && !delegation) {
|
|
75
|
-
throw new InvalidRequestError({
|
|
76
|
-
message:
|
|
77
|
-
"No counterfactual info or delegated implementation address found.",
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const account = await createAccount({
|
|
82
|
-
chain: client.chain,
|
|
83
|
-
transport: custom(client.transport),
|
|
84
|
-
signer: createDummySigner(params.from),
|
|
85
|
-
accountAddress: params.from,
|
|
86
|
-
counterfactualInfo,
|
|
87
|
-
permissions: params.capabilities?.permissions,
|
|
88
|
-
delegation,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const authorizationRequest =
|
|
92
|
-
delegation &&
|
|
93
|
-
!(await isDelegated(client, {
|
|
94
|
-
address: account.address,
|
|
95
|
-
delegation,
|
|
96
|
-
}))
|
|
97
|
-
? await createAuthorizationRequest(client, {
|
|
98
|
-
address: account.address,
|
|
99
|
-
delegation,
|
|
100
|
-
})
|
|
101
|
-
: undefined;
|
|
102
|
-
|
|
103
|
-
if (params.capabilities?.permissions && authorizationRequest) {
|
|
104
|
-
// The user shouldn't see this in most cases since we require
|
|
105
|
-
// the account to be delegated before creating the session.
|
|
106
|
-
throw new InvalidRequestError({
|
|
107
|
-
message:
|
|
108
|
-
"When using a 7702 account with a session key, the account must be delegated before preparing calls.",
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (authorizationRequest) {
|
|
113
|
-
// @ts-expect-error - this is available but not typed as public
|
|
114
|
-
client.middleware.gasEstimator = default7702GasEstimator();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// TODO: oops we don't actually support setting the policyId as an override here
|
|
118
|
-
// if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
|
|
119
|
-
const builtUo = await client.buildUserOperation({
|
|
120
|
-
uo: params.calls.map((x) => ({
|
|
121
|
-
target: x.to,
|
|
122
|
-
data: x.data ?? "0x",
|
|
123
|
-
value: x.value ? fromHex(x.value, "bigint") : undefined,
|
|
124
|
-
})),
|
|
125
|
-
account,
|
|
126
|
-
overrides: {
|
|
127
|
-
...params.capabilities?.gasParamsOverride,
|
|
128
|
-
nonceKey: params.capabilities?.nonceOverride?.nonceKey
|
|
129
|
-
? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
|
|
130
|
-
: undefined,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// The eip7702Auth field should never be included in the UO sig
|
|
135
|
-
// request. It's handled by a separate authorization request.
|
|
136
|
-
if ("eip7702Auth" in builtUo) {
|
|
137
|
-
builtUo.eip7702Auth = undefined;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const hexlifiedUo = deepHexlify(builtUo);
|
|
141
|
-
|
|
142
|
-
const ep = account.getEntryPoint();
|
|
143
|
-
|
|
144
|
-
const uoHash = ep.getUserOperationHash(hexlifiedUo);
|
|
145
|
-
|
|
146
|
-
const uoRequest = {
|
|
147
|
-
type:
|
|
148
|
-
ep.version === "0.7.0"
|
|
149
|
-
? ("user-operation-v070" as const)
|
|
150
|
-
: ep.version === "0.6.0"
|
|
151
|
-
? ("user-operation-v060" as const)
|
|
152
|
-
: assertNever(ep.version, "Unexpected entry point version"),
|
|
153
|
-
data: hexlifiedUo,
|
|
154
|
-
chainId: toHex(client.chain.id),
|
|
155
|
-
signatureRequest: {
|
|
156
|
-
type: "personal_sign" as const,
|
|
157
|
-
data: {
|
|
158
|
-
raw: uoHash,
|
|
159
|
-
},
|
|
160
|
-
rawPayload: hashMessage({
|
|
161
|
-
raw: uoHash,
|
|
162
|
-
}),
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
return authorizationRequest
|
|
167
|
-
? {
|
|
168
|
-
type: "array" as const,
|
|
169
|
-
data: [authorizationRequest, uoRequest],
|
|
170
|
-
}
|
|
171
|
-
: uoRequest;
|
|
172
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type {
|
|
3
|
-
SignatureRequest,
|
|
4
|
-
SmartAccountClient,
|
|
5
|
-
SmartContractAccount,
|
|
6
|
-
} from "@aa-sdk/core";
|
|
7
|
-
import {
|
|
8
|
-
ChainNotFoundError,
|
|
9
|
-
custom,
|
|
10
|
-
toHex,
|
|
11
|
-
type Chain,
|
|
12
|
-
type Transport,
|
|
13
|
-
} from "viem";
|
|
14
|
-
import type {
|
|
15
|
-
wallet_prepareSign,
|
|
16
|
-
WalletServerViemRpcSchema,
|
|
17
|
-
} from "@alchemy/wallet-api-types/rpc";
|
|
18
|
-
import { SignableMessage, jsonSafeTypedData } from "@alchemy/wallet-api-types";
|
|
19
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
20
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
21
|
-
import { Value } from "@sinclair/typebox/value";
|
|
22
|
-
|
|
23
|
-
export type PrepareSignParams = Static<
|
|
24
|
-
(typeof wallet_prepareSign)["properties"]["Request"]["properties"]["params"]
|
|
25
|
-
>[0];
|
|
26
|
-
|
|
27
|
-
export type PrepareSignResult = Static<
|
|
28
|
-
(typeof wallet_prepareSign)["properties"]["ReturnType"]
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
export async function prepareSign(
|
|
32
|
-
client: SmartAccountClient<
|
|
33
|
-
Transport,
|
|
34
|
-
Chain,
|
|
35
|
-
SmartContractAccount | undefined,
|
|
36
|
-
Record<string, unknown>,
|
|
37
|
-
WalletServerViemRpcSchema
|
|
38
|
-
>,
|
|
39
|
-
params: PrepareSignParams,
|
|
40
|
-
): Promise<PrepareSignResult> {
|
|
41
|
-
if (!client.chain) {
|
|
42
|
-
throw new ChainNotFoundError();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
46
|
-
method: "wallet_requestAccount",
|
|
47
|
-
params: [
|
|
48
|
-
{
|
|
49
|
-
accountAddress: params.from,
|
|
50
|
-
includeCounterfactualInfo: true,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const account = await createAccount({
|
|
56
|
-
chain: client.chain,
|
|
57
|
-
transport: custom(client.transport),
|
|
58
|
-
signer: createDummySigner(params.from),
|
|
59
|
-
accountAddress: params.from,
|
|
60
|
-
counterfactualInfo,
|
|
61
|
-
permissions: params.capabilities?.permissions,
|
|
62
|
-
delegation,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const signatureRequest = await account.prepareSign(
|
|
66
|
-
params.signatureRequest as SignatureRequest,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
if (signatureRequest.type === "personal_sign") {
|
|
70
|
-
return {
|
|
71
|
-
chainId: toHex(client.chain.id),
|
|
72
|
-
signatureRequest: {
|
|
73
|
-
type: signatureRequest.type,
|
|
74
|
-
data: Value.Encode(SignableMessage, signatureRequest.data),
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
} else {
|
|
78
|
-
const typedData = signatureRequest.data;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
chainId: toHex(client.chain.id),
|
|
82
|
-
signatureRequest: {
|
|
83
|
-
type: signatureRequest.type,
|
|
84
|
-
data: jsonSafeTypedData(typedData),
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|