diff --git a/tonBlockchainAPI.js b/tonBlockchainAPI.js index 122bc86..ee93e67 100644 --- a/tonBlockchainAPI.js +++ b/tonBlockchainAPI.js @@ -16,8 +16,7 @@ new TonWeb.HttpProvider("https://toncenter.com/api/v2/jsonRPC"), { headers: { - "X-API-Key": - API_KEY, + "X-API-Key": API_KEY, }, } ); @@ -151,7 +150,7 @@ .then((data) => { if (data) { const friendly = - data?.result?.non_bounceable?.b64url || + data?.result?.bounceable?.b64url || rawAddr.replace(":retry:", ""); const cleanAddr = rawAddr.replace(":retry:", ""); addrCache.set(cleanAddr, friendly); @@ -172,13 +171,13 @@ } /** - * Convert raw address to b64 format with rate limiting - * @param {string} rawAddr - The raw address to convert + * Convert address to b64 format with rate limiting + * @param {string} rawAddr - The address to convert (raw, EQ, UQ formats) * @returns {Promise} Promise object that resolves with user-friendly address */ tonBlockchainAPI.convertTob64 = function (rawAddr) { return new Promise((resolve) => { - // if it doesn't look like a raw address, return as-is + // if it doesn't look like an address, return as-is if (!rawAddr || typeof rawAddr !== "string" || rawAddr === "Unknown") { resolve(rawAddr); return; @@ -193,8 +192,9 @@ const isRawAddress = rawAddr.includes(":") && rawAddr.match(/^-?\d+:[a-fA-F0-9]{64}$/); - if (!isRawAddress) { - // Already user-friendly or not a TON address + const isFriendlyAddress = rawAddr.match(/^[EUk]Q[A-Za-z0-9_-]{46}$/); + + if (!isRawAddress && !isFriendlyAddress) { resolve(rawAddr); return; } @@ -205,7 +205,7 @@ return; } - // Add to queue for conversion + // Add to queue for conversion (works for both raw and friendly addresses) requestQueue.push({ rawAddr, resolve }); processRequestQueue(); }); @@ -263,7 +263,7 @@ /** * Get balance for an address - * @param {string} address - The TON address to check + * @param {string} address - The TON address to check * @returns {Promise} Promise object that resolves with balance in TON */ tonBlockchainAPI.getMainnetBalance = function (address) { @@ -325,7 +325,7 @@ }; /** - * Send TON transaction + * Send TON transaction * @param {string} privHex - Private key in hexadecimal format * @param {string} toAddress - Recipient's TON address * @param {string|number} amount - Amount to send in TON