frist
This commit is contained in:
81
src/generator/payload.js
Normal file
81
src/generator/payload.js
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user