@account-kit/wallet-client 0.1.0-alpha.11 → 0.1.0-alpha.12

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 (141) hide show
  1. package/dist/esm/client/actions/getCallsStatus.d.ts +4 -3
  2. package/dist/esm/client/actions/getCallsStatus.js +1 -0
  3. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  4. package/dist/esm/client/actions/grantPermissions.d.ts +5 -4
  5. package/dist/esm/client/actions/grantPermissions.js +21 -5
  6. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  7. package/dist/esm/client/actions/prepareCalls.d.ts +4 -3
  8. package/dist/esm/client/actions/prepareCalls.js +1 -0
  9. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  10. package/dist/esm/client/actions/prepareSign.d.ts +4 -3
  11. package/dist/esm/client/actions/prepareSign.js +1 -0
  12. package/dist/esm/client/actions/prepareSign.js.map +1 -1
  13. package/dist/esm/client/actions/requestAccount.js +1 -1
  14. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  15. package/dist/esm/client/client.e2e-test.js +171 -349
  16. package/dist/esm/client/client.e2e-test.js.map +1 -1
  17. package/dist/esm/client/index.d.ts +1 -4
  18. package/dist/esm/client/index.js +13 -18
  19. package/dist/esm/client/index.js.map +1 -1
  20. package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +1 -5
  21. package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +8 -32
  22. package/dist/esm/internal/account.js.map +1 -0
  23. package/dist/esm/types.d.ts +2 -8
  24. package/dist/esm/types.js.map +1 -1
  25. package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
  26. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  27. package/dist/types/client/actions/grantPermissions.d.ts +5 -4
  28. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  29. package/dist/types/client/actions/prepareCalls.d.ts +4 -3
  30. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  31. package/dist/types/client/actions/prepareSign.d.ts +4 -3
  32. package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
  33. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  34. package/dist/types/client/index.d.ts +1 -4
  35. package/dist/types/client/index.d.ts.map +1 -1
  36. package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +2 -6
  37. package/dist/types/internal/account.d.ts.map +1 -0
  38. package/dist/types/types.d.ts +2 -8
  39. package/dist/types/types.d.ts.map +1 -1
  40. package/package.json +3 -8
  41. package/src/client/actions/getCallsStatus.ts +8 -6
  42. package/src/client/actions/grantPermissions.ts +41 -10
  43. package/src/client/actions/prepareCalls.ts +11 -6
  44. package/src/client/actions/prepareSign.ts +9 -6
  45. package/src/client/actions/requestAccount.ts +1 -1
  46. package/src/client/client.e2e-test.ts +208 -442
  47. package/src/client/index.ts +22 -23
  48. package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +9 -49
  49. package/src/types.ts +4 -15
  50. package/dist/esm/exports/internal.d.ts +0 -4
  51. package/dist/esm/exports/internal.js +0 -3
  52. package/dist/esm/exports/internal.js.map +0 -1
  53. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
  54. package/dist/esm/isomorphic/actions/createSession.js +0 -94
  55. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  56. package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
  57. package/dist/esm/isomorphic/actions/formatSign.js +0 -42
  58. package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
  59. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
  60. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
  61. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  62. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
  63. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
  64. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  65. package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
  66. package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
  67. package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
  68. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
  69. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -183
  70. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  71. package/dist/esm/isomorphic/client.d.ts +0 -275
  72. package/dist/esm/isomorphic/client.js +0 -41
  73. package/dist/esm/isomorphic/client.js.map +0 -1
  74. package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
  75. package/dist/esm/isomorphic/utils/7702.js +0 -70
  76. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  77. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  78. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  79. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  80. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  81. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  82. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -15
  83. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  84. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  85. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  86. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  87. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  88. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  89. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  90. package/dist/esm/local/client.d.ts +0 -3
  91. package/dist/esm/local/client.js +0 -97
  92. package/dist/esm/local/client.js.map +0 -1
  93. package/dist/esm/remote/client.d.ts +0 -9
  94. package/dist/esm/remote/client.js +0 -41
  95. package/dist/esm/remote/client.js.map +0 -1
  96. package/dist/types/exports/internal.d.ts +0 -5
  97. package/dist/types/exports/internal.d.ts.map +0 -1
  98. package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
  99. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  100. package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
  101. package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
  102. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
  103. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  104. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
  105. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  106. package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
  107. package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
  108. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  109. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  110. package/dist/types/isomorphic/client.d.ts +0 -276
  111. package/dist/types/isomorphic/client.d.ts.map +0 -1
  112. package/dist/types/isomorphic/utils/7702.d.ts +0 -20
  113. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  114. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  115. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  116. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  117. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  118. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  119. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  120. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  121. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  122. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  123. package/dist/types/local/client.d.ts +0 -4
  124. package/dist/types/local/client.d.ts.map +0 -1
  125. package/dist/types/remote/client.d.ts +0 -10
  126. package/dist/types/remote/client.d.ts.map +0 -1
  127. package/src/exports/internal.ts +0 -8
  128. package/src/isomorphic/actions/createSession.ts +0 -163
  129. package/src/isomorphic/actions/formatSign.ts +0 -76
  130. package/src/isomorphic/actions/getCallsStatus.ts +0 -112
  131. package/src/isomorphic/actions/prepareCalls.ts +0 -172
  132. package/src/isomorphic/actions/prepareSign.ts +0 -88
  133. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -271
  134. package/src/isomorphic/client.ts +0 -102
  135. package/src/isomorphic/utils/7702.ts +0 -135
  136. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  137. package/src/isomorphic/utils/decodeSignature.ts +0 -21
  138. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
  139. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  140. package/src/local/client.ts +0 -136
  141. package/src/remote/client.ts +0 -67
