@talken/talkenkit 2.4.22 → 2.4.23
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.
- package/README.md +159 -325
- package/dist/Arc-R3PUWRPJ.js +7 -0
- package/dist/Brave-24BM36UM.js +7 -0
- package/dist/Browser-4R4QKTV2.js +7 -0
- package/dist/Chrome-TLI42HDP.js +7 -0
- package/dist/Edge-AZ34LAFM.js +7 -0
- package/dist/Firefox-ZDK7RHKK.js +7 -0
- package/dist/Linux-VYP66PDO.js +7 -0
- package/dist/Macos-5QL4JBJE.js +7 -0
- package/dist/Opera-BKMCKUXC.js +7 -0
- package/dist/Safari-PXQIVS6N.js +7 -0
- package/dist/Windows-GTAT3OTE.js +7 -0
- package/dist/abcWallet-AYWSIGAG.js +7 -0
- package/dist/abcWallet-O4GH6RHS.js +181 -0
- package/dist/ar_AR-ZRPPM56D.js +7 -0
- package/dist/arbitrum-IA4OWRTN.js +7 -0
- package/dist/argentWallet-M6SBG4CU.js +7 -0
- package/dist/assets-NU2OP443.js +7 -0
- package/dist/avalanche-MXEFEDSW.js +7 -0
- package/dist/base-Z4LFBE5D.js +7 -0
- package/dist/berasigWallet-NNBFDHFK.js +7 -0
- package/dist/bestWallet-XRIABRUE.js +7 -0
- package/dist/bifrostWallet-ORF3DABG.js +7 -0
- package/dist/binanceWallet-BCWLBY3Q.js +7 -0
- package/dist/bitgetWallet-CLYTW54T.js +7 -0
- package/dist/bitskiWallet-X5NWL5CE.js +7 -0
- package/dist/bitverseWallet-6SGDFATJ.js +7 -0
- package/dist/blast-TN2WIMWF.js +7 -0
- package/dist/bloomWallet-MXLAOWS6.js +7 -0
- package/dist/braveWallet-6QAF4GDN.js +7 -0
- package/dist/bsc-RVE67I5L.js +7 -0
- package/dist/bybitWallet-GR4PFINZ.js +7 -0
- package/dist/celo-E6XU57FO.js +7 -0
- package/dist/chunk-N7AWNQBH.js +5319 -0
- package/dist/clvWallet-ZIMSRU5J.js +7 -0
- package/dist/coin98Wallet-RFXRNVWP.js +7 -0
- package/dist/coinbaseWallet-WWX6LF36.js +7 -0
- package/dist/compassWallet-3LBTWCKI.js +7 -0
- package/dist/connect-MR6XDLIE.js +7 -0
- package/dist/coreWallet-52SXITOT.js +7 -0
- package/dist/create-X4WFHLCW.js +7 -0
- package/dist/cronos-ROYR77VZ.js +7 -0
- package/dist/dawnWallet-ONVAA3S4.js +7 -0
- package/dist/de_DE-GYZFZXWH.js +7 -0
- package/dist/desigWallet-WJMSF3PS.js +7 -0
- package/dist/en_US-AV7YDYDW.js +7 -0
- package/dist/enkryptWallet-FR4QCDFK.js +7 -0
- package/dist/es_419-OGVOQEFZ.js +7 -0
- package/dist/ethereum-RFBAMUVK.js +7 -0
- package/dist/flow-NBCRNYVF.js +7 -0
- package/dist/foxWallet-5ESSNXJV.js +7 -0
- package/dist/fr_FR-Q5QBQBX2.js +1355 -0
- package/dist/frameWallet-FDBUY4AA.js +7 -0
- package/dist/frontierWallet-HNIG7QYQ.js +7 -0
- package/dist/gateWallet-ZVEZILRP.js +7 -0
- package/dist/gnosis-T7U5EW2Q.js +7 -0
- package/dist/hardhat-NEEC6JX7.js +7 -0
- package/dist/hi_IN-7I7LRHGW.js +7 -0
- package/dist/id_ID-ZMGZ2JFV.js +7 -0
- package/dist/imTokenWallet-N2MYFADO.js +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +168 -243
- package/dist/injectedWallet-H7LYKTQS.js +7 -0
- package/dist/iopayWallet-IJHJ7NYT.js +7 -0
- package/dist/ja_JP-NYBCHQTZ.js +7 -0
- package/dist/kaia-A33DVQBT.js +7 -0
- package/dist/kaiaWallet-5K6WZ3AH.js +7 -0
- package/dist/kaikasWallet-F6Z6IPWN.js +7 -0
- package/dist/ko_KR-67WE736M.js +7 -0
- package/dist/krakenWallet-DAOXUKWO.js +7 -0
- package/dist/kresusWallet-AUJWLAOF.js +7 -0
- package/dist/ledgerWallet-KZKJ5Q2S.js +7 -0
- package/dist/login-CWDTIDNK.js +7 -0
- package/dist/magicEden-PKT2ZXEQ.js +7 -0
- package/dist/manta-5V6W5D7G.js +7 -0
- package/dist/mantle-KBL3OIYT.js +7 -0
- package/dist/metaMaskWallet-YFHEHW7V.js +7 -0
- package/dist/mewWallet-6V4UZOQC.js +7 -0
- package/dist/ms_MY-65AJIBUS.js +7 -0
- package/dist/nestWallet-BFZZZYLV.js +7 -0
- package/dist/oktoWallet-GJFOPPEA.js +7 -0
- package/dist/okxWallet-GJMKZIND.js +7 -0
- package/dist/omniWallet-DEYUMT4A.js +7 -0
- package/dist/oneInchWallet-D7BQOLOO.js +7 -0
- package/dist/oneKeyWallet-4MM7G2SZ.js +7 -0
- package/dist/optimism-YWJ3IQHA.js +7 -0
- package/dist/paraSwapWallet-TMV5MUEF.js +7 -0
- package/dist/phantomWallet-IPGVKCAB.js +7 -0
- package/dist/polygon-WWEUOMKW.js +7 -0
- package/dist/pt_BR-DMJANC65.js +7 -0
- package/dist/rabbyWallet-FLVUU35F.js +7 -0
- package/dist/rainbowWallet-2SR6TVBF.js +7 -0
- package/dist/ramperWallet-AF5AKK2S.js +7 -0
- package/dist/refresh-HJGJRASX.js +7 -0
- package/dist/ronin-PNHX5V6H.js +7 -0
- package/dist/roninWallet-SAB5ESVK.js +7 -0
- package/dist/ru_RU-WER7RQ6A.js +1355 -0
- package/dist/safeWallet-VUYZPLY4.js +7 -0
- package/dist/safeheronWallet-6JG77AKC.js +7 -0
- package/dist/safepalWallet-KQJ4OCNH.js +7 -0
- package/dist/scan-DEOT2M37.js +7 -0
- package/dist/scroll-NMZWDUQH.js +7 -0
- package/dist/seifWallet-QATOS33A.js +7 -0
- package/dist/services/AbcAuthService.d.ts +11 -12
- package/dist/sign-A7IJEUT5.js +7 -0
- package/dist/subWallet-LOZELSAO.js +7 -0
- package/dist/tahoWallet-L6KHUNKD.js +7 -0
- package/dist/talismanWallet-BLXUHONV.js +7 -0
- package/dist/th_TH-JOSHEZ6D.js +1355 -0
- package/dist/themes/baseTheme.js +0 -1
- package/dist/themes/darkTheme.js +0 -1
- package/dist/themes/lightTheme.js +0 -1
- package/dist/themes/midnightTheme.js +0 -1
- package/dist/tokenPocketWallet-BVMBOYTC.js +7 -0
- package/dist/tokenaryWallet-Z2IGVXSA.js +7 -0
- package/dist/tr_TR-EAMG2YPO.js +1355 -0
- package/dist/trustWallet-E2GVGE4U.js +7 -0
- package/dist/uk_UA-GO2TRVWA.js +1355 -0
- package/dist/uniswapWallet-T26M44R7.js +7 -0
- package/dist/utils/apiClientFactory.d.ts +1 -6
- package/dist/utils/embeddedTxAdapter.d.ts +54 -0
- package/dist/valoraWallet-RX3ONO47.js +7 -0
- package/dist/vi_VN-5HLLSOJA.js +7 -0
- package/dist/walletConnectWallet-FNSU4KNU.js +7 -0
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +0 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +1 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +7 -6
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +3 -4
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +3 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +4 -6
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +37 -44
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -2
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.d.ts +1 -3
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +8 -8
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.d.ts +1 -2
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +1 -5
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +4 -9
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +2 -4
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +1 -5
- package/dist/wallets/walletConnectors/abcWallet/api/index.d.ts +3 -68
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +6 -41
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +1 -38
- package/dist/wallets/walletConnectors/abcWallet/constants.js +1 -7
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +3 -3
- package/dist/wallets/walletConnectors/abcWallet/index.js +33 -45
- package/dist/wallets/walletConnectors/abcWallet/resolveTalkenApiUrl.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/resolveTalkenApiUrl.js +7 -0
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +4 -4
- package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
- package/dist/wallets/walletConnectors/chunk-35RTM3PL.js +1 -0
- package/dist/wallets/walletConnectors/chunk-AFM6KHDP.js +314 -0
- package/dist/wallets/walletConnectors/chunk-AXMN57KP.js +1387 -0
- package/dist/wallets/walletConnectors/chunk-BYZ5QLMX.js +436 -0
- package/dist/wallets/walletConnectors/chunk-CC6GTQBN.js +148 -0
- package/dist/wallets/walletConnectors/chunk-FAVNVTIA.js +479 -0
- package/dist/wallets/walletConnectors/chunk-GFWUFYT2.js +16 -0
- package/dist/wallets/walletConnectors/chunk-QP36UXD5.js +54 -0
- package/dist/wallets/walletConnectors/chunk-R6ZE7JAZ.js +15 -0
- package/dist/wallets/walletConnectors/chunk-RIJTOH57.js +771 -0
- package/dist/wallets/walletConnectors/chunk-RY43MKRA.js +552 -0
- package/dist/wallets/walletConnectors/chunk-TQXCRSMS.js +199 -0
- package/dist/wallets/walletConnectors/chunk-URFU24K7.js +273 -0
- package/dist/wallets/walletConnectors/chunk-USS5CPXQ.js +54 -0
- package/dist/wallets/walletConnectors/chunk-VQYS4NXP.js +314 -0
- package/dist/wallets/walletConnectors/chunk-YPM7FC4M.js +104 -0
- package/dist/wallets/walletConnectors/chunk-Z3L3JJNU.js +356 -0
- package/dist/wallets/walletConnectors/index.js +76 -76
- package/dist/wigwamWallet-5GKUN7ZJ.js +7 -0
- package/dist/xdc-X7V4QFNF.js +7 -0
- package/dist/xdefiWallet-ZA65GDWS.js +7 -0
- package/dist/zealWallet-URNQ2AWF.js +7 -0
- package/dist/zerionWallet-CYFHB5PA.js +7 -0
- package/dist/zetachain-BMJKVYBN.js +7 -0
- package/dist/zh_CN-THPIFVWJ.js +7 -0
- package/dist/zh_HK-R7XP4TGF.js +7 -0
- package/dist/zh_TW-F5LD752V.js +7 -0
- package/dist/zkSync-JL26RB7U.js +7 -0
- package/dist/zora-YZH32HP3.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
|
|
4
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
5
|
+
var EventEmitter = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.events = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
on(event, listener) {
|
|
10
|
+
if (!this.events.has(event)) {
|
|
11
|
+
this.events.set(event, []);
|
|
12
|
+
}
|
|
13
|
+
this.events.get(event).push(listener);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
off(event, listener) {
|
|
17
|
+
const listeners = this.events.get(event);
|
|
18
|
+
if (listeners) {
|
|
19
|
+
const index = listeners.indexOf(listener);
|
|
20
|
+
if (index !== -1) {
|
|
21
|
+
listeners.splice(index, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
removeListener(event, listener) {
|
|
27
|
+
return this.off(event, listener);
|
|
28
|
+
}
|
|
29
|
+
emit(event, ...args) {
|
|
30
|
+
const listeners = this.events.get(event);
|
|
31
|
+
if (listeners) {
|
|
32
|
+
for (const listener of listeners) {
|
|
33
|
+
listener(...args);
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
removeAllListeners(event) {
|
|
40
|
+
if (event) {
|
|
41
|
+
this.events.delete(event);
|
|
42
|
+
} else {
|
|
43
|
+
this.events.clear();
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var SolanaErrorCode = {
|
|
49
|
+
USER_REJECTED: 4001,
|
|
50
|
+
UNAUTHORIZED: 4100,
|
|
51
|
+
UNSUPPORTED_METHOD: 4200,
|
|
52
|
+
DISCONNECTED: 4900,
|
|
53
|
+
INVALID_PARAMS: -32602,
|
|
54
|
+
INTERNAL_ERROR: -32603
|
|
55
|
+
};
|
|
56
|
+
var SolanaProviderError = class extends Error {
|
|
57
|
+
constructor(code, message, data) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.data = data;
|
|
61
|
+
this.name = "SolanaProviderError";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var AbcSolanaProvider = class extends EventEmitter {
|
|
65
|
+
constructor(talkenApi) {
|
|
66
|
+
super();
|
|
67
|
+
this.wallet = null;
|
|
68
|
+
this.connected = false;
|
|
69
|
+
this.talkenApi = talkenApi;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set request interceptor for sign/transfer confirmation modals
|
|
73
|
+
*/
|
|
74
|
+
setRequestInterceptor(interceptor) {
|
|
75
|
+
this.requestInterceptor = interceptor;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Call request interceptor if set (throws on user cancel)
|
|
79
|
+
*/
|
|
80
|
+
async callInterceptor(request) {
|
|
81
|
+
if (this.requestInterceptor) {
|
|
82
|
+
await this.requestInterceptor(request);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Set wallet information
|
|
87
|
+
*/
|
|
88
|
+
setWallet(wallet) {
|
|
89
|
+
const previousAddress = this.wallet?.address;
|
|
90
|
+
this.wallet = wallet;
|
|
91
|
+
this.connected = true;
|
|
92
|
+
if (previousAddress !== wallet.address) {
|
|
93
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
94
|
+
}
|
|
95
|
+
this.emit("connect", {
|
|
96
|
+
address: wallet.address,
|
|
97
|
+
network: wallet.network
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Clear wallet (disconnect)
|
|
102
|
+
*/
|
|
103
|
+
clearWallet() {
|
|
104
|
+
this.wallet = null;
|
|
105
|
+
this.connected = false;
|
|
106
|
+
this.emit("disconnect");
|
|
107
|
+
this.emit("accountsChanged", []);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Set TalkenApiClient for backend-proxied transaction flow
|
|
111
|
+
* When set, native SOL transfers will use a single API call instead of multi-step WaaS
|
|
112
|
+
*/
|
|
113
|
+
setTalkenApi(talkenApi) {
|
|
114
|
+
this.talkenApi = talkenApi;
|
|
115
|
+
}
|
|
116
|
+
getTalkenApiClientOrThrow() {
|
|
117
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
118
|
+
if (!api) {
|
|
119
|
+
throw new SolanaProviderError(
|
|
120
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
121
|
+
"TalkenApiClient not initialized"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return api;
|
|
125
|
+
}
|
|
126
|
+
getSigningNetwork() {
|
|
127
|
+
return this.wallet?.network === "solana" ? "solana" : "solana_devnet";
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if connected
|
|
131
|
+
*/
|
|
132
|
+
isConnected() {
|
|
133
|
+
return this.connected && this.wallet !== null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get Solana address
|
|
137
|
+
*/
|
|
138
|
+
async getAddress() {
|
|
139
|
+
if (!this.wallet) {
|
|
140
|
+
throw new SolanaProviderError(
|
|
141
|
+
SolanaErrorCode.DISCONNECTED,
|
|
142
|
+
"Wallet not connected"
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return this.wallet.address;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get public key
|
|
149
|
+
*/
|
|
150
|
+
async getPublicKey() {
|
|
151
|
+
if (!this.wallet) {
|
|
152
|
+
throw new SolanaProviderError(
|
|
153
|
+
SolanaErrorCode.DISCONNECTED,
|
|
154
|
+
"Wallet not connected"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return this.wallet.publicKey;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sign Solana message (no PIN required)
|
|
161
|
+
* Uses encrypted_share which doesn't require PIN
|
|
162
|
+
*/
|
|
163
|
+
async signMessage(encodedMessage, _display) {
|
|
164
|
+
if (!this.wallet) {
|
|
165
|
+
throw new SolanaProviderError(
|
|
166
|
+
SolanaErrorCode.DISCONNECTED,
|
|
167
|
+
"Wallet not connected"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const decodedText = new TextDecoder().decode(encodedMessage);
|
|
172
|
+
await this.callInterceptor({
|
|
173
|
+
chain: "solana",
|
|
174
|
+
method: "signMessage",
|
|
175
|
+
address: this.wallet.address,
|
|
176
|
+
network: this.wallet.network,
|
|
177
|
+
message: decodedText
|
|
178
|
+
});
|
|
179
|
+
const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
180
|
+
const result = await this.getTalkenApiClientOrThrow().solana.sign({
|
|
181
|
+
message: messageHex,
|
|
182
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
183
|
+
keyId: this.wallet.keyId,
|
|
184
|
+
secretStore: this.wallet.secretStore || "",
|
|
185
|
+
network: this.getSigningNetwork()
|
|
186
|
+
});
|
|
187
|
+
const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
|
|
188
|
+
const signatureBytes = new Uint8Array(
|
|
189
|
+
signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
|
|
190
|
+
);
|
|
191
|
+
return { signature: signatureBytes };
|
|
192
|
+
} catch (error) {
|
|
193
|
+
this.emit("error", error);
|
|
194
|
+
throw new SolanaProviderError(
|
|
195
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
196
|
+
"Failed to sign message",
|
|
197
|
+
error
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sign arbitrary Solana transaction (requires PIN)
|
|
203
|
+
* Supports both Legacy Transaction and VersionedTransaction
|
|
204
|
+
* Used for custom transactions, dApp interactions, and protocol integrations
|
|
205
|
+
*/
|
|
206
|
+
async signTransaction(transaction) {
|
|
207
|
+
if (!this.wallet) {
|
|
208
|
+
throw new SolanaProviderError(
|
|
209
|
+
SolanaErrorCode.DISCONNECTED,
|
|
210
|
+
"Wallet not connected"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
let txMessage = "";
|
|
215
|
+
try {
|
|
216
|
+
txMessage = JSON.stringify(transaction, null, 2);
|
|
217
|
+
} catch {
|
|
218
|
+
txMessage = String(transaction);
|
|
219
|
+
}
|
|
220
|
+
await this.callInterceptor({
|
|
221
|
+
chain: "solana",
|
|
222
|
+
method: "signTransaction",
|
|
223
|
+
address: this.wallet.address,
|
|
224
|
+
network: this.wallet.network,
|
|
225
|
+
message: txMessage,
|
|
226
|
+
isTransaction: true
|
|
227
|
+
});
|
|
228
|
+
const { VersionedTransaction, PublicKey } = await import("@solana/web3.js");
|
|
229
|
+
const isVersioned = transaction instanceof VersionedTransaction;
|
|
230
|
+
let serialized;
|
|
231
|
+
if (isVersioned) {
|
|
232
|
+
serialized = transaction.message.serialize();
|
|
233
|
+
} else {
|
|
234
|
+
serialized = transaction.serializeMessage();
|
|
235
|
+
}
|
|
236
|
+
const messageHex = Buffer.from(serialized).toString("hex");
|
|
237
|
+
const signatureResponse = await this.getTalkenApiClientOrThrow().solana.sign({
|
|
238
|
+
keyId: this.wallet.keyId,
|
|
239
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
240
|
+
secretStore: this.wallet.secretStore || "",
|
|
241
|
+
message: messageHex,
|
|
242
|
+
network: this.getSigningNetwork()
|
|
243
|
+
});
|
|
244
|
+
const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
|
|
245
|
+
const signatureBytes = Buffer.from(signatureHex, "hex");
|
|
246
|
+
const publicKey = new PublicKey(this.wallet.address);
|
|
247
|
+
if (isVersioned) {
|
|
248
|
+
transaction.addSignature(publicKey, signatureBytes);
|
|
249
|
+
} else {
|
|
250
|
+
transaction.addSignature(publicKey, signatureBytes);
|
|
251
|
+
}
|
|
252
|
+
return transaction;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (error.code === 4001 || error.cancelled) {
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
this.emit("error", error);
|
|
258
|
+
throw new SolanaProviderError(
|
|
259
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
260
|
+
"Failed to sign transaction",
|
|
261
|
+
error
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Sign multiple transactions (batch signing)
|
|
267
|
+
*/
|
|
268
|
+
async signAllTransactions(transactions) {
|
|
269
|
+
const signedTransactions = [];
|
|
270
|
+
for (const transaction of transactions) {
|
|
271
|
+
const signed = await this.signTransaction(transaction);
|
|
272
|
+
signedTransactions.push(signed);
|
|
273
|
+
}
|
|
274
|
+
return signedTransactions;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Unified transfer: SOL, SPL token, or NFT
|
|
278
|
+
* - No mintAddress → native SOL transfer (kind='native')
|
|
279
|
+
* - With mintAddress → SPL/NFT transfer (kind='spl')
|
|
280
|
+
* - NFT = transfer({ mintAddress, toAddress, amount: 1 })
|
|
281
|
+
*/
|
|
282
|
+
async transfer(params) {
|
|
283
|
+
if (!this.wallet) {
|
|
284
|
+
throw new SolanaProviderError(
|
|
285
|
+
SolanaErrorCode.DISCONNECTED,
|
|
286
|
+
"Wallet not connected"
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const symbol = params.mintAddress ? "SPL" : "SOL";
|
|
291
|
+
await this.callInterceptor({
|
|
292
|
+
chain: "solana",
|
|
293
|
+
method: "transfer",
|
|
294
|
+
fromAddress: this.wallet.address,
|
|
295
|
+
toAddress: params.toAddress,
|
|
296
|
+
amount: String(params.amount),
|
|
297
|
+
symbol,
|
|
298
|
+
network: this.wallet.network,
|
|
299
|
+
tokenAddress: params.mintAddress,
|
|
300
|
+
isNativeToken: !params.mintAddress,
|
|
301
|
+
feeSymbol: "SOL"
|
|
302
|
+
});
|
|
303
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
304
|
+
if (!pinHash) {
|
|
305
|
+
throw new SolanaProviderError(
|
|
306
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
307
|
+
"PIN hash not found. Please login again."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
console.log("[AbcSolanaProvider] transfer START", {
|
|
311
|
+
kind: params.mintAddress ? "spl" : "native",
|
|
312
|
+
toAddress: params.toAddress,
|
|
313
|
+
amount: params.amount,
|
|
314
|
+
mintAddress: params.mintAddress || null,
|
|
315
|
+
network: this.wallet.network,
|
|
316
|
+
hasPinHash: !!pinHash
|
|
317
|
+
});
|
|
318
|
+
const api = this.getTalkenApiClientOrThrow();
|
|
319
|
+
if (params.mintAddress) {
|
|
320
|
+
const apiNetwork = this.wallet.network === "solana" ? "solana_mainnet" : this.wallet.network;
|
|
321
|
+
const { PublicKey, Connection } = await import("@solana/web3.js");
|
|
322
|
+
const connection = new Connection(this.getRpcUrl(), "confirmed");
|
|
323
|
+
const mintPubkey = new PublicKey(params.mintAddress);
|
|
324
|
+
const mintInfo = await connection.getParsedAccountInfo(mintPubkey);
|
|
325
|
+
const decimals = mintInfo.value?.data?.parsed?.info?.decimals || 9;
|
|
326
|
+
const rawAmount = Math.floor(params.amount * 10 ** decimals);
|
|
327
|
+
const result2 = await api.solana.transfer({
|
|
328
|
+
kind: "spl",
|
|
329
|
+
toAddress: params.toAddress,
|
|
330
|
+
mintAddress: params.mintAddress,
|
|
331
|
+
amount: String(rawAmount),
|
|
332
|
+
decimals,
|
|
333
|
+
network: apiNetwork,
|
|
334
|
+
pin: pinHash
|
|
335
|
+
});
|
|
336
|
+
console.log("[AbcSolanaProvider] SPL transfer result:", result2);
|
|
337
|
+
return { signature: result2.txHash };
|
|
338
|
+
}
|
|
339
|
+
const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
|
|
340
|
+
const amountLamports = params.amount * LAMPORTS_PER_SOL;
|
|
341
|
+
console.log("[AbcSolanaProvider] native transfer request:", {
|
|
342
|
+
toAddress: params.toAddress,
|
|
343
|
+
amountLamports: String(amountLamports),
|
|
344
|
+
amountSOL: params.amount
|
|
345
|
+
});
|
|
346
|
+
const result = await api.solana.transfer({
|
|
347
|
+
kind: "native",
|
|
348
|
+
toAddress: params.toAddress,
|
|
349
|
+
amountLamports: String(amountLamports),
|
|
350
|
+
pin: pinHash
|
|
351
|
+
});
|
|
352
|
+
console.log("[AbcSolanaProvider] native transfer result:", result);
|
|
353
|
+
return { signature: result.txHash };
|
|
354
|
+
} catch (error) {
|
|
355
|
+
console.error("[AbcSolanaProvider] transfer FAILED:", {
|
|
356
|
+
message: error.message,
|
|
357
|
+
code: error.code,
|
|
358
|
+
status: error.status,
|
|
359
|
+
details: error.details || error.data
|
|
360
|
+
});
|
|
361
|
+
if (error.code === 4001 || error.cancelled) {
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
this.emit("error", error);
|
|
365
|
+
throw new SolanaProviderError(
|
|
366
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
367
|
+
"Failed to transfer",
|
|
368
|
+
error
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get wallet info
|
|
374
|
+
*/
|
|
375
|
+
getWalletInfo() {
|
|
376
|
+
if (!this.wallet)
|
|
377
|
+
return null;
|
|
378
|
+
return {
|
|
379
|
+
address: this.wallet.address,
|
|
380
|
+
publicKey: this.wallet.publicKey,
|
|
381
|
+
network: this.wallet.network
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Get SPL token balance
|
|
386
|
+
*
|
|
387
|
+
* @param mintAddress - Token mint address
|
|
388
|
+
* @returns Token balance information
|
|
389
|
+
*/
|
|
390
|
+
async getTokenBalance(mintAddress) {
|
|
391
|
+
if (!this.wallet) {
|
|
392
|
+
throw new SolanaProviderError(
|
|
393
|
+
SolanaErrorCode.DISCONNECTED,
|
|
394
|
+
"Wallet not connected"
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
try {
|
|
398
|
+
const { PublicKey, Connection } = await import("@solana/web3.js");
|
|
399
|
+
const { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } = await import("@solana/spl-token");
|
|
400
|
+
const connection = new Connection(this.getRpcUrl(), "confirmed");
|
|
401
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
402
|
+
const ownerPubkey = new PublicKey(this.wallet.address);
|
|
403
|
+
const tokenAccount = await getAssociatedTokenAddress(
|
|
404
|
+
mintPubkey,
|
|
405
|
+
ownerPubkey,
|
|
406
|
+
false,
|
|
407
|
+
TOKEN_PROGRAM_ID
|
|
408
|
+
);
|
|
409
|
+
const balance = await connection.getTokenAccountBalance(tokenAccount);
|
|
410
|
+
return {
|
|
411
|
+
amount: balance.value.amount,
|
|
412
|
+
decimals: balance.value.decimals,
|
|
413
|
+
uiAmount: balance.value.uiAmount || 0
|
|
414
|
+
};
|
|
415
|
+
} catch (error) {
|
|
416
|
+
this.emit("error", error);
|
|
417
|
+
throw new SolanaProviderError(
|
|
418
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
419
|
+
"Failed to get token balance",
|
|
420
|
+
error
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Get RPC URL based on network
|
|
426
|
+
*/
|
|
427
|
+
getRpcUrl() {
|
|
428
|
+
const isMainnet = this.wallet?.network === "solana";
|
|
429
|
+
return isMainnet ? process.env.NEXT_PUBLIC_SOLANA_RPC_MAINNET || "https://api.mainnet-beta.solana.com" : process.env.NEXT_PUBLIC_SOLANA_RPC_DEVNET || "https://api.devnet.solana.com";
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export {
|
|
434
|
+
SolanaProviderError,
|
|
435
|
+
AbcSolanaProvider
|
|
436
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/wallets/walletConnectors/abcWallet/api/WalletscanApi.ts
|
|
4
|
+
import { getTalkenApiClient, networkNameToChainKey } from "@talken/talkenkit";
|
|
5
|
+
var WalletscanApi = class {
|
|
6
|
+
/**
|
|
7
|
+
* Get token metadata via TalkenApiClient walletscan endpoint
|
|
8
|
+
*
|
|
9
|
+
* @param params - Contract address and networks
|
|
10
|
+
* @returns Token metadata or null if not found/failed
|
|
11
|
+
*/
|
|
12
|
+
async getContractToken(params) {
|
|
13
|
+
const api = getTalkenApiClient();
|
|
14
|
+
if (!api)
|
|
15
|
+
throw new Error("TalkenApiClient not initialized");
|
|
16
|
+
try {
|
|
17
|
+
const tokens = await api.walletscan.getToken({
|
|
18
|
+
contractAddress: params.contractAddress,
|
|
19
|
+
chainKeys: networkNameToChainKey(params.networks)
|
|
20
|
+
});
|
|
21
|
+
return tokens.length > 0 ? tokens[0] : null;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.warn(
|
|
24
|
+
"[WalletscanApi] TalkenApi getToken failed:",
|
|
25
|
+
params.contractAddress,
|
|
26
|
+
error
|
|
27
|
+
);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get token metadata with timeout
|
|
33
|
+
*
|
|
34
|
+
* @param params - Contract address and networks
|
|
35
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
36
|
+
* @returns Token metadata or null if timeout/failed
|
|
37
|
+
*/
|
|
38
|
+
async getContractTokenWithTimeout(params, timeoutMs = 3e3) {
|
|
39
|
+
try {
|
|
40
|
+
const result = await Promise.race([
|
|
41
|
+
this.getContractToken(params),
|
|
42
|
+
new Promise(
|
|
43
|
+
(resolve) => setTimeout(() => resolve(null), timeoutMs)
|
|
44
|
+
)
|
|
45
|
+
]);
|
|
46
|
+
return result;
|
|
47
|
+
} catch (_error) {
|
|
48
|
+
console.warn(
|
|
49
|
+
"[WalletscanApi] Token metadata request timed out:",
|
|
50
|
+
params.contractAddress
|
|
51
|
+
);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get native coin info via TalkenApiClient walletscan endpoint
|
|
57
|
+
*
|
|
58
|
+
* @param params - Wallet address and networks
|
|
59
|
+
* @returns Array of native coins or empty array if failed
|
|
60
|
+
*/
|
|
61
|
+
async getNativeToken(params) {
|
|
62
|
+
const api = getTalkenApiClient();
|
|
63
|
+
if (!api)
|
|
64
|
+
throw new Error("TalkenApiClient not initialized");
|
|
65
|
+
try {
|
|
66
|
+
return await api.walletscan.getNativeTokens({
|
|
67
|
+
walletAddress: params.walletAddress,
|
|
68
|
+
chainKeys: networkNameToChainKey(params.networks)
|
|
69
|
+
});
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.warn("[WalletscanApi] TalkenApi getNativeTokens failed:", error);
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get native coin info with timeout
|
|
77
|
+
*
|
|
78
|
+
* @param params - Wallet address and networks
|
|
79
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
80
|
+
* @returns First native coin or null if timeout/failed
|
|
81
|
+
*/
|
|
82
|
+
async getNativeTokenWithTimeout(params, timeoutMs = 3e3) {
|
|
83
|
+
try {
|
|
84
|
+
const natives = await Promise.race([
|
|
85
|
+
this.getNativeToken(params),
|
|
86
|
+
new Promise(
|
|
87
|
+
(resolve) => setTimeout(() => resolve([]), timeoutMs)
|
|
88
|
+
)
|
|
89
|
+
]);
|
|
90
|
+
return natives.length > 0 ? natives[0] : null;
|
|
91
|
+
} catch (_error) {
|
|
92
|
+
console.warn("[WalletscanApi] Native coin request timed out");
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get NFT metadata via TalkenApiClient walletscan endpoint
|
|
98
|
+
*
|
|
99
|
+
* @param params - Contract address, wallet address, and networks
|
|
100
|
+
* @returns Array of NFT metadata or empty array if failed
|
|
101
|
+
*/
|
|
102
|
+
async getNFT(params) {
|
|
103
|
+
const api = getTalkenApiClient();
|
|
104
|
+
if (!api)
|
|
105
|
+
throw new Error("TalkenApiClient not initialized");
|
|
106
|
+
try {
|
|
107
|
+
return await api.walletscan.getNfts({
|
|
108
|
+
chainKeys: networkNameToChainKey(params.networks),
|
|
109
|
+
walletAddress: params.walletAddress
|
|
110
|
+
});
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.warn(
|
|
113
|
+
"[WalletscanApi] TalkenApi getNfts failed:",
|
|
114
|
+
params.contractAddress,
|
|
115
|
+
error
|
|
116
|
+
);
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get NFT metadata with timeout
|
|
122
|
+
*
|
|
123
|
+
* @param params - Contract address, wallet address, and networks
|
|
124
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
125
|
+
* @returns First NFT or null if timeout/failed/empty
|
|
126
|
+
*/
|
|
127
|
+
async getNFTWithTimeout(params, timeoutMs = 3e3) {
|
|
128
|
+
try {
|
|
129
|
+
const nfts = await Promise.race([
|
|
130
|
+
this.getNFT(params),
|
|
131
|
+
new Promise(
|
|
132
|
+
(resolve) => setTimeout(() => resolve([]), timeoutMs)
|
|
133
|
+
)
|
|
134
|
+
]);
|
|
135
|
+
return nfts.length > 0 ? nfts[0] : null;
|
|
136
|
+
} catch (_error) {
|
|
137
|
+
console.warn(
|
|
138
|
+
"[WalletscanApi] NFT metadata request timed out:",
|
|
139
|
+
params.contractAddress
|
|
140
|
+
);
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
WalletscanApi
|
|
148
|
+
};
|