This commit is contained in:
dela
2026-02-20 13:16:51 +08:00
commit 0ac4b23f07
36 changed files with 5042 additions and 0 deletions

81
src/generator/payload.js Normal file
View File

@@ -0,0 +1,81 @@
/**
* Payload Builder - Assembling the Final Form
*
* Takes all our crafted components and stitches them into
* the exact JSON structure hCaptcha expects.
*/
export class PayloadBuilder {
/**
* Build the getcaptcha request payload
*/
static build({ siteKey, host, n, c, motionData }) {
const now = Date.now();
return {
v: '1', // Protocol version
sitekey: siteKey,
host,
hl: 'en', // Language
// Challenge response
n, // Proof of work from hsw.js
c: JSON.stringify(c), // Config from checksiteconfig
// Motion telemetry
motionData: JSON.stringify(motionData),
// Timestamps
prev: {
escaped: false,
passed: false,
expiredChallenge: false,
expiredResponse: false,
},
// Widget metadata
d: PayloadBuilder._generateWidgetData(host, now),
// Response type
pst: false, // Previous success token
};
}
/**
* Generate widget embedding data
*/
static _generateWidgetData(host, timestamp) {
return {
gt: 0, // Widget type
ct: timestamp - 1000, // Creation time
fc: 1, // Frame count
ff: false, // First frame
// Fake performance metrics
pd: {
si: timestamp - 5000, // Script init
ce: timestamp - 4500, // Challenge end
cs: timestamp - 4000, // Challenge start
re: timestamp - 500, // Response end
rs: timestamp - 1000, // Response start
},
};
}
/**
* Build form-encoded payload (alternative format)
*/
static buildFormData(data) {
const params = new URLSearchParams();
for (const [key, value] of Object.entries(data)) {
if (typeof value === 'object') {
params.append(key, JSON.stringify(value));
} else {
params.append(key, String(value));
}
}
return params.toString();
}
}