@account-kit/wallet-client 0.1.0-alpha.9 → 4.50.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/esm/client/actions/formatSign.d.ts +30 -0
- package/dist/esm/client/actions/formatSign.js +32 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/esm/client/actions/getCallsStatus.js +3 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +10 -11
- package/dist/esm/client/actions/grantPermissions.js +26 -12
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +10 -3
- package/dist/esm/client/actions/listAccounts.js +14 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +6 -3
- package/dist/esm/client/actions/prepareCalls.js +12 -8
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +28 -0
- package/dist/esm/client/actions/prepareSign.js +31 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +3 -1
- package/dist/esm/client/actions/requestAccount.js +5 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/esm/client/actions/sendPreparedCalls.js +2 -0
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +5 -2
- package/dist/esm/client/actions/signMessage.js +5 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/esm/client/actions/signPreparedCalls.js +3 -3
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/esm/client/actions/signSignatureRequest.js +4 -7
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +2 -0
- package/dist/esm/client/actions/signTypedData.js +2 -0
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +0 -2
- package/dist/esm/client/decorator.js +1 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +10 -6
- package/dist/esm/client/index.js +18 -21
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +1 -5
- package/dist/esm/exports/index.js +1 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/internal/account.d.ts +33 -0
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +25 -49
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +5 -11
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +13 -1
- package/dist/esm/utils.js +13 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +4 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/client/actions/formatSign.d.ts +31 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +10 -11
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +10 -3
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +6 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +29 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +3 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +5 -2
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +2 -0
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +0 -2
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +10 -6
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +1 -5
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/internal/account.d.ts +34 -0
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +5 -11
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +13 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +32 -28
- package/src/client/actions/formatSign.ts +55 -0
- package/src/client/actions/getCallsStatus.ts +10 -6
- package/src/client/actions/grantPermissions.ts +46 -18
- package/src/client/actions/listAccounts.ts +22 -5
- package/src/client/actions/prepareCalls.ts +22 -16
- package/src/client/actions/prepareSign.ts +51 -0
- package/src/client/actions/requestAccount.ts +6 -4
- package/src/client/actions/sendPreparedCalls.ts +3 -1
- package/src/client/actions/signMessage.ts +5 -2
- package/src/client/actions/signPreparedCalls.ts +8 -12
- package/src/client/actions/signSignatureRequest.ts +12 -15
- package/src/client/actions/signTypedData.ts +2 -0
- package/src/client/decorator.ts +1 -8
- package/src/client/index.ts +41 -33
- package/src/exports/index.ts +1 -13
- package/src/internal/account.ts +120 -0
- package/src/types.ts +7 -18
- package/src/utils.ts +13 -1
- package/src/version.ts +3 -0
- package/dist/esm/capabilities/eip7702Auth.d.ts +0 -4
- package/dist/esm/capabilities/eip7702Auth.js +0 -18
- package/dist/esm/capabilities/eip7702Auth.js.map +0 -1
- package/dist/esm/capabilities/index.d.ts +0 -41
- package/dist/esm/capabilities/index.js +0 -14
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/multiDimensionalNonce.d.ts +0 -3
- package/dist/esm/capabilities/multiDimensionalNonce.js +0 -7
- package/dist/esm/capabilities/multiDimensionalNonce.js.map +0 -1
- package/dist/esm/capabilities/overrides.d.ts +0 -26
- package/dist/esm/capabilities/overrides.js +0 -14
- package/dist/esm/capabilities/overrides.js.map +0 -1
- package/dist/esm/capabilities/paymaster.d.ts +0 -3
- package/dist/esm/capabilities/paymaster.js +0 -5
- package/dist/esm/capabilities/paymaster.js.map +0 -1
- package/dist/esm/capabilities/permissions/index.d.ts +0 -145
- package/dist/esm/capabilities/permissions/index.js +0 -83
- package/dist/esm/capabilities/permissions/index.js.map +0 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
- package/dist/esm/capabilities/permissions/mav2.js +0 -88
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/client/actions/createAccount.d.ts +0 -35
- package/dist/esm/client/actions/createAccount.js +0 -32
- package/dist/esm/client/actions/createAccount.js.map +0 -1
- package/dist/esm/client/client.e2e-test.d.ts +0 -1
- package/dist/esm/client/client.e2e-test.js +0 -375
- package/dist/esm/client/client.e2e-test.js.map +0 -1
- package/dist/esm/exports/internal.d.ts +0 -14
- package/dist/esm/exports/internal.js +0 -16
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/esm/isomorphic/actions/createSession.js +0 -95
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -157
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -239
- package/dist/esm/isomorphic/client.js +0 -37
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -23
- package/dist/esm/isomorphic/utils/7702.js +0 -75
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -24
- package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
- package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
- package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
- package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
- package/dist/esm/local/client.d.ts +0 -3
- package/dist/esm/local/client.js +0 -97
- package/dist/esm/local/client.js.map +0 -1
- package/dist/esm/remote/client.d.ts +0 -9
- package/dist/esm/remote/client.js +0 -41
- package/dist/esm/remote/client.js.map +0 -1
- package/dist/esm/rpc/examples.d.ts +0 -230
- package/dist/esm/rpc/examples.js +0 -314
- package/dist/esm/rpc/examples.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -755
- package/dist/esm/rpc/request.js +0 -214
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -703
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -712
- package/dist/esm/schemas.js +0 -463
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
- package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -42
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/multiDimensionalNonce.d.ts +0 -4
- package/dist/types/capabilities/multiDimensionalNonce.d.ts.map +0 -1
- package/dist/types/capabilities/overrides.d.ts +0 -27
- package/dist/types/capabilities/overrides.d.ts.map +0 -1
- package/dist/types/capabilities/paymaster.d.ts +0 -4
- package/dist/types/capabilities/paymaster.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/index.d.ts +0 -146
- package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
- package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
- package/dist/types/client/actions/createAccount.d.ts +0 -36
- package/dist/types/client/actions/createAccount.d.ts.map +0 -1
- package/dist/types/client/client.e2e-test.d.ts +0 -2
- package/dist/types/client/client.e2e-test.d.ts.map +0 -1
- package/dist/types/exports/internal.d.ts +0 -15
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -240
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -24
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts +0 -25
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
- package/dist/types/local/client.d.ts +0 -4
- package/dist/types/local/client.d.ts.map +0 -1
- package/dist/types/remote/client.d.ts +0 -10
- package/dist/types/remote/client.d.ts.map +0 -1
- package/dist/types/rpc/examples.d.ts +0 -231
- package/dist/types/rpc/examples.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -756
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -704
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -713
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/eip7702Auth.ts +0 -26
- package/src/capabilities/index.ts +0 -14
- package/src/capabilities/multiDimensionalNonce.ts +0 -7
- package/src/capabilities/overrides.ts +0 -35
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -163
- package/src/capabilities/permissions/mav2.ts +0 -138
- package/src/client/actions/createAccount.ts +0 -53
- package/src/client/client.e2e-test.ts +0 -463
- package/src/exports/internal.ts +0 -17
- package/src/isomorphic/actions/createSession.ts +0 -159
- package/src/isomorphic/actions/getCallsStatus.ts +0 -170
- package/src/isomorphic/actions/prepareCalls.ts +0 -170
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -232
- package/src/isomorphic/client.ts +0 -94
- package/src/isomorphic/utils/7702.ts +0 -143
- package/src/isomorphic/utils/createAccount.ts +0 -170
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -18
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- package/src/remote/client.ts +0 -67
- package/src/rpc/examples.ts +0 -342
- package/src/rpc/request.ts +0 -300
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -657
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { AccountNotFoundError, type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
toHex,
|
|
4
|
+
type Address,
|
|
5
|
+
type Hex,
|
|
6
|
+
type IsUndefined,
|
|
7
|
+
type Prettify,
|
|
8
|
+
} from "viem";
|
|
4
9
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
10
|
+
import type { Static } from "@sinclair/typebox";
|
|
11
|
+
import { wallet_createSession } from "@alchemy/wallet-api-types/rpc";
|
|
12
|
+
import { encodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
|
|
13
|
+
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
5
14
|
|
|
6
15
|
export type GrantPermissionsParams<
|
|
7
16
|
TAccount extends Address | undefined = Address | undefined,
|
|
8
|
-
> =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
> = Prettify<
|
|
18
|
+
Omit<
|
|
19
|
+
Static<
|
|
20
|
+
(typeof wallet_createSession)["properties"]["Request"]["properties"]["params"]
|
|
21
|
+
>[0],
|
|
22
|
+
"account" | "chainId"
|
|
23
|
+
> &
|
|
24
|
+
(IsUndefined<TAccount> extends true
|
|
25
|
+
? { account: Address }
|
|
26
|
+
: { account?: never })
|
|
27
|
+
>;
|
|
12
28
|
|
|
13
29
|
export type GrantPermissionsResult = {
|
|
14
30
|
context: Hex;
|
|
@@ -23,21 +39,21 @@ export type GrantPermissionsResult = {
|
|
|
23
39
|
* @param {GrantPermissionsParams} params - The parameters for granting permissions
|
|
24
40
|
* @param {Address} [params.account] - The account address (required if client was not initialized with an account)
|
|
25
41
|
* @param {number} params.expirySec - Unix timestamp when the permissions expire
|
|
26
|
-
* @param {
|
|
42
|
+
* @param {sessionKeyData} params.key - The session key information
|
|
27
43
|
* @param {string} params.key.publicKey - The public key of the session key
|
|
28
44
|
* @param {string} params.key.type - The type of the key (e.g., "secp256k1")
|
|
29
45
|
* @param {Array} params.permissions - Array of permission objects defining what the session key can do
|
|
30
46
|
* @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
|
|
31
|
-
* @returns {Hex} result.context - A hex identifier for the granted permissions context
|
|
32
47
|
*
|
|
33
48
|
* @example
|
|
49
|
+
* ```ts
|
|
34
50
|
* // Create a session key and grant root permissions
|
|
35
51
|
* const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
|
|
36
52
|
* const account = await client.requestAccount();
|
|
37
53
|
*
|
|
38
54
|
* const permissions = await client.grantPermissions({
|
|
39
55
|
* account: account.address,
|
|
40
|
-
*
|
|
56
|
+
* expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
|
|
41
57
|
* key: {
|
|
42
58
|
* publicKey: await sessionKey.getAddress(),
|
|
43
59
|
* type: "secp256k1",
|
|
@@ -58,10 +74,7 @@ export type GrantPermissionsResult = {
|
|
|
58
74
|
* });
|
|
59
75
|
*
|
|
60
76
|
* // Sign with the session key
|
|
61
|
-
* const signedCalls = await
|
|
62
|
-
* sessionKey,
|
|
63
|
-
* preparedCalls,
|
|
64
|
-
* );
|
|
77
|
+
* const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
|
|
65
78
|
*
|
|
66
79
|
* // Send the prepared call using the session key
|
|
67
80
|
* const result = await client.sendPreparedCalls({
|
|
@@ -70,6 +83,7 @@ export type GrantPermissionsResult = {
|
|
|
70
83
|
* permissions,
|
|
71
84
|
* },
|
|
72
85
|
* });
|
|
86
|
+
* ```
|
|
73
87
|
*/
|
|
74
88
|
export async function grantPermissions<
|
|
75
89
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -79,14 +93,28 @@ export async function grantPermissions<
|
|
|
79
93
|
params: GrantPermissionsParams<TAccount>,
|
|
80
94
|
): Promise<GrantPermissionsResult> {
|
|
81
95
|
const account = params.account ?? client.account?.address;
|
|
82
|
-
|
|
83
96
|
if (!account) {
|
|
84
97
|
throw new AccountNotFoundError();
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
const { sessionId, signatureRequest } = await client.request({
|
|
101
|
+
method: "wallet_createSession",
|
|
102
|
+
params: [
|
|
103
|
+
{
|
|
104
|
+
...params,
|
|
105
|
+
account,
|
|
106
|
+
chainId: toHex(client.chain.id),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
91
109
|
});
|
|
110
|
+
|
|
111
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
context: encodePermissionsContext({
|
|
115
|
+
contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
|
|
116
|
+
sessionId,
|
|
117
|
+
signature: signature.data,
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
92
120
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type { wallet_listAccounts } from "
|
|
2
|
+
import type { wallet_listAccounts } from "@alchemy/wallet-api-types/rpc";
|
|
3
3
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
4
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
5
|
+
import type { Address } from "viem";
|
|
4
6
|
|
|
5
|
-
export type ListAccountsParams =
|
|
6
|
-
typeof wallet_listAccounts
|
|
7
|
-
|
|
7
|
+
export type ListAccountsParams = Omit<
|
|
8
|
+
Static<typeof wallet_listAccounts>["Request"]["params"][0],
|
|
9
|
+
"signerAddress"
|
|
10
|
+
> & { signerAddress?: Address };
|
|
8
11
|
|
|
9
12
|
export type ListAccountsResult = Static<
|
|
10
13
|
typeof wallet_listAccounts
|
|
@@ -14,6 +17,7 @@ export type ListAccountsResult = Static<
|
|
|
14
17
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
15
18
|
*
|
|
16
19
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
|
+
* @param {SmartAccountSigner} signer - The signer for which to list accounts
|
|
17
21
|
* @param {ListAccountsParams} params - Parameters for listing accounts
|
|
18
22
|
* @param {string} params.signerAddress - The address of the signer to list accounts for
|
|
19
23
|
* @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)
|
|
@@ -21,6 +25,7 @@ export type ListAccountsResult = Static<
|
|
|
21
25
|
* @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata
|
|
22
26
|
*
|
|
23
27
|
* @example
|
|
28
|
+
* ```ts
|
|
24
29
|
* // Fetch the first page of accounts
|
|
25
30
|
* const firstPage = await client.listAccounts({
|
|
26
31
|
* signerAddress: "0x123...",
|
|
@@ -33,10 +38,22 @@ export type ListAccountsResult = Static<
|
|
|
33
38
|
* limit: 10,
|
|
34
39
|
* after: firstPage.meta.after
|
|
35
40
|
* });
|
|
41
|
+
* ```
|
|
36
42
|
*/
|
|
37
43
|
export async function listAccounts(
|
|
38
44
|
client: InnerWalletApiClient,
|
|
45
|
+
signer: SmartAccountSigner,
|
|
39
46
|
params: ListAccountsParams,
|
|
40
47
|
): Promise<ListAccountsResult> {
|
|
41
|
-
|
|
48
|
+
const signerAddress = params.signerAddress ?? (await signer.getAddress());
|
|
49
|
+
|
|
50
|
+
return client.request({
|
|
51
|
+
method: "wallet_listAccounts",
|
|
52
|
+
params: [
|
|
53
|
+
{
|
|
54
|
+
...params,
|
|
55
|
+
signerAddress,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
42
59
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { AccountNotFoundError } from "@aa-sdk/core";
|
|
2
2
|
import { toHex, type Address, type IsUndefined } from "viem";
|
|
3
|
-
import type {
|
|
4
|
-
PrepareCallsParams as IsomorphicPrepareCallsParams,
|
|
5
|
-
PrepareCallsResult as IsomorphicPrepareCallsResult,
|
|
6
|
-
} from "../../isomorphic/actions/prepareCalls.ts";
|
|
7
3
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
4
|
+
import type { Static } from "@sinclair/typebox";
|
|
5
|
+
import { wallet_prepareCalls } from "@alchemy/wallet-api-types/rpc";
|
|
8
6
|
|
|
9
7
|
export type GetAccountParam<TAccount> =
|
|
10
8
|
IsUndefined<TAccount> extends true
|
|
@@ -13,10 +11,17 @@ export type GetAccountParam<TAccount> =
|
|
|
13
11
|
|
|
14
12
|
export type PrepareCallsParams<
|
|
15
13
|
TAccount extends Address | undefined = Address | undefined,
|
|
16
|
-
> = Omit<
|
|
14
|
+
> = Omit<
|
|
15
|
+
Static<
|
|
16
|
+
(typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]
|
|
17
|
+
>[0],
|
|
18
|
+
"from" | "chainId"
|
|
19
|
+
> &
|
|
17
20
|
(IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });
|
|
18
21
|
|
|
19
|
-
export type PrepareCallsResult =
|
|
22
|
+
export type PrepareCallsResult = Static<
|
|
23
|
+
typeof wallet_prepareCalls
|
|
24
|
+
>["ReturnType"];
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
@@ -32,6 +37,7 @@ export type PrepareCallsResult = IsomorphicPrepareCallsResult;
|
|
|
32
37
|
* the user operation data and signature request
|
|
33
38
|
*
|
|
34
39
|
* @example
|
|
40
|
+
* ```ts
|
|
35
41
|
* // Prepare a sponsored user operation call
|
|
36
42
|
* const result = await client.prepareCalls({
|
|
37
43
|
* calls: [{
|
|
@@ -43,6 +49,7 @@ export type PrepareCallsResult = IsomorphicPrepareCallsResult;
|
|
|
43
49
|
* paymasterService: { policyId: "your-policy-id" }
|
|
44
50
|
* }
|
|
45
51
|
* });
|
|
52
|
+
* ```
|
|
46
53
|
*/
|
|
47
54
|
export async function prepareCalls<
|
|
48
55
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -51,26 +58,25 @@ export async function prepareCalls<
|
|
|
51
58
|
params: PrepareCallsParams<TAccount>,
|
|
52
59
|
): Promise<PrepareCallsResult> {
|
|
53
60
|
const from = params.from ?? client.account?.address;
|
|
54
|
-
|
|
55
61
|
if (!from) {
|
|
56
62
|
throw new AccountNotFoundError();
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
if (client.
|
|
65
|
+
if (client.policyIds && !params.capabilities?.paymasterService) {
|
|
60
66
|
params.capabilities = {
|
|
61
67
|
...params.capabilities,
|
|
62
|
-
paymasterService: {
|
|
68
|
+
paymasterService: { policyIds: client.policyIds },
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
const params_ = {
|
|
67
|
-
...params,
|
|
68
|
-
chainId: toHex(client.chain.id),
|
|
69
|
-
from,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
72
|
return await client.request({
|
|
73
73
|
method: "wallet_prepareCalls",
|
|
74
|
-
params: [
|
|
74
|
+
params: [
|
|
75
|
+
{
|
|
76
|
+
...params,
|
|
77
|
+
chainId: toHex(client.chain.id),
|
|
78
|
+
from,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
75
81
|
});
|
|
76
82
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
2
|
+
import { toHex, type Address, type IsUndefined } from "viem";
|
|
3
|
+
import { AccountNotFoundError } from "@aa-sdk/core";
|
|
4
|
+
import type { Static } from "@sinclair/typebox";
|
|
5
|
+
import { wallet_prepareSign } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
+
|
|
7
|
+
export type PrepareSignParams<
|
|
8
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
9
|
+
> = Omit<
|
|
10
|
+
Static<
|
|
11
|
+
(typeof wallet_prepareSign)["properties"]["Request"]["properties"]["params"]
|
|
12
|
+
>[0],
|
|
13
|
+
"from" | "chainId"
|
|
14
|
+
> &
|
|
15
|
+
(IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });
|
|
16
|
+
|
|
17
|
+
export type PrepareSignResult = Static<typeof wallet_prepareSign>["ReturnType"];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Prepares a signature request for signing messages or transactions.
|
|
21
|
+
*
|
|
22
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
23
|
+
* @param {PrepareSignParams} params - Parameters for preparing the signature request
|
|
24
|
+
* @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Prepare a message to be signed
|
|
29
|
+
* const result = await client.prepareSign({
|
|
30
|
+
* from: "0x1234...",
|
|
31
|
+
* type: "personal_sign",
|
|
32
|
+
* data: "Hello, world!",
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function prepareSign<
|
|
37
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
38
|
+
>(
|
|
39
|
+
client: InnerWalletApiClient,
|
|
40
|
+
params: PrepareSignParams<TAccount>,
|
|
41
|
+
): Promise<PrepareSignResult> {
|
|
42
|
+
const from = params.from ?? client.account?.address;
|
|
43
|
+
if (!from) {
|
|
44
|
+
throw new AccountNotFoundError();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return client.request({
|
|
48
|
+
method: "wallet_prepareSign",
|
|
49
|
+
params: [{ ...params, from, chainId: toHex(client.chain.id) }],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -7,10 +7,10 @@ import { Value } from "@sinclair/typebox/value";
|
|
|
7
7
|
import type { Address } from "abitype";
|
|
8
8
|
import deepEqual from "deep-equal";
|
|
9
9
|
import { custom } from "viem";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import { TypeSerializedInitcode } from "../../schemas.js";
|
|
10
|
+
import type { wallet_requestAccount } from "@alchemy/wallet-api-types/rpc";
|
|
11
|
+
import { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
13
12
|
import type { InnerWalletApiClient } from "../../types.js";
|
|
13
|
+
import { createAccount } from "../../internal/account.js";
|
|
14
14
|
|
|
15
15
|
export type RequestAccountParams = Omit<
|
|
16
16
|
Extract<
|
|
@@ -35,9 +35,11 @@ export type RequestAccountResult = SmartContractAccount;
|
|
|
35
35
|
* @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
|
+
* ```ts
|
|
38
39
|
* // Request an account with default parameters using a local signer
|
|
39
40
|
* const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
|
|
40
41
|
* const account = await client.requestAccount(signer);
|
|
42
|
+
* ```
|
|
41
43
|
*/
|
|
42
44
|
export async function requestAccount(
|
|
43
45
|
client: InnerWalletApiClient,
|
|
@@ -76,7 +78,7 @@ export async function requestAccount(
|
|
|
76
78
|
const account = await createAccount({
|
|
77
79
|
accountAddress,
|
|
78
80
|
counterfactualInfo: counterfactualInfo
|
|
79
|
-
? Value.Parse(
|
|
81
|
+
? Value.Parse(SerializedInitcode, counterfactualInfo)
|
|
80
82
|
: undefined,
|
|
81
83
|
delegation,
|
|
82
84
|
chain: client.chain,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Static } from "@sinclair/typebox";
|
|
2
2
|
import { toHex } from "viem";
|
|
3
|
-
import type { wallet_sendPreparedCalls } from "
|
|
3
|
+
import type { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
|
|
4
4
|
import type { InnerWalletApiClient, WithoutChainId } from "../../types.ts";
|
|
5
5
|
|
|
6
6
|
export type SendPreparedCallsParams = WithoutChainId<
|
|
@@ -22,6 +22,7 @@ export type SendPreparedCallsResult = Static<
|
|
|
22
22
|
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
|
+
* ```ts
|
|
25
26
|
* // First prepare the calls
|
|
26
27
|
* const preparedCalls = await client.prepareCalls({
|
|
27
28
|
* calls: [{
|
|
@@ -41,6 +42,7 @@ export type SendPreparedCallsResult = Static<
|
|
|
41
42
|
* const result = await client.sendPreparedCalls({
|
|
42
43
|
* signedCalls,
|
|
43
44
|
* });
|
|
45
|
+
* ```
|
|
44
46
|
*/
|
|
45
47
|
export async function sendPreparedCalls(
|
|
46
48
|
client: InnerWalletApiClient,
|
|
@@ -13,16 +13,19 @@ export type SignMessageResult = Hex;
|
|
|
13
13
|
*
|
|
14
14
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
15
15
|
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {SignMessageParams} params - Parameters for signing the message
|
|
17
|
+
* @param {SignableMessage} params.message - The message to sign using EIP-191. Can be a string, or object with raw bytes.
|
|
18
|
+
* @param {Address} [params.account] - Optional account address to use for signing. If not provided, uses the client's current account.
|
|
17
19
|
* @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
|
|
18
20
|
*
|
|
19
21
|
* @example
|
|
22
|
+
* ```ts
|
|
20
23
|
* // Sign a simple text message
|
|
21
24
|
* const signature = await client.signMessage("Hello, world!");
|
|
22
25
|
*
|
|
23
|
-
* @example
|
|
24
26
|
* // Sign a raw hex message
|
|
25
27
|
* const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
|
|
28
|
+
* ```
|
|
26
29
|
*/
|
|
27
30
|
export async function signMessage(
|
|
28
31
|
client: InnerWalletApiClient,
|
|
@@ -2,12 +2,12 @@ import type { PrepareCallsResult } from "./prepareCalls.ts";
|
|
|
2
2
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
3
3
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
4
4
|
import type { Static } from "@sinclair/typebox";
|
|
5
|
-
import { wallet_sendPreparedCalls } from "
|
|
5
|
+
import { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
|
|
6
6
|
import {
|
|
7
|
-
PreparedCall_Authorization,
|
|
8
|
-
PreparedCall_UserOpV060,
|
|
9
|
-
PreparedCall_UserOpV070,
|
|
10
|
-
} from "
|
|
7
|
+
type PreparedCall_Authorization,
|
|
8
|
+
type PreparedCall_UserOpV060,
|
|
9
|
+
type PreparedCall_UserOpV070,
|
|
10
|
+
} from "@alchemy/wallet-api-types";
|
|
11
11
|
|
|
12
12
|
export type SignPreparedCallsParams = PrepareCallsResult;
|
|
13
13
|
|
|
@@ -21,14 +21,12 @@ export type SignPreparedCallsResult = Static<
|
|
|
21
21
|
* @param {SmartAccountSigner} signer - The signer to use
|
|
22
22
|
* @param {SignPreparedCallsParams} params - The prepared calls with signature requests
|
|
23
23
|
* @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
|
|
24
|
-
|
|
24
|
+
*/
|
|
25
25
|
export async function signPreparedCalls(
|
|
26
26
|
signer: SmartAccountSigner,
|
|
27
27
|
params: SignPreparedCallsParams,
|
|
28
28
|
): Promise<SignPreparedCallsResult> {
|
|
29
|
-
const signAuthorizationCall = async (
|
|
30
|
-
call: Static<typeof PreparedCall_Authorization>,
|
|
31
|
-
) => {
|
|
29
|
+
const signAuthorizationCall = async (call: PreparedCall_Authorization) => {
|
|
32
30
|
const { signatureRequest: _signatureRequest, ...rest } = call;
|
|
33
31
|
const signature = await signSignatureRequest(signer, {
|
|
34
32
|
type: "eip7702Auth",
|
|
@@ -44,9 +42,7 @@ export async function signPreparedCalls(
|
|
|
44
42
|
};
|
|
45
43
|
|
|
46
44
|
const signUserOperationCall = async (
|
|
47
|
-
call:
|
|
48
|
-
| Static<typeof PreparedCall_UserOpV060>
|
|
49
|
-
| Static<typeof PreparedCall_UserOpV070>,
|
|
45
|
+
call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,
|
|
50
46
|
) => {
|
|
51
47
|
const { signatureRequest, ...rest } = call;
|
|
52
48
|
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
2
|
import { type Hex, hexToNumber, serializeSignature } from "viem";
|
|
4
3
|
import { assertNever } from "../../utils.js";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
type PersonalSignSignatureRequest,
|
|
6
|
+
type TypedDataSignatureRequest,
|
|
7
|
+
type AuthorizationSignatureRequest,
|
|
8
|
+
type Eip7702UnsignedAuth,
|
|
9
|
+
} from "@alchemy/wallet-api-types";
|
|
11
10
|
import { vToYParity } from "ox/Signature";
|
|
12
11
|
import type { WithoutRawPayload } from "../../types.ts";
|
|
13
12
|
|
|
14
13
|
export type SignSignatureRequestParams = WithoutRawPayload<
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
| (
|
|
18
|
-
data:
|
|
14
|
+
| PersonalSignSignatureRequest
|
|
15
|
+
| TypedDataSignatureRequest
|
|
16
|
+
| (AuthorizationSignatureRequest & {
|
|
17
|
+
data: Eip7702UnsignedAuth;
|
|
19
18
|
})
|
|
20
19
|
>;
|
|
21
20
|
|
|
@@ -31,20 +30,17 @@ export type SignSignatureRequestResult = {
|
|
|
31
30
|
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
32
31
|
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
33
32
|
* @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
|
|
34
|
-
* @param {
|
|
33
|
+
* @param {SignSignatureRequestParams["data"]} params.data - The data to sign, format depends on the signature type
|
|
35
34
|
* @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
|
|
36
|
-
* @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)
|
|
37
|
-
* @returns {Hex} result.signature - The hex-encoded signature
|
|
38
|
-
* @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
|
|
39
35
|
*
|
|
40
36
|
* @example
|
|
37
|
+
* ```ts
|
|
41
38
|
* // Sign a personal message
|
|
42
39
|
* const result = await client.signSignatureRequest({
|
|
43
40
|
* type: 'personal_sign',
|
|
44
41
|
* data: 'Hello, world!'
|
|
45
42
|
* });
|
|
46
43
|
*
|
|
47
|
-
* @example
|
|
48
44
|
* // Sign typed data (EIP-712)
|
|
49
45
|
* const result = await client.signSignatureRequest({
|
|
50
46
|
* type: 'eth_signTypedData_v4',
|
|
@@ -55,6 +51,7 @@ export type SignSignatureRequestResult = {
|
|
|
55
51
|
* message: { ... }
|
|
56
52
|
* }
|
|
57
53
|
* });
|
|
54
|
+
* ```
|
|
58
55
|
*/
|
|
59
56
|
|
|
60
57
|
export async function signSignatureRequest(
|
|
@@ -19,6 +19,7 @@ export type SignTypedDataResult = Hex;
|
|
|
19
19
|
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
+
* ```ts
|
|
22
23
|
* // Sign typed data
|
|
23
24
|
* const signature = await client.signTypedData({
|
|
24
25
|
* domain: {
|
|
@@ -39,6 +40,7 @@ export type SignTypedDataResult = Hex;
|
|
|
39
40
|
* wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'
|
|
40
41
|
* }
|
|
41
42
|
* });
|
|
43
|
+
* ```
|
|
42
44
|
*/
|
|
43
45
|
export async function signTypedData(
|
|
44
46
|
client: InnerWalletApiClient,
|
package/src/client/decorator.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { Address, Hex } from "viem";
|
|
3
3
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
4
|
-
import {
|
|
5
|
-
createAccount,
|
|
6
|
-
type CreateAccountParams,
|
|
7
|
-
type CreateAccountResult,
|
|
8
|
-
} from "./actions/createAccount.js";
|
|
9
4
|
import {
|
|
10
5
|
getCallsStatus,
|
|
11
6
|
type GetCallsStatusParams,
|
|
@@ -64,7 +59,6 @@ export type SmartWalletActions<
|
|
|
64
59
|
sendPreparedCalls: (
|
|
65
60
|
params: SendPreparedCallsParams,
|
|
66
61
|
) => Promise<SendPreparedCallsResult>;
|
|
67
|
-
createAccount: (params: CreateAccountParams) => Promise<CreateAccountResult>;
|
|
68
62
|
listAccounts: (params: ListAccountsParams) => Promise<ListAccountsResult>;
|
|
69
63
|
getCallsStatus: (
|
|
70
64
|
params: GetCallsStatusParams,
|
|
@@ -90,9 +84,8 @@ export function smartWalletClientActions<
|
|
|
90
84
|
): SmartWalletActions<TAccount> {
|
|
91
85
|
return {
|
|
92
86
|
requestAccount: (params) => requestAccount(client, signer, params),
|
|
93
|
-
createAccount: (params) => createAccount(client, signer, params),
|
|
94
87
|
prepareCalls: (params) => prepareCalls(client, params),
|
|
95
|
-
listAccounts: (params) => listAccounts(client, params),
|
|
88
|
+
listAccounts: (params) => listAccounts(client, signer, params),
|
|
96
89
|
sendPreparedCalls: (params) => sendPreparedCalls(client, params),
|
|
97
90
|
getCallsStatus: (params) => getCallsStatus(client, params),
|
|
98
91
|
signSignatureRequest: (params) => signSignatureRequest(signer, params),
|
package/src/client/index.ts
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { AlchemyTransport } from "@account-kit/infra";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
type Address,
|
|
5
|
+
type Chain,
|
|
6
|
+
type Prettify,
|
|
7
|
+
createClient,
|
|
8
|
+
custom,
|
|
9
|
+
} from "viem";
|
|
6
10
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
7
11
|
import {
|
|
8
12
|
smartWalletClientActions,
|
|
9
13
|
type SmartWalletActions,
|
|
10
14
|
} from "./decorator.js";
|
|
15
|
+
import { Provider } from "ox";
|
|
16
|
+
import { WalletServerRpcSchema } from "@alchemy/wallet-api-types/rpc";
|
|
17
|
+
import { internalStateDecorator } from "../internal/decorator.js";
|
|
11
18
|
|
|
12
19
|
export type SmartWalletClientParams<
|
|
13
20
|
TAccount extends Address | undefined = Address | undefined,
|
|
14
|
-
> = Prettify<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
21
|
+
> = Prettify<
|
|
22
|
+
{
|
|
23
|
+
transport: AlchemyTransport;
|
|
24
|
+
chain: Chain;
|
|
25
|
+
signer: SmartAccountSigner;
|
|
26
|
+
account?: TAccount | Address | undefined;
|
|
27
|
+
} & (
|
|
28
|
+
| { policyId?: string; policyIds?: never }
|
|
29
|
+
| { policyIds?: string[]; policyId?: never }
|
|
30
|
+
)
|
|
31
|
+
>;
|
|
22
32
|
|
|
23
33
|
export type SmartWalletClient<
|
|
24
34
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -31,12 +41,12 @@ export type SmartWalletClient<
|
|
|
31
41
|
* @param {AlchemyTransport} params.transport - The Alchemy transport to use
|
|
32
42
|
* @param {Chain} params.chain - The chain to use
|
|
33
43
|
* @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
44
|
* @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
|
|
36
45
|
* @param {Address} [params.account] - The smart account address to use (optional)
|
|
37
46
|
* @returns {SmartWalletClient} - A viem-compatible client
|
|
38
47
|
*
|
|
39
48
|
* @example
|
|
49
|
+
* ```ts
|
|
40
50
|
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
41
51
|
* import { alchemy, arbitrumSepolia } from "@account-kit/infra";
|
|
42
52
|
* import { generatePrivateKey } from "viem/accounts";
|
|
@@ -49,9 +59,9 @@ export type SmartWalletClient<
|
|
|
49
59
|
* const client = createSmartWalletClient({
|
|
50
60
|
* transport,
|
|
51
61
|
* chain: arbitrumSepolia,
|
|
52
|
-
* mode: "remote",
|
|
53
62
|
* signer,
|
|
54
63
|
* });
|
|
64
|
+
* ```
|
|
55
65
|
*/
|
|
56
66
|
export function createSmartWalletClient<
|
|
57
67
|
TAccount extends Address | undefined = undefined,
|
|
@@ -60,26 +70,26 @@ export function createSmartWalletClient<
|
|
|
60
70
|
export function createSmartWalletClient(
|
|
61
71
|
params: SmartWalletClientParams,
|
|
62
72
|
): SmartWalletClient {
|
|
63
|
-
const { transport, chain,
|
|
73
|
+
const { transport, chain, account, signer } = params;
|
|
74
|
+
|
|
75
|
+
const policyIds = params.policyId
|
|
76
|
+
? [params.policyId]
|
|
77
|
+
: params.policyIds
|
|
78
|
+
? params.policyIds
|
|
79
|
+
: undefined;
|
|
64
80
|
|
|
65
|
-
const innerClient =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
policyId,
|
|
77
|
-
account,
|
|
78
|
-
});
|
|
81
|
+
const innerClient = createClient({
|
|
82
|
+
transport: (opts) =>
|
|
83
|
+
custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(
|
|
84
|
+
opts,
|
|
85
|
+
),
|
|
86
|
+
chain,
|
|
87
|
+
account,
|
|
88
|
+
}).extend(() => ({
|
|
89
|
+
policyIds,
|
|
90
|
+
internal: internalStateDecorator(),
|
|
91
|
+
}));
|
|
79
92
|
|
|
80
|
-
// TODO: we need to do a few things here:
|
|
81
|
-
// 1. decorate the client with the wallet api actions
|
|
82
|
-
// 2. potentially we might want to make this client async and have it use `requestAccount` so that it can create a SCA client with an account attached to it
|
|
83
93
|
return innerClient.extend((client) =>
|
|
84
94
|
smartWalletClientActions(client, signer),
|
|
85
95
|
);
|
|
@@ -90,7 +100,6 @@ export function createSmartWalletClient(
|
|
|
90
100
|
// transport: alchemy({ apiKey: "123" }),
|
|
91
101
|
// chain: baseSepolia,
|
|
92
102
|
// signer: createDummySigner(zeroAddress),
|
|
93
|
-
// mode: "local",
|
|
94
103
|
// });
|
|
95
104
|
|
|
96
105
|
// const account1 = await clientWithoutAccount.requestAccount();
|
|
@@ -99,7 +108,6 @@ export function createSmartWalletClient(
|
|
|
99
108
|
// transport: alchemy({ apiKey: "123" }),
|
|
100
109
|
// chain: baseSepolia,
|
|
101
110
|
// signer: createDummySigner(zeroAddress),
|
|
102
|
-
// mode: "local",
|
|
103
111
|
// account: zeroAddress,
|
|
104
112
|
// });
|
|
105
113
|
|