diff --git a/index.html b/index.html index 7f4529e..b5152c3 100644 --- a/index.html +++ b/index.html @@ -2345,11 +2345,18 @@ } // Check for TON/FLO/BTC private key format (WIF - Wallet Import Format) - const base58Regex = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/; - if (base58Regex.test(input) && input.length >= 51 && input.length <= 56) { + const base58Regex = + /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/; + if ( + base58Regex.test(input) && + input.length >= 51 && + input.length <= 56 + ) { // Only accept private keys with specific prefixes that can be converted to TON - const validPrivateKeyPrefixes = ['R',, 'K', 'L', 'T']; - if (validPrivateKeyPrefixes.some(prefix => input.startsWith(prefix))) { + const validPrivateKeyPrefixes = ["R", "K", "L", "T"]; + if ( + validPrivateKeyPrefixes.some((prefix) => input.startsWith(prefix)) + ) { return true; } return false; // Reject other Base58 strings (like BTC addresses) @@ -2898,6 +2905,34 @@ } } + // Validation function for recover wallet (only private keys,) + function isValidRecoverPrivateKey(input) { + // Check if it's a hex private key (64 or 128 characters) - TON format + const hexOnly = /^[0-9a-fA-F]+$/.test(input); + if (hexOnly && (input.length === 64 || input.length === 128)) { + return true; + } + + // Check for TON/FLO/BTC private key format (WIF - Wallet Import Format) + const base58Regex = + /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/; + if ( + base58Regex.test(input) && + input.length >= 51 && + input.length <= 56 + ) { + // Only accept private keys with specific prefixes for TON/FLO/BTC + const validPrivateKeyPrefixes = ["R", "K", "L", "T"]; + if ( + validPrivateKeyPrefixes.some((prefix) => input.startsWith(prefix)) + ) { + return true; + } + } + + return false; + } + // Recover wallet functionality async function recoverWallet() { const privateKeyInput = document @@ -2913,6 +2948,27 @@ return; } + // Validate private key format + if (!isValidRecoverPrivateKey(privateKeyInput)) { + output.innerHTML = ` +
+
+ +
+
+

Invalid Private Key Format

+

Please enter a valid private key (TON/FLO/BTC format).

+

Addresses and other formats are not supported.

+
+
+ `; + showNotification( + "Invalid private key format - only TON/FLO/BTC private keys supported", + "error" + ); + return; + } + // Show loading state const originalHTML = button.innerHTML; button.disabled = true; @@ -2921,7 +2977,7 @@ try { let wallet; - if (typeof tonCrypto !== "undefined" ) { + if (typeof tonCrypto !== "undefined") { wallet = await tonCrypto.recoverFromInput(privateKeyInput); } const tonData = wallet.TON || wallet; @@ -3045,11 +3101,15 @@

Recovery Failed

-

Please check that you've entered a valid private key in the correct format.

+

Unable to recover address from the provided private key. Please ensure you've entered a valid TON/FLO/BTC private key.

+
`; - showNotification("Failed to recover ", "error"); + showNotification( + "Failed to recover address from private key", + "error" + ); } finally { button.disabled = false; button.innerHTML = originalHTML;