@account-kit/wallet-client 0.1.0-alpha.9 → 4.50.0

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 (276) hide show
  1. package/LICENSE +21 -0
  2. package/dist/esm/client/actions/formatSign.d.ts +30 -0
  3. package/dist/esm/client/actions/formatSign.js +32 -0
  4. package/dist/esm/client/actions/formatSign.js.map +1 -0
  5. package/dist/esm/client/actions/getCallsStatus.d.ts +6 -3
  6. package/dist/esm/client/actions/getCallsStatus.js +3 -0
  7. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +10 -11
  9. package/dist/esm/client/actions/grantPermissions.js +26 -12
  10. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  11. package/dist/esm/client/actions/listAccounts.d.ts +10 -3
  12. package/dist/esm/client/actions/listAccounts.js +14 -2
  13. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  14. package/dist/esm/client/actions/prepareCalls.d.ts +6 -3
  15. package/dist/esm/client/actions/prepareCalls.js +12 -8
  16. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  17. package/dist/esm/client/actions/prepareSign.d.ts +28 -0
  18. package/dist/esm/client/actions/prepareSign.js +31 -0
  19. package/dist/esm/client/actions/prepareSign.js.map +1 -0
  20. package/dist/esm/client/actions/requestAccount.d.ts +3 -1
  21. package/dist/esm/client/actions/requestAccount.js +5 -3
  22. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  23. package/dist/esm/client/actions/sendPreparedCalls.d.ts +3 -1
  24. package/dist/esm/client/actions/sendPreparedCalls.js +2 -0
  25. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  26. package/dist/esm/client/actions/signMessage.d.ts +5 -2
  27. package/dist/esm/client/actions/signMessage.js +5 -2
  28. package/dist/esm/client/actions/signMessage.js.map +1 -1
  29. package/dist/esm/client/actions/signPreparedCalls.d.ts +2 -2
  30. package/dist/esm/client/actions/signPreparedCalls.js +3 -3
  31. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
  32. package/dist/esm/client/actions/signSignatureRequest.d.ts +6 -10
  33. package/dist/esm/client/actions/signSignatureRequest.js +4 -7
  34. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  35. package/dist/esm/client/actions/signTypedData.d.ts +2 -0
  36. package/dist/esm/client/actions/signTypedData.js +2 -0
  37. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  38. package/dist/esm/client/decorator.d.ts +0 -2
  39. package/dist/esm/client/decorator.js +1 -3
  40. package/dist/esm/client/decorator.js.map +1 -1
  41. package/dist/esm/client/index.d.ts +10 -6
  42. package/dist/esm/client/index.js +18 -21
  43. package/dist/esm/client/index.js.map +1 -1
  44. package/dist/esm/exports/index.d.ts +1 -5
  45. package/dist/esm/exports/index.js +1 -6
  46. package/dist/esm/exports/index.js.map +1 -1
  47. package/dist/esm/internal/account.d.ts +33 -0
  48. package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +25 -49
  49. package/dist/esm/internal/account.js.map +1 -0
  50. package/dist/esm/types.d.ts +5 -11
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils.d.ts +13 -1
  53. package/dist/esm/utils.js +13 -1
  54. package/dist/esm/utils.js.map +1 -1
  55. package/dist/esm/version.d.ts +1 -0
  56. package/dist/esm/version.js +4 -0
  57. package/dist/esm/version.js.map +1 -0
  58. package/dist/types/client/actions/formatSign.d.ts +31 -0
  59. package/dist/types/client/actions/formatSign.d.ts.map +1 -0
  60. package/dist/types/client/actions/getCallsStatus.d.ts +6 -3
  61. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  62. package/dist/types/client/actions/grantPermissions.d.ts +10 -11
  63. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  64. package/dist/types/client/actions/listAccounts.d.ts +10 -3
  65. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  66. package/dist/types/client/actions/prepareCalls.d.ts +6 -3
  67. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  68. package/dist/types/client/actions/prepareSign.d.ts +29 -0
  69. package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
  70. package/dist/types/client/actions/requestAccount.d.ts +3 -1
  71. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  72. package/dist/types/client/actions/sendPreparedCalls.d.ts +3 -1
  73. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  74. package/dist/types/client/actions/signMessage.d.ts +5 -2
  75. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  76. package/dist/types/client/actions/signPreparedCalls.d.ts +2 -2
  77. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
  78. package/dist/types/client/actions/signSignatureRequest.d.ts +6 -10
  79. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  80. package/dist/types/client/actions/signTypedData.d.ts +2 -0
  81. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  82. package/dist/types/client/decorator.d.ts +0 -2
  83. package/dist/types/client/decorator.d.ts.map +1 -1
  84. package/dist/types/client/index.d.ts +10 -6
  85. package/dist/types/client/index.d.ts.map +1 -1
  86. package/dist/types/exports/index.d.ts +1 -5
  87. package/dist/types/exports/index.d.ts.map +1 -1
  88. package/dist/types/internal/account.d.ts +34 -0
  89. package/dist/types/internal/account.d.ts.map +1 -0
  90. package/dist/types/types.d.ts +5 -11
  91. package/dist/types/types.d.ts.map +1 -1
  92. package/dist/types/utils.d.ts +13 -1
  93. package/dist/types/utils.d.ts.map +1 -1
  94. package/dist/types/version.d.ts +2 -0
  95. package/dist/types/version.d.ts.map +1 -0
  96. package/package.json +33 -28
  97. package/src/client/actions/formatSign.ts +55 -0
  98. package/src/client/actions/getCallsStatus.ts +10 -6
  99. package/src/client/actions/grantPermissions.ts +46 -18
  100. package/src/client/actions/listAccounts.ts +22 -5
  101. package/src/client/actions/prepareCalls.ts +22 -16
  102. package/src/client/actions/prepareSign.ts +51 -0
  103. package/src/client/actions/requestAccount.ts +6 -4
  104. package/src/client/actions/sendPreparedCalls.ts +3 -1
  105. package/src/client/actions/signMessage.ts +5 -2
  106. package/src/client/actions/signPreparedCalls.ts +8 -12
  107. package/src/client/actions/signSignatureRequest.ts +12 -15
  108. package/src/client/actions/signTypedData.ts +2 -0
  109. package/src/client/decorator.ts +1 -8
  110. package/src/client/index.ts +41 -33
  111. package/src/exports/index.ts +1 -13
  112. package/src/internal/account.ts +120 -0
  113. package/src/types.ts +7 -18
  114. package/src/utils.ts +13 -1
  115. package/src/version.ts +3 -0
  116. package/dist/esm/capabilities/eip7702Auth.d.ts +0 -4
  117. package/dist/esm/capabilities/eip7702Auth.js +0 -18
  118. package/dist/esm/capabilities/eip7702Auth.js.map +0 -1
  119. package/dist/esm/capabilities/index.d.ts +0 -41
  120. package/dist/esm/capabilities/index.js +0 -14
  121. package/dist/esm/capabilities/index.js.map +0 -1
  122. package/dist/esm/capabilities/multiDimensionalNonce.d.ts +0 -3
  123. package/dist/esm/capabilities/multiDimensionalNonce.js +0 -7
  124. package/dist/esm/capabilities/multiDimensionalNonce.js.map +0 -1
  125. package/dist/esm/capabilities/overrides.d.ts +0 -26
  126. package/dist/esm/capabilities/overrides.js +0 -14
  127. package/dist/esm/capabilities/overrides.js.map +0 -1
  128. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  129. package/dist/esm/capabilities/paymaster.js +0 -5
  130. package/dist/esm/capabilities/paymaster.js.map +0 -1
  131. package/dist/esm/capabilities/permissions/index.d.ts +0 -145
  132. package/dist/esm/capabilities/permissions/index.js +0 -83
  133. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  134. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  135. package/dist/esm/capabilities/permissions/mav2.js +0 -88
  136. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  137. package/dist/esm/client/actions/createAccount.d.ts +0 -35
  138. package/dist/esm/client/actions/createAccount.js +0 -32
  139. package/dist/esm/client/actions/createAccount.js.map +0 -1
  140. package/dist/esm/client/client.e2e-test.d.ts +0 -1
  141. package/dist/esm/client/client.e2e-test.js +0 -375
  142. package/dist/esm/client/client.e2e-test.js.map +0 -1
  143. package/dist/esm/exports/internal.d.ts +0 -14
  144. package/dist/esm/exports/internal.js +0 -16
  145. package/dist/esm/exports/internal.js.map +0 -1
  146. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
  147. package/dist/esm/isomorphic/actions/createSession.js +0 -95
  148. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  149. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
  150. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
  151. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  152. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
  153. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
  154. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  155. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  156. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -157
  157. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  158. package/dist/esm/isomorphic/client.d.ts +0 -239
  159. package/dist/esm/isomorphic/client.js +0 -37
  160. package/dist/esm/isomorphic/client.js.map +0 -1
  161. package/dist/esm/isomorphic/utils/7702.d.ts +0 -23
  162. package/dist/esm/isomorphic/utils/7702.js +0 -75
  163. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  164. package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -24
  165. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  166. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  167. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  168. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  169. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  170. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
  171. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  172. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  173. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  174. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  175. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  176. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  177. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  178. package/dist/esm/local/client.d.ts +0 -3
  179. package/dist/esm/local/client.js +0 -97
  180. package/dist/esm/local/client.js.map +0 -1
  181. package/dist/esm/remote/client.d.ts +0 -9
  182. package/dist/esm/remote/client.js +0 -41
  183. package/dist/esm/remote/client.js.map +0 -1
  184. package/dist/esm/rpc/examples.d.ts +0 -230
  185. package/dist/esm/rpc/examples.js +0 -314
  186. package/dist/esm/rpc/examples.js.map +0 -1
  187. package/dist/esm/rpc/request.d.ts +0 -755
  188. package/dist/esm/rpc/request.js +0 -214
  189. package/dist/esm/rpc/request.js.map +0 -1
  190. package/dist/esm/rpc/schema.d.ts +0 -703
  191. package/dist/esm/rpc/schema.js +0 -5
  192. package/dist/esm/rpc/schema.js.map +0 -1
  193. package/dist/esm/schemas.d.ts +0 -712
  194. package/dist/esm/schemas.js +0 -463
  195. package/dist/esm/schemas.js.map +0 -1
  196. package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
  197. package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
  198. package/dist/types/capabilities/index.d.ts +0 -42
  199. package/dist/types/capabilities/index.d.ts.map +0 -1
  200. package/dist/types/capabilities/multiDimensionalNonce.d.ts +0 -4
  201. package/dist/types/capabilities/multiDimensionalNonce.d.ts.map +0 -1
  202. package/dist/types/capabilities/overrides.d.ts +0 -27
  203. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  204. package/dist/types/capabilities/paymaster.d.ts +0 -4
  205. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  206. package/dist/types/capabilities/permissions/index.d.ts +0 -146
  207. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  208. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  209. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  210. package/dist/types/client/actions/createAccount.d.ts +0 -36
  211. package/dist/types/client/actions/createAccount.d.ts.map +0 -1
  212. package/dist/types/client/client.e2e-test.d.ts +0 -2
  213. package/dist/types/client/client.e2e-test.d.ts.map +0 -1
  214. package/dist/types/exports/internal.d.ts +0 -15
  215. package/dist/types/exports/internal.d.ts.map +0 -1
  216. package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
  217. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  218. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
  219. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  220. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
  221. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  222. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
  223. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  224. package/dist/types/isomorphic/client.d.ts +0 -240
  225. package/dist/types/isomorphic/client.d.ts.map +0 -1
  226. package/dist/types/isomorphic/utils/7702.d.ts +0 -24
  227. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  228. package/dist/types/isomorphic/utils/createAccount.d.ts +0 -25
  229. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  230. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  231. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  232. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  233. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  234. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  235. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  236. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  237. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  238. package/dist/types/local/client.d.ts +0 -4
  239. package/dist/types/local/client.d.ts.map +0 -1
  240. package/dist/types/remote/client.d.ts +0 -10
  241. package/dist/types/remote/client.d.ts.map +0 -1
  242. package/dist/types/rpc/examples.d.ts +0 -231
  243. package/dist/types/rpc/examples.d.ts.map +0 -1
  244. package/dist/types/rpc/request.d.ts +0 -756
  245. package/dist/types/rpc/request.d.ts.map +0 -1
  246. package/dist/types/rpc/schema.d.ts +0 -704
  247. package/dist/types/rpc/schema.d.ts.map +0 -1
  248. package/dist/types/schemas.d.ts +0 -713
  249. package/dist/types/schemas.d.ts.map +0 -1
  250. package/src/capabilities/eip7702Auth.ts +0 -26
  251. package/src/capabilities/index.ts +0 -14
  252. package/src/capabilities/multiDimensionalNonce.ts +0 -7
  253. package/src/capabilities/overrides.ts +0 -35
  254. package/src/capabilities/paymaster.ts +0 -5
  255. package/src/capabilities/permissions/index.ts +0 -163
  256. package/src/capabilities/permissions/mav2.ts +0 -138
  257. package/src/client/actions/createAccount.ts +0 -53
  258. package/src/client/client.e2e-test.ts +0 -463
  259. package/src/exports/internal.ts +0 -17
  260. package/src/isomorphic/actions/createSession.ts +0 -159
  261. package/src/isomorphic/actions/getCallsStatus.ts +0 -170
  262. package/src/isomorphic/actions/prepareCalls.ts +0 -170
  263. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -232
  264. package/src/isomorphic/client.ts +0 -94
  265. package/src/isomorphic/utils/7702.ts +0 -143
  266. package/src/isomorphic/utils/createAccount.ts +0 -170
  267. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  268. package/src/isomorphic/utils/decodeSignature.ts +0 -18
  269. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
  270. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  271. package/src/local/client.ts +0 -136
  272. package/src/remote/client.ts +0 -67
  273. package/src/rpc/examples.ts +0 -342
  274. package/src/rpc/request.ts +0 -300
  275. package/src/rpc/schema.ts +0 -40
  276. package/src/schemas.ts +0 -657
