@account-kit/wallet-client 0.1.0-alpha.8 → 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 (269) 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 +28 -39
  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} +33 -35
  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 +14 -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 +14 -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 +40 -45
  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/{isomorphic/utils/createAccount.ts → internal/account.ts} +37 -54
  113. package/src/types.ts +7 -18
  114. package/src/utils.ts +15 -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 -38
  120. package/dist/esm/capabilities/index.js +0 -12
  121. package/dist/esm/capabilities/index.js.map +0 -1
  122. package/dist/esm/capabilities/overrides.d.ts +0 -26
  123. package/dist/esm/capabilities/overrides.js +0 -14
  124. package/dist/esm/capabilities/overrides.js.map +0 -1
  125. package/dist/esm/capabilities/paymaster.d.ts +0 -3
  126. package/dist/esm/capabilities/paymaster.js +0 -5
  127. package/dist/esm/capabilities/paymaster.js.map +0 -1
  128. package/dist/esm/capabilities/permissions/index.d.ts +0 -145
  129. package/dist/esm/capabilities/permissions/index.js +0 -83
  130. package/dist/esm/capabilities/permissions/index.js.map +0 -1
  131. package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
  132. package/dist/esm/capabilities/permissions/mav2.js +0 -88
  133. package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
  134. package/dist/esm/client/actions/createAccount.d.ts +0 -35
  135. package/dist/esm/client/actions/createAccount.js +0 -32
  136. package/dist/esm/client/actions/createAccount.js.map +0 -1
  137. package/dist/esm/client/client.e2e-test.d.ts +0 -1
  138. package/dist/esm/client/client.e2e-test.js +0 -375
  139. package/dist/esm/client/client.e2e-test.js.map +0 -1
  140. package/dist/esm/exports/internal.d.ts +0 -13
  141. package/dist/esm/exports/internal.js +0 -15
  142. package/dist/esm/exports/internal.js.map +0 -1
  143. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
  144. package/dist/esm/isomorphic/actions/createSession.js +0 -89
  145. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  146. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
  147. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
  148. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  149. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
  150. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -101
  151. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  152. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  153. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -148
  154. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  155. package/dist/esm/isomorphic/client.d.ts +0 -239
  156. package/dist/esm/isomorphic/client.js +0 -37
  157. package/dist/esm/isomorphic/client.js.map +0 -1
  158. package/dist/esm/isomorphic/utils/7702.d.ts +0 -18
  159. package/dist/esm/isomorphic/utils/7702.js +0 -74
  160. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  161. package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -23
  162. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  163. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  164. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  165. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  166. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  167. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
  168. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  169. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  170. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  171. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  172. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  173. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  174. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  175. package/dist/esm/local/client.d.ts +0 -3
  176. package/dist/esm/local/client.js +0 -97
  177. package/dist/esm/local/client.js.map +0 -1
  178. package/dist/esm/remote/client.d.ts +0 -9
  179. package/dist/esm/remote/client.js +0 -41
  180. package/dist/esm/remote/client.js.map +0 -1
  181. package/dist/esm/rpc/examples.d.ts +0 -230
  182. package/dist/esm/rpc/examples.js +0 -314
  183. package/dist/esm/rpc/examples.js.map +0 -1
  184. package/dist/esm/rpc/request.d.ts +0 -711
  185. package/dist/esm/rpc/request.js +0 -213
  186. package/dist/esm/rpc/request.js.map +0 -1
  187. package/dist/esm/rpc/schema.d.ts +0 -659
  188. package/dist/esm/rpc/schema.js +0 -5
  189. package/dist/esm/rpc/schema.js.map +0 -1
  190. package/dist/esm/schemas.d.ts +0 -693
  191. package/dist/esm/schemas.js +0 -419
  192. package/dist/esm/schemas.js.map +0 -1
  193. package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
  194. package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
  195. package/dist/types/capabilities/index.d.ts +0 -39
  196. package/dist/types/capabilities/index.d.ts.map +0 -1
  197. package/dist/types/capabilities/overrides.d.ts +0 -27
  198. package/dist/types/capabilities/overrides.d.ts.map +0 -1
  199. package/dist/types/capabilities/paymaster.d.ts +0 -4
  200. package/dist/types/capabilities/paymaster.d.ts.map +0 -1
  201. package/dist/types/capabilities/permissions/index.d.ts +0 -146
  202. package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
  203. package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
  204. package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
  205. package/dist/types/client/actions/createAccount.d.ts +0 -36
  206. package/dist/types/client/actions/createAccount.d.ts.map +0 -1
  207. package/dist/types/client/client.e2e-test.d.ts +0 -2
  208. package/dist/types/client/client.e2e-test.d.ts.map +0 -1
  209. package/dist/types/exports/internal.d.ts +0 -14
  210. package/dist/types/exports/internal.d.ts.map +0 -1
  211. package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
  212. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  213. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
  214. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  215. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
  216. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  217. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
  218. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  219. package/dist/types/isomorphic/client.d.ts +0 -240
  220. package/dist/types/isomorphic/client.d.ts.map +0 -1
  221. package/dist/types/isomorphic/utils/7702.d.ts +0 -19
  222. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  223. package/dist/types/isomorphic/utils/createAccount.d.ts +0 -24
  224. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  225. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  226. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  227. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  228. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  229. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  230. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  231. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  232. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  233. package/dist/types/local/client.d.ts +0 -4
  234. package/dist/types/local/client.d.ts.map +0 -1
  235. package/dist/types/remote/client.d.ts +0 -10
  236. package/dist/types/remote/client.d.ts.map +0 -1
  237. package/dist/types/rpc/examples.d.ts +0 -231
  238. package/dist/types/rpc/examples.d.ts.map +0 -1
  239. package/dist/types/rpc/request.d.ts +0 -712
  240. package/dist/types/rpc/request.d.ts.map +0 -1
  241. package/dist/types/rpc/schema.d.ts +0 -660
  242. package/dist/types/rpc/schema.d.ts.map +0 -1
  243. package/dist/types/schemas.d.ts +0 -694
  244. package/dist/types/schemas.d.ts.map +0 -1
  245. package/src/capabilities/eip7702Auth.ts +0 -26
  246. package/src/capabilities/index.ts +0 -12
  247. package/src/capabilities/overrides.ts +0 -35
  248. package/src/capabilities/paymaster.ts +0 -5
  249. package/src/capabilities/permissions/index.ts +0 -163
  250. package/src/capabilities/permissions/mav2.ts +0 -138
  251. package/src/client/actions/createAccount.ts +0 -53
  252. package/src/client/client.e2e-test.ts +0 -463
  253. package/src/exports/internal.ts +0 -16
  254. package/src/isomorphic/actions/createSession.ts +0 -151
  255. package/src/isomorphic/actions/getCallsStatus.ts +0 -170
  256. package/src/isomorphic/actions/prepareCalls.ts +0 -152
  257. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -222
  258. package/src/isomorphic/client.ts +0 -94
  259. package/src/isomorphic/utils/7702.ts +0 -132
  260. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  261. package/src/isomorphic/utils/decodeSignature.ts +0 -18
  262. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
  263. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  264. package/src/local/client.ts +0 -136
  265. package/src/remote/client.ts +0 -67
  266. package/src/rpc/examples.ts +0 -342
  267. package/src/rpc/request.ts +0 -299
  268. package/src/rpc/schema.ts +0 -40
  269. package/src/schemas.ts +0 -585
