@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.
- package/LICENSE +9 -0
- package/dist/Arc-ILTINY4C.js +8 -0
- package/dist/Brave-4L5B7JJR.js +8 -0
- package/dist/Browser-XMB4J5WD.js +8 -0
- package/dist/Chrome-6ZDQIHC5.js +8 -0
- package/dist/Edge-OAWCEU7H.js +8 -0
- package/dist/Firefox-O66FZK3V.js +8 -0
- package/dist/Linux-NUJF4EPC.js +8 -0
- package/dist/Macos-46EJ2NPK.js +8 -0
- package/dist/Opera-KTUB3UWN.js +8 -0
- package/dist/Safari-A3Q6PIT2.js +8 -0
- package/dist/Windows-NL32NG52.js +8 -0
- package/dist/abcWallet-ES4OPRSK.js +8 -0
- package/dist/ar_AR-YBBYUEGS.js +8 -0
- package/dist/arbitrum-D2TUFPZI.js +8 -0
- package/dist/argentWallet-A5HM5FRP.js +8 -0
- package/dist/assets-4NDWRKXE.js +8 -0
- package/dist/avalanche-BOOSH35S.js +8 -0
- package/dist/base-3JMRS35B.js +8 -0
- package/dist/berasigWallet-6IOU73YL.js +8 -0
- package/dist/bestWallet-6LJUU6OL.js +8 -0
- package/dist/bifrostWallet-SLPPXZ2K.js +8 -0
- package/dist/binanceWallet-Z67J7362.js +8 -0
- package/dist/bitgetWallet-DLLOWMCI.js +8 -0
- package/dist/bitskiWallet-CPOXGABT.js +8 -0
- package/dist/bitverseWallet-SAK4MIS6.js +8 -0
- package/dist/blast-4GF24NR7.js +8 -0
- package/dist/bloomWallet-YIRCNQZJ.js +8 -0
- package/dist/braveWallet-PNBKQKJC.js +8 -0
- package/dist/bsc-KU6MBOYR.js +8 -0
- package/dist/bybitWallet-GCDBAJKO.js +8 -0
- package/dist/celo-5A5VXMPX.js +8 -0
- package/dist/chunk-TJX4M23U.js +27 -0
- package/dist/clvWallet-R6YRCMZO.js +8 -0
- package/dist/coin98Wallet-4Y3ROAGP.js +8 -0
- package/dist/coinbaseWallet-L4QDZB5W.js +8 -0
- package/dist/compassWallet-NNBX35AV.js +8 -0
- package/dist/components/ConnectButton/ConnectButtonRenderer.d.ts +1 -1
- package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +1 -1
- package/dist/config/networks.d.ts +125 -0
- package/dist/connect-Q2RLUT5B.js +8 -0
- package/dist/contexts/index.d.ts +2 -2
- package/dist/coreWallet-PN2LMNGN.js +8 -0
- package/dist/create-HQ4QXTKY.js +8 -0
- package/dist/cronos-KZAB32FC.js +8 -0
- package/dist/dawnWallet-AMO43DL3.js +8 -0
- package/dist/de_DE-RUWMVYCQ.js +8 -0
- package/dist/desigWallet-AD335WX5.js +8 -0
- package/dist/en_US-NQ25CUR4.js +8 -0
- package/dist/enkryptWallet-OOP27GE2.js +8 -0
- package/dist/es_419-HKJPYJRI.js +8 -0
- package/dist/ethereum-WAFT6DML.js +8 -0
- package/dist/flow-XANNOAPJ.js +8 -0
- package/dist/foxWallet-UDUWOW52.js +8 -0
- package/dist/fr_FR-2O5ZDLPQ.js +1356 -0
- package/dist/frameWallet-BEABTFIT.js +8 -0
- package/dist/frontierWallet-RG47M3C5.js +8 -0
- package/dist/gateWallet-XOP74BMB.js +8 -0
- package/dist/gnosis-7GFI4V27.js +8 -0
- package/dist/hardhat-6HKZWC4T.js +8 -0
- package/dist/hi_IN-XRZ4YIUW.js +8 -0
- package/dist/id_ID-REEY4CSS.js +8 -0
- package/dist/imTokenWallet-LTPKXYUD.js +8 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1114 -403
- package/dist/injectedWallet-YCFZTULL.js +8 -0
- package/dist/iopayWallet-XS37QAUO.js +8 -0
- package/dist/ja_JP-2OPCVN6X.js +8 -0
- package/dist/kaia-DQ3OSYXE.js +8 -0
- package/dist/kaiaWallet-2XZDQZ63.js +8 -0
- package/dist/kaikasWallet-V2GCFPEB.js +8 -0
- package/dist/ko_KR-DDXBZTYT.js +8 -0
- package/dist/krakenWallet-3VM7ZM2O.js +8 -0
- package/dist/kresusWallet-4MXFQP4P.js +8 -0
- package/dist/ledgerWallet-YC3HF3NJ.js +8 -0
- package/dist/login-DGIK764Z.js +8 -0
- package/dist/magicEden-BLYGUG47.js +8 -0
- package/dist/manta-OEF3QP66.js +8 -0
- package/dist/mantle-EYIH4GGM.js +8 -0
- package/dist/metaMaskWallet-ZZMFVM52.js +8 -0
- package/dist/mewWallet-D6JN37EZ.js +8 -0
- package/dist/ms_MY-PX7G4XTD.js +8 -0
- package/dist/nestWallet-X3CDHKNV.js +8 -0
- package/dist/oktoWallet-ZYLL2RLN.js +8 -0
- package/dist/okxWallet-FLICEG4S.js +8 -0
- package/dist/omniWallet-DAQHKHUN.js +8 -0
- package/dist/oneInchWallet-BRGGUXND.js +8 -0
- package/dist/oneKeyWallet-KDU2JIFD.js +8 -0
- package/dist/optimism-6GXRYJDW.js +8 -0
- package/dist/paraSwapWallet-7UHWT54G.js +8 -0
- package/dist/phantomWallet-BSCGZT6L.js +8 -0
- package/dist/polygon-YNJM552P.js +8 -0
- package/dist/pt_BR-A5R4SBSC.js +8 -0
- package/dist/rabbyWallet-RZIUL3YN.js +8 -0
- package/dist/rainbowWallet-4ALDT5ZL.js +8 -0
- package/dist/ramperWallet-IB3JRE2F.js +8 -0
- package/dist/refresh-R5NYTT3S.js +8 -0
- package/dist/ronin-LU7LZPWA.js +8 -0
- package/dist/roninWallet-BS7VDK7U.js +8 -0
- package/dist/ru_RU-4QDZLRSW.js +1356 -0
- package/dist/safeWallet-5NR62MJV.js +8 -0
- package/dist/safeheronWallet-7ELUSU44.js +8 -0
- package/dist/safepalWallet-CZJABQ5N.js +8 -0
- package/dist/scan-BVZ7DVJ4.js +8 -0
- package/dist/scroll-XRP46UTI.js +8 -0
- package/dist/secure-GEK7TTJY.js +8 -0
- package/dist/seifWallet-XLBMTX4R.js +8 -0
- package/dist/sign-PREOQ4RR.js +8 -0
- package/dist/solana/SolanaWalletProvider.d.ts +1 -1
- package/dist/subWallet-47USA4OE.js +8 -0
- package/dist/tahoWallet-N3XXJ3NW.js +8 -0
- package/dist/talismanWallet-SV3B42TQ.js +8 -0
- package/dist/th_TH-4TWPYDKX.js +1356 -0
- package/dist/themes/baseTheme.js +1 -0
- package/dist/themes/darkTheme.js +1 -0
- package/dist/themes/lightTheme.js +1 -0
- package/dist/themes/midnightTheme.js +1 -0
- package/dist/tokenPocketWallet-7IYW3MIL.js +8 -0
- package/dist/tokenaryWallet-7D2LN65X.js +8 -0
- package/dist/tr_TR-C37KIU7M.js +1356 -0
- package/dist/trustWallet-HJQBMBC6.js +8 -0
- package/dist/uk_UA-I77HS4GO.js +1356 -0
- package/dist/uniswapWallet-JZ2ULELN.js +8 -0
- package/dist/utils/abcWaasAdapter.d.ts +75 -0
- package/dist/valoraWallet-PCTL6UBB.js +8 -0
- package/dist/vi_VN-KVPDLW26.js +8 -0
- package/dist/walletConnectWallet-AJ36XVBT.js +8 -0
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +11 -8
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +4 -11
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.d.ts +1 -19
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/index.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +2 -0
- package/dist/wallets/walletConnectors/chunk-2GIBC7XF.js +39 -0
- package/dist/wallets/walletConnectors/chunk-2J66VMY5.js +152 -0
- package/dist/wallets/walletConnectors/chunk-34WMJDUY.js +481 -0
- package/dist/wallets/walletConnectors/chunk-3J3XZMJ7.js +39 -0
- package/dist/wallets/walletConnectors/chunk-4IRVZPIN.js +63 -0
- package/dist/wallets/walletConnectors/chunk-5OFAP55G.js +44 -0
- package/dist/wallets/walletConnectors/chunk-6YPK343Z.js +63 -0
- package/dist/wallets/walletConnectors/chunk-7P5HZGEV.js +627 -0
- package/dist/wallets/walletConnectors/chunk-A6LBRVGP.js +63 -0
- package/dist/wallets/walletConnectors/chunk-BKXPGZMQ.js +228 -0
- package/dist/wallets/walletConnectors/chunk-CNHVIXPV.js +228 -0
- package/dist/wallets/walletConnectors/chunk-DAZZIITX.js +1678 -0
- package/dist/wallets/walletConnectors/chunk-ESRU5KCF.js +151 -0
- package/dist/wallets/walletConnectors/chunk-F4JFONDA.js +601 -0
- package/dist/wallets/walletConnectors/chunk-GXHCAEWR.js +63 -0
- package/dist/wallets/walletConnectors/chunk-HDYBRMYW.js +194 -0
- package/dist/wallets/walletConnectors/chunk-HOE4UOHR.js +514 -0
- package/dist/wallets/walletConnectors/chunk-JJAJOFZI.js +63 -0
- package/dist/wallets/walletConnectors/chunk-KFIUFVQH.js +624 -0
- package/dist/wallets/walletConnectors/chunk-KFROJI25.js +535 -0
- package/dist/wallets/walletConnectors/chunk-KHVILXGK.js +514 -0
- package/dist/wallets/walletConnectors/chunk-LGT7LQAJ.js +63 -0
- package/dist/wallets/walletConnectors/chunk-LHBQ2Z3Q.js +63 -0
- package/dist/wallets/walletConnectors/chunk-M76GLEFL.js +63 -0
- package/dist/wallets/walletConnectors/chunk-MFIE6UCG.js +63 -0
- package/dist/wallets/walletConnectors/chunk-NKJLO4QH.js +39 -0
- package/dist/wallets/walletConnectors/chunk-NURTFXQU.js +568 -0
- package/dist/wallets/walletConnectors/chunk-NWDLOM7Q.js +646 -0
- package/dist/wallets/walletConnectors/chunk-OHRTTVNJ.js +44 -0
- package/dist/wallets/walletConnectors/chunk-OMYDLPUM.js +63 -0
- package/dist/wallets/walletConnectors/chunk-P2MTINFI.js +280 -0
- package/dist/wallets/walletConnectors/chunk-PUFQKZA7.js +63 -0
- package/dist/wallets/walletConnectors/chunk-RLBGBBIO.js +309 -0
- package/dist/wallets/walletConnectors/chunk-S2B56ZVJ.js +481 -0
- package/dist/wallets/walletConnectors/chunk-SFP47DS6.js +63 -0
- package/dist/wallets/walletConnectors/chunk-SNZL5LJ6.js +637 -0
- package/dist/wallets/walletConnectors/chunk-SPR4W5TG.js +474 -0
- package/dist/wallets/walletConnectors/chunk-SSDCG5BG.js +63 -0
- package/dist/wallets/walletConnectors/chunk-TUUNSVKZ.js +345 -0
- package/dist/wallets/walletConnectors/chunk-U2CUEL35.js +240 -0
- package/dist/wallets/walletConnectors/chunk-VLEVJVJR.js +63 -0
- package/dist/wallets/walletConnectors/chunk-W2VDZD74.js +478 -0
- package/dist/wallets/walletConnectors/chunk-WAO3KL5U.js +285 -0
- package/dist/wallets/walletConnectors/chunk-WYSKBMHW.js +280 -0
- package/dist/wallets/walletConnectors/chunk-XYPR4BAF.js +436 -0
- package/dist/wallets/walletConnectors/index.js +58 -58
- package/dist/wigwamWallet-D3MVGB5Z.js +8 -0
- package/dist/xdc-5NQHQJE5.js +8 -0
- package/dist/xdefiWallet-B4O6HAIP.js +8 -0
- package/dist/zealWallet-6SPNICRX.js +8 -0
- package/dist/zerionWallet-XZ3JCAOO.js +8 -0
- package/dist/zetachain-U6IILKZJ.js +8 -0
- package/dist/zh_CN-KGLAIP3N.js +8 -0
- package/dist/zh_HK-AEXEN6P6.js +8 -0
- package/dist/zh_TW-6C7R5V3K.js +8 -0
- package/dist/zkSync-TMPB52ZN.js +8 -0
- package/dist/zora-S46CHEOU.js +8 -0
- package/package.json +11 -12
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/wallets/walletConnectors/abcWallet/abcBitcoinProvider.ts
|
|
4
|
+
var EventEmitter = class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.events = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
on(event, listener) {
|
|
9
|
+
if (!this.events.has(event)) {
|
|
10
|
+
this.events.set(event, []);
|
|
11
|
+
}
|
|
12
|
+
this.events.get(event).push(listener);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
off(event, listener) {
|
|
16
|
+
const listeners = this.events.get(event);
|
|
17
|
+
if (listeners) {
|
|
18
|
+
const index = listeners.indexOf(listener);
|
|
19
|
+
if (index !== -1) {
|
|
20
|
+
listeners.splice(index, 1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
removeListener(event, listener) {
|
|
26
|
+
return this.off(event, listener);
|
|
27
|
+
}
|
|
28
|
+
emit(event, ...args) {
|
|
29
|
+
const listeners = this.events.get(event);
|
|
30
|
+
if (listeners) {
|
|
31
|
+
for (const listener of listeners) {
|
|
32
|
+
listener(...args);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
removeAllListeners(event) {
|
|
39
|
+
if (event) {
|
|
40
|
+
this.events.delete(event);
|
|
41
|
+
} else {
|
|
42
|
+
this.events.clear();
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var BitcoinErrorCode = {
|
|
48
|
+
USER_REJECTED: 4001,
|
|
49
|
+
UNAUTHORIZED: 4100,
|
|
50
|
+
UNSUPPORTED_METHOD: 4200,
|
|
51
|
+
DISCONNECTED: 4900,
|
|
52
|
+
INVALID_PARAMS: -32602,
|
|
53
|
+
INTERNAL_ERROR: -32603,
|
|
54
|
+
INSUFFICIENT_FUNDS: 5001,
|
|
55
|
+
UTXO_NOT_FOUND: 5002
|
|
56
|
+
};
|
|
57
|
+
var BitcoinProviderError = class extends Error {
|
|
58
|
+
constructor(code, message, data) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.data = data;
|
|
62
|
+
this.name = "BitcoinProviderError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var BITCOIN_NETWORKS = {
|
|
66
|
+
mainnet: {
|
|
67
|
+
name: "Bitcoin Mainnet",
|
|
68
|
+
type: "bitcoin",
|
|
69
|
+
explorer: "https://blockstream.info"
|
|
70
|
+
},
|
|
71
|
+
testnet: {
|
|
72
|
+
name: "Bitcoin Testnet",
|
|
73
|
+
type: "bitcoin_testnet",
|
|
74
|
+
explorer: "https://blockstream.info/testnet"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var AbcBitcoinProvider = class extends EventEmitter {
|
|
78
|
+
// 1 minute
|
|
79
|
+
constructor(client) {
|
|
80
|
+
super();
|
|
81
|
+
this.wallet = null;
|
|
82
|
+
this.network = BITCOIN_NETWORKS.testnet;
|
|
83
|
+
this.connected = false;
|
|
84
|
+
this.utxoCache = /* @__PURE__ */ new Map();
|
|
85
|
+
this.cacheExpiry = /* @__PURE__ */ new Map();
|
|
86
|
+
this.CACHE_TTL = 6e4;
|
|
87
|
+
this.client = client;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set wallet information
|
|
91
|
+
*/
|
|
92
|
+
setWallet(wallet) {
|
|
93
|
+
const previousAddress = this.wallet?.address;
|
|
94
|
+
this.wallet = wallet;
|
|
95
|
+
this.connected = true;
|
|
96
|
+
if (wallet.network === "bitcoin") {
|
|
97
|
+
this.network = BITCOIN_NETWORKS.mainnet;
|
|
98
|
+
} else {
|
|
99
|
+
this.network = BITCOIN_NETWORKS.testnet;
|
|
100
|
+
}
|
|
101
|
+
if (previousAddress !== wallet.address) {
|
|
102
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
103
|
+
this.clearUtxoCache();
|
|
104
|
+
}
|
|
105
|
+
this.emit("connect", {
|
|
106
|
+
address: wallet.address,
|
|
107
|
+
network: this.network.type
|
|
108
|
+
});
|
|
109
|
+
console.log("[BitcoinProvider] \u2705 Wallet connected:", wallet.address);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Clear wallet (disconnect)
|
|
113
|
+
*/
|
|
114
|
+
clearWallet() {
|
|
115
|
+
this.wallet = null;
|
|
116
|
+
this.connected = false;
|
|
117
|
+
this.clearUtxoCache();
|
|
118
|
+
this.emit("disconnect");
|
|
119
|
+
this.emit("accountsChanged", []);
|
|
120
|
+
console.log("[BitcoinProvider] \u{1F50C} Wallet disconnected");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Set PIN request callback for transaction signing
|
|
124
|
+
*/
|
|
125
|
+
setRequestPinCallback(callback) {
|
|
126
|
+
this.requestPinCallback = callback;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Request PIN from user
|
|
130
|
+
* First tries global callback, then falls back to manual callback
|
|
131
|
+
*/
|
|
132
|
+
async requestPin() {
|
|
133
|
+
const globalRequestPin = window.__TALKENKIT_REQUEST_PIN__;
|
|
134
|
+
if (globalRequestPin && typeof globalRequestPin === "function") {
|
|
135
|
+
return globalRequestPin("transaction");
|
|
136
|
+
}
|
|
137
|
+
if (!this.requestPinCallback) {
|
|
138
|
+
throw new BitcoinProviderError(
|
|
139
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
140
|
+
"PIN request callback not configured. Make sure RainbowKitProvider is rendered."
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return this.requestPinCallback();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Set network
|
|
147
|
+
*/
|
|
148
|
+
setNetwork(networkKey) {
|
|
149
|
+
const newNetwork = BITCOIN_NETWORKS[networkKey];
|
|
150
|
+
if (!newNetwork) {
|
|
151
|
+
throw new BitcoinProviderError(
|
|
152
|
+
BitcoinErrorCode.INVALID_PARAMS,
|
|
153
|
+
`Unknown network: ${networkKey}`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
const previousType = this.network.type;
|
|
157
|
+
this.network = newNetwork;
|
|
158
|
+
if (previousType !== newNetwork.type) {
|
|
159
|
+
this.emit("networkChanged", newNetwork.type);
|
|
160
|
+
this.clearUtxoCache();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get current network
|
|
165
|
+
*/
|
|
166
|
+
getNetwork() {
|
|
167
|
+
return this.network;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if connected
|
|
171
|
+
*/
|
|
172
|
+
isConnected() {
|
|
173
|
+
return this.connected && this.wallet !== null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get Bitcoin address
|
|
177
|
+
*/
|
|
178
|
+
async getAddress() {
|
|
179
|
+
if (!this.wallet) {
|
|
180
|
+
throw new BitcoinProviderError(
|
|
181
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
182
|
+
"Wallet not connected"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return this.wallet.address;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get compressed public key (33 bytes)
|
|
189
|
+
*/
|
|
190
|
+
async getPublicKey() {
|
|
191
|
+
if (!this.wallet) {
|
|
192
|
+
throw new BitcoinProviderError(
|
|
193
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
194
|
+
"Wallet not connected"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return this.wallet.publicKey;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get address type (bech32, p2pkh, etc.)
|
|
201
|
+
*/
|
|
202
|
+
getAddressType() {
|
|
203
|
+
if (!this.wallet) {
|
|
204
|
+
throw new BitcoinProviderError(
|
|
205
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
206
|
+
"Wallet not connected"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return this.wallet.addressType;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Clear UTXO cache
|
|
213
|
+
*/
|
|
214
|
+
clearUtxoCache() {
|
|
215
|
+
this.utxoCache.clear();
|
|
216
|
+
this.cacheExpiry.clear();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Check if cache is valid
|
|
220
|
+
*/
|
|
221
|
+
isCacheValid(address) {
|
|
222
|
+
const expiry = this.cacheExpiry.get(address);
|
|
223
|
+
if (!expiry)
|
|
224
|
+
return false;
|
|
225
|
+
return Date.now() < expiry;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get UTXOs for address (with caching)
|
|
229
|
+
*/
|
|
230
|
+
async getUtxos(forceRefresh = false) {
|
|
231
|
+
if (!this.wallet) {
|
|
232
|
+
throw new BitcoinProviderError(
|
|
233
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
234
|
+
"Wallet not connected"
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
const address = this.wallet.address;
|
|
238
|
+
if (!forceRefresh && this.isCacheValid(address)) {
|
|
239
|
+
const cached = this.utxoCache.get(address);
|
|
240
|
+
if (cached) {
|
|
241
|
+
console.log(
|
|
242
|
+
`[BitcoinProvider] \u{1F4E6} Using cached UTXOs (${cached.length} items)`
|
|
243
|
+
);
|
|
244
|
+
return cached;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
console.log("[BitcoinProvider] \u{1F50D} Fetching UTXOs from network...");
|
|
249
|
+
const utxos = await this.client.bitcoin.getUtxos(
|
|
250
|
+
address,
|
|
251
|
+
this.network.type
|
|
252
|
+
);
|
|
253
|
+
this.utxoCache.set(address, utxos);
|
|
254
|
+
this.cacheExpiry.set(address, Date.now() + this.CACHE_TTL);
|
|
255
|
+
console.log(`[BitcoinProvider] \u2705 Fetched ${utxos.length} UTXOs`);
|
|
256
|
+
return utxos;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error(
|
|
259
|
+
"[BitcoinProvider] \u274C Failed to fetch UTXOs:",
|
|
260
|
+
error.message
|
|
261
|
+
);
|
|
262
|
+
throw new BitcoinProviderError(
|
|
263
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
264
|
+
"Failed to fetch UTXOs",
|
|
265
|
+
error
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get total balance (sum of all UTXOs)
|
|
271
|
+
* Returns balance in satoshis
|
|
272
|
+
*/
|
|
273
|
+
async getBalance(forceRefresh = false) {
|
|
274
|
+
const utxos = await this.getUtxos(forceRefresh);
|
|
275
|
+
const balance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
276
|
+
console.log(
|
|
277
|
+
`[BitcoinProvider] \u{1F4B0} Balance: ${balance} satoshis (${balance / 1e8} BTC)`
|
|
278
|
+
);
|
|
279
|
+
return balance;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Estimate transaction fee
|
|
283
|
+
* Returns fee rate in satoshis per byte
|
|
284
|
+
*/
|
|
285
|
+
async estimateFee(targetBlocks = 6) {
|
|
286
|
+
try {
|
|
287
|
+
const feeRate = await this.client.bitcoin.estimateFee(
|
|
288
|
+
this.network.type,
|
|
289
|
+
targetBlocks
|
|
290
|
+
);
|
|
291
|
+
console.log(`[BitcoinProvider] \u26FD Fee rate: ${feeRate} sat/byte`);
|
|
292
|
+
return feeRate;
|
|
293
|
+
} catch (_error) {
|
|
294
|
+
console.error("[BitcoinProvider] \u26A0\uFE0F Fee estimation failed, using default");
|
|
295
|
+
return 1;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Sign Bitcoin message (BIP-322)
|
|
300
|
+
* NOTE: Currently not supported - Bitcoin uses v2 API which doesn't have message signing endpoint
|
|
301
|
+
* Only transaction signing is supported via PSBT
|
|
302
|
+
*
|
|
303
|
+
* @param message - Message to sign (string)
|
|
304
|
+
* @returns Signature in base64 format
|
|
305
|
+
*/
|
|
306
|
+
async signMessage(message) {
|
|
307
|
+
console.log("[BitcoinProvider] \u26A0\uFE0F Bitcoin message signing requested");
|
|
308
|
+
throw new BitcoinProviderError(
|
|
309
|
+
BitcoinErrorCode.UNSUPPORTED_METHOD,
|
|
310
|
+
"Bitcoin message signing is not supported. Bitcoin uses v2 API which only supports transaction signing (PSBT). Use signTransaction() instead."
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* High-level transaction sending (like Solana pattern)
|
|
315
|
+
* Creates, signs, and broadcasts transaction
|
|
316
|
+
*
|
|
317
|
+
* @param params - Transaction parameters
|
|
318
|
+
* @param params.toAddress - Recipient Bitcoin address
|
|
319
|
+
* @param params.amount - Amount in BTC (will be converted to satoshis)
|
|
320
|
+
* @returns Transaction hash
|
|
321
|
+
*/
|
|
322
|
+
async sendTransaction(params) {
|
|
323
|
+
if (!this.wallet) {
|
|
324
|
+
throw new BitcoinProviderError(
|
|
325
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
326
|
+
"Wallet not connected"
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
console.log("[BitcoinProvider] \u{1F4B8} Starting high-level transaction...");
|
|
331
|
+
const authStateKey = "talkenkit_abc_auth_state";
|
|
332
|
+
const authState = typeof window !== "undefined" ? localStorage.getItem(authStateKey) : null;
|
|
333
|
+
if (!authState) {
|
|
334
|
+
throw new BitcoinProviderError(
|
|
335
|
+
BitcoinErrorCode.UNAUTHORIZED,
|
|
336
|
+
"Not authenticated - auth state not found"
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const parsed = JSON.parse(authState);
|
|
340
|
+
const evmWallet = parsed.wallet;
|
|
341
|
+
if (!evmWallet?.uid || !evmWallet?.sid || !evmWallet?.pvencstr || !evmWallet?.wid) {
|
|
342
|
+
throw new BitcoinProviderError(
|
|
343
|
+
BitcoinErrorCode.UNAUTHORIZED,
|
|
344
|
+
"EVM wallet data not found (required for Bitcoin signing)"
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
console.log(
|
|
348
|
+
"[BitcoinProvider] \u{1F510} Requesting PIN for Bitcoin transaction..."
|
|
349
|
+
);
|
|
350
|
+
const pin = await this.requestPin();
|
|
351
|
+
const encoder = new TextEncoder();
|
|
352
|
+
const data = encoder.encode(pin);
|
|
353
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
354
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
355
|
+
const pinHash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
356
|
+
const satoshis = Math.floor(params.amount * 1e8);
|
|
357
|
+
const SecureService = (await import("./abcWallet/secure.js")).default;
|
|
358
|
+
const secureService = new SecureService(this.client.bitcoin.getBaseURL());
|
|
359
|
+
const walletData = {
|
|
360
|
+
address: evmWallet.address,
|
|
361
|
+
keyId: evmWallet.keyId,
|
|
362
|
+
encryptedShare: evmWallet.encryptedShare,
|
|
363
|
+
uid: evmWallet.uid,
|
|
364
|
+
sid: evmWallet.sid,
|
|
365
|
+
wid: evmWallet.wid,
|
|
366
|
+
pvencstr: evmWallet.pvencstr,
|
|
367
|
+
encryptDevicePassword: evmWallet.encryptDevicePassword,
|
|
368
|
+
pubkey: evmWallet.pubkey
|
|
369
|
+
};
|
|
370
|
+
const txHash = await this.client.bitcoin.sendTransaction(
|
|
371
|
+
{
|
|
372
|
+
amount: satoshis.toString(),
|
|
373
|
+
to: params.toAddress,
|
|
374
|
+
pubkey: this.wallet.publicKey,
|
|
375
|
+
network: this.network.type
|
|
376
|
+
},
|
|
377
|
+
walletData,
|
|
378
|
+
pinHash,
|
|
379
|
+
secureService
|
|
380
|
+
);
|
|
381
|
+
console.log("[BitcoinProvider] \u2705 Transaction complete:", txHash);
|
|
382
|
+
this.emit("transactionBroadcasted", {
|
|
383
|
+
txHash,
|
|
384
|
+
explorerUrl: `${this.network.explorer}/tx/${txHash}`
|
|
385
|
+
});
|
|
386
|
+
this.clearUtxoCache();
|
|
387
|
+
return txHash;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.error("[BitcoinProvider] \u274C Transaction failed:", error.message);
|
|
390
|
+
if (error.message?.includes("insufficient")) {
|
|
391
|
+
throw new BitcoinProviderError(
|
|
392
|
+
BitcoinErrorCode.INSUFFICIENT_FUNDS,
|
|
393
|
+
"Insufficient BTC balance",
|
|
394
|
+
error
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
if (error.message?.includes("cancelled") || error.message?.includes("rejected")) {
|
|
398
|
+
throw new BitcoinProviderError(
|
|
399
|
+
BitcoinErrorCode.USER_REJECTED,
|
|
400
|
+
"User rejected transaction",
|
|
401
|
+
error
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
this.emit("error", error);
|
|
405
|
+
throw new BitcoinProviderError(
|
|
406
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
407
|
+
"Failed to send transaction",
|
|
408
|
+
error
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Broadcast signed transaction to network
|
|
414
|
+
*
|
|
415
|
+
* @param rawTransaction - Raw transaction in hex format
|
|
416
|
+
* @param psbt - Optional finalized PSBT
|
|
417
|
+
* @returns Transaction hash
|
|
418
|
+
*/
|
|
419
|
+
async broadcastTransaction(rawTransaction, psbt) {
|
|
420
|
+
if (!this.wallet) {
|
|
421
|
+
throw new BitcoinProviderError(
|
|
422
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
423
|
+
"Wallet not connected"
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
console.log("[BitcoinProvider] \u{1F4E1} Broadcasting transaction...");
|
|
428
|
+
const result = await this.client.bitcoin.sendBitcoinTransaction({
|
|
429
|
+
network: this.network.type,
|
|
430
|
+
rawTransaction,
|
|
431
|
+
...psbt && { psbt }
|
|
432
|
+
});
|
|
433
|
+
console.log(
|
|
434
|
+
"[BitcoinProvider] \u2705 Transaction broadcasted:",
|
|
435
|
+
result.txHash
|
|
436
|
+
);
|
|
437
|
+
this.emit("transactionBroadcasted", {
|
|
438
|
+
txHash: result.txHash,
|
|
439
|
+
explorerUrl: `${this.network.explorer}/tx/${result.txHash}`
|
|
440
|
+
});
|
|
441
|
+
this.clearUtxoCache();
|
|
442
|
+
return result.txHash;
|
|
443
|
+
} catch (error) {
|
|
444
|
+
console.error(
|
|
445
|
+
"[BitcoinProvider] \u274C Transaction broadcast failed:",
|
|
446
|
+
error.message
|
|
447
|
+
);
|
|
448
|
+
this.emit("error", error);
|
|
449
|
+
throw new BitcoinProviderError(
|
|
450
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
451
|
+
"Failed to broadcast transaction",
|
|
452
|
+
error
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Get wallet info
|
|
458
|
+
*/
|
|
459
|
+
getWalletInfo() {
|
|
460
|
+
if (!this.wallet)
|
|
461
|
+
return null;
|
|
462
|
+
return {
|
|
463
|
+
address: this.wallet.address,
|
|
464
|
+
publicKey: this.wallet.publicKey,
|
|
465
|
+
addressType: this.wallet.addressType,
|
|
466
|
+
network: this.network.type
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Refresh UTXO cache
|
|
471
|
+
*/
|
|
472
|
+
async refreshUtxos() {
|
|
473
|
+
return this.getUtxos(true);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
export {
|
|
478
|
+
BitcoinProviderError,
|
|
479
|
+
BITCOIN_NETWORKS,
|
|
480
|
+
AbcBitcoinProvider
|
|
481
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
WalletApi
|
|
4
|
+
} from "./chunk-JBRW4UTW.js";
|
|
5
|
+
import {
|
|
6
|
+
TransactionApi
|
|
7
|
+
} from "./chunk-KD2OAMDA.js";
|
|
8
|
+
import {
|
|
9
|
+
AuthApi
|
|
10
|
+
} from "./chunk-W7R3JGSC.js";
|
|
11
|
+
import {
|
|
12
|
+
BitcoinApi
|
|
13
|
+
} from "./chunk-SNZL5LJ6.js";
|
|
14
|
+
import {
|
|
15
|
+
SigningApi
|
|
16
|
+
} from "./chunk-4UGXLYKP.js";
|
|
17
|
+
import {
|
|
18
|
+
SolanaApi
|
|
19
|
+
} from "./chunk-DMRM7XAS.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
|
+
};
|