@@ -1,271 +0,0 @@
1
- import {
2
- getEntryPoint,
3
- type SmartAccountClient,
4
- type SmartContractAccount,
5
- } from "@aa-sdk/core";
6
- import { Value } from "@sinclair/typebox/value";
7
- import {
8
- BaseError,
9
- ChainNotFoundError,
10
- concat,
11
- concatHex,
12
- getContract,
13
- numberToHex,
14
- parseSignature,
15
- toHex,
16
- type Address,
17
- type Chain,
18
- type Hex,
19
- type Transport,
20
- } from "viem";
21
- import type {
22
- wallet_sendPreparedCalls,
23
- WalletServerViemRpcSchema,
24
- } from "@alchemy/wallet-api-types/rpc";
25
- import { decodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
26
- import { CallId } from "@alchemy/wallet-api-types";
27
- import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
28
- import { InvalidRequestError } from "ox/RpcResponse";
29
- import { assertNever } from "../../utils.js";
30
- import type { Static } from "@sinclair/typebox";
31
- import { decodeSignature } from "../utils/decodeSignature.js";
32
-
33
- export type SendPreparedCallsParams = Static<
34
- (typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]
35
- >[0];
36
-
37
- export type SendPreparedCallsResult = Static<
38
- (typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]
39
- >;
40
-
41
- // TODO: this only supports MAv2 right now, we need to fix this
42
- export async function sendPreparedCalls(
43
- client: SmartAccountClient<
44
- Transport,
45
- Chain,
46
- SmartContractAccount | undefined,
47
- Record<string, unknown>,
48
- WalletServerViemRpcSchema
49
- >,
50
- params: SendPreparedCallsParams,
51
- ): Promise<SendPreparedCallsResult> {
52
- if (!client.chain) {
53
- throw new ChainNotFoundError();
54
- }
55
-
56
- const deferredAction: Hex | undefined = (() => {
57
- if (!params.capabilities?.permissions) {
58
- return;
59
- }
60
-
61
- const decodedContext = decodePermissionsContext(
62
- params.capabilities.permissions,
63
- );
64
-
65
- if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
66
- throw new InvalidRequestError({
67
- message:
68
- "Remote mode deferred action not supported in isomorphic client",
69
- });
70
- }
71
-
72
- return decodedContext.deferredAction;
73
- })();
74
-
75
- const userOps =
76
- params.type === "array"
77
- ? params.data.filter((it) => {
78
- const isUserOp =
79
- it.type === "user-operation-v060" ||
80
- it.type === "user-operation-v070";
81
- if (isUserOp && it.chainId !== toHex(client.chain.id)) {
82
- throw new InvalidRequestError({
83
- message:
84
- "Multiple chain IDs in a single request are not currently supported.",
85
- });
86
- }
87
- return isUserOp;
88
- })
89
- : [params];
90
-
91
- if (!userOps.length) {
92
- throw new InvalidRequestError({
93
- message: "Calls must include at least one user operation",
94
- });
95
- }
96
-
97
- const authorizations =
98
- params.type === "array"
99
- ? params.data.filter((it) => it.type === "authorization")
100
- : [];
101
-
102
- if (authorizations.length > 1) {
103
- throw new InvalidRequestError({
104
- message:
105
- "Multiple authorizations in a single request are not currently supported",
106
- });
107
- }
108
- const [authorization] = authorizations;
109
-
110
- // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
111
- if (
112
- authorization &&
113
- !isSupportedDelegationAddress7702(authorization.data.address)
114
- ) {
115
- throw new InvalidRequestError({
116
- message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
117
- });
118
- }
119
-
120
- const hashes = await Promise.all(
121
- userOps.map(async (userOp, idx) => {
122
- const ep: { address: Address } =
123
- userOp.type === "user-operation-v060"
124
- ? getEntryPoint(client.chain, { version: "0.6.0" })
125
- : userOp.type === "user-operation-v070"
126
- ? getEntryPoint(client.chain, { version: "0.7.0" })
127
- : assertNever(userOp, "Unexpected user op type");
128
- const authSig = authorization
129
- ? parseSignature(decodeSignature(authorization.signature).data)
130
- : undefined;
131
- const uoSigHex = decodeSignature(userOp.signature).data;
132
-
133
- const { counterfactualInfo, delegation } = await client.request({
134
- method: "wallet_requestAccount",
135
- params: [
136
- {
137
- accountAddress: userOp.data.sender,
138
- includeCounterfactualInfo: true,
139
- },
140
- ],
141
- });
142
-
143
- if (!counterfactualInfo && !delegation) {
144
- throw new InvalidRequestError({
145
- message:
146
- "No counterfactual info or delegated implementation address found.",
147
- });
148
- }
149
-
150
- const deferredActionData: Hex | undefined = deferredAction
151
- ? await (async () => {
152
- // determine whether the data should be appended to the signature.
153
- // logic ported from @account-kit/smart-contracts `modularAccountV2Base.ts`
154
-
155
- const deferredActionNonce = BigInt(
156
- `0x${deferredAction.slice(4, 68)}`,
157
- );
158
-
159
- const entryPoint = getEntryPoint(client.chain, {
160
- version: "0.7.0",
161
- });
162
-
163
- const entryPointContract = getContract({
164
- address: entryPoint.address,
165
- abi: entryPoint.abi,
166
- client,
167
- });
168
-
169
- // Set these values if the deferred action has not been consumed. We check this with the EP
170
- const nextNonceForDeferredAction: bigint =
171
- (await entryPointContract.read.getNonce([
172
- userOp.data.sender,
173
- deferredActionNonce >> 64n,
174
- ])) as bigint;
175
-
176
- if (deferredActionNonce === nextNonceForDeferredAction) {
177
- return `0x${deferredAction.slice(68)}`;
178
- } else if (deferredActionNonce > nextNonceForDeferredAction) {
179
- // if nonce is greater than the next nonce, its invalid, so we throw
180
- throw new InvalidRequestError({
181
- message: "Invalid session nonce",
182
- });
183
- }
184
-
185
- // In this case, the deferred action has already been consumed, so no data should be appended to the signature.
186
- // The signer entity should already be accounted for in `userOp.nonce`.
187
- return undefined;
188
- })()
189
- : undefined;
190
-
191
- const factoryType = counterfactualInfo?.factoryType;
192
-
193
- // build signature based on account type
194
- const signature = (() => {
195
- switch (factoryType) {
196
- // light accounts
197
- case "LightAccountV1.0.1":
198
- case "LightAccountV1.0.2":
199
- case "LightAccountV1.1.0":
200
- case "MAv1.0.0-MultiOwner":
201
- // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
202
- return uoSigHex;
203
- case "LightAccountV2.0.0":
204
- // for LAv2, we need to prepend the "SignatureType.EOA" byte.
205
- // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
206
- return concat(["0x00", uoSigHex]);
207
- case undefined: // undefined defaults to sma-b
208
- case "MAv2.0.0-sma-b":
209
- // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
210
- // Signature Segment" and "SignatureType.EOA" bytes
211
- return deferredActionData != null
212
- ? concatHex([deferredActionData, "0xFF", "0x00", uoSigHex])
213
- : concat(["0xFF", "0x00", uoSigHex]);
214
- case "LightAccountV2.0.0-MultiOwner":
215
- // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
216
- // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
217
- return concat(["0x00", uoSigHex]);
218
- case "MAv2.0.0-ma-ssv":
219
- case "MAv2.0.0-ma-webauthn":
220
- case "MAv1.0.0-MultiSig":
221
- case "unknown":
222
- throw new InvalidRequestError({
223
- message: `Unsupported factory type: ${factoryType}`,
224
- });
225
- default:
226
- return assertNever(factoryType, "Unsupported factory type");
227
- }
228
- })();
229
-
230
- return client
231
- .sendRawUserOperation(
232
- {
233
- ...userOp.data,
234
- signature,
235
- eip7702Auth:
236
- idx === 0 && authorization && authSig
237
- ? {
238
- ...authorization.data,
239
- chainId: authorization.chainId,
240
- ...{
241
- ...authSig,
242
- yParity: numberToHex(authSig.yParity),
243
- },
244
- }
245
- : undefined,
246
- },
247
- ep.address,
248
- )
249
- .catch((err) => {
250
- if (
251
- err instanceof BaseError &&
252
- err.details.endsWith("is not a contract and initCode is empty")
253
- ) {
254
- throw new BaseError(
255
- `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,
256
- );
257
- }
258
- throw err;
259
- });
260
- }),
261
- );
262
-
263
- return {
264
- preparedCallIds: hashes.map((hash) =>
265
- Value.Encode(CallId, {
266
- chainId: toHex(client.chain.id),
267
- hash,
268
- }),
269
- ),
270
- };
271
- }
@@ -1,102 +0,0 @@
1
- import {
2
- createSmartAccountClient,
3
- type ClientMiddlewareFn,
4
- type SmartAccountClient,
5
- type SmartAccountClientRpcSchema,
6
- type SmartContractAccount,
7
- } from "@aa-sdk/core";
8
- import {
9
- alchemyFeeEstimator,
10
- alchemyGasAndPaymasterAndDataMiddleware,
11
- alchemyGasManagerMiddleware,
12
- type AlchemyTransport,
13
- } from "@account-kit/infra";
14
- import { type Chain, type Transport } from "viem";
15
- import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
16
- import {
17
- createSession,
18
- type CreateSessionParams,
19
- } from "./actions/createSession.js";
20
- import {
21
- getCallsStatus,
22
- type GetCallsStatusParams,
23
- } from "./actions/getCallsStatus.js";
24
- import {
25
- prepareCalls,
26
- type PrepareCallsParams,
27
- } from "./actions/prepareCalls.js";
28
- import {
29
- sendPreparedCalls,
30
- type SendPreparedCallsParams,
31
- } from "./actions/sendPreparedCalls.js";
32
- import { prepareSign, type PrepareSignParams } from "./actions/prepareSign.js";
33
- import { formatSign, type FormatSignParams } from "./actions/formatSign.js";
34
-
35
- // let's start with something that takes in as many params as possible, then we can eliminate them as we don't need them
36
- type ClientParams = {
37
- chain: Chain;
38
- transport: Transport;
39
- policyId?: string;
40
- useErc7677middleware?: boolean;
41
- feeEstimator?: ClientMiddlewareFn;
42
- };
43
-
44
- export function isomorphicClientActions(
45
- client: SmartAccountClient<
46
- Transport,
47
- Chain,
48
- SmartContractAccount | undefined,
49
- Record<string, unknown>,
50
- WalletServerViemRpcSchema
51
- >,
52
- ) {
53
- return {
54
- prepareCalls: (params: PrepareCallsParams) => prepareCalls(client, params),
55
- sendPreparedCalls: (params: SendPreparedCallsParams) =>
56
- sendPreparedCalls(client, params),
57
- getCallsStatus: (params: GetCallsStatusParams) =>
58
- getCallsStatus(client, params),
59
- createSession: (params: CreateSessionParams) =>
60
- createSession(client, params),
61
- prepareSign: (params: PrepareSignParams) => prepareSign(client, params),
62
- formatSign: (params: FormatSignParams) => formatSign(client, params),
63
- };
64
- }
65
-
66
- // the isomorphic client likely won't be exposed directly. This client contains the business logic that can be run on the wallet server or on the client
67
- // if the dev chooses to run the client in "local" mode.
68
- export function createIsomorphicClient({
69
- chain,
70
- transport,
71
- policyId,
72
- useErc7677middleware = true,
73
- feeEstimator,
74
- }: ClientParams): SmartAccountClient<
75
- Transport,
76
- Chain,
77
- SmartContractAccount | undefined,
78
- ReturnType<typeof isomorphicClientActions>,
79
- WalletServerViemRpcSchema & SmartAccountClientRpcSchema
80
- > {
81
- // This must be a smart account client since as of now we use it to build UOs under the hood
82
- const client = createSmartAccountClient({
83
- transport,
84
- chain,
85
- // TODO: we will want to enforce alchemy transport here probably
86
- feeEstimator:
87
- feeEstimator ?? alchemyFeeEstimator(transport as AlchemyTransport),
88
- ...(policyId
89
- ? useErc7677middleware
90
- ? alchemyGasManagerMiddleware(policyId)
91
- : // NOTE: DO NOT USE THIS MIDDLEWARE in the server, currently we require using the erc7677 middleware
92
- alchemyGasAndPaymasterAndDataMiddleware({
93
- policyId,
94
- transport: transport as AlchemyTransport,
95
- })
96
- : {}),
97
- }).extend(isomorphicClientActions);
98
-
99
- return client;
100
- }
101
-
102
- export type IsomorphicClient = ReturnType<typeof createIsomorphicClient>;
@@ -1,135 +0,0 @@
1
- import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
- import {
3
- concatHex,
4
- numberToHex,
5
- type Address,
6
- type Chain,
7
- type Transport,
8
- isAddress,
9
- hexToNumber,
10
- } from "viem";
11
- import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
12
- import {
13
- Eip7702AccountTypeToDelegationAddress,
14
- SUPPORTED_DELEGATION_ADDRESSES,
15
- type Supported7702AccountType,
16
- type Eip7702AuthCapability,
17
- } from "@alchemy/wallet-api-types/capabilities";
18
- import type { PreparedCall_Authorization } from "@alchemy/wallet-api-types";
19
- import { InvalidRequestError } from "ox/RpcResponse";
20
- import { hashAuthorization } from "viem/utils";
21
-
22
- /** Checks if an address is actively delegated on-chain. */
23
- export const isDelegated = async (
24
- client: SmartAccountClient<
25
- Transport,
26
- Chain,
27
- SmartContractAccount | undefined,
28
- Record<string, unknown>,
29
- WalletServerViemRpcSchema
30
- >,
31
- params: { address: Address; delegation: Address },
32
- ): Promise<boolean> => {
33
- const expectedCode = concatHex(["0xef0100", params.delegation]);
34
- const code = (await client.getCode({ address: params.address })) ?? "0x";
35
- return code.toLowerCase() === expectedCode.toLowerCase();
36
- };
37
-
38
- export const createAuthorizationRequest = async (
39
- client: SmartAccountClient<
40
- Transport,
41
- Chain,
42
- SmartContractAccount | undefined,
43
- Record<string, unknown>,
44
- WalletServerViemRpcSchema
45
- >,
46
- params: { address: Address; delegation: Address },
47
- ): Promise<PreparedCall_Authorization> => {
48
- const data = {
49
- address: params.delegation,
50
- nonce: numberToHex(
51
- await client.getTransactionCount({
52
- address: params.address,
53
- }),
54
- ),
55
- };
56
- return {
57
- type: "authorization" as const,
58
- data,
59
- chainId: numberToHex(client.chain.id),
60
- signatureRequest: {
61
- type: "eip7702Auth" as const,
62
- rawPayload: hashAuthorization({
63
- chainId: client.chain.id,
64
- nonce: hexToNumber(data.nonce),
65
- address: params.delegation,
66
- }),
67
- },
68
- };
69
- };
70
-
71
- export const DelegationAddressToAccountType: Record<
72
- Address,
73
- Supported7702AccountType
74
- > = Object.fromEntries(
75
- Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
76
- value,
77
- key,
78
- ]),
79
- ) as Record<Address, Supported7702AccountType>;
80
-
81
- export const isSupportedDelegationAddress7702 = (address: Address): boolean => {
82
- return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);
83
- };
84
-
85
- export const getAccountTypeForDelegationAddress7702 = (
86
- address: Address,
87
- ): Supported7702AccountType | undefined => {
88
- return DelegationAddressToAccountType[address];
89
- };
90
-
91
- const getDelegationAddressForAccountType7702 = (
92
- accountType: Supported7702AccountType,
93
- ): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {
94
- return Eip7702AccountTypeToDelegationAddress[accountType];
95
- };
96
-
97
- const DEFAULT_7702_DELEGATION_ADDR =
98
- Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
99
-
100
- export const parseDelegation = (
101
- eip7702AuthCapability: Eip7702AuthCapability,
102
- ) => {
103
- return eip7702AuthCapability === true
104
- ? DEFAULT_7702_DELEGATION_ADDR
105
- : isAddress(eip7702AuthCapability.delegation)
106
- ? eip7702AuthCapability.delegation
107
- : getDelegationAddressForAccountType7702(
108
- eip7702AuthCapability.delegation,
109
- );
110
- };
111
-
112
- export const assertValid7702AccountAddress = (
113
- fromAddress: Address,
114
- eip7702AuthCapability: Eip7702AuthCapability | undefined,
115
- ) => {
116
- if (eip7702AuthCapability) {
117
- if (
118
- typeof eip7702AuthCapability === "object" &&
119
- "account" in eip7702AuthCapability &&
120
- eip7702AuthCapability?.account !== fromAddress
121
- ) {
122
- throw new InvalidRequestError({
123
- message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
124
- });
125
- }
126
-
127
- const delegation = parseDelegation(eip7702AuthCapability);
128
-
129
- if (!isSupportedDelegationAddress7702(delegation)) {
130
- throw new InvalidRequestError({
131
- message: `Unsupported 7702 delegation address: ${delegation}`,
132
- });
133
- }
134
- }
135
- };
@@ -1,27 +0,0 @@
1
- import { type SmartAccountSigner } from "@aa-sdk/core";
2
- import type { TypedData } from "abitype";
3
- import {
4
- BaseError,
5
- type Address,
6
- type Hex,
7
- type SignableMessage,
8
- type TypedDataDefinition,
9
- } from "viem";
10
-
11
- export const createDummySigner = (address: Address): SmartAccountSigner => ({
12
- signerType: "",
13
- inner: undefined,
14
- getAddress: async function (): Promise<`0x${string}`> {
15
- return address;
16
- },
17
- // Not supported on the server
18
- signMessage: function (_message: SignableMessage): Promise<Hex> {
19
- throw new BaseError("signMessage not implemented by dummy signer.");
20
- },
21
- signTypedData: function <
22
- const TTypedData extends TypedData | Record<string, unknown>,
23
- TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData,
24
- >(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {
25
- throw new BaseError("signTypedData not implemented by dummy signer.");
26
- },
27
- });
@@ -1,21 +0,0 @@
1
- import { Value } from "@sinclair/typebox/value";
2
- import type { StaticDecode } from "@sinclair/typebox";
3
- import {
4
- EcdsaSig,
5
- type EcdsaSig as EcdsaSigType,
6
- } from "@alchemy/wallet-api-types";
7
- import { assertNever } from "../../utils.js";
8
-
9
- export const decodeSignature = (
10
- signature: EcdsaSigType["signature"],
11
- ): StaticDecode<typeof EcdsaSig>["signature"] => {
12
- switch (signature.type) {
13
- case "ecdsa":
14
- case "secp256k1":
15
- return Value.Decode(EcdsaSig, {
16
- signature,
17
- } satisfies EcdsaSigType).signature;
18
- default:
19
- return assertNever(signature, "Unexpected signature type");
20
- }
21
- };
@@ -1,51 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import { InvalidRequestError } from "ox/RpcResponse";
3
- import type { Address } from "viem";
4
- import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
5
- import {
6
- decodePermissionsContext,
7
- PermissionsCapability,
8
- } from "@alchemy/wallet-api-types/capabilities";
9
- import { SerializedInitcode } from "@alchemy/wallet-api-types";
10
-
11
- export function parsePermissionsContext(
12
- permissions?: StaticDecode<typeof PermissionsCapability>,
13
- parsedCi?: StaticDecode<typeof SerializedInitcode> | undefined,
14
- delegation7702?: Address,
15
- ) {
16
- if (!permissions) {
17
- return undefined;
18
- }
19
-
20
- if ("sessionId" in permissions) {
21
- throw new InvalidRequestError({
22
- message: "Remote permissions are not supported in isomorphic client",
23
- });
24
- }
25
-
26
- if (!("context" in permissions)) {
27
- return undefined;
28
- }
29
-
30
- const isMAV2 =
31
- (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
32
- (delegation7702 &&
33
- getAccountTypeForDelegationAddress7702(delegation7702) ===
34
- "ModularAccountV2");
35
-
36
- if (!isMAV2) {
37
- throw new InvalidRequestError({
38
- message: "Permissions are currently only supported by MAv2 accounts",
39
- });
40
- }
41
-
42
- const context = decodePermissionsContext(permissions);
43
-
44
- if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
45
- throw new InvalidRequestError({
46
- message: "Remote mode deferred action not supported in isomorphic client",
47
- });
48
- }
49
-
50
- return context;
51
- }
@@ -1,34 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import type { SerializedInitcode } from "@alchemy/wallet-api-types";
3
-
4
- export type Feature = "permissions";
5
-
6
- type FactoryType = StaticDecode<typeof SerializedInitcode>["factoryType"];
7
-
8
- const supportedFeatures: Record<FactoryType, Feature[]> = {
9
- "LightAccountV1.0.1": [],
10
- "LightAccountV1.0.2": [],
11
- "LightAccountV1.1.0": [],
12
- "LightAccountV2.0.0": [],
13
- "LightAccountV2.0.0-MultiOwner": [],
14
- "MAv1.0.0-MultiOwner": [],
15
- "MAv1.0.0-MultiSig": [],
16
- "MAv2.0.0-sma-b": ["permissions"],
17
- "MAv2.0.0-ma-ssv": ["permissions"],
18
- "MAv2.0.0-ma-webauthn": [],
19
- unknown: [],
20
- };
21
-
22
- export function supportsFeature(
23
- counterfactualInfo: StaticDecode<typeof SerializedInitcode>,
24
- feature: Feature,
25
- ): boolean {
26
- const factorySupportedFeatures =
27
- supportedFeatures[counterfactualInfo.factoryType];
28
- if (factorySupportedFeatures === undefined) {
29
- throw new Error(
30
- "Unsupported FactoryType: " + counterfactualInfo.factoryType,
31
- );
32
- }
33
- return factorySupportedFeatures.includes(feature);
34
- }