@talken/talkenkit 2.8.0 → 2.8.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 (61) hide show
  1. package/dist/{abcWallet-OW2B7I33.js → abcWallet-TMP56C3B.js} +1 -1
  2. package/dist/{chunk-NPNOKJUQ.js → chunk-WEQ3DKBC.js} +6 -15
  3. package/dist/index.js +6 -6
  4. package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +1 -1
  5. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +1 -1
  6. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +2 -1
  7. package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +4 -4
  8. package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +1 -1
  9. package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +3 -3
  10. package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +2 -1
  11. package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +5 -5
  12. package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +2 -1
  13. package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +3 -3
  14. package/dist/wallets/walletConnectors/abcWallet/api/index.js +3 -3
  15. package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +1 -1
  16. package/dist/wallets/walletConnectors/abcWallet/index.js +8 -8
  17. package/dist/wallets/walletConnectors/abcWallet/types.js +1 -1
  18. package/dist/wallets/walletConnectors/abcWallet/utils.js +1 -1
  19. package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +1 -1
  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-QKP4J4F3.js → chunk-24AEUYOZ.js} +2 -2
  26. package/dist/wallets/walletConnectors/{chunk-MIJYDG4E.js → chunk-2DROHKQL.js} +11 -11
  27. package/dist/wallets/walletConnectors/{chunk-ZQ6IZRWU.js → chunk-4BG6V5TZ.js} +5 -5
  28. package/dist/wallets/walletConnectors/{chunk-FQ66CNGO.js → chunk-R3SLVZUQ.js} +4 -4
  29. package/dist/wallets/walletConnectors/{chunk-JQ5ICHFB.js → chunk-URTS7ZIZ.js} +5 -5
  30. package/dist/wallets/walletConnectors/{chunk-4KPMQVKH.js → chunk-YFNVHCMA.js} +5 -5
  31. package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
  32. package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
  33. package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
  34. package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
  35. package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
  36. package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
  37. package/dist/wallets/walletConnectors/index.js +66 -66
  38. package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
  39. package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
  40. package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
  41. package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
  42. package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
  43. package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
  44. package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
  45. package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
  46. package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
  47. package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
  48. package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
  49. package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
  50. package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
  51. package/package.json +1 -1
  52. package/dist/wallets/walletConnectors/chunk-3ONGJ7J6.js +0 -345
  53. package/dist/wallets/walletConnectors/chunk-5PBINUGT.js +0 -132
  54. package/dist/wallets/walletConnectors/chunk-D67HHSCD.js +0 -277
  55. package/dist/wallets/walletConnectors/chunk-GE6XT2KO.js +0 -340
  56. package/dist/wallets/walletConnectors/chunk-ND3YMIS3.js +0 -218
  57. package/dist/wallets/walletConnectors/chunk-PKEF5NWU.js +0 -378
  58. package/dist/wallets/walletConnectors/chunk-VPSJSCJ6.js +0 -3056
  59. package/dist/wallets/walletConnectors/chunk-ZWMW2ZDF.js +0 -492
  60. package/dist/wallets/walletConnectors/{chunk-C2AQPMGG.js → chunk-I7QLXYSA.js} +4 -4
  61. package/dist/wallets/walletConnectors/{chunk-22YTEJA4.js → chunk-PYIAXFRD.js} +6 -6
