@account-kit/wallet-client 0.1.0-alpha.5 → 0.1.0-alpha.7

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.
Files changed (121) hide show
  1. package/dist/esm/capabilities/eip7702Auth.js +3 -1
  2. package/dist/esm/capabilities/eip7702Auth.js.map +1 -1
  3. package/dist/esm/capabilities/overrides.js +8 -8
  4. package/dist/esm/capabilities/overrides.js.map +1 -1
  5. package/dist/esm/capabilities/permissions/index.d.ts +1 -1
  6. package/dist/esm/capabilities/permissions/index.js +6 -3
  7. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +5 -60
  9. package/dist/esm/client/actions/grantPermissions.js +5 -58
  10. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  11. package/dist/esm/client/actions/requestAccount.js +5 -2
  12. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  13. package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
  14. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  15. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  16. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  17. package/dist/esm/client/actions/signPreparedCalls.js +54 -0
  18. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  19. package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
  20. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  21. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  22. package/dist/esm/client/client.e2e-test.js +80 -24
  23. package/dist/esm/client/client.e2e-test.js.map +1 -1
  24. package/dist/esm/client/decorator.d.ts +3 -1
  25. package/dist/esm/client/decorator.js +3 -1
  26. package/dist/esm/client/decorator.js.map +1 -1
  27. package/dist/esm/exports/index.d.ts +2 -1
  28. package/dist/esm/exports/index.js +2 -1
  29. package/dist/esm/exports/index.js.map +1 -1
  30. package/dist/esm/isomorphic/actions/createSession.js +18 -32
  31. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  32. package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
  33. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  34. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  35. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
  36. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  37. package/dist/esm/isomorphic/client.d.ts +139 -13
  38. package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
  39. package/dist/esm/isomorphic/utils/7702.js +14 -6
  40. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  41. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  42. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  43. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  44. package/dist/esm/local/client.js +2 -3
  45. package/dist/esm/local/client.js.map +1 -1
  46. package/dist/esm/remote/client.js +3 -7
  47. package/dist/esm/remote/client.js.map +1 -1
  48. package/dist/esm/rpc/examples.d.ts +3 -3
  49. package/dist/esm/rpc/examples.js +3 -3
  50. package/dist/esm/rpc/examples.js.map +1 -1
  51. package/dist/esm/rpc/request.d.ts +357 -49
  52. package/dist/esm/rpc/request.js +26 -53
  53. package/dist/esm/rpc/request.js.map +1 -1
  54. package/dist/esm/rpc/schema.d.ts +323 -57
  55. package/dist/esm/rpc/schema.js.map +1 -1
  56. package/dist/esm/schemas.d.ts +451 -13
  57. package/dist/esm/schemas.js +165 -52
  58. package/dist/esm/schemas.js.map +1 -1
  59. package/dist/esm/types.d.ts +3 -0
  60. package/dist/esm/types.js.map +1 -1
  61. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -1
  62. package/dist/types/capabilities/permissions/index.d.ts +1 -1
  63. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  64. package/dist/types/client/actions/grantPermissions.d.ts +5 -60
  65. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  66. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  67. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  68. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  69. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  70. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  71. package/dist/types/client/actions/signSignatureRequest.d.ts +8 -7
  72. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  73. package/dist/types/client/decorator.d.ts +3 -1
  74. package/dist/types/client/decorator.d.ts.map +1 -1
  75. package/dist/types/exports/index.d.ts +2 -1
  76. package/dist/types/exports/index.d.ts.map +1 -1
  77. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  78. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  79. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  80. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  81. package/dist/types/isomorphic/client.d.ts +139 -13
  82. package/dist/types/isomorphic/client.d.ts.map +1 -1
  83. package/dist/types/isomorphic/utils/7702.d.ts +4 -3
  84. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  85. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  86. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  87. package/dist/types/remote/client.d.ts.map +1 -1
  88. package/dist/types/rpc/examples.d.ts +3 -3
  89. package/dist/types/rpc/examples.d.ts.map +1 -1
  90. package/dist/types/rpc/request.d.ts +357 -49
  91. package/dist/types/rpc/request.d.ts.map +1 -1
  92. package/dist/types/rpc/schema.d.ts +323 -57
  93. package/dist/types/rpc/schema.d.ts.map +1 -1
  94. package/dist/types/schemas.d.ts +451 -13
  95. package/dist/types/schemas.d.ts.map +1 -1
  96. package/dist/types/types.d.ts +3 -0
  97. package/dist/types/types.d.ts.map +1 -1
  98. package/package.json +5 -5
  99. package/src/capabilities/eip7702Auth.ts +17 -10
  100. package/src/capabilities/overrides.ts +8 -8
  101. package/src/capabilities/permissions/index.ts +8 -3
  102. package/src/client/actions/grantPermissions.ts +5 -60
  103. package/src/client/actions/requestAccount.ts +10 -8
  104. package/src/client/actions/sendPreparedCalls.ts +17 -17
  105. package/src/client/actions/signPreparedCalls.ts +72 -0
  106. package/src/client/actions/signSignatureRequest.ts +50 -46
  107. package/src/client/client.e2e-test.ts +101 -33
  108. package/src/client/decorator.ts +14 -5
  109. package/src/exports/index.ts +2 -1
  110. package/src/isomorphic/actions/createSession.ts +20 -42
  111. package/src/isomorphic/actions/prepareCalls.ts +25 -17
  112. package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
  113. package/src/isomorphic/utils/7702.ts +18 -8
  114. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  115. package/src/local/client.ts +2 -6
  116. package/src/remote/client.ts +3 -10
  117. package/src/rpc/examples.ts +3 -4
  118. package/src/rpc/request.ts +41 -63
  119. package/src/rpc/schema.ts +2 -2
  120. package/src/schemas.ts +227 -53
  121. 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
- { title: "Multiplier" },
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({ title: "Absolute" }), Mutliplier]),
13
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
14
14
  ),
15
15
  verificationGasLimit: Type.Optional(
16
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
16
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
17
17
  ),
18
18
  callGasLimit: Type.Optional(
19
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
19
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
20
20
  ),
21
21
  paymasterVerificationGasLimit: Type.Optional(
22
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
22
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
23
23
  ),
24
24
  paymasterPostOpGasLimit: Type.Optional(
25
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
25
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
26
26
  ),
27
27
  maxFeePerGas: Type.Optional(
28
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
28
+ Type.Union([TypeHex({ description: "Absolute" }), Mutliplier]),
29
29
  ),
30
30
  maxPriorityFeePerGas: Type.Optional(
31
- Type.Union([TypeHex({ title: "Absolute" }), Mutliplier]),
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
- title: "Permissions context",
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
- title: "Remote permission",
142
+ description: "Remote permission",
143
143
  },
144
144
  );
145
145
 
146
146
  export const PermissionsData = Type.Object({
147
147
  chainId: TypeHex(),
148
- expiry: Type.Optional(Type.Integer()),
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.expiry - Unix timestamp when the permissions expire
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 preparedCall = await client.prepareCalls({
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 signature = await signSignatureRequest(
61
+ * const signedCalls = await client.signPreparedCalls(
66
62
  * sessionKey,
67
- * preparedCall.signatureRequest,
63
+ * preparedCalls,
68
64
  * );
69
65
  *
70
66
  * // Send the prepared call using the session key
71
67
  * const result = await client.sendPreparedCalls({
72
- * ...preparedCall,
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
  * },
@@ -57,6 +57,7 @@ export async function requestAccount(
57
57
  };
58
58
 
59
59
  const cachedAccount = client.internal.getAccount();
60
+
60
61
  if (
61
62
  cachedAccount &&
62
63
  ((args.accountAddress &&
@@ -66,17 +67,18 @@ export async function requestAccount(
66
67
  return cachedAccount.account;
67
68
  }
68
69
 
69
- const { counterfactualInfo, accountAddress } = await client.request({
70
- method: "wallet_requestAccount",
71
- params: [args],
72
- });
70
+ const { accountAddress, counterfactualInfo, delegation } =
71
+ await client.request({
72
+ method: "wallet_requestAccount",
73
+ params: [args],
74
+ });
73
75
 
74
76
  const account = await createAccount({
75
77
  accountAddress,
76
- counterfactualInfo: Value.Parse(
77
- TypeSerializedInitcode,
78
- counterfactualInfo!,
79
- ),
78
+ counterfactualInfo: counterfactualInfo
79
+ ? Value.Parse(TypeSerializedInitcode, counterfactualInfo)
80
+ : undefined,
81
+ delegation,
80
82
  chain: client.chain,
81
83
  transport: custom(client.transport),
82
84
  signer,
@@ -1,11 +1,12 @@
1
- import type { Static, StaticDecode } from "@sinclair/typebox";
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 = Omit<
7
- StaticDecode<typeof wallet_sendPreparedCalls>["Request"]["params"][0],
8
- "chainId"
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
- * // Sign the signature request using signSignatureRequest with your signer
44
- * const signedRequest = await client.signSignatureRequest(preparedCalls.signatureRequest);
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
- * ...preparedCalls,
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: [{ ...params, chainId: toHex(client.chain.id) }],
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,72 @@
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 { signatureRequest: _signatureRequest, ...rest } = call;
41
+ const signature = await signSignatureRequest(signer, {
42
+ type: "eip7702Auth",
43
+ data: {
44
+ ...call.data,
45
+ chainId: call.chainId,
46
+ },
47
+ });
48
+ return {
49
+ ...rest,
50
+ signature,
51
+ };
52
+ }
53
+ case "user-operation-v060":
54
+ case "user-operation-v070": {
55
+ const { signatureRequest, ...rest } = call;
56
+ const signature = await signSignatureRequest(
57
+ signer,
58
+ signatureRequest,
59
+ );
60
+ return {
61
+ ...rest,
62
+ signature,
63
+ };
64
+ }
65
+ default: {
66
+ return assertNever(call, "Unexpected call type");
67
+ }
68
+ }
69
+ }),
70
+ ),
71
+ };
72
+ }
@@ -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, toHex } from "viem";
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 type { Eip7702ExtendedFields } from "@aa-sdk/core";
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 = Static<typeof TypeSignatureRequest>;
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: Exclude<TypeSignatureType, "contract">; // TODO: Add support for identifying contract signatures
12
- signature: Hex;
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 eth_signTypedData_v4.
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
- const signature =
58
- params.type === "personal_sign"
59
- ? await signer.signMessage(params.data)
60
- : params.type === "eth_signTypedData_v4"
61
- ? await signer.signTypedData(params.data)
62
- : assertNever(params, "Unexpected signature request type");
63
-
64
- if (!params.authorizationRequest) {
65
- return {
66
- type: "secp256k1" as const,
67
- signature,
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
- if (!signer.signAuthorization) {
72
- throw new Error("Signer does not implement signAuthorization");
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
  }