@talken/talkenkit 2.4.11 → 2.4.13

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 (58) hide show
  1. package/dist/abcWallet-4Y7KXZBE.js +184 -0
  2. package/dist/abcWallet-DRHY5BUW.js +184 -0
  3. package/dist/abcWallet-KPGRZYCP.js +184 -0
  4. package/dist/abcWallet-NTVWBYWF.js +184 -0
  5. package/dist/abcWallet-S7EO644R.js +184 -0
  6. package/dist/abcWallet-YOPLVWVE.js +184 -0
  7. package/dist/chunk-5NAGRWKN.js +6991 -0
  8. package/dist/chunk-GG57EUYL.js +7132 -0
  9. package/dist/chunk-KZZG24U5.js +7015 -0
  10. package/dist/chunk-MLJXZ6R2.js +7130 -0
  11. package/dist/chunk-NWF5NI55.js +7130 -0
  12. package/dist/chunk-ZRBHEE5W.js +7130 -0
  13. package/dist/index.js +44 -8
  14. package/dist/wallets/walletConnectors/abcWallet/abcApi.d.ts +19 -0
  15. package/dist/wallets/walletConnectors/abcWallet/abcApi.js +1 -1
  16. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +3 -3
  17. package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +9 -0
  18. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +1 -1
  19. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +1 -1
  20. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +4 -4
  21. package/dist/wallets/walletConnectors/abcWallet/index.js +4 -4
  22. package/dist/wallets/walletConnectors/chunk-2KHZAE46.js +47 -0
  23. package/dist/wallets/walletConnectors/chunk-2NHQTZGS.js +276 -0
  24. package/dist/wallets/walletConnectors/chunk-4Q7XTNTE.js +63 -0
  25. package/dist/wallets/walletConnectors/chunk-4SCX34NL.js +276 -0
  26. package/dist/wallets/walletConnectors/chunk-6KJQ2GQZ.js +47 -0
  27. package/dist/wallets/walletConnectors/chunk-B6GPEHW7.js +47 -0
  28. package/dist/wallets/walletConnectors/chunk-CZ7WCJW5.js +63 -0
  29. package/dist/wallets/walletConnectors/chunk-DNSC37SU.js +47 -0
  30. package/dist/wallets/walletConnectors/chunk-EN5R4RRF.js +47 -0
  31. package/dist/wallets/walletConnectors/chunk-FCRLSDVW.js +513 -0
  32. package/dist/wallets/walletConnectors/chunk-FLCBPO5T.js +276 -0
  33. package/dist/wallets/walletConnectors/chunk-HIRSPIIU.js +1760 -0
  34. package/dist/wallets/walletConnectors/chunk-JKDAQWPW.js +47 -0
  35. package/dist/wallets/walletConnectors/chunk-JW3YCANT.js +464 -0
  36. package/dist/wallets/walletConnectors/chunk-K42FR6F7.js +513 -0
  37. package/dist/wallets/walletConnectors/chunk-K7WCM7JL.js +513 -0
  38. package/dist/wallets/walletConnectors/chunk-L2ICV2P2.js +276 -0
  39. package/dist/wallets/walletConnectors/chunk-LVODOLXE.js +47 -0
  40. package/dist/wallets/walletConnectors/chunk-MOQSXFIP.js +47 -0
  41. package/dist/wallets/walletConnectors/chunk-MSK4NN2E.js +47 -0
  42. package/dist/wallets/walletConnectors/chunk-NY2MBDVO.js +276 -0
  43. package/dist/wallets/walletConnectors/chunk-PE6CXY5F.js +513 -0
  44. package/dist/wallets/walletConnectors/chunk-PPTSQD3J.js +276 -0
  45. package/dist/wallets/walletConnectors/chunk-PQDQUIIL.js +276 -0
  46. package/dist/wallets/walletConnectors/chunk-QOZL4BMA.js +513 -0
  47. package/dist/wallets/walletConnectors/chunk-RWJX5CRR.js +276 -0
  48. package/dist/wallets/walletConnectors/chunk-S6LSALLS.js +47 -0
  49. package/dist/wallets/walletConnectors/chunk-UTRMKLD5.js +1683 -0
  50. package/dist/wallets/walletConnectors/chunk-UX4IUIRD.js +515 -0
  51. package/dist/wallets/walletConnectors/chunk-UYFNIOUH.js +475 -0
  52. package/dist/wallets/walletConnectors/chunk-VDVBAWB4.js +1670 -0
  53. package/dist/wallets/walletConnectors/chunk-WCHG2Q2N.js +276 -0
  54. package/dist/wallets/walletConnectors/chunk-XKNVF62K.js +276 -0
  55. package/dist/wallets/walletConnectors/chunk-Z2IWGNDA.js +515 -0
  56. package/dist/wallets/walletConnectors/chunk-Z34L5C76.js +1760 -0
  57. package/dist/wallets/walletConnectors/index.js +49 -49
  58. package/package.json +1 -1
@@ -0,0 +1,513 @@
1
+ "use client";
2
+ import {
3
+ hexToNumber,
4
+ numberToHex
5
+ } from "./chunk-5RSS3SRV.js";
6
+
7
+ // src/wallets/walletConnectors/abcWallet/abcProvider.ts
8
+ var EventEmitter = class {
9
+ constructor() {
10
+ this.events = /* @__PURE__ */ new Map();
11
+ }
12
+ on(event, listener) {
13
+ if (!this.events.has(event)) {
14
+ this.events.set(event, []);
15
+ }
16
+ this.events.get(event).push(listener);
17
+ return this;
18
+ }
19
+ off(event, listener) {
20
+ const listeners = this.events.get(event);
21
+ if (listeners) {
22
+ const index = listeners.indexOf(listener);
23
+ if (index !== -1) {
24
+ listeners.splice(index, 1);
25
+ }
26
+ }
27
+ return this;
28
+ }
29
+ removeListener(event, listener) {
30
+ return this.off(event, listener);
31
+ }
32
+ emit(event, ...args) {
33
+ const listeners = this.events.get(event);
34
+ if (listeners) {
35
+ for (const listener of listeners) {
36
+ listener(...args);
37
+ }
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ removeAllListeners(event) {
43
+ if (event) {
44
+ this.events.delete(event);
45
+ } else {
46
+ this.events.clear();
47
+ }
48
+ return this;
49
+ }
50
+ };
51
+ var ProviderRpcError = class extends Error {
52
+ constructor(code, message, data) {
53
+ super(message);
54
+ this.code = code;
55
+ this.data = data;
56
+ this.name = "ProviderRpcError";
57
+ }
58
+ };
59
+ var ErrorCode = {
60
+ USER_REJECTED: 4001,
61
+ UNAUTHORIZED: 4100,
62
+ UNSUPPORTED_METHOD: 4200,
63
+ DISCONNECTED: 4900,
64
+ CHAIN_DISCONNECTED: 4901,
65
+ INVALID_PARAMS: -32602,
66
+ INTERNAL_ERROR: -32603
67
+ };
68
+ var AbcEvmProvider = class extends EventEmitter {
69
+ constructor(client) {
70
+ super();
71
+ this.wallet = null;
72
+ this.chainId = 1;
73
+ // Default to Ethereum mainnet
74
+ this.connected = false;
75
+ this.client = client;
76
+ }
77
+ /**
78
+ * Set wallet information
79
+ */
80
+ setWallet(wallet) {
81
+ const previousAddress = this.wallet?.address;
82
+ const previousChainId = this.chainId;
83
+ this.wallet = wallet;
84
+ this.chainId = wallet.chainId;
85
+ this.connected = true;
86
+ if (previousAddress !== wallet.address) {
87
+ this.emit("accountsChanged", [wallet.address]);
88
+ }
89
+ if (previousChainId !== wallet.chainId) {
90
+ this.emit("chainChanged", numberToHex(wallet.chainId));
91
+ }
92
+ this.emit("connect", { chainId: numberToHex(wallet.chainId) });
93
+ }
94
+ /**
95
+ * Clear wallet (disconnect)
96
+ */
97
+ clearWallet() {
98
+ this.wallet = null;
99
+ this.connected = false;
100
+ this.emit("disconnect", {
101
+ code: ErrorCode.DISCONNECTED,
102
+ message: "User disconnected"
103
+ });
104
+ this.emit("accountsChanged", []);
105
+ }
106
+ /**
107
+ * Set PIN request callback
108
+ */
109
+ setRequestPinCallback(callback) {
110
+ this.requestPinCallback = callback;
111
+ }
112
+ /**
113
+ * Request PIN from user
114
+ */
115
+ async requestPin() {
116
+ if (!this.requestPinCallback) {
117
+ throw new ProviderRpcError(
118
+ ErrorCode.INTERNAL_ERROR,
119
+ "PIN request callback not configured"
120
+ );
121
+ }
122
+ return this.requestPinCallback();
123
+ }
124
+ /**
125
+ * EIP-1193 request method
126
+ */
127
+ async request(args) {
128
+ const { method, params } = args;
129
+ switch (method) {
130
+ case "eth_requestAccounts":
131
+ return this.eth_requestAccounts();
132
+ case "eth_accounts":
133
+ return this.eth_accounts();
134
+ case "eth_chainId":
135
+ return this.eth_chainId();
136
+ case "eth_sendTransaction":
137
+ case "wallet_sendTransaction":
138
+ return this.eth_sendTransaction(params);
139
+ case "eth_signTransaction":
140
+ return this.eth_signTransaction(params);
141
+ case "personal_sign":
142
+ return this.personal_sign(params);
143
+ case "eth_sign":
144
+ return this.eth_sign(params);
145
+ case "eth_signTypedData":
146
+ case "eth_signTypedData_v3":
147
+ case "eth_signTypedData_v4":
148
+ return this.eth_signTypedData(params);
149
+ case "wallet_switchEthereumChain":
150
+ return this.wallet_switchEthereumChain(params);
151
+ case "wallet_addEthereumChain":
152
+ return this.wallet_addEthereumChain(params);
153
+ case "eth_estimateGas":
154
+ return this.eth_estimateGas(params);
155
+ case "eth_getTransactionCount":
156
+ return this.eth_getTransactionCount(Array.isArray(params) ? params : []);
157
+ case "eth_blockNumber":
158
+ case "eth_call":
159
+ case "eth_gasPrice":
160
+ case "eth_getBalance":
161
+ case "eth_getBlockByHash":
162
+ case "eth_getBlockByNumber":
163
+ case "eth_getCode":
164
+ case "eth_getStorageAt":
165
+ case "eth_getTransactionByHash":
166
+ case "eth_getTransactionReceipt":
167
+ throw new ProviderRpcError(
168
+ ErrorCode.UNSUPPORTED_METHOD,
169
+ `Method ${method} should be handled by RPC provider`
170
+ );
171
+ default:
172
+ throw new ProviderRpcError(
173
+ ErrorCode.UNSUPPORTED_METHOD,
174
+ `Method ${method} not supported`
175
+ );
176
+ }
177
+ }
178
+ /**
179
+ * Request accounts (EIP-1193)
180
+ */
181
+ async eth_requestAccounts() {
182
+ if (!this.wallet) {
183
+ throw new ProviderRpcError(
184
+ ErrorCode.UNAUTHORIZED,
185
+ "Wallet not connected"
186
+ );
187
+ }
188
+ return [this.wallet.address];
189
+ }
190
+ /**
191
+ * Get accounts
192
+ */
193
+ async eth_accounts() {
194
+ if (!this.wallet) {
195
+ return [];
196
+ }
197
+ return [this.wallet.address];
198
+ }
199
+ /**
200
+ * Get chain ID
201
+ */
202
+ async eth_chainId() {
203
+ return numberToHex(this.chainId);
204
+ }
205
+ /**
206
+ * Send transaction
207
+ */
208
+ async eth_sendTransaction(params) {
209
+ if (!this.wallet) {
210
+ throw new ProviderRpcError(
211
+ ErrorCode.UNAUTHORIZED,
212
+ "Wallet not connected"
213
+ );
214
+ }
215
+ if (!Array.isArray(params) || params.length === 0) {
216
+ throw new ProviderRpcError(
217
+ ErrorCode.INVALID_PARAMS,
218
+ "Invalid transaction params"
219
+ );
220
+ }
221
+ const tx = params[0];
222
+ const isContractDeployment = !tx.to || tx.to === "0x" || tx.to === "0x0" || tx.to === "0x0000000000000000000000000000000000000000";
223
+ if (isContractDeployment) {
224
+ tx.to = "0x";
225
+ } else if (!tx.to) {
226
+ throw new ProviderRpcError(
227
+ ErrorCode.INVALID_PARAMS,
228
+ 'Transaction must have "to" field'
229
+ );
230
+ }
231
+ const pin = await this.requestPin();
232
+ const signParams = {
233
+ chainId: this.chainId,
234
+ transaction: tx,
235
+ keyId: this.wallet.keyId,
236
+ encryptedShare: this.wallet.encryptedShare,
237
+ pin
238
+ };
239
+ const signResult = await this.client.signTransaction(signParams);
240
+ if (!signResult.signature) {
241
+ throw new ProviderRpcError(
242
+ ErrorCode.INTERNAL_ERROR,
243
+ "Failed to get signed transaction from ABC WaaS"
244
+ );
245
+ }
246
+ const sendResult = await this.client.sendRawTransaction(
247
+ this.chainId,
248
+ signResult.signature
249
+ // serializedTx
250
+ );
251
+ return sendResult.txHash;
252
+ }
253
+ /**
254
+ * Sign transaction (without sending)
255
+ */
256
+ async eth_signTransaction(params) {
257
+ if (!this.wallet) {
258
+ throw new ProviderRpcError(
259
+ ErrorCode.UNAUTHORIZED,
260
+ "Wallet not connected"
261
+ );
262
+ }
263
+ if (!Array.isArray(params) || params.length === 0) {
264
+ throw new ProviderRpcError(
265
+ ErrorCode.INVALID_PARAMS,
266
+ "Invalid transaction params"
267
+ );
268
+ }
269
+ const tx = params[0];
270
+ const pin = await this.requestPin();
271
+ const signParams = {
272
+ chainId: this.chainId,
273
+ transaction: tx,
274
+ keyId: this.wallet.keyId,
275
+ encryptedShare: this.wallet.encryptedShare,
276
+ pin
277
+ };
278
+ const result = await this.client.signTransaction(signParams);
279
+ return result.signature;
280
+ }
281
+ /**
282
+ * Personal sign (EIP-191)
283
+ */
284
+ async personal_sign(params) {
285
+ if (!this.wallet) {
286
+ console.error("[AbcProvider] \u274C Wallet not connected");
287
+ throw new ProviderRpcError(
288
+ ErrorCode.UNAUTHORIZED,
289
+ "Wallet not connected"
290
+ );
291
+ }
292
+ if (!Array.isArray(params) || params.length < 2) {
293
+ console.error("[AbcProvider] \u274C Invalid params:", params);
294
+ throw new ProviderRpcError(
295
+ ErrorCode.INVALID_PARAMS,
296
+ "Invalid personal_sign params"
297
+ );
298
+ }
299
+ const [message, address] = params;
300
+ if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
301
+ console.error("[AbcProvider] \u274C Address mismatch");
302
+ throw new ProviderRpcError(
303
+ ErrorCode.INVALID_PARAMS,
304
+ "Address does not match connected wallet"
305
+ );
306
+ }
307
+ if (!this.wallet.sid) {
308
+ console.error("[AbcProvider] \u274C Missing sid");
309
+ throw new ProviderRpcError(
310
+ ErrorCode.INTERNAL_ERROR,
311
+ "Wallet session ID (sid) is missing - please reconnect wallet"
312
+ );
313
+ }
314
+ if (!this.wallet.pvencstr) {
315
+ console.error("[AbcProvider] \u274C Missing pvencstr");
316
+ throw new ProviderRpcError(
317
+ ErrorCode.INTERNAL_ERROR,
318
+ "Wallet pvencstr is missing - please reconnect wallet"
319
+ );
320
+ }
321
+ if (!this.wallet.wid) {
322
+ console.error("[AbcProvider] \u274C Missing wid");
323
+ throw new ProviderRpcError(
324
+ ErrorCode.INTERNAL_ERROR,
325
+ "Wallet wid is missing - please reconnect wallet"
326
+ );
327
+ }
328
+ const result = await this.client.signMessage({
329
+ message,
330
+ address: this.wallet.address,
331
+ // ciphertext removed - not needed for message signing
332
+ sid: this.wallet.sid,
333
+ uid: this.wallet.uid,
334
+ pvencstr: this.wallet.pvencstr,
335
+ wid: this.wallet.wid
336
+ });
337
+ return result.signature;
338
+ }
339
+ /**
340
+ * Eth sign
341
+ */
342
+ async eth_sign(params) {
343
+ if (!Array.isArray(params) || params.length < 2) {
344
+ throw new ProviderRpcError(
345
+ ErrorCode.INVALID_PARAMS,
346
+ "Invalid eth_sign params"
347
+ );
348
+ }
349
+ const [address, message] = params;
350
+ return this.personal_sign([message, address]);
351
+ }
352
+ /**
353
+ * Sign typed data (EIP-712)
354
+ */
355
+ async eth_signTypedData(params) {
356
+ if (!this.wallet) {
357
+ throw new ProviderRpcError(
358
+ ErrorCode.UNAUTHORIZED,
359
+ "Wallet not connected"
360
+ );
361
+ }
362
+ if (!Array.isArray(params) || params.length < 2) {
363
+ throw new ProviderRpcError(
364
+ ErrorCode.INVALID_PARAMS,
365
+ "Invalid signTypedData params"
366
+ );
367
+ }
368
+ const [address, typedData] = params;
369
+ if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
370
+ throw new ProviderRpcError(
371
+ ErrorCode.INVALID_PARAMS,
372
+ "Address does not match connected wallet"
373
+ );
374
+ }
375
+ const result = await this.client.signTypedData({
376
+ typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData)
377
+ // ciphertext removed - not needed for typed data signing
378
+ });
379
+ return result.signature;
380
+ }
381
+ /**
382
+ * Switch Ethereum chain
383
+ */
384
+ async wallet_switchEthereumChain(params) {
385
+ if (!Array.isArray(params) || params.length === 0) {
386
+ throw new ProviderRpcError(
387
+ ErrorCode.INVALID_PARAMS,
388
+ "Invalid switchEthereumChain params"
389
+ );
390
+ }
391
+ const { chainId } = params[0];
392
+ const newChainId = hexToNumber(chainId);
393
+ if (this.chainId === newChainId) {
394
+ return null;
395
+ }
396
+ const _previousChainId = this.chainId;
397
+ this.chainId = newChainId;
398
+ if (this.wallet) {
399
+ this.wallet.chainId = newChainId;
400
+ }
401
+ this.emit("chainChanged", numberToHex(newChainId));
402
+ return null;
403
+ }
404
+ /**
405
+ * Add Ethereum chain
406
+ */
407
+ async wallet_addEthereumChain(params) {
408
+ return this.wallet_switchEthereumChain(params);
409
+ }
410
+ /**
411
+ * Get transaction count (nonce) using ABC WaaS API
412
+ */
413
+ async eth_getTransactionCount(params) {
414
+ console.log("[AbcEvmProvider] \u{1F4CA} Getting transaction count for ABC Wallet");
415
+ const address = params[0]?.toLowerCase();
416
+ if (!address) {
417
+ throw new ProviderRpcError(
418
+ ErrorCode.INVALID_PARAMS,
419
+ "Missing address parameter"
420
+ );
421
+ }
422
+ const currentChainId = this.chainId;
423
+ console.log("[AbcEvmProvider] Transaction count for:", {
424
+ address,
425
+ chainId: currentChainId
426
+ });
427
+ try {
428
+ const nonce = await this.client.getTransactionCount({
429
+ chainId: currentChainId,
430
+ address
431
+ });
432
+ console.log(
433
+ `[AbcEvmProvider] \u2705 Transaction count from ABC WaaS: ${nonce}`
434
+ );
435
+ return nonce;
436
+ } catch (error) {
437
+ console.error(
438
+ "[AbcEvmProvider] \u274C Failed to get transaction count from ABC WaaS:",
439
+ error
440
+ );
441
+ throw new ProviderRpcError(
442
+ ErrorCode.INTERNAL_ERROR,
443
+ `Failed to get transaction count: ${error instanceof Error ? error.message : String(error)}`
444
+ );
445
+ }
446
+ }
447
+ /**
448
+ * Estimate gas for transaction
449
+ * Uses ABC WaaS gas estimation API with fallback
450
+ */
451
+ async eth_estimateGas(params) {
452
+ if (!Array.isArray(params) || params.length === 0) {
453
+ throw new ProviderRpcError(
454
+ ErrorCode.INVALID_PARAMS,
455
+ "Invalid estimateGas params"
456
+ );
457
+ }
458
+ const tx = params[0];
459
+ if (!tx.to) {
460
+ throw new ProviderRpcError(
461
+ ErrorCode.INVALID_PARAMS,
462
+ 'Transaction must have "to" field'
463
+ );
464
+ }
465
+ try {
466
+ const gasLimit = await this.client.estimateGas({
467
+ chainId: this.chainId,
468
+ from: tx.from || this.wallet?.address,
469
+ to: tx.to,
470
+ value: tx.value,
471
+ data: tx.data
472
+ });
473
+ return gasLimit;
474
+ } catch (error) {
475
+ console.warn(
476
+ "[AbcEvmProvider] Gas estimation failed, using fallback:",
477
+ error
478
+ );
479
+ if (tx.data && tx.data !== "0x") {
480
+ return "0x493e0";
481
+ }
482
+ return "0x5208";
483
+ }
484
+ }
485
+ /**
486
+ * Check if connected
487
+ */
488
+ isConnected() {
489
+ return this.connected;
490
+ }
491
+ /**
492
+ * Get current wallet
493
+ */
494
+ getWallet() {
495
+ return this.wallet;
496
+ }
497
+ /**
498
+ * Get current chain ID
499
+ */
500
+ getChainId() {
501
+ return this.chainId;
502
+ }
503
+ };
504
+ function createAbcEvmProvider(client) {
505
+ return new AbcEvmProvider(client);
506
+ }
507
+ var createAbcProvider = createAbcEvmProvider;
508
+
509
+ export {
510
+ AbcEvmProvider,
511
+ createAbcEvmProvider,
512
+ createAbcProvider
513
+ };