@talken/talkenkit 2.3.7 → 2.3.8

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 (194) hide show
  1. package/LICENSE +9 -0
  2. package/dist/Arc-ILTINY4C.js +8 -0
  3. package/dist/Brave-4L5B7JJR.js +8 -0
  4. package/dist/Browser-XMB4J5WD.js +8 -0
  5. package/dist/Chrome-6ZDQIHC5.js +8 -0
  6. package/dist/Edge-OAWCEU7H.js +8 -0
  7. package/dist/Firefox-O66FZK3V.js +8 -0
  8. package/dist/Linux-NUJF4EPC.js +8 -0
  9. package/dist/Macos-46EJ2NPK.js +8 -0
  10. package/dist/Opera-KTUB3UWN.js +8 -0
  11. package/dist/Safari-A3Q6PIT2.js +8 -0
  12. package/dist/Windows-NL32NG52.js +8 -0
  13. package/dist/abcWallet-ES4OPRSK.js +8 -0
  14. package/dist/ar_AR-YBBYUEGS.js +8 -0
  15. package/dist/arbitrum-D2TUFPZI.js +8 -0
  16. package/dist/argentWallet-A5HM5FRP.js +8 -0
  17. package/dist/assets-4NDWRKXE.js +8 -0
  18. package/dist/avalanche-BOOSH35S.js +8 -0
  19. package/dist/base-3JMRS35B.js +8 -0
  20. package/dist/berasigWallet-6IOU73YL.js +8 -0
  21. package/dist/bestWallet-6LJUU6OL.js +8 -0
  22. package/dist/bifrostWallet-SLPPXZ2K.js +8 -0
  23. package/dist/binanceWallet-Z67J7362.js +8 -0
  24. package/dist/bitgetWallet-DLLOWMCI.js +8 -0
  25. package/dist/bitskiWallet-CPOXGABT.js +8 -0
  26. package/dist/bitverseWallet-SAK4MIS6.js +8 -0
  27. package/dist/blast-4GF24NR7.js +8 -0
  28. package/dist/bloomWallet-YIRCNQZJ.js +8 -0
  29. package/dist/braveWallet-PNBKQKJC.js +8 -0
  30. package/dist/bsc-KU6MBOYR.js +8 -0
  31. package/dist/bybitWallet-GCDBAJKO.js +8 -0
  32. package/dist/celo-5A5VXMPX.js +8 -0
  33. package/dist/chunk-TJX4M23U.js +27 -0
  34. package/dist/clvWallet-R6YRCMZO.js +8 -0
  35. package/dist/coin98Wallet-4Y3ROAGP.js +8 -0
  36. package/dist/coinbaseWallet-L4QDZB5W.js +8 -0
  37. package/dist/compassWallet-NNBX35AV.js +8 -0
  38. package/dist/components/ConnectButton/ConnectButtonRenderer.d.ts +1 -1
  39. package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +1 -1
  40. package/dist/config/networks.d.ts +125 -0
  41. package/dist/connect-Q2RLUT5B.js +8 -0
  42. package/dist/contexts/index.d.ts +2 -2
  43. package/dist/coreWallet-PN2LMNGN.js +8 -0
  44. package/dist/create-HQ4QXTKY.js +8 -0
  45. package/dist/cronos-KZAB32FC.js +8 -0
  46. package/dist/dawnWallet-AMO43DL3.js +8 -0
  47. package/dist/de_DE-RUWMVYCQ.js +8 -0
  48. package/dist/desigWallet-AD335WX5.js +8 -0
  49. package/dist/en_US-NQ25CUR4.js +8 -0
  50. package/dist/enkryptWallet-OOP27GE2.js +8 -0
  51. package/dist/es_419-HKJPYJRI.js +8 -0
  52. package/dist/ethereum-WAFT6DML.js +8 -0
  53. package/dist/flow-XANNOAPJ.js +8 -0
  54. package/dist/foxWallet-UDUWOW52.js +8 -0
  55. package/dist/fr_FR-2O5ZDLPQ.js +1356 -0
  56. package/dist/frameWallet-BEABTFIT.js +8 -0
  57. package/dist/frontierWallet-RG47M3C5.js +8 -0
  58. package/dist/gateWallet-XOP74BMB.js +8 -0
  59. package/dist/gnosis-7GFI4V27.js +8 -0
  60. package/dist/hardhat-6HKZWC4T.js +8 -0
  61. package/dist/hi_IN-XRZ4YIUW.js +8 -0
  62. package/dist/id_ID-REEY4CSS.js +8 -0
  63. package/dist/imTokenWallet-LTPKXYUD.js +8 -0
  64. package/dist/index.d.ts +5 -1
  65. package/dist/index.js +1114 -403
  66. package/dist/injectedWallet-YCFZTULL.js +8 -0
  67. package/dist/iopayWallet-XS37QAUO.js +8 -0
  68. package/dist/ja_JP-2OPCVN6X.js +8 -0
  69. package/dist/kaia-DQ3OSYXE.js +8 -0
  70. package/dist/kaiaWallet-2XZDQZ63.js +8 -0
  71. package/dist/kaikasWallet-V2GCFPEB.js +8 -0
  72. package/dist/ko_KR-DDXBZTYT.js +8 -0
  73. package/dist/krakenWallet-3VM7ZM2O.js +8 -0
  74. package/dist/kresusWallet-4MXFQP4P.js +8 -0
  75. package/dist/ledgerWallet-YC3HF3NJ.js +8 -0
  76. package/dist/login-DGIK764Z.js +8 -0
  77. package/dist/magicEden-BLYGUG47.js +8 -0
  78. package/dist/manta-OEF3QP66.js +8 -0
  79. package/dist/mantle-EYIH4GGM.js +8 -0
  80. package/dist/metaMaskWallet-ZZMFVM52.js +8 -0
  81. package/dist/mewWallet-D6JN37EZ.js +8 -0
  82. package/dist/ms_MY-PX7G4XTD.js +8 -0
  83. package/dist/nestWallet-X3CDHKNV.js +8 -0
  84. package/dist/oktoWallet-ZYLL2RLN.js +8 -0
  85. package/dist/okxWallet-FLICEG4S.js +8 -0
  86. package/dist/omniWallet-DAQHKHUN.js +8 -0
  87. package/dist/oneInchWallet-BRGGUXND.js +8 -0
  88. package/dist/oneKeyWallet-KDU2JIFD.js +8 -0
  89. package/dist/optimism-6GXRYJDW.js +8 -0
  90. package/dist/paraSwapWallet-7UHWT54G.js +8 -0
  91. package/dist/phantomWallet-BSCGZT6L.js +8 -0
  92. package/dist/polygon-YNJM552P.js +8 -0
  93. package/dist/pt_BR-A5R4SBSC.js +8 -0
  94. package/dist/rabbyWallet-RZIUL3YN.js +8 -0
  95. package/dist/rainbowWallet-4ALDT5ZL.js +8 -0
  96. package/dist/ramperWallet-IB3JRE2F.js +8 -0
  97. package/dist/refresh-R5NYTT3S.js +8 -0
  98. package/dist/ronin-LU7LZPWA.js +8 -0
  99. package/dist/roninWallet-BS7VDK7U.js +8 -0
  100. package/dist/ru_RU-4QDZLRSW.js +1356 -0
  101. package/dist/safeWallet-5NR62MJV.js +8 -0
  102. package/dist/safeheronWallet-7ELUSU44.js +8 -0
  103. package/dist/safepalWallet-CZJABQ5N.js +8 -0
  104. package/dist/scan-BVZ7DVJ4.js +8 -0
  105. package/dist/scroll-XRP46UTI.js +8 -0
  106. package/dist/secure-GEK7TTJY.js +8 -0
  107. package/dist/seifWallet-XLBMTX4R.js +8 -0
  108. package/dist/sign-PREOQ4RR.js +8 -0
  109. package/dist/solana/SolanaWalletProvider.d.ts +1 -1
  110. package/dist/subWallet-47USA4OE.js +8 -0
  111. package/dist/tahoWallet-N3XXJ3NW.js +8 -0
  112. package/dist/talismanWallet-SV3B42TQ.js +8 -0
  113. package/dist/th_TH-4TWPYDKX.js +1356 -0
  114. package/dist/themes/baseTheme.js +1 -0
  115. package/dist/themes/darkTheme.js +1 -0
  116. package/dist/themes/lightTheme.js +1 -0
  117. package/dist/themes/midnightTheme.js +1 -0
  118. package/dist/tokenPocketWallet-7IYW3MIL.js +8 -0
  119. package/dist/tokenaryWallet-7D2LN65X.js +8 -0
  120. package/dist/tr_TR-C37KIU7M.js +1356 -0
  121. package/dist/trustWallet-HJQBMBC6.js +8 -0
  122. package/dist/uk_UA-I77HS4GO.js +1356 -0
  123. package/dist/uniswapWallet-JZ2ULELN.js +8 -0
  124. package/dist/utils/abcWaasAdapter.d.ts +75 -0
  125. package/dist/valoraWallet-PCTL6UBB.js +8 -0
  126. package/dist/vi_VN-KVPDLW26.js +8 -0
  127. package/dist/walletConnectWallet-AJ36XVBT.js +8 -0
  128. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +11 -8
  129. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +1 -1
  130. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +4 -11
  131. package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
  132. package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.d.ts +1 -19
  133. package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +1 -1
  134. package/dist/wallets/walletConnectors/abcWallet/api/index.js +6 -6
  135. package/dist/wallets/walletConnectors/abcWallet/index.js +6 -6
  136. package/dist/wallets/walletConnectors/abcWallet/types.d.ts +2 -0
  137. package/dist/wallets/walletConnectors/chunk-2GIBC7XF.js +39 -0
  138. package/dist/wallets/walletConnectors/chunk-2J66VMY5.js +152 -0
  139. package/dist/wallets/walletConnectors/chunk-34WMJDUY.js +481 -0
  140. package/dist/wallets/walletConnectors/chunk-3J3XZMJ7.js +39 -0
  141. package/dist/wallets/walletConnectors/chunk-4IRVZPIN.js +63 -0
  142. package/dist/wallets/walletConnectors/chunk-5OFAP55G.js +44 -0
  143. package/dist/wallets/walletConnectors/chunk-6YPK343Z.js +63 -0
  144. package/dist/wallets/walletConnectors/chunk-7P5HZGEV.js +627 -0
  145. package/dist/wallets/walletConnectors/chunk-A6LBRVGP.js +63 -0
  146. package/dist/wallets/walletConnectors/chunk-BKXPGZMQ.js +228 -0
  147. package/dist/wallets/walletConnectors/chunk-CNHVIXPV.js +228 -0
  148. package/dist/wallets/walletConnectors/chunk-DAZZIITX.js +1678 -0
  149. package/dist/wallets/walletConnectors/chunk-ESRU5KCF.js +151 -0
  150. package/dist/wallets/walletConnectors/chunk-F4JFONDA.js +601 -0
  151. package/dist/wallets/walletConnectors/chunk-GXHCAEWR.js +63 -0
  152. package/dist/wallets/walletConnectors/chunk-HDYBRMYW.js +194 -0
  153. package/dist/wallets/walletConnectors/chunk-HOE4UOHR.js +514 -0
  154. package/dist/wallets/walletConnectors/chunk-JJAJOFZI.js +63 -0
  155. package/dist/wallets/walletConnectors/chunk-KFIUFVQH.js +624 -0
  156. package/dist/wallets/walletConnectors/chunk-KFROJI25.js +535 -0
  157. package/dist/wallets/walletConnectors/chunk-KHVILXGK.js +514 -0
  158. package/dist/wallets/walletConnectors/chunk-LGT7LQAJ.js +63 -0
  159. package/dist/wallets/walletConnectors/chunk-LHBQ2Z3Q.js +63 -0
  160. package/dist/wallets/walletConnectors/chunk-M76GLEFL.js +63 -0
  161. package/dist/wallets/walletConnectors/chunk-MFIE6UCG.js +63 -0
  162. package/dist/wallets/walletConnectors/chunk-NKJLO4QH.js +39 -0
  163. package/dist/wallets/walletConnectors/chunk-NURTFXQU.js +568 -0
  164. package/dist/wallets/walletConnectors/chunk-NWDLOM7Q.js +646 -0
  165. package/dist/wallets/walletConnectors/chunk-OHRTTVNJ.js +44 -0
  166. package/dist/wallets/walletConnectors/chunk-OMYDLPUM.js +63 -0
  167. package/dist/wallets/walletConnectors/chunk-P2MTINFI.js +280 -0
  168. package/dist/wallets/walletConnectors/chunk-PUFQKZA7.js +63 -0
  169. package/dist/wallets/walletConnectors/chunk-RLBGBBIO.js +309 -0
  170. package/dist/wallets/walletConnectors/chunk-S2B56ZVJ.js +481 -0
  171. package/dist/wallets/walletConnectors/chunk-SFP47DS6.js +63 -0
  172. package/dist/wallets/walletConnectors/chunk-SNZL5LJ6.js +637 -0
  173. package/dist/wallets/walletConnectors/chunk-SPR4W5TG.js +474 -0
  174. package/dist/wallets/walletConnectors/chunk-SSDCG5BG.js +63 -0
  175. package/dist/wallets/walletConnectors/chunk-TUUNSVKZ.js +345 -0
  176. package/dist/wallets/walletConnectors/chunk-U2CUEL35.js +240 -0
  177. package/dist/wallets/walletConnectors/chunk-VLEVJVJR.js +63 -0
  178. package/dist/wallets/walletConnectors/chunk-W2VDZD74.js +478 -0
  179. package/dist/wallets/walletConnectors/chunk-WAO3KL5U.js +285 -0
  180. package/dist/wallets/walletConnectors/chunk-WYSKBMHW.js +280 -0
  181. package/dist/wallets/walletConnectors/chunk-XYPR4BAF.js +436 -0
  182. package/dist/wallets/walletConnectors/index.js +58 -58
  183. package/dist/wigwamWallet-D3MVGB5Z.js +8 -0
  184. package/dist/xdc-5NQHQJE5.js +8 -0
  185. package/dist/xdefiWallet-B4O6HAIP.js +8 -0
  186. package/dist/zealWallet-6SPNICRX.js +8 -0
  187. package/dist/zerionWallet-XZ3JCAOO.js +8 -0
  188. package/dist/zetachain-U6IILKZJ.js +8 -0
  189. package/dist/zh_CN-KGLAIP3N.js +8 -0
  190. package/dist/zh_HK-AEXEN6P6.js +8 -0
  191. package/dist/zh_TW-6C7R5V3K.js +8 -0
  192. package/dist/zkSync-TMPB52ZN.js +8 -0
  193. package/dist/zora-S46CHEOU.js +8 -0
  194. package/package.json +11 -12
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import {
3
+ SigningApi
4
+ } from "./chunk-4UGXLYKP.js";
5
+ import {
6
+ WalletApi
7
+ } from "./chunk-JBRW4UTW.js";
8
+ import {
9
+ AuthApi
10
+ } from "./chunk-W7R3JGSC.js";
11
+ import {
12
+ SolanaApi
13
+ } from "./chunk-DMRM7XAS.js";
14
+ import {
15
+ TransactionApi
16
+ } from "./chunk-KD2OAMDA.js";
17
+ import {
18
+ BitcoinApi
19
+ } from "./chunk-NWDLOM7Q.js";
20
+
21
+ // src/wallets/walletConnectors/abcWallet/api/index.ts
22
+ var AbcWaasApiClient = class {
23
+ constructor(config) {
24
+ this.auth = new AuthApi(config);
25
+ this.wallet = new WalletApi(config);
26
+ this.transaction = new TransactionApi(config);
27
+ this.signing = new SigningApi(config);
28
+ this.solana = new SolanaApi(config);
29
+ this.bitcoin = new BitcoinApi(config);
30
+ }
31
+ /**
32
+ * Check if user is authenticated
33
+ */
34
+ isAuthenticated() {
35
+ return this.auth.isAuthenticated();
36
+ }
37
+ /**
38
+ * Check if access token is expired
39
+ */
40
+ isTokenExpired() {
41
+ return this.auth.isTokenExpired();
42
+ }
43
+ /**
44
+ * Get current access token
45
+ */
46
+ getAccessToken() {
47
+ return this.auth.getAccessToken();
48
+ }
49
+ /**
50
+ * Logout (clear tokens)
51
+ */
52
+ async logout() {
53
+ await this.auth.logout();
54
+ }
55
+ };
56
+ function createAbcWaasApiClient(config) {
57
+ return new AbcWaasApiClient(config);
58
+ }
59
+
60
+ export {
61
+ AbcWaasApiClient,
62
+ createAbcWaasApiClient
63
+ };
@@ -0,0 +1,624 @@
1
+ "use client";
2
+ import {
3
+ BaseApiClient
4
+ } from "./chunk-IOLHAU7H.js";
5
+ import {
6
+ createAbcError
7
+ } from "./chunk-W23N7VC4.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("[BitcoinApi] \u2705 Bitcoin wallet generated:", addressResult);
53
+ return {
54
+ uid: result.uid || "",
55
+ sessionId: result.share_id,
56
+ shareId: result.share_id,
57
+ publicKey: result.public_key,
58
+ // Compressed (33 bytes, 0x02 or 0x03 prefix)
59
+ address: addressResult,
60
+ addressType,
61
+ keyId: result.key_id || result.share_id,
62
+ encryptedShare: result.encrypted_share || "",
63
+ network
64
+ };
65
+ }
66
+ /**
67
+ * Recover Bitcoin wallet
68
+ * Uses V3 API wallet recovery endpoint
69
+ *
70
+ * @param pin - Hashed PIN (SHA-256)
71
+ * @param network - Bitcoin network
72
+ * @param addressType - Bitcoin address type
73
+ * @returns Recovered Bitcoin wallet information
74
+ */
75
+ async recoverBitcoinWallet(pin, network = "bitcoin", addressType = "bech32") {
76
+ console.log("[BitcoinApi] \u{1F527} Recovering Bitcoin wallet...", {
77
+ network,
78
+ addressType
79
+ });
80
+ const response = await this.request("/v3/wallet/recover", {
81
+ method: "POST",
82
+ contentType: "json",
83
+ body: {
84
+ curve: "secp256k1",
85
+ password: pin,
86
+ network
87
+ }
88
+ });
89
+ if (response.status !== "success" || !response.result) {
90
+ console.error("[BitcoinApi] \u274C Recovery failed:", response);
91
+ throw createAbcError(
92
+ "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
93
+ "Failed to recover Bitcoin wallet",
94
+ response
95
+ );
96
+ }
97
+ const result = response.result;
98
+ const addressResult = await this.getBitcoinAddress(
99
+ result.public_key,
100
+ network,
101
+ addressType
102
+ );
103
+ console.log("[BitcoinApi] \u2705 Bitcoin wallet recovered:", addressResult);
104
+ return {
105
+ uid: result.uid || "",
106
+ sessionId: result.share_id,
107
+ shareId: result.share_id,
108
+ publicKey: result.public_key,
109
+ address: addressResult,
110
+ addressType,
111
+ keyId: result.key_id || result.share_id,
112
+ encryptedShare: result.encrypted_share || "",
113
+ network
114
+ };
115
+ }
116
+ /**
117
+ * Get Bitcoin address from compressed public key
118
+ * Converts compressed public key to Bitcoin address based on address type
119
+ *
120
+ * @param publicKey - Compressed public key (33 bytes, hex)
121
+ * @param network - Bitcoin network
122
+ * @param addressType - Address format type (currently not used by API)
123
+ * @returns Bitcoin address
124
+ */
125
+ async getBitcoinAddress(publicKey, network, _addressType = "bech32") {
126
+ const url = `${this.baseURL}/wapi/v2/btc/address`;
127
+ const params = new URLSearchParams({
128
+ pubkey: publicKey,
129
+ network
130
+ });
131
+ const response = await fetch(`${url}?${params}`, {
132
+ method: "GET",
133
+ headers: {
134
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
135
+ }
136
+ });
137
+ const data = await response.json();
138
+ if (!response.ok) {
139
+ throw createAbcError(
140
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
141
+ "Failed to get Bitcoin address",
142
+ data
143
+ );
144
+ }
145
+ return data.address;
146
+ }
147
+ /**
148
+ * Get UTXOs (Unspent Transaction Outputs) for address
149
+ * Bitcoin uses UTXO model unlike EVM/Solana account model
150
+ *
151
+ * @param address - Bitcoin address
152
+ * @param network - Bitcoin network
153
+ * @returns Array of UTXOs
154
+ */
155
+ async getUtxos(address, network) {
156
+ const url = `${this.baseURL}/wapi/v2/bitcoin/utxo/list`;
157
+ const params = new URLSearchParams({ network, address });
158
+ console.log("[BitcoinApi] \u{1F50D} Fetching UTXOs for:", address);
159
+ const response = await fetch(`${url}?${params}`, {
160
+ method: "GET",
161
+ headers: {
162
+ ...DEFAULT_HEADERS,
163
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
164
+ }
165
+ });
166
+ const data = await response.json();
167
+ if (!response.ok || data.status !== "success") {
168
+ throw createAbcError(
169
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
170
+ "Failed to get UTXOs",
171
+ data
172
+ );
173
+ }
174
+ const utxos = data.result?.utxos || [];
175
+ console.log(`[BitcoinApi] \u2705 Found ${utxos.length} UTXOs`);
176
+ return utxos;
177
+ }
178
+ /**
179
+ * Sign Bitcoin transaction (PSBT-based)
180
+ * Bitcoin transactions are signed using PSBT (BIP-174) format
181
+ * Each input requires individual signature
182
+ *
183
+ * @param params - Transaction signing parameters
184
+ * @returns Signed PSBT with multiple input signatures
185
+ */
186
+ async signBitcoinTransaction(params) {
187
+ const url = `${this.baseURL}/v3/wallet/sign`;
188
+ console.log("[BitcoinApi] \u{1F510} Signing Bitcoin transaction (PSBT)...");
189
+ const response = await fetch(url, {
190
+ method: "POST",
191
+ headers: {
192
+ "Content-Type": "application/json",
193
+ Accept: "application/json",
194
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
195
+ },
196
+ body: JSON.stringify({
197
+ uid: params.uid,
198
+ share_id: params.shareId,
199
+ message: params.psbt,
200
+ // PSBT in base64
201
+ password: params.pin,
202
+ network: params.network
203
+ })
204
+ });
205
+ const data = await response.json();
206
+ if (!response.ok || data.status !== "success") {
207
+ console.error("[BitcoinApi] \u274C Transaction signing failed:", data);
208
+ throw createAbcError(
209
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
210
+ "Failed to sign Bitcoin transaction",
211
+ data
212
+ );
213
+ }
214
+ console.log("[BitcoinApi] \u2705 Transaction signed successfully");
215
+ return {
216
+ signedPsbt: data.result?.signedPsbt,
217
+ signatures: data.result?.signatures || []
218
+ };
219
+ }
220
+ /**
221
+ * Sign Bitcoin message (BIP-322)
222
+ * Bitcoin message signing using BIP-322 standard
223
+ * Supports both legacy and modern address types
224
+ *
225
+ * @param params - Message signing parameters
226
+ * @returns BIP-322 signature
227
+ */
228
+ async signBitcoinMessage(params) {
229
+ const url = `${this.baseURL}/v3/wallet/sign`;
230
+ console.log("[BitcoinApi] \u{1F510} Signing Bitcoin message (BIP-322)...");
231
+ const response = await fetch(url, {
232
+ method: "POST",
233
+ headers: {
234
+ "Content-Type": "application/json",
235
+ Accept: "application/json",
236
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
237
+ },
238
+ body: JSON.stringify({
239
+ uid: params.uid,
240
+ share_id: params.shareId,
241
+ message: params.message,
242
+ // Hex-encoded message
243
+ password: params.pin,
244
+ messageType: params.messageType || "bip322",
245
+ network: params.network
246
+ })
247
+ });
248
+ const responseText = await response.text();
249
+ console.log("[BitcoinApi] \u{1F4E5} Sign message raw response:", {
250
+ status: response.status,
251
+ statusText: response.statusText,
252
+ text: responseText.substring(0, 500)
253
+ });
254
+ if (!responseText) {
255
+ throw createAbcError(
256
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
257
+ "Empty response from sign message API",
258
+ { status: response.status }
259
+ );
260
+ }
261
+ let data;
262
+ try {
263
+ data = JSON.parse(responseText);
264
+ } catch (parseError) {
265
+ console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
266
+ throw createAbcError(
267
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
268
+ "Invalid JSON response from sign message API",
269
+ { responseText, parseError }
270
+ );
271
+ }
272
+ if (!response.ok || data.status !== "success") {
273
+ console.error("[BitcoinApi] \u274C Message signing failed:", data);
274
+ throw createAbcError(
275
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
276
+ "Failed to sign Bitcoin message",
277
+ data
278
+ );
279
+ }
280
+ console.log("[BitcoinApi] \u2705 Message signed successfully");
281
+ return {
282
+ signature: data.result?.signature,
283
+ messageHash: data.result?.messageHash,
284
+ address: data.result?.address,
285
+ network: params.network
286
+ };
287
+ }
288
+ /**
289
+ * Send Bitcoin transaction
290
+ * Broadcasts signed transaction to Bitcoin network
291
+ *
292
+ * @param params - Transaction broadcast parameters
293
+ * @returns Transaction hash
294
+ */
295
+ async sendBitcoinTransaction(params) {
296
+ const url = `${this.baseURL}/wapi/v2/bitcoin/tx/sendTransaction`;
297
+ console.log("[BitcoinApi] \u{1F4E1} Broadcasting Bitcoin transaction...");
298
+ const response = await fetch(url, {
299
+ method: "POST",
300
+ headers: {
301
+ ...DEFAULT_HEADERS,
302
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
303
+ },
304
+ body: JSON.stringify({
305
+ network: params.network,
306
+ rawTransaction: params.rawTransaction,
307
+ ...params.psbt && { psbt: params.psbt }
308
+ })
309
+ });
310
+ const data = await response.json();
311
+ if (!response.ok || data.status !== "success") {
312
+ console.error("[BitcoinApi] \u274C Transaction broadcast failed:", data);
313
+ throw createAbcError(
314
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
315
+ "Failed to send Bitcoin transaction",
316
+ data
317
+ );
318
+ }
319
+ const txHash = data.result?.data;
320
+ console.log("[BitcoinApi] \u2705 Transaction broadcasted:", txHash);
321
+ return {
322
+ txHash
323
+ };
324
+ }
325
+ /**
326
+ * Generate Bitcoin transaction (Step 1 of 3)
327
+ * Creates PSBT and returns hashes to sign
328
+ *
329
+ * @param params - Transaction parameters
330
+ * @returns Transaction data with hashes to sign
331
+ */
332
+ async generateTransaction(params) {
333
+ const url = `${this.baseURL}/wapi/v2/btc/transaction/generate`;
334
+ console.log("[BitcoinApi] \u{1F527} Generating transaction...", params);
335
+ const response = await fetch(url, {
336
+ method: "POST",
337
+ headers: {
338
+ "Content-Type": "application/json",
339
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
340
+ },
341
+ body: JSON.stringify(params)
342
+ });
343
+ const data = await response.json();
344
+ if (!response.ok || !data.hashes) {
345
+ const errorMsg = typeof data.error === "string" ? data.error : JSON.stringify(data.error || data);
346
+ console.error("[BitcoinApi] \u274C Generate failed:", errorMsg);
347
+ throw createAbcError(
348
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
349
+ `Failed to generate transaction: ${errorMsg}`,
350
+ data
351
+ );
352
+ }
353
+ console.log(
354
+ `[BitcoinApi] \u2705 Generated ${data.hashes.length} hashes to sign`
355
+ );
356
+ return data;
357
+ }
358
+ /**
359
+ * Sign transaction hash (Step 2 of 3)
360
+ * Uses Secure Channel encryption for signing
361
+ * Based on tg-wallet-frontend reference implementation
362
+ *
363
+ * @param hash - Transaction hash to sign
364
+ * @param wallet - Full wallet object with Bitcoin signing fields
365
+ * @param pinHash - Hashed PIN for device password
366
+ * @param secureService - Secure service instance for encryption
367
+ * @returns Signature hex string (r + s without 0x prefix on s)
368
+ */
369
+ async signHash(hash, wallet, pinHash, secureService) {
370
+ console.log("[BitcoinApi] \u{1F510} Signing hash:", `${hash.substring(0, 20)}...`);
371
+ if (!wallet.wid || !wallet.pvencstr) {
372
+ console.error("[BitcoinApi] \u274C Missing Bitcoin signing fields:", {
373
+ hasWid: !!wallet.wid,
374
+ hasPvencstr: !!wallet.pvencstr,
375
+ hasSid: !!wallet.sid,
376
+ hasUid: !!wallet.uid
377
+ });
378
+ throw createAbcError(
379
+ "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
380
+ "Wallet missing required fields for Bitcoin signing (wid, pvencstr)",
381
+ { hasWid: !!wallet.wid, hasPvencstr: !!wallet.pvencstr }
382
+ );
383
+ }
384
+ console.log("[BitcoinApi] \u2705 Wallet fields validated for Bitcoin signing");
385
+ console.log("[BitcoinApi] \u{1F4CB} Wallet PLAINTEXT values:", {
386
+ hasWid: !!wallet.wid,
387
+ widLength: wallet.wid?.length,
388
+ hasPvencstr: !!wallet.pvencstr,
389
+ pvencstrLength: wallet.pvencstr?.length,
390
+ hasEncryptDevicePassword: !!wallet.encryptDevicePassword,
391
+ encryptDevicePasswordLength: wallet.encryptDevicePassword?.length
392
+ });
393
+ const encryptDevicePassword = await secureService.getEncryptPlain(
394
+ wallet.encryptDevicePassword || pinHash
395
+ );
396
+ const pvencstr = await secureService.getEncryptPlain(wallet.pvencstr);
397
+ const wid = await secureService.getEncryptPlain(wallet.wid);
398
+ const secureChannelId = await secureService.getSecureChannelId();
399
+ console.log("[BitcoinApi] \u{1F510} Encrypted values:", {
400
+ encryptDevicePasswordLength: encryptDevicePassword.length,
401
+ pvencstrLength: pvencstr.length,
402
+ widLength: wid.length,
403
+ secureChannelId
404
+ });
405
+ const params = new URLSearchParams({
406
+ uid: wallet.uid,
407
+ sid: wallet.sid || "",
408
+ // Handle optional sid
409
+ hash,
410
+ pvencstr,
411
+ wid,
412
+ encryptDevicePassword
413
+ });
414
+ console.log("[BitcoinApi] \u{1F4E4} Request params:", {
415
+ uid: wallet.uid,
416
+ sid: wallet.sid || "",
417
+ hashLength: hash.length,
418
+ bodyLength: params.toString().length
419
+ });
420
+ const url = `${this.baseURL}/wapi/v2/sign/hash`;
421
+ const response = await fetch(url, {
422
+ method: "POST",
423
+ headers: {
424
+ "Content-Type": "application/x-www-form-urlencoded",
425
+ "Secure-Channel": secureChannelId,
426
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
427
+ },
428
+ body: params.toString()
429
+ });
430
+ const responseText = await response.text();
431
+ console.log("[BitcoinApi] \u{1F4E5} Raw response:", {
432
+ status: response.status,
433
+ statusText: response.statusText,
434
+ text: responseText.substring(0, 200)
435
+ });
436
+ if (!responseText) {
437
+ throw createAbcError(
438
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
439
+ "Empty response from sign hash API",
440
+ { status: response.status }
441
+ );
442
+ }
443
+ let data;
444
+ try {
445
+ data = JSON.parse(responseText);
446
+ } catch (parseError) {
447
+ console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
448
+ throw createAbcError(
449
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
450
+ "Invalid JSON response from sign hash API",
451
+ { responseText, parseError }
452
+ );
453
+ }
454
+ if (!response.ok || data.iserr === true || !data.signstr) {
455
+ const errorDetails = data.errmsg || data.errors?.[0] || data.message || data;
456
+ console.error("[BitcoinApi] \u274C Sign failed:", errorDetails);
457
+ throw createAbcError(
458
+ "SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
459
+ `Failed to sign hash: ${JSON.stringify(errorDetails)}`,
460
+ data
461
+ );
462
+ }
463
+ console.log("[BitcoinApi] \u2705 Sign successful, parsing signature...");
464
+ const signstr = JSON.parse(data.signstr);
465
+ const sig_list = signstr.sig_list;
466
+ const signatures = [];
467
+ for (const sig of sig_list) {
468
+ const r = sig.r;
469
+ const s = sig.s.startsWith("0x") ? sig.s.substring(2) : sig.s;
470
+ const combinedSig = r + s;
471
+ signatures.push(combinedSig);
472
+ }
473
+ console.log(
474
+ "[BitcoinApi] \u2705 Signature generated:",
475
+ `${signatures[0].substring(0, 32)}...`
476
+ );
477
+ return signatures[0];
478
+ }
479
+ /**
480
+ * Finalize and broadcast transaction (Step 3 of 3)
481
+ * Broadcasts signed transaction to Bitcoin network
482
+ *
483
+ * @param params - Transaction parameters with signatures
484
+ * @returns Transaction hash
485
+ */
486
+ async finalizeTransaction(params) {
487
+ const url = `${this.baseURL}/wapi/v2/btc/transaction/finalize`;
488
+ console.log("[BitcoinApi] \u{1F4E1} Broadcasting transaction...");
489
+ console.log("[BitcoinApi] \u{1F4E4} Finalize params:", {
490
+ signatureCount: params.signatureHex.length,
491
+ amount: params.amount,
492
+ to: params.to,
493
+ pubkey: `${params.pubkey.substring(0, 20)}...`
494
+ });
495
+ const response = await fetch(url, {
496
+ method: "POST",
497
+ headers: {
498
+ "Content-Type": "application/json",
499
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
500
+ },
501
+ body: JSON.stringify(params)
502
+ });
503
+ const responseText = await response.text();
504
+ console.log("[BitcoinApi] \u{1F4E5} Finalize raw response:", {
505
+ status: response.status,
506
+ statusText: response.statusText,
507
+ text: responseText.substring(0, 200)
508
+ });
509
+ if (!responseText) {
510
+ throw createAbcError(
511
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
512
+ "Empty response from finalize API",
513
+ { status: response.status }
514
+ );
515
+ }
516
+ let data;
517
+ try {
518
+ data = JSON.parse(responseText);
519
+ } catch (parseError) {
520
+ console.error("[BitcoinApi] \u274C JSON parse error:", parseError);
521
+ throw createAbcError(
522
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
523
+ "Invalid JSON response from finalize API",
524
+ { responseText, parseError }
525
+ );
526
+ }
527
+ console.log("[BitcoinApi] \u{1F4CB} Finalize parsed data:", data);
528
+ if (!response.ok) {
529
+ const errorMsg = data.error || data.message || data.errmsg || "Unknown error";
530
+ console.error("[BitcoinApi] \u274C Finalize failed:", errorMsg);
531
+ throw createAbcError(
532
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
533
+ `Failed to finalize transaction: ${errorMsg}`,
534
+ data
535
+ );
536
+ }
537
+ const txHash = data.result?.tx_hash || data.tx_hash || data.result?.txHash || data.txHash;
538
+ if (!txHash) {
539
+ console.error("[BitcoinApi] \u274C No tx_hash in response:", data);
540
+ throw createAbcError(
541
+ "NETWORK_ERROR" /* NETWORK_ERROR */,
542
+ "Transaction hash not found in response",
543
+ data
544
+ );
545
+ }
546
+ console.log("[BitcoinApi] \u2705 Transaction sent:", txHash);
547
+ return txHash;
548
+ }
549
+ /**
550
+ * Send Bitcoin transaction (Complete flow: generate → sign → finalize)
551
+ * High-level API that handles all 3 steps
552
+ *
553
+ * @param params - Transaction parameters
554
+ * @param wallet - EVM wallet credentials
555
+ * @param pinHash - Hashed PIN
556
+ * @param secureService - Secure service instance
557
+ * @returns Transaction hash
558
+ */
559
+ async sendTransaction(params, wallet, pinHash, secureService) {
560
+ console.log("[BitcoinApi] \u{1F4B8} Starting Bitcoin transaction flow...");
561
+ const generateData = await this.generateTransaction({
562
+ amount: params.amount,
563
+ pubkey: params.pubkey,
564
+ to: params.to,
565
+ feeRate: "2"
566
+ // Default fee rate
567
+ });
568
+ const { hashes, fee_rate } = generateData;
569
+ const signatureHex = [];
570
+ for (let i = 0; i < hashes.length; i++) {
571
+ const signature = await this.signHash(
572
+ hashes[i],
573
+ wallet,
574
+ pinHash,
575
+ secureService
576
+ );
577
+ signatureHex.push(signature);
578
+ }
579
+ const txHash = await this.finalizeTransaction({
580
+ network: params.network,
581
+ signatureHex,
582
+ feeRate: fee_rate,
583
+ amount: params.amount,
584
+ pubkey: params.pubkey,
585
+ to: params.to
586
+ });
587
+ console.log("[BitcoinApi] \u2705 Transaction complete:", txHash);
588
+ return txHash;
589
+ }
590
+ /**
591
+ * Estimate Bitcoin transaction fee
592
+ * Gets recommended fee rate (satoshis per byte) for target confirmation blocks
593
+ *
594
+ * @param network - Bitcoin network
595
+ * @param targetBlocks - Target confirmation blocks (default: 6)
596
+ * @returns Fee rate in satoshis per byte
597
+ */
598
+ async estimateFee(network, targetBlocks = 6) {
599
+ const url = `${this.baseURL}/wapi/v2/bitcoin/fee/estimate`;
600
+ const params = new URLSearchParams({
601
+ network,
602
+ targetBlocks: targetBlocks.toString()
603
+ });
604
+ const response = await fetch(`${url}?${params}`, {
605
+ method: "GET",
606
+ headers: {
607
+ ...DEFAULT_HEADERS,
608
+ ...this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {}
609
+ }
610
+ });
611
+ const data = await response.json();
612
+ if (!response.ok || data.status !== "success") {
613
+ console.warn("[BitcoinApi] \u26A0\uFE0F Fee estimation failed, using fallback");
614
+ return 1;
615
+ }
616
+ const feeRate = data.result?.feeRate || 1;
617
+ console.log(`[BitcoinApi] \u26FD Estimated fee rate: ${feeRate} sat/byte`);
618
+ return feeRate;
619
+ }
620
+ };
621
+
622
+ export {
623
+ BitcoinApi
624
+ };