@@ -1,218 +0,0 @@
1
- "use client";
2
- import {
3
- getBitcoinNetwork,
4
- getEvmNetwork,
5
- getSolanaNetwork,
6
- getTronNetwork,
7
- getXrplNetwork
8
- } from "./chunk-KXPCOVNY.js";
9
- import {
10
- AbcError
11
- } from "./chunk-BUAWEYGV.js";
12
- import {
13
- getCredentialManager
14
- } from "./chunk-YNE2UX2Z.js";
15
- import {
16
- createLogger
17
- } from "./chunk-2DFJ6LEN.js";
18
-
19
- // src/wallets/walletConnectors/abcWallet/walletGeneration.ts
20
- import { getTalkenApiClient } from "@talken/talkenkit";
21
- var logger = createLogger("WalletGeneration");
22
- async function mapApiResponseToWallets(genResponse, infoResponse, email) {
23
- const accounts = infoResponse?.accounts || [];
24
- const evmAccount = accounts[0] || infoResponse || {};
25
- const uid = String(genResponse.uid || evmAccount.uid || "");
26
- const wid = String(genResponse.wid || evmAccount.wid || "");
27
- const sid = String(
28
- evmAccount.sid || evmAccount.ethAddress || genResponse.evmAddress || ""
29
- );
30
- const pubkey = String(evmAccount.pubkey || genResponse.pubkey || "");
31
- const solMaterial = genResponse.solana || {};
32
- let btcAddress = genResponse.btcAddress || "";
33
- let trxAddress = genResponse.trxAddress || "";
34
- let xrpAddress = genResponse.xrpAddress || "";
35
- if ((!btcAddress || !trxAddress || !xrpAddress) && pubkey) {
36
- try {
37
- const api = getTalkenApiClient();
38
- if (api) {
39
- const addrResponse = await api.wallet.getAddressForChain("all");
40
- if (!btcAddress)
41
- btcAddress = addrResponse?.btc || addrResponse?.btcAddress || "";
42
- if (!trxAddress)
43
- trxAddress = addrResponse?.trx || addrResponse?.trxAddress || "";
44
- if (!xrpAddress)
45
- xrpAddress = addrResponse?.xrp || addrResponse?.xrpAddress || "";
46
- }
47
- } catch (err) {
48
- logger.warn("Failed to derive BTC/TRX/XRP addresses:", err);
49
- }
50
- }
51
- const pvencstr = String(evmAccount.pvencstr || "");
52
- const edp = String(evmAccount.encryptDevicePassword || "");
53
- if (uid && wid && sid && pvencstr && edp) {
54
- getCredentialManager().setEvmSigningCredentials({
55
- uid,
56
- wid,
57
- sid,
58
- pvencstr,
59
- encryptDevicePassword: edp
60
- });
61
- }
62
- const evmWallet = {
63
- uid,
64
- sessionId: sid,
65
- keyId: wid,
66
- encryptedShare: pvencstr,
67
- secretStore: edp,
68
- address: genResponse.evmAddress || sid,
69
- chainId: getEvmNetwork(),
70
- sid,
71
- type: "evm",
72
- email,
73
- pubkey
74
- };
75
- const solanaWallet = {
76
- uid,
77
- sessionId: String(solMaterial.shareId || ""),
78
- keyId: String(solMaterial.keyId || ""),
79
- encryptedShare: String(solMaterial.encryptedShare || ""),
80
- secretStore: String(solMaterial.secretStore || ""),
81
- shareId: String(solMaterial.shareId || ""),
82
- publicKey: String(solMaterial.publicKey || ""),
83
- address: genResponse.solAddress || solMaterial.address || "",
84
- network: getSolanaNetwork()
85
- };
86
- const bitcoinWallet = {
87
- uid,
88
- sessionId: sid,
89
- keyId: wid,
90
- encryptedShare: String(evmAccount.pvencstr || ""),
91
- shareId: sid,
92
- publicKey: pubkey,
93
- address: btcAddress,
94
- addressType: "bech32",
95
- network: getBitcoinNetwork()
96
- };
97
- const tronWallet = {
98
- uid,
99
- sessionId: sid,
100
- keyId: wid,
101
- encryptedShare: String(evmAccount.pvencstr || ""),
102
- shareId: sid,
103
- publicKey: pubkey,
104
- address: trxAddress,
105
- network: getTronNetwork()
106
- };
107
- const xrplWallet = {
108
- uid,
109
- sessionId: sid,
110
- keyId: wid,
111
- encryptedShare: String(evmAccount.pvencstr || ""),
112
- shareId: sid,
113
- publicKey: pubkey,
114
- address: xrpAddress,
115
- network: getXrplNetwork()
116
- };
117
- return { evmWallet, solanaWallet, bitcoinWallet, tronWallet, xrplWallet };
118
- }
119
- async function generateMpcWallets(hashedPin, email) {
120
- const api = getTalkenApiClient();
121
- if (!api) {
122
- throw new AbcError(
123
- "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
124
- "TalkenApiClient not initialized"
125
- );
126
- }
127
- try {
128
- const genResponse = await api.wallet.generate(hashedPin, email);
129
- const infoResponse = await api.wallet.getInfo().catch(() => ({}));
130
- return await mapApiResponseToWallets(
131
- genResponse,
132
- infoResponse,
133
- email || ""
134
- );
135
- } catch (error) {
136
- throw new AbcError(
137
- "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
138
- `Failed to generate MPC wallets: ${error.message}`,
139
- { originalError: error }
140
- );
141
- }
142
- }
143
- async function recoverMpcWallets(hashedPin, email) {
144
- const api = getTalkenApiClient();
145
- if (!api) {
146
- throw new AbcError(
147
- "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
148
- "TalkenApiClient not initialized"
149
- );
150
- }
151
- try {
152
- const genResponse = await api.wallet.recover(hashedPin, email);
153
- const infoResponse = await api.wallet.getInfo().catch(() => ({}));
154
- return await mapApiResponseToWallets(
155
- genResponse,
156
- infoResponse,
157
- email || ""
158
- );
159
- } catch (error) {
160
- throw new AbcError(
161
- "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
162
- `Failed to recover MPC wallets: ${error.message}`,
163
- { originalError: error }
164
- );
165
- }
166
- }
167
- function validateMpcWallets(result) {
168
- const errors = [];
169
- if (!result.evmWallet) {
170
- errors.push("EVM wallet is missing");
171
- } else {
172
- if (!result.evmWallet.address || !result.evmWallet.address.startsWith("0x")) {
173
- errors.push("Invalid EVM wallet address");
174
- }
175
- }
176
- if (!result.solanaWallet) {
177
- errors.push("Solana wallet is missing");
178
- } else {
179
- if (!result.solanaWallet.address) {
180
- errors.push("Invalid Solana wallet address");
181
- }
182
- }
183
- if (!result.bitcoinWallet) {
184
- errors.push("Bitcoin wallet is missing");
185
- } else {
186
- if (!result.bitcoinWallet.address) {
187
- errors.push("Invalid Bitcoin wallet address");
188
- }
189
- }
190
- if (!result.tronWallet) {
191
- errors.push("TRON wallet is missing");
192
- } else {
193
- if (!result.tronWallet.address) {
194
- errors.push("Invalid TRON wallet address");
195
- } else if (!result.tronWallet.address.startsWith("T")) {
196
- errors.push("Invalid TRON address format (expected T prefix)");
197
- }
198
- }
199
- if (!result.xrplWallet) {
200
- errors.push("XRPL wallet is missing");
201
- } else {
202
- if (!result.xrplWallet.address) {
203
- errors.push("Invalid XRPL wallet address");
204
- } else if (!result.xrplWallet.address.startsWith("r")) {
205
- errors.push("Invalid XRPL address format (expected r prefix)");
206
- }
207
- }
208
- return {
209
- valid: errors.length === 0,
210
- errors
211
- };
212
- }
213
-
214
- export {
215
- generateMpcWallets,
216
- recoverMpcWallets,
217
- validateMpcWallets
218
- };
@@ -1,378 +0,0 @@
1
- "use client";
2
- import {
3
- WalletscanApi
4
- } from "./chunk-S6XEM7RM.js";
5
- import {
6
- AbstractChainProvider
7
- } from "./chunk-5PBINUGT.js";
8
- import {
9
- getCredentialManager
10
- } from "./chunk-YNE2UX2Z.js";
11
- import {
12
- ProviderErrorCode,
13
- SolanaProviderError
14
- } from "./chunk-YXWHHI4S.js";
15
- import {
16
- createLogger
17
- } from "./chunk-2DFJ6LEN.js";
18
-
19
- // src/utils/apiClientFactory.ts
20
- function createWalletscanApi() {
21
- return new WalletscanApi();
22
- }
23
-
24
- // src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
25
- var logger = createLogger("AbcSolanaProvider");
26
- var AbcSolanaProvider = class extends AbstractChainProvider {
27
- onWalletSet(wallet) {
28
- this.emit("connect", {
29
- address: wallet.address,
30
- network: wallet.network
31
- });
32
- }
33
- /**
34
- * Call request interceptor if set (throws on user cancel)
35
- */
36
- async callInterceptor(request) {
37
- if (this.requestInterceptor) {
38
- await this.requestInterceptor(request);
39
- }
40
- }
41
- getSigningNetwork() {
42
- return this.wallet?.network === "solana" ? "solana" : "solana_devnet";
43
- }
44
- /**
45
- * Get Solana address
46
- */
47
- async getAddress() {
48
- if (!this.wallet) {
49
- throw new SolanaProviderError(
50
- ProviderErrorCode.DISCONNECTED,
51
- "Wallet not connected"
52
- );
53
- }
54
- return this.wallet.address;
55
- }
56
- /**
57
- * Get public key
58
- */
59
- async getPublicKey() {
60
- if (!this.wallet) {
61
- throw new SolanaProviderError(
62
- ProviderErrorCode.DISCONNECTED,
63
- "Wallet not connected"
64
- );
65
- }
66
- return this.wallet.publicKey;
67
- }
68
- /**
69
- * Sign Solana message via PIN mode.
70
- * Server resolves signing material from PIN hash.
71
- * In AK mode, PIN is auto-injected by server-side delegated credentials.
72
- */
73
- async signMessage(encodedMessage, _display) {
74
- if (!this.wallet) {
75
- throw new SolanaProviderError(
76
- ProviderErrorCode.DISCONNECTED,
77
- "Wallet not connected"
78
- );
79
- }
80
- try {
81
- const decodedText = new TextDecoder().decode(encodedMessage);
82
- await this.callInterceptor({
83
- chain: "solana",
84
- method: "signMessage",
85
- address: this.wallet.address,
86
- network: this.wallet.network,
87
- message: decodedText
88
- });
89
- const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
90
- const solApi = this.getTalkenApiClientOrThrow();
91
- const pinHash = solApi.isAccessKeyMode() ? void 0 : getCredentialManager().getPinHash();
92
- if (!pinHash && !solApi.isAccessKeyMode()) {
93
- throw new SolanaProviderError(
94
- ProviderErrorCode.UNAUTHORIZED,
95
- "PIN hash not found. Please re-enter your PIN."
96
- );
97
- }
98
- const result = await solApi.solana.sign({
99
- message: messageHex,
100
- pin: pinHash || void 0,
101
- network: this.getSigningNetwork()
102
- });
103
- const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
104
- const signatureBytes = new Uint8Array(
105
- signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
106
- );
107
- return { signature: signatureBytes };
108
- } catch (error) {
109
- this.emit("error", error);
110
- throw new SolanaProviderError(
111
- ProviderErrorCode.INTERNAL_ERROR,
112
- "Failed to sign message",
113
- error
114
- );
115
- }
116
- }
117
- /**
118
- * Sign arbitrary Solana transaction (requires PIN)
119
- * Supports both Legacy Transaction and VersionedTransaction
120
- * Used for custom transactions, dApp interactions, and protocol integrations
121
- */
122
- async signTransaction(transaction) {
123
- if (!this.wallet) {
124
- throw new SolanaProviderError(
125
- ProviderErrorCode.DISCONNECTED,
126
- "Wallet not connected"
127
- );
128
- }
129
- try {
130
- let txMessage = "";
131
- try {
132
- txMessage = JSON.stringify(transaction, null, 2);
133
- } catch {
134
- txMessage = String(transaction);
135
- }
136
- await this.callInterceptor({
137
- chain: "solana",
138
- method: "signTransaction",
139
- address: this.wallet.address,
140
- network: this.wallet.network,
141
- message: txMessage,
142
- isTransaction: true
143
- });
144
- const { VersionedTransaction, PublicKey } = await import("@solana/web3.js");
145
- const isVersioned = transaction instanceof VersionedTransaction;
146
- let serialized;
147
- if (isVersioned) {
148
- serialized = transaction.message.serialize();
149
- } else {
150
- serialized = transaction.serializeMessage();
151
- }
152
- const messageHex = Buffer.from(serialized).toString("hex");
153
- const pinHash = getCredentialManager().getPinHash();
154
- const signatureResponse = await this.getTalkenApiClientOrThrow().solana.sign({
155
- message: messageHex,
156
- pin: pinHash || void 0,
157
- network: this.getSigningNetwork()
158
- });
159
- const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
160
- const signatureBytes = Buffer.from(signatureHex, "hex");
161
- const publicKey = new PublicKey(this.wallet.address);
162
- if (isVersioned) {
163
- transaction.addSignature(publicKey, signatureBytes);
164
- } else {
165
- transaction.addSignature(publicKey, signatureBytes);
166
- }
167
- return transaction;
168
- } catch (error) {
169
- if (error.code === 4001 || error.cancelled) {
170
- throw error;
171
- }
172
- this.emit("error", error);
173
- throw new SolanaProviderError(
174
- ProviderErrorCode.INTERNAL_ERROR,
175
- "Failed to sign transaction",
176
- error
177
- );
178
- }
179
- }
180
- /**
181
- * Sign multiple transactions (batch signing)
182
- */
183
- async signAllTransactions(transactions) {
184
- const signedTransactions = [];
185
- for (const transaction of transactions) {
186
- const signed = await this.signTransaction(transaction);
187
- signedTransactions.push(signed);
188
- }
189
- return signedTransactions;
190
- }
191
- /**
192
- * Unified transfer: SOL, SPL token, or NFT
193
- * - No mintAddress → native SOL transfer (kind='native')
194
- * - With mintAddress → SPL/NFT transfer (kind='spl')
195
- * - NFT = transfer({ mintAddress, toAddress, amount: 1 })
196
- */
197
- async transfer(params) {
198
- if (!this.wallet) {
199
- throw new SolanaProviderError(
200
- ProviderErrorCode.DISCONNECTED,
201
- "Wallet not connected"
202
- );
203
- }
204
- try {
205
- const symbol = params.mintAddress ? "SPL" : "SOL";
206
- await this.callInterceptor({
207
- chain: "solana",
208
- method: "transfer",
209
- fromAddress: this.wallet.address,
210
- toAddress: params.toAddress,
211
- amount: String(params.amount),
212
- symbol,
213
- network: this.wallet.network,
214
- tokenAddress: params.mintAddress,
215
- isNativeToken: !params.mintAddress,
216
- estimatedFee: "0.000005",
217
- feeSymbol: "SOL"
218
- });
219
- const api = this.getTalkenApiClientOrThrow();
220
- const pinHash = api.isAccessKeyMode() ? void 0 : getCredentialManager().getPinHash();
221
- if (!pinHash && !api.isAccessKeyMode()) {
222
- throw new SolanaProviderError(
223
- ProviderErrorCode.INTERNAL_ERROR,
224
- "PIN hash not found. Please login again."
225
- );
226
- }
227
- logger.info("transfer START", {
228
- kind: params.mintAddress ? "spl" : "native",
229
- toAddress: params.toAddress,
230
- amount: params.amount,
231
- mintAddress: params.mintAddress || null,
232
- network: this.wallet.network,
233
- hasPinHash: !!pinHash
234
- });
235
- const apiNetwork = this.wallet.network === "solana" ? "solana" : "solana_devnet";
236
- this.showPendingTx({ network: apiNetwork, chain: "solana" });
237
- if (params.mintAddress) {
238
- const walletscanApi = createWalletscanApi();
239
- const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
240
- contractAddress: params.mintAddress,
241
- networks: apiNetwork
242
- });
243
- const decimals = tokenMeta?.decimals ?? 9;
244
- const rawAmount = Math.floor(params.amount * 10 ** decimals);
245
- const result2 = await api.solana.transfer({
246
- kind: "spl",
247
- toAddress: params.toAddress,
248
- mintAddress: params.mintAddress,
249
- amount: String(rawAmount),
250
- decimals,
251
- network: apiNetwork,
252
- pin: pinHash || void 0,
253
- waitForConfirmation: true
254
- });
255
- logger.info("SPL transfer result:", result2);
256
- this.updateSolanaTransactionResult(result2, apiNetwork);
257
- return { signature: result2.txHash };
258
- }
259
- const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
260
- const amountLamports = params.amount * LAMPORTS_PER_SOL;
261
- logger.info("native transfer request:", {
262
- toAddress: params.toAddress,
263
- amountLamports: String(amountLamports),
264
- amountSOL: params.amount
265
- });
266
- const result = await api.solana.transfer({
267
- kind: "native",
268
- toAddress: params.toAddress,
269
- amountLamports: String(amountLamports),
270
- network: apiNetwork,
271
- pin: pinHash || void 0,
272
- waitForConfirmation: true
273
- });
274
- logger.info("native transfer result:", result);
275
- this.updateSolanaTransactionResult(result, apiNetwork);
276
- return { signature: result.txHash };
277
- } catch (error) {
278
- logger.error("transfer FAILED:", {
279
- message: error.message,
280
- code: error.code,
281
- status: error.status,
282
- details: error.details || error.data
283
- });
284
- this.failTxResult({
285
- network: this.wallet?.network || "solana",
286
- chain: "solana",
287
- errorMessage: error.message
288
- });
289
- if (error.code === 4001 || error.cancelled) {
290
- throw error;
291
- }
292
- this.emit("error", error);
293
- throw new SolanaProviderError(
294
- ProviderErrorCode.INTERNAL_ERROR,
295
- "Failed to transfer",
296
- error
297
- );
298
- }
299
- }
300
- /**
301
- * Get wallet info
302
- */
303
- getWalletInfo() {
304
- if (!this.wallet)
305
- return null;
306
- return {
307
- address: this.wallet.address,
308
- publicKey: this.wallet.publicKey,
309
- network: this.wallet.network
310
- };
311
- }
312
- /**
313
- * Get SPL token balance
314
- *
315
- * @param mintAddress - Token mint address
316
- * @returns Token balance information
317
- */
318
- async getTokenBalance(mintAddress) {
319
- if (!this.wallet) {
320
- throw new SolanaProviderError(
321
- ProviderErrorCode.DISCONNECTED,
322
- "Wallet not connected"
323
- );
324
- }
325
- try {
326
- const walletscanApi = createWalletscanApi();
327
- const balance = await walletscanApi.getWalletTokenBalanceWithTimeout({
328
- walletAddress: this.wallet.address,
329
- networks: this.wallet.network,
330
- contractAddress: mintAddress
331
- });
332
- if (!balance) {
333
- return {
334
- amount: "0",
335
- decimals: 0,
336
- uiAmount: 0
337
- };
338
- }
339
- return {
340
- amount: String(balance.balance ?? 0),
341
- decimals: balance.decimals ?? 0,
342
- uiAmount: balance.hrBalance ?? 0
343
- };
344
- } catch (error) {
345
- this.emit("error", error);
346
- throw new SolanaProviderError(
347
- ProviderErrorCode.INTERNAL_ERROR,
348
- "Failed to get token balance",
349
- error
350
- );
351
- }
352
- }
353
- updateSolanaTransactionResult(result, network) {
354
- let receipt = result.receipt;
355
- if (!receipt && result.confirmation) {
356
- const data = result.confirmation?.data?.result ?? result.confirmation?.result ?? result.confirmation;
357
- const slot = data?.slot;
358
- const meta = data?.meta;
359
- receipt = {
360
- status: meta?.err === null ? 1 : 0,
361
- blockNumber: slot ?? null,
362
- gasUsed: meta?.fee != null ? String(meta.fee) : null
363
- };
364
- }
365
- const cluster = network.includes("devnet") ? "?cluster=devnet" : "";
366
- this.updateTxResult({
367
- txHash: result.txHash,
368
- network,
369
- chain: "solana",
370
- receipt,
371
- explorerUrl: `https://explorer.solana.com/tx/${result.txHash}${cluster}`
372
- });
373
- }
374
- };
375
-
376
- export {
377
- AbcSolanaProvider
378
- };