@account-kit/wallet-client 0.1.0-alpha.5 → 0.1.0-alpha.6
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/capabilities/eip7702Auth.js +3 -1
- package/dist/esm/capabilities/eip7702Auth.js.map +1 -1
- package/dist/esm/capabilities/overrides.js +8 -8
- package/dist/esm/capabilities/overrides.js.map +1 -1
- package/dist/esm/capabilities/permissions/index.d.ts +1 -1
- package/dist/esm/capabilities/permissions/index.js +6 -3
- package/dist/esm/capabilities/permissions/index.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +5 -60
- package/dist/esm/client/actions/grantPermissions.js +5 -58
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
- package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +53 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
- package/dist/esm/client/actions/signSignatureRequest.js +69 -31
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +28 -25
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +3 -1
- package/dist/esm/client/decorator.js +3 -1
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/exports/index.d.ts +2 -1
- package/dist/esm/exports/index.js +2 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +18 -32
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +139 -13
- package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
- package/dist/esm/isomorphic/utils/7702.js +14 -6
- package/dist/esm/isomorphic/utils/7702.js.map +1 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- package/dist/esm/local/client.js +2 -3
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.js +3 -7
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/examples.d.ts +3 -3
- package/dist/esm/rpc/examples.js +3 -3
- package/dist/esm/rpc/examples.js.map +1 -1
- package/dist/esm/rpc/request.d.ts +357 -49
- package/dist/esm/rpc/request.js +26 -53
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +323 -57
- package/dist/esm/rpc/schema.js.map +1 -1
- package/dist/esm/schemas.d.ts +451 -13
- package/dist/esm/schemas.js +165 -52
- package/dist/esm/schemas.js.map +1 -1
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/index.d.ts +1 -1
- package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +5 -60
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
- package/dist/types/client/actions/sendPreparedCalls.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 +8 -7
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +3 -1
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +2 -1
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +139 -13
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +4 -3
- package/dist/types/isomorphic/utils/7702.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/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/examples.d.ts +3 -3
- package/dist/types/rpc/examples.d.ts.map +1 -1
- package/dist/types/rpc/request.d.ts +357 -49
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +323 -57
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +451 -13
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/capabilities/eip7702Auth.ts +17 -10
- package/src/capabilities/overrides.ts +8 -8
- package/src/capabilities/permissions/index.ts +8 -3
- package/src/client/actions/grantPermissions.ts +5 -60
- package/src/client/actions/sendPreparedCalls.ts +17 -17
- package/src/client/actions/signPreparedCalls.ts +71 -0
- package/src/client/actions/signSignatureRequest.ts +50 -46
- package/src/client/client.e2e-test.ts +32 -35
- package/src/client/decorator.ts +14 -5
- package/src/exports/index.ts +2 -1
- package/src/isomorphic/actions/createSession.ts +20 -42
- package/src/isomorphic/actions/prepareCalls.ts +25 -17
- package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
- package/src/isomorphic/utils/7702.ts +18 -8
- package/src/isomorphic/utils/decodeSignature.ts +18 -0
- package/src/local/client.ts +2 -6
- package/src/remote/client.ts +3 -10
- package/src/rpc/examples.ts +3 -4
- package/src/rpc/request.ts +41 -63
- package/src/rpc/schema.ts +2 -2
- package/src/schemas.ts +227 -53
- package/src/types.ts +4 -0
|
@@ -3,32 +3,32 @@ import { TypeHex } from "../schemas.js";
|
|
|
3
3
|
|
|
4
4
|
export const Mutliplier = Type.Object(
|
|
5
5
|
{ multiplier: Type.Number() },
|
|
6
|
-
{
|
|
6
|
+
{ description: "Multiplier" },
|
|
7
7
|
);
|
|
8
8
|
|
|
9
9
|
// This is still being defined in https://github.com/ethereum/ERCs/pull/947/files#diff-dab085f963ca621595044bcbc0922705aa38b69f5bf8770dcb3d0496a633efcfR158
|
|
10
10
|
export const GasParamsOverrideCapability = Type.Object(
|
|
11
11
|
{
|
|
12
12
|
preVerificationGas: Type.Optional(
|
|
13
|
-
Type.Union([TypeHex({
|
|
13
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
14
14
|
),
|
|
15
15
|
verificationGasLimit: Type.Optional(
|
|
16
|
-
Type.Union([TypeHex({
|
|
16
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
17
17
|
),
|
|
18
18
|
callGasLimit: Type.Optional(
|
|
19
|
-
Type.Union([TypeHex({
|
|
19
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
20
20
|
),
|
|
21
21
|
paymasterVerificationGasLimit: Type.Optional(
|
|
22
|
-
Type.Union([TypeHex({
|
|
22
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
23
23
|
),
|
|
24
24
|
paymasterPostOpGasLimit: Type.Optional(
|
|
25
|
-
Type.Union([TypeHex({
|
|
25
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
26
26
|
),
|
|
27
27
|
maxFeePerGas: Type.Optional(
|
|
28
|
-
Type.Union([TypeHex({
|
|
28
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
29
29
|
),
|
|
30
30
|
maxPriorityFeePerGas: Type.Optional(
|
|
31
|
-
Type.Union([TypeHex({
|
|
31
|
+
Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
|
|
32
32
|
),
|
|
33
33
|
},
|
|
34
34
|
{ minProperties: 1 },
|
|
@@ -129,7 +129,7 @@ export const PermissionsContext = Type.Object(
|
|
|
129
129
|
context: TypeHex(),
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
|
-
|
|
132
|
+
description: "Permissions context",
|
|
133
133
|
},
|
|
134
134
|
);
|
|
135
135
|
|
|
@@ -139,13 +139,18 @@ export const RemotePermission = Type.Object(
|
|
|
139
139
|
signature: TypeHex(),
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
|
-
|
|
142
|
+
description: "Remote permission",
|
|
143
143
|
},
|
|
144
144
|
);
|
|
145
145
|
|
|
146
146
|
export const PermissionsData = Type.Object({
|
|
147
147
|
chainId: TypeHex(),
|
|
148
|
-
|
|
148
|
+
expirySec: Type.Optional(
|
|
149
|
+
Type.Integer({
|
|
150
|
+
maximum: 9999999999, // This is valid until November 20, 2286.
|
|
151
|
+
description: "Unix timestamp in seconds (0 for no expiry)",
|
|
152
|
+
}),
|
|
153
|
+
),
|
|
149
154
|
key: KeySigner,
|
|
150
155
|
permissions: PermissionsArray,
|
|
151
156
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AccountNotFoundError, type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
2
|
import { type Address, type Hex, type IsUndefined, toHex } from "viem";
|
|
4
3
|
import type { CreateSessionParams } from "../../isomorphic/actions/createSession.ts";
|
|
5
|
-
import { TypeEip7702AuthExtendedFields } from "../../schemas.js";
|
|
6
4
|
import type { InnerWalletApiClient } from "../../types.ts";
|
|
7
5
|
|
|
8
6
|
export type GrantPermissionsParams<
|
|
@@ -14,7 +12,6 @@ export type GrantPermissionsParams<
|
|
|
14
12
|
|
|
15
13
|
export type GrantPermissionsResult = {
|
|
16
14
|
context: Hex;
|
|
17
|
-
signedAuthorization?: Static<typeof TypeEip7702AuthExtendedFields>;
|
|
18
15
|
};
|
|
19
16
|
|
|
20
17
|
/**
|
|
@@ -25,14 +22,13 @@ export type GrantPermissionsResult = {
|
|
|
25
22
|
* @param {SmartAccountSigner} signer - The signer of the smart account
|
|
26
23
|
* @param {GrantPermissionsParams} params - The parameters for granting permissions
|
|
27
24
|
* @param {Address} [params.account] - The account address (required if client was not initialized with an account)
|
|
28
|
-
* @param {number} params.
|
|
25
|
+
* @param {number} params.expirySec - Unix timestamp when the permissions expire
|
|
29
26
|
* @param {object} params.key - The session key information
|
|
30
27
|
* @param {string} params.key.publicKey - The public key of the session key
|
|
31
28
|
* @param {string} params.key.type - The type of the key (e.g., "secp256k1")
|
|
32
29
|
* @param {Array} params.permissions - Array of permission objects defining what the session key can do
|
|
33
30
|
* @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier
|
|
34
31
|
* @returns {Hex} result.context - A hex identifier for the granted permissions context
|
|
35
|
-
* @returns {Static<typeof TypeEip7702AuthExtendedFields>} result.signedAuthorization - The EIP-7702 authorization fields, if applicable
|
|
36
32
|
*
|
|
37
33
|
* @example
|
|
38
34
|
* // Create a session key and grant root permissions
|
|
@@ -50,7 +46,7 @@ export type GrantPermissionsResult = {
|
|
|
50
46
|
* });
|
|
51
47
|
*
|
|
52
48
|
* // Use the permissions to prepare a call
|
|
53
|
-
* const
|
|
49
|
+
* const preparedCalls = await client.prepareCalls({
|
|
54
50
|
* calls: [{ to: zeroAddress, value: "0x0" }],
|
|
55
51
|
* from: account.address,
|
|
56
52
|
* capabilities: {
|
|
@@ -62,65 +58,14 @@ export type GrantPermissionsResult = {
|
|
|
62
58
|
* });
|
|
63
59
|
*
|
|
64
60
|
* // Sign with the session key
|
|
65
|
-
* const
|
|
61
|
+
* const signedCalls = await client.signPreparedCalls(
|
|
66
62
|
* sessionKey,
|
|
67
|
-
*
|
|
63
|
+
* preparedCalls,
|
|
68
64
|
* );
|
|
69
65
|
*
|
|
70
66
|
* // Send the prepared call using the session key
|
|
71
67
|
* const result = await client.sendPreparedCalls({
|
|
72
|
-
* ...
|
|
73
|
-
* signature,
|
|
74
|
-
* capabilities: {
|
|
75
|
-
* permissions,
|
|
76
|
-
* },
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* // Create a session key and grant root permissions using a 7702 account
|
|
81
|
-
* const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
|
|
82
|
-
* const account = await client.requestAccount({
|
|
83
|
-
* creationHint: {
|
|
84
|
-
* accountType: "7702",
|
|
85
|
-
* }
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* const permissions = await client.grantPermissions({
|
|
89
|
-
* account: account.address,
|
|
90
|
-
* expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
|
|
91
|
-
* key: {
|
|
92
|
-
* publicKey: await sessionKey.getAddress(),
|
|
93
|
-
* type: "secp256k1",
|
|
94
|
-
* },
|
|
95
|
-
* permissions: [{ type: "root" }],
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* // Use the permissions to prepare a call
|
|
99
|
-
* const preparedCall = await client.prepareCalls({
|
|
100
|
-
* calls: [{ to: zeroAddress, value: "0x0" }],
|
|
101
|
-
* from: account.address,
|
|
102
|
-
* capabilities: {
|
|
103
|
-
* paymasterService: {
|
|
104
|
-
* policyId: "your-paymaster-policy-id",
|
|
105
|
-
* },
|
|
106
|
-
* permissions,
|
|
107
|
-
* },
|
|
108
|
-
* });
|
|
109
|
-
*
|
|
110
|
-
* // Sign with the session key
|
|
111
|
-
* // If the 7702 account delegation is not yet installed, the result
|
|
112
|
-
* // here will include a `signedAuthorization` field that that
|
|
113
|
-
* // must be included when sending the account's first call.
|
|
114
|
-
* const { signedAuthorization, ...signature} = await signSignatureRequest(
|
|
115
|
-
* sessionKey,
|
|
116
|
-
* preparedCall.signatureRequest,
|
|
117
|
-
* );
|
|
118
|
-
*
|
|
119
|
-
* // Send the prepared call using the session key
|
|
120
|
-
* const result = await client.sendPreparedCalls({
|
|
121
|
-
* ...preparedCall,
|
|
122
|
-
* signature,
|
|
123
|
-
* signedAuthorization,
|
|
68
|
+
* ...signedCalls,
|
|
124
69
|
* capabilities: {
|
|
125
70
|
* permissions,
|
|
126
71
|
* },
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { Static
|
|
1
|
+
import type { Static } from "@sinclair/typebox";
|
|
2
2
|
import { toHex } from "viem";
|
|
3
3
|
import type { wallet_sendPreparedCalls } from "../../rpc/request.ts";
|
|
4
|
-
import type { InnerWalletApiClient } from "../../types.ts";
|
|
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<
|
|
@@ -18,13 +19,6 @@ export type SendPreparedCallsResult = Static<
|
|
|
18
19
|
*
|
|
19
20
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
21
|
* @param {SendPreparedCallsParams} params - Parameters for sending prepared calls
|
|
21
|
-
* @param {string} params.type - The user operation type ('user-operation-v060' or 'user-operation-v070')
|
|
22
|
-
* @param {object} params.data - The user operation data without signature
|
|
23
|
-
* @param {string} params.chainId - The chain ID in hex format
|
|
24
|
-
* @param {object} params.signature - The signature object
|
|
25
|
-
* @param {string} params.signature.type - The signature type (must be 'ecdsa')
|
|
26
|
-
* @param {string} params.signature.signature - The hex-encoded signature value
|
|
27
|
-
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
28
22
|
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the prepared call IDs
|
|
29
23
|
*
|
|
30
24
|
* @example
|
|
@@ -40,13 +34,12 @@ export type SendPreparedCallsResult = Static<
|
|
|
40
34
|
* }
|
|
41
35
|
* });
|
|
42
36
|
*
|
|
43
|
-
* //
|
|
44
|
-
* const
|
|
37
|
+
* // Then sign the calls
|
|
38
|
+
* const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
45
39
|
*
|
|
46
40
|
* // Then send the prepared calls with the signature
|
|
47
41
|
* const result = await client.sendPreparedCalls({
|
|
48
|
-
*
|
|
49
|
-
* signature: signedRequest.signature,
|
|
42
|
+
* signedCalls,
|
|
50
43
|
* });
|
|
51
44
|
*/
|
|
52
45
|
export async function sendPreparedCalls(
|
|
@@ -55,6 +48,13 @@ export async function sendPreparedCalls(
|
|
|
55
48
|
): Promise<SendPreparedCallsResult> {
|
|
56
49
|
return client.request({
|
|
57
50
|
method: "wallet_sendPreparedCalls",
|
|
58
|
-
params: [
|
|
51
|
+
params: [
|
|
52
|
+
params.type === "array"
|
|
53
|
+
? params
|
|
54
|
+
: {
|
|
55
|
+
...params,
|
|
56
|
+
chainId: toHex(client.chain.id),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 "../../rpc/request.js";
|
|
6
|
+
import { assertNever } from "../../utils.js";
|
|
7
|
+
|
|
8
|
+
export type SignPreparedCallsParams = PrepareCallsResult;
|
|
9
|
+
|
|
10
|
+
export type SignPreparedCallsResult = Static<
|
|
11
|
+
(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
|
|
12
|
+
>[0];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Signs prepared calls using the provided signer.
|
|
16
|
+
*
|
|
17
|
+
* @param {SmartAccountSigner} signer - The signer to use
|
|
18
|
+
* @param {SignPreparedCallsParams} params - The prepared calls with signature requests
|
|
19
|
+
* @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
|
|
20
|
+
**/
|
|
21
|
+
export async function signPreparedCalls(
|
|
22
|
+
signer: SmartAccountSigner,
|
|
23
|
+
params: SignPreparedCallsParams,
|
|
24
|
+
): Promise<SignPreparedCallsResult> {
|
|
25
|
+
if (params.type !== "array") {
|
|
26
|
+
const { signatureRequest, ...call } = params;
|
|
27
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
28
|
+
return {
|
|
29
|
+
...call,
|
|
30
|
+
signature,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
type: "array" as const,
|
|
36
|
+
data: await Promise.all(
|
|
37
|
+
params.data.map(async (call) => {
|
|
38
|
+
switch (call.type) {
|
|
39
|
+
case "authorization": {
|
|
40
|
+
const signature = await signSignatureRequest(signer, {
|
|
41
|
+
type: "eip7702Auth",
|
|
42
|
+
data: {
|
|
43
|
+
...call.data,
|
|
44
|
+
chainId: call.chainId,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
...call,
|
|
49
|
+
signature,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
case "user-operation-v060":
|
|
53
|
+
case "user-operation-v070": {
|
|
54
|
+
const { signatureRequest, ...rest } = call;
|
|
55
|
+
const signature = await signSignatureRequest(
|
|
56
|
+
signer,
|
|
57
|
+
signatureRequest,
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
...rest,
|
|
61
|
+
signature,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
default: {
|
|
65
|
+
return assertNever(call, "Unexpected call type");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { Static } from "@sinclair/typebox";
|
|
3
|
-
import { type Hex,
|
|
4
|
-
import { TypeSignatureRequest, type TypeSignatureType } from "../../schemas.js";
|
|
3
|
+
import { type Hex, hexToNumber, serializeSignature } from "viem";
|
|
5
4
|
import { assertNever } from "../../utils.js";
|
|
6
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
TypeAuthorizationSignatureRequest,
|
|
7
|
+
TypePersonalSignSignatureRequest,
|
|
8
|
+
TypeTypedDataSignatureRequest,
|
|
9
|
+
} from "../../schemas.js";
|
|
10
|
+
import { TypeEip7702UnsignedAuth } from "../../schemas.js";
|
|
11
|
+
import { vToYParity } from "ox/Signature";
|
|
7
12
|
|
|
8
|
-
export type SignSignatureRequestParams =
|
|
13
|
+
export type SignSignatureRequestParams =
|
|
14
|
+
| Static<typeof TypePersonalSignSignatureRequest>
|
|
15
|
+
| Static<typeof TypeTypedDataSignatureRequest>
|
|
16
|
+
| (Static<typeof TypeAuthorizationSignatureRequest> & {
|
|
17
|
+
data: Static<typeof TypeEip7702UnsignedAuth>;
|
|
18
|
+
});
|
|
9
19
|
|
|
10
20
|
export type SignSignatureRequestResult = {
|
|
11
|
-
type:
|
|
12
|
-
|
|
13
|
-
signedAuthorization?: Eip7702ExtendedFields["eip7702Auth"];
|
|
21
|
+
type: "secp256k1";
|
|
22
|
+
data: Hex;
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* Signs a signature request using the provided signer.
|
|
18
|
-
* This method handles different types of signature requests including personal_sign and
|
|
27
|
+
* This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.
|
|
19
28
|
*
|
|
20
29
|
* @param {SmartAccountSigner} signer - The signer to use for signing the request
|
|
21
30
|
* @param {SignSignatureRequestParams} params - The signature request parameters
|
|
@@ -45,49 +54,44 @@ export type SignSignatureRequestResult = {
|
|
|
45
54
|
* }
|
|
46
55
|
* });
|
|
47
56
|
*/
|
|
48
|
-
export function signSignatureRequest(
|
|
49
|
-
signer: SmartAccountSigner,
|
|
50
|
-
params: SignSignatureRequestParams,
|
|
51
|
-
): Promise<SignSignatureRequestResult>;
|
|
52
57
|
|
|
53
58
|
export async function signSignatureRequest(
|
|
54
59
|
signer: SmartAccountSigner,
|
|
55
60
|
params: SignSignatureRequestParams,
|
|
56
61
|
): Promise<SignSignatureRequestResult> {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
switch (params.type) {
|
|
63
|
+
case "personal_sign": {
|
|
64
|
+
return {
|
|
65
|
+
type: "secp256k1",
|
|
66
|
+
data: await signer.signMessage(params.data),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
case "eth_signTypedData_v4": {
|
|
70
|
+
return {
|
|
71
|
+
type: "secp256k1",
|
|
72
|
+
data: await signer.signTypedData(params.data),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
case "eip7702Auth": {
|
|
76
|
+
if (!signer.signAuthorization) {
|
|
77
|
+
throw new Error("Signer does not implement signAuthorization");
|
|
78
|
+
}
|
|
79
|
+
const { r, s, v, yParity } = await signer.signAuthorization({
|
|
80
|
+
...params.data,
|
|
81
|
+
chainId: hexToNumber(params.data.chainId),
|
|
82
|
+
nonce: hexToNumber(params.data.nonce),
|
|
83
|
+
});
|
|
70
84
|
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
return {
|
|
86
|
+
type: "secp256k1",
|
|
87
|
+
data: serializeSignature({
|
|
88
|
+
r,
|
|
89
|
+
s,
|
|
90
|
+
yParity: yParity ?? vToYParity(Number(v)),
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return assertNever(params, `Unexpected signature request type.`);
|
|
73
96
|
}
|
|
74
|
-
|
|
75
|
-
const authSig = await signer.signAuthorization(params.authorizationRequest);
|
|
76
|
-
const { r, s } = authSig;
|
|
77
|
-
const yParity = toHex(authSig.yParity ?? authSig.v - 27n);
|
|
78
|
-
|
|
79
|
-
const signedAuthorization = {
|
|
80
|
-
chainId: toHex(params.authorizationRequest.chainId),
|
|
81
|
-
nonce: toHex(params.authorizationRequest.nonce),
|
|
82
|
-
address: params.authorizationRequest.address,
|
|
83
|
-
r,
|
|
84
|
-
s,
|
|
85
|
-
yParity,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
type: "secp256k1" as const,
|
|
90
|
-
signature,
|
|
91
|
-
signedAuthorization,
|
|
92
|
-
};
|
|
93
97
|
}
|
|
@@ -2,7 +2,6 @@ import { LocalAccountSigner } from "@aa-sdk/core";
|
|
|
2
2
|
import { alchemy, arbitrumSepolia } from "@account-kit/infra";
|
|
3
3
|
import { describe, expect, it } from "bun:test";
|
|
4
4
|
import { createPublicClient, zeroAddress, type Address } from "viem";
|
|
5
|
-
import { signSignatureRequest } from "./actions/signSignatureRequest.js";
|
|
6
5
|
import { createSmartWalletClient } from "./index.js";
|
|
7
6
|
|
|
8
7
|
describe("Client E2E Tests", () => {
|
|
@@ -122,7 +121,7 @@ describe("Client E2E Tests", () => {
|
|
|
122
121
|
|
|
123
122
|
it("should successfully send a UO with paymaster", async () => {
|
|
124
123
|
const account = await client.requestAccount();
|
|
125
|
-
const
|
|
124
|
+
const preparedCalls = await client.prepareCalls({
|
|
126
125
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
127
126
|
from: account.address,
|
|
128
127
|
capabilities: {
|
|
@@ -132,14 +131,9 @@ describe("Client E2E Tests", () => {
|
|
|
132
131
|
},
|
|
133
132
|
});
|
|
134
133
|
|
|
135
|
-
const
|
|
136
|
-
preparedCall.signatureRequest,
|
|
137
|
-
);
|
|
134
|
+
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
138
135
|
|
|
139
|
-
const result = await client.sendPreparedCalls(
|
|
140
|
-
...preparedCall,
|
|
141
|
-
signature,
|
|
142
|
-
});
|
|
136
|
+
const result = await client.sendPreparedCalls(signedCalls);
|
|
143
137
|
|
|
144
138
|
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
145
139
|
});
|
|
@@ -151,7 +145,7 @@ describe("Client E2E Tests", () => {
|
|
|
151
145
|
|
|
152
146
|
const permissions = await client.grantPermissions({
|
|
153
147
|
account: account.address,
|
|
154
|
-
|
|
148
|
+
expirySec: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
155
149
|
key: {
|
|
156
150
|
publicKey: await sessionKey.getAddress(),
|
|
157
151
|
type: "secp256k1",
|
|
@@ -159,7 +153,14 @@ describe("Client E2E Tests", () => {
|
|
|
159
153
|
permissions: [{ type: "root" }],
|
|
160
154
|
});
|
|
161
155
|
|
|
162
|
-
const
|
|
156
|
+
const sessionKeyClient = createSmartWalletClient({
|
|
157
|
+
transport,
|
|
158
|
+
chain: arbitrumSepolia,
|
|
159
|
+
mode: "local",
|
|
160
|
+
signer: sessionKey,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const preparedCalls = await sessionKeyClient.prepareCalls({
|
|
163
164
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
164
165
|
from: account.address,
|
|
165
166
|
capabilities: {
|
|
@@ -170,14 +171,11 @@ describe("Client E2E Tests", () => {
|
|
|
170
171
|
},
|
|
171
172
|
});
|
|
172
173
|
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
preparedCall.signatureRequest,
|
|
176
|
-
);
|
|
174
|
+
const signedCalls =
|
|
175
|
+
await sessionKeyClient.signPreparedCalls(preparedCalls);
|
|
177
176
|
|
|
178
|
-
const result = await
|
|
179
|
-
...
|
|
180
|
-
signature,
|
|
177
|
+
const result = await sessionKeyClient.sendPreparedCalls({
|
|
178
|
+
...signedCalls,
|
|
181
179
|
capabilities: {
|
|
182
180
|
permissions,
|
|
183
181
|
},
|
|
@@ -295,7 +293,7 @@ describe("Client E2E Tests", () => {
|
|
|
295
293
|
|
|
296
294
|
it("should successfully send a UO with paymaster", async () => {
|
|
297
295
|
const account = await client.requestAccount();
|
|
298
|
-
const
|
|
296
|
+
const preparedCalls = await client.prepareCalls({
|
|
299
297
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
300
298
|
from: account.address,
|
|
301
299
|
capabilities: {
|
|
@@ -305,14 +303,9 @@ describe("Client E2E Tests", () => {
|
|
|
305
303
|
},
|
|
306
304
|
});
|
|
307
305
|
|
|
308
|
-
const
|
|
309
|
-
preparedCall.signatureRequest,
|
|
310
|
-
);
|
|
306
|
+
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
311
307
|
|
|
312
|
-
const result = await client.sendPreparedCalls(
|
|
313
|
-
...preparedCall,
|
|
314
|
-
signature,
|
|
315
|
-
});
|
|
308
|
+
const result = await client.sendPreparedCalls(signedCalls);
|
|
316
309
|
|
|
317
310
|
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
318
311
|
});
|
|
@@ -324,7 +317,7 @@ describe("Client E2E Tests", () => {
|
|
|
324
317
|
|
|
325
318
|
const permissions = await client.grantPermissions({
|
|
326
319
|
account: account.address,
|
|
327
|
-
|
|
320
|
+
expirySec: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
328
321
|
key: {
|
|
329
322
|
publicKey: await sessionKey.getAddress(),
|
|
330
323
|
type: "secp256k1",
|
|
@@ -332,7 +325,14 @@ describe("Client E2E Tests", () => {
|
|
|
332
325
|
permissions: [{ type: "root" }],
|
|
333
326
|
});
|
|
334
327
|
|
|
335
|
-
const
|
|
328
|
+
const sessionKeyClient = createSmartWalletClient({
|
|
329
|
+
transport,
|
|
330
|
+
chain: arbitrumSepolia,
|
|
331
|
+
mode: "remote",
|
|
332
|
+
signer: sessionKey,
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
const preparedCalls = await sessionKeyClient.prepareCalls({
|
|
336
336
|
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
337
337
|
from: account.address,
|
|
338
338
|
capabilities: {
|
|
@@ -343,14 +343,11 @@ describe("Client E2E Tests", () => {
|
|
|
343
343
|
},
|
|
344
344
|
});
|
|
345
345
|
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
preparedCall.signatureRequest,
|
|
349
|
-
);
|
|
346
|
+
const signedCalls =
|
|
347
|
+
await sessionKeyClient.signPreparedCalls(preparedCalls);
|
|
350
348
|
|
|
351
|
-
const result = await
|
|
352
|
-
...
|
|
353
|
-
signature,
|
|
349
|
+
const result = await sessionKeyClient.sendPreparedCalls({
|
|
350
|
+
...signedCalls,
|
|
354
351
|
capabilities: {
|
|
355
352
|
permissions,
|
|
356
353
|
},
|
package/src/client/decorator.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { Address, Hex } from "viem";
|
|
3
|
-
import type {
|
|
4
|
-
SendPreparedCallsParams,
|
|
5
|
-
SendPreparedCallsResult,
|
|
6
|
-
} from "../isomorphic/actions/sendPreparedCalls.ts";
|
|
7
3
|
import type { InnerWalletApiClient } from "../types.ts";
|
|
8
4
|
import {
|
|
9
5
|
createAccount,
|
|
@@ -35,7 +31,11 @@ import {
|
|
|
35
31
|
type RequestAccountParams,
|
|
36
32
|
type RequestAccountResult,
|
|
37
33
|
} from "./actions/requestAccount.js";
|
|
38
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
sendPreparedCalls,
|
|
36
|
+
type SendPreparedCallsParams,
|
|
37
|
+
type SendPreparedCallsResult,
|
|
38
|
+
} from "./actions/sendPreparedCalls.js";
|
|
39
39
|
import { signMessage, type SignMessageParams } from "./actions/signMessage.js";
|
|
40
40
|
import {
|
|
41
41
|
signSignatureRequest,
|
|
@@ -46,6 +46,11 @@ import {
|
|
|
46
46
|
signTypedData,
|
|
47
47
|
type SignTypedDataParams,
|
|
48
48
|
} from "./actions/signTypedData.js";
|
|
49
|
+
import {
|
|
50
|
+
signPreparedCalls,
|
|
51
|
+
type SignPreparedCallsParams,
|
|
52
|
+
type SignPreparedCallsResult,
|
|
53
|
+
} from "./actions/signPreparedCalls.js";
|
|
49
54
|
|
|
50
55
|
export type SmartWalletActions<
|
|
51
56
|
TAccount extends Address | undefined = Address | undefined,
|
|
@@ -67,6 +72,9 @@ export type SmartWalletActions<
|
|
|
67
72
|
signSignatureRequest: (
|
|
68
73
|
params: SignSignatureRequestParams,
|
|
69
74
|
) => Promise<SignSignatureRequestResult>;
|
|
75
|
+
signPreparedCalls: (
|
|
76
|
+
params: SignPreparedCallsParams,
|
|
77
|
+
) => Promise<SignPreparedCallsResult>;
|
|
70
78
|
signMessage: (params: SignMessageParams) => Promise<Hex>;
|
|
71
79
|
signTypedData: (params: SignTypedDataParams) => Promise<Hex>;
|
|
72
80
|
grantPermissions: (
|
|
@@ -88,6 +96,7 @@ export function smartWalletClientActions<
|
|
|
88
96
|
sendPreparedCalls: (params) => sendPreparedCalls(client, params),
|
|
89
97
|
getCallsStatus: (params) => getCallsStatus(client, params),
|
|
90
98
|
signSignatureRequest: (params) => signSignatureRequest(signer, params),
|
|
99
|
+
signPreparedCalls: (params) => signPreparedCalls(signer, params),
|
|
91
100
|
signMessage: (params) => signMessage(client, signer, params),
|
|
92
101
|
signTypedData: (params) => signTypedData(client, signer, params),
|
|
93
102
|
grantPermissions: (params) => grantPermissions(client, signer, params),
|
package/src/exports/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export { grantPermissions } from "../client/actions/grantPermissions.js";
|
|
|
29
29
|
export { listAccounts } from "../client/actions/listAccounts.js";
|
|
30
30
|
export { prepareCalls } from "../client/actions/prepareCalls.js";
|
|
31
31
|
export { requestAccount } from "../client/actions/requestAccount.js";
|
|
32
|
-
export { signMessage } from "../client/actions/signMessage.js";
|
|
33
32
|
export { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
33
|
+
export { signPreparedCalls } from "../client/actions/signPreparedCalls.js";
|
|
34
|
+
export { signMessage } from "../client/actions/signMessage.js";
|
|
34
35
|
export { signTypedData } from "../client/actions/signTypedData.js";
|