zksync-sso 0.0.0-beta.1

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 (300) hide show
  1. package/.gitignore +5 -0
  2. package/.lintstagedrc.js +5 -0
  3. package/.npmignore +10 -0
  4. package/README.md +3 -0
  5. package/dist/_cjs/abi/Factory.js +197 -0
  6. package/dist/_cjs/abi/Factory.js.map +1 -0
  7. package/dist/_cjs/abi/SessionKeyModule.js +1104 -0
  8. package/dist/_cjs/abi/SessionKeyModule.js.map +1 -0
  9. package/dist/_cjs/client/actions/account.js +140 -0
  10. package/dist/_cjs/client/actions/account.js.map +1 -0
  11. package/dist/_cjs/client/actions/index.js +19 -0
  12. package/dist/_cjs/client/actions/index.js.map +1 -0
  13. package/dist/_cjs/client/actions/passkey.js +122 -0
  14. package/dist/_cjs/client/actions/passkey.js.map +1 -0
  15. package/dist/_cjs/client/actions/session.js +40 -0
  16. package/dist/_cjs/client/actions/session.js.map +1 -0
  17. package/dist/_cjs/client/clients/passkey.js +46 -0
  18. package/dist/_cjs/client/clients/passkey.js.map +1 -0
  19. package/dist/_cjs/client/clients/session.js +48 -0
  20. package/dist/_cjs/client/clients/session.js.map +1 -0
  21. package/dist/_cjs/client/decorators/index.js +19 -0
  22. package/dist/_cjs/client/decorators/index.js.map +1 -0
  23. package/dist/_cjs/client/decorators/passkey.js +15 -0
  24. package/dist/_cjs/client/decorators/passkey.js.map +1 -0
  25. package/dist/_cjs/client/decorators/session.js +7 -0
  26. package/dist/_cjs/client/decorators/session.js.map +1 -0
  27. package/dist/_cjs/client/decorators/session_wallet.js +32 -0
  28. package/dist/_cjs/client/decorators/session_wallet.js.map +1 -0
  29. package/dist/_cjs/client/index.js +22 -0
  30. package/dist/_cjs/client/index.js.map +1 -0
  31. package/dist/_cjs/client/passkey.js +20 -0
  32. package/dist/_cjs/client/passkey.js.map +1 -0
  33. package/dist/_cjs/client/smart-account.js +45 -0
  34. package/dist/_cjs/client/smart-account.js.map +1 -0
  35. package/dist/_cjs/client/utils/assertEip712Transaction.js +44 -0
  36. package/dist/_cjs/client/utils/assertEip712Transaction.js.map +1 -0
  37. package/dist/_cjs/client/utils/getEip712Domain.js +57 -0
  38. package/dist/_cjs/client/utils/getEip712Domain.js.map +1 -0
  39. package/dist/_cjs/client/utils/isEip712Transaction.js +16 -0
  40. package/dist/_cjs/client/utils/isEip712Transaction.js.map +1 -0
  41. package/dist/_cjs/client-auth-server/Signer.js +264 -0
  42. package/dist/_cjs/client-auth-server/Signer.js.map +1 -0
  43. package/dist/_cjs/client-auth-server/WalletProvider.js +107 -0
  44. package/dist/_cjs/client-auth-server/WalletProvider.js.map +1 -0
  45. package/dist/_cjs/client-auth-server/index.js +20 -0
  46. package/dist/_cjs/client-auth-server/index.js.map +1 -0
  47. package/dist/_cjs/client-auth-server/interface.js +3 -0
  48. package/dist/_cjs/client-auth-server/interface.js.map +1 -0
  49. package/dist/_cjs/client-auth-server/rpc.js +3 -0
  50. package/dist/_cjs/client-auth-server/rpc.js.map +1 -0
  51. package/dist/_cjs/client-auth-server/session.js +90 -0
  52. package/dist/_cjs/client-auth-server/session.js.map +1 -0
  53. package/dist/_cjs/communicator/PopupCommunicator.js +138 -0
  54. package/dist/_cjs/communicator/PopupCommunicator.js.map +1 -0
  55. package/dist/_cjs/communicator/index.js +6 -0
  56. package/dist/_cjs/communicator/index.js.map +1 -0
  57. package/dist/_cjs/communicator/interface.js +3 -0
  58. package/dist/_cjs/communicator/interface.js.map +1 -0
  59. package/dist/_cjs/connector/index.js +148 -0
  60. package/dist/_cjs/connector/index.js.map +1 -0
  61. package/dist/_cjs/errors/constants.js +97 -0
  62. package/dist/_cjs/errors/constants.js.map +1 -0
  63. package/dist/_cjs/errors/errors.js +122 -0
  64. package/dist/_cjs/errors/errors.js.map +1 -0
  65. package/dist/_cjs/errors/index.js +10 -0
  66. package/dist/_cjs/errors/index.js.map +1 -0
  67. package/dist/_cjs/errors/serialize.js +63 -0
  68. package/dist/_cjs/errors/serialize.js.map +1 -0
  69. package/dist/_cjs/errors/utils.js +95 -0
  70. package/dist/_cjs/errors/utils.js.map +1 -0
  71. package/dist/_cjs/index.js +6 -0
  72. package/dist/_cjs/index.js.map +1 -0
  73. package/dist/_cjs/package.json +1 -0
  74. package/dist/_cjs/utils/encoding.js +32 -0
  75. package/dist/_cjs/utils/encoding.js.map +1 -0
  76. package/dist/_cjs/utils/helpers.js +43 -0
  77. package/dist/_cjs/utils/helpers.js.map +1 -0
  78. package/dist/_cjs/utils/index.js +20 -0
  79. package/dist/_cjs/utils/index.js.map +1 -0
  80. package/dist/_cjs/utils/passkey.js +243 -0
  81. package/dist/_cjs/utils/passkey.js.map +1 -0
  82. package/dist/_cjs/utils/session.js +30 -0
  83. package/dist/_cjs/utils/session.js.map +1 -0
  84. package/dist/_cjs/utils/storage.js +93 -0
  85. package/dist/_cjs/utils/storage.js.map +1 -0
  86. package/dist/_cjs/version.js +5 -0
  87. package/dist/_cjs/version.js.map +1 -0
  88. package/dist/_esm/abi/Factory.js +194 -0
  89. package/dist/_esm/abi/Factory.js.map +1 -0
  90. package/dist/_esm/abi/SessionKeyModule.js +1101 -0
  91. package/dist/_esm/abi/SessionKeyModule.js.map +1 -0
  92. package/dist/_esm/client/actions/account.js +137 -0
  93. package/dist/_esm/client/actions/account.js.map +1 -0
  94. package/dist/_esm/client/actions/index.js +3 -0
  95. package/dist/_esm/client/actions/index.js.map +1 -0
  96. package/dist/_esm/client/actions/passkey.js +121 -0
  97. package/dist/_esm/client/actions/passkey.js.map +1 -0
  98. package/dist/_esm/client/actions/session.js +36 -0
  99. package/dist/_esm/client/actions/session.js.map +1 -0
  100. package/dist/_esm/client/clients/passkey.js +43 -0
  101. package/dist/_esm/client/clients/passkey.js.map +1 -0
  102. package/dist/_esm/client/clients/session.js +45 -0
  103. package/dist/_esm/client/clients/session.js.map +1 -0
  104. package/dist/_esm/client/decorators/index.js +3 -0
  105. package/dist/_esm/client/decorators/index.js.map +1 -0
  106. package/dist/_esm/client/decorators/passkey.js +13 -0
  107. package/dist/_esm/client/decorators/passkey.js.map +1 -0
  108. package/dist/_esm/client/decorators/session.js +5 -0
  109. package/dist/_esm/client/decorators/session.js.map +1 -0
  110. package/dist/_esm/client/decorators/session_wallet.js +171 -0
  111. package/dist/_esm/client/decorators/session_wallet.js.map +1 -0
  112. package/dist/_esm/client/index.js +3 -0
  113. package/dist/_esm/client/index.js.map +1 -0
  114. package/dist/_esm/client/passkey.js +4 -0
  115. package/dist/_esm/client/passkey.js.map +1 -0
  116. package/dist/_esm/client/smart-account.js +46 -0
  117. package/dist/_esm/client/smart-account.js.map +1 -0
  118. package/dist/_esm/client/utils/assertEip712Transaction.js +39 -0
  119. package/dist/_esm/client/utils/assertEip712Transaction.js.map +1 -0
  120. package/dist/_esm/client/utils/getEip712Domain.js +57 -0
  121. package/dist/_esm/client/utils/getEip712Domain.js.map +1 -0
  122. package/dist/_esm/client/utils/isEip712Transaction.js +13 -0
  123. package/dist/_esm/client/utils/isEip712Transaction.js.map +1 -0
  124. package/dist/_esm/client-auth-server/Signer.js +262 -0
  125. package/dist/_esm/client-auth-server/Signer.js.map +1 -0
  126. package/dist/_esm/client-auth-server/WalletProvider.js +104 -0
  127. package/dist/_esm/client-auth-server/WalletProvider.js.map +1 -0
  128. package/dist/_esm/client-auth-server/index.js +4 -0
  129. package/dist/_esm/client-auth-server/index.js.map +1 -0
  130. package/dist/_esm/client-auth-server/interface.js +2 -0
  131. package/dist/_esm/client-auth-server/interface.js.map +1 -0
  132. package/dist/_esm/client-auth-server/rpc.js +2 -0
  133. package/dist/_esm/client-auth-server/rpc.js.map +1 -0
  134. package/dist/_esm/client-auth-server/session.js +91 -0
  135. package/dist/_esm/client-auth-server/session.js.map +1 -0
  136. package/dist/_esm/communicator/PopupCommunicator.js +136 -0
  137. package/dist/_esm/communicator/PopupCommunicator.js.map +1 -0
  138. package/dist/_esm/communicator/index.js +2 -0
  139. package/dist/_esm/communicator/index.js.map +1 -0
  140. package/dist/_esm/communicator/interface.js +2 -0
  141. package/dist/_esm/communicator/interface.js.map +1 -0
  142. package/dist/_esm/connector/index.js +146 -0
  143. package/dist/_esm/connector/index.js.map +1 -0
  144. package/dist/_esm/errors/constants.js +94 -0
  145. package/dist/_esm/errors/constants.js.map +1 -0
  146. package/dist/_esm/errors/errors.js +124 -0
  147. package/dist/_esm/errors/errors.js.map +1 -0
  148. package/dist/_esm/errors/index.js +4 -0
  149. package/dist/_esm/errors/index.js.map +1 -0
  150. package/dist/_esm/errors/serialize.js +69 -0
  151. package/dist/_esm/errors/serialize.js.map +1 -0
  152. package/dist/_esm/errors/utils.js +101 -0
  153. package/dist/_esm/errors/utils.js.map +1 -0
  154. package/dist/_esm/index.js +2 -0
  155. package/dist/_esm/index.js.map +1 -0
  156. package/dist/_esm/package.json +1 -0
  157. package/dist/_esm/utils/encoding.js +26 -0
  158. package/dist/_esm/utils/encoding.js.map +1 -0
  159. package/dist/_esm/utils/helpers.js +40 -0
  160. package/dist/_esm/utils/helpers.js.map +1 -0
  161. package/dist/_esm/utils/index.js +4 -0
  162. package/dist/_esm/utils/index.js.map +1 -0
  163. package/dist/_esm/utils/passkey.js +294 -0
  164. package/dist/_esm/utils/passkey.js.map +1 -0
  165. package/dist/_esm/utils/session.js +31 -0
  166. package/dist/_esm/utils/session.js.map +1 -0
  167. package/dist/_esm/utils/storage.js +89 -0
  168. package/dist/_esm/utils/storage.js.map +1 -0
  169. package/dist/_esm/version.js +2 -0
  170. package/dist/_esm/version.js.map +1 -0
  171. package/dist/_types/abi/Factory.d.ts +149 -0
  172. package/dist/_types/abi/Factory.d.ts.map +1 -0
  173. package/dist/_types/abi/SessionKeyModule.d.ts +846 -0
  174. package/dist/_types/abi/SessionKeyModule.d.ts.map +1 -0
  175. package/dist/_types/client/actions/account.d.ts +38 -0
  176. package/dist/_types/client/actions/account.d.ts.map +1 -0
  177. package/dist/_types/client/actions/index.d.ts +3 -0
  178. package/dist/_types/client/actions/index.d.ts.map +1 -0
  179. package/dist/_types/client/actions/passkey.d.ts +45 -0
  180. package/dist/_types/client/actions/passkey.d.ts.map +1 -0
  181. package/dist/_types/client/actions/session.d.ts +14 -0
  182. package/dist/_types/client/actions/session.d.ts.map +1 -0
  183. package/dist/_types/client/clients/passkey.d.ts +32 -0
  184. package/dist/_types/client/clients/passkey.d.ts.map +1 -0
  185. package/dist/_types/client/clients/session.d.ts +26 -0
  186. package/dist/_types/client/clients/session.d.ts.map +1 -0
  187. package/dist/_types/client/decorators/index.d.ts +3 -0
  188. package/dist/_types/client/decorators/index.d.ts.map +1 -0
  189. package/dist/_types/client/decorators/passkey.d.ts +8 -0
  190. package/dist/_types/client/decorators/passkey.d.ts.map +1 -0
  191. package/dist/_types/client/decorators/session.d.ts +5 -0
  192. package/dist/_types/client/decorators/session.d.ts.map +1 -0
  193. package/dist/_types/client/decorators/session_wallet.d.ts +5 -0
  194. package/dist/_types/client/decorators/session_wallet.d.ts.map +1 -0
  195. package/dist/_types/client/index.d.ts +3 -0
  196. package/dist/_types/client/index.d.ts.map +1 -0
  197. package/dist/_types/client/passkey.d.ts +4 -0
  198. package/dist/_types/client/passkey.d.ts.map +1 -0
  199. package/dist/_types/client/smart-account.d.ts +24 -0
  200. package/dist/_types/client/smart-account.d.ts.map +1 -0
  201. package/dist/_types/client/utils/assertEip712Transaction.d.ts +11 -0
  202. package/dist/_types/client/utils/assertEip712Transaction.d.ts.map +1 -0
  203. package/dist/_types/client/utils/getEip712Domain.d.ts +3 -0
  204. package/dist/_types/client/utils/getEip712Domain.d.ts.map +1 -0
  205. package/dist/_types/client/utils/isEip712Transaction.d.ts +4 -0
  206. package/dist/_types/client/utils/isEip712Transaction.d.ts.map +1 -0
  207. package/dist/_types/client-auth-server/Signer.d.ts +52 -0
  208. package/dist/_types/client-auth-server/Signer.d.ts.map +1 -0
  209. package/dist/_types/client-auth-server/WalletProvider.d.ts +27 -0
  210. package/dist/_types/client-auth-server/WalletProvider.d.ts.map +1 -0
  211. package/dist/_types/client-auth-server/index.d.ts +4 -0
  212. package/dist/_types/client-auth-server/index.d.ts.map +1 -0
  213. package/dist/_types/client-auth-server/interface.d.ts +34 -0
  214. package/dist/_types/client-auth-server/interface.d.ts.map +1 -0
  215. package/dist/_types/client-auth-server/rpc.d.ts +55 -0
  216. package/dist/_types/client-auth-server/rpc.d.ts.map +1 -0
  217. package/dist/_types/client-auth-server/session.d.ts +45 -0
  218. package/dist/_types/client-auth-server/session.d.ts.map +1 -0
  219. package/dist/_types/communicator/PopupCommunicator.d.ts +20 -0
  220. package/dist/_types/communicator/PopupCommunicator.d.ts.map +1 -0
  221. package/dist/_types/communicator/index.d.ts +3 -0
  222. package/dist/_types/communicator/index.d.ts.map +1 -0
  223. package/dist/_types/communicator/interface.d.ts +16 -0
  224. package/dist/_types/communicator/interface.d.ts.map +1 -0
  225. package/dist/_types/connector/index.d.ts +8 -0
  226. package/dist/_types/connector/index.d.ts.map +1 -0
  227. package/dist/_types/errors/constants.d.ts +96 -0
  228. package/dist/_types/errors/constants.d.ts.map +1 -0
  229. package/dist/_types/errors/errors.d.ts +48 -0
  230. package/dist/_types/errors/errors.d.ts.map +1 -0
  231. package/dist/_types/errors/index.d.ts +5 -0
  232. package/dist/_types/errors/index.d.ts.map +1 -0
  233. package/dist/_types/errors/serialize.d.ts +13 -0
  234. package/dist/_types/errors/serialize.d.ts.map +1 -0
  235. package/dist/_types/errors/utils.d.ts +30 -0
  236. package/dist/_types/errors/utils.d.ts.map +1 -0
  237. package/dist/_types/index.d.ts +4 -0
  238. package/dist/_types/index.d.ts.map +1 -0
  239. package/dist/_types/utils/encoding.d.ts +12 -0
  240. package/dist/_types/utils/encoding.d.ts.map +1 -0
  241. package/dist/_types/utils/helpers.d.ts +4 -0
  242. package/dist/_types/utils/helpers.d.ts.map +1 -0
  243. package/dist/_types/utils/index.d.ts +4 -0
  244. package/dist/_types/utils/index.d.ts.map +1 -0
  245. package/dist/_types/utils/passkey.d.ts +47 -0
  246. package/dist/_types/utils/passkey.d.ts.map +1 -0
  247. package/dist/_types/utils/session.d.ts +95 -0
  248. package/dist/_types/utils/session.d.ts.map +1 -0
  249. package/dist/_types/utils/storage.d.ts +30 -0
  250. package/dist/_types/utils/storage.d.ts.map +1 -0
  251. package/dist/_types/version.d.ts +2 -0
  252. package/dist/_types/version.d.ts.map +1 -0
  253. package/eslint.config.js +6 -0
  254. package/package.json +144 -0
  255. package/prepare-package.mjs +39 -0
  256. package/project.json +67 -0
  257. package/src/abi/Factory.ts +193 -0
  258. package/src/abi/SessionKeyModule.ts +1100 -0
  259. package/src/client/actions/account.ts +198 -0
  260. package/src/client/actions/index.ts +2 -0
  261. package/src/client/actions/passkey.ts +165 -0
  262. package/src/client/actions/session.ts +118 -0
  263. package/src/client/clients/passkey.ts +107 -0
  264. package/src/client/clients/session.ts +105 -0
  265. package/src/client/decorators/index.ts +2 -0
  266. package/src/client/decorators/passkey.ts +22 -0
  267. package/src/client/decorators/session.ts +17 -0
  268. package/src/client/decorators/session_wallet.ts +184 -0
  269. package/src/client/index.ts +2 -0
  270. package/src/client/passkey.ts +3 -0
  271. package/src/client/smart-account.ts +68 -0
  272. package/src/client/utils/assertEip712Transaction.ts +49 -0
  273. package/src/client/utils/getEip712Domain.ts +84 -0
  274. package/src/client/utils/isEip712Transaction.ts +18 -0
  275. package/src/client-auth-server/Signer.ts +260 -0
  276. package/src/client-auth-server/WalletProvider.ts +114 -0
  277. package/src/client-auth-server/index.ts +3 -0
  278. package/src/client-auth-server/interface.ts +39 -0
  279. package/src/client-auth-server/rpc.ts +69 -0
  280. package/src/client-auth-server/session.ts +139 -0
  281. package/src/communicator/PopupCommunicator.ts +111 -0
  282. package/src/communicator/index.ts +2 -0
  283. package/src/communicator/interface.ts +15 -0
  284. package/src/connector/index.ts +171 -0
  285. package/src/errors/constants.ts +119 -0
  286. package/src/errors/errors.ts +168 -0
  287. package/src/errors/index.ts +4 -0
  288. package/src/errors/serialize.ts +91 -0
  289. package/src/errors/utils.ts +152 -0
  290. package/src/index.ts +3 -0
  291. package/src/types/index.d.ts +9 -0
  292. package/src/utils/encoding.ts +36 -0
  293. package/src/utils/helpers.ts +43 -0
  294. package/src/utils/index.ts +3 -0
  295. package/src/utils/passkey.ts +344 -0
  296. package/src/utils/session.ts +103 -0
  297. package/src/utils/storage.ts +87 -0
  298. package/src/version.ts +1 -0
  299. package/tsconfig.base.json +44 -0
  300. package/tsconfig.json +11 -0
@@ -0,0 +1,171 @@
1
+ import {} from "viem";
2
+ import { deployContract, getAddresses, getChainId, prepareTransactionRequest, sendRawTransaction, signMessage, signTypedData, writeContract } from "viem/actions";
3
+ import { getGeneralPaymasterInput, sendEip712Transaction, sendTransaction, signTransaction } from "viem/zksync";
4
+ export function zksyncSsoWalletActions(client) {
5
+ return {
6
+ deployContract: (args) => deployContract(client, args),
7
+ getAddresses: () => getAddresses(client),
8
+ getChainId: () => getChainId(client),
9
+ prepareTransactionRequest: (args) => prepareTransactionRequest(client, args),
10
+ sendRawTransaction: (args) => sendRawTransaction(client, args),
11
+ sendTransaction: async (args) => {
12
+ const tx = client.chain.formatters?.transaction?.format(args) || args;
13
+ /* await verifyTransactionData({
14
+ value: tx.value,
15
+ chain: tx.chain || undefined,
16
+ to: tx.to || undefined,
17
+ data: tx.data,
18
+ gas: tx.gas,
19
+ gasPrice: tx.gasPrice,
20
+ maxFeePerGas: tx.maxFeePerGas,
21
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
22
+ }, client); */
23
+ if (tx.eip712Meta) {
24
+ const transaction = {
25
+ ...tx,
26
+ account: client.account,
27
+ paymaster: tx.eip712Meta.paymasterParams.paymaster,
28
+ // TODO: Find permanent fix as this only works for general paymasters with no input
29
+ paymasterInput: getGeneralPaymasterInput({ innerInput: "0x" }),
30
+ };
31
+ return await sendEip712Transaction(client, transaction);
32
+ }
33
+ return await sendTransaction(client, tx);
34
+ },
35
+ signMessage: (args) => signMessage(client, args),
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ signTransaction: (args) => signTransaction(client, args),
38
+ signTypedData: (args) => signTypedData(client, args),
39
+ writeContract: (args) => writeContract(client, args),
40
+ };
41
+ }
42
+ /* export class SpendLimitError extends Error {
43
+ public tokenAddress: Address;
44
+ public spendLimit: bigint;
45
+
46
+ constructor(message: string, info: { tokenAddress: Address, spendLimit: bigint }) {
47
+ super(message);
48
+ this.tokenAddress = info.tokenAddress;
49
+ this.spendLimit = info.spendLimit;
50
+ }
51
+ }
52
+
53
+ const l2BaseTokenAddress = getAddress('0x000000000000000000000000000000000000800a');
54
+
55
+ const blockedMethods = [
56
+ "approve", // do not allow token approvals to prevent indirect token transfer
57
+ ];
58
+ const isBlockedMethod = (method: string) => {
59
+ return blockedMethods.includes(method);
60
+ }
61
+
62
+ const decodeERC20TransactionData = (transactionData: Hash) => {
63
+ try {
64
+ const { functionName, args } = decodeFunctionData({
65
+ abi: erc20Abi,
66
+ data: transactionData,
67
+ });
68
+ return { functionName, args };
69
+ } catch {
70
+ return { functionName: undefined, args: [] };
71
+ }
72
+ }
73
+
74
+ const getTotalFee = (fee: {
75
+ gas?: bigint,
76
+ gasPrice?: bigint,
77
+ maxFeePerGas?: bigint,
78
+ maxPriorityFeePerGas?: bigint,
79
+ }): bigint => {
80
+ if (!fee.gas) return 0n;
81
+
82
+ if (fee.gasPrice) {
83
+ return fee.gas * fee.gasPrice;
84
+ } else if (fee.maxFeePerGas && fee.maxPriorityFeePerGas) {
85
+ return fee.gas * (fee.maxFeePerGas + fee.maxPriorityFeePerGas);
86
+ } else if (fee.maxFeePerGas) {
87
+ return fee.gas * fee.maxFeePerGas;
88
+ } else if (fee.maxPriorityFeePerGas) {
89
+ return fee.gas * fee.maxPriorityFeePerGas;
90
+ }
91
+
92
+ return 0n;
93
+ }
94
+
95
+ const verifyTransactionData = async (
96
+ transaction: {
97
+ value?: bigint;
98
+ chain?: { id: number | undefined };
99
+ to?: Address;
100
+ data?: Hash;
101
+ gas?: bigint,
102
+ gasPrice?: bigint,
103
+ maxFeePerGas?: bigint,
104
+ maxPriorityFeePerGas?: bigint,
105
+ },
106
+ client: ClientWithZksyncSsoSessionData
107
+ ) => {
108
+ const spendLimitCache = new Map<Address, bigint>(); // Prevent multiple calls to getTokenSpendLimit (mostly for ETH)
109
+ const exceedsSpendLimit = async (tokenAddress: Address, amount: bigint): Promise<boolean> => {
110
+ if (!spendLimitCache.has(tokenAddress)) {
111
+ const spendLimit = await getTokenSpendLimit(client, { tokenAddress, sessionKey: client.sessionKey!, contracts: client.contracts });
112
+ spendLimitCache.set(tokenAddress, spendLimit);
113
+ }
114
+
115
+ const tokenSpendLimit = spendLimitCache.get(tokenAddress)!;
116
+ if (tokenSpendLimit < amount) {
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+
123
+ // Verify transaction value
124
+ const value = transaction.value || 0n;
125
+ if (await exceedsSpendLimit(getAddress(l2BaseTokenAddress), value)) {
126
+ throw new SpendLimitError(`Transaction value ${value} exceeds account spend limit`, {
127
+ tokenAddress: getAddress(l2BaseTokenAddress),
128
+ spendLimit: spendLimitCache.get(getAddress(l2BaseTokenAddress))!,
129
+ });
130
+ }
131
+
132
+ // Verify total fee
133
+ const totalFee = getTotalFee({
134
+ gas: transaction.gas,
135
+ gasPrice: transaction.gasPrice,
136
+ maxFeePerGas: transaction.maxFeePerGas,
137
+ maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
138
+ });
139
+ if (await exceedsSpendLimit(getAddress(l2BaseTokenAddress), totalFee)) {
140
+ throw new SpendLimitError(`Total fee ${totalFee} exceeds account spend limit`, {
141
+ tokenAddress: getAddress(l2BaseTokenAddress),
142
+ spendLimit: spendLimitCache.get(getAddress(l2BaseTokenAddress))!,
143
+ });
144
+ }
145
+
146
+ if (!transaction.data || !transaction.to) return;
147
+
148
+ // Assuming transaction is an erc20 transaction
149
+ const { functionName, args } = decodeERC20TransactionData(transaction.data);
150
+ if (!functionName) return;
151
+
152
+ // Verify if method is not blocked
153
+ if (isBlockedMethod(functionName)) {
154
+ throw new Error(`Method "${functionName}" is not allowed for this account`);
155
+ }
156
+
157
+ const tokenAddress = getAddress(transaction.to.toLowerCase());
158
+
159
+ // Verify transfer amount
160
+ if (functionName === "transfer") {
161
+ const [_to, _amount] = args;
162
+ const amount = _amount ? BigInt(_amount) : 0n;
163
+ if (await exceedsSpendLimit(tokenAddress, amount)) {
164
+ throw new SpendLimitError(`Amount ${amount} exceeds account spend limit`, {
165
+ tokenAddress,
166
+ spendLimit: spendLimitCache.get(tokenAddress)!,
167
+ });
168
+ }
169
+ }
170
+ } */
171
+ //# sourceMappingURL=session_wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session_wallet.js","sourceRoot":"","sources":["../../../../src/client/decorators/session_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgH,MAAM,MAAM,CAAC;AACpI,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClK,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAShH,MAAM,UAAU,sBAAsB,CAIpC,MAAiE;IACjE,OAAO;QACL,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;QACtD,YAAY,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;QACxC,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QACpC,yBAAyB,EAAE,CAAC,IAAI,EAAE,EAAE,CAClC,yBAAyB,CAAC,MAAM,EAAE,IAAI,CAAC;QACzC,kBAAkB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC;QAC9D,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC9B,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;YACtE;;;;;;;;;0BASc;YACd,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;gBAClB,MAAM,WAAW,GAAG;oBAClB,GAAG,EAAE;oBACL,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,SAAS;oBAClD,mFAAmF;oBACnF,cAAc,EAAE,wBAAwB,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;iBAC/D,CAAC;gBACF,OAAO,MAAM,qBAAqB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,MAAM,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,8DAA8D;QAC9D,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,IAAW,CAAC;QAC/D,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC;QACpD,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC;KACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgII"}
@@ -0,0 +1,3 @@
1
+ export { deployAccount, fetchAccount } from "./actions/account.js";
2
+ export * from "./clients/session.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./actions/passkey.js";
2
+ export * from "./clients/passkey.js";
3
+ export * from "./decorators/passkey.js";
4
+ //# sourceMappingURL=passkey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkey.js","sourceRoot":"","sources":["../../../src/client/passkey.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { hashMessage, hashTypedData } from "viem";
2
+ import { toAccount } from "viem/accounts";
3
+ import { serializeTransaction } from "viem/zksync";
4
+ import { getEip712Domain } from "./utils/getEip712Domain.js";
5
+ /**
6
+ * Creates a [ZKsync Smart Account](https://docs.zksync.io/build/developer-reference/account-abstraction/building-smart-accounts)
7
+ * from a Contract Address and a custom sign function.
8
+ */
9
+ export function toSmartAccount(parameters) {
10
+ const { address, sign } = parameters;
11
+ const account = toAccount({
12
+ address,
13
+ sign,
14
+ async signMessage({ message }) {
15
+ return sign({
16
+ hash: hashMessage(message),
17
+ });
18
+ },
19
+ async signTransaction(transaction) {
20
+ const signableTransaction = {
21
+ ...transaction,
22
+ from: this.address,
23
+ type: "eip712",
24
+ gas: 100000000n, // TODO remove when gas estimation is fixed
25
+ };
26
+ const eip712DomainAndMessage = getEip712Domain(signableTransaction);
27
+ const digest = hashTypedData(eip712DomainAndMessage);
28
+ return serializeTransaction({
29
+ ...signableTransaction,
30
+ customSignature: await sign({
31
+ hash: digest,
32
+ }),
33
+ });
34
+ },
35
+ async signTypedData(typedData) {
36
+ return sign({
37
+ hash: hashTypedData(typedData),
38
+ });
39
+ },
40
+ });
41
+ return {
42
+ ...account,
43
+ source: "smartAccountZksync",
44
+ };
45
+ }
46
+ //# sourceMappingURL=smart-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-account.js","sourceRoot":"","sources":["../../../src/client/smart-account.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,WAAW,EAAE,aAAa,EAA+B,MAAM,MAAM,CAAC;AAC7G,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAA4C,MAAM,aAAa,CAAC;AAE7F,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAgB7D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAoC;IAEpC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IAErC,MAAM,OAAO,GAAG,SAAS,CAAC;QACxB,OAAO;QACP,IAAI;QACJ,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;YAC3B,OAAO,IAAI,CAAC;gBACV,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC;aAC3B,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,eAAe,CAAC,WAAW;YAC/B,MAAM,mBAAmB,GAAG;gBAC1B,GAAG,WAAW;gBACd,IAAI,EAAE,IAAI,CAAC,OAAQ;gBACnB,IAAI,EAAE,QAAQ;gBACd,GAAG,EAAE,UAAY,EAAE,2CAA2C;aACxB,CAAC;YAEzC,MAAM,sBAAsB,GAAG,eAAe,CAAC,mBAAmB,CAAC,CAAC;YACpE,MAAM,MAAM,GAAG,aAAa,CAAC,sBAAsB,CAAC,CAAC;YAErD,OAAO,oBAAoB,CAAC;gBAC1B,GAAG,mBAAmB;gBACtB,eAAe,EAAE,MAAM,IAAI,CAAC;oBAC1B,IAAI,EAAE,MAAM;iBACb,CAAC;aACH,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,SAAS;YAC3B,OAAO,IAAI,CAAC;gBACV,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,OAAO;QACV,MAAM,EAAE,oBAAoB;KACP,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { BaseError, InvalidAddressError, InvalidChainIdError, isAddress } from "viem";
2
+ import { isEIP712Transaction } from "./isEip712Transaction.js";
3
+ export function assertEip712Transaction(transaction) {
4
+ const { chainId, to, from, paymaster, paymasterInput } = transaction;
5
+ if (!isEIP712Transaction(transaction))
6
+ throw new InvalidEip712TransactionError();
7
+ if (!chainId || chainId <= 0)
8
+ throw new InvalidChainIdError({ chainId });
9
+ if (to && !isAddress(to))
10
+ throw new InvalidAddressError({ address: to });
11
+ if (from && !isAddress(from))
12
+ throw new InvalidAddressError({ address: from });
13
+ if (paymaster && !isAddress(paymaster))
14
+ throw new InvalidAddressError({ address: paymaster });
15
+ if (paymaster && !paymasterInput) {
16
+ throw new BaseError("`paymasterInput` must be provided when `paymaster` is defined");
17
+ }
18
+ if (!paymaster && paymasterInput) {
19
+ throw new BaseError("`paymaster` must be provided when `paymasterInput` is defined");
20
+ }
21
+ }
22
+ export class InvalidEip712TransactionError extends BaseError {
23
+ constructor() {
24
+ super([
25
+ "Transaction is not an EIP712 transaction.",
26
+ "",
27
+ "Transaction must:",
28
+ " - include `type: \"eip712\"`",
29
+ " - include one of the following: `customSignature`, `paymaster`, `paymasterInput`, `gasPerPubdata`, `factoryDeps`",
30
+ ].join("\n"));
31
+ Object.defineProperty(this, "name", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: "InvalidEip712TransactionError"
36
+ });
37
+ }
38
+ }
39
+ //# sourceMappingURL=assertEip712Transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertEip712Transaction.js","sourceRoot":"","sources":["../../../../src/client/utils/assertEip712Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqB,mBAAmB,EAAE,mBAAmB,EAAE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,+BAA+B;WAAC;IAYhD,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ import { toHex } from "viem";
2
+ import { hashBytecode } from "viem/zksync";
3
+ import { assertEip712Transaction } from "./assertEip712Transaction.js";
4
+ const gasPerPubdataDefault = 50000n;
5
+ /* TODO: This is already available at viem already but not exported (viem also has a mistake in domain name letter casing) */
6
+ export const getEip712Domain = (transaction) => {
7
+ assertEip712Transaction(transaction);
8
+ const message = transactionToMessage(transaction);
9
+ return {
10
+ domain: {
11
+ // cspell:ignore zkSync
12
+ name: `zkSync`,
13
+ version: "2",
14
+ chainId: transaction.chainId,
15
+ },
16
+ types: {
17
+ Transaction: [
18
+ { name: "txType", type: "uint256" },
19
+ { name: "from", type: "uint256" },
20
+ { name: "to", type: "uint256" },
21
+ { name: "gasLimit", type: "uint256" },
22
+ { name: "gasPerPubdataByteLimit", type: "uint256" },
23
+ { name: "maxFeePerGas", type: "uint256" },
24
+ { name: "maxPriorityFeePerGas", type: "uint256" },
25
+ { name: "paymaster", type: "uint256" },
26
+ { name: "nonce", type: "uint256" },
27
+ { name: "value", type: "uint256" },
28
+ { name: "data", type: "bytes" },
29
+ { name: "factoryDeps", type: "bytes32[]" },
30
+ { name: "paymasterInput", type: "bytes" },
31
+ ],
32
+ },
33
+ primaryType: "Transaction",
34
+ message: message,
35
+ };
36
+ };
37
+ //////////////////////////////////////////////////////////////////////////////
38
+ // Utilities
39
+ function transactionToMessage(transaction) {
40
+ const { gas, nonce, to, from, value, maxFeePerGas, maxPriorityFeePerGas, factoryDeps, paymaster, paymasterInput, gasPerPubdata, data, } = transaction;
41
+ return {
42
+ txType: 113n,
43
+ from: BigInt(from),
44
+ to: to ? BigInt(to) : 0n,
45
+ gasLimit: gas ?? 0n,
46
+ gasPerPubdataByteLimit: gasPerPubdata ?? gasPerPubdataDefault,
47
+ maxFeePerGas: maxFeePerGas ?? 0n,
48
+ maxPriorityFeePerGas: maxPriorityFeePerGas ?? 0n,
49
+ paymaster: paymaster ? BigInt(paymaster) : 0n,
50
+ nonce: nonce ? BigInt(nonce) : 0n,
51
+ value: value ?? 0n,
52
+ data: data ? data : "0x0",
53
+ factoryDeps: factoryDeps?.map((dep) => toHex(hashBytecode(dep))) ?? [],
54
+ paymasterInput: paymasterInput ? paymasterInput : "0x",
55
+ };
56
+ }
57
+ //# sourceMappingURL=getEip712Domain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getEip712Domain.js","sourceRoot":"","sources":["../../../../src/client/utils/getEip712Domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAuB,YAAY,EAAsH,MAAM,aAAa,CAAC;AAEpL,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC,6HAA6H;AAC7H,MAAM,CAAC,MAAM,eAAe,GAGxB,CAAC,WAAW,EAAE,EAAE;IAClB,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAErC,MAAM,OAAO,GAAG,oBAAoB,CAClC,WAAkD,CACnD,CAAC;IAEF,OAAO;QACL,MAAM,EAAE;YACN,uBAAuB;YACvB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,WAAW,CAAC,OAAO;SAC7B;QACD,KAAK,EAAE;YACL,WAAW,EAAE;gBACX,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;gBACnC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;gBACjC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC/B,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;gBACrC,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,SAAS,EAAE;gBACnD,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,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M,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QACjC,KAAK,EAAE,KAAK,IAAI,EAAE;QAClB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;QACzB,WAAW,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;QACtE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI;KACvD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export function isEIP712Transaction(transaction) {
2
+ if (transaction.type === "eip712")
3
+ return true;
4
+ if (("customSignature" in transaction && transaction.customSignature)
5
+ || ("paymaster" in transaction && transaction.paymaster)
6
+ || ("paymasterInput" in transaction && transaction.paymasterInput)
7
+ || ("gasPerPubdata" in transaction
8
+ && typeof transaction.gasPerPubdata === "bigint")
9
+ || ("factoryDeps" in transaction && transaction.factoryDeps))
10
+ return true;
11
+ return false;
12
+ }
13
+ //# sourceMappingURL=isEip712Transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isEip712Transaction.js","sourceRoot":"","sources":["../../../../src/client/utils/isEip712Transaction.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,mBAAmB,CACjC,WAAwD;IAExD,IAAI,WAAW,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC/C,IACE,CAAC,iBAAiB,IAAI,WAAW,IAAI,WAAW,CAAC,eAAe,CAAC;WAC9D,CAAC,WAAW,IAAI,WAAW,IAAI,WAAW,CAAC,SAAS,CAAC;WACrD,CAAC,gBAAgB,IAAI,WAAW,IAAI,WAAW,CAAC,cAAc,CAAC;WAC/D,CAAC,eAAe,IAAI,WAAW;eAC7B,OAAO,WAAW,CAAC,aAAa,KAAK,QAAQ,CAAC;WAC9C,CAAC,aAAa,IAAI,WAAW,IAAI,WAAW,CAAC,WAAW,CAAC;QAE9D,OAAO,IAAI,CAAC;IACd,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,262 @@
1
+ import { hexToNumber, http } from "viem";
2
+ import { createZksyncSessionClient } from "../client/index.js";
3
+ import {} from "../utils/session.js";
4
+ import { StorageItem } from "../utils/storage.js";
5
+ export class Signer {
6
+ constructor({ metadata, communicator, updateListener, session, chains, transports }) {
7
+ Object.defineProperty(this, "getMetadata", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ Object.defineProperty(this, "communicator", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ Object.defineProperty(this, "updateListener", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "chains", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "transports", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: {}
36
+ });
37
+ Object.defineProperty(this, "sessionParameters", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ Object.defineProperty(this, "_account", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ Object.defineProperty(this, "_chainsInfo", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: new StorageItem(StorageItem.scopedStorageKey("chainsInfo"), [])
54
+ });
55
+ Object.defineProperty(this, "walletClient", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ Object.defineProperty(this, "clearState", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: () => {
66
+ this._account.remove();
67
+ this._chainsInfo.remove();
68
+ }
69
+ });
70
+ if (!chains.length)
71
+ throw new Error("At least one chain must be included in the config");
72
+ this.getMetadata = metadata;
73
+ this.communicator = communicator;
74
+ this.updateListener = updateListener;
75
+ this.sessionParameters = session;
76
+ this.chains = chains;
77
+ this.transports = transports || {};
78
+ this._account = new StorageItem(StorageItem.scopedStorageKey("account"), null, {
79
+ onChange: (newValue) => {
80
+ if (newValue) {
81
+ this.updateListener.onAccountsUpdate([newValue.address]);
82
+ this.updateListener.onChainUpdate(newValue.activeChainId);
83
+ this.createWalletClient();
84
+ }
85
+ else {
86
+ this.updateListener.onAccountsUpdate([]);
87
+ }
88
+ },
89
+ });
90
+ try {
91
+ if (this.account)
92
+ this.createWalletClient();
93
+ }
94
+ catch (error) {
95
+ console.error("Failed to create wallet client", error);
96
+ console.error("Logging out to prevent crash loop");
97
+ this.clearState();
98
+ }
99
+ }
100
+ get account() {
101
+ const account = this._account.get();
102
+ if (!account)
103
+ return null;
104
+ const chain = this.chains.find((e) => e.id === account.activeChainId);
105
+ return {
106
+ ...account,
107
+ activeChainId: chain?.id || this.chains[0].id,
108
+ };
109
+ }
110
+ get session() { return this.account?.session; }
111
+ get chainsInfo() { return this._chainsInfo.get(); }
112
+ get accounts() { return this.account ? [this.account.address] : []; }
113
+ get chain() {
114
+ const chainId = this.account?.activeChainId || this.chains[0].id;
115
+ return this.chains.find((e) => e.id === chainId);
116
+ }
117
+ createWalletClient() {
118
+ const session = this.session;
119
+ const chain = this.chain;
120
+ const chainInfo = this.chainsInfo.find((e) => e.id === chain.id);
121
+ if (!this.account)
122
+ throw new Error("Account is not set");
123
+ if (!chainInfo)
124
+ throw new Error(`Chain info for ${chain} wasn't set during handshake`);
125
+ if (session) {
126
+ this.walletClient = createZksyncSessionClient({
127
+ address: this.account.address,
128
+ sessionKey: session.sessionKey,
129
+ sessionConfig: session.sessionConfig,
130
+ contracts: chainInfo.contracts,
131
+ chain,
132
+ transport: this.transports[chain.id] || http(),
133
+ });
134
+ }
135
+ else {
136
+ this.walletClient = undefined;
137
+ }
138
+ }
139
+ async handshake() {
140
+ let sessionPreferences;
141
+ let metadata = {
142
+ name: "Unknown DApp",
143
+ icon: null,
144
+ };
145
+ try {
146
+ metadata = this.getMetadata();
147
+ }
148
+ catch (error) {
149
+ console.error("Failed to get website metadata. Proceeding with default one.", error);
150
+ }
151
+ if (this.sessionParameters) {
152
+ try {
153
+ sessionPreferences = await this.sessionParameters();
154
+ }
155
+ catch (error) {
156
+ console.error("Failed to get session data. Proceeding connection with no session.", error);
157
+ }
158
+ }
159
+ const responseMessage = await this.sendRpcRequest({
160
+ method: "eth_requestAccounts",
161
+ params: {
162
+ metadata,
163
+ sessionPreferences,
164
+ },
165
+ });
166
+ const handshakeData = responseMessage.content.result;
167
+ this._chainsInfo.set(handshakeData.chainsInfo);
168
+ this._account.set({
169
+ address: handshakeData.account.address,
170
+ activeChainId: handshakeData.account.activeChainId || this.chain.id,
171
+ session: handshakeData.account.session,
172
+ });
173
+ return this.accounts;
174
+ }
175
+ switchChain(chainId) {
176
+ const chain = this.chains.find((chain) => chain.id === chainId);
177
+ const chainInfo = this.chainsInfo.find((e) => e.id === chainId);
178
+ if (!chainInfo) {
179
+ console.error(`Chain ${chainId} is not supported or chain info was not set during handshake`);
180
+ return false;
181
+ }
182
+ ;
183
+ if (!chain) {
184
+ console.error(`Chain ${chainId} is missing in the configuration`);
185
+ return false;
186
+ }
187
+ ;
188
+ if (chain.id === this.chain.id)
189
+ return true;
190
+ this._account.set({
191
+ ...this.account,
192
+ activeChainId: chain.id,
193
+ });
194
+ return true;
195
+ }
196
+ async request(request) {
197
+ const localResult = await this.tryLocalHandling(request);
198
+ if (localResult !== undefined)
199
+ return localResult;
200
+ const response = await this.sendRpcRequest(request);
201
+ return response.content.result;
202
+ }
203
+ async disconnect() {
204
+ this.clearState();
205
+ }
206
+ async tryLocalHandling(request) {
207
+ switch (request.method) {
208
+ case "eth_estimateGas": {
209
+ if (!this.walletClient || !this.session)
210
+ return undefined;
211
+ const params = request.params;
212
+ const res = await this.walletClient.request({ method: request.method, params: params });
213
+ return res;
214
+ }
215
+ case "eth_sendTransaction": {
216
+ if (!this.walletClient || !this.session)
217
+ return undefined;
218
+ const params = request.params;
219
+ const transactionRequest = params[0];
220
+ const res = await this.walletClient.sendTransaction(transactionRequest);
221
+ return res;
222
+ }
223
+ case "wallet_switchEthereumChain": {
224
+ const params = request.params;
225
+ const chainId = params[0].chainId;
226
+ const switched = this.switchChain(typeof chainId === "string" ? hexToNumber(chainId) : chainId);
227
+ return switched ? null : undefined;
228
+ }
229
+ case "wallet_getCapabilities": {
230
+ const chainInfo = this.chainsInfo.find((e) => e.id === this.chain.id);
231
+ if (!chainInfo)
232
+ throw new Error("Chain info is not set");
233
+ return { [this.chain.id]: chainInfo.capabilities };
234
+ }
235
+ case "eth_accounts": {
236
+ return this.accounts;
237
+ }
238
+ default:
239
+ return undefined;
240
+ }
241
+ }
242
+ async sendRpcRequest(request) {
243
+ // Open popup immediately to make sure popup won't be blocked by Safari
244
+ await this.communicator.ready();
245
+ const message = this.createRequestMessage({
246
+ action: request,
247
+ chainId: this.chain.id,
248
+ });
249
+ const response = await this.communicator.postRequestAndWaitForResponse(message);
250
+ const content = response.content;
251
+ if ("error" in content)
252
+ throw content.error;
253
+ return response;
254
+ }
255
+ createRequestMessage(content) {
256
+ return {
257
+ id: crypto.randomUUID(),
258
+ content,
259
+ };
260
+ }
261
+ }
262
+ //# sourceMappingURL=Signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signer.js","sourceRoot":"","sources":["../../../src/client-auth-server/Signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,WAAW,EAAE,IAAI,EAAsF,MAAM,MAAM,CAAC;AAElK,OAAO,EAAE,yBAAyB,EAA+B,MAAM,oBAAoB,CAAC;AAE5F,OAAO,EAAsB,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAsClD,MAAM,OAAO,MAAM;IAYjB,YAAY,EAAE,QAAQ,E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