@talken/talkenkit 2.3.15 → 2.4.5
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/dist/{chunk-UWHLB4MJ.js → chunk-RQ637EP3.js} +0 -2
- package/dist/components/ConnectOptions/ExternalWallets/EthereumWallet/EthereumWalletList.d.ts +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6783 -6571
- package/dist/{secure-SSSSQ4NA.js → secure-X6ZSGFOB.js} +1 -1
- package/dist/services/AbcAuthService.d.ts +1 -1
- package/dist/solana/AbcSolanaAutoConnector.d.ts +7 -0
- package/dist/solana/SolanaWalletProvider.d.ts +18 -2
- package/dist/solana/config.d.ts +26 -0
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.d.ts +7 -0
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +37 -0
- package/dist/wallets/walletConnectors/abcWallet/abcApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +166 -0
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +725 -0
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.d.ts +5 -0
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/SigningApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +16 -5
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +13 -13
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.js +5 -7
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +3 -7
- package/dist/wallets/walletConnectors/abcWallet/index.js +36 -46
- package/dist/wallets/walletConnectors/abcWallet/secure.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.d.ts +38 -0
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +15 -0
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +34 -1
- package/dist/wallets/walletConnectors/abcWallet/types.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/utils.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +2 -2
- package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
- package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
- package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
- package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
- package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
- package/dist/wallets/walletConnectors/chunk-2GNL2GNB.js +154 -0
- package/dist/wallets/walletConnectors/{chunk-5DDAV4BZ.js → chunk-2NAY6X3G.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-ZIYAL44B.js → chunk-2NVHWZUE.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-LENPUTNQ.js → chunk-36J4NGMW.js} +12 -20
- package/dist/wallets/walletConnectors/{chunk-4MF5RSML.js → chunk-3CTIR723.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-AVPBPELO.js → chunk-3WLUH24A.js} +10 -10
- package/dist/wallets/walletConnectors/{chunk-YEHCPL4R.js → chunk-53LPTQ6J.js} +2 -2
- package/dist/wallets/walletConnectors/{chunk-GXGRTWJM.js → chunk-5CZGFT24.js} +10 -10
- package/dist/wallets/walletConnectors/{chunk-BJHGC546.js → chunk-5JIPWC5W.js} +12 -24
- package/dist/wallets/walletConnectors/{chunk-4N6JD6LY.js → chunk-5LPD35BU.js} +9 -9
- package/dist/wallets/walletConnectors/{chunk-UV5HHESJ.js → chunk-5RSS3SRV.js} +29 -12
- package/dist/wallets/walletConnectors/{chunk-3ZE57J3R.js → chunk-64TRAZ6V.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-KKPINUPY.js → chunk-6BAXMYSN.js} +2 -2
- package/dist/wallets/walletConnectors/{chunk-PPIFAF7N.js → chunk-7MOCKWA7.js} +65 -19
- package/dist/wallets/walletConnectors/{chunk-75RN2RLT.js → chunk-7TYZCXIR.js} +12 -12
- package/dist/wallets/walletConnectors/{chunk-HVPQO6ZG.js → chunk-7UIXGYOT.js} +5 -20
- package/dist/wallets/walletConnectors/{chunk-BL57XWJY.js → chunk-7UQQKSV7.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-FGBDWBWQ.js → chunk-AIKTQX6B.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-AO24PU7X.js +104 -0
- package/dist/wallets/walletConnectors/{chunk-4YJWX7I3.js → chunk-APLOMU6R.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-AZAV5URB.js +267 -0
- package/dist/wallets/walletConnectors/chunk-BO6OI7XU.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-P2GV6NQG.js → chunk-BV3DCJXA.js} +12 -20
- package/dist/wallets/walletConnectors/{chunk-KJHOGJ3A.js → chunk-CNRPEVLV.js} +16 -4
- package/dist/wallets/walletConnectors/{chunk-OC2O4BHA.js → chunk-COPAK5YT.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-CZVBS7QE.js +436 -0
- package/dist/wallets/walletConnectors/{chunk-QKUFFUM5.js → chunk-DA5J6GHZ.js} +14 -4
- package/dist/wallets/walletConnectors/chunk-FMDSZ2CE.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-5CCU7PNU.js → chunk-FQTLYAWT.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-FUOQBONI.js +47 -0
- package/dist/wallets/walletConnectors/chunk-FWCS4HBL.js +1695 -0
- package/dist/wallets/walletConnectors/chunk-FY7UDC3W.js +63 -0
- package/dist/wallets/walletConnectors/chunk-GZUP3M2X.js +63 -0
- package/dist/wallets/walletConnectors/chunk-H52W4ZFE.js +272 -0
- package/dist/wallets/walletConnectors/chunk-HEQZLRTH.js +309 -0
- package/dist/wallets/walletConnectors/{chunk-ISAMATTH.js → chunk-HFC4AK72.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-HKIV22NT.js +63 -0
- package/dist/wallets/walletConnectors/chunk-HLC24OGS.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-5TDZSXJ4.js → chunk-HTD7IRKM.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-IQJWD4IN.js +269 -0
- package/dist/wallets/walletConnectors/chunk-IZUAJRJ4.js +311 -0
- package/dist/wallets/walletConnectors/{chunk-NX5MQHSQ.js → chunk-J6VUIOSE.js} +23 -2
- package/dist/wallets/walletConnectors/chunk-JH2SJPEY.js +63 -0
- package/dist/wallets/walletConnectors/chunk-JQ57SCY6.js +313 -0
- package/dist/wallets/walletConnectors/{chunk-F5P2INHS.js → chunk-KB7OGAUC.js} +14 -4
- package/dist/wallets/walletConnectors/chunk-KXEAFXAA.js +226 -0
- package/dist/wallets/walletConnectors/{chunk-JR2C4XXX.js → chunk-LLWI2QWC.js} +74 -18
- package/dist/wallets/walletConnectors/{chunk-H2MX4NAL.js → chunk-LQ2U33WM.js} +29 -16
- package/dist/wallets/walletConnectors/{chunk-BNSBK5PQ.js → chunk-M7KXDTM6.js} +14 -4
- package/dist/wallets/walletConnectors/{chunk-CYYBGUSO.js → chunk-MKAXMNZM.js} +4 -4
- package/dist/wallets/walletConnectors/chunk-MNRRJSFM.js +272 -0
- package/dist/wallets/walletConnectors/chunk-MPFE6GP2.js +306 -0
- package/dist/wallets/walletConnectors/{chunk-EEY5CXKO.js → chunk-MPNSYA4E.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-NDLQSZ2F.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-G2LI5MVX.js → chunk-NDYGTKP5.js} +0 -2
- package/dist/wallets/walletConnectors/chunk-NLBRSN6Q.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-BSBRWKNG.js → chunk-NPF7NOA7.js} +69 -23
- package/dist/wallets/walletConnectors/{chunk-7DEZCGNV.js → chunk-NUJ6VD2U.js} +82 -16
- package/dist/wallets/walletConnectors/chunk-PSRATZTN.js +47 -0
- package/dist/wallets/walletConnectors/{chunk-MZOFZ2NQ.js → chunk-QCIIXMAZ.js} +2 -2
- package/dist/wallets/walletConnectors/{chunk-GHLLVM7O.js → chunk-RCI7QYCZ.js} +82 -18
- package/dist/wallets/walletConnectors/{chunk-QI2VB7LL.js → chunk-RHQXGWIW.js} +82 -16
- package/dist/wallets/walletConnectors/chunk-RPOLRZ4N.js +276 -0
- package/dist/wallets/walletConnectors/{chunk-5UEBEMEE.js → chunk-RQIUWXDF.js} +2 -1
- package/dist/wallets/walletConnectors/{chunk-RLR4Y5WO.js → chunk-SCD35IRD.js} +4 -0
- package/dist/wallets/walletConnectors/{chunk-EGOIRXTV.js → chunk-SOCVQ5N3.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-TTRSCIGA.js +194 -0
- package/dist/wallets/walletConnectors/chunk-TYUEB4VT.js +477 -0
- package/dist/wallets/walletConnectors/{chunk-WTYSUOKN.js → chunk-UZXTNCDO.js} +17 -5
- package/dist/wallets/walletConnectors/chunk-V33I7JGZ.js +156 -0
- package/dist/wallets/walletConnectors/chunk-V4Q3GNBX.js +484 -0
- package/dist/wallets/walletConnectors/chunk-VCCTIYUJ.js +63 -0
- package/dist/wallets/walletConnectors/chunk-VGOISIH3.js +223 -0
- package/dist/wallets/walletConnectors/chunk-XFGVJOQL.js +223 -0
- package/dist/wallets/walletConnectors/chunk-XIOPKI2F.js +47 -0
- package/dist/wallets/walletConnectors/{chunk-O6EAIC4G.js → chunk-XJ4SP35I.js} +4 -1
- package/dist/wallets/walletConnectors/chunk-XKGUE56S.js +226 -0
- package/dist/wallets/walletConnectors/chunk-XQEAXENJ.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-RY4RAB3D.js → chunk-YCZ4CZQ6.js} +106 -66
- package/dist/wallets/walletConnectors/chunk-Z2DC2J7S.js +345 -0
- package/dist/wallets/walletConnectors/chunk-Z2K3RHWK.js +47 -0
- package/dist/wallets/walletConnectors/chunk-ZASMSEC3.js +63 -0
- package/dist/wallets/walletConnectors/{chunk-G7PEFBL6.js → chunk-ZNBWRE3K.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-ZNVFM2J2.js +156 -0
- package/dist/wallets/walletConnectors/chunk-ZQLQELFC.js +309 -0
- package/dist/wallets/walletConnectors/chunk-ZR7CEF64.js +63 -0
- package/dist/wallets/walletConnectors/chunk-ZSGFDK77.js +63 -0
- package/dist/wallets/walletConnectors/chunk-ZUIY2TRJ.js +1695 -0
- package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
- package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
- package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
- package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
- package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
- package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
- package/dist/wallets/walletConnectors/index.js +55 -55
- package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
- package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
- package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
- package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
- package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
- package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
- package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
- package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
- package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
- package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
- package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
- package/package.json +12 -11
- package/LICENSE +0 -9
- package/dist/solana/hooks/index.d.ts +0 -12
- package/dist/solana/hooks/useSolanaAccount.d.ts +0 -98
- package/dist/solana/hooks/useSolanaConnection.d.ts +0 -72
- package/dist/solana/hooks/useSolanaSendTransaction.d.ts +0 -98
- package/dist/solana/hooks/useSolanaSignMessage.d.ts +0 -82
- package/dist/wallets/walletConnectors/abcWallet/abcSolProvider.d.ts +0 -45
- package/dist/wallets/walletConnectors/abcWallet/abcSolProvider.js +0 -10
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaConnector.d.ts +0 -115
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaConnector.js +0 -12
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +0 -143
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +0 -13
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWallet.d.ts +0 -18
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWallet.js +0 -15
- package/dist/wallets/walletConnectors/chunk-2XZBPMQJ.js +0 -39
- package/dist/wallets/walletConnectors/chunk-3SVPZCA6.js +0 -71
- package/dist/wallets/walletConnectors/chunk-3ZZXE7EL.js +0 -39
- package/dist/wallets/walletConnectors/chunk-5QEUEPNY.js +0 -94
- package/dist/wallets/walletConnectors/chunk-75W4VLFA.js +0 -482
- package/dist/wallets/walletConnectors/chunk-B6JLYR3I.js +0 -66
- package/dist/wallets/walletConnectors/chunk-FROV5VDF.js +0 -346
- package/dist/wallets/walletConnectors/chunk-HKWBR5B7.js +0 -102
- package/dist/wallets/walletConnectors/chunk-K4APJ4PE.js +0 -96
- package/dist/wallets/walletConnectors/chunk-LJ2B47VF.js +0 -108
- package/dist/wallets/walletConnectors/chunk-LXINMUQC.js +0 -186
- package/dist/wallets/walletConnectors/chunk-MORUEOYX.js +0 -76
- package/dist/wallets/walletConnectors/chunk-MQTXA63X.js +0 -27
- package/dist/wallets/walletConnectors/chunk-N4FOYXQD.js +0 -63
- package/dist/wallets/walletConnectors/chunk-NEXFU6BZ.js +0 -39
- package/dist/wallets/walletConnectors/chunk-PMZJGS7X.js +0 -73
- package/dist/wallets/walletConnectors/chunk-QEHZXKRF.js +0 -39
- package/dist/wallets/walletConnectors/chunk-T6KJZAPR.js +0 -47
- package/dist/wallets/walletConnectors/chunk-UBCMBPX3.js +0 -58
- package/dist/wallets/walletConnectors/chunk-UGQXI3RN.js +0 -284
- package/dist/wallets/walletConnectors/chunk-WZZVA3LW.js +0 -101
- package/dist/wallets/walletConnectors/chunk-X4WUD7PF.js +0 -63
- package/dist/wallets/walletConnectors/chunk-XOQNQKZE.js +0 -98
- package/dist/wallets/walletConnectors/chunk-XPSCFUX6.js +0 -372
- package/dist/wallets/walletConnectors/chunk-Y3LWEDF6.js +0 -63
- package/dist/wallets/walletConnectors/chunk-ZJ6OFFD5.js +0 -95
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
AbcError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RQIUWXDF.js";
|
|
5
5
|
|
|
6
6
|
// src/wallets/walletConnectors/abcWallet/walletGeneration.ts
|
|
7
7
|
async function generateMpcWallets(client, uid, hashedPin, evmChainId = 1, bitcoinNetwork = "bitcoin") {
|
|
@@ -134,7 +134,10 @@ async function generateBitcoinWallet(evmWallet, client, network) {
|
|
|
134
134
|
"bech32"
|
|
135
135
|
// Native SegWit (recommended)
|
|
136
136
|
);
|
|
137
|
-
console.log(
|
|
137
|
+
console.log(
|
|
138
|
+
"[Bitcoin] \u2705 Address generated:",
|
|
139
|
+
`${bitcoinAddress.substring(0, 6)}...${bitcoinAddress.substring(bitcoinAddress.length - 4)}`
|
|
140
|
+
);
|
|
138
141
|
return {
|
|
139
142
|
uid: evmWallet.uid,
|
|
140
143
|
sessionId: evmWallet.keyId,
|
|
@@ -178,7 +181,10 @@ async function recoverEvmWallet(client, uid, hashedPin, chainId) {
|
|
|
178
181
|
chainId
|
|
179
182
|
});
|
|
180
183
|
}
|
|
181
|
-
console.log(
|
|
184
|
+
console.log(
|
|
185
|
+
"\u2705 [EVM] Wallet recovered:",
|
|
186
|
+
`${wallet.address.substring(0, 6)}...${wallet.address.substring(wallet.address.length - 4)}`
|
|
187
|
+
);
|
|
182
188
|
return wallet;
|
|
183
189
|
} catch (error) {
|
|
184
190
|
console.error("\u274C [EVM] Recovery failed:", error.message);
|
|
@@ -202,7 +208,10 @@ async function recoverSolanaWallet(client, hashedPin) {
|
|
|
202
208
|
}
|
|
203
209
|
wallet = await solanaApi.recoverSolanaWallet(hashedPin);
|
|
204
210
|
}
|
|
205
|
-
console.log(
|
|
211
|
+
console.log(
|
|
212
|
+
"\u2705 [Solana] Wallet recovered:",
|
|
213
|
+
`${wallet.address.substring(0, 6)}...${wallet.address.substring(wallet.address.length - 4)}`
|
|
214
|
+
);
|
|
206
215
|
return wallet;
|
|
207
216
|
} catch (error) {
|
|
208
217
|
console.error("\u274C [Solana] Recovery failed:", error.message);
|
|
@@ -230,7 +239,10 @@ async function recoverBitcoinWallet(evmWallet, client, network) {
|
|
|
230
239
|
"bech32"
|
|
231
240
|
// Native SegWit (recommended)
|
|
232
241
|
);
|
|
233
|
-
console.log(
|
|
242
|
+
console.log(
|
|
243
|
+
"[Bitcoin] \u2705 Address recovered:",
|
|
244
|
+
`${bitcoinAddress.substring(0, 6)}...${bitcoinAddress.substring(bitcoinAddress.length - 4)}`
|
|
245
|
+
);
|
|
234
246
|
return {
|
|
235
247
|
uid: evmWallet.uid,
|
|
236
248
|
sessionId: evmWallet.keyId,
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
BaseApiClient
|
|
4
|
+
} from "./chunk-MPFE6GP2.js";
|
|
5
|
+
import {
|
|
6
|
+
getSolanaNetwork
|
|
7
|
+
} from "./chunk-A7FIBI6X.js";
|
|
8
|
+
import {
|
|
9
|
+
createAbcError
|
|
10
|
+
} from "./chunk-5RSS3SRV.js";
|
|
11
|
+
import {
|
|
12
|
+
ABC_ENDPOINTS,
|
|
13
|
+
DEFAULT_HEADERS
|
|
14
|
+
} from "./chunk-VETRBBA2.js";
|
|
15
|
+
|
|
16
|
+
// src/wallets/walletConnectors/abcWallet/api/WalletApi.ts
|
|
17
|
+
var WalletApi = class extends BaseApiClient {
|
|
18
|
+
/**
|
|
19
|
+
* Generate or recover EVM wallet
|
|
20
|
+
*/
|
|
21
|
+
async generateOrRecoverWallet(params) {
|
|
22
|
+
const response = await this.request(
|
|
23
|
+
// Use 'any' to get raw API response
|
|
24
|
+
ABC_ENDPOINTS.MPC_WALLETS,
|
|
25
|
+
// Use correct EVM endpoint, not WALLETS_V3 (Solana only)
|
|
26
|
+
{
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: {
|
|
29
|
+
uid: params.uid,
|
|
30
|
+
pin: params.pin,
|
|
31
|
+
chainId: params.chainId,
|
|
32
|
+
network: params.network || "mainnet"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
if (response.status === "success" && response.data) {
|
|
37
|
+
const raw = response.data;
|
|
38
|
+
console.log("[WalletApi] Raw wallet API response:", {
|
|
39
|
+
hasUid: !!raw.uid,
|
|
40
|
+
hasSid: !!raw.sid,
|
|
41
|
+
hasWid: !!raw.wid,
|
|
42
|
+
hasPvencstr: !!raw.pvencstr,
|
|
43
|
+
hasEncryptDevicePassword: !!raw.encryptDevicePassword,
|
|
44
|
+
hasPubkey: !!raw.pubkey,
|
|
45
|
+
allKeys: Object.keys(raw)
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
address: raw.address || "",
|
|
49
|
+
keyId: raw.keyId || raw.key_id || raw.sid,
|
|
50
|
+
encryptedShare: raw.encryptedShare || raw.encrypted_share || "",
|
|
51
|
+
uid: raw.uid,
|
|
52
|
+
sid: raw.sid,
|
|
53
|
+
wid: raw.wid,
|
|
54
|
+
// Preserve for Bitcoin signing
|
|
55
|
+
pvencstr: raw.pvencstr,
|
|
56
|
+
// Preserve for Bitcoin signing
|
|
57
|
+
encryptDevicePassword: raw.encryptDevicePassword,
|
|
58
|
+
// Preserve for Bitcoin signing
|
|
59
|
+
pubkey: raw.pubkey || null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
throw createAbcError(
|
|
63
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
64
|
+
"Failed to generate wallet",
|
|
65
|
+
response
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get wallet info
|
|
70
|
+
*/
|
|
71
|
+
async getWalletInfo(uid) {
|
|
72
|
+
const response = await this.request(ABC_ENDPOINTS.INFO, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
body: { uid }
|
|
75
|
+
});
|
|
76
|
+
if (response.status === "success") {
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
throw createAbcError(
|
|
80
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
81
|
+
"Failed to get wallet info",
|
|
82
|
+
response
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generate or recover Solana wallet (Ed25519)
|
|
87
|
+
*/
|
|
88
|
+
async generateSolanaWallet(pin, _isRecover = false) {
|
|
89
|
+
const url = `\${this.baseURL}/v3/wallet/\${isRecover ? 'recover' : 'generate'}`;
|
|
90
|
+
const response = await fetch(url, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: {
|
|
93
|
+
...DEFAULT_HEADERS,
|
|
94
|
+
...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
|
|
95
|
+
},
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
curve: "ed25519",
|
|
98
|
+
password: pin
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
const data = await response.json();
|
|
102
|
+
if (!response.ok || data.status !== "success") {
|
|
103
|
+
throw createAbcError(
|
|
104
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
105
|
+
"Failed to generate Solana wallet",
|
|
106
|
+
data
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const result = data.result;
|
|
110
|
+
const solanaNetwork = getSolanaNetwork();
|
|
111
|
+
const addressResult = await this.getSolanaAddress(
|
|
112
|
+
result.public_key,
|
|
113
|
+
solanaNetwork
|
|
114
|
+
);
|
|
115
|
+
return {
|
|
116
|
+
uid: result.uid || "",
|
|
117
|
+
sessionId: result.share_id,
|
|
118
|
+
shareId: result.share_id,
|
|
119
|
+
publicKey: result.public_key,
|
|
120
|
+
address: addressResult,
|
|
121
|
+
keyId: result.key_id || result.share_id,
|
|
122
|
+
encryptedShare: result.encrypted_share || "",
|
|
123
|
+
network: solanaNetwork
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get Solana address from Ed25519 public key
|
|
128
|
+
*/
|
|
129
|
+
async getSolanaAddress(publicKey, network) {
|
|
130
|
+
const url = "${this.baseURL}/wapi/v2/solana/wallet/getAddress";
|
|
131
|
+
const response = await fetch(url, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: {
|
|
134
|
+
...DEFAULT_HEADERS,
|
|
135
|
+
...this.accessToken ? { Authorization: "Bearer ${this.accessToken}" } : {}
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify({
|
|
138
|
+
network,
|
|
139
|
+
publicKey
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
const data = await response.json();
|
|
143
|
+
if (!response.ok || data.status !== "success") {
|
|
144
|
+
throw createAbcError(
|
|
145
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
146
|
+
"Failed to get Solana address",
|
|
147
|
+
data
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return data.result?.data?.address;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
WalletApi
|
|
156
|
+
};
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
BaseApiClient
|
|
4
|
+
} from "./chunk-MPFE6GP2.js";
|
|
5
|
+
import {
|
|
6
|
+
createAbcError
|
|
7
|
+
} from "./chunk-5RSS3SRV.js";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_HEADERS
|
|
10
|
+
} from "./chunk-VETRBBA2.js";
|
|
11
|
+
|
|
12
|
+
// src/wallets/walletConnectors/abcWallet/api/BitcoinApi.ts
|
|
13
|
+
var BitcoinApi = class extends BaseApiClient {
|
|
14
|
+
/**
|
|
15
|
+
* Generate Bitcoin wallet
|
|
16
|
+
* Uses V3 API with secp256k1 curve (same as EVM but compressed public key)
|
|
17
|
+
*
|
|
18
|
+
* @param pin - Hashed PIN (SHA-256)
|
|
19
|
+
* @param network - Bitcoin network (mainnet or testnet)
|
|
20
|
+
* @param addressType - Bitcoin address type (bech32 recommended)
|
|
21
|
+
* @returns Bitcoin wallet information
|
|
22
|
+
*/
|
|
23
|
+
async generateBitcoinWallet(pin, network = "bitcoin", addressType = "bech32") {
|
|
24
|
+
console.log("[BitcoinApi] \u{1F527} Generating Bitcoin wallet...", {
|
|
25
|
+
network,
|
|
26
|
+
addressType
|
|
27
|
+
});
|
|
28
|
+
const response = await this.request("/v3/wallet/generate", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
contentType: "json",
|
|
31
|
+
body: {
|
|
32
|
+
curve: "secp256k1",
|
|
33
|
+
// Same as EVM but compressed public key
|
|
34
|
+
password: pin,
|
|
35
|
+
network
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (response.status !== "success" || !response.result) {
|
|
39
|
+
console.error("[BitcoinApi] \u274C Generation failed:", response);
|
|
40
|
+
throw createAbcError(
|
|
41
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
42
|
+
"Failed to generate Bitcoin wallet",
|
|
43
|
+
response
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const result = response.result;
|
|
47
|
+
const addressResult = await this.getBitcoinAddress(
|
|
48
|
+
result.public_key,
|
|
49
|
+
network,
|
|
50
|
+
addressType
|
|
51
|
+
);
|
|
52
|
+
console.log(
|
|
53
|
+
"[BitcoinApi] \u2705 Bitcoin wallet generated:",
|
|
54
|
+
`${addressResult.substring(0, 6)}...${addressResult.substring(addressResult.length - 4)}`
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
uid: result.uid || "",
|
|
58
|
+
sessionId: result.share_id,
|
|
59
|
+
shareId: result.share_id,
|
|
60
|
+
publicKey: result.public_key,
|
|
61
|
+
// Compressed (33 bytes, 0x02 or 0x03 prefix)
|
|
62
|
+
address: addressResult,
|
|
63
|
+
addressType,
|
|
64
|
+
keyId: result.key_id || result.share_id,
|
|
65
|
+
encryptedShare: result.encrypted_share || "",
|
|
66
|
+
network
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Recover Bitcoin wallet
|
|
71
|
+
* Uses V3 API wallet recovery endpoint
|
|
72
|
+
*
|
|
73
|
+
* @param pin - Hashed PIN (SHA-256)
|
|
74
|
+
* @param network - Bitcoin network
|
|
75
|
+
* @param addressType - Bitcoin address type
|
|
76
|
+
* @returns Recovered Bitcoin wallet information
|
|
77
|
+
*/
|
|
78
|
+
async recoverBitcoinWallet(pin, network = "bitcoin", addressType = "bech32") {
|
|
79
|
+
console.log("[BitcoinApi] \u{1F527} Recovering Bitcoin wallet...", {
|
|
80
|
+
network,
|
|
81
|
+
addressType
|
|
82
|
+
});
|
|
83
|
+
const response = await this.request("/v3/wallet/recover", {
|
|
84
|
+
method: "POST",
|
|
85
|
+
contentType: "json",
|
|
86
|
+
body: {
|
|
87
|
+
curve: "secp256k1",
|
|
88
|
+
password: pin,
|
|
89
|
+
network
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (response.status !== "success" || !response.result) {
|
|
93
|
+
console.error("[BitcoinApi] \u274C Recovery failed:", response);
|
|
94
|
+
throw createAbcError(
|
|
95
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
96
|
+
"Failed to recover Bitcoin wallet",
|
|
97
|
+
response
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const result = response.result;
|
|
101
|
+
const addressResult = await this.getBitcoinAddress(
|
|
102
|
+
result.public_key,
|
|
103
|
+
network,
|
|
104
|
+
addressType
|
|
105
|
+
);
|
|
106
|
+
console.log(
|
|
107
|
+
"[BitcoinApi] \u2705 Bitcoin wallet recovered:",
|
|
108
|
+
`${addressResult.substring(0, 6)}...${addressResult.substring(addressResult.length - 4)}`
|
|
109
|
+
);
|
|
110
|
+
return {
|
|
111
|
+
uid: result.uid || "",
|
|
112
|
+
sessionId: result.share_id,
|
|
113
|
+
shareId: result.share_id,
|
|
114
|
+
publicKey: result.public_key,
|
|
115
|
+
address: addressResult,
|
|
116
|
+
addressType,
|
|
117
|
+
keyId: result.key_id || result.share_id,
|
|
118
|
+
encryptedShare: result.encrypted_share || "",
|
|
119
|
+
network
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get Bitcoin address from compressed public key
|
|
124
|
+
* Converts compressed public key to Bitcoin address based on address type
|
|
125
|
+
*
|
|
126
|
+
* @param publicKey - Compressed public key (33 bytes, hex)
|
|
127
|
+
* @param network - Bitcoin network
|
|
128
|
+
* @param addressType - Address format type (currently not used by API)
|
|
129
|
+
* @returns Bitcoin address
|
|
130
|
+
*/
|
|
131
|
+
async getBitcoinAddress(publicKey, network, _addressType = "bech32") {
|
|
132
|
+
const url = `${this.baseURL}/wapi/v2/btc/address`;
|
|
133
|
+
const params = new URLSearchParams({
|
|
134
|
+
pubkey: publicKey,
|
|
135
|
+
network
|
|
136
|
+
});
|
|
137
|
+
const response = await fetch(`${url}?${params}`, {
|
|
138
|
+
method: "GET",
|
|
139
|
+
headers: {
|
|
140
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const data = await response.json();
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
throw createAbcError(
|
|
146
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
147
|
+
"Failed to get Bitcoin address",
|
|
148
|
+
data
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return data.address;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get UTXOs (Unspent Transaction Outputs) for address
|
|
155
|
+
* Bitcoin uses UTXO model unlike EVM/Solana account model
|
|
156
|
+
*
|
|
157
|
+
* @param address - Bitcoin address
|
|
158
|
+
* @param network - Bitcoin network
|
|
159
|
+
* @returns Array of UTXOs
|
|
160
|
+
*/
|
|
161
|
+
async getUtxos(address, network) {
|
|
162
|
+
console.log(
|
|
163
|
+
"[BitcoinApi] \u{1F50D} Fetching UTXOs for:",
|
|
164
|
+
`${address.substring(0, 6)}...${address.substring(address.length - 4)}`
|
|
165
|
+
);
|
|
166
|
+
const url = `${this.baseURL}/wapi/v2/bitcoin/utxo/list`;
|
|
167
|
+
const params = new URLSearchParams({ network, address });
|
|
168
|
+
console.log("[BitcoinApi] \u{1F50D} Fetching UTXOs for:", address);
|
|
169
|
+
const response = await fetch(`${url}?${params}`, {
|
|
170
|
+
method: "GET",
|
|
171
|
+
headers: {
|
|
172
|
+
...DEFAULT_HEADERS,
|
|
173
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const data = await response.json();
|
|
177
|
+
if (!response.ok || data.status !== "success") {
|
|
178
|
+
throw createAbcError(
|
|
179
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
180
|
+
"Failed to get UTXOs",
|
|
181
|
+
data
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const utxos = data.result?.utxos || [];
|
|
185
|
+
console.log(`[BitcoinApi] \u2705 Found ${utxos.length} UTXOs`);
|
|
186
|
+
return utxos;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Send Bitcoin transaction
|
|
190
|
+
* Broadcasts signed transaction to Bitcoin network
|
|
191
|
+
*
|
|
192
|
+
* @param params - Transaction broadcast parameters
|
|
193
|
+
* @returns Transaction hash
|
|
194
|
+
*/
|
|
195
|
+
async sendBitcoinTransaction(params) {
|
|
196
|
+
const url = `${this.baseURL}/wapi/v2/bitcoin/tx/sendTransaction`;
|
|
197
|
+
console.log("[BitcoinApi] \u{1F4E1} Broadcasting Bitcoin transaction...");
|
|
198
|
+
const response = await fetch(url, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers: {
|
|
201
|
+
...DEFAULT_HEADERS,
|
|
202
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
203
|
+
},
|
|
204
|
+
body: JSON.stringify({
|
|
205
|
+
network: params.network,
|
|
206
|
+
rawTransaction: params.rawTransaction,
|
|
207
|
+
...params.psbt && { psbt: params.psbt }
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
const data = await response.json();
|
|
211
|
+
if (!response.ok || data.status !== "success") {
|
|
212
|
+
console.error("[BitcoinApi] \u274C Transaction broadcast failed:", data);
|
|
213
|
+
throw createAbcError(
|
|
214
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
215
|
+
"Failed to send Bitcoin transaction",
|
|
216
|
+
data
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
const txHash = data.result?.data;
|
|
220
|
+
console.log("[BitcoinApi] \u2705 Transaction broadcasted:", txHash);
|
|
221
|
+
return {
|
|
222
|
+
txHash
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Generate Bitcoin transaction (Step 1 of 3)
|
|
227
|
+
* Creates PSBT and returns hashes to sign
|
|
228
|
+
*
|
|
229
|
+
* @param params - Transaction parameters
|
|
230
|
+
* @returns Transaction data with hashes to sign
|
|
231
|
+
*/
|
|
232
|
+
async generateTransaction(params) {
|
|
233
|
+
const url = `${this.baseURL}/wapi/v2/btc/transaction/generate`;
|
|
234
|
+
console.log("[BitcoinApi] \u{1F527} Generating transaction...", params);
|
|
235
|
+
const response = await fetch(url, {
|
|
236
|
+
method: "POST",
|
|
237
|
+
headers: {
|
|
238
|
+
"Content-Type": "application/json",
|
|
239
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
240
|
+
},
|
|
241
|
+
body: JSON.stringify(params)
|
|
242
|
+
});
|
|
243
|
+
const data = await response.json();
|
|
244
|
+
if (!response.ok || !data.hashes) {
|
|
245
|
+
const errorMsg = typeof data.error === "string" ? data.error : JSON.stringify(data.error || data);
|
|
246
|
+
console.error("[BitcoinApi] \u274C Generate failed:", errorMsg);
|
|
247
|
+
throw createAbcError(
|
|
248
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
249
|
+
`Failed to generate transaction: ${errorMsg}`,
|
|
250
|
+
data
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
console.log(
|
|
254
|
+
`[BitcoinApi] \u2705 Generated ${data.hashes.length} hashes to sign`
|
|
255
|
+
);
|
|
256
|
+
return data;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Sign transaction hash (Step 2 of 3)
|
|
260
|
+
* Uses Secure Channel encryption for signing
|
|
261
|
+
* Based on tg-wallet-frontend reference implementation
|
|
262
|
+
*
|
|
263
|
+
* @param hash - Transaction hash to sign
|
|
264
|
+
* @param wallet - Full wallet object with Bitcoin signing fields
|
|
265
|
+
* @param pinHash - Hashed PIN for device password
|
|
266
|
+
* @param secureService - Secure service instance for encryption
|
|
267
|
+
* @returns Signature hex string (r + s without 0x prefix on s)
|
|
268
|
+
*/
|
|
269
|
+
async signHash(hash, wallet, pinHash, secureService) {
|
|
270
|
+
console.log("[BitcoinApi] \u{1F510} Signing hash:", `${hash.substring(0, 20)}...`);
|
|
271
|
+
if (!wallet.wid || !wallet.pvencstr) {
|
|
272
|
+
console.error("[BitcoinApi] \u274C Missing Bitcoin signing fields:", {
|
|
273
|
+
hasWid: !!wallet.wid,
|
|
274
|
+
hasPvencstr: !!wallet.pvencstr,
|
|
275
|
+
hasSid: !!wallet.sid,
|
|
276
|
+
hasUid: !!wallet.uid
|
|
277
|
+
});
|
|
278
|
+
throw createAbcError(
|
|
279
|
+
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
280
|
+
"Wallet missing required fields for Bitcoin signing (wid, pvencstr)",
|
|
281
|
+
{ hasWid: !!wallet.wid, hasPvencstr: !!wallet.pvencstr }
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
const encryptDevicePassword = await secureService.getEncryptPlain(
|
|
285
|
+
wallet.encryptDevicePassword || pinHash
|
|
286
|
+
);
|
|
287
|
+
const pvencstr = await secureService.getEncryptPlain(wallet.pvencstr);
|
|
288
|
+
const wid = await secureService.getEncryptPlain(wallet.wid);
|
|
289
|
+
const secureChannelId = await secureService.getSecureChannelId();
|
|
290
|
+
const params = new URLSearchParams({
|
|
291
|
+
uid: wallet.uid,
|
|
292
|
+
sid: wallet.sid || "",
|
|
293
|
+
// Handle optional sid
|
|
294
|
+
hash,
|
|
295
|
+
pvencstr,
|
|
296
|
+
wid,
|
|
297
|
+
encryptDevicePassword
|
|
298
|
+
});
|
|
299
|
+
const url = `${this.baseURL}/wapi/v2/sign/hash`;
|
|
300
|
+
const response = await fetch(url, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: {
|
|
303
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
304
|
+
"Secure-Channel": secureChannelId,
|
|
305
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
306
|
+
},
|
|
307
|
+
body: params.toString()
|
|
308
|
+
});
|
|
309
|
+
const responseText = await response.text();
|
|
310
|
+
if (!responseText) {
|
|
311
|
+
throw createAbcError(
|
|
312
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
313
|
+
"Empty response from sign hash API",
|
|
314
|
+
{ status: response.status }
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
let data;
|
|
318
|
+
try {
|
|
319
|
+
data = JSON.parse(responseText);
|
|
320
|
+
} catch (parseError) {
|
|
321
|
+
console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
|
|
322
|
+
throw createAbcError(
|
|
323
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
324
|
+
"Invalid JSON response from sign hash API",
|
|
325
|
+
{ responseText, parseError }
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
if (!response.ok || data.iserr === true || !data.signstr) {
|
|
329
|
+
const errorDetails = data.errmsg || data.errors?.[0] || data.message || data;
|
|
330
|
+
console.error("[BitcoinApi] \u274C Sign failed:", errorDetails);
|
|
331
|
+
throw createAbcError(
|
|
332
|
+
"SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
|
|
333
|
+
`Failed to sign hash: ${JSON.stringify(errorDetails)}`,
|
|
334
|
+
data
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
const signstr = JSON.parse(data.signstr);
|
|
338
|
+
const sig_list = signstr.sig_list;
|
|
339
|
+
const signatures = [];
|
|
340
|
+
for (const sig of sig_list) {
|
|
341
|
+
const r = sig.r;
|
|
342
|
+
const s = sig.s.startsWith("0x") ? sig.s.substring(2) : sig.s;
|
|
343
|
+
const combinedSig = r + s;
|
|
344
|
+
signatures.push(combinedSig);
|
|
345
|
+
}
|
|
346
|
+
console.log(
|
|
347
|
+
"[BitcoinApi] \u2705 Signature generated:",
|
|
348
|
+
`${signatures[0].substring(0, 32)}...`
|
|
349
|
+
);
|
|
350
|
+
return signatures[0];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Finalize and broadcast transaction (Step 3 of 3)
|
|
354
|
+
* Broadcasts signed transaction to Bitcoin network
|
|
355
|
+
*
|
|
356
|
+
* @param params - Transaction parameters with signatures
|
|
357
|
+
* @returns Transaction hash
|
|
358
|
+
*/
|
|
359
|
+
async finalizeTransaction(params) {
|
|
360
|
+
const url = `${this.baseURL}/wapi/v2/btc/transaction/finalize`;
|
|
361
|
+
const response = await fetch(url, {
|
|
362
|
+
method: "POST",
|
|
363
|
+
headers: {
|
|
364
|
+
"Content-Type": "application/json",
|
|
365
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
366
|
+
},
|
|
367
|
+
body: JSON.stringify(params)
|
|
368
|
+
});
|
|
369
|
+
const responseText = await response.text();
|
|
370
|
+
if (!responseText) {
|
|
371
|
+
throw createAbcError(
|
|
372
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
373
|
+
"Empty response from finalize API",
|
|
374
|
+
{ status: response.status }
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
let data;
|
|
378
|
+
try {
|
|
379
|
+
data = JSON.parse(responseText);
|
|
380
|
+
} catch (parseError) {
|
|
381
|
+
console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
|
|
382
|
+
throw createAbcError(
|
|
383
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
384
|
+
"Invalid JSON response from finalize API",
|
|
385
|
+
{ responseText, parseError }
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
const errorMsg = data.error || data.message || data.errmsg || "Unknown error";
|
|
390
|
+
console.error("[BitcoinApi] \u274C Finalize failed:", errorMsg);
|
|
391
|
+
throw createAbcError(
|
|
392
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
393
|
+
`Failed to finalize transaction: ${errorMsg}`,
|
|
394
|
+
data
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
const txHash = data.result?.tx_hash || data.tx_hash || data.result?.txHash || data.txHash;
|
|
398
|
+
if (!txHash) {
|
|
399
|
+
console.error("[BitcoinApi] \u274C No tx_hash in response:", data);
|
|
400
|
+
throw createAbcError(
|
|
401
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
402
|
+
"Transaction hash not found in response",
|
|
403
|
+
data
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
console.log("[BitcoinApi] \u2705 Transaction sent:", txHash);
|
|
407
|
+
return txHash;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Send Bitcoin transaction (Complete flow: generate → sign → finalize)
|
|
411
|
+
* High-level API that handles all 3 steps
|
|
412
|
+
*
|
|
413
|
+
* @param params - Transaction parameters
|
|
414
|
+
* @param wallet - EVM wallet credentials
|
|
415
|
+
* @param pinHash - Hashed PIN
|
|
416
|
+
* @param secureService - Secure service instance
|
|
417
|
+
* @returns Transaction hash
|
|
418
|
+
*/
|
|
419
|
+
async sendTransaction(params, wallet, pinHash, secureService) {
|
|
420
|
+
console.log("[BitcoinApi] \u{1F4B8} Starting Bitcoin transaction flow...");
|
|
421
|
+
const generateData = await this.generateTransaction({
|
|
422
|
+
amount: params.amount,
|
|
423
|
+
pubkey: params.pubkey,
|
|
424
|
+
to: params.to,
|
|
425
|
+
feeRate: "2"
|
|
426
|
+
// Default fee rate
|
|
427
|
+
});
|
|
428
|
+
const { hashes, fee_rate } = generateData;
|
|
429
|
+
const signatureHex = [];
|
|
430
|
+
for (let i = 0; i < hashes.length; i++) {
|
|
431
|
+
const signature = await this.signHash(
|
|
432
|
+
hashes[i],
|
|
433
|
+
wallet,
|
|
434
|
+
pinHash,
|
|
435
|
+
secureService
|
|
436
|
+
);
|
|
437
|
+
signatureHex.push(signature);
|
|
438
|
+
}
|
|
439
|
+
const txHash = await this.finalizeTransaction({
|
|
440
|
+
network: params.network,
|
|
441
|
+
signatureHex,
|
|
442
|
+
feeRate: fee_rate,
|
|
443
|
+
amount: params.amount,
|
|
444
|
+
pubkey: params.pubkey,
|
|
445
|
+
to: params.to
|
|
446
|
+
});
|
|
447
|
+
console.log("[BitcoinApi] \u2705 Transaction complete:", txHash);
|
|
448
|
+
return txHash;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Estimate Bitcoin transaction fee
|
|
452
|
+
* Gets recommended fee rate (satoshis per byte) for target confirmation blocks
|
|
453
|
+
*
|
|
454
|
+
* @param network - Bitcoin network
|
|
455
|
+
* @param targetBlocks - Target confirmation blocks (default: 6)
|
|
456
|
+
* @returns Fee rate in satoshis per byte
|
|
457
|
+
*/
|
|
458
|
+
async estimateFee(network, targetBlocks = 6) {
|
|
459
|
+
const url = `${this.baseURL}/wapi/v2/bitcoin/fee/estimate`;
|
|
460
|
+
const params = new URLSearchParams({
|
|
461
|
+
network,
|
|
462
|
+
targetBlocks: targetBlocks.toString()
|
|
463
|
+
});
|
|
464
|
+
const response = await fetch(`${url}?${params}`, {
|
|
465
|
+
method: "GET",
|
|
466
|
+
headers: {
|
|
467
|
+
...DEFAULT_HEADERS,
|
|
468
|
+
...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
const data = await response.json();
|
|
472
|
+
if (!response.ok || data.status !== "success") {
|
|
473
|
+
console.warn("[BitcoinApi] \u26A0\uFE0F Fee estimation failed, using fallback");
|
|
474
|
+
return 1;
|
|
475
|
+
}
|
|
476
|
+
const feeRate = data.result?.feeRate || 1;
|
|
477
|
+
console.log(`[BitcoinApi] \u26FD Estimated fee rate: ${feeRate} sat/byte`);
|
|
478
|
+
return feeRate;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
export {
|
|
483
|
+
BitcoinApi
|
|
484
|
+
};
|