@talken/talkenkit 2.4.20 → 2.4.22

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 (175) hide show
  1. package/LICENSE +9 -0
  2. package/dist/abcWallet-4RS3B4ZG.js +188 -0
  3. package/dist/abcWallet-EBOW2RJB.js +188 -0
  4. package/dist/abcWallet-RS4EOJ4I.js +188 -0
  5. package/dist/abcWallet-SNEZVK7V.js +188 -0
  6. package/dist/abcWallet-TC7M2JYX.js +188 -0
  7. package/dist/abcWallet-VZMW2DR3.js +188 -0
  8. package/dist/abcWallet-XJ3WSUVI.js +188 -0
  9. package/dist/abcWallet-XNCBZAIQ.js +188 -0
  10. package/dist/chunk-6FLQAAC4.js +7213 -0
  11. package/dist/chunk-7GIIMIPN.js +7213 -0
  12. package/dist/chunk-IBFA37SC.js +7228 -0
  13. package/dist/chunk-O5ZOC4NJ.js +7215 -0
  14. package/dist/chunk-OPOAKGEX.js +7216 -0
  15. package/dist/chunk-OTIHVCVR.js +7213 -0
  16. package/dist/chunk-P77BVZZF.js +7369 -0
  17. package/dist/chunk-RFLXXSQH.js +7139 -0
  18. package/dist/components/ConfirmationModal/NonEvmConfirmationModal.css.d.ts +11 -0
  19. package/dist/components/ConfirmationModal/NonEvmSignConfirmationModal.d.ts +9 -0
  20. package/dist/components/ConfirmationModal/NonEvmTransferConfirmationModal.d.ts +9 -0
  21. package/dist/components/ConfirmationModal/SignConfirmationModal.css.d.ts +1 -19
  22. package/dist/components/ConfirmationModal/TransactionConfirmationModal.css.d.ts +1 -20
  23. package/dist/components/ConfirmationModal/commonStyles.css.d.ts +19 -0
  24. package/dist/components/ConfirmationModal/index.d.ts +2 -0
  25. package/dist/components/ConfirmationModal/utils.d.ts +2 -1
  26. package/dist/hooks/useWalletCapabilities.d.ts +2 -0
  27. package/dist/index.css +227 -307
  28. package/dist/index.d.ts +4 -2
  29. package/dist/index.js +2007 -1067
  30. package/dist/providers/SignConfirmationProvider/NonEvmConfirmationContext.d.ts +6 -0
  31. package/dist/providers/SignConfirmationProvider/index.d.ts +2 -1
  32. package/dist/providers/SignConfirmationProvider/requestParsers.d.ts +6 -1
  33. package/dist/providers/SignConfirmationProvider/types.d.ts +35 -1
  34. package/dist/wallets/capabilities/detectCapabilities.d.ts +7 -0
  35. package/dist/wallets/capabilities/requestWalletAction.d.ts +8 -0
  36. package/dist/wallets/capabilities/types.d.ts +50 -0
  37. package/dist/wallets/walletConnectors/abcWallet/abcApi.js +3 -3
  38. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
  39. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +10 -0
  40. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
  41. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +5 -5
  42. package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +9 -0
  43. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +3 -3
  44. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +10 -0
  45. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
  46. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +16 -0
  47. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +115 -33
  48. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +16 -0
  49. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +1 -1
  50. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +7 -7
  51. package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.js +4 -4
  52. package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.js +3 -3
  53. package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +4 -4
  54. package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +4 -4
  55. package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +4 -4
  56. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +9 -4
  57. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +2 -2
  58. package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.js +4 -4
  59. package/dist/wallets/walletConnectors/abcWallet/api/TronApi.js +4 -4
  60. package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.js +4 -4
  61. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +4 -4
  62. package/dist/wallets/walletConnectors/abcWallet/api/index.js +17 -17
  63. package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +5 -4
  64. package/dist/wallets/walletConnectors/abcWallet/constants.js +1 -1
  65. package/dist/wallets/walletConnectors/abcWallet/index.js +21 -21
  66. package/dist/wallets/walletConnectors/abcWallet/types.d.ts +31 -1
  67. package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
  68. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  69. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  70. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  71. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  72. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  73. package/dist/wallets/walletConnectors/chunk-2IZBLAHI.js +52 -0
  74. package/dist/wallets/walletConnectors/chunk-32IJ3ILH.js +71 -0
  75. package/dist/wallets/walletConnectors/chunk-3AX66UHT.js +479 -0
  76. package/dist/wallets/walletConnectors/chunk-3BVPV64G.js +36 -0
  77. package/dist/wallets/walletConnectors/chunk-3DGFHWI3.js +302 -0
  78. package/dist/wallets/walletConnectors/chunk-4FKUVQCM.js +655 -0
  79. package/dist/wallets/walletConnectors/chunk-56SF4VRC.js +640 -0
  80. package/dist/wallets/walletConnectors/chunk-5KOE7NJW.js +52 -0
  81. package/dist/wallets/walletConnectors/chunk-6CVXZ3ZW.js +771 -0
  82. package/dist/wallets/walletConnectors/chunk-6GCWEPU7.js +643 -0
  83. package/dist/wallets/walletConnectors/chunk-6YFP3Q2I.js +118 -0
  84. package/dist/wallets/walletConnectors/chunk-7EEPPULA.js +118 -0
  85. package/dist/wallets/walletConnectors/chunk-7QL42XTB.js +302 -0
  86. package/dist/wallets/walletConnectors/chunk-A7ZSPSFX.js +577 -0
  87. package/dist/wallets/walletConnectors/chunk-AI3CT254.js +302 -0
  88. package/dist/wallets/walletConnectors/chunk-AMNVH7CZ.js +151 -0
  89. package/dist/wallets/walletConnectors/chunk-AOREXGRM.js +350 -0
  90. package/dist/wallets/walletConnectors/chunk-BLO7E54F.js +302 -0
  91. package/dist/wallets/walletConnectors/chunk-BNRH5PYS.js +52 -0
  92. package/dist/wallets/walletConnectors/chunk-BOV5FXU6.js +151 -0
  93. package/dist/wallets/walletConnectors/chunk-BR25RFNF.js +260 -0
  94. package/dist/wallets/walletConnectors/chunk-BXQ2UWJ3.js +91 -0
  95. package/dist/wallets/walletConnectors/chunk-CAMPW7O2.js +874 -0
  96. package/dist/wallets/walletConnectors/chunk-CLMFCNP7.js +52 -0
  97. package/dist/wallets/walletConnectors/chunk-DSZOE65L.js +107 -0
  98. package/dist/wallets/walletConnectors/chunk-DU6RCLWT.js +272 -0
  99. package/dist/wallets/walletConnectors/chunk-ENN6UGGA.js +421 -0
  100. package/dist/wallets/walletConnectors/chunk-EXWDLN5V.js +204 -0
  101. package/dist/wallets/walletConnectors/chunk-FFU26Y5Y.js +272 -0
  102. package/dist/wallets/walletConnectors/chunk-FGS2WHVA.js +118 -0
  103. package/dist/wallets/walletConnectors/chunk-FJJ3QI4R.js +91 -0
  104. package/dist/wallets/walletConnectors/chunk-FS2OOQYF.js +204 -0
  105. package/dist/wallets/walletConnectors/chunk-G5X3COSW.js +205 -0
  106. package/dist/wallets/walletConnectors/chunk-H53R4SFZ.js +204 -0
  107. package/dist/wallets/walletConnectors/chunk-J4QGDATF.js +71 -0
  108. package/dist/wallets/walletConnectors/chunk-JIJNCMJR.js +874 -0
  109. package/dist/wallets/walletConnectors/chunk-JSGZYU4A.js +52 -0
  110. package/dist/wallets/walletConnectors/chunk-JVT7R2GZ.js +771 -0
  111. package/dist/wallets/walletConnectors/chunk-K3JNN5UK.js +71 -0
  112. package/dist/wallets/walletConnectors/chunk-KBHPY3NA.js +302 -0
  113. package/dist/wallets/walletConnectors/chunk-KEX6WS23.js +640 -0
  114. package/dist/wallets/walletConnectors/chunk-KHYKVVR7.js +52 -0
  115. package/dist/wallets/walletConnectors/chunk-LOL7ZZ3S.js +302 -0
  116. package/dist/wallets/walletConnectors/chunk-LOSXI36Y.js +479 -0
  117. package/dist/wallets/walletConnectors/chunk-M2U5QGM7.js +260 -0
  118. package/dist/wallets/walletConnectors/chunk-M73AWLIV.js +107 -0
  119. package/dist/wallets/walletConnectors/chunk-MAUC46AE.js +302 -0
  120. package/dist/wallets/walletConnectors/chunk-MBRXYEQC.js +272 -0
  121. package/dist/wallets/walletConnectors/chunk-MDDD4LG2.js +874 -0
  122. package/dist/wallets/walletConnectors/chunk-MMR2QAEU.js +642 -0
  123. package/dist/wallets/walletConnectors/chunk-MNZZRFUC.js +302 -0
  124. package/dist/wallets/walletConnectors/chunk-OIRY24PH.js +302 -0
  125. package/dist/wallets/walletConnectors/chunk-ORBX4JE2.js +52 -0
  126. package/dist/wallets/walletConnectors/chunk-OXJFFDW7.js +761 -0
  127. package/dist/wallets/walletConnectors/chunk-QD3PPWTN.js +272 -0
  128. package/dist/wallets/walletConnectors/chunk-RCIABMG5.js +259 -0
  129. package/dist/wallets/walletConnectors/chunk-RHC4SVLB.js +71 -0
  130. package/dist/wallets/walletConnectors/chunk-S2CB4KFC.js +71 -0
  131. package/dist/wallets/walletConnectors/chunk-S6HZD4XZ.js +302 -0
  132. package/dist/wallets/walletConnectors/chunk-S72LCNVX.js +272 -0
  133. package/dist/wallets/walletConnectors/chunk-SCWE5EEX.js +91 -0
  134. package/dist/wallets/walletConnectors/chunk-TKEL4D4E.js +151 -0
  135. package/dist/wallets/walletConnectors/chunk-TKJEMEBZ.js +71 -0
  136. package/dist/wallets/walletConnectors/chunk-TZ44ZREA.js +302 -0
  137. package/dist/wallets/walletConnectors/chunk-UGQSI3US.js +547 -0
  138. package/dist/wallets/walletConnectors/chunk-UU4JYY3C.js +205 -0
  139. package/dist/wallets/walletConnectors/chunk-V5P5BL6Z.js +302 -0
  140. package/dist/wallets/walletConnectors/chunk-VH6DIRPF.js +71 -0
  141. package/dist/wallets/walletConnectors/chunk-VPNZAMW5.js +205 -0
  142. package/dist/wallets/walletConnectors/chunk-W6QN6QXO.js +52 -0
  143. package/dist/wallets/walletConnectors/chunk-WDULICVN.js +302 -0
  144. package/dist/wallets/walletConnectors/chunk-WGGHGODM.js +272 -0
  145. package/dist/wallets/walletConnectors/chunk-XUCMTLM3.js +52 -0
  146. package/dist/wallets/walletConnectors/chunk-Y5WAX6WO.js +52 -0
  147. package/dist/wallets/walletConnectors/chunk-Y62PFBWE.js +640 -0
  148. package/dist/wallets/walletConnectors/chunk-Z6ABK6G6.js +107 -0
  149. package/dist/wallets/walletConnectors/chunk-ZCA5QSIM.js +71 -0
  150. package/dist/wallets/walletConnectors/chunk-ZJDZJW55.js +479 -0
  151. package/dist/wallets/walletConnectors/chunk-ZOF7ZDGU.js +52 -0
  152. package/dist/wallets/walletConnectors/chunk-ZUU57RHO.js +36 -0
  153. package/dist/wallets/walletConnectors/chunk-ZWFGRREM.js +36 -0
  154. package/dist/wallets/walletConnectors/chunk-ZY5BCHP2.js +302 -0
  155. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  156. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  157. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  158. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  159. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  160. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  161. package/dist/wallets/walletConnectors/index.js +88 -88
  162. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  163. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  164. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  165. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  166. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  167. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  168. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  169. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  170. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  171. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  172. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  173. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  174. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  175. package/package.json +11 -12
@@ -0,0 +1,640 @@
1
+ "use client";
2
+ import {
3
+ getChainKey,
4
+ getNetworkName
5
+ } from "./chunk-7QHCSJDN.js";
6
+ import {
7
+ hexToNumber,
8
+ numberToHex
9
+ } from "./chunk-ZJDZJW55.js";
10
+
11
+ // src/wallets/walletConnectors/abcWallet/abcProvider.ts
12
+ import { getTalkenApiClient } from "@talken/talkenkit";
13
+ import { parseGwei } from "viem";
14
+ var EventEmitter = class {
15
+ constructor() {
16
+ this.events = /* @__PURE__ */ new Map();
17
+ }
18
+ on(event, listener) {
19
+ if (!this.events.has(event)) {
20
+ this.events.set(event, []);
21
+ }
22
+ this.events.get(event).push(listener);
23
+ return this;
24
+ }
25
+ off(event, listener) {
26
+ const listeners = this.events.get(event);
27
+ if (listeners) {
28
+ const index = listeners.indexOf(listener);
29
+ if (index !== -1) {
30
+ listeners.splice(index, 1);
31
+ }
32
+ }
33
+ return this;
34
+ }
35
+ removeListener(event, listener) {
36
+ return this.off(event, listener);
37
+ }
38
+ emit(event, ...args) {
39
+ const listeners = this.events.get(event);
40
+ if (listeners) {
41
+ for (const listener of listeners) {
42
+ listener(...args);
43
+ }
44
+ return true;
45
+ }
46
+ return false;
47
+ }
48
+ removeAllListeners(event) {
49
+ if (event) {
50
+ this.events.delete(event);
51
+ } else {
52
+ this.events.clear();
53
+ }
54
+ return this;
55
+ }
56
+ };
57
+ var ProviderRpcError = class extends Error {
58
+ constructor(code, message, data) {
59
+ super(message);
60
+ this.code = code;
61
+ this.data = data;
62
+ this.name = "ProviderRpcError";
63
+ }
64
+ };
65
+ var ErrorCode = {
66
+ USER_REJECTED: 4001,
67
+ UNAUTHORIZED: 4100,
68
+ UNSUPPORTED_METHOD: 4200,
69
+ DISCONNECTED: 4900,
70
+ CHAIN_DISCONNECTED: 4901,
71
+ INVALID_PARAMS: -32602,
72
+ INTERNAL_ERROR: -32603
73
+ };
74
+ var AbcEvmProvider = class extends EventEmitter {
75
+ constructor(client) {
76
+ super();
77
+ this.wallet = null;
78
+ this.chainId = 1;
79
+ // Default to Ethereum mainnet
80
+ this.connected = false;
81
+ this.client = client;
82
+ }
83
+ /**
84
+ * Set wallet information
85
+ */
86
+ setWallet(wallet) {
87
+ const previousAddress = this.wallet?.address;
88
+ const previousChainId = this.chainId;
89
+ this.wallet = wallet;
90
+ this.chainId = wallet.chainId;
91
+ this.connected = true;
92
+ if (previousAddress !== wallet.address) {
93
+ this.emit("accountsChanged", [wallet.address]);
94
+ }
95
+ if (previousChainId !== wallet.chainId) {
96
+ this.emit("chainChanged", numberToHex(wallet.chainId));
97
+ }
98
+ this.emit("connect", { chainId: numberToHex(wallet.chainId) });
99
+ }
100
+ /**
101
+ * Clear wallet (disconnect)
102
+ */
103
+ clearWallet() {
104
+ this.wallet = null;
105
+ this.connected = false;
106
+ this.emit("disconnect", {
107
+ code: ErrorCode.DISCONNECTED,
108
+ message: "User disconnected"
109
+ });
110
+ this.emit("accountsChanged", []);
111
+ }
112
+ /**
113
+ * Set request interceptor for sign confirmation
114
+ * The interceptor is called before signing operations to show confirmation UI
115
+ */
116
+ setRequestInterceptor(interceptor) {
117
+ this.requestInterceptor = interceptor;
118
+ }
119
+ /**
120
+ * Set TalkenApiClient for backend-proxied transaction flow
121
+ * When set, transaction methods will use a single API call instead of multi-step WaaS
122
+ */
123
+ setTalkenApi(talkenApi) {
124
+ this.talkenApi = talkenApi;
125
+ }
126
+ /**
127
+ * Call request interceptor if configured
128
+ * Called by specific signing/transaction methods that need user confirmation
129
+ * @returns Resolved transaction with user modifications if changed in confirmation modal
130
+ */
131
+ async callInterceptor(method, params) {
132
+ if (!this.requestInterceptor) {
133
+ return void 0;
134
+ }
135
+ const request = {
136
+ method,
137
+ params,
138
+ chainId: this.chainId,
139
+ address: this.wallet?.address || ""
140
+ };
141
+ return this.requestInterceptor(request);
142
+ }
143
+ /**
144
+ * EIP-1193 request method
145
+ */
146
+ async request(args) {
147
+ const { method, params } = args;
148
+ switch (method) {
149
+ case "eth_requestAccounts":
150
+ return this.eth_requestAccounts();
151
+ case "eth_accounts":
152
+ return this.eth_accounts();
153
+ case "eth_chainId":
154
+ return this.eth_chainId();
155
+ case "eth_sendTransaction":
156
+ case "wallet_sendTransaction":
157
+ return this.eth_sendTransaction(params);
158
+ case "eth_signTransaction":
159
+ return this.eth_signTransaction(params);
160
+ case "personal_sign":
161
+ return this.personal_sign(params);
162
+ case "eth_sign":
163
+ return this.eth_sign(params);
164
+ case "eth_signTypedData":
165
+ case "eth_signTypedData_v3":
166
+ case "eth_signTypedData_v4":
167
+ return this.eth_signTypedData(params);
168
+ case "wallet_getCapabilities":
169
+ return this.wallet_getCapabilities();
170
+ case "eth_signAuthorization":
171
+ return this.eth_signAuthorization(params);
172
+ case "wallet_switchEthereumChain":
173
+ return this.wallet_switchEthereumChain(params);
174
+ case "wallet_addEthereumChain":
175
+ return this.wallet_addEthereumChain(params);
176
+ case "eth_estimateGas":
177
+ return this.eth_estimateGas(params);
178
+ case "eth_getTransactionCount":
179
+ return this.eth_getTransactionCount(
180
+ Array.isArray(params) ? params : []
181
+ );
182
+ case "eth_blockNumber":
183
+ case "eth_call":
184
+ case "eth_gasPrice":
185
+ case "eth_getBalance":
186
+ case "eth_getBlockByHash":
187
+ case "eth_getBlockByNumber":
188
+ case "eth_getCode":
189
+ case "eth_getStorageAt":
190
+ case "eth_getTransactionByHash":
191
+ case "eth_getTransactionReceipt":
192
+ throw new ProviderRpcError(
193
+ ErrorCode.UNSUPPORTED_METHOD,
194
+ `Method ${method} should be handled by RPC provider`
195
+ );
196
+ default:
197
+ throw new ProviderRpcError(
198
+ ErrorCode.UNSUPPORTED_METHOD,
199
+ `Method ${method} not supported`
200
+ );
201
+ }
202
+ }
203
+ /**
204
+ * Request accounts (EIP-1193)
205
+ */
206
+ async eth_requestAccounts() {
207
+ if (!this.wallet) {
208
+ throw new ProviderRpcError(
209
+ ErrorCode.UNAUTHORIZED,
210
+ "Wallet not connected"
211
+ );
212
+ }
213
+ return [this.wallet.address];
214
+ }
215
+ /**
216
+ * Get accounts
217
+ */
218
+ async eth_accounts() {
219
+ if (!this.wallet) {
220
+ return [];
221
+ }
222
+ return [this.wallet.address];
223
+ }
224
+ /**
225
+ * Get chain ID
226
+ */
227
+ async eth_chainId() {
228
+ return numberToHex(this.chainId);
229
+ }
230
+ /**
231
+ * Send transaction
232
+ */
233
+ async eth_sendTransaction(params) {
234
+ if (!this.wallet) {
235
+ throw new ProviderRpcError(
236
+ ErrorCode.UNAUTHORIZED,
237
+ "Wallet not connected"
238
+ );
239
+ }
240
+ if (!Array.isArray(params) || params.length === 0) {
241
+ throw new ProviderRpcError(
242
+ ErrorCode.INVALID_PARAMS,
243
+ "Invalid transaction params"
244
+ );
245
+ }
246
+ const resolved = await this.callInterceptor("eth_sendTransaction", params);
247
+ const tx = params[0];
248
+ if (resolved) {
249
+ if (resolved.data) {
250
+ tx.data = resolved.data;
251
+ }
252
+ if (resolved.gasFee?.maxFeePerGas) {
253
+ try {
254
+ const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
255
+ tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
256
+ } catch (error) {
257
+ console.error(
258
+ "[AbcProvider] \u274C Failed to parse maxFeePerGas:",
259
+ error
260
+ );
261
+ }
262
+ }
263
+ if (resolved.gasFee?.maxPriorityFeePerGas) {
264
+ try {
265
+ const priorityFeeWei = parseGwei(
266
+ resolved.gasFee.maxPriorityFeePerGas
267
+ );
268
+ tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
269
+ } catch (error) {
270
+ console.error(
271
+ "[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
272
+ error
273
+ );
274
+ }
275
+ }
276
+ }
277
+ const isContractDeployment = !tx.to || tx.to === "0x" || tx.to === "0x0" || tx.to === "0x0000000000000000000000000000000000000000";
278
+ if (isContractDeployment) {
279
+ tx.to = "0x";
280
+ } else if (!tx.to) {
281
+ throw new ProviderRpcError(
282
+ ErrorCode.INVALID_PARAMS,
283
+ 'Transaction must have "to" field'
284
+ );
285
+ }
286
+ const pinHash = localStorage.getItem("talkenkit_abc_pin_hash");
287
+ if (!pinHash) {
288
+ throw new ProviderRpcError(
289
+ ErrorCode.INTERNAL_ERROR,
290
+ "PIN hash not found. Please login again."
291
+ );
292
+ }
293
+ const hexValue = tx.value || "0x0";
294
+ const amountWei = BigInt(hexValue).toString();
295
+ const api = this.talkenApi || getTalkenApiClient();
296
+ const result = await api.evm.sendTransaction({
297
+ chainKey: getChainKey(this.chainId),
298
+ to: tx.to,
299
+ amountWei,
300
+ pin: pinHash,
301
+ data: tx.data || "0x",
302
+ gasLimit: tx.gas || tx.gasLimit,
303
+ maxFeePerGas: tx.maxFeePerGas,
304
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas
305
+ });
306
+ return result.txHash;
307
+ }
308
+ /**
309
+ * Sign transaction (without sending)
310
+ */
311
+ async eth_signTransaction(params) {
312
+ if (!this.wallet) {
313
+ throw new ProviderRpcError(
314
+ ErrorCode.UNAUTHORIZED,
315
+ "Wallet not connected"
316
+ );
317
+ }
318
+ if (!Array.isArray(params) || params.length === 0) {
319
+ throw new ProviderRpcError(
320
+ ErrorCode.INVALID_PARAMS,
321
+ "Invalid transaction params"
322
+ );
323
+ }
324
+ const resolved = await this.callInterceptor("eth_signTransaction", params);
325
+ const tx = params[0];
326
+ if (resolved) {
327
+ if (resolved.data) {
328
+ tx.data = resolved.data;
329
+ }
330
+ if (resolved.gasFee?.maxFeePerGas) {
331
+ try {
332
+ const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
333
+ tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
334
+ } catch (error) {
335
+ console.error(
336
+ "[AbcProvider] \u274C Failed to parse maxFeePerGas:",
337
+ error
338
+ );
339
+ }
340
+ }
341
+ if (resolved.gasFee?.maxPriorityFeePerGas) {
342
+ try {
343
+ const priorityFeeWei = parseGwei(
344
+ resolved.gasFee.maxPriorityFeePerGas
345
+ );
346
+ tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
347
+ } catch (error) {
348
+ console.error(
349
+ "[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
350
+ error
351
+ );
352
+ }
353
+ }
354
+ }
355
+ const api = this.talkenApi || getTalkenApiClient();
356
+ const result = await api.evm.signTransaction({
357
+ network: getNetworkName(this.chainId),
358
+ to: tx.to,
359
+ value: tx.value || "0x0",
360
+ data: tx.data || "0x",
361
+ gasLimit: tx.gas || tx.gasLimit,
362
+ maxFeePerGas: tx.maxFeePerGas,
363
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
364
+ nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0
365
+ });
366
+ return result.signature;
367
+ }
368
+ /**
369
+ * Personal sign (EIP-191)
370
+ */
371
+ async personal_sign(params) {
372
+ if (!this.wallet) {
373
+ console.error("[AbcProvider] \u274C Wallet not connected");
374
+ throw new ProviderRpcError(
375
+ ErrorCode.UNAUTHORIZED,
376
+ "Wallet not connected"
377
+ );
378
+ }
379
+ if (!Array.isArray(params) || params.length < 2) {
380
+ console.error("[AbcProvider] \u274C Invalid params:", params);
381
+ throw new ProviderRpcError(
382
+ ErrorCode.INVALID_PARAMS,
383
+ "Invalid personal_sign params"
384
+ );
385
+ }
386
+ await this.callInterceptor("personal_sign", params);
387
+ const [message, address] = params;
388
+ if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
389
+ console.error("[AbcProvider] \u274C Address mismatch");
390
+ throw new ProviderRpcError(
391
+ ErrorCode.INVALID_PARAMS,
392
+ "Address does not match connected wallet"
393
+ );
394
+ }
395
+ const api = this.talkenApi || getTalkenApiClient();
396
+ const network = getNetworkName(this.chainId);
397
+ const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
398
+ const result = await api.evm.signPersonal({
399
+ network,
400
+ message,
401
+ address,
402
+ pin: pinHash
403
+ });
404
+ return result.signature;
405
+ }
406
+ /**
407
+ * Eth sign
408
+ */
409
+ async eth_sign(params) {
410
+ if (!Array.isArray(params) || params.length < 2) {
411
+ throw new ProviderRpcError(
412
+ ErrorCode.INVALID_PARAMS,
413
+ "Invalid eth_sign params"
414
+ );
415
+ }
416
+ const [address, message] = params;
417
+ return this.personal_sign([message, address]);
418
+ }
419
+ /**
420
+ * Sign typed data (EIP-712)
421
+ */
422
+ async eth_signTypedData(params) {
423
+ if (!this.wallet) {
424
+ throw new ProviderRpcError(
425
+ ErrorCode.UNAUTHORIZED,
426
+ "Wallet not connected"
427
+ );
428
+ }
429
+ if (!Array.isArray(params) || params.length < 2) {
430
+ throw new ProviderRpcError(
431
+ ErrorCode.INVALID_PARAMS,
432
+ "Invalid signTypedData params"
433
+ );
434
+ }
435
+ await this.callInterceptor("eth_signTypedData_v4", params);
436
+ const [address, typedData] = params;
437
+ if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
438
+ throw new ProviderRpcError(
439
+ ErrorCode.INVALID_PARAMS,
440
+ "Address does not match connected wallet"
441
+ );
442
+ }
443
+ const api = this.talkenApi || getTalkenApiClient();
444
+ const network = getNetworkName(this.chainId);
445
+ const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
446
+ const result = await api.evm.signTypedData({
447
+ network,
448
+ typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
449
+ pin: pinHash
450
+ });
451
+ return result.signature;
452
+ }
453
+ /**
454
+ * Return normalized wallet capabilities for ABC embedded wallets.
455
+ * ABC supports EIP-7702 authorization signing via talken-api.
456
+ */
457
+ async wallet_getCapabilities() {
458
+ return {
459
+ supportsTypedDataV4: true,
460
+ supports7702Authorization: true,
461
+ supports5792Batch: false,
462
+ supportsPaymasterService: false,
463
+ supportsPermit2RelayHints: true,
464
+ walletType: "abc-embedded"
465
+ };
466
+ }
467
+ /**
468
+ * Sign EIP-7702 authorization via Talken API.
469
+ */
470
+ async eth_signAuthorization(params) {
471
+ if (!this.wallet) {
472
+ throw new ProviderRpcError(
473
+ ErrorCode.UNAUTHORIZED,
474
+ "Wallet not connected"
475
+ );
476
+ }
477
+ if (!Array.isArray(params) || params.length < 2) {
478
+ throw new ProviderRpcError(
479
+ ErrorCode.INVALID_PARAMS,
480
+ "Invalid signAuthorization params"
481
+ );
482
+ }
483
+ const [address, authorization] = params;
484
+ if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
485
+ throw new ProviderRpcError(
486
+ ErrorCode.INVALID_PARAMS,
487
+ "Address does not match connected wallet"
488
+ );
489
+ }
490
+ if (!authorization?.address || authorization.chainId == null || authorization.nonce == null) {
491
+ throw new ProviderRpcError(
492
+ ErrorCode.INVALID_PARAMS,
493
+ "Authorization payload is incomplete"
494
+ );
495
+ }
496
+ const api = this.talkenApi || getTalkenApiClient();
497
+ const network = getNetworkName(this.chainId);
498
+ const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
499
+ const chainIdValue = typeof authorization.chainId === "string" ? Number(BigInt(authorization.chainId)) : Number(authorization.chainId);
500
+ const nonceValue = typeof authorization.nonce === "string" ? BigInt(authorization.nonce).toString() : String(authorization.nonce);
501
+ const result = await api.evm.signAuthorization({
502
+ network,
503
+ authorization: {
504
+ chainId: chainIdValue,
505
+ address: authorization.address,
506
+ nonce: nonceValue
507
+ },
508
+ pin: pinHash
509
+ });
510
+ return result.authorization;
511
+ }
512
+ /**
513
+ * Switch Ethereum chain
514
+ */
515
+ async wallet_switchEthereumChain(params) {
516
+ if (!Array.isArray(params) || params.length === 0) {
517
+ throw new ProviderRpcError(
518
+ ErrorCode.INVALID_PARAMS,
519
+ "Invalid switchEthereumChain params"
520
+ );
521
+ }
522
+ const { chainId } = params[0];
523
+ const newChainId = hexToNumber(chainId);
524
+ if (this.chainId === newChainId) {
525
+ return null;
526
+ }
527
+ const _previousChainId = this.chainId;
528
+ this.chainId = newChainId;
529
+ if (this.wallet) {
530
+ this.wallet.chainId = newChainId;
531
+ }
532
+ this.emit("chainChanged", numberToHex(newChainId));
533
+ return null;
534
+ }
535
+ /**
536
+ * Add Ethereum chain
537
+ */
538
+ async wallet_addEthereumChain(params) {
539
+ return this.wallet_switchEthereumChain(params);
540
+ }
541
+ /**
542
+ * Get transaction count (nonce) using ABC WaaS API
543
+ */
544
+ async eth_getTransactionCount(params) {
545
+ const address = params[0]?.toLowerCase();
546
+ if (!address) {
547
+ throw new ProviderRpcError(
548
+ ErrorCode.INVALID_PARAMS,
549
+ "Missing address parameter"
550
+ );
551
+ }
552
+ const currentChainId = this.chainId;
553
+ try {
554
+ const nonce = await this.client.getTransactionCount({
555
+ chainId: currentChainId,
556
+ address
557
+ });
558
+ return nonce;
559
+ } catch (error) {
560
+ console.error(
561
+ "[AbcEvmProvider] \u274C Failed to get transaction count from ABC WaaS:",
562
+ error
563
+ );
564
+ throw new ProviderRpcError(
565
+ ErrorCode.INTERNAL_ERROR,
566
+ `Failed to get transaction count: ${error instanceof Error ? error.message : String(error)}`
567
+ );
568
+ }
569
+ }
570
+ /**
571
+ * Estimate gas for transaction
572
+ * Uses ABC WaaS gas estimation API with fallback
573
+ */
574
+ async eth_estimateGas(params) {
575
+ if (!Array.isArray(params) || params.length === 0) {
576
+ throw new ProviderRpcError(
577
+ ErrorCode.INVALID_PARAMS,
578
+ "Invalid estimateGas params"
579
+ );
580
+ }
581
+ const tx = params[0];
582
+ if (!tx.to) {
583
+ throw new ProviderRpcError(
584
+ ErrorCode.INVALID_PARAMS,
585
+ 'Transaction must have "to" field'
586
+ );
587
+ }
588
+ try {
589
+ const gasLimit = await this.client.estimateGas({
590
+ chainId: this.chainId,
591
+ from: tx.from || this.wallet?.address,
592
+ to: tx.to,
593
+ value: tx.value,
594
+ data: tx.data
595
+ });
596
+ return gasLimit;
597
+ } catch (error) {
598
+ console.warn(
599
+ "[AbcEvmProvider] Gas estimation failed, using fallback:",
600
+ error
601
+ );
602
+ if (tx.data && tx.data !== "0x") {
603
+ return "0x493e0";
604
+ }
605
+ return "0x5208";
606
+ }
607
+ }
608
+ /**
609
+ * Check if connected
610
+ */
611
+ isConnected() {
612
+ return this.connected;
613
+ }
614
+ /**
615
+ * Get current wallet
616
+ */
617
+ getWallet() {
618
+ return this.wallet;
619
+ }
620
+ /**
621
+ * Get current chain ID
622
+ */
623
+ getChainId() {
624
+ return this.chainId;
625
+ }
626
+ };
627
+ function createAbcEvmProvider(client, talkenApi) {
628
+ const provider = new AbcEvmProvider(client);
629
+ if (talkenApi) {
630
+ provider.setTalkenApi(talkenApi);
631
+ }
632
+ return provider;
633
+ }
634
+ var createAbcProvider = createAbcEvmProvider;
635
+
636
+ export {
637
+ AbcEvmProvider,
638
+ createAbcEvmProvider,
639
+ createAbcProvider
640
+ };