@@ -1,132 +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
- export const createAuthorizationRequest = async (
19
- client: SmartAccountClient<
20
- Transport,
21
- Chain,
22
- SmartContractAccount | undefined,
23
- Record<string, unknown>,
24
- WalletServerViemRpcSchema
25
- >,
26
- params: { address: Address; delegation: Address },
27
- ): Promise<Static<typeof PreparedCall_Authorization> | undefined> => {
28
- const expectedCode = concatHex(["0xef0100", params.delegation]);
29
- const code = (await client.getCode({ address: params.address })) ?? "0x";
30
- if (code.toLowerCase() === expectedCode.toLowerCase()) {
31
- return undefined; // Already authorized.
32
- }
33
- const data = {
34
- address: params.delegation,
35
- nonce: numberToHex(
36
- await client.getTransactionCount({
37
- address: params.address,
38
- }),
39
- ),
40
- };
41
- return {
42
- type: "authorization" as const,
43
- data,
44
- chainId: numberToHex(client.chain.id),
45
- signatureRequest: {
46
- type: "eip7702Auth" as const,
47
- rawPayload: hashAuthorization({
48
- chainId: client.chain.id,
49
- nonce: hexToNumber(data.nonce),
50
- address: params.delegation,
51
- }),
52
- },
53
- };
54
- };
55
-
56
- export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"] as const;
57
-
58
- type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
59
-
60
- const Eip7702AccountTypeToDelegationAddress = {
61
- ModularAccountV2: "0x69007702764179f14F51cdce752f4f775d74E139",
62
- } as const satisfies Record<Supported7702AccountType, Address>;
63
-
64
- const DelegationAddressToAccountType: Record<
65
- Address,
66
- Supported7702AccountType
67
- > = Object.fromEntries(
68
- Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
69
- value,
70
- key,
71
- ]),
72
- ) as Record<Address, Supported7702AccountType>;
73
-
74
- export const SUPPORTED_DELEGATION_ADDRESSES = Object.values(
75
- Eip7702AccountTypeToDelegationAddress,
76
- );
77
-
78
- export const isSupportedDelegationAddress7702 = (address: Address): boolean => {
79
- return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);
80
- };
81
-
82
- export const getAccountTypeForDelegationAddress7702 = (
83
- address: Address,
84
- ): Supported7702AccountType | undefined => {
85
- return DelegationAddressToAccountType[address];
86
- };
87
-
88
- const getDelegationAddressForAccountType7702 = (
89
- accountType: Supported7702AccountType,
90
- ): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {
91
- return Eip7702AccountTypeToDelegationAddress[accountType];
92
- };
93
-
94
- const DEFAULT_7702_DELEGATION_ADDR =
95
- Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
96
-
97
- export const parseDelegation = (
98
- eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,
99
- ) => {
100
- return eip7702AuthCapability === true
101
- ? DEFAULT_7702_DELEGATION_ADDR
102
- : isAddress(eip7702AuthCapability.delegation)
103
- ? eip7702AuthCapability.delegation
104
- : getDelegationAddressForAccountType7702(
105
- eip7702AuthCapability.delegation,
106
- );
107
- };
108
-
109
- export const assertValid7702AccountAddress = (
110
- fromAddress: Address,
111
- eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,
112
- ) => {
113
- if (eip7702AuthCapability) {
114
- if (
115
- typeof eip7702AuthCapability === "object" &&
116
- "account" in eip7702AuthCapability &&
117
- eip7702AuthCapability?.account !== fromAddress
118
- ) {
119
- throw new InvalidRequestError({
120
- message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
121
- });
122
- }
123
-
124
- const delegation = parseDelegation(eip7702AuthCapability);
125
-
126
- if (!isSupportedDelegationAddress7702(delegation)) {
127
- throw new InvalidRequestError({
128
- message: `Unsupported 7702 delegation address: ${delegation}`,
129
- });
130
- }
131
- }
132
- };
@@ -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
- };