@talken/talkenkit 2.4.26 → 2.4.29

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 (55) hide show
  1. package/dist/abcWallet-TLGPQAMU.js +161 -0
  2. package/dist/chunk-MI7TNBED.js +5458 -0
  3. package/dist/hooks/useEstimateFee.d.ts +21 -0
  4. package/dist/hooks/useProfile.d.ts +1 -1
  5. package/dist/index.css +9 -1
  6. package/dist/index.d.ts +2 -1
  7. package/dist/index.js +113 -220
  8. package/dist/services/AbcAuthService.d.ts +0 -3
  9. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
  10. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +2 -2
  11. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +3 -3
  12. package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +1 -1
  13. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -1
  14. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +3 -3
  15. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +1 -1
  16. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +1 -0
  17. package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +3 -1
  18. package/dist/wallets/walletConnectors/abcWallet/api/index.js +4 -4
  19. package/dist/wallets/walletConnectors/abcWallet/index.js +8 -8
  20. package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
  21. package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
  22. package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
  23. package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
  24. package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
  25. package/dist/wallets/walletConnectors/chunk-3LF7FVL6.js +595 -0
  26. package/dist/wallets/walletConnectors/chunk-5RDUTGDR.js +54 -0
  27. package/dist/wallets/walletConnectors/chunk-6HBDJDNH.js +300 -0
  28. package/dist/wallets/walletConnectors/chunk-BHEVY4QY.js +827 -0
  29. package/dist/wallets/walletConnectors/chunk-FBJ5H6PM.js +300 -0
  30. package/dist/wallets/walletConnectors/chunk-IN3HEGZM.js +446 -0
  31. package/dist/wallets/walletConnectors/chunk-J3YPHDHM.js +827 -0
  32. package/dist/wallets/walletConnectors/chunk-NULM3THX.js +241 -0
  33. package/dist/wallets/walletConnectors/chunk-UPYPPBXD.js +1485 -0
  34. package/dist/wallets/walletConnectors/chunk-VMCIDCO5.js +54 -0
  35. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  36. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  37. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  38. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  39. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  40. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  41. package/dist/wallets/walletConnectors/index.js +75 -75
  42. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  43. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  44. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  45. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  46. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  47. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  48. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  49. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  50. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  51. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  52. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  53. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  54. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  55. package/package.json +1 -1
