UNPKG

vk-captcha-bypass

Version:

Обход VK Captcha

74 lines 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generatePoW = exports.computeHashWithNonce = exports.removeFirstElementFromAllArrays = exports.getSerializedObjectSizeInKB = exports.generateMouseTrace = exports.getRandomNumber = void 0; const crypto_1 = require("crypto"); const getRandomNumber = (min, max) => { return Math.floor(Math.random() * (max - min + 1)) + min; }; exports.getRandomNumber = getRandomNumber; const generateMouseTrace = (params = {}) => { const points = []; let { from, to, intervalMs = 500, durationMs = (0, exports.getRandomNumber)(2000, 15_000) } = params; from ??= { x: (0, exports.getRandomNumber)(1080 / 2, 1080), y: (0, exports.getRandomNumber)(720 / 2, 720), }; to ??= { x: (0, exports.getRandomNumber)(from.x - 300, from.x + 300), y: (0, exports.getRandomNumber)(from.y - 300, from.y + 300), }; const totalSteps = Math.floor(durationMs / intervalMs); const dx = to.x - from.x; const dy = to.y - from.y; for (let step = 0; step < totalSteps; step++) { const t = Math.min(1, step / totalSteps); const easedT = t * (2 - t); const noiseX = (Math.random() - 0.5) * 6; const noiseY = (Math.random() - 0.5) * 6; const x = Math.round(from.x + dx * easedT + noiseX); const y = Math.round(from.y + dy * easedT + noiseY); points.push({ x, y }); } return points; }; exports.generateMouseTrace = generateMouseTrace; const getSerializedObjectSizeInKB = (object) => { let totalKB = 0; Object.keys(object).forEach(key => { const value = object[key]; if (value) { const bytes = JSON.stringify(value).length; totalKB += bytes; } }); return totalKB / 1024; }; exports.getSerializedObjectSizeInKB = getSerializedObjectSizeInKB; const removeFirstElementFromAllArrays = (object) => { Object.keys(object).forEach(t => { const array = object[t]; if (array) array.shift(); }); }; exports.removeFirstElementFromAllArrays = removeFirstElementFromAllArrays; const computeHashWithNonce = async (input, nonce) => { const encoder = new TextEncoder(); const data = encoder.encode(input + nonce); const hashBuffer = await crypto_1.subtle.digest('SHA-256', data); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); return hashHex; }; exports.computeHashWithNonce = computeHashWithNonce; const generatePoW = async (input, difficulty) => { let nonce = 0; let hash = ''; while (!hash.startsWith('0'.repeat(difficulty))) { nonce++; hash = await (0, exports.computeHashWithNonce)(input, nonce); } return hash; }; exports.generatePoW = generatePoW; //# sourceMappingURL=utils.js.map