@@ -1,143 +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 "../../rpc/schema.js";
12
- import { PreparedCall_Authorization } from "../../schemas.js";
13
- import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
14
- import type { Static } from "@sinclair/typebox";
15
- import { InvalidRequestError } from "ox/RpcResponse";
16
- import { hashAuthorization } from "viem/utils";
17
-
18
- /** Checks if an address is actively delegated on-chain. */
19
- export const isDelegated = async (
20
- client: SmartAccountClient<
21
- Transport,
22
- Chain,
23
- SmartContractAccount | undefined,
24
- Record<string, unknown>,
25
- WalletServerViemRpcSchema
26
- >,
27
- params: { address: Address; delegation: Address },
28
- ): Promise<boolean> => {
29
- const expectedCode = concatHex(["0xef0100", params.delegation]);
30
- const code = (await client.getCode({ address: params.address })) ?? "0x";
31
- return code.toLowerCase() === expectedCode.toLowerCase();
32
- };
33
-
34
- export const createAuthorizationRequest = async (
35
- client: SmartAccountClient<
36
- Transport,
37
- Chain,
38
- SmartContractAccount | undefined,
39
- Record<string, unknown>,
40
- WalletServerViemRpcSchema
41
- >,
42
- params: { address: Address; delegation: Address },
43
- ): Promise<Static<typeof PreparedCall_Authorization>> => {
44
- const data = {
45
- address: params.delegation,
46
- nonce: numberToHex(
47
- await client.getTransactionCount({
48
- address: params.address,
49
- }),
50
- ),
51
- };
52
- return {
53
- type: "authorization" as const,
54
- data,
55
- chainId: numberToHex(client.chain.id),
56
- signatureRequest: {
57
- type: "eip7702Auth" as const,
58
- rawPayload: hashAuthorization({
59
- chainId: client.chain.id,
60
- nonce: hexToNumber(data.nonce),
61
- address: params.delegation,
62
- }),
63
- },
64
- };
65
- };
66
-
67
- export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"] as const;
68
-
69
- type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
70
-
71
- const Eip7702AccountTypeToDelegationAddress = {
72
- ModularAccountV2: "0x69007702764179f14F51cdce752f4f775d74E139",
73
- } as const satisfies Record<Supported7702AccountType, Address>;
74
-
75
- const DelegationAddressToAccountType: Record<
76
- Address,
77
- Supported7702AccountType
78
- > = Object.fromEntries(
79
- Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
80
- value,
81
- key,
82
- ]),
83
- ) as Record<Address, Supported7702AccountType>;
84
-
85
- export const SUPPORTED_DELEGATION_ADDRESSES = Object.values(
86
- Eip7702AccountTypeToDelegationAddress,
87
- );
88
-
89
- export const isSupportedDelegationAddress7702 = (address: Address): boolean => {
90
- return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);
91
- };
92
-
93
- export const getAccountTypeForDelegationAddress7702 = (
94
- address: Address,
95
- ): Supported7702AccountType | undefined => {
96
- return DelegationAddressToAccountType[address];
97
- };
98
-
99
- const getDelegationAddressForAccountType7702 = (
100
- accountType: Supported7702AccountType,
101
- ): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {
102
- return Eip7702AccountTypeToDelegationAddress[accountType];
103
- };
104
-
105
- const DEFAULT_7702_DELEGATION_ADDR =
106
- Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
107
-
108
- export const parseDelegation = (
109
- eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,
110
- ) => {
111
- return eip7702AuthCapability === true
112
- ? DEFAULT_7702_DELEGATION_ADDR
113
- : isAddress(eip7702AuthCapability.delegation)
114
- ? eip7702AuthCapability.delegation
115
- : getDelegationAddressForAccountType7702(
116
- eip7702AuthCapability.delegation,
117
- );
118
- };
119
-
120
- export const assertValid7702AccountAddress = (
121
- fromAddress: Address,
122
- eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,
123
- ) => {
124
- if (eip7702AuthCapability) {
125
- if (
126
- typeof eip7702AuthCapability === "object" &&
127
- "account" in eip7702AuthCapability &&
128
- eip7702AuthCapability?.account !== fromAddress
129
- ) {
130
- throw new InvalidRequestError({
131
- message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
132
- });
133
- }
134
-
135
- const delegation = parseDelegation(eip7702AuthCapability);
136
-
137
- if (!isSupportedDelegationAddress7702(delegation)) {
138
- throw new InvalidRequestError({
139
- message: `Unsupported 7702 delegation address: ${delegation}`,
140
- });
141
- }
142
- }
143
- };
@@ -1,170 +0,0 @@
1
- import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
2
- import {
3
- createLightAccount,
4
- createModularAccountV2,
5
- createMultiOwnerLightAccount,
6
- createMultiOwnerModularAccount,
7
- type ModularAccountV2,
8
- } from "@account-kit/smart-contracts";
9
- import type { StaticDecode } from "@sinclair/typebox";
10
- import type { Address, Chain, Transport } from "viem";
11
- import { concatHex, hexToBigInt, hexToNumber, zeroAddress } from "viem";
12
- import type { TypeSerializedInitcode } from "../../schemas.js";
13
- import { parsePermissionsContext } from "./parsePermissionsContext.js";
14
- import { assertNever } from "../../utils.js";
15
- import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
16
- import { PermissionsCapability } from "../../capabilities/permissions/index.js";
17
- import { InternalError, InvalidRequestError } from "ox/RpcResponse";
18
-
19
- type CreateAccountParams = {
20
- chain: Chain;
21
- transport: Transport;
22
- signer: SmartAccountSigner;
23
- accountAddress: Address;
24
- counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts
25
- permissions?: StaticDecode<typeof PermissionsCapability>;
26
- delegation?: Address;
27
- };
28
-
29
- /**
30
- * Creates a smart account instance from the given parameters.
31
- * @param params - The parameters for creating a smart account.
32
- * @returns A promise that resolves to the created smart account.
33
- */
34
- export async function createAccount(
35
- params: CreateAccountParams,
36
- ): Promise<SmartContractAccount> {
37
- const { counterfactualInfo: ci, ...accountParams } = params;
38
-
39
- // This throws if we pass a permission context and the account is not MA-v2
40
- // TODO: test that this edge case is handled correctly
41
- const parsedContext = parsePermissionsContext(
42
- params.permissions,
43
- ci,
44
- params.delegation,
45
- );
46
-
47
- const signerEntity =
48
- parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
49
- ? {
50
- entityId: hexToNumber(parsedContext.entityId),
51
- isGlobalValidation: parsedContext.isGlobalValidation,
52
- }
53
- : undefined;
54
-
55
- const mode = params.delegation ? "7702" : "default";
56
-
57
- if (mode === "7702") {
58
- const accountType = getAccountTypeForDelegationAddress7702(
59
- params.delegation!,
60
- );
61
- if (accountType !== "ModularAccountV2") {
62
- throw new Error("7702 mode currently only supports ModularAccountV2");
63
- }
64
- return createModularAccountV2({
65
- ...accountParams,
66
- signerEntity,
67
- deferredAction: parsedContext?.deferredAction,
68
- mode,
69
- });
70
- }
71
-
72
- if (mode !== "default") {
73
- return assertNever(mode, "Unexpected mode in createAccount");
74
- }
75
-
76
- // At this point, we are guaranteed to be in default mode, where ci
77
- // (counterfactualInfo) must be defined
78
-
79
- if (!ci) {
80
- throw new InternalError({
81
- message: "Counterfactual info not found",
82
- });
83
- }
84
-
85
- const factoryType = ci.factoryType;
86
- const commonParams = {
87
- ...accountParams,
88
- initCode: concatHex([ci.factoryAddress, ci.factoryData]),
89
- };
90
-
91
- // Return the account created based on the factory type
92
- switch (factoryType) {
93
- case "MAv2.0.0-sma-b":
94
- return createModularAccountV2({
95
- ...commonParams,
96
- signerEntity,
97
- deferredAction: parsedContext?.deferredAction,
98
- mode,
99
- });
100
- case "LightAccountV2.0.0":
101
- return createLightAccount({
102
- ...commonParams,
103
- version: "v2.0.0",
104
- });
105
- case "LightAccountV1.0.1":
106
- return createLightAccount({
107
- ...commonParams,
108
- version: "v1.0.1",
109
- });
110
- case "LightAccountV1.0.2":
111
- return createLightAccount({
112
- ...commonParams,
113
- version: "v1.0.2",
114
- });
115
- case "LightAccountV1.1.0":
116
- return createLightAccount({
117
- ...commonParams,
118
- version: "v1.1.0",
119
- });
120
- case "MAv1.0.0-MultiOwner":
121
- return createMultiOwnerModularAccount({
122
- ...commonParams,
123
- });
124
- case "LightAccountV2.0.0-MultiOwner":
125
- return createMultiOwnerLightAccount({
126
- ...commonParams,
127
- version: "v2.0.0",
128
- });
129
- case "MAv1.0.0-MultiSig":
130
- case "MAv2.0.0-ma-ssv":
131
- case "MAv2.0.0-ma-webauthn":
132
- case "unknown":
133
- case undefined:
134
- throw new InvalidRequestError({
135
- message: `Account type currently unsupported: ${factoryType}`,
136
- });
137
- default:
138
- return assertNever(factoryType, "Unsupported factory type");
139
- }
140
- }
141
-
142
- export function isModularAccountV2(
143
- account: SmartContractAccount,
144
- ): account is ModularAccountV2 {
145
- return account.source === "ModularAccountV2";
146
- }
147
-
148
- // Performs basic checks on the initialOwners array and returns a new array with the signer address added if not present.
149
- // Pulled from MAv1 support in Account Kit.
150
- export function prepareInitialOwners(
151
- initialOwners: Address[],
152
- signerAddress: Address,
153
- ): Address[] {
154
- const preparedOwners = Array.from(
155
- new Set([...initialOwners, signerAddress]),
156
- ).sort((a, b) => {
157
- const bigintA = hexToBigInt(a);
158
- const bigintB = hexToBigInt(b);
159
-
160
- return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;
161
- });
162
-
163
- if (preparedOwners.some((x) => x === zeroAddress)) {
164
- throw new InvalidRequestError({
165
- message: "Initial owners cannot contain the zero address",
166
- });
167
- }
168
-
169
- return preparedOwners;
170
- }
@@ -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,18 +0,0 @@
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
- };
@@ -1,49 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import { InvalidRequestError } from "ox/RpcResponse";
3
- import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
4
- import type { TypeSerializedInitcode } from "../../schemas.js";
5
- import type { Address } from "viem";
6
- import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
7
- import { PermissionsCapability } from "../../capabilities/permissions/index.js";
8
-
9
- export function parsePermissionsContext(
10
- permissions?: StaticDecode<typeof PermissionsCapability>,
11
- parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined,
12
- delegation7702?: Address,
13
- ) {
14
- if (!permissions) {
15
- return undefined;
16
- }
17
-
18
- if ("sessionId" in permissions) {
19
- throw new InvalidRequestError({
20
- message: "Remote permissions are not supported in isomorphic client",
21
- });
22
- }
23
-
24
- if (!("context" in permissions)) {
25
- return undefined;
26
- }
27
-
28
- const isMAV2 =
29
- (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
30
- (delegation7702 &&
31
- getAccountTypeForDelegationAddress7702(delegation7702) ===
32
- "ModularAccountV2");
33
-
34
- if (!isMAV2) {
35
- throw new InvalidRequestError({
36
- message: "Permissions are currently only supported by MAv2 accounts",
37
- });
38
- }
39
-
40
- const context = decodePermissionsContext(permissions);
41
-
42
- if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
43
- throw new InvalidRequestError({
44
- message: "Remote mode deferred action not supported in isomorphic client",
45
- });
46
- }
47
-
48
- return context;
49
- }
@@ -1,34 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import type { TypeSerializedInitcode } from "../../schemas.ts";
3
-
4
- export type Feature = "permissions";
5
-
6
- type FactoryType = StaticDecode<typeof TypeSerializedInitcode>["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 TypeSerializedInitcode>,
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
- }
@@ -1,136 +0,0 @@
1
- import { split } from "@aa-sdk/core";
2
- import { buildDeferredActionDigest } from "@account-kit/smart-contracts/experimental";
3
- import { createClient, custom, type Address } from "viem";
4
- import {
5
- encodePermissionsContext,
6
- prefixSignatureKeyType,
7
- } from "../capabilities/permissions/mav2.js";
8
- import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
9
- import { internalStateDecorator } from "../internal/decorator.js";
10
- import type { PrepareCallsParams } from "../isomorphic/actions/prepareCalls.ts";
11
- import {
12
- createIsomorphicClient,
13
- type IsomorphicClient,
14
- } from "../isomorphic/client.js";
15
- import type {
16
- CreateInnerClientParams,
17
- InnerClientActions,
18
- InnerWalletApiClient,
19
- } from "../types.ts";
20
- import { assertNever } from "../utils.js";
21
-
22
- const localMethods = [
23
- "wallet_prepareCalls",
24
- "wallet_sendPreparedCalls",
25
- "wallet_getCallsStatus",
26
- "wallet_createSession",
27
- ] as const satisfies string[];
28
- type LocalMethod = (typeof localMethods)[number];
29
-
30
- export function createLocalClient<
31
- TAccount extends Address | undefined = Address | undefined,
32
- >(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
33
-
34
- export function createLocalClient(
35
- params: CreateInnerClientParams,
36
- ): InnerWalletApiClient {
37
- const { chain, transport, policyId, account } = params;
38
- const isomorphicClient = createIsomorphicClient({
39
- transport,
40
- chain,
41
- policyId,
42
- useErc7677middleware: false,
43
- });
44
-
45
- const clientMap: Record<string, ReturnType<typeof createIsomorphicClient>> = {
46
- [policyId ?? "default"]: isomorphicClient,
47
- };
48
-
49
- const innerTransport = split({
50
- overrides: [
51
- {
52
- methods: localMethods,
53
- transport: custom(
54
- {
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- async request(args: { method: LocalMethod; params: any }) {
57
- switch (args.method) {
58
- case "wallet_prepareCalls": {
59
- const params = args.params[0] as PrepareCallsParams;
60
- const capabilityPolicyId =
61
- params.capabilities?.paymasterService?.policyId;
62
-
63
- if (
64
- capabilityPolicyId != null &&
65
- policyId !== capabilityPolicyId &&
66
- !clientMap[capabilityPolicyId]
67
- ) {
68
- clientMap[capabilityPolicyId] = createIsomorphicClient({
69
- transport,
70
- chain,
71
- policyId: capabilityPolicyId,
72
- });
73
- }
74
-
75
- const client =
76
- clientMap[capabilityPolicyId ?? policyId ?? "default"];
77
- return client.prepareCalls(params);
78
- }
79
- case "wallet_sendPreparedCalls":
80
- return isomorphicClient.sendPreparedCalls(args.params[0]);
81
- case "wallet_getCallsStatus":
82
- return isomorphicClient.getCallsStatus(args.params[0]);
83
- case "wallet_createSession": {
84
- return isomorphicClient.createSession(args.params[0]);
85
- }
86
- default:
87
- return assertNever(
88
- args.method,
89
- `Unexpected method: ${args.method}`,
90
- );
91
- }
92
- },
93
- },
94
- {
95
- retryCount: 0,
96
- },
97
- ),
98
- },
99
- ],
100
- fallback: transport,
101
- });
102
-
103
- return createClient({
104
- transport: innerTransport,
105
- chain,
106
- account,
107
- })
108
- .extend(() => ({
109
- policyId,
110
- ...innerClientActions(isomorphicClient),
111
- }))
112
- .extend(() => ({
113
- internal: internalStateDecorator(),
114
- }));
115
- }
116
-
117
- const innerClientActions = (
118
- isomorphicClient: IsomorphicClient,
119
- ): InnerClientActions => {
120
- return {
121
- grantPermissions: async (signer, params) => {
122
- const { signatureRequest, fullPreSignatureDeferredActionDigest } =
123
- await isomorphicClient.createSession(params);
124
- const signature = await signSignatureRequest(signer, signatureRequest);
125
- return {
126
- context: encodePermissionsContext({
127
- contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
128
- deferredAction: buildDeferredActionDigest({
129
- fullPreSignatureDeferredActionDigest,
130
- sig: prefixSignatureKeyType(signature.data, signature.type),
131
- }),
132
- }),
133
- };
134
- },
135
- };
136
- };
@@ -1,67 +0,0 @@
1
- import { Provider } from "ox";
2
- import { createClient, custom, type Address } from "viem";
3
- import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
4
- import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
5
- import { internalStateDecorator } from "../internal/decorator.js";
6
- import { WalletServerRpcSchema } from "../rpc/schema.js";
7
- import type {
8
- CreateInnerClientParams,
9
- InnerClientActions,
10
- InnerWalletApiClient,
11
- InnerWalletApiClientBase,
12
- } from "../types.ts";
13
-
14
- /**
15
- * This is a low-level client just used to make RPC requests in remote mode
16
- * This should be wrapped by a higher-level smart account client that provides actions
17
- * that uses this client under the hood
18
- * @returns
19
- */
20
- export function createRemoteClient<
21
- TAccount extends Address | undefined = Address | undefined,
22
- >(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
23
-
24
- export function createRemoteClient(
25
- params: CreateInnerClientParams,
26
- ): InnerWalletApiClient {
27
- const { transport, chain, account } = params;
28
-
29
- const client = createClient({
30
- transport: (opts) =>
31
- custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(
32
- opts,
33
- ),
34
- chain,
35
- account,
36
- })
37
- .extend((_client) => ({
38
- policyId: params.policyId,
39
- ...innerClientActions(_client),
40
- }))
41
- .extend(() => ({
42
- internal: internalStateDecorator(),
43
- }));
44
-
45
- return client;
46
- }
47
-
48
- const innerClientActions = (
49
- apiClient: InnerWalletApiClientBase,
50
- ): InnerClientActions => {
51
- return {
52
- grantPermissions: async (signer, params) => {
53
- const { sessionId, signatureRequest } = await apiClient.request({
54
- method: "wallet_createSession",
55
- params: [params],
56
- });
57
- const signature = await signSignatureRequest(signer, signatureRequest);
58
- return {
59
- context: encodePermissionsContext({
60
- contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
61
- sessionId,
62
- signature: signature.data,
63
- }),
64
- };
65
- },
66
- };
67
- };