@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.
Files changed (117) 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/sendPreparedCalls.d.ts +6 -14
  12. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  13. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  14. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  15. package/dist/esm/client/actions/signPreparedCalls.js +53 -0
  16. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  17. package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
  18. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  19. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  20. package/dist/esm/client/client.e2e-test.js +28 -25
  21. package/dist/esm/client/client.e2e-test.js.map +1 -1
  22. package/dist/esm/client/decorator.d.ts +3 -1
  23. package/dist/esm/client/decorator.js +3 -1
  24. package/dist/esm/client/decorator.js.map +1 -1
  25. package/dist/esm/exports/index.d.ts +2 -1
  26. package/dist/esm/exports/index.js +2 -1
  27. package/dist/esm/exports/index.js.map +1 -1
  28. package/dist/esm/isomorphic/actions/createSession.js +18 -32
  29. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  30. package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
  31. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  32. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  33. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
  34. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  35. package/dist/esm/isomorphic/client.d.ts +139 -13
  36. package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
  37. package/dist/esm/isomorphic/utils/7702.js +14 -6
  38. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  39. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  40. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  41. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  42. package/dist/esm/local/client.js +2 -3
  43. package/dist/esm/local/client.js.map +1 -1
  44. package/dist/esm/remote/client.js +3 -7
  45. package/dist/esm/remote/client.js.map +1 -1
  46. package/dist/esm/rpc/examples.d.ts +3 -3
  47. package/dist/esm/rpc/examples.js +3 -3
  48. package/dist/esm/rpc/examples.js.map +1 -1
  49. package/dist/esm/rpc/request.d.ts +357 -49
  50. package/dist/esm/rpc/request.js +26 -53
  51. package/dist/esm/rpc/request.js.map +1 -1
  52. package/dist/esm/rpc/schema.d.ts +323 -57
  53. package/dist/esm/rpc/schema.js.map +1 -1
  54. package/dist/esm/schemas.d.ts +451 -13
  55. package/dist/esm/schemas.js +165 -52
  56. package/dist/esm/schemas.js.map +1 -1
  57. package/dist/esm/types.d.ts +3 -0
  58. package/dist/esm/types.js.map +1 -1
  59. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -1
  60. package/dist/types/capabilities/permissions/index.d.ts +1 -1
  61. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  62. package/dist/types/client/actions/grantPermissions.d.ts +5 -60
  63. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  64. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  65. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  66. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  67. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  68. package/dist/types/client/actions/signSignatureRequest.d.ts +8 -7
  69. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  70. package/dist/types/client/decorator.d.ts +3 -1
  71. package/dist/types/client/decorator.d.ts.map +1 -1
  72. package/dist/types/exports/index.d.ts +2 -1
  73. package/dist/types/exports/index.d.ts.map +1 -1
  74. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  75. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  76. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  77. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  78. package/dist/types/isomorphic/client.d.ts +139 -13
  79. package/dist/types/isomorphic/client.d.ts.map +1 -1
  80. package/dist/types/isomorphic/utils/7702.d.ts +4 -3
  81. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  82. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  83. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  84. package/dist/types/remote/client.d.ts.map +1 -1
  85. package/dist/types/rpc/examples.d.ts +3 -3
  86. package/dist/types/rpc/examples.d.ts.map +1 -1
  87. package/dist/types/rpc/request.d.ts +357 -49
  88. package/dist/types/rpc/request.d.ts.map +1 -1
  89. package/dist/types/rpc/schema.d.ts +323 -57
  90. package/dist/types/rpc/schema.d.ts.map +1 -1
  91. package/dist/types/schemas.d.ts +451 -13
  92. package/dist/types/schemas.d.ts.map +1 -1
  93. package/dist/types/types.d.ts +3 -0
  94. package/dist/types/types.d.ts.map +1 -1
  95. package/package.json +2 -2
  96. package/src/capabilities/eip7702Auth.ts +17 -10
  97. package/src/capabilities/overrides.ts +8 -8
  98. package/src/capabilities/permissions/index.ts +8 -3
  99. package/src/client/actions/grantPermissions.ts +5 -60
  100. package/src/client/actions/sendPreparedCalls.ts +17 -17
  101. package/src/client/actions/signPreparedCalls.ts +71 -0
  102. package/src/client/actions/signSignatureRequest.ts +50 -46
  103. package/src/client/client.e2e-test.ts +32 -35
  104. package/src/client/decorator.ts +14 -5
  105. package/src/exports/index.ts +2 -1
  106. package/src/isomorphic/actions/createSession.ts +20 -42
  107. package/src/isomorphic/actions/prepareCalls.ts +25 -17
  108. package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
  109. package/src/isomorphic/utils/7702.ts +18 -8
  110. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  111. package/src/local/client.ts +2 -6
  112. package/src/remote/client.ts +3 -10
  113. package/src/rpc/examples.ts +3 -4
  114. package/src/rpc/request.ts +41 -63
  115. package/src/rpc/schema.ts +2 -2
  116. package/src/schemas.ts +227 -53
  117. package/src/types.ts +4 -0
