@talken/talkenkit 2.3.5 → 2.3.7
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/components/ChainIndicator/ChainIndicator.css.d.ts +4 -0
- package/dist/components/ChainIndicator/ChainIndicator.d.ts +53 -0
- package/dist/components/ChainIndicator/index.d.ts +2 -0
- package/dist/components/ChainSelector/ChainSelector.css.d.ts +5 -0
- package/dist/components/ChainSelector/ChainSelector.d.ts +38 -0
- package/dist/components/ChainSelector/index.d.ts +2 -0
- package/dist/components/ConnectButton/ConnectButtonRenderer.d.ts +9 -0
- package/dist/components/ConnectOptions/DesktopOptions.d.ts +5 -1
- package/dist/components/ConnectOptions/MultiChainConnectOptions.d.ts +31 -0
- package/dist/components/ConnectOptions/index.d.ts +3 -0
- package/dist/components/ModalSelection/ModalSelection.d.ts +2 -1
- package/dist/components/ProfileDetails/ProfileDetails.d.ts +1 -2
- package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +8 -1
- package/dist/components/SolanaWalletList/SolanaWalletList.css.d.ts +7 -0
- package/dist/components/SolanaWalletList/SolanaWalletList.d.ts +32 -0
- package/dist/components/SolanaWalletList/index.d.ts +2 -0
- package/dist/contexts/MultiChainContext.d.ts +68 -0
- package/dist/contexts/index.d.ts +7 -0
- package/dist/index.css +105 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1445 -899
- package/dist/solana/SolanaWalletProvider.d.ts +38 -0
- package/dist/solana/config.d.ts +57 -0
- package/dist/solana/index.d.ts +11 -0
- package/dist/solana/utils/detection.d.ts +27 -0
- package/dist/solana/wallets/backpackWallet.d.ts +19 -0
- package/dist/solana/wallets/index.d.ts +8 -0
- package/dist/solana/wallets/phantomSolanaWallet.d.ts +17 -0
- package/dist/solana/wallets/solflareWallet.d.ts +17 -0
- package/dist/types/solana.d.ts +97 -0
- package/dist/wallets/recentSolanaWalletIds.d.ts +16 -0
- package/dist/wallets/walletConnectors/abcWallet/abcApi.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWallet.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/index.js +4 -4
- package/dist/wallets/walletConnectors/chunk-3SVPZCA6.js +71 -0
- package/dist/wallets/walletConnectors/chunk-5QEUEPNY.js +94 -0
- package/dist/wallets/walletConnectors/chunk-B6JLYR3I.js +66 -0
- package/dist/wallets/walletConnectors/{chunk-6JKWIEGA.js → chunk-BHMMHU7Y.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-HKWBR5B7.js +102 -0
- package/dist/wallets/walletConnectors/chunk-K4APJ4PE.js +96 -0
- package/dist/wallets/walletConnectors/chunk-LJ2B47VF.js +108 -0
- package/dist/wallets/walletConnectors/chunk-LXINMUQC.js +186 -0
- package/dist/wallets/walletConnectors/chunk-MORUEOYX.js +76 -0
- package/dist/wallets/walletConnectors/chunk-MQTXA63X.js +27 -0
- package/dist/wallets/walletConnectors/{chunk-G2IHR6PW.js → chunk-NLKL4KD2.js} +11 -11
- package/dist/wallets/walletConnectors/{chunk-KOT7JYJR.js → chunk-OEB7MRS5.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-RWIZ25FJ.js → chunk-P2E4LSYH.js} +17 -23
- package/dist/wallets/walletConnectors/chunk-PMZJGS7X.js +73 -0
- package/dist/wallets/walletConnectors/{chunk-BRM4ZVXZ.js → chunk-RSZS2RMC.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-WZZVA3LW.js +101 -0
- package/dist/wallets/walletConnectors/chunk-XEIKWKH7.js +63 -0
- package/dist/wallets/walletConnectors/chunk-XOQNQKZE.js +98 -0
- package/dist/wallets/walletConnectors/chunk-ZAGAF6PO.js +63 -0
- package/dist/wallets/walletConnectors/chunk-ZJ6OFFD5.js +95 -0
- package/dist/wallets/walletConnectors/index.js +24 -24
- package/package.json +17 -11
- package/LICENSE +0 -9
- package/dist/wallets/walletConnectors/chunk-2J66VMY5.js +0 -152
- package/dist/wallets/walletConnectors/chunk-2ZPGPZCP.js +0 -228
- package/dist/wallets/walletConnectors/chunk-3DPCIDW6.js +0 -1730
- package/dist/wallets/walletConnectors/chunk-4HKJ53H3.js +0 -1742
- package/dist/wallets/walletConnectors/chunk-5EARL7FN.js +0 -39
- package/dist/wallets/walletConnectors/chunk-7SXCH5TL.js +0 -1752
- package/dist/wallets/walletConnectors/chunk-7UZBDZZZ.js +0 -599
- package/dist/wallets/walletConnectors/chunk-BUDWZAL7.js +0 -44
- package/dist/wallets/walletConnectors/chunk-CSWWNAYR.js +0 -44
- package/dist/wallets/walletConnectors/chunk-E4N7SPPU.js +0 -39
- package/dist/wallets/walletConnectors/chunk-ENU7XLF5.js +0 -44
- package/dist/wallets/walletConnectors/chunk-ESRU5KCF.js +0 -151
- package/dist/wallets/walletConnectors/chunk-FF7ZIXKD.js +0 -39
- package/dist/wallets/walletConnectors/chunk-FJCL2YPU.js +0 -1737
- package/dist/wallets/walletConnectors/chunk-FSU3WBH3.js +0 -63
- package/dist/wallets/walletConnectors/chunk-HD6YCICR.js +0 -228
- package/dist/wallets/walletConnectors/chunk-HDYBRMYW.js +0 -194
- package/dist/wallets/walletConnectors/chunk-HIZCIW5L.js +0 -228
- package/dist/wallets/walletConnectors/chunk-JRNBDHFL.js +0 -44
- package/dist/wallets/walletConnectors/chunk-KIQDE4N6.js +0 -39
- package/dist/wallets/walletConnectors/chunk-KZOSE2PI.js +0 -228
- package/dist/wallets/walletConnectors/chunk-LNZJLKFB.js +0 -39
- package/dist/wallets/walletConnectors/chunk-LV765WZL.js +0 -1748
- package/dist/wallets/walletConnectors/chunk-MSI2BPP5.js +0 -1722
- package/dist/wallets/walletConnectors/chunk-MX2IY5CD.js +0 -44
- package/dist/wallets/walletConnectors/chunk-NLX2EV7O.js +0 -44
- package/dist/wallets/walletConnectors/chunk-NVAZ3B3V.js +0 -228
- package/dist/wallets/walletConnectors/chunk-OEWU3ZMN.js +0 -39
- package/dist/wallets/walletConnectors/chunk-P2MTINFI.js +0 -280
- package/dist/wallets/walletConnectors/chunk-PNMSIVVT.js +0 -44
- package/dist/wallets/walletConnectors/chunk-PZNYT2HC.js +0 -1722
- package/dist/wallets/walletConnectors/chunk-QPAE4SDS.js +0 -39
- package/dist/wallets/walletConnectors/chunk-QZRNNI3E.js +0 -39
- package/dist/wallets/walletConnectors/chunk-R4UYVU5X.js +0 -1721
- package/dist/wallets/walletConnectors/chunk-RLBGBBIO.js +0 -309
- package/dist/wallets/walletConnectors/chunk-TUUNSVKZ.js +0 -345
- package/dist/wallets/walletConnectors/chunk-U2CUEL35.js +0 -240
- package/dist/wallets/walletConnectors/chunk-V6NRLREB.js +0 -44
- package/dist/wallets/walletConnectors/chunk-VM7AEC7H.js +0 -39
- package/dist/wallets/walletConnectors/chunk-W2VDZD74.js +0 -478
- package/dist/wallets/walletConnectors/chunk-WAO3KL5U.js +0 -285
- package/dist/wallets/walletConnectors/chunk-WPHTIILX.js +0 -228
- package/dist/wallets/walletConnectors/chunk-WSCJY2QD.js +0 -228
- package/dist/wallets/walletConnectors/chunk-X3JQB5QL.js +0 -44
- package/dist/wallets/walletConnectors/chunk-X4CDP7L7.js +0 -228
- package/dist/wallets/walletConnectors/chunk-XETOVXYM.js +0 -228
- package/dist/wallets/walletConnectors/chunk-XYPR4BAF.js +0 -436
- package/dist/wallets/walletConnectors/chunk-Z2ZRPTPX.js +0 -1726
- package/dist/wallets/walletConnectors/{chunk-VCBVYFLJ.js → chunk-6TLWAEJV.js} +7 -7
- package/dist/wallets/walletConnectors/{chunk-47TQ23J4.js → chunk-74ALNZG4.js} +8 -8
- package/dist/wallets/walletConnectors/{chunk-66SCJ77O.js → chunk-CM5OGUJV.js} +6 -6
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
AbcError,
|
|
4
|
-
AbcStorageKey
|
|
5
|
-
} from "./chunk-5UEBEMEE.js";
|
|
6
|
-
import {
|
|
7
|
-
PIN_CONFIG,
|
|
8
|
-
STORAGE_PREFIX,
|
|
9
|
-
TOKEN_EXPIRY
|
|
10
|
-
} from "./chunk-VETRBBA2.js";
|
|
11
|
-
|
|
12
|
-
// src/wallets/walletConnectors/abcWallet/utils.ts
|
|
13
|
-
import CryptoJS from "crypto-js";
|
|
14
|
-
async function hashPin(pin) {
|
|
15
|
-
if (typeof window === "undefined" || !window.crypto?.subtle) {
|
|
16
|
-
return btoa(pin);
|
|
17
|
-
}
|
|
18
|
-
const encoder = new TextEncoder();
|
|
19
|
-
const data = encoder.encode(pin);
|
|
20
|
-
const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
|
|
21
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
22
|
-
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
23
|
-
return hashHex;
|
|
24
|
-
}
|
|
25
|
-
function validatePin(pin) {
|
|
26
|
-
if (!pin || typeof pin !== "string") {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const pinLength = pin.length;
|
|
30
|
-
if (pinLength < PIN_CONFIG.MIN_LENGTH || pinLength > PIN_CONFIG.MAX_LENGTH) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return /^\d+$/.test(pin);
|
|
34
|
-
}
|
|
35
|
-
function validateEmail(email) {
|
|
36
|
-
if (!email || typeof email !== "string") {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
40
|
-
return emailRegex.test(email);
|
|
41
|
-
}
|
|
42
|
-
function getStorageKey(key) {
|
|
43
|
-
return `${STORAGE_PREFIX}${key}`;
|
|
44
|
-
}
|
|
45
|
-
function saveToStorage(key, value) {
|
|
46
|
-
if (typeof window === "undefined")
|
|
47
|
-
return;
|
|
48
|
-
try {
|
|
49
|
-
const storageKey = getStorageKey(key);
|
|
50
|
-
const serialized = JSON.stringify(value);
|
|
51
|
-
localStorage.setItem(storageKey, serialized);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("Failed to save to storage:", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function loadFromStorage(key) {
|
|
57
|
-
if (typeof window === "undefined")
|
|
58
|
-
return null;
|
|
59
|
-
try {
|
|
60
|
-
const storageKey = getStorageKey(key);
|
|
61
|
-
const serialized = localStorage.getItem(storageKey);
|
|
62
|
-
if (!serialized)
|
|
63
|
-
return null;
|
|
64
|
-
try {
|
|
65
|
-
return JSON.parse(serialized);
|
|
66
|
-
} catch {
|
|
67
|
-
return serialized;
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error("Failed to load from storage:", error);
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function removeFromStorage(key) {
|
|
75
|
-
if (typeof window === "undefined")
|
|
76
|
-
return;
|
|
77
|
-
try {
|
|
78
|
-
const storageKey = getStorageKey(key);
|
|
79
|
-
localStorage.removeItem(storageKey);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error("Failed to remove from storage:", error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function clearStorage() {
|
|
85
|
-
if (typeof window === "undefined")
|
|
86
|
-
return;
|
|
87
|
-
for (const key of Object.values(AbcStorageKey)) {
|
|
88
|
-
removeFromStorage(key);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function isTokenExpired(expiresAt) {
|
|
92
|
-
if (!expiresAt)
|
|
93
|
-
return true;
|
|
94
|
-
return Date.now() >= expiresAt - TOKEN_EXPIRY.REFRESH_BUFFER;
|
|
95
|
-
}
|
|
96
|
-
function calculateExpiryTimestamp(expiresIn) {
|
|
97
|
-
return Date.now() + expiresIn * 1e3;
|
|
98
|
-
}
|
|
99
|
-
function saveAuthState(state) {
|
|
100
|
-
saveToStorage("auth_state" /* AUTH_STATE */, state);
|
|
101
|
-
if (state.user) {
|
|
102
|
-
saveToStorage("user" /* USER */, state.user);
|
|
103
|
-
}
|
|
104
|
-
if (state.wallet) {
|
|
105
|
-
saveToStorage("wallet" /* WALLET */, state.wallet);
|
|
106
|
-
}
|
|
107
|
-
if (state.solanaWallet) {
|
|
108
|
-
saveToStorage("solana_wallet" /* SOLANA_WALLET */, state.solanaWallet);
|
|
109
|
-
}
|
|
110
|
-
if (state.bitcoinWallet) {
|
|
111
|
-
saveToStorage("bitcoin_wallet" /* BITCOIN_WALLET */, state.bitcoinWallet);
|
|
112
|
-
}
|
|
113
|
-
if (state.accessToken) {
|
|
114
|
-
saveToStorage("access_token" /* ACCESS_TOKEN */, state.accessToken);
|
|
115
|
-
}
|
|
116
|
-
if (state.refreshToken) {
|
|
117
|
-
saveToStorage("refresh_token" /* REFRESH_TOKEN */, state.refreshToken);
|
|
118
|
-
}
|
|
119
|
-
if (state.expiresAt) {
|
|
120
|
-
saveToStorage("expires_at" /* EXPIRES_AT */, state.expiresAt);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function loadAuthState() {
|
|
124
|
-
console.log("[DEBUG loadAuthState] Starting auth state load");
|
|
125
|
-
const state = loadFromStorage("auth_state" /* AUTH_STATE */);
|
|
126
|
-
console.log("[DEBUG loadAuthState] Loaded state from AUTH_STATE key:", state);
|
|
127
|
-
if (state) {
|
|
128
|
-
console.log("[DEBUG loadAuthState] State exists, checking expiration");
|
|
129
|
-
if (state.accessToken && isTokenExpired(state.expiresAt)) {
|
|
130
|
-
console.log("[DEBUG loadAuthState] Token expired, clearing state");
|
|
131
|
-
clearStorage();
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
console.log("[DEBUG loadAuthState] Returning valid state");
|
|
135
|
-
return state;
|
|
136
|
-
}
|
|
137
|
-
console.log("[DEBUG loadAuthState] No state found, trying individual items");
|
|
138
|
-
const user = loadFromStorage("user" /* USER */);
|
|
139
|
-
const wallet = loadFromStorage("wallet" /* WALLET */);
|
|
140
|
-
const solanaWallet = loadFromStorage("solana_wallet" /* SOLANA_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
|
-
console.log("[DEBUG loadAuthState] Individual items:", {
|
|
145
|
-
user,
|
|
146
|
-
wallet,
|
|
147
|
-
solanaWallet,
|
|
148
|
-
accessToken
|
|
149
|
-
});
|
|
150
|
-
if (!user || !accessToken) {
|
|
151
|
-
console.log(
|
|
152
|
-
"[DEBUG loadAuthState] Missing user or accessToken, returning null"
|
|
153
|
-
);
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
console.log(
|
|
157
|
-
"[DEBUG loadAuthState] Reconstructing state from individual items"
|
|
158
|
-
);
|
|
159
|
-
const bitcoinWallet = loadFromStorage("bitcoin_wallet" /* BITCOIN_WALLET */);
|
|
160
|
-
return {
|
|
161
|
-
isAuthenticated: true,
|
|
162
|
-
user,
|
|
163
|
-
wallet,
|
|
164
|
-
solanaWallet,
|
|
165
|
-
bitcoinWallet,
|
|
166
|
-
accessToken,
|
|
167
|
-
refreshToken,
|
|
168
|
-
expiresAt
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function clearAuthState() {
|
|
172
|
-
clearStorage();
|
|
173
|
-
}
|
|
174
|
-
function getChainType(chainId) {
|
|
175
|
-
if (chainId === 900)
|
|
176
|
-
return "solana";
|
|
177
|
-
if (chainId === 800)
|
|
178
|
-
return "bitcoin";
|
|
179
|
-
return "evm";
|
|
180
|
-
}
|
|
181
|
-
function formatAddress(address, startLength = 6, endLength = 4) {
|
|
182
|
-
if (!address || address.length <= startLength + endLength) {
|
|
183
|
-
return address;
|
|
184
|
-
}
|
|
185
|
-
const start = address.substring(0, startLength);
|
|
186
|
-
const end = address.substring(address.length - endLength);
|
|
187
|
-
return `${start}...${end}`;
|
|
188
|
-
}
|
|
189
|
-
function createAbcError(code, message, details) {
|
|
190
|
-
return new AbcError(code, message, details);
|
|
191
|
-
}
|
|
192
|
-
function sleep(ms) {
|
|
193
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
194
|
-
}
|
|
195
|
-
async function retry(fn, maxRetries = 3, delay = 1e3, backoffMultiplier = 2) {
|
|
196
|
-
let lastError = null;
|
|
197
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
198
|
-
try {
|
|
199
|
-
return await fn();
|
|
200
|
-
} catch (error) {
|
|
201
|
-
lastError = error;
|
|
202
|
-
if (attempt < maxRetries - 1) {
|
|
203
|
-
const waitTime = delay * backoffMultiplier ** attempt;
|
|
204
|
-
await sleep(waitTime);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
throw lastError || new Error("Retry failed");
|
|
209
|
-
}
|
|
210
|
-
function parseApiError(error) {
|
|
211
|
-
if (error instanceof AbcError) {
|
|
212
|
-
return error;
|
|
213
|
-
}
|
|
214
|
-
if (!error.response) {
|
|
215
|
-
return createAbcError(
|
|
216
|
-
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
217
|
-
"Network error occurred",
|
|
218
|
-
error
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
const response = error.response;
|
|
222
|
-
const data = response.data;
|
|
223
|
-
if (response.status === 401) {
|
|
224
|
-
return createAbcError(
|
|
225
|
-
"TOKEN_EXPIRED" /* TOKEN_EXPIRED */,
|
|
226
|
-
"Authentication token expired",
|
|
227
|
-
data
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
if (typeof data === "object" && "iserr" in data) {
|
|
231
|
-
const bitcoinData = data;
|
|
232
|
-
if (bitcoinData.iserr === true) {
|
|
233
|
-
return createAbcError(
|
|
234
|
-
"SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
|
|
235
|
-
bitcoinData.errmsg || "Bitcoin signature failed",
|
|
236
|
-
data
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
if (!bitcoinData.signstr) {
|
|
240
|
-
return createAbcError(
|
|
241
|
-
"SIGNATURE_FAILED" /* SIGNATURE_FAILED */,
|
|
242
|
-
"Bitcoin signature missing in response",
|
|
243
|
-
data
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
return createAbcError(
|
|
247
|
-
"UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
248
|
-
"Unexpected success response in error parser",
|
|
249
|
-
data
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
if (data?.error) {
|
|
253
|
-
return createAbcError(
|
|
254
|
-
"UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
255
|
-
data.error.message || "API error occurred",
|
|
256
|
-
data
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
if (data?.message) {
|
|
260
|
-
return createAbcError(
|
|
261
|
-
"UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
262
|
-
data.message.text || "API error occurred",
|
|
263
|
-
data
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
return createAbcError(
|
|
267
|
-
"UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
268
|
-
"An unknown error occurred",
|
|
269
|
-
error
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
function isBrowser() {
|
|
273
|
-
return typeof window !== "undefined";
|
|
274
|
-
}
|
|
275
|
-
function isWeb3Available() {
|
|
276
|
-
return isBrowser() && typeof window.ethereum !== "undefined";
|
|
277
|
-
}
|
|
278
|
-
function generateId() {
|
|
279
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
280
|
-
}
|
|
281
|
-
function deepClone(obj) {
|
|
282
|
-
return JSON.parse(JSON.stringify(obj));
|
|
283
|
-
}
|
|
284
|
-
function isEmpty(obj) {
|
|
285
|
-
if (obj == null)
|
|
286
|
-
return true;
|
|
287
|
-
if (Array.isArray(obj))
|
|
288
|
-
return obj.length === 0;
|
|
289
|
-
if (typeof obj === "object")
|
|
290
|
-
return Object.keys(obj).length === 0;
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
function debounce(func, wait) {
|
|
294
|
-
let timeout = null;
|
|
295
|
-
return function(...args) {
|
|
296
|
-
if (timeout) {
|
|
297
|
-
clearTimeout(timeout);
|
|
298
|
-
}
|
|
299
|
-
timeout = setTimeout(() => {
|
|
300
|
-
func.apply(this, args);
|
|
301
|
-
}, wait);
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function throttle(func, limit) {
|
|
305
|
-
let inThrottle = false;
|
|
306
|
-
return function(...args) {
|
|
307
|
-
if (!inThrottle) {
|
|
308
|
-
func.apply(this, args);
|
|
309
|
-
inThrottle = true;
|
|
310
|
-
setTimeout(() => {
|
|
311
|
-
inThrottle = false;
|
|
312
|
-
}, limit);
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function hexToNumber(hex) {
|
|
317
|
-
return Number.parseInt(hex, 16);
|
|
318
|
-
}
|
|
319
|
-
function numberToHex(num) {
|
|
320
|
-
return `0x${num.toString(16)}`;
|
|
321
|
-
}
|
|
322
|
-
function isValidEthereumAddress(address) {
|
|
323
|
-
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
324
|
-
}
|
|
325
|
-
function isValidSolanaAddress(address) {
|
|
326
|
-
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
|
|
327
|
-
}
|
|
328
|
-
function getExplorerUrl(chainId, txHash) {
|
|
329
|
-
const explorers = {
|
|
330
|
-
1: "https://etherscan.io/tx/",
|
|
331
|
-
5: "https://goerli.etherscan.io/tx/",
|
|
332
|
-
137: "https://polygonscan.com/tx/",
|
|
333
|
-
56: "https://bscscan.com/tx/",
|
|
334
|
-
900: "https://explorer.solana.com/tx/"
|
|
335
|
-
// Solana
|
|
336
|
-
};
|
|
337
|
-
const baseUrl = explorers[chainId];
|
|
338
|
-
return baseUrl ? `${baseUrl}${txHash}` : null;
|
|
339
|
-
}
|
|
340
|
-
function generateSalt() {
|
|
341
|
-
const array = new Uint8Array(16);
|
|
342
|
-
crypto.getRandomValues(array);
|
|
343
|
-
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
344
|
-
""
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
function deriveKeyFromPin(pin, salt) {
|
|
348
|
-
return CryptoJS.PBKDF2(pin, salt, {
|
|
349
|
-
keySize: 256 / 32,
|
|
350
|
-
iterations: 1e5
|
|
351
|
-
}).toString();
|
|
352
|
-
}
|
|
353
|
-
function encryptWithPin(data, pin, salt) {
|
|
354
|
-
const key = deriveKeyFromPin(pin, salt);
|
|
355
|
-
const encrypted = CryptoJS.AES.encrypt(data, key).toString();
|
|
356
|
-
return encrypted;
|
|
357
|
-
}
|
|
358
|
-
function decryptWithPin(encrypted, pin, salt) {
|
|
359
|
-
try {
|
|
360
|
-
const key = deriveKeyFromPin(pin, salt);
|
|
361
|
-
const decrypted = CryptoJS.AES.decrypt(encrypted, key);
|
|
362
|
-
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
|
|
363
|
-
if (!decryptedText) {
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
return decryptedText;
|
|
367
|
-
} catch (error) {
|
|
368
|
-
console.error("Decryption failed:", error);
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
function hasEncryptedTokens() {
|
|
373
|
-
if (typeof window === "undefined")
|
|
374
|
-
return false;
|
|
375
|
-
const encrypted = loadFromStorage("encrypted_tokens" /* ENCRYPTED_TOKENS */);
|
|
376
|
-
const salt = loadFromStorage("token_salt" /* TOKEN_SALT */);
|
|
377
|
-
return !!encrypted && !!salt;
|
|
378
|
-
}
|
|
379
|
-
function saveEncryptedTokens(accessToken, refreshToken, expiresIn, hashedPin) {
|
|
380
|
-
if (typeof window === "undefined")
|
|
381
|
-
return;
|
|
382
|
-
try {
|
|
383
|
-
let salt = loadFromStorage("token_salt" /* TOKEN_SALT */);
|
|
384
|
-
if (!salt) {
|
|
385
|
-
salt = generateSalt();
|
|
386
|
-
saveToStorage("token_salt" /* TOKEN_SALT */, salt);
|
|
387
|
-
}
|
|
388
|
-
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
389
|
-
const tokenData = {
|
|
390
|
-
accessToken,
|
|
391
|
-
refreshToken,
|
|
392
|
-
expiresAt
|
|
393
|
-
};
|
|
394
|
-
const encrypted = encryptWithPin(
|
|
395
|
-
JSON.stringify(tokenData),
|
|
396
|
-
hashedPin,
|
|
397
|
-
salt
|
|
398
|
-
);
|
|
399
|
-
saveToStorage("encrypted_tokens" /* ENCRYPTED_TOKENS */, encrypted);
|
|
400
|
-
removeFromStorage("access_token" /* ACCESS_TOKEN */);
|
|
401
|
-
removeFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
402
|
-
removeFromStorage("expires_at" /* EXPIRES_AT */);
|
|
403
|
-
} catch (error) {
|
|
404
|
-
console.error("Failed to save encrypted tokens:", error);
|
|
405
|
-
throw new AbcError(
|
|
406
|
-
"ENCRYPTION_FAILED" /* ENCRYPTION_FAILED */,
|
|
407
|
-
"Failed to encrypt tokens"
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
function loadEncryptedTokens(hashedPin) {
|
|
412
|
-
if (typeof window === "undefined")
|
|
413
|
-
return null;
|
|
414
|
-
try {
|
|
415
|
-
const encrypted = loadFromStorage("encrypted_tokens" /* ENCRYPTED_TOKENS */);
|
|
416
|
-
const salt = loadFromStorage("token_salt" /* TOKEN_SALT */);
|
|
417
|
-
if (!encrypted || !salt) {
|
|
418
|
-
return null;
|
|
419
|
-
}
|
|
420
|
-
const decrypted = decryptWithPin(encrypted, hashedPin, salt);
|
|
421
|
-
if (!decrypted) {
|
|
422
|
-
throw new AbcError("INVALID_PIN" /* INVALID_PIN */, "Incorrect PIN");
|
|
423
|
-
}
|
|
424
|
-
const tokenData = JSON.parse(decrypted);
|
|
425
|
-
return tokenData;
|
|
426
|
-
} catch (error) {
|
|
427
|
-
console.error("Failed to load encrypted tokens:", error);
|
|
428
|
-
if (error instanceof AbcError) {
|
|
429
|
-
throw error;
|
|
430
|
-
}
|
|
431
|
-
throw new AbcError(
|
|
432
|
-
"DECRYPTION_FAILED" /* DECRYPTION_FAILED */,
|
|
433
|
-
"Failed to decrypt tokens"
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
function clearEncryptedTokens() {
|
|
438
|
-
removeFromStorage("encrypted_tokens" /* ENCRYPTED_TOKENS */);
|
|
439
|
-
removeFromStorage("token_salt" /* TOKEN_SALT */);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
export {
|
|
443
|
-
hashPin,
|
|
444
|
-
validatePin,
|
|
445
|
-
validateEmail,
|
|
446
|
-
getStorageKey,
|
|
447
|
-
saveToStorage,
|
|
448
|
-
loadFromStorage,
|
|
449
|
-
removeFromStorage,
|
|
450
|
-
clearStorage,
|
|
451
|
-
isTokenExpired,
|
|
452
|
-
calculateExpiryTimestamp,
|
|
453
|
-
saveAuthState,
|
|
454
|
-
loadAuthState,
|
|
455
|
-
clearAuthState,
|
|
456
|
-
getChainType,
|
|
457
|
-
formatAddress,
|
|
458
|
-
createAbcError,
|
|
459
|
-
sleep,
|
|
460
|
-
retry,
|
|
461
|
-
parseApiError,
|
|
462
|
-
isBrowser,
|
|
463
|
-
isWeb3Available,
|
|
464
|
-
generateId,
|
|
465
|
-
deepClone,
|
|
466
|
-
isEmpty,
|
|
467
|
-
debounce,
|
|
468
|
-
throttle,
|
|
469
|
-
hexToNumber,
|
|
470
|
-
numberToHex,
|
|
471
|
-
isValidEthereumAddress,
|
|
472
|
-
isValidSolanaAddress,
|
|
473
|
-
getExplorerUrl,
|
|
474
|
-
hasEncryptedTokens,
|
|
475
|
-
saveEncryptedTokens,
|
|
476
|
-
loadEncryptedTokens,
|
|
477
|
-
clearEncryptedTokens
|
|
478
|
-
};
|