const crypto = require("crypto")
function generateSign(fullUrl, userId, dynamicRules) {
const time = 1695067389557;
const url = new URL(fullUrl);
const msg = [
dynamicRules.static_param,
time,
url.pathname + url.search,
userId || 0,
].join("\n");
console.log(msg)
const shaHash = crypto.createHash('sha1').update(msg).digest('hex');
const hashAscii = Buffer.from(shaHash, 'ascii');
const checksum = dynamicRules.checksum_indexes.reduce((result, value) => result + hashAscii[value], 0) + dynamicRules.checksum_constant;
const sign = [dynamicRules.start, shaHash, Math.abs(checksum).toString(16), dynamicRules.end].join(":");
return { sign, time };
}
const dynamicRules = {
"end": 65087768,
"start": 11599,
"format": "11599:{}:{:x}:65087768",
"prefix": 11599,
"suffix": 65087768,
"revision": "202309181613-dd542e89cd",
"app_token": "33d57ade8c02dbc5a333db99ff9ae26a",
"static_param": "8XVYZGDF5k51qm2FX6uFsPGpzIeQGIhM",
"checksum_indexes": [
0,
0,
2,
4,
4,
4,
5,
6,
8,
8,
12,
12,
13,
13,
14,
19,
20,
21,
21,
26,
26,
29,
30,
30,
30,
31,
36,
37,
38,
39,
39,
39
],
"checksum_constant": -195
}
const result = generateSign('https://onlyfans.com/api2/v2/posts/login?limit=10&offset=0&skip_users=all', 0, dynamicRules);
console.log("Res: " + result.sign);
console.log("Exp: 11599:60fa9d23d4da90072e6d9fafda2431f95aba171e:84b:65087768");