@@ -24,12 +24,7 @@ import type { wallet_createSession } from "../../rpc/request.js";
24
24
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
25
25
  import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
26
26
  import { createDummySigner } from "../utils/createDummySigner.js";
27
- import { createAuthorization } from "../utils/7702.js";
28
27
  import { InvalidRequestError } from "ox/RpcResponse";
29
- import {
30
- parseDelegation,
31
- assertValid7702AccountAddress,
32
- } from "../utils/7702.js";
33
28
 
34
29
  export type CreateSessionParams = Omit<
35
30
  Static<
@@ -63,30 +58,26 @@ export async function createSession(
63
58
  throw new ChainNotFoundError();
64
59
  }
65
60
 
66
- assertValid7702AccountAddress(
67
- params.account,
68
- params.capabilities?.eip7702Auth,
69
- );
70
-
71
- const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth
72
- ? {
73
- counterfactualInfo: undefined,
74
- delegation: parseDelegation(params.capabilities.eip7702Auth),
75
- }
76
- : await client.request({
77
- method: "wallet_requestAccount",
78
- params: [
79
- {
80
- accountAddress: params.account,
81
- includeCounterfactualInfo: true,
82
- },
83
- ],
84
- });
61
+ const { counterfactualInfo, delegation } = await client.request({
62
+ method: "wallet_requestAccount",
63
+ params: [
64
+ {
65
+ accountAddress: params.account,
66
+ includeCounterfactualInfo: true,
67
+ },
68
+ ],
69
+ });
85
70
 
86
- if (!counterfactualInfo && !delegation) {
71
+ if (delegation) {
87
72
  throw new InvalidRequestError({
88
73
  message:
89
- "No counterfactual info or delegated implementation address found.",
74
+ "'wallet_createSession' does not currently support 7702 accounts.",
75
+ });
76
+ }
77
+
78
+ if (!counterfactualInfo) {
79
+ throw new InvalidRequestError({
80
+ message: "No counterfactual info found.",
90
81
  });
91
82
  }
92
83
 
@@ -126,7 +117,7 @@ export async function createSession(
126
117
  },
127
118
  entityId,
128
119
  nonce,
129
- deadline: params.expiry,
120
+ deadline: params.expirySec,
130
121
  })
131
122
  .addPermissions({
132
123
  permissions: params.permissions.map((permission) =>
@@ -135,25 +126,12 @@ export async function createSession(
135
126
  })
136
127
  .compileDeferred();
137
128
 
138
- // If using 7702, we need an Authorization (unless it's already authorized).
139
- const authorizationRequest = delegation
140
- ? await createAuthorization(client, {
141
- address: account.address,
142
- delegation,
143
- })
144
- : undefined;
145
-
146
- const signatureRequest = {
147
- type: "eth_signTypedData_v4" as const,
148
- data: typedData,
149
- };
150
-
151
129
  return {
152
130
  sessionId: null, // In remote mode, the server will set this later.
153
131
  entityId: toHex(entityId),
154
132
  signatureRequest: {
155
- ...signatureRequest,
156
- ...(authorizationRequest ? { authorizationRequest } : {}),
133
+ type: "eth_signTypedData_v4" as const,
134
+ data: typedData,
157
135
  },
158
136
  fullPreSignatureDeferredActionDigest,
159
137
  };
@@ -17,8 +17,9 @@ import type { wallet_prepareCalls } from "../../rpc/request.js";
17
17
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
18
18
  import { createAccount } from "../utils/createAccount.js";
19
19
  import { createDummySigner } from "../utils/createDummySigner.js";
20
- import { createAuthorization, parseDelegation } from "../utils/7702.js";
20
+ import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
21
21
  import { InvalidRequestError } from "ox/RpcResponse";
22
+ import { assertNever } from "../../utils.js";
22
23
  import { assertValid7702AccountAddress } from "../utils/7702.js";
23
24
 
24
25
  export type PrepareCallsParams = Omit<
@@ -83,7 +84,7 @@ export async function prepareCalls(
83
84
 
84
85
  // If using 7702, we need an Authorization (unless it's already authorized).
85
86
  const authorizationRequest = delegation
86
- ? await createAuthorization(client, {
87
+ ? await createAuthorizationRequest(client, {
87
88
  address: account.address,
88
89
  delegation,
89
90
  })
@@ -107,29 +108,36 @@ export async function prepareCalls(
107
108
  });
108
109
 
109
110
  // The eip7702Auth field should never be included in the UO sig
110
- // request. It's handled by the separate authorization request.
111
+ // request. It's handled by a separate authorization request.
111
112
  if ("eip7702Auth" in builtUo) {
112
113
  builtUo.eip7702Auth = undefined;
113
114
  }
114
- const uoRequest = deepHexlify(builtUo);
115
115
 
116
- const signatureRequest = {
117
- type: "personal_sign" as const,
118
- data: {
119
- raw: account.getEntryPoint().getUserOperationHash(uoRequest),
120
- },
121
- };
116
+ const hexlifiedUo = deepHexlify(builtUo);
117
+
118
+ const ep = account.getEntryPoint();
122
119
 
123
- return {
120
+ const uoRequest = {
124
121
  type:
125
- account.getEntryPoint().version === "0.7.0"
126
- ? "user-operation-v070"
127
- : "user-operation-v060",
128
- data: uoRequest,
122
+ ep.version === "0.7.0"
123
+ ? ("user-operation-v070" as const)
124
+ : ep.version === "0.6.0"
125
+ ? ("user-operation-v060" as const)
126
+ : assertNever(ep.version, "Unexpected entry point version"),
127
+ data: hexlifiedUo,
129
128
  chainId: toHex(client.chain.id),
130
129
  signatureRequest: {
131
- ...signatureRequest,
132
- ...(authorizationRequest ? { authorizationRequest } : {}),
130
+ type: "personal_sign" as const,
131
+ data: {
132
+ raw: ep.getUserOperationHash(hexlifiedUo),
133
+ },
133
134
  },
134
135
  };
136
+
137
+ return authorizationRequest
138
+ ? {
139
+ type: "array" as const,
140
+ data: [authorizationRequest, uoRequest],
141
+ }
142
+ : uoRequest;
135
143
  }
@@ -3,31 +3,33 @@ import {
3
3
  type SmartAccountClient,
4
4
  type SmartContractAccount,
5
5
  } from "@aa-sdk/core";
6
- import type { Static, StaticDecode } from "@sinclair/typebox";
7
6
  import { Value } from "@sinclair/typebox/value";
8
7
  import {
9
8
  BaseError,
10
9
  ChainNotFoundError,
11
10
  concat,
12
11
  concatHex,
12
+ numberToHex,
13
+ parseSignature,
13
14
  toHex,
15
+ type Address,
14
16
  type Chain,
15
17
  type Hex,
16
18
  type Transport,
17
19
  } from "viem";
18
20
  import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
19
- import type { wallet_sendPreparedCalls } from "../../rpc/request.js";
21
+ import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
20
22
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
21
23
  import { TypeCallId } from "../../schemas.js";
22
24
  import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
23
25
  import { InvalidRequestError } from "ox/RpcResponse";
26
+ import { assertNever } from "../../utils.js";
27
+ import type { Static } from "@sinclair/typebox";
28
+ import { decodeSignature } from "../utils/decodeSignature.js";
24
29
 
25
- export type SendPreparedCallsParams = Omit<
26
- StaticDecode<
27
- (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
28
- >[0],
29
- "chainId"
30
- >;
30
+ export type SendPreparedCallsParams = Static<
31
+ (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
32
+ >[0];
31
33
 
32
34
  export type SendPreparedCallsResult = Static<
33
35
  (typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
@@ -48,16 +50,6 @@ export async function sendPreparedCalls(
48
50
  throw new ChainNotFoundError();
49
51
  }
50
52
 
51
- // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
52
- if (
53
- params.signedAuthorization &&
54
- !isSupportedDelegationAddress7702(params.signedAuthorization.address)
55
- ) {
56
- throw new InvalidRequestError({
57
- message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
58
- });
59
- }
60
-
61
53
  const deferredAction: Hex | undefined = (() => {
62
54
  if (!params.capabilities?.permissions) {
63
55
  return;
@@ -77,46 +69,104 @@ export async function sendPreparedCalls(
77
69
  return decodedContext.deferredAction;
78
70
  })();
79
71
 
80
- const entryPoint =
81
- params.type === "user-operation-v060"
82
- ? getEntryPoint(client.chain, { version: "0.6.0" })
83
- : getEntryPoint(client.chain, { version: "0.7.0" });
72
+ const userOps =
73
+ params.type === "array"
74
+ ? params.data.filter((it) => {
75
+ const isUserOp =
76
+ it.type === "user-operation-v060" ||
77
+ it.type === "user-operation-v070";
78
+ if (isUserOp && it.chainId !== toHex(client.chain.id)) {
79
+ throw new InvalidRequestError({
80
+ message:
81
+ "Multiple chain IDs in a single request are not currently supported.",
82
+ });
83
+ }
84
+ return isUserOp;
85
+ })
86
+ : [params];
87
+
88
+ const authorizations =
89
+ params.type === "array"
90
+ ? params.data.filter((it) => it.type === "authorization")
91
+ : [];
84
92
 
85
- const hash = await client
86
- .sendRawUserOperation(
87
- {
88
- ...params.data,
89
- signature:
90
- deferredAction != null
91
- ? concatHex([
92
- `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).
93
- "0xff",
94
- "0x00",
95
- params.signature.signature,
96
- ])
97
- : concat(["0xFF", "0x00", params.signature.signature]),
98
- eip7702Auth: params.signedAuthorization,
99
- },
100
- entryPoint.address,
101
- )
102
- .catch((err) => {
103
- if (
104
- err instanceof BaseError &&
105
- err.details.endsWith("is not a contract and initCode is empty")
106
- ) {
107
- throw new BaseError(
108
- `${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`,
109
- );
110
- }
111
- throw err;
93
+ if (authorizations.length > 1) {
94
+ throw new InvalidRequestError({
95
+ message:
96
+ "Multiple authorizations in a single request are not currently supported",
112
97
  });
98
+ }
99
+ const [authorization] = authorizations;
100
+
101
+ // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
102
+ if (
103
+ authorization &&
104
+ !isSupportedDelegationAddress7702(authorization.data.address)
105
+ ) {
106
+ throw new InvalidRequestError({
107
+ message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
108
+ });
109
+ }
113
110
 
114
- const callId = Value.Encode(TypeCallId, {
115
- chainId: toHex(client.chain.id),
116
- hash,
117
- });
111
+ const hashes = await Promise.all(
112
+ userOps.map(async (userOp, idx) => {
113
+ const ep: { address: Address } =
114
+ userOp.type === "user-operation-v060"
115
+ ? getEntryPoint(client.chain, { version: "0.6.0" })
116
+ : userOp.type === "user-operation-v070"
117
+ ? getEntryPoint(client.chain, { version: "0.7.0" })
118
+ : assertNever(userOp, "Unexpected user op type");
119
+ const authSig = authorization
120
+ ? parseSignature(decodeSignature(authorization.signature).data)
121
+ : undefined;
122
+ const uoSigHex = decodeSignature(userOp.signature).data;
123
+ return client
124
+ .sendRawUserOperation(
125
+ {
126
+ ...userOp.data,
127
+ signature:
128
+ deferredAction != null
129
+ ? concatHex([
130
+ `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).
131
+ "0xff",
132
+ "0x00",
133
+ uoSigHex,
134
+ ])
135
+ : concat(["0xFF", "0x00", uoSigHex]),
136
+ eip7702Auth:
137
+ idx === 0 && authorization && authSig
138
+ ? {
139
+ ...authorization.data,
140
+ chainId: authorization.chainId,
141
+ ...{
142
+ ...authSig,
143
+ yParity: numberToHex(authSig.yParity),
144
+ },
145
+ }
146
+ : undefined,
147
+ },
148
+ ep.address,
149
+ )
150
+ .catch((err) => {
151
+ if (
152
+ err instanceof BaseError &&
153
+ err.details.endsWith("is not a contract and initCode is empty")
154
+ ) {
155
+ throw new BaseError(
156
+ `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
157
+ );
158
+ }
159
+ throw err;
160
+ });
161
+ }),
162
+ );
118
163
 
119
164
  return {
120
- preparedCallIds: [callId],
165
+ preparedCallIds: hashes.map((hash) =>
166
+ Value.Encode(TypeCallId, {
167
+ chainId: toHex(client.chain.id),
168
+ hash,
169
+ }),
170
+ ),
121
171
  };
122
172
  }
@@ -1,18 +1,19 @@
1
1
  import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
2
  import {
3
3
  concatHex,
4
- type Authorization,
4
+ numberToHex,
5
5
  type Address,
6
6
  type Chain,
7
7
  type Transport,
8
8
  isAddress,
9
9
  } from "viem";
10
10
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
11
+ import { PreparedCall_Authorization } from "../../schemas.js";
11
12
  import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
12
13
  import type { Static } from "@sinclair/typebox";
13
14
  import { InvalidRequestError } from "ox/RpcResponse";
14
15
 
15
- export const createAuthorization = async (
16
+ export const createAuthorizationRequest = async (
16
17
  client: SmartAccountClient<
17
18
  Transport,
18
19
  Chain,
@@ -21,18 +22,27 @@ export const createAuthorization = async (
21
22
  WalletServerViemRpcSchema
22
23
  >,
23
24
  params: { address: Address; delegation: Address },
24
- ): Promise<Authorization<number, false> | undefined> => {
25
+ ): Promise<Static<typeof PreparedCall_Authorization> | undefined> => {
25
26
  const expectedCode = concatHex(["0xef0100", params.delegation]);
26
27
  const code = (await client.getCode({ address: params.address })) ?? "0x";
27
28
  if (code.toLowerCase() === expectedCode.toLowerCase()) {
28
29
  return undefined; // Already authorized.
29
30
  }
30
- return {
31
- chainId: client.chain.id,
31
+ const data = {
32
32
  address: params.delegation,
33
- nonce: await client.getTransactionCount({
34
- address: params.address,
35
- }),
33
+ nonce: numberToHex(
34
+ await client.getTransactionCount({
35
+ address: params.address,
36
+ }),
37
+ ),
38
+ };
39
+ return {
40
+ type: "authorization" as const,
41
+ data,
42
+ chainId: numberToHex(client.chain.id),
43
+ signatureRequest: {
44
+ type: "eip7702Auth" as const,
45
+ },
36
46
  };
37
47
  };
38
48
 
@@ -0,0 +1,18 @@
1
+ import { Value } from "@sinclair/typebox/value";
2
+ import type { Static, StaticDecode } from "@sinclair/typebox";
3
+ import { TypeEcdsaSig } from "../../schemas.js";
4
+ import { assertNever } from "../../utils.js";
5
+
6
+ export const decodeSignature = (
7
+ signature: Static<typeof TypeEcdsaSig>["signature"],
8
+ ): StaticDecode<typeof TypeEcdsaSig>["signature"] => {
9
+ switch (signature.type) {
10
+ case "ecdsa":
11
+ case "secp256k1":
12
+ return Value.Decode(TypeEcdsaSig, { signature } satisfies Static<
13
+ typeof TypeEcdsaSig
14
+ >).signature;
15
+ default:
16
+ return assertNever(signature, "Unexpected signature type");
17
+ }
18
+ };
@@ -121,19 +121,15 @@ const innerClientActions = (
121
121
  grantPermissions: async (signer, params) => {
122
122
  const { signatureRequest, fullPreSignatureDeferredActionDigest } =
123
123
  await isomorphicClient.createSession(params);
124
- const { signedAuthorization, signature } = await signSignatureRequest(
125
- signer,
126
- signatureRequest,
127
- );
124
+ const signature = await signSignatureRequest(signer, signatureRequest);
128
125
  return {
129
126
  context: encodePermissionsContext({
130
127
  contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
131
128
  deferredAction: buildDeferredActionDigest({
132
129
  fullPreSignatureDeferredActionDigest,
133
- sig: prefixSignatureKeyType(signature, "secp256k1"),
130
+ sig: prefixSignatureKeyType(signature.data, signature.type),
134
131
  }),
135
132
  }),
136
- signedAuthorization,
137
133
  };
138
134
  },
139
135
  };
@@ -1,5 +1,5 @@
1
1
  import { Provider } from "ox";
2
- import { BaseError, createClient, custom, type Address } from "viem";
2
+ import { createClient, custom, type Address } from "viem";
3
3
  import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
4
4
  import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
5
5
  import { internalStateDecorator } from "../internal/decorator.js";
@@ -54,20 +54,13 @@ const innerClientActions = (
54
54
  method: "wallet_createSession",
55
55
  params: [params],
56
56
  });
57
- if (signatureRequest.type !== "eth_signTypedData_v4") {
58
- throw new BaseError("Unexpected signature request type");
59
- }
60
- const { signedAuthorization, signature } = await signSignatureRequest(
61
- signer,
62
- signatureRequest,
63
- );
57
+ const signature = await signSignatureRequest(signer, signatureRequest);
64
58
  return {
65
59
  context: encodePermissionsContext({
66
60
  contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
67
61
  sessionId,
68
- signature,
62
+ signature: signature.data,
69
63
  }),
70
- signedAuthorization,
71
64
  };
72
65
  },
73
66
  };
@@ -82,9 +82,8 @@ const SendPreparedCalls = [
82
82
  },
83
83
  chainId: "0x66eee",
84
84
  signature: {
85
- type: "ecdsa",
86
- signature:
87
- "0xb1a055089b1ba8387ed435f2bd0afe7ff69f22b928cdfdea1b5323c64d6af387164de3fa6febf031b544de46a84d6fb7f084b9798ddfaba820950c257139a7321b",
85
+ type: "secp256k1",
86
+ data: "0xb1a055089b1ba8387ed435f2bd0afe7ff69f22b928cdfdea1b5323c64d6af387164de3fa6febf031b544de46a84d6fb7f084b9798ddfaba820950c257139a7321b",
88
87
  },
89
88
  },
90
89
  ],
@@ -200,7 +199,7 @@ const CreateSession = [
200
199
  type: "root",
201
200
  },
202
201
  ],
203
- expiry: 1747969653,
202
+ expirySec: 1747969653,
204
203
  },
205
204
  ],
206
205
  },
@@ -6,57 +6,43 @@ import {
6
6
  RemotePermission,
7
7
  } from "../capabilities/permissions/index.js";
8
8
  import {
9
+ TypeCallArray,
10
+ TypePrepareCall_UserOpV060_Signed,
11
+ TypePrepareCall_UserOpV070_Signed,
12
+ PreparedCall_Authorization,
13
+ PreparedCall_UserOpV060,
14
+ PreparedCall_UserOpV070,
9
15
  TypeAddress,
10
16
  TypeBase64UrlEncodedString,
11
17
  TypeCreationOptions,
12
- TypeEip7702AuthExtendedFields,
13
18
  TypeHex,
14
19
  TypeSerializedInitcode,
15
- TypeSignatureRequest,
16
- TypeUserOperationRequest_v6,
17
- TypeUserOperationRequest_v7,
20
+ TypeTypedDataSignatureRequest,
18
21
  TypeUuid,
19
- TypeSignatureType,
20
22
  } from "../schemas.js";
21
23
  import { Examples } from "./examples.js";
22
- import { Eip7702AuthCapability } from "../capabilities/eip7702Auth.js";
23
24
 
24
25
  export const wallet_sendPreparedCalls = Type.Object(
25
26
  {
26
27
  Request: Type.Object({
27
28
  method: Type.Literal("wallet_sendPreparedCalls"),
28
29
  params: Type.Tuple([
29
- Type.Object({
30
- type: Type.Union([
31
- Type.Literal("user-operation-v060", {
32
- title: "User Operation (Entrypoint v0.6.0)",
33
- }),
34
- Type.Literal("user-operation-v070", {
35
- title: "User Operation (Entrypoint v0.7.0)",
36
- }),
37
- ]),
38
- data: Type.Union([
39
- Type.Omit(TypeUserOperationRequest_v6, ["signature"], {
40
- title: "Unsigned User Operation (Entrypoint v0.6.0)",
41
- }),
42
- Type.Omit(TypeUserOperationRequest_v7, ["signature"], {
43
- title: "Unsigned User Operation (Entrypoint v0.7.0)",
44
- }),
30
+ Type.Intersect([
31
+ Type.Union([
32
+ TypeCallArray,
33
+ TypePrepareCall_UserOpV060_Signed,
34
+ TypePrepareCall_UserOpV070_Signed,
45
35
  ]),
46
- chainId: TypeHex(),
47
- signature: Type.Object({
48
- type: Type.Exclude(TypeSignatureType, Type.Literal("contract")),
49
- signature: TypeHex(),
36
+ Type.Object({
37
+ capabilities: Type.Optional(
38
+ Type.Object({
39
+ permissions: Type.Optional(
40
+ Type.Union([PermissionsContext, RemotePermission]),
41
+ ),
42
+ }),
43
+ ),
50
44
  }),
51
- signedAuthorization: Type.Optional(TypeEip7702AuthExtendedFields),
52
- capabilities: Type.Optional(
53
- Type.Object({
54
- permissions: Type.Optional(
55
- Type.Union([PermissionsContext, RemotePermission]),
56
- ),
57
- }),
58
- ),
59
- }),
45
+ ]),
60
46
  ]),
61
47
  }),
62
48
  ReturnType: Type.Object({
@@ -89,26 +75,23 @@ export const wallet_prepareCalls = Type.Object(
89
75
  }),
90
76
  ]),
91
77
  }),
92
- ReturnType: Type.Object({
93
- type: Type.Union([
94
- Type.Literal("user-operation-v060", {
95
- title: "User Operation (Entrypoint v0.6.0)",
96
- }),
97
- Type.Literal("user-operation-v070", {
98
- title: "User Operation (Entrypoint v0.7.0)",
99
- }),
100
- ]),
101
- data: Type.Union([
102
- Type.Omit(TypeUserOperationRequest_v6, ["signature"], {
103
- title: "Unsigned User Operation (Entrypoint v0.6.0)",
104
- }),
105
- Type.Omit(TypeUserOperationRequest_v7, ["signature"], {
106
- title: "Unsigned User Operation (Entrypoint v0.7.0)",
107
- }),
108
- ]),
109
- chainId: TypeHex(),
110
- signatureRequest: TypeSignatureRequest,
111
- }),
78
+ ReturnType: Type.Union([
79
+ Type.Object(
80
+ {
81
+ type: Type.Literal("array"),
82
+ data: Type.Array(
83
+ Type.Union([
84
+ PreparedCall_UserOpV060,
85
+ PreparedCall_UserOpV070,
86
+ PreparedCall_Authorization,
87
+ ]),
88
+ ),
89
+ },
90
+ { description: "Array of prepared calls" },
91
+ ),
92
+ PreparedCall_UserOpV060,
93
+ PreparedCall_UserOpV070,
94
+ ]),
112
95
  },
113
96
  {
114
97
  description:
@@ -133,7 +116,7 @@ export const wallet_requestAccount = Type.Object(
133
116
  ),
134
117
  },
135
118
  {
136
- title: "Using signer address",
119
+ description: "Using signer address",
137
120
  },
138
121
  ),
139
122
  Type.Object(
@@ -144,7 +127,7 @@ export const wallet_requestAccount = Type.Object(
144
127
  ),
145
128
  },
146
129
  {
147
- title: "Using smart contract account address",
130
+ description: "Using smart contract account address",
148
131
  },
149
132
  ),
150
133
  ]),
@@ -229,18 +212,13 @@ export const wallet_createSession = Type.Object(
229
212
  PermissionsData,
230
213
  Type.Object({
231
214
  account: TypeAddress,
232
- capabilities: Type.Optional(
233
- Type.Object({
234
- eip7702Auth: Type.Optional(Eip7702AuthCapability),
235
- }),
236
- ),
237
215
  }),
238
216
  ]),
239
217
  ]),
240
218
  }),
241
219
  ReturnType: Type.Object({
242
220
  sessionId: TypeHex(),
243
- signatureRequest: TypeSignatureRequest,
221
+ signatureRequest: TypeTypedDataSignatureRequest,
244
222
  }),
245
223
  },
246
224
  {