@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/client/actions/createAccount.d.ts +27 -2
- package/dist/esm/client/actions/createAccount.js +25 -0
- package/dist/esm/client/actions/createAccount.js.map +1 -1
- package/dist/esm/client/actions/formatSign.d.ts +28 -0
- package/dist/esm/client/actions/formatSign.js +30 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/esm/client/actions/getCallsStatus.js +19 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +63 -6
- package/dist/esm/client/actions/grantPermissions.js +63 -3
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +32 -4
- package/dist/esm/client/actions/listAccounts.js +35 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +32 -6
- package/dist/esm/client/actions/prepareCalls.js +39 -5
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +25 -0
- package/dist/esm/client/actions/prepareSign.js +28 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +24 -6
- package/dist/esm/client/actions/requestAccount.js +38 -7
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/esm/client/actions/sendPreparedCalls.js +37 -1
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +25 -5
- package/dist/esm/client/actions/signMessage.js +22 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +43 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +39 -5
- package/dist/esm/client/actions/signSignatureRequest.js +69 -11
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +37 -4
- package/dist/esm/client/actions/signTypedData.js +34 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +249 -45
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +12 -8
- package/dist/esm/client/decorator.js +5 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +38 -12
- package/dist/esm/client/index.js +0 -3
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +5 -6
- package/dist/esm/exports/index.js +4 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +1 -10
- package/dist/esm/exports/internal.js +0 -12
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/internal/decorator.d.ts +2 -0
- package/dist/esm/internal/decorator.js +10 -0
- package/dist/esm/internal/decorator.js.map +1 -0
- package/dist/esm/isomorphic/actions/createSession.d.ts +1 -2
- package/dist/esm/isomorphic/actions/createSession.js +40 -11
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +8 -0
- package/dist/esm/isomorphic/actions/formatSign.js +42 -0
- package/dist/esm/isomorphic/actions/formatSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/esm/isomorphic/actions/getCallsStatus.js +38 -27
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/esm/isomorphic/actions/prepareCalls.js +78 -20
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +7 -0
- package/dist/esm/isomorphic/actions/prepareSign.js +49 -0
- package/dist/esm/isomorphic/actions/prepareSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +165 -25
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +204 -27
- package/dist/esm/isomorphic/client.js +6 -2
- package/dist/esm/isomorphic/client.js.map +1 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +19 -0
- package/dist/esm/isomorphic/utils/7702.js +70 -0
- package/dist/esm/isomorphic/utils/7702.js.map +1 -0
- package/dist/esm/isomorphic/utils/createAccount.d.ts +5 -4
- package/dist/esm/isomorphic/utils/createAccount.js +84 -10
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +15 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +19 -6
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
- package/dist/esm/local/client.d.ts +3 -3
- package/dist/esm/local/client.js +11 -4
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +9 -3
- package/dist/esm/remote/client.js +10 -11
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/types.d.ts +27 -13
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/client/actions/createAccount.d.ts +27 -2
- package/dist/types/client/actions/createAccount.d.ts.map +1 -1
- package/dist/types/client/actions/formatSign.d.ts +29 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +63 -6
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +32 -4
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +32 -6
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +26 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +24 -6
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +25 -5
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts +39 -5
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +37 -4
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +12 -8
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +38 -12
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +5 -6
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +1 -10
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/internal/decorator.d.ts +3 -0
- package/dist/types/internal/decorator.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/createSession.d.ts +1 -2
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +9 -0
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +8 -0
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +204 -27
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +20 -0
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/createAccount.d.ts +5 -4
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
- package/dist/types/local/client.d.ts +3 -3
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +9 -3
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/types.d.ts +27 -13
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/client/actions/createAccount.ts +27 -2
- package/src/client/actions/formatSign.ts +53 -0
- package/src/client/actions/getCallsStatus.ts +21 -12
- package/src/client/actions/grantPermissions.ts +69 -26
- package/src/client/actions/listAccounts.ts +44 -6
- package/src/client/actions/prepareCalls.ts +46 -26
- package/src/client/actions/prepareSign.ts +46 -0
- package/src/client/actions/requestAccount.ts +60 -41
- package/src/client/actions/sendPreparedCalls.ts +44 -7
- package/src/client/actions/signMessage.ts +26 -21
- package/src/client/actions/signPreparedCalls.ts +67 -0
- package/src/client/actions/signSignatureRequest.ts +84 -20
- package/src/client/actions/signTypedData.ts +40 -19
- package/src/client/client.e2e-test.ts +408 -127
- package/src/client/decorator.ts +28 -26
- package/src/client/index.ts +50 -40
- package/src/exports/index.ts +5 -13
- package/src/exports/internal.ts +2 -10
- package/src/internal/decorator.ts +12 -0
- package/src/isomorphic/actions/createSession.ts +56 -13
- package/src/isomorphic/actions/formatSign.ts +76 -0
- package/src/isomorphic/actions/getCallsStatus.ts +47 -33
- package/src/isomorphic/actions/prepareCalls.ts +95 -23
- package/src/isomorphic/actions/prepareSign.ts +88 -0
- package/src/isomorphic/actions/sendPreparedCalls.ts +218 -42
- package/src/isomorphic/client.ts +10 -2
- package/src/isomorphic/utils/7702.ts +135 -0
- package/src/isomorphic/utils/createAccount.ts +101 -13
- package/src/isomorphic/utils/createDummySigner.ts +3 -2
- package/src/isomorphic/utils/decodeSignature.ts +21 -0
- package/src/isomorphic/utils/parsePermissionsContext.ts +29 -11
- package/src/isomorphic/utils/supportsFeature.ts +34 -0
- package/src/local/client.ts +58 -55
- package/src/remote/client.ts +19 -19
- package/src/types.ts +29 -23
- package/src/utils.ts +2 -0
- package/dist/esm/capabilities/index.d.ts +0 -31
- package/dist/esm/capabilities/index.js +0 -10
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/overrides.d.ts +0 -26
- package/dist/esm/capabilities/overrides.js +0 -14
- package/dist/esm/capabilities/overrides.js.map +0 -1
- package/dist/esm/capabilities/paymaster.d.ts +0 -3
- package/dist/esm/capabilities/paymaster.js +0 -5
- package/dist/esm/capabilities/paymaster.js.map +0 -1
- package/dist/esm/capabilities/permissions/index.d.ts +0 -138
- package/dist/esm/capabilities/permissions/index.js +0 -71
- package/dist/esm/capabilities/permissions/index.js.map +0 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
- package/dist/esm/capabilities/permissions/mav2.js +0 -79
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -352
- package/dist/esm/rpc/request.js +0 -204
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -342
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -216
- package/dist/esm/schemas.js +0 -211
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -32
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/overrides.d.ts +0 -27
- package/dist/types/capabilities/overrides.d.ts.map +0 -1
- package/dist/types/capabilities/paymaster.d.ts +0 -4
- package/dist/types/capabilities/paymaster.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/index.d.ts +0 -139
- package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
- package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -353
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -343
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -217
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/index.ts +0 -13
- package/src/capabilities/overrides.ts +0 -20
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -142
- package/src/capabilities/permissions/mav2.ts +0 -127
- package/src/rpc/request.ts +0 -273
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -257
package/src/client/decorator.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
JsonRpcAccount,
|
|
5
|
-
SignableMessage,
|
|
6
|
-
TypedDataDefinition,
|
|
7
|
-
} from "viem";
|
|
8
|
-
import type {
|
|
9
|
-
SendPreparedCallsParams,
|
|
10
|
-
SendPreparedCallsResult,
|
|
11
|
-
} from "../isomorphic/actions/sendPreparedCalls";
|
|
12
|
-
import type { InnerWalletApiClient } from "../types";
|
|
2
|
+
import type { Address, Hex } from "viem";
|
|
3
|
+
import type { InnerWalletApiClient } from "../types.ts";
|
|
13
4
|
import {
|
|
14
5
|
createAccount,
|
|
15
6
|
type CreateAccountParams,
|
|
@@ -40,20 +31,32 @@ import {
|
|
|
40
31
|
type RequestAccountParams,
|
|
41
32
|
type RequestAccountResult,
|
|
42
33
|
} from "./actions/requestAccount.js";
|
|
43
|
-
import {
|
|
44
|
-
|
|
34
|
+
import {
|
|
35
|
+
sendPreparedCalls,
|
|
36
|
+
type SendPreparedCallsParams,
|
|
37
|
+
type SendPreparedCallsResult,
|
|
38
|
+
} from "./actions/sendPreparedCalls.js";
|
|
39
|
+
import { signMessage, type SignMessageParams } from "./actions/signMessage.js";
|
|
45
40
|
import {
|
|
46
41
|
signSignatureRequest,
|
|
47
42
|
type SignSignatureRequestParams,
|
|
48
43
|
type SignSignatureRequestResult,
|
|
49
44
|
} from "./actions/signSignatureRequest.js";
|
|
50
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
signTypedData,
|
|
47
|
+
type SignTypedDataParams,
|
|
48
|
+
} from "./actions/signTypedData.js";
|
|
49
|
+
import {
|
|
50
|
+
signPreparedCalls,
|
|
51
|
+
type SignPreparedCallsParams,
|
|
52
|
+
type SignPreparedCallsResult,
|
|
53
|
+
} from "./actions/signPreparedCalls.js";
|
|
51
54
|
|
|
52
55
|
export type SmartWalletActions<
|
|
53
|
-
TAccount extends
|
|
56
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
54
57
|
> = {
|
|
55
58
|
requestAccount: (
|
|
56
|
-
params?: RequestAccountParams
|
|
59
|
+
params?: RequestAccountParams,
|
|
57
60
|
) => Promise<RequestAccountResult>;
|
|
58
61
|
prepareCalls: (
|
|
59
62
|
params: PrepareCallsParams<TAccount>,
|
|
@@ -69,32 +72,31 @@ export type SmartWalletActions<
|
|
|
69
72
|
signSignatureRequest: (
|
|
70
73
|
params: SignSignatureRequestParams,
|
|
71
74
|
) => Promise<SignSignatureRequestResult>;
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
signPreparedCalls: (
|
|
76
|
+
params: SignPreparedCallsParams,
|
|
77
|
+
) => Promise<SignPreparedCallsResult>;
|
|
78
|
+
signMessage: (params: SignMessageParams) => Promise<Hex>;
|
|
79
|
+
signTypedData: (params: SignTypedDataParams) => Promise<Hex>;
|
|
74
80
|
grantPermissions: (
|
|
75
81
|
params: GrantPermissionsParams<TAccount>,
|
|
76
82
|
) => Promise<GrantPermissionsResult>;
|
|
77
83
|
};
|
|
78
84
|
|
|
79
85
|
export function smartWalletClientActions<
|
|
80
|
-
TAccount extends
|
|
86
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
81
87
|
>(
|
|
82
|
-
client: InnerWalletApiClient<TAccount>,
|
|
83
|
-
signer: SmartAccountSigner,
|
|
84
|
-
): SmartWalletActions<TAccount>;
|
|
85
|
-
|
|
86
|
-
export function smartWalletClientActions(
|
|
87
88
|
client: InnerWalletApiClient,
|
|
88
89
|
signer: SmartAccountSigner,
|
|
89
|
-
): SmartWalletActions {
|
|
90
|
+
): SmartWalletActions<TAccount> {
|
|
90
91
|
return {
|
|
91
92
|
requestAccount: (params) => requestAccount(client, signer, params),
|
|
92
93
|
createAccount: (params) => createAccount(client, signer, params),
|
|
93
94
|
prepareCalls: (params) => prepareCalls(client, params),
|
|
94
|
-
listAccounts: (params) => listAccounts(client, params),
|
|
95
|
+
listAccounts: (params) => listAccounts(client, signer, params),
|
|
95
96
|
sendPreparedCalls: (params) => sendPreparedCalls(client, params),
|
|
96
97
|
getCallsStatus: (params) => getCallsStatus(client, params),
|
|
97
98
|
signSignatureRequest: (params) => signSignatureRequest(signer, params),
|
|
99
|
+
signPreparedCalls: (params) => signPreparedCalls(signer, params),
|
|
98
100
|
signMessage: (params) => signMessage(client, signer, params),
|
|
99
101
|
signTypedData: (params) => signTypedData(client, signer, params),
|
|
100
102
|
grantPermissions: (params) => grantPermissions(client, signer, params),
|
package/src/client/index.ts
CHANGED
|
@@ -1,55 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
type Address,
|
|
5
|
-
type Chain,
|
|
6
|
-
type IsUndefined,
|
|
7
|
-
type JsonRpcAccount,
|
|
8
|
-
type Prettify,
|
|
9
|
-
} from "viem";
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type { AlchemyTransport } from "@account-kit/infra";
|
|
3
|
+
import type { Address, Chain, Prettify } from "viem";
|
|
10
4
|
import { createLocalClient } from "../local/client.js";
|
|
11
5
|
import { createRemoteClient } from "../remote/client.js";
|
|
12
|
-
import type { InnerWalletApiClient } from "../types";
|
|
6
|
+
import type { InnerWalletApiClient } from "../types.ts";
|
|
13
7
|
import {
|
|
14
8
|
smartWalletClientActions,
|
|
15
9
|
type SmartWalletActions,
|
|
16
10
|
} from "./decorator.js";
|
|
17
11
|
|
|
18
12
|
export type SmartWalletClientParams<
|
|
19
|
-
TAccount extends
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
policyId?: string;
|
|
29
|
-
} & (IsUndefined<TAccount> extends true
|
|
30
|
-
? {
|
|
31
|
-
account?: never;
|
|
32
|
-
}
|
|
33
|
-
: {
|
|
34
|
-
account: Address;
|
|
35
|
-
})
|
|
36
|
-
>;
|
|
13
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
14
|
+
> = Prettify<{
|
|
15
|
+
transport: AlchemyTransport;
|
|
16
|
+
chain: Chain;
|
|
17
|
+
signer: SmartAccountSigner;
|
|
18
|
+
mode: "local" | "remote";
|
|
19
|
+
policyId?: string;
|
|
20
|
+
account?: TAccount | Address | undefined;
|
|
21
|
+
}>;
|
|
37
22
|
|
|
38
|
-
export
|
|
39
|
-
TAccount extends
|
|
40
|
-
|
|
41
|
-
| undefined,
|
|
42
|
-
>(
|
|
43
|
-
params: SmartWalletClientParams<TAccount>,
|
|
44
|
-
): InnerWalletApiClient<TAccount> & SmartWalletActions<TAccount>;
|
|
23
|
+
export type SmartWalletClient<
|
|
24
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
25
|
+
> = InnerWalletApiClient & SmartWalletActions<TAccount>;
|
|
45
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Creates a smart wallet client that can be used to interact with a smart account.
|
|
29
|
+
*
|
|
30
|
+
* @param {SmartWalletClientParams} params - The parameters for creating the smart wallet client
|
|
31
|
+
* @param {AlchemyTransport} params.transport - The Alchemy transport to use
|
|
32
|
+
* @param {Chain} params.chain - The chain to use
|
|
33
|
+
* @param {SmartAccountSigner} params.signer - The signer to use for the smart account
|
|
34
|
+
* @param {"local" | "remote"} params.mode - The client's mode (local or remote).
|
|
35
|
+
* @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
|
|
36
|
+
* @param {Address} [params.account] - The smart account address to use (optional)
|
|
37
|
+
* @returns {SmartWalletClient} - A viem-compatible client
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
41
|
+
* import { alchemy, arbitrumSepolia } from "@account-kit/infra";
|
|
42
|
+
* import { generatePrivateKey } from "viem/accounts";
|
|
43
|
+
* import { createSmartWalletClient } from "@account-kit/wallet-client";
|
|
44
|
+
*
|
|
45
|
+
* const signer = LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey());
|
|
46
|
+
* const transport = alchemy({
|
|
47
|
+
* apiKey: "your-alchemy-api-key",
|
|
48
|
+
* });
|
|
49
|
+
* const client = createSmartWalletClient({
|
|
50
|
+
* transport,
|
|
51
|
+
* chain: arbitrumSepolia,
|
|
52
|
+
* mode: "remote",
|
|
53
|
+
* signer,
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
46
56
|
export function createSmartWalletClient<
|
|
47
|
-
TAccount extends
|
|
48
|
-
>(
|
|
49
|
-
params: SmartWalletClientParams<TAccount>,
|
|
50
|
-
): InnerWalletApiClient<TAccount> & SmartWalletActions<TAccount>;
|
|
57
|
+
TAccount extends Address | undefined = undefined,
|
|
58
|
+
>(params: SmartWalletClientParams<TAccount>): SmartWalletClient<TAccount>;
|
|
51
59
|
|
|
52
|
-
export function createSmartWalletClient(
|
|
60
|
+
export function createSmartWalletClient(
|
|
61
|
+
params: SmartWalletClientParams,
|
|
62
|
+
): SmartWalletClient {
|
|
53
63
|
const { transport, chain, policyId, mode, account, signer } = params;
|
|
54
64
|
|
|
55
65
|
const innerClient =
|
package/src/exports/index.ts
CHANGED
|
@@ -2,31 +2,23 @@
|
|
|
2
2
|
// and we shouldn't export * for the sake of tree-shaking
|
|
3
3
|
export {
|
|
4
4
|
createSmartWalletClient,
|
|
5
|
+
type SmartWalletClient,
|
|
5
6
|
type SmartWalletClientParams,
|
|
6
7
|
} from "../client/index.js";
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
WalletServerRpcSchema,
|
|
10
11
|
type WalletServerRpcSchemaType,
|
|
11
|
-
|
|
12
|
-
} from "../rpc/schema.js";
|
|
13
|
-
|
|
14
|
-
// capabilities: TODO: should these actually just have the types exported?
|
|
15
|
-
export { Capabilities } from "../capabilities/index.js";
|
|
16
|
-
export { PaymasterCapability } from "../capabilities/paymaster.js";
|
|
17
|
-
export {
|
|
18
|
-
PermissionsArray,
|
|
19
|
-
PermissionsCapability,
|
|
20
|
-
PermissionsContext,
|
|
21
|
-
PermissionsData,
|
|
22
|
-
} from "../capabilities/permissions/index.js";
|
|
12
|
+
} from "@alchemy/wallet-api-types/rpc";
|
|
23
13
|
|
|
24
14
|
// client actions
|
|
25
15
|
export { createAccount } from "../client/actions/createAccount.js";
|
|
26
16
|
export { getCallsStatus } from "../client/actions/getCallsStatus.js";
|
|
17
|
+
export { grantPermissions } from "../client/actions/grantPermissions.js";
|
|
27
18
|
export { listAccounts } from "../client/actions/listAccounts.js";
|
|
28
19
|
export { prepareCalls } from "../client/actions/prepareCalls.js";
|
|
29
20
|
export { requestAccount } from "../client/actions/requestAccount.js";
|
|
30
|
-
export { signMessage } from "../client/actions/signMessage.js";
|
|
31
21
|
export { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
22
|
+
export { signPreparedCalls } from "../client/actions/signPreparedCalls.js";
|
|
23
|
+
export { signMessage } from "../client/actions/signMessage.js";
|
|
32
24
|
export { signTypedData } from "../client/actions/signTypedData.js";
|
package/src/exports/internal.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
// exports from this file are meant to be imported by our packages in the monorepo
|
|
2
2
|
// we will expose this in the package.json as a named export like `this-pkg/internal`
|
|
3
3
|
// TODO: name `this-pkg`
|
|
4
|
-
export * from "../capabilities/index.js";
|
|
5
|
-
export * from "../capabilities/paymaster.js";
|
|
6
|
-
export * from "../capabilities/permissions/index.js";
|
|
7
|
-
export * from "../capabilities/permissions/mav2.js";
|
|
8
4
|
export type * from "../isomorphic/client.js";
|
|
9
5
|
export { createIsomorphicClient } from "../isomorphic/client.js";
|
|
10
6
|
export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
|
|
11
|
-
|
|
12
|
-
export *
|
|
13
|
-
export * from "../rpc/schema.js";
|
|
14
|
-
export * from "../schemas.js";
|
|
15
|
-
export type * from "../types";
|
|
16
|
-
export * from "../utils.js";
|
|
7
|
+
|
|
8
|
+
export type * from "../types.ts";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CachedAccount, InternalState } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
export function internalStateDecorator(): InternalState {
|
|
4
|
+
let account: CachedAccount | undefined = undefined;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
setAccount: (newAccount: CachedAccount) => {
|
|
8
|
+
account = newAccount;
|
|
9
|
+
},
|
|
10
|
+
getAccount: () => account,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -12,18 +12,26 @@ import { Value } from "@sinclair/typebox/value";
|
|
|
12
12
|
import {
|
|
13
13
|
ChainNotFoundError,
|
|
14
14
|
custom,
|
|
15
|
+
hashTypedData,
|
|
15
16
|
hexToNumber,
|
|
16
17
|
toHex,
|
|
17
18
|
type Chain,
|
|
18
19
|
type Hex,
|
|
19
20
|
type Transport,
|
|
20
21
|
} from "viem";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
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";
|
|
25
31
|
import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
|
|
26
32
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
33
|
+
import { supportsFeature } from "../utils/supportsFeature.js";
|
|
34
|
+
import { isDelegated } from "../utils/7702.js";
|
|
27
35
|
|
|
28
36
|
export type CreateSessionParams = Omit<
|
|
29
37
|
Static<
|
|
@@ -57,29 +65,58 @@ export async function createSession(
|
|
|
57
65
|
throw new ChainNotFoundError();
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
const { counterfactualInfo } = await client.request({
|
|
68
|
+
const { counterfactualInfo, delegation } = await client.request({
|
|
61
69
|
method: "wallet_requestAccount",
|
|
62
70
|
params: [
|
|
63
71
|
{
|
|
64
|
-
includeCounterfactualInfo: true,
|
|
65
72
|
accountAddress: params.account,
|
|
73
|
+
includeCounterfactualInfo: true,
|
|
66
74
|
},
|
|
67
75
|
],
|
|
68
76
|
});
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
});
|
|
71
89
|
}
|
|
72
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
|
|
73
107
|
const account = await createAccount({
|
|
74
108
|
chain: client.chain,
|
|
75
109
|
transport: custom(client.transport),
|
|
76
110
|
signer: createDummySigner(params.account),
|
|
77
111
|
accountAddress: params.account,
|
|
78
112
|
counterfactualInfo,
|
|
113
|
+
delegation,
|
|
79
114
|
});
|
|
80
115
|
|
|
81
116
|
if (!isModularAccountV2(account)) {
|
|
82
|
-
throw new
|
|
117
|
+
throw new InvalidRequestError({
|
|
118
|
+
message: "Sessions are currently only supported by MAv2 accounts.",
|
|
119
|
+
});
|
|
83
120
|
}
|
|
84
121
|
|
|
85
122
|
const _client = createSmartAccountClient({
|
|
@@ -96,24 +133,30 @@ export async function createSession(
|
|
|
96
133
|
const { typedData, fullPreSignatureDeferredActionDigest } =
|
|
97
134
|
await new PermissionBuilder({
|
|
98
135
|
client: _client,
|
|
99
|
-
key:
|
|
136
|
+
key: {
|
|
137
|
+
...params.key,
|
|
138
|
+
// Alias 'ecdsa' to 'secp256k1'
|
|
139
|
+
type: params.key.type === "ecdsa" ? "secp256k1" : params.key.type,
|
|
140
|
+
},
|
|
100
141
|
entityId,
|
|
101
142
|
nonce,
|
|
102
|
-
deadline: params.
|
|
143
|
+
deadline: params.expirySec,
|
|
103
144
|
})
|
|
104
145
|
.addPermissions({
|
|
105
146
|
permissions: params.permissions.map((permission) =>
|
|
106
|
-
Value.Encode(
|
|
147
|
+
Value.Encode(Permission, permission),
|
|
107
148
|
),
|
|
108
149
|
})
|
|
109
150
|
.compileDeferred();
|
|
110
151
|
|
|
111
152
|
return {
|
|
112
153
|
sessionId: null, // In remote mode, the server will set this later.
|
|
154
|
+
chainId: toHex(client.chain.id),
|
|
113
155
|
entityId: toHex(entityId),
|
|
114
156
|
signatureRequest: {
|
|
115
|
-
type: "eth_signTypedData_v4",
|
|
157
|
+
type: "eth_signTypedData_v4" as const,
|
|
116
158
|
data: typedData,
|
|
159
|
+
rawPayload: hashTypedData(typedData),
|
|
117
160
|
},
|
|
118
161
|
fullPreSignatureDeferredActionDigest,
|
|
119
162
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -12,9 +12,14 @@ import {
|
|
|
12
12
|
type TransactionReceipt,
|
|
13
13
|
type Transport,
|
|
14
14
|
} from "viem";
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
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";
|
|
18
23
|
import { castToHex } from "../../utils.js";
|
|
19
24
|
|
|
20
25
|
export type GetCallsStatusParams = Static<
|
|
@@ -25,25 +30,6 @@ export type GetCallsStatusResponse = Static<
|
|
|
25
30
|
(typeof wallet_getCallsStatus)["properties"]["ReturnType"]
|
|
26
31
|
>;
|
|
27
32
|
|
|
28
|
-
const ReceiptStatus: Record<TransactionReceipt["status"], Hex> = {
|
|
29
|
-
reverted: "0x0",
|
|
30
|
-
success: "0x1",
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** EIP-5792 call status codes */
|
|
34
|
-
export const CallStatusCode = {
|
|
35
|
-
/** Batch has been received by the wallet but has not completed execution onchain */
|
|
36
|
-
PENDING: 100,
|
|
37
|
-
/** Batch has been included onchain without reverts, receipts array contains info of all calls */
|
|
38
|
-
CONFIRMED: 200,
|
|
39
|
-
/** Batch has not been included onchain and wallet will not retry */
|
|
40
|
-
OFFCHAIN_FAILURE: 400,
|
|
41
|
-
/** Batch reverted *completely* and only changes related to gas charge may have been included onchain */
|
|
42
|
-
CHAIN_RULES_FAILURE: 500,
|
|
43
|
-
/** Batch reverted *partially* and some changes related to batch calls may have been included onchain */
|
|
44
|
-
PARTIAL_CHAIN_RULES_FAILURE: 600,
|
|
45
|
-
} as const;
|
|
46
|
-
|
|
47
33
|
export async function getCallsStatus(
|
|
48
34
|
client: SmartAccountClient<
|
|
49
35
|
Transport,
|
|
@@ -57,24 +43,52 @@ export async function getCallsStatus(
|
|
|
57
43
|
if (!client.chain) {
|
|
58
44
|
throw new ChainNotFoundError();
|
|
59
45
|
}
|
|
46
|
+
const { chainId, hash } = Value.Decode(CallId, callId);
|
|
60
47
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const result = await client.getUserOperationReceipt(hash);
|
|
64
|
-
|
|
65
|
-
return {
|
|
48
|
+
const baseResp = {
|
|
66
49
|
id: callId,
|
|
67
50
|
chainId,
|
|
68
51
|
atomic: true,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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)],
|
|
75
84
|
};
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
const ReceiptStatus: Record<TransactionReceipt["status"], Hex> = {
|
|
88
|
+
reverted: "0x0",
|
|
89
|
+
success: "0x1",
|
|
90
|
+
};
|
|
91
|
+
|
|
78
92
|
function transformReceipt(
|
|
79
93
|
receipt: TransactionReceipt,
|
|
80
94
|
): NonNullable<GetCallsStatusResponse["receipts"]>[number] {
|