feat(pdd): add realistic Bézier mouse trajectory simulation to generate 700+ char anti-content tokens

This commit is contained in:
yml2213
2026-09-14 14:03:07 +08:00
parent f35e47e419
commit 0cbcb89dd8
2 changed files with 66 additions and 3 deletions
@@ -51,12 +51,15 @@ test('PurePddAntiContent executes with ultra-low latency (< 1ms per token)', ()
assert.ok(avg < 2, `Average generation time should be < 2ms (actual: ${avg.toFixed(3)}ms)`)
})
test('PurePddAntiContent.getTokenAsync generates valid tokens via official JS engine', async () => {
test('PurePddAntiContent.getTokenAsync generates valid high-credibility tokens with simulated trajectory', async () => {
const token = await pddAntiContentEngine.getTokenAsync({
cookies: '_nano_fp=42e47e06a644482087; api_uid=rBQ51234',
serverTimeMs: 1726119845000,
})
assert.ok(token.startsWith('0as'), 'Async token must start with 0as prefix')
assert.ok(token.length > 200, `Async token length should be > 200 (actual: ${token.length})`)
assert.ok(
token.length > 600,
`High-credibility token length should be > 600 chars (actual: ${token.length})`,
)
})
@@ -44,10 +44,67 @@ function createSandbox(cookies, options = {}) {
documentElement: { clientWidth: 1920, clientHeight: 950, scrollTop: 0 },
body: { clientWidth: 1920, clientHeight: 950, scrollTop: 0 },
cookie: cookies || "",
addEventListener: ()=>{},
addEventListener: (name, handler) => {
if (!sandbox._handlers) sandbox._handlers = {};
sandbox._handlers[name] = handler;
},
removeEventListener: ()=>{},
createElement: (tag) => ({ getContext: () => null })
};
sandbox.addEventListener = sandbox.document.addEventListener;
sandbox._simulateTrajectory = () => {
const handlers = sandbox._handlers || {};
const count = 22 + Math.floor(Math.random() * 8);
const p0 = { x: 300 + Math.random() * 200, y: 200 + Math.random() * 150 };
const p1 = { x: p0.x + (Math.random() - 0.5) * 300, y: p0.y + (Math.random() - 0.5) * 200 };
const p2 = { x: p1.x + (Math.random() - 0.5) * 300, y: p1.y + (Math.random() - 0.5) * 200 };
const p3 = { x: 600 + Math.random() * 250, y: 350 + Math.random() * 200 };
const targets = ["order-list-table", "order-row-item", "order-search-filter", "btn-query", "app"];
let tStamp = 50 + Math.floor(Math.random() * 50);
const mm = handlers["mousemove"];
const md = handlers["mousedown"];
const clk = handlers["click"];
if (mm && typeof mm.handleEvent === "function") {
for (let i = 0; i <= count; i++) {
const t = i / count;
const cx = Math.pow(1 - t, 3) * p0.x + 3 * Math.pow(1 - t, 2) * t * p1.x + 3 * (1 - t) * Math.pow(t, 2) * p2.x + Math.pow(t, 3) * p3.x;
const cy = Math.pow(1 - t, 3) * p0.y + 3 * Math.pow(1 - t, 2) * t * p1.y + 3 * (1 - t) * Math.pow(t, 2) * p2.y + Math.pow(t, 3) * p3.y;
tStamp += Math.floor(25 + Math.random() * 45);
mm.handleEvent({
isTrusted: true,
clientX: Math.round(cx + (Math.random() - 0.5) * 2),
clientY: Math.round(cy + (Math.random() - 0.5) * 2),
timeStamp: tStamp,
target: { id: targets[Math.floor(Math.random() * targets.length)] }
});
}
}
if (md && typeof md.handleEvent === "function") {
tStamp += Math.floor(50 + Math.random() * 100);
md.handleEvent({
isTrusted: true,
clientX: Math.round(p3.x),
clientY: Math.round(p3.y),
timeStamp: tStamp,
target: { id: "btn-query" }
});
}
if (clk && typeof clk.handleEvent === "function") {
tStamp += Math.floor(30 + Math.random() * 50);
clk.handleEvent({
isTrusted: true,
clientX: Math.round(p3.x),
clientY: Math.round(p3.y),
timeStamp: tStamp,
target: { id: "btn-query" }
});
}
};
return sandbox;
}
@@ -75,6 +132,9 @@ async function generateAntiContent(cookies, serverTime, options = {}) {
const sandbox = createSandbox(cookies, options);
const ctx = vm.createContext(sandbox);
const genToken = vm.runInContext(AntiCode, ctx);
if (options.simulateInteraction !== false && typeof sandbox._simulateTrajectory === "function") {
sandbox._simulateTrajectory();
}
return await genToken(serverTime);
}