@talken/talkenkit 2.4.24 → 2.4.26
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/AbcCredentialManager-DDHLW2IH.js +7 -0
- package/dist/abcWallet-GFKDYN2Z.js +161 -0
- package/dist/abcWallet-MWUFO3JQ.js +161 -0
- package/dist/abcWallet-OL47MLVO.js +161 -0
- package/dist/abcWallet-VYU3TEGJ.js +161 -0
- package/dist/abcWallet-WZGXGXUA.js +161 -0
- package/dist/chunk-2OHX4KTB.js +5382 -0
- package/dist/chunk-ALBABQ53.js +354 -0
- package/dist/chunk-NQCUKFAV.js +5381 -0
- package/dist/chunk-RIEG3EJO.js +5385 -0
- package/dist/chunk-RKEFBYBO.js +5402 -0
- package/dist/chunk-UKIPSWEV.js +5386 -0
- package/dist/hooks/useProfile.d.ts +13 -6
- package/dist/hooks/useSolanaWallet.d.ts +9 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +276 -181
- package/dist/providers/SignConfirmationProvider/useApiClient.d.ts +3 -0
- package/dist/solana/ConfiguredWalletProvider.d.ts +10 -0
- package/dist/solana/LegacySolflareWalletAdapter.d.ts +32 -0
- package/dist/solana/connectExternalWallet.d.ts +9 -0
- package/dist/solana/isWalletReady.d.ts +2 -0
- package/dist/transactions/transactionStore.d.ts +2 -5
- package/dist/utils/apiClientFactory.d.ts +16 -1
- package/dist/wallets/capabilities/detectCapabilities.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +0 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +11 -3
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.d.ts +21 -0
- package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +8 -0
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +28 -115
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +1 -6
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +23 -1
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.d.ts +14 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +8 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +20 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/index.d.ts +3 -0
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +17 -5
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +4 -0
- package/dist/wallets/walletConnectors/abcWallet/constants.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/index.js +33 -21
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +4 -0
- package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +3 -3
- package/dist/wallets/walletConnectors/chunk-6WF4SXLB.js +156 -0
- package/dist/wallets/walletConnectors/chunk-7DM6H5BJ.js +54 -0
- package/dist/wallets/walletConnectors/chunk-7F5DVU5U.js +300 -0
- package/dist/wallets/walletConnectors/chunk-7ORDZ6EQ.js +1479 -0
- package/dist/wallets/walletConnectors/chunk-A66MTFML.js +223 -0
- package/dist/wallets/walletConnectors/chunk-ACLPF2UW.js +96 -0
- package/dist/wallets/walletConnectors/chunk-BXH3GDX5.js +273 -0
- package/dist/wallets/walletConnectors/chunk-CABLJOMU.js +194 -0
- package/dist/wallets/walletConnectors/chunk-CE37VZAR.js +300 -0
- package/dist/wallets/walletConnectors/chunk-DPTDOCWL.js +205 -0
- package/dist/wallets/walletConnectors/chunk-E7TDM6P6.js +205 -0
- package/dist/wallets/walletConnectors/chunk-GBMOX5JN.js +54 -0
- package/dist/wallets/walletConnectors/chunk-GWYZ2IPP.js +1479 -0
- package/dist/wallets/walletConnectors/chunk-HF6GFAE5.js +54 -0
- package/dist/wallets/walletConnectors/chunk-IM7DEERX.js +585 -0
- package/dist/wallets/walletConnectors/chunk-INFMRNND.js +300 -0
- package/dist/wallets/walletConnectors/chunk-JADQLTFW.js +194 -0
- package/dist/wallets/walletConnectors/chunk-JGXJY3SB.js +1 -0
- package/dist/wallets/walletConnectors/chunk-K3VHBOXQ.js +32 -0
- package/dist/wallets/walletConnectors/chunk-KZS2C73S.js +814 -0
- package/dist/wallets/walletConnectors/chunk-L6EUMSX2.js +54 -0
- package/dist/wallets/walletConnectors/chunk-LJNUFDGO.js +205 -0
- package/dist/wallets/walletConnectors/chunk-MO2AXXLI.js +30 -0
- package/dist/wallets/walletConnectors/chunk-NYDDRNUI.js +445 -0
- package/dist/wallets/walletConnectors/chunk-O4DNG6JJ.js +54 -0
- package/dist/wallets/walletConnectors/chunk-OMOYFHBT.js +1485 -0
- package/dist/wallets/walletConnectors/chunk-OTLZVWY7.js +39 -0
- package/dist/wallets/walletConnectors/chunk-PDXO6AOG.js +300 -0
- package/dist/wallets/walletConnectors/chunk-VDWJ3NQ5.js +52 -0
- package/dist/wallets/walletConnectors/chunk-VKOPUEQG.js +445 -0
- package/dist/wallets/walletConnectors/chunk-VTOD7PXP.js +817 -0
- package/dist/wallets/walletConnectors/chunk-WC7BGU5Z.js +814 -0
- package/dist/wallets/walletConnectors/chunk-YDSBY7NO.js +54 -0
- package/dist/wallets/walletConnectors/chunk-YV6IZWGE.js +393 -0
- package/dist/wallets/walletConnectors/chunk-Z5SBGIWT.js +300 -0
- package/dist/wallets/walletConnectors/chunk-ZKCUYHBK.js +300 -0
- package/dist/wallets/walletConnectors/index.js +90 -90
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
AbcError
|
|
4
|
+
} from "./chunk-4P3SPC44.js";
|
|
5
|
+
import {
|
|
6
|
+
PIN_CONFIG,
|
|
7
|
+
STORAGE_PREFIX,
|
|
8
|
+
TOKEN_EXPIRY
|
|
9
|
+
} from "./chunk-DPTDOCWL.js";
|
|
10
|
+
|
|
11
|
+
// src/wallets/walletConnectors/abcWallet/utils.ts
|
|
12
|
+
async function hashPin(pin) {
|
|
13
|
+
if (typeof window === "undefined" || !window.crypto?.subtle) {
|
|
14
|
+
return btoa(pin);
|
|
15
|
+
}
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const data = encoder.encode(pin);
|
|
18
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
|
|
19
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
20
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
21
|
+
return hashHex;
|
|
22
|
+
}
|
|
23
|
+
function validatePin(pin) {
|
|
24
|
+
if (!pin || typeof pin !== "string") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const pinLength = pin.length;
|
|
28
|
+
if (pinLength < PIN_CONFIG.MIN_LENGTH || pinLength > PIN_CONFIG.MAX_LENGTH) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return /^\d+$/.test(pin);
|
|
32
|
+
}
|
|
33
|
+
function validateEmail(email) {
|
|
34
|
+
if (!email || typeof email !== "string") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
|
+
return emailRegex.test(email);
|
|
39
|
+
}
|
|
40
|
+
function getStorageKey(key) {
|
|
41
|
+
return `${STORAGE_PREFIX}${key}`;
|
|
42
|
+
}
|
|
43
|
+
function saveToStorage(key, value) {
|
|
44
|
+
if (typeof window === "undefined")
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const storageKey = getStorageKey(key);
|
|
48
|
+
const serialized = JSON.stringify(value);
|
|
49
|
+
localStorage.setItem(storageKey, serialized);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Failed to save to storage:", error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function loadFromStorage(key) {
|
|
55
|
+
if (typeof window === "undefined")
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
const storageKey = getStorageKey(key);
|
|
59
|
+
const serialized = localStorage.getItem(storageKey);
|
|
60
|
+
if (!serialized)
|
|
61
|
+
return null;
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(serialized);
|
|
64
|
+
} catch {
|
|
65
|
+
return serialized;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Failed to load from storage:", error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function removeFromStorage(key) {
|
|
73
|
+
if (typeof window === "undefined")
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
const storageKey = getStorageKey(key);
|
|
77
|
+
localStorage.removeItem(storageKey);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("Failed to remove from storage:", error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function clearStorage() {
|
|
83
|
+
if (typeof window === "undefined")
|
|
84
|
+
return;
|
|
85
|
+
const keysToRemove = [];
|
|
86
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
87
|
+
const key = localStorage.key(i);
|
|
88
|
+
if (key?.startsWith(STORAGE_PREFIX)) {
|
|
89
|
+
keysToRemove.push(key);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const key of keysToRemove) {
|
|
93
|
+
localStorage.removeItem(key);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function isTokenExpired(expiresAt) {
|
|
97
|
+
if (!expiresAt)
|
|
98
|
+
return true;
|
|
99
|
+
return Date.now() >= expiresAt - TOKEN_EXPIRY.REFRESH_BUFFER;
|
|
100
|
+
}
|
|
101
|
+
function calculateExpiryTimestamp(expiresIn) {
|
|
102
|
+
return Date.now() + expiresIn * 1e3;
|
|
103
|
+
}
|
|
104
|
+
function saveAuthState(state) {
|
|
105
|
+
saveToStorage("auth_state" /* AUTH_STATE */, state);
|
|
106
|
+
if (state.user) {
|
|
107
|
+
saveToStorage("user" /* USER */, state.user);
|
|
108
|
+
}
|
|
109
|
+
if (state.wallet) {
|
|
110
|
+
saveToStorage("wallet" /* WALLET */, state.wallet);
|
|
111
|
+
}
|
|
112
|
+
if (state.solanaWallet) {
|
|
113
|
+
saveToStorage("solana_wallet" /* SOLANA_WALLET */, state.solanaWallet);
|
|
114
|
+
}
|
|
115
|
+
if (state.bitcoinWallet) {
|
|
116
|
+
saveToStorage("bitcoin_wallet" /* BITCOIN_WALLET */, state.bitcoinWallet);
|
|
117
|
+
}
|
|
118
|
+
if (state.tronWallet) {
|
|
119
|
+
saveToStorage("tron_wallet" /* TRON_WALLET */, state.tronWallet);
|
|
120
|
+
}
|
|
121
|
+
if (state.accessToken) {
|
|
122
|
+
saveToStorage("access_token" /* ACCESS_TOKEN */, state.accessToken);
|
|
123
|
+
}
|
|
124
|
+
if (state.refreshToken) {
|
|
125
|
+
saveToStorage("refresh_token" /* REFRESH_TOKEN */, state.refreshToken);
|
|
126
|
+
}
|
|
127
|
+
if (state.expiresAt) {
|
|
128
|
+
saveToStorage("expires_at" /* EXPIRES_AT */, state.expiresAt);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function hydrateAuthStateFromIndividualStorage(state) {
|
|
132
|
+
const user = loadFromStorage("user" /* USER */);
|
|
133
|
+
const wallet = loadFromStorage("wallet" /* WALLET */);
|
|
134
|
+
const solanaWallet = loadFromStorage(
|
|
135
|
+
"solana_wallet" /* SOLANA_WALLET */
|
|
136
|
+
);
|
|
137
|
+
const bitcoinWallet = loadFromStorage(
|
|
138
|
+
"bitcoin_wallet" /* BITCOIN_WALLET */
|
|
139
|
+
);
|
|
140
|
+
const tronWallet = loadFromStorage("tron_wallet" /* TRON_WALLET */);
|
|
141
|
+
const accessToken = loadFromStorage("access_token" /* ACCESS_TOKEN */);
|
|
142
|
+
const refreshToken = loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
143
|
+
const expiresAt = loadFromStorage("expires_at" /* EXPIRES_AT */);
|
|
144
|
+
const nextState = {
|
|
145
|
+
...state,
|
|
146
|
+
user: state.user || user || null,
|
|
147
|
+
wallet: state.wallet || wallet || null,
|
|
148
|
+
solanaWallet: state.solanaWallet || solanaWallet || null,
|
|
149
|
+
bitcoinWallet: state.bitcoinWallet || bitcoinWallet || null,
|
|
150
|
+
tronWallet: state.tronWallet || tronWallet || null,
|
|
151
|
+
accessToken: state.accessToken || accessToken || null,
|
|
152
|
+
refreshToken: state.refreshToken || refreshToken || null,
|
|
153
|
+
expiresAt: state.expiresAt || expiresAt || null
|
|
154
|
+
};
|
|
155
|
+
const wasHydrated = nextState.user !== state.user || nextState.wallet !== state.wallet || nextState.solanaWallet !== state.solanaWallet || nextState.bitcoinWallet !== state.bitcoinWallet || nextState.tronWallet !== state.tronWallet || nextState.accessToken !== state.accessToken || nextState.refreshToken !== state.refreshToken || nextState.expiresAt !== state.expiresAt;
|
|
156
|
+
if (wasHydrated) {
|
|
157
|
+
saveToStorage("auth_state" /* AUTH_STATE */, nextState);
|
|
158
|
+
}
|
|
159
|
+
return nextState;
|
|
160
|
+
}
|
|
161
|
+
function loadAuthState() {
|
|
162
|
+
const state = loadFromStorage("auth_state" /* AUTH_STATE */);
|
|
163
|
+
if (state) {
|
|
164
|
+
if (state.accessToken && isTokenExpired(state.expiresAt)) {
|
|
165
|
+
clearStorage();
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return hydrateAuthStateFromIndividualStorage(state);
|
|
169
|
+
}
|
|
170
|
+
const user = loadFromStorage("user" /* USER */);
|
|
171
|
+
const wallet = loadFromStorage("wallet" /* WALLET */);
|
|
172
|
+
const solanaWallet = loadFromStorage("solana_wallet" /* SOLANA_WALLET */);
|
|
173
|
+
const accessToken = loadFromStorage("access_token" /* ACCESS_TOKEN */);
|
|
174
|
+
const refreshToken = loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
175
|
+
const expiresAt = loadFromStorage("expires_at" /* EXPIRES_AT */);
|
|
176
|
+
if (!user || !accessToken) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const bitcoinWallet = loadFromStorage("bitcoin_wallet" /* BITCOIN_WALLET */);
|
|
180
|
+
const tronWallet = loadFromStorage("tron_wallet" /* TRON_WALLET */);
|
|
181
|
+
return {
|
|
182
|
+
isAuthenticated: true,
|
|
183
|
+
user,
|
|
184
|
+
wallet,
|
|
185
|
+
solanaWallet,
|
|
186
|
+
bitcoinWallet,
|
|
187
|
+
tronWallet,
|
|
188
|
+
accessToken,
|
|
189
|
+
refreshToken,
|
|
190
|
+
expiresAt
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function clearAuthState() {
|
|
194
|
+
clearStorage();
|
|
195
|
+
}
|
|
196
|
+
function createAbcError(code, message, details, statusCode) {
|
|
197
|
+
return new AbcError(code, message, details, statusCode);
|
|
198
|
+
}
|
|
199
|
+
function hexToNumber(hex) {
|
|
200
|
+
return Number.parseInt(hex, 16);
|
|
201
|
+
}
|
|
202
|
+
function numberToHex(num) {
|
|
203
|
+
return `0x${num.toString(16)}`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export {
|
|
207
|
+
hashPin,
|
|
208
|
+
validatePin,
|
|
209
|
+
validateEmail,
|
|
210
|
+
getStorageKey,
|
|
211
|
+
saveToStorage,
|
|
212
|
+
loadFromStorage,
|
|
213
|
+
removeFromStorage,
|
|
214
|
+
clearStorage,
|
|
215
|
+
isTokenExpired,
|
|
216
|
+
calculateExpiryTimestamp,
|
|
217
|
+
saveAuthState,
|
|
218
|
+
loadAuthState,
|
|
219
|
+
clearAuthState,
|
|
220
|
+
createAbcError,
|
|
221
|
+
hexToNumber,
|
|
222
|
+
numberToHex
|
|
223
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
STORAGE_PREFIX
|
|
4
|
+
} from "./chunk-DPTDOCWL.js";
|
|
5
|
+
|
|
6
|
+
// src/wallets/walletConnectors/abcWallet/sessionUtils.ts
|
|
7
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
8
|
+
var SessionExpiredError = class extends Error {
|
|
9
|
+
constructor(message = "Session expired. Please reconnect your wallet.") {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "SessionExpiredError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function dispatchSessionExpired() {
|
|
15
|
+
if (typeof window !== "undefined") {
|
|
16
|
+
console.warn("[SessionUtils] \u{1F6A8} dispatchSessionExpired called from:");
|
|
17
|
+
console.trace();
|
|
18
|
+
window.dispatchEvent(new CustomEvent("talkenkit:session_expired"));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function handleUnauthorizedResponse(response) {
|
|
22
|
+
if (response.status === 401) {
|
|
23
|
+
dispatchSessionExpired();
|
|
24
|
+
throw new SessionExpiredError(
|
|
25
|
+
"Session expired. Please reconnect your wallet."
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function fetchWithSessionCheck(url, options) {
|
|
30
|
+
const response = await fetch(url, options);
|
|
31
|
+
if (!response.ok && response.status === 401) {
|
|
32
|
+
const errorText = await response.text();
|
|
33
|
+
console.error("[ABC WaaS] \u274C Unauthorized (401):", errorText);
|
|
34
|
+
dispatchSessionExpired();
|
|
35
|
+
throw new SessionExpiredError(
|
|
36
|
+
"Session expired. Please reconnect your wallet."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
async function refreshAccessToken(pinCallback) {
|
|
42
|
+
if (pinCallback) {
|
|
43
|
+
await pinCallback();
|
|
44
|
+
}
|
|
45
|
+
const api = getTalkenApiClient();
|
|
46
|
+
if (!api) {
|
|
47
|
+
console.warn(
|
|
48
|
+
"[SessionUtils] TalkenApiClient not initialized - opening connect modal"
|
|
49
|
+
);
|
|
50
|
+
dispatchSessionExpired();
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
52
|
+
throw new SessionExpiredError(
|
|
53
|
+
"Session expired. Please reconnect your wallet."
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const refreshToken = api.getRefreshToken() || localStorage.getItem(`${STORAGE_PREFIX}refresh_token`);
|
|
57
|
+
if (!refreshToken) {
|
|
58
|
+
console.warn("[SessionUtils] No refresh token - opening connect modal");
|
|
59
|
+
dispatchSessionExpired();
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
61
|
+
throw new SessionExpiredError(
|
|
62
|
+
"Session expired. Please reconnect your wallet."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const res = await api.auth.refresh();
|
|
67
|
+
const expiresAt = Date.now() + res.expiresIn * 1e3;
|
|
68
|
+
api.setTokens(res.accessToken, res.refreshToken || refreshToken, expiresAt);
|
|
69
|
+
localStorage.setItem(`${STORAGE_PREFIX}access_token`, res.accessToken);
|
|
70
|
+
if (res.refreshToken) {
|
|
71
|
+
localStorage.setItem(`${STORAGE_PREFIX}refresh_token`, res.refreshToken);
|
|
72
|
+
}
|
|
73
|
+
localStorage.setItem(`${STORAGE_PREFIX}expires_at`, String(expiresAt));
|
|
74
|
+
console.log(
|
|
75
|
+
"[SessionUtils] \u2705 Token refreshed - expires in:",
|
|
76
|
+
(res.expiresIn / 60 / 60).toFixed(2),
|
|
77
|
+
"hours"
|
|
78
|
+
);
|
|
79
|
+
return res.accessToken;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("[SessionUtils] Token refresh failed:", error);
|
|
82
|
+
dispatchSessionExpired();
|
|
83
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
84
|
+
throw new SessionExpiredError(
|
|
85
|
+
"Session expired. Please reconnect your wallet."
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
SessionExpiredError,
|
|
92
|
+
dispatchSessionExpired,
|
|
93
|
+
handleUnauthorizedResponse,
|
|
94
|
+
fetchWithSessionCheck,
|
|
95
|
+
refreshAccessToken
|
|
96
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
loadAuthState,
|
|
4
|
+
saveAuthState
|
|
5
|
+
} from "./chunk-A66MTFML.js";
|
|
6
|
+
|
|
7
|
+
// src/wallets/walletConnectors/abcWallet/abcBitcoinConnector.ts
|
|
8
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
9
|
+
var AbcBitcoinConnector = class {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.wallet = null;
|
|
12
|
+
this.connected = false;
|
|
13
|
+
// Event listeners
|
|
14
|
+
this.connectListeners = /* @__PURE__ */ new Set();
|
|
15
|
+
this.disconnectListeners = /* @__PURE__ */ new Set();
|
|
16
|
+
this.accountsChangedListeners = /* @__PURE__ */ new Set();
|
|
17
|
+
this.networkChangedListeners = /* @__PURE__ */ new Set();
|
|
18
|
+
this.provider = config.provider;
|
|
19
|
+
this.setupProviderListeners();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Setup provider event listeners
|
|
23
|
+
*/
|
|
24
|
+
setupProviderListeners() {
|
|
25
|
+
this.provider.on("connect", () => {
|
|
26
|
+
this.connected = true;
|
|
27
|
+
if (this.wallet) {
|
|
28
|
+
for (const listener of this.connectListeners) {
|
|
29
|
+
listener(this.wallet);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.provider.on("disconnect", () => {
|
|
34
|
+
this.connected = false;
|
|
35
|
+
this.wallet = null;
|
|
36
|
+
for (const listener of this.disconnectListeners) {
|
|
37
|
+
listener();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
this.provider.on("accountsChanged", (accounts) => {
|
|
41
|
+
for (const listener of this.accountsChangedListeners) {
|
|
42
|
+
listener(accounts);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.provider.on("networkChanged", (network) => {
|
|
46
|
+
for (const listener of this.networkChangedListeners) {
|
|
47
|
+
listener(network);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Connect Bitcoin wallet
|
|
53
|
+
*/
|
|
54
|
+
async connect() {
|
|
55
|
+
try {
|
|
56
|
+
const authState = loadAuthState();
|
|
57
|
+
console.log("[BitcoinConnector] \u{1F527} connect() called:", {
|
|
58
|
+
hasAuthState: !!authState,
|
|
59
|
+
isAuthenticated: authState?.isAuthenticated,
|
|
60
|
+
hasBitcoinWallet: !!authState?.bitcoinWallet,
|
|
61
|
+
bitcoinAddress: authState?.bitcoinWallet?.address
|
|
62
|
+
});
|
|
63
|
+
if (!authState || !authState.isAuthenticated || !authState.bitcoinWallet) {
|
|
64
|
+
throw new Error("BITCOIN_LOGIN_REQUIRED");
|
|
65
|
+
}
|
|
66
|
+
this.wallet = authState.bitcoinWallet;
|
|
67
|
+
this.provider.setWallet(authState.bitcoinWallet);
|
|
68
|
+
console.log("[BitcoinConnector] \u2705 Wallet set:", {
|
|
69
|
+
address: authState.bitcoinWallet.address,
|
|
70
|
+
publicKey: authState.bitcoinWallet.publicKey,
|
|
71
|
+
addressType: authState.bitcoinWallet.addressType,
|
|
72
|
+
network: authState.bitcoinWallet.network
|
|
73
|
+
});
|
|
74
|
+
this.connected = true;
|
|
75
|
+
return {
|
|
76
|
+
address: authState.bitcoinWallet.address,
|
|
77
|
+
publicKey: authState.bitcoinWallet.publicKey,
|
|
78
|
+
network: authState.bitcoinWallet.network
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error.message === "BITCOIN_LOGIN_REQUIRED") {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
console.error("[BitcoinConnector] \u274C connect error:", error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Disconnect Bitcoin wallet
|
|
90
|
+
*/
|
|
91
|
+
async disconnect() {
|
|
92
|
+
try {
|
|
93
|
+
this.provider.clearWallet();
|
|
94
|
+
this.wallet = null;
|
|
95
|
+
this.connected = false;
|
|
96
|
+
console.log("[BitcoinConnector] \u2705 Wallet disconnected");
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("[BitcoinConnector] \u274C disconnect error:", error);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get Bitcoin address
|
|
104
|
+
*/
|
|
105
|
+
async getAddress() {
|
|
106
|
+
return this.provider.getAddress();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get compressed public key (33 bytes)
|
|
110
|
+
*/
|
|
111
|
+
async getPublicKey() {
|
|
112
|
+
return this.provider.getPublicKey();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get address type (bech32, p2pkh, etc.)
|
|
116
|
+
*/
|
|
117
|
+
getAddressType() {
|
|
118
|
+
return this.provider.getAddressType();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get UTXOs
|
|
122
|
+
*/
|
|
123
|
+
async getUtxos(forceRefresh = false) {
|
|
124
|
+
return this.provider.getUtxos(forceRefresh);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get balance (in satoshis)
|
|
128
|
+
*/
|
|
129
|
+
async getBalance(forceRefresh = false) {
|
|
130
|
+
return this.provider.getBalance(forceRefresh);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Estimate transaction fee
|
|
134
|
+
*/
|
|
135
|
+
async estimateFee(targetBlocks = 6) {
|
|
136
|
+
return this.provider.estimateFee(targetBlocks);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sign Bitcoin message (BIP-322)
|
|
140
|
+
* NOTE: Currently not supported - Bitcoin uses v2 API which doesn't have message signing endpoint
|
|
141
|
+
*/
|
|
142
|
+
async signMessage(message) {
|
|
143
|
+
return this.provider.signMessage(message);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Send Bitcoin transaction (high-level API)
|
|
147
|
+
* Creates, signs, and broadcasts transaction
|
|
148
|
+
*/
|
|
149
|
+
async sendTransaction(params) {
|
|
150
|
+
return this.provider.sendTransaction(params);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Broadcast signed transaction to network (low-level API)
|
|
154
|
+
*/
|
|
155
|
+
async broadcastTransaction(rawTransaction, psbt) {
|
|
156
|
+
return this.provider.broadcastTransaction(rawTransaction, psbt);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if authorized (has valid session)
|
|
160
|
+
*/
|
|
161
|
+
async isAuthorized() {
|
|
162
|
+
try {
|
|
163
|
+
const authState = loadAuthState();
|
|
164
|
+
if (!authState || !authState.isAuthenticated) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (!authState.bitcoinWallet) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
const api = getTalkenApiClient();
|
|
171
|
+
return !!api && !api.isTokenExpired();
|
|
172
|
+
} catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if connected
|
|
178
|
+
*/
|
|
179
|
+
isConnected() {
|
|
180
|
+
return this.connected && this.provider.isConnected();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get current wallet
|
|
184
|
+
*/
|
|
185
|
+
getWallet() {
|
|
186
|
+
return this.wallet;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get provider
|
|
190
|
+
*/
|
|
191
|
+
getProvider() {
|
|
192
|
+
return this.provider;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get wallet info
|
|
196
|
+
*/
|
|
197
|
+
getWalletInfo() {
|
|
198
|
+
return this.provider.getWalletInfo();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Switch network
|
|
202
|
+
*/
|
|
203
|
+
async switchNetwork(network) {
|
|
204
|
+
this.provider.setNetwork(network);
|
|
205
|
+
const authState = loadAuthState();
|
|
206
|
+
if (authState?.bitcoinWallet) {
|
|
207
|
+
authState.bitcoinWallet.network = network === "mainnet" ? "bitcoin" /* Mainnet */ : "bitcoin_testnet" /* Testnet */;
|
|
208
|
+
saveAuthState(authState);
|
|
209
|
+
}
|
|
210
|
+
console.log("[BitcoinConnector] \u{1F504} Network switched to:", network);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get current network
|
|
214
|
+
*/
|
|
215
|
+
getNetwork() {
|
|
216
|
+
return this.provider.getNetwork().type;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Refresh UTXO cache
|
|
220
|
+
*/
|
|
221
|
+
async refreshUtxos() {
|
|
222
|
+
return this.provider.refreshUtxos();
|
|
223
|
+
}
|
|
224
|
+
on(event, listener) {
|
|
225
|
+
switch (event) {
|
|
226
|
+
case "connect":
|
|
227
|
+
this.connectListeners.add(listener);
|
|
228
|
+
break;
|
|
229
|
+
case "disconnect":
|
|
230
|
+
this.disconnectListeners.add(listener);
|
|
231
|
+
break;
|
|
232
|
+
case "accountsChanged":
|
|
233
|
+
this.accountsChangedListeners.add(listener);
|
|
234
|
+
break;
|
|
235
|
+
case "networkChanged":
|
|
236
|
+
this.networkChangedListeners.add(listener);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
off(event, listener) {
|
|
241
|
+
switch (event) {
|
|
242
|
+
case "connect":
|
|
243
|
+
this.connectListeners.delete(listener);
|
|
244
|
+
break;
|
|
245
|
+
case "disconnect":
|
|
246
|
+
this.disconnectListeners.delete(listener);
|
|
247
|
+
break;
|
|
248
|
+
case "accountsChanged":
|
|
249
|
+
this.accountsChangedListeners.delete(listener);
|
|
250
|
+
break;
|
|
251
|
+
case "networkChanged":
|
|
252
|
+
this.networkChangedListeners.delete(listener);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Remove all listeners
|
|
258
|
+
*/
|
|
259
|
+
removeAllListeners() {
|
|
260
|
+
this.connectListeners.clear();
|
|
261
|
+
this.disconnectListeners.clear();
|
|
262
|
+
this.accountsChangedListeners.clear();
|
|
263
|
+
this.networkChangedListeners.clear();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
function createAbcBitcoinConnector(config) {
|
|
267
|
+
return new AbcBitcoinConnector(config);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
AbcBitcoinConnector,
|
|
272
|
+
createAbcBitcoinConnector
|
|
273
|
+
};
|