@@ -0,0 +1,446 @@
1
+ "use client";
2
+ import {
3
+ WalletscanApi
4
+ } from "./chunk-NULM3THX.js";
5
+ import {
6
+ getCredentialManager
7
+ } from "./chunk-6WF4SXLB.js";
8
+
9
+ // src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
10
+ import { getTalkenApiClient } from "@talken/talkenkit";
11
+
12
+ // src/utils/apiClientFactory.ts
13
+ function createWalletscanApi() {
14
+ return new WalletscanApi();
15
+ }
16
+
17
+ // src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
18
+ var EventEmitter = class {
19
+ constructor() {
20
+ this.events = /* @__PURE__ */ new Map();
21
+ }
22
+ on(event, listener) {
23
+ if (!this.events.has(event)) {
24
+ this.events.set(event, []);
25
+ }
26
+ this.events.get(event).push(listener);
27
+ return this;
28
+ }
29
+ off(event, listener) {
30
+ const listeners = this.events.get(event);
31
+ if (listeners) {
32
+ const index = listeners.indexOf(listener);
33
+ if (index !== -1) {
34
+ listeners.splice(index, 1);
35
+ }
36
+ }
37
+ return this;
38
+ }
39
+ removeListener(event, listener) {
40
+ return this.off(event, listener);
41
+ }
42
+ emit(event, ...args) {
43
+ const listeners = this.events.get(event);
44
+ if (listeners) {
45
+ for (const listener of listeners) {
46
+ listener(...args);
47
+ }
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ removeAllListeners(event) {
53
+ if (event) {
54
+ this.events.delete(event);
55
+ } else {
56
+ this.events.clear();
57
+ }
58
+ return this;
59
+ }
60
+ };
61
+ var SolanaErrorCode = {
62
+ USER_REJECTED: 4001,
63
+ UNAUTHORIZED: 4100,
64
+ UNSUPPORTED_METHOD: 4200,
65
+ DISCONNECTED: 4900,
66
+ INVALID_PARAMS: -32602,
67
+ INTERNAL_ERROR: -32603
68
+ };
69
+ var SolanaProviderError = class extends Error {
70
+ constructor(code, message, data) {
71
+ super(message);
72
+ this.code = code;
73
+ this.data = data;
74
+ this.name = "SolanaProviderError";
75
+ }
76
+ };
77
+ var AbcSolanaProvider = class extends EventEmitter {
78
+ constructor(talkenApi) {
79
+ super();
80
+ this.wallet = null;
81
+ this.connected = false;
82
+ this.talkenApi = talkenApi;
83
+ }
84
+ /**
85
+ * Set request interceptor for sign/transfer confirmation modals
86
+ */
87
+ setRequestInterceptor(interceptor) {
88
+ this.requestInterceptor = interceptor;
89
+ }
90
+ /**
91
+ * Call request interceptor if set (throws on user cancel)
92
+ */
93
+ async callInterceptor(request) {
94
+ if (this.requestInterceptor) {
95
+ await this.requestInterceptor(request);
96
+ }
97
+ }
98
+ /**
99
+ * Set wallet information
100
+ */
101
+ setWallet(wallet) {
102
+ const previousAddress = this.wallet?.address;
103
+ this.wallet = wallet;
104
+ this.connected = true;
105
+ if (previousAddress !== wallet.address) {
106
+ this.emit("accountsChanged", [wallet.address]);
107
+ }
108
+ this.emit("connect", {
109
+ address: wallet.address,
110
+ network: wallet.network
111
+ });
112
+ }
113
+ /**
114
+ * Clear wallet (disconnect)
115
+ */
116
+ clearWallet() {
117
+ this.wallet = null;
118
+ this.connected = false;
119
+ this.emit("disconnect");
120
+ this.emit("accountsChanged", []);
121
+ }
122
+ /**
123
+ * Set TalkenApiClient for backend-proxied transaction flow
124
+ * When set, native SOL transfers will use a single API call instead of multi-step WaaS
125
+ */
126
+ setTalkenApi(talkenApi) {
127
+ this.talkenApi = talkenApi;
128
+ }
129
+ getTalkenApiClientOrThrow() {
130
+ const api = this.talkenApi || getTalkenApiClient();
131
+ if (!api) {
132
+ throw new SolanaProviderError(
133
+ SolanaErrorCode.INTERNAL_ERROR,
134
+ "TalkenApiClient not initialized"
135
+ );
136
+ }
137
+ return api;
138
+ }
139
+ getSigningNetwork() {
140
+ return this.wallet?.network === "solana" ? "solana" : "solana_devnet";
141
+ }
142
+ /**
143
+ * Check if connected
144
+ */
145
+ isConnected() {
146
+ return this.connected && this.wallet !== null;
147
+ }
148
+ /**
149
+ * Get Solana address
150
+ */
151
+ async getAddress() {
152
+ if (!this.wallet) {
153
+ throw new SolanaProviderError(
154
+ SolanaErrorCode.DISCONNECTED,
155
+ "Wallet not connected"
156
+ );
157
+ }
158
+ return this.wallet.address;
159
+ }
160
+ /**
161
+ * Get public key
162
+ */
163
+ async getPublicKey() {
164
+ if (!this.wallet) {
165
+ throw new SolanaProviderError(
166
+ SolanaErrorCode.DISCONNECTED,
167
+ "Wallet not connected"
168
+ );
169
+ }
170
+ return this.wallet.publicKey;
171
+ }
172
+ /**
173
+ * Sign Solana message (no PIN required)
174
+ * Uses encrypted_share which doesn't require PIN
175
+ */
176
+ async signMessage(encodedMessage, _display) {
177
+ if (!this.wallet) {
178
+ throw new SolanaProviderError(
179
+ SolanaErrorCode.DISCONNECTED,
180
+ "Wallet not connected"
181
+ );
182
+ }
183
+ try {
184
+ const decodedText = new TextDecoder().decode(encodedMessage);
185
+ await this.callInterceptor({
186
+ chain: "solana",
187
+ method: "signMessage",
188
+ address: this.wallet.address,
189
+ network: this.wallet.network,
190
+ message: decodedText
191
+ });
192
+ const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
193
+ const result = await this.getTalkenApiClientOrThrow().solana.sign({
194
+ message: messageHex,
195
+ encryptedShare: this.wallet.encryptedShare,
196
+ keyId: this.wallet.keyId,
197
+ secretStore: this.wallet.secretStore || "",
198
+ network: this.getSigningNetwork()
199
+ });
200
+ const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
201
+ const signatureBytes = new Uint8Array(
202
+ signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
203
+ );
204
+ return { signature: signatureBytes };
205
+ } catch (error) {
206
+ this.emit("error", error);
207
+ throw new SolanaProviderError(
208
+ SolanaErrorCode.INTERNAL_ERROR,
209
+ "Failed to sign message",
210
+ error
211
+ );
212
+ }
213
+ }
214
+ /**
215
+ * Sign arbitrary Solana transaction (requires PIN)
216
+ * Supports both Legacy Transaction and VersionedTransaction
217
+ * Used for custom transactions, dApp interactions, and protocol integrations
218
+ */
219
+ async signTransaction(transaction) {
220
+ if (!this.wallet) {
221
+ throw new SolanaProviderError(
222
+ SolanaErrorCode.DISCONNECTED,
223
+ "Wallet not connected"
224
+ );
225
+ }
226
+ try {
227
+ let txMessage = "";
228
+ try {
229
+ txMessage = JSON.stringify(transaction, null, 2);
230
+ } catch {
231
+ txMessage = String(transaction);
232
+ }
233
+ await this.callInterceptor({
234
+ chain: "solana",
235
+ method: "signTransaction",
236
+ address: this.wallet.address,
237
+ network: this.wallet.network,
238
+ message: txMessage,
239
+ isTransaction: true
240
+ });
241
+ const { VersionedTransaction, PublicKey } = await import("@solana/web3.js");
242
+ const isVersioned = transaction instanceof VersionedTransaction;
243
+ let serialized;
244
+ if (isVersioned) {
245
+ serialized = transaction.message.serialize();
246
+ } else {
247
+ serialized = transaction.serializeMessage();
248
+ }
249
+ const messageHex = Buffer.from(serialized).toString("hex");
250
+ const signatureResponse = await this.getTalkenApiClientOrThrow().solana.sign({
251
+ keyId: this.wallet.keyId,
252
+ encryptedShare: this.wallet.encryptedShare,
253
+ secretStore: this.wallet.secretStore || "",
254
+ message: messageHex,
255
+ network: this.getSigningNetwork()
256
+ });
257
+ const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
258
+ const signatureBytes = Buffer.from(signatureHex, "hex");
259
+ const publicKey = new PublicKey(this.wallet.address);
260
+ if (isVersioned) {
261
+ transaction.addSignature(publicKey, signatureBytes);
262
+ } else {
263
+ transaction.addSignature(publicKey, signatureBytes);
264
+ }
265
+ return transaction;
266
+ } catch (error) {
267
+ if (error.code === 4001 || error.cancelled) {
268
+ throw error;
269
+ }
270
+ this.emit("error", error);
271
+ throw new SolanaProviderError(
272
+ SolanaErrorCode.INTERNAL_ERROR,
273
+ "Failed to sign transaction",
274
+ error
275
+ );
276
+ }
277
+ }
278
+ /**
279
+ * Sign multiple transactions (batch signing)
280
+ */
281
+ async signAllTransactions(transactions) {
282
+ const signedTransactions = [];
283
+ for (const transaction of transactions) {
284
+ const signed = await this.signTransaction(transaction);
285
+ signedTransactions.push(signed);
286
+ }
287
+ return signedTransactions;
288
+ }
289
+ /**
290
+ * Unified transfer: SOL, SPL token, or NFT
291
+ * - No mintAddress → native SOL transfer (kind='native')
292
+ * - With mintAddress → SPL/NFT transfer (kind='spl')
293
+ * - NFT = transfer({ mintAddress, toAddress, amount: 1 })
294
+ */
295
+ async transfer(params) {
296
+ if (!this.wallet) {
297
+ throw new SolanaProviderError(
298
+ SolanaErrorCode.DISCONNECTED,
299
+ "Wallet not connected"
300
+ );
301
+ }
302
+ try {
303
+ const symbol = params.mintAddress ? "SPL" : "SOL";
304
+ await this.callInterceptor({
305
+ chain: "solana",
306
+ method: "transfer",
307
+ fromAddress: this.wallet.address,
308
+ toAddress: params.toAddress,
309
+ amount: String(params.amount),
310
+ symbol,
311
+ network: this.wallet.network,
312
+ tokenAddress: params.mintAddress,
313
+ isNativeToken: !params.mintAddress,
314
+ estimatedFee: "0.000005",
315
+ feeSymbol: "SOL"
316
+ });
317
+ const pinHash = getCredentialManager().getPinHash();
318
+ if (!pinHash) {
319
+ throw new SolanaProviderError(
320
+ SolanaErrorCode.INTERNAL_ERROR,
321
+ "PIN hash not found. Please login again."
322
+ );
323
+ }
324
+ console.log("[AbcSolanaProvider] transfer START", {
325
+ kind: params.mintAddress ? "spl" : "native",
326
+ toAddress: params.toAddress,
327
+ amount: params.amount,
328
+ mintAddress: params.mintAddress || null,
329
+ network: this.wallet.network,
330
+ hasPinHash: !!pinHash
331
+ });
332
+ const api = this.getTalkenApiClientOrThrow();
333
+ const apiNetwork = this.wallet.network === "solana" ? "solana" : "solana_devnet";
334
+ if (params.mintAddress) {
335
+ const walletscanApi = createWalletscanApi();
336
+ const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
337
+ contractAddress: params.mintAddress,
338
+ networks: apiNetwork
339
+ });
340
+ const decimals = tokenMeta?.decimals ?? 9;
341
+ const rawAmount = Math.floor(params.amount * 10 ** decimals);
342
+ const result2 = await api.solana.transfer({
343
+ kind: "spl",
344
+ toAddress: params.toAddress,
345
+ mintAddress: params.mintAddress,
346
+ amount: String(rawAmount),
347
+ decimals,
348
+ network: apiNetwork,
349
+ pin: pinHash
350
+ });
351
+ console.log("[AbcSolanaProvider] SPL transfer result:", result2);
352
+ return { signature: result2.txHash };
353
+ }
354
+ const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
355
+ const amountLamports = params.amount * LAMPORTS_PER_SOL;
356
+ console.log("[AbcSolanaProvider] native transfer request:", {
357
+ toAddress: params.toAddress,
358
+ amountLamports: String(amountLamports),
359
+ amountSOL: params.amount
360
+ });
361
+ const result = await api.solana.transfer({
362
+ kind: "native",
363
+ toAddress: params.toAddress,
364
+ amountLamports: String(amountLamports),
365
+ network: apiNetwork,
366
+ pin: pinHash
367
+ });
368
+ console.log("[AbcSolanaProvider] native transfer result:", result);
369
+ return { signature: result.txHash };
370
+ } catch (error) {
371
+ console.error("[AbcSolanaProvider] transfer FAILED:", {
372
+ message: error.message,
373
+ code: error.code,
374
+ status: error.status,
375
+ details: error.details || error.data
376
+ });
377
+ if (error.code === 4001 || error.cancelled) {
378
+ throw error;
379
+ }
380
+ this.emit("error", error);
381
+ throw new SolanaProviderError(
382
+ SolanaErrorCode.INTERNAL_ERROR,
383
+ "Failed to transfer",
384
+ error
385
+ );
386
+ }
387
+ }
388
+ /**
389
+ * Get wallet info
390
+ */
391
+ getWalletInfo() {
392
+ if (!this.wallet)
393
+ return null;
394
+ return {
395
+ address: this.wallet.address,
396
+ publicKey: this.wallet.publicKey,
397
+ network: this.wallet.network
398
+ };
399
+ }
400
+ /**
401
+ * Get SPL token balance
402
+ *
403
+ * @param mintAddress - Token mint address
404
+ * @returns Token balance information
405
+ */
406
+ async getTokenBalance(mintAddress) {
407
+ if (!this.wallet) {
408
+ throw new SolanaProviderError(
409
+ SolanaErrorCode.DISCONNECTED,
410
+ "Wallet not connected"
411
+ );
412
+ }
413
+ try {
414
+ const walletscanApi = createWalletscanApi();
415
+ const balance = await walletscanApi.getWalletTokenBalanceWithTimeout({
416
+ walletAddress: this.wallet.address,
417
+ networks: this.wallet.network,
418
+ contractAddress: mintAddress
419
+ });
420
+ if (!balance) {
421
+ return {
422
+ amount: "0",
423
+ decimals: 0,
424
+ uiAmount: 0
425
+ };
426
+ }
427
+ return {
428
+ amount: String(balance.balance ?? 0),
429
+ decimals: balance.decimals ?? 0,
430
+ uiAmount: balance.hrBalance ?? 0
431
+ };
432
+ } catch (error) {
433
+ this.emit("error", error);
434
+ throw new SolanaProviderError(
435
+ SolanaErrorCode.INTERNAL_ERROR,
436
+ "Failed to get token balance",
437
+ error
438
+ );
439
+ }
440
+ }
441
+ };
442
+
443
+ export {
444
+ SolanaProviderError,
445
+ AbcSolanaProvider
446
+ };