UNPKG

hive-keychain-commons

Version:

Platform-agnostic functions used in Hive Keychain mobile and extensions

73 lines (72 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransferUtils = exports.TransferWarning = void 0; const crypto_utils_1 = require("./crypto.utils"); const exchanges_utils_1 = require("./exchanges.utils"); const keys_utils_1 = require("./keys.utils"); var TransferWarning; (function (TransferWarning) { TransferWarning["PRIVATE_KEY_IN_MEMO"] = "private_key_in_memo"; TransferWarning["PHISHING"] = "phishing"; TransferWarning["EXCHANGE_DEPOSIT"] = "exchange_deposit"; TransferWarning["EXCHANGE_MEMO"] = "exchange_memo"; TransferWarning["EXCHANGE_RECURRENT"] = "exchange_recurrent"; TransferWarning["EXCHANGE_VSC"] = "EXCHANGE_VSC"; })(TransferWarning = exports.TransferWarning || (exports.TransferWarning = {})); const getPrivateKeysMemoValidationWarning = (memo) => { const memoTemp = memo.startsWith('#') ? memo.substring(1, memo.length) : memo; let found; found = memoTemp.match(/[\w\d]{51,52}/g); if (found) { for (const word of found) { if ((0, crypto_utils_1.isWif)(word) && word.length === 51) { if ((0, keys_utils_1.getPublicKeyFromPrivateKeyString)(word)) return true; } else if (word.startsWith('P') && word.length === 52) { return true; } } } return false; }; const getTransferWarning = (account, currency, memo, phisingAccounts, isRecurrent, isOnVsc) => { const exchangeWarning = getExchangeValidationWarning(account, currency, memo.length > 0, isRecurrent, isOnVsc); if (exchangeWarning) return exchangeWarning; const privateKeyInMemoWarning = getPrivateKeysMemoValidationWarning(memo); if (privateKeyInMemoWarning) return TransferWarning.PRIVATE_KEY_IN_MEMO; // return chrome.i18n.getMessage('popup_warning_private_key_in_memo'); if (phisingAccounts.includes(account)) { return TransferWarning.PHISHING; // return chrome.i18n.getMessage('popup_warning_phishing', [account]); } return; }; const getExchangeValidationWarning = (account, currency, hasMemo, isRecurrent, isOnVsc) => { const exchange = exchanges_utils_1.ExchangesUtils.getExchanges().find((exch) => exch.username === account); if (!exchange) return; if (exchange && isOnVsc) return TransferWarning.EXCHANGE_VSC; if (!exchange.acceptedCoins.includes(currency)) { // return chrome.i18n.getMessage('popup_warning_exchange_deposit', [currency]); return TransferWarning.EXCHANGE_DEPOSIT; } if (!hasMemo) { // return chrome.i18n.getMessage('popup_warning_exchange_memo'); return TransferWarning.EXCHANGE_MEMO; } if (isRecurrent) return TransferWarning.EXCHANGE_RECURRENT; // return chrome.i18n.getMessage( // 'popup_html_transfer_recurrent_exchange_warning', // ); return; }; exports.TransferUtils = { getTransferWarning, };