@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
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type SmartAccountSigner,
|
|
3
|
+
type SmartContractAccount,
|
|
4
|
+
} from "@aa-sdk/core";
|
|
2
5
|
import type { Static } from "@sinclair/typebox";
|
|
3
6
|
import { Value } from "@sinclair/typebox/value";
|
|
4
7
|
import type { Address } from "abitype";
|
|
5
|
-
import
|
|
8
|
+
import deepEqual from "deep-equal";
|
|
9
|
+
import { custom } from "viem";
|
|
6
10
|
import { createAccount } from "../../isomorphic/utils/createAccount.js";
|
|
7
|
-
import type { wallet_requestAccount } from "
|
|
8
|
-
import {
|
|
11
|
+
import type { wallet_requestAccount } from "@alchemy/wallet-api-types/rpc";
|
|
12
|
+
import { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
9
13
|
import type { InnerWalletApiClient } from "../../types.js";
|
|
10
14
|
|
|
11
|
-
export type RequestAccountParams<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Extract<
|
|
19
|
-
Static<typeof wallet_requestAccount>["Request"]["params"][0],
|
|
20
|
-
{ signerAddress: Address }
|
|
21
|
-
>,
|
|
22
|
-
"signerAddress" | "includeCounterfactualInfo"
|
|
23
|
-
>
|
|
24
|
-
: never;
|
|
15
|
+
export type RequestAccountParams = Omit<
|
|
16
|
+
Extract<
|
|
17
|
+
Static<typeof wallet_requestAccount>["Request"]["params"][0],
|
|
18
|
+
{ signerAddress: Address }
|
|
19
|
+
>,
|
|
20
|
+
"signerAddress" | "includeCounterfactualInfo"
|
|
21
|
+
> & { accountAddress?: Address };
|
|
25
22
|
|
|
26
|
-
// TODO: this could be more specific potentially :shrug:
|
|
27
23
|
export type RequestAccountResult = SmartContractAccount;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Requests an account for the provided signer using the wallet API client.
|
|
27
|
+
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
28
|
+
* If an account already exists, the creationHint will be ignored.
|
|
29
|
+
*
|
|
30
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
31
|
+
* @param {SmartAccountSigner} signer - The signer that will be associated with the account
|
|
32
|
+
* @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account
|
|
33
|
+
* @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer
|
|
34
|
+
* @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists
|
|
35
|
+
* @returns {Promise<RequestAccountResult>} A Promise that resolves to a SmartContractAccount instance
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Request an account with default parameters using a local signer
|
|
39
|
+
* const signer = LocalAccountSigner.privateKeyToAccountSigner("0x...");
|
|
40
|
+
* const account = await client.requestAccount(signer);
|
|
41
|
+
*/
|
|
39
42
|
export async function requestAccount(
|
|
40
43
|
client: InnerWalletApiClient,
|
|
41
44
|
signer: SmartAccountSigner,
|
|
42
45
|
params?: RequestAccountParams,
|
|
43
46
|
): Promise<RequestAccountResult> {
|
|
44
47
|
const args =
|
|
45
|
-
client.account && !params
|
|
48
|
+
(client.account && !params) || params?.accountAddress
|
|
46
49
|
? {
|
|
47
|
-
accountAddress: client.account
|
|
50
|
+
accountAddress: params?.accountAddress ?? client.account!.address,
|
|
48
51
|
includeCounterfactualInfo: true,
|
|
49
52
|
}
|
|
50
53
|
: {
|
|
@@ -53,19 +56,35 @@ export async function requestAccount(
|
|
|
53
56
|
includeCounterfactualInfo: true,
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
const cachedAccount = client.internal.getAccount();
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
cachedAccount &&
|
|
63
|
+
((args.accountAddress &&
|
|
64
|
+
cachedAccount.account.address === args.accountAddress) ||
|
|
65
|
+
deepEqual(cachedAccount.requestParams, args, { strict: true }))
|
|
66
|
+
) {
|
|
67
|
+
return cachedAccount.account;
|
|
68
|
+
}
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const { accountAddress, counterfactualInfo, delegation } =
|
|
71
|
+
await client.request({
|
|
72
|
+
method: "wallet_requestAccount",
|
|
73
|
+
params: [args],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const account = await createAccount({
|
|
77
|
+
accountAddress,
|
|
78
|
+
counterfactualInfo: counterfactualInfo
|
|
79
|
+
? Value.Parse(SerializedInitcode, counterfactualInfo)
|
|
80
|
+
: undefined,
|
|
81
|
+
delegation,
|
|
67
82
|
chain: client.chain,
|
|
68
83
|
transport: custom(client.transport),
|
|
69
84
|
signer,
|
|
70
85
|
});
|
|
86
|
+
|
|
87
|
+
client.internal.setAccount({ account, requestParams: args });
|
|
88
|
+
|
|
89
|
+
return account;
|
|
71
90
|
}
|
|
@@ -1,23 +1,60 @@
|
|
|
1
|
-
import type { Static
|
|
1
|
+
import type { Static } from "@sinclair/typebox";
|
|
2
2
|
import { toHex } from "viem";
|
|
3
|
-
import type { wallet_sendPreparedCalls } from "
|
|
4
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
3
|
+
import type { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import type { InnerWalletApiClient, WithoutChainId } from "../../types.ts";
|
|
5
5
|
|
|
6
|
-
export type SendPreparedCallsParams =
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type SendPreparedCallsParams = WithoutChainId<
|
|
7
|
+
Static<
|
|
8
|
+
(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
|
|
9
|
+
>[0]
|
|
9
10
|
>;
|
|
10
11
|
|
|
11
12
|
export type SendPreparedCallsResult = Static<
|
|
12
13
|
typeof wallet_sendPreparedCalls
|
|
13
14
|
>["ReturnType"];
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Sends prepared calls by submitting a signed user operation.
|
|
18
|
+
* This method is used after signing the signature request returned from prepareCalls.
|
|
19
|
+
*
|
|
20
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
21
|
+
* @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
|
|
22
|
+
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // First prepare the calls
|
|
26
|
+
* const preparedCalls = await client.prepareCalls({
|
|
27
|
+
* calls: [{
|
|
28
|
+
* to: "0x1234...",
|
|
29
|
+
* data: "0xabcdef...",
|
|
30
|
+
* value: "0x0"
|
|
31
|
+
* }],
|
|
32
|
+
* capabilities: {
|
|
33
|
+
* paymasterService: { policyId: "your-policy-id" }
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Then sign the calls
|
|
38
|
+
* const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
39
|
+
*
|
|
40
|
+
* // Then send the prepared calls with the signature
|
|
41
|
+
* const result = await client.sendPreparedCalls({
|
|
42
|
+
* signedCalls,
|
|
43
|
+
* });
|
|
44
|
+
*/
|
|
15
45
|
export async function sendPreparedCalls(
|
|
16
46
|
client: InnerWalletApiClient,
|
|
17
47
|
params: SendPreparedCallsParams,
|
|
18
48
|
): Promise<SendPreparedCallsResult> {
|
|
19
49
|
return client.request({
|
|
20
50
|
method: "wallet_sendPreparedCalls",
|
|
21
|
-
params: [
|
|
51
|
+
params: [
|
|
52
|
+
params.type === "array"
|
|
53
|
+
? params
|
|
54
|
+
: {
|
|
55
|
+
...params,
|
|
56
|
+
chainId: toHex(client.chain.id),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
22
59
|
});
|
|
23
60
|
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type Hex,
|
|
5
|
-
type JsonRpcAccount,
|
|
6
|
-
type SignableMessage,
|
|
7
|
-
} from "viem";
|
|
8
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
1
|
+
import { type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import { type Address, type Hex, type SignableMessage } from "viem";
|
|
3
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
9
4
|
import { requestAccount } from "./requestAccount.js";
|
|
10
5
|
|
|
11
|
-
export type SignMessageParams = SignableMessage;
|
|
6
|
+
export type SignMessageParams = { message: SignableMessage; account?: Address };
|
|
12
7
|
|
|
13
8
|
export type SignMessageResult = Hex;
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Signs a message using the smart account.
|
|
12
|
+
* This method requests the account associated with the signer and uses it to sign the message.
|
|
13
|
+
*
|
|
14
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
15
|
+
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
16
|
+
* @param {SignableMessage} message - The message to sign
|
|
17
|
+
* @returns {Promise<SignMessageResult>} A Promise that resolves to the signed message as a hex string
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Sign a simple text message
|
|
21
|
+
* const signature = await client.signMessage("Hello, world!");
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Sign a raw hex message
|
|
25
|
+
* const signature = await client.signMessage({ raw: "0x48656c6c6f2c20776f726c6421" });
|
|
26
|
+
*/
|
|
25
27
|
export async function signMessage(
|
|
26
28
|
client: InnerWalletApiClient,
|
|
27
29
|
signer: SmartAccountSigner,
|
|
28
30
|
params: SignMessageParams,
|
|
29
31
|
): Promise<SignMessageResult> {
|
|
30
|
-
const account = await requestAccount(client, signer
|
|
31
|
-
|
|
32
|
+
const account = await requestAccount(client, signer, {
|
|
33
|
+
accountAddress: params.account ?? client.account?.address,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return account.signMessageWith6492({ message: params.message });
|
|
32
37
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { PrepareCallsResult } from "./prepareCalls.ts";
|
|
2
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
3
|
+
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
4
|
+
import type { Static } from "@sinclair/typebox";
|
|
5
|
+
import { wallet_sendPreparedCalls } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
+
import {
|
|
7
|
+
type PreparedCall_Authorization,
|
|
8
|
+
type PreparedCall_UserOpV060,
|
|
9
|
+
type PreparedCall_UserOpV070,
|
|
10
|
+
} from "@alchemy/wallet-api-types";
|
|
11
|
+
|
|
12
|
+
export type SignPreparedCallsParams = PrepareCallsResult;
|
|
13
|
+
|
|
14
|
+
export type SignPreparedCallsResult = Static<
|
|
15
|
+
(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
|
|
16
|
+
>[0];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Signs prepared calls using the provided signer.
|
|
20
|
+
*
|
|
21
|
+
* @param {SmartAccountSigner} signer - The signer to use
|
|
22
|
+
* @param {SignPreparedCallsParams} params - The prepared calls with signature requests
|
|
23
|
+
* @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
|
|
24
|
+
**/
|
|
25
|
+
export async function signPreparedCalls(
|
|
26
|
+
signer: SmartAccountSigner,
|
|
27
|
+
params: SignPreparedCallsParams,
|
|
28
|
+
): Promise<SignPreparedCallsResult> {
|
|
29
|
+
const signAuthorizationCall = async (call: PreparedCall_Authorization) => {
|
|
30
|
+
const { signatureRequest: _signatureRequest, ...rest } = call;
|
|
31
|
+
const signature = await signSignatureRequest(signer, {
|
|
32
|
+
type: "eip7702Auth",
|
|
33
|
+
data: {
|
|
34
|
+
...rest.data,
|
|
35
|
+
chainId: call.chainId,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
...rest,
|
|
40
|
+
signature,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const signUserOperationCall = async (
|
|
45
|
+
call: PreparedCall_UserOpV060 | PreparedCall_UserOpV070,
|
|
46
|
+
) => {
|
|
47
|
+
const { signatureRequest, ...rest } = call;
|
|
48
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
49
|
+
return {
|
|
50
|
+
...rest,
|
|
51
|
+
signature,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return params.type === "array"
|
|
56
|
+
? {
|
|
57
|
+
type: "array" as const,
|
|
58
|
+
data: await Promise.all(
|
|
59
|
+
params.data.map((call) =>
|
|
60
|
+
call.type === "authorization"
|
|
61
|
+
? signAuthorizationCall(call)
|
|
62
|
+
: signUserOperationCall(call),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
}
|
|
66
|
+
: signUserOperationCall(params);
|
|
67
|
+
}
|
|
@@ -1,34 +1,98 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import type
|
|
3
|
-
import { type Hex } from "viem";
|
|
4
|
-
import { TypeSignatureRequest } from "../../schemas.js";
|
|
2
|
+
import { type Hex, hexToNumber, serializeSignature } from "viem";
|
|
5
3
|
import { assertNever } from "../../utils.js";
|
|
4
|
+
import {
|
|
5
|
+
type PersonalSignSignatureRequest,
|
|
6
|
+
type TypedDataSignatureRequest,
|
|
7
|
+
type AuthorizationSignatureRequest,
|
|
8
|
+
type Eip7702UnsignedAuth,
|
|
9
|
+
} from "@alchemy/wallet-api-types";
|
|
10
|
+
import { vToYParity } from "ox/Signature";
|
|
11
|
+
import type { WithoutRawPayload } from "../../types.ts";
|
|
6
12
|
|
|
7
|
-
export type SignSignatureRequestParams =
|
|
13
|
+
export type SignSignatureRequestParams = WithoutRawPayload<
|
|
14
|
+
| PersonalSignSignatureRequest
|
|
15
|
+
| TypedDataSignatureRequest
|
|
16
|
+
| (AuthorizationSignatureRequest & {
|
|
17
|
+
data: Eip7702UnsignedAuth;
|
|
18
|
+
})
|
|
19
|
+
>;
|
|
8
20
|
|
|
9
21
|
export type SignSignatureRequestResult = {
|
|
10
|
-
type: "
|
|
11
|
-
|
|
22
|
+
type: "secp256k1";
|
|
23
|
+
data: Hex;
|
|
12
24
|
};
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Signs a signature request using the provided signer.
|
|
28
|
+
* This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
|
|
29
|
+
*
|
|
30
|
+
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
31
|
+
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
32
|
+
* @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')
|
|
33
|
+
* @param {any} params.data - The data to sign, format depends on the signature type
|
|
34
|
+
* @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result
|
|
35
|
+
* @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)
|
|
36
|
+
* @returns {Hex} result.signature - The hex-encoded signature
|
|
37
|
+
* @returns {Eip7702ExtendedFields["eip7702Auth"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Sign a personal message
|
|
41
|
+
* const result = await client.signSignatureRequest({
|
|
42
|
+
* type: 'personal_sign',
|
|
43
|
+
* data: 'Hello, world!'
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Sign typed data (EIP-712)
|
|
48
|
+
* const result = await client.signSignatureRequest({
|
|
49
|
+
* type: 'eth_signTypedData_v4',
|
|
50
|
+
* data: {
|
|
51
|
+
* domain: { ... },
|
|
52
|
+
* types: { ... },
|
|
53
|
+
* primaryType: '...',
|
|
54
|
+
* message: { ... }
|
|
55
|
+
* }
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
18
58
|
|
|
19
59
|
export async function signSignatureRequest(
|
|
20
60
|
signer: SmartAccountSigner,
|
|
21
61
|
params: SignSignatureRequestParams,
|
|
22
62
|
): Promise<SignSignatureRequestResult> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
63
|
+
switch (params.type) {
|
|
64
|
+
case "personal_sign": {
|
|
65
|
+
return {
|
|
66
|
+
type: "secp256k1",
|
|
67
|
+
data: await signer.signMessage(params.data),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
case "eth_signTypedData_v4": {
|
|
71
|
+
return {
|
|
72
|
+
type: "secp256k1",
|
|
73
|
+
data: await signer.signTypedData(params.data),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
case "eip7702Auth": {
|
|
77
|
+
if (!signer.signAuthorization) {
|
|
78
|
+
throw new Error("Signer does not implement signAuthorization");
|
|
79
|
+
}
|
|
80
|
+
const { r, s, v, yParity } = await signer.signAuthorization({
|
|
81
|
+
...params.data,
|
|
82
|
+
chainId: hexToNumber(params.data.chainId),
|
|
83
|
+
nonce: hexToNumber(params.data.nonce),
|
|
84
|
+
});
|
|
29
85
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
86
|
+
return {
|
|
87
|
+
type: "secp256k1",
|
|
88
|
+
data: serializeSignature({
|
|
89
|
+
r,
|
|
90
|
+
s,
|
|
91
|
+
yParity: yParity ?? vToYParity(Number(v)),
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
return assertNever(params, `Unexpected signature request type.`);
|
|
97
|
+
}
|
|
34
98
|
}
|
|
@@ -1,32 +1,53 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type Hex,
|
|
5
|
-
type JsonRpcAccount,
|
|
6
|
-
type TypedDataDefinition,
|
|
7
|
-
} from "viem";
|
|
8
|
-
import type { InnerWalletApiClient } from "../../types";
|
|
2
|
+
import { type Address, type Hex, type TypedDataDefinition } from "viem";
|
|
3
|
+
import type { InnerWalletApiClient } from "../../types.ts";
|
|
9
4
|
import { requestAccount } from "./requestAccount.js";
|
|
10
5
|
|
|
11
|
-
export type SignTypedDataParams = TypedDataDefinition
|
|
6
|
+
export type SignTypedDataParams = TypedDataDefinition & {
|
|
7
|
+
account?: Address;
|
|
8
|
+
};
|
|
12
9
|
|
|
13
10
|
export type SignTypedDataResult = Hex;
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Signs typed data (EIP-712) using the smart account.
|
|
14
|
+
* This method requests the account associated with the signer and uses it to sign the typed data.
|
|
15
|
+
*
|
|
16
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
17
|
+
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
18
|
+
* @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
|
|
19
|
+
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Sign typed data
|
|
23
|
+
* const signature = await client.signTypedData({
|
|
24
|
+
* domain: {
|
|
25
|
+
* name: 'Example DApp',
|
|
26
|
+
* version: '1',
|
|
27
|
+
* chainId: 1,
|
|
28
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
|
|
29
|
+
* },
|
|
30
|
+
* types: {
|
|
31
|
+
* Person: [
|
|
32
|
+
* { name: 'name', type: 'string' },
|
|
33
|
+
* { name: 'wallet', type: 'address' }
|
|
34
|
+
* ]
|
|
35
|
+
* },
|
|
36
|
+
* primaryType: 'Person',
|
|
37
|
+
* message: {
|
|
38
|
+
* name: 'John Doe',
|
|
39
|
+
* wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'
|
|
40
|
+
* }
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
25
43
|
export async function signTypedData(
|
|
26
44
|
client: InnerWalletApiClient,
|
|
27
45
|
signer: SmartAccountSigner,
|
|
28
46
|
params: SignTypedDataParams,
|
|
29
47
|
): Promise<SignTypedDataResult> {
|
|
30
|
-
const account = await requestAccount(client, signer
|
|
48
|
+
const account = await requestAccount(client, signer, {
|
|
49
|
+
accountAddress: params.account ?? client.account?.address,
|
|
50
|
+
});
|
|
51
|
+
|
|
31
52
|
return account.signTypedDataWith6492(params);
|
|
32
53
|
}
|