@unorouter/verify-core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/detectors/thinking-signature.d.ts +70 -0
- package/dist/detectors/thinking-signature.d.ts.map +1 -0
- package/dist/detectors/thinking-signature.js +177 -0
- package/dist/detectors/thinking-signature.js.map +1 -0
- package/dist/detectors/token-truth.d.ts +40 -0
- package/dist/detectors/token-truth.d.ts.map +1 -0
- package/dist/detectors/token-truth.js +145 -0
- package/dist/detectors/token-truth.js.map +1 -0
- package/dist/runner.d.ts +10 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +25 -1
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic thinking-signature check.
|
|
3
|
+
*
|
|
4
|
+
* Claude attaches a server-generated `signature` to every thinking block. A
|
|
5
|
+
* relay serving some other model cannot produce one, so this is the only
|
|
6
|
+
* evidence here that does not rest on asking the model who it is: identity and
|
|
7
|
+
* behaviour probes can be coached with a system prompt, a signature cannot.
|
|
8
|
+
*
|
|
9
|
+
* What it does NOT prove: which tier answered. Sonnet returns a perfectly valid
|
|
10
|
+
* signature when sold as Opus, so a pass here still needs the tier checks.
|
|
11
|
+
*
|
|
12
|
+
* Ported from veridrop (AGPL-3.0), whose detector stops at "a signature-shaped
|
|
13
|
+
* string is present".
|
|
14
|
+
*
|
|
15
|
+
* Their DESIGN.md also specifies a replay step (hand the thinking block back so
|
|
16
|
+
* Anthropic re-validates the signature, rejecting a forgery with 400/422) which
|
|
17
|
+
* they never implemented. We built and measured it: **it does not work through a
|
|
18
|
+
* relay**. Tested against two live upstreams (a6 merchant 3542 and pol) by
|
|
19
|
+
* replaying a genuine block and then the same block with 308 bytes of random
|
|
20
|
+
* base64 in place of the signature. Both upstreams returned 200 for both. A
|
|
21
|
+
* relay re-issues the turn to its own backend rather than passing our thinking
|
|
22
|
+
* block through, so nothing ever validates it.
|
|
23
|
+
*
|
|
24
|
+
* `strict` therefore stays off by default and is documented as proving only
|
|
25
|
+
* that the endpoint accepts the block, not that the signature is real. Do not
|
|
26
|
+
* present it as cryptographic proof.
|
|
27
|
+
*/
|
|
28
|
+
import type { TransportFn } from "../transport";
|
|
29
|
+
export type SignatureState =
|
|
30
|
+
/** Signed thinking block: a genuine Anthropic path answered. */
|
|
31
|
+
"signed"
|
|
32
|
+
/**
|
|
33
|
+
* Thought, but no signature. Expected when the lane crosses an
|
|
34
|
+
* OpenAI-shaped hop, which has no field to carry one, so this is
|
|
35
|
+
* unprovable rather than fake. Never a hard fail on its own.
|
|
36
|
+
*/
|
|
37
|
+
| "unsigned"
|
|
38
|
+
/** Thinking was requested and no block came back at all. */
|
|
39
|
+
| "no-thinking"
|
|
40
|
+
/** Model or endpoint cannot be asked; carries no evidence either way. */
|
|
41
|
+
| "skipped";
|
|
42
|
+
export type SignatureResult = {
|
|
43
|
+
state: SignatureState;
|
|
44
|
+
signatureLength: number;
|
|
45
|
+
/** First 32 chars, for the report; never the whole signature. */
|
|
46
|
+
signaturePrefix: string | null;
|
|
47
|
+
thinkingChars: number;
|
|
48
|
+
/** Only set when the replay check actually ran. */
|
|
49
|
+
replayVerified?: boolean;
|
|
50
|
+
reason?: string;
|
|
51
|
+
};
|
|
52
|
+
export declare function thinkingModeFor(model: string): {
|
|
53
|
+
kind: "adaptive" | "extended";
|
|
54
|
+
} | null;
|
|
55
|
+
export declare function checkThinkingSignature(opts: {
|
|
56
|
+
transport: TransportFn;
|
|
57
|
+
baseUrl: string;
|
|
58
|
+
apiKey: string;
|
|
59
|
+
model: string;
|
|
60
|
+
timeoutMs: number;
|
|
61
|
+
/**
|
|
62
|
+
* Replay the thinking block to the same endpoint. Measured as NOT proving
|
|
63
|
+
* authenticity through a relay (see the module docstring): both a genuine and
|
|
64
|
+
* a forged signature come back 200, because the relay re-issues the turn
|
|
65
|
+
* upstream instead of forwarding our block. Off by default; it only tells you
|
|
66
|
+
* the endpoint accepts a thinking block in the request.
|
|
67
|
+
*/
|
|
68
|
+
strict?: boolean;
|
|
69
|
+
}): Promise<SignatureResult>;
|
|
70
|
+
//# sourceMappingURL=thinking-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-signature.d.ts","sourceRoot":"","sources":["../../src/detectors/thinking-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqBhD,MAAM,MAAM,cAAc;AACxB,gEAAgE;AAC9D,QAAQ;AACV;;;;GAIG;GACD,UAAU;AACZ,4DAA4D;GAC1D,aAAa;AACf,yEAAyE;GACvE,SAAS,CAAC;AAEd,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAkBF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GACZ;IAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAAA;CAAE,GAAG,IAAI,CAK1C;AA4BD,wBAAsB,sBAAsB,CAAC,IAAI,EAAE;IACjD,SAAS,EAAE,WAAW,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,eAAe,CAAC,CA0E3B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic thinking-signature check.
|
|
3
|
+
*
|
|
4
|
+
* Claude attaches a server-generated `signature` to every thinking block. A
|
|
5
|
+
* relay serving some other model cannot produce one, so this is the only
|
|
6
|
+
* evidence here that does not rest on asking the model who it is: identity and
|
|
7
|
+
* behaviour probes can be coached with a system prompt, a signature cannot.
|
|
8
|
+
*
|
|
9
|
+
* What it does NOT prove: which tier answered. Sonnet returns a perfectly valid
|
|
10
|
+
* signature when sold as Opus, so a pass here still needs the tier checks.
|
|
11
|
+
*
|
|
12
|
+
* Ported from veridrop (AGPL-3.0), whose detector stops at "a signature-shaped
|
|
13
|
+
* string is present".
|
|
14
|
+
*
|
|
15
|
+
* Their DESIGN.md also specifies a replay step (hand the thinking block back so
|
|
16
|
+
* Anthropic re-validates the signature, rejecting a forgery with 400/422) which
|
|
17
|
+
* they never implemented. We built and measured it: **it does not work through a
|
|
18
|
+
* relay**. Tested against two live upstreams (a6 merchant 3542 and pol) by
|
|
19
|
+
* replaying a genuine block and then the same block with 308 bytes of random
|
|
20
|
+
* base64 in place of the signature. Both upstreams returned 200 for both. A
|
|
21
|
+
* relay re-issues the turn to its own backend rather than passing our thinking
|
|
22
|
+
* block through, so nothing ever validates it.
|
|
23
|
+
*
|
|
24
|
+
* `strict` therefore stays off by default and is documented as proving only
|
|
25
|
+
* that the endpoint accepts the block, not that the signature is real. Do not
|
|
26
|
+
* present it as cryptographic proof.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Multi-step GCD: hard enough that adaptive models decide to think, and
|
|
30
|
+
* deliberately not the 1071/462 pair from Anthropic's own docs, which a relay
|
|
31
|
+
* could special-case.
|
|
32
|
+
*/
|
|
33
|
+
const PROBE_PROMPT = "Find the greatest common divisor of 2378 and 1547 using the Euclidean algorithm.";
|
|
34
|
+
const THINKING_BUDGET_TOKENS = 2000;
|
|
35
|
+
/**
|
|
36
|
+
* Covers thinking + answer together. Too small and an adaptive model skips
|
|
37
|
+
* thinking entirely to fit, which reads as a fake when it is our own fault.
|
|
38
|
+
*/
|
|
39
|
+
const MAX_TOKENS = 16000;
|
|
40
|
+
/** Real signatures run to hundreds of chars; this only rejects a stub. */
|
|
41
|
+
const SIGNATURE_MIN_LEN = 50;
|
|
42
|
+
/** Adaptive-thinking models take `effort` at the top level, not inside `thinking`. */
|
|
43
|
+
const ADAPTIVE_MODELS = ["claude-opus-4-7", "claude-opus-4-8"];
|
|
44
|
+
/** Extended-thinking models take a token budget instead. */
|
|
45
|
+
const EXTENDED_MODELS = [
|
|
46
|
+
"claude-opus-4-6",
|
|
47
|
+
"claude-opus-4-5",
|
|
48
|
+
"claude-opus-4-1",
|
|
49
|
+
"claude-sonnet-4-6",
|
|
50
|
+
"claude-sonnet-4-5",
|
|
51
|
+
"claude-haiku-4-5",
|
|
52
|
+
];
|
|
53
|
+
const normalize = (model) => model.toLowerCase().replace(/[._]/g, "-").split("/").pop() ?? "";
|
|
54
|
+
export function thinkingModeFor(model) {
|
|
55
|
+
const m = normalize(model);
|
|
56
|
+
if (ADAPTIVE_MODELS.some((p) => m.startsWith(p)))
|
|
57
|
+
return { kind: "adaptive" };
|
|
58
|
+
if (EXTENDED_MODELS.some((p) => m.startsWith(p)))
|
|
59
|
+
return { kind: "extended" };
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function readThinking(data) {
|
|
63
|
+
const content = data?.content;
|
|
64
|
+
if (!Array.isArray(content))
|
|
65
|
+
return { block: null, signature: "", chars: 0 };
|
|
66
|
+
for (const raw of content) {
|
|
67
|
+
if (!raw || typeof raw !== "object")
|
|
68
|
+
continue;
|
|
69
|
+
const b = raw;
|
|
70
|
+
if (b.type !== "thinking" && b.type !== "redacted_thinking")
|
|
71
|
+
continue;
|
|
72
|
+
return {
|
|
73
|
+
block: b,
|
|
74
|
+
signature: typeof b.signature === "string" ? b.signature : "",
|
|
75
|
+
chars: typeof b.thinking === "string" ? b.thinking.length : 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { block: null, signature: "", chars: 0 };
|
|
79
|
+
}
|
|
80
|
+
export async function checkThinkingSignature(opts) {
|
|
81
|
+
const mode = thinkingModeFor(opts.model);
|
|
82
|
+
const empty = { signatureLength: 0, signaturePrefix: null, thinkingChars: 0 };
|
|
83
|
+
if (!mode)
|
|
84
|
+
return { state: "skipped", ...empty, reason: "model-has-no-thinking-mode" };
|
|
85
|
+
const url = `${opts.baseUrl.replace(/\/+$/, "")}/v1/messages`;
|
|
86
|
+
const headers = {
|
|
87
|
+
"Content-Type": "application/json",
|
|
88
|
+
"x-api-key": opts.apiKey,
|
|
89
|
+
"anthropic-version": "2023-06-01",
|
|
90
|
+
};
|
|
91
|
+
const messages = [{ role: "user", content: PROBE_PROMPT }];
|
|
92
|
+
// Non-streaming on purpose: streaming an adaptive model silently drops the
|
|
93
|
+
// thinking block, so a real Claude would look unsigned.
|
|
94
|
+
const body = {
|
|
95
|
+
model: opts.model,
|
|
96
|
+
max_tokens: MAX_TOKENS,
|
|
97
|
+
messages,
|
|
98
|
+
thinking: mode.kind === "extended"
|
|
99
|
+
? { type: "enabled", budget_tokens: THINKING_BUDGET_TOKENS }
|
|
100
|
+
: { type: "adaptive", display: "summarized" },
|
|
101
|
+
};
|
|
102
|
+
// Sibling of `thinking`, never nested inside it: nesting is a 400.
|
|
103
|
+
if (mode.kind === "adaptive")
|
|
104
|
+
body["output_config"] = { effort: "xhigh" };
|
|
105
|
+
const res = await opts.transport({
|
|
106
|
+
mode: "direct",
|
|
107
|
+
url,
|
|
108
|
+
headers,
|
|
109
|
+
reqBody: body,
|
|
110
|
+
timeoutMs: opts.timeoutMs,
|
|
111
|
+
});
|
|
112
|
+
if (res.status === null || res.status >= 400)
|
|
113
|
+
return {
|
|
114
|
+
state: "skipped",
|
|
115
|
+
...empty,
|
|
116
|
+
reason: `probe-failed:${res.status ?? "network"}`,
|
|
117
|
+
};
|
|
118
|
+
const found = readThinking(res.data);
|
|
119
|
+
if (!found.block)
|
|
120
|
+
return { state: "no-thinking", ...empty, reason: "no-thinking-block" };
|
|
121
|
+
const sig = found.signature;
|
|
122
|
+
const base = {
|
|
123
|
+
signatureLength: sig.length,
|
|
124
|
+
signaturePrefix: sig ? sig.slice(0, 32) : null,
|
|
125
|
+
thinkingChars: found.chars,
|
|
126
|
+
};
|
|
127
|
+
if (!sig)
|
|
128
|
+
return { state: "unsigned", ...base, reason: "no-signature-field" };
|
|
129
|
+
if (sig.length < SIGNATURE_MIN_LEN)
|
|
130
|
+
return { state: "unsigned", ...base, reason: "signature-too-short" };
|
|
131
|
+
if (!opts.strict)
|
|
132
|
+
return { state: "signed", ...base };
|
|
133
|
+
const replayVerified = await verifySignature({
|
|
134
|
+
transport: opts.transport,
|
|
135
|
+
url,
|
|
136
|
+
headers,
|
|
137
|
+
model: opts.model,
|
|
138
|
+
block: found.block,
|
|
139
|
+
timeoutMs: opts.timeoutMs,
|
|
140
|
+
});
|
|
141
|
+
// A rejection is real evidence (the endpoint checked and refused); an
|
|
142
|
+
// acceptance is not, so it never upgrades or downgrades the state on its own.
|
|
143
|
+
return {
|
|
144
|
+
state: replayVerified ? "signed" : "unsigned",
|
|
145
|
+
...base,
|
|
146
|
+
replayVerified,
|
|
147
|
+
...(replayVerified ? {} : { reason: "signature-rejected-on-replay" }),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Hand the thinking block back to the endpoint. Against api.anthropic.com this
|
|
152
|
+
* would re-validate the signature; against a relay it does not (measured: a
|
|
153
|
+
* forged 308-byte signature returned 200 on both upstreams tested), so the
|
|
154
|
+
* result is reported as `replayVerified` evidence rather than a verdict.
|
|
155
|
+
*/
|
|
156
|
+
async function verifySignature(opts) {
|
|
157
|
+
const res = await opts.transport({
|
|
158
|
+
mode: "direct",
|
|
159
|
+
url: opts.url,
|
|
160
|
+
headers: opts.headers,
|
|
161
|
+
reqBody: {
|
|
162
|
+
model: opts.model,
|
|
163
|
+
max_tokens: 1,
|
|
164
|
+
messages: [
|
|
165
|
+
{ role: "user", content: PROBE_PROMPT },
|
|
166
|
+
{ role: "assistant", content: [opts.block] },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
timeoutMs: opts.timeoutMs,
|
|
170
|
+
});
|
|
171
|
+
// A network failure proves nothing, so treat only an explicit rejection as
|
|
172
|
+
// a forged signature.
|
|
173
|
+
if (res.status === null)
|
|
174
|
+
return true;
|
|
175
|
+
return res.status < 400;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=thinking-signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-signature.js","sourceRoot":"","sources":["../../src/detectors/thinking-signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH;;;;GAIG;AACH,MAAM,YAAY,GAChB,kFAAkF,CAAC;AAErF,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,GAAG,KAAK,CAAC;AAEzB,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AA2B7B,sFAAsF;AACtF,MAAM,eAAe,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAE/D,4DAA4D;AAC5D,MAAM,eAAe,GAAG;IACtB,iBAAiB;IACjB,iBAAiB;IACjB,iBAAiB;IACjB,mBAAmB;IACnB,mBAAmB;IACnB,kBAAkB;CACnB,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAClC,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AAEnE,MAAM,UAAU,eAAe,CAC7B,KAAa;IAEb,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAA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QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;IACH,sEAAsE;IACtE,8EAA8E;IAC9E,OAAO;QACL,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU;QAC7C,GAAG,IAAI;QACP,cAAc;QACd,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,eAAe,CAAC,IAO9B;IACC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC;QAC/B,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE;YACP,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE;gBACvC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aAC7C;SACF;QACD,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;IACH,2EAA2E;IAC3E,sBAAsB;IACtB,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrC,OAAO,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-accounting checks for Anthropic endpoints.
|
|
3
|
+
*
|
|
4
|
+
* The signature check answers "is this really Claude". These answer a different
|
|
5
|
+
* question the signature cannot: "are the numbers you are billing me true".
|
|
6
|
+
* A relay can forward genuine Claude and still inflate `input_tokens` on every
|
|
7
|
+
* call, and nothing in an identity probe would notice.
|
|
8
|
+
*
|
|
9
|
+
* Ported from veridrop (AGPL-3.0) `token_usage.py` / `integrity.py`, whose
|
|
10
|
+
* tolerances were calibrated against the official API. Do not tighten them
|
|
11
|
+
* without re-measuring: the loose-looking bounds exist because real Anthropic
|
|
12
|
+
* responses sat near them.
|
|
13
|
+
*/
|
|
14
|
+
import type { TransportFn } from "../transport";
|
|
15
|
+
export type TokenTruthCheck = {
|
|
16
|
+
id: "usage-present" | "input-delta" | "output-bounded" | "count-tokens";
|
|
17
|
+
pass: boolean;
|
|
18
|
+
detail: string;
|
|
19
|
+
};
|
|
20
|
+
export type TokenTruthResult = {
|
|
21
|
+
/** null when nothing could be measured (endpoint refused every probe). */
|
|
22
|
+
ok: boolean | null;
|
|
23
|
+
checks: TokenTruthCheck[];
|
|
24
|
+
shortInputTokens: number | null;
|
|
25
|
+
longInputTokens: number | null;
|
|
26
|
+
countTokens: number | null;
|
|
27
|
+
reason?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function expectedInputDelta(model: string): {
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function checkTokenTruth(opts: {
|
|
34
|
+
transport: TransportFn;
|
|
35
|
+
baseUrl: string;
|
|
36
|
+
apiKey: string;
|
|
37
|
+
model: string;
|
|
38
|
+
timeoutMs: number;
|
|
39
|
+
}): Promise<TokenTruthResult>;
|
|
40
|
+
//# sourceMappingURL=token-truth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-truth.d.ts","sourceRoot":"","sources":["../../src/detectors/token-truth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsBhD,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,eAAe,GAAG,aAAa,GAAG,gBAAgB,GAAG,cAAc,CAAC;IACxE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0EAA0E;IAC1E,EAAE,EAAE,OAAO,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAKF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAK9E;AAcD,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,WAAW,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2G5B"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-accounting checks for Anthropic endpoints.
|
|
3
|
+
*
|
|
4
|
+
* The signature check answers "is this really Claude". These answer a different
|
|
5
|
+
* question the signature cannot: "are the numbers you are billing me true".
|
|
6
|
+
* A relay can forward genuine Claude and still inflate `input_tokens` on every
|
|
7
|
+
* call, and nothing in an identity probe would notice.
|
|
8
|
+
*
|
|
9
|
+
* Ported from veridrop (AGPL-3.0) `token_usage.py` / `integrity.py`, whose
|
|
10
|
+
* tolerances were calibrated against the official API. Do not tighten them
|
|
11
|
+
* without re-measuring: the loose-looking bounds exist because real Anthropic
|
|
12
|
+
* responses sat near them.
|
|
13
|
+
*/
|
|
14
|
+
const SHORT_PROMPT = "Reply with exactly: ok";
|
|
15
|
+
/** The long variant adds a fixed run of tokens; the delta is what we check. */
|
|
16
|
+
const LONG_PROMPT = `${SHORT_PROMPT}\n\nReference text:${" apple".repeat(80)}`;
|
|
17
|
+
const MAX_TOKENS = 16;
|
|
18
|
+
/**
|
|
19
|
+
* Expected `input_tokens` growth between the short and long prompt.
|
|
20
|
+
*
|
|
21
|
+
* Two bands because Anthropic changed tokenizer: opus-4-7/4-8 encode that same
|
|
22
|
+
* text into materially more tokens. A relay claiming a new-tokenizer model
|
|
23
|
+
* while serving an older one lands in the wrong band, which makes this a tier
|
|
24
|
+
* check as well as a billing check.
|
|
25
|
+
*/
|
|
26
|
+
const DELTA_OLD = { min: 45, max: 140 };
|
|
27
|
+
const DELTA_NEW = { min: 90, max: 230 };
|
|
28
|
+
const NEW_TOKENIZER_MODELS = ["claude-opus-4-7", "claude-opus-4-8"];
|
|
29
|
+
/** `count_tokens` should agree with the billed `input_tokens` this closely. */
|
|
30
|
+
const countTolerance = (n) => Math.max(4, Math.round(n * 0.2));
|
|
31
|
+
const normalize = (model) => model.toLowerCase().replace(/[._]/g, "-").split("/").pop() ?? "";
|
|
32
|
+
export function expectedInputDelta(model) {
|
|
33
|
+
const m = normalize(model);
|
|
34
|
+
return NEW_TOKENIZER_MODELS.some((p) => m.startsWith(p))
|
|
35
|
+
? DELTA_NEW
|
|
36
|
+
: DELTA_OLD;
|
|
37
|
+
}
|
|
38
|
+
/** Rejects booleans, which are `typeof "number"`-adjacent traps in JS. */
|
|
39
|
+
function intOf(v) {
|
|
40
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : null;
|
|
41
|
+
}
|
|
42
|
+
function usageOf(data) {
|
|
43
|
+
const u = data?.usage;
|
|
44
|
+
return { input: intOf(u?.input_tokens), output: intOf(u?.output_tokens) };
|
|
45
|
+
}
|
|
46
|
+
export async function checkTokenTruth(opts) {
|
|
47
|
+
const base = opts.baseUrl.replace(/\/+$/, "");
|
|
48
|
+
const headers = {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"x-api-key": opts.apiKey,
|
|
51
|
+
"anthropic-version": "2023-06-01",
|
|
52
|
+
};
|
|
53
|
+
const ask = (prompt) => opts.transport({
|
|
54
|
+
mode: "direct",
|
|
55
|
+
url: `${base}/v1/messages`,
|
|
56
|
+
headers,
|
|
57
|
+
reqBody: {
|
|
58
|
+
model: opts.model,
|
|
59
|
+
max_tokens: MAX_TOKENS,
|
|
60
|
+
messages: [{ role: "user", content: prompt }],
|
|
61
|
+
},
|
|
62
|
+
timeoutMs: opts.timeoutMs,
|
|
63
|
+
});
|
|
64
|
+
const [shortRes, longRes] = await Promise.all([
|
|
65
|
+
ask(SHORT_PROMPT),
|
|
66
|
+
ask(LONG_PROMPT),
|
|
67
|
+
]);
|
|
68
|
+
const noCounts = {
|
|
69
|
+
shortInputTokens: null,
|
|
70
|
+
longInputTokens: null,
|
|
71
|
+
countTokens: null,
|
|
72
|
+
};
|
|
73
|
+
if (shortRes.status === null || shortRes.status >= 400)
|
|
74
|
+
return {
|
|
75
|
+
ok: null,
|
|
76
|
+
checks: [],
|
|
77
|
+
...noCounts,
|
|
78
|
+
reason: `probe-failed:${shortRes.status ?? "network"}`,
|
|
79
|
+
};
|
|
80
|
+
const s = usageOf(shortRes.data);
|
|
81
|
+
const l = usageOf(longRes.data);
|
|
82
|
+
const checks = [];
|
|
83
|
+
const usagePresent = s.input !== null && l.input !== null;
|
|
84
|
+
checks.push({
|
|
85
|
+
id: "usage-present",
|
|
86
|
+
pass: usagePresent,
|
|
87
|
+
detail: usagePresent
|
|
88
|
+
? `short=${s.input}, long=${l.input}`
|
|
89
|
+
: "endpoint reported no usage counts",
|
|
90
|
+
});
|
|
91
|
+
// Without usage there is nothing to verify; a missing field is not fraud.
|
|
92
|
+
if (!usagePresent)
|
|
93
|
+
return { ok: null, checks, ...noCounts, reason: "no-usage-reported" };
|
|
94
|
+
const band = expectedInputDelta(opts.model);
|
|
95
|
+
const delta = l.input - s.input;
|
|
96
|
+
const deltaOk = delta >= band.min && delta <= band.max;
|
|
97
|
+
checks.push({
|
|
98
|
+
id: "input-delta",
|
|
99
|
+
pass: deltaOk,
|
|
100
|
+
detail: `delta=${delta}, expected ${band.min}-${band.max}`,
|
|
101
|
+
});
|
|
102
|
+
// Output above the cap we set means the count is invented, not merely padded.
|
|
103
|
+
const outputs = [s.output, l.output].filter((v) => v !== null);
|
|
104
|
+
const outputOk = outputs.every((v) => v > 0 && v <= MAX_TOKENS + 4);
|
|
105
|
+
checks.push({
|
|
106
|
+
id: "output-bounded",
|
|
107
|
+
pass: outputOk,
|
|
108
|
+
detail: `outputs=${outputs.join(",") || "none"} (cap ${MAX_TOKENS})`,
|
|
109
|
+
});
|
|
110
|
+
// The same upstream pricing the same request without generating: the
|
|
111
|
+
// strongest anti-inflation signal available, when the endpoint exposes it.
|
|
112
|
+
let counted = null;
|
|
113
|
+
const countRes = await opts.transport({
|
|
114
|
+
mode: "direct",
|
|
115
|
+
url: `${base}/v1/messages/count_tokens`,
|
|
116
|
+
headers,
|
|
117
|
+
reqBody: {
|
|
118
|
+
model: opts.model,
|
|
119
|
+
messages: [{ role: "user", content: SHORT_PROMPT }],
|
|
120
|
+
},
|
|
121
|
+
timeoutMs: opts.timeoutMs,
|
|
122
|
+
});
|
|
123
|
+
if (countRes.status !== null && countRes.status < 400) {
|
|
124
|
+
counted = intOf(countRes.data?.input_tokens);
|
|
125
|
+
if (counted !== null) {
|
|
126
|
+
const drift = Math.abs(counted - s.input);
|
|
127
|
+
const tol = countTolerance(s.input);
|
|
128
|
+
checks.push({
|
|
129
|
+
id: "count-tokens",
|
|
130
|
+
pass: drift <= tol,
|
|
131
|
+
detail: `count=${counted} vs billed=${s.input}, drift=${drift} (tolerance ${tol})`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A missing count_tokens endpoint is common on relays and proves nothing, so
|
|
136
|
+
// it is simply absent from the checks rather than counted as a failure.
|
|
137
|
+
return {
|
|
138
|
+
ok: checks.every((c) => c.pass),
|
|
139
|
+
checks,
|
|
140
|
+
shortInputTokens: s.input,
|
|
141
|
+
longInputTokens: l.input,
|
|
142
|
+
countTokens: counted,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=token-truth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-truth.js","sourceRoot":"","sources":["../../src/detectors/token-truth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAC9C,+EAA+E;AAC/E,MAAM,WAAW,GAAG,GAAG,YAAY,sBAAsB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/E,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAEpE,+EAA+E;AAC/E,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAkBvE,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAClC,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AAEnE,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,CAAC,GAAG,SAAS,CAAC,KA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S;KAC1B,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,KAAK,IAAI,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtD,OAAO,GAAG,KAAK,CAAE,QAAQ,CAAC,IAAmC,EAAE,YAAY,CAAC,CAAC;QAC7E,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,KAAM,CAAC,CAAC;YAC3C,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,KAAM,CAAC,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC;gBACV,EAAE,EAAE,cAAc;gBAClB,IAAI,EAAE,KAAK,IAAI,GAAG;gBAClB,MAAM,EAAE,SAAS,OAAO,cAAc,CAAC,CAAC,KAAK,WAAW,KAAK,eAAe,GAAG,GAAG;aACnF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,6EAA6E;IAC7E,wEAAwE;IAExE,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/B,MAAM;QACN,gBAAgB,EAAE,CAAC,CAAC,KAAK;QACzB,eAAe,EAAE,CAAC,CAAC,KAAK;QACxB,WAAW,EAAE,OAAO;KACrB,CAAC;AACJ,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -8,5 +8,15 @@ export declare function runVerification(opts: {
|
|
|
8
8
|
mode: TransportMode;
|
|
9
9
|
timeoutMs?: number;
|
|
10
10
|
transport?: TransportFn;
|
|
11
|
+
/**
|
|
12
|
+
* Run the Anthropic thinking-signature check too. Opt-in: it costs one extra
|
|
13
|
+
* generation and only applies to Claude models that support thinking.
|
|
14
|
+
*/
|
|
15
|
+
checkSignature?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Verify the endpoint's token accounting (billing inflation, and the
|
|
18
|
+
* tokenizer band that doubles as a tier check). Opt-in: three extra requests.
|
|
19
|
+
*/
|
|
20
|
+
checkTokenTruth?: boolean;
|
|
11
21
|
}): Promise<VerifyResult>;
|
|
12
22
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAEV,aAAa,EACb,cAAc,EACd,YAAY,EACb,MAAM,SAAS,CAAC;AAqOjB,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,YAAY,CAAC,CAsGxB"}
|
package/dist/runner.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { checkThinkingSignature } from "./detectors/thinking-signature";
|
|
2
|
+
import { checkTokenTruth } from "./detectors/token-truth";
|
|
1
3
|
import { sleep } from "./internal/utils";
|
|
2
4
|
import { echoesNonce, makeNonce } from "./nonce";
|
|
3
5
|
import { runHandshake } from "./handshake";
|
|
4
6
|
import { PROBES } from "./probes";
|
|
5
|
-
import { PROVIDER_CONFIGS } from "./providers/config";
|
|
7
|
+
import { normalizeProbeBaseUrl, PROVIDER_CONFIGS, } from "./providers/config";
|
|
6
8
|
import { detectSignal, isTransientError } from "./signals";
|
|
7
9
|
import { probeTransport } from "./transport";
|
|
8
10
|
import { aggregateVerdict, probeReason } from "./verdict";
|
|
@@ -213,6 +215,26 @@ export async function runVerification(opts) {
|
|
|
213
215
|
timeoutMs,
|
|
214
216
|
transport,
|
|
215
217
|
})));
|
|
218
|
+
// Runs concurrently with nothing else pending, after the probes, so a
|
|
219
|
+
// signature failure can never mask a probe result.
|
|
220
|
+
const signature = opts.checkSignature && resolvedProvider === "anthropic"
|
|
221
|
+
? await checkThinkingSignature({
|
|
222
|
+
transport,
|
|
223
|
+
baseUrl: normalizeProbeBaseUrl(opts.baseUrl),
|
|
224
|
+
apiKey: opts.apiKey,
|
|
225
|
+
model: opts.model,
|
|
226
|
+
timeoutMs,
|
|
227
|
+
})
|
|
228
|
+
: undefined;
|
|
229
|
+
const tokenTruth = opts.checkTokenTruth && resolvedProvider === "anthropic"
|
|
230
|
+
? await checkTokenTruth({
|
|
231
|
+
transport,
|
|
232
|
+
baseUrl: normalizeProbeBaseUrl(opts.baseUrl),
|
|
233
|
+
apiKey: opts.apiKey,
|
|
234
|
+
model: opts.model,
|
|
235
|
+
timeoutMs,
|
|
236
|
+
})
|
|
237
|
+
: undefined;
|
|
216
238
|
const detectedModel = results.find((r) => r.detectedModel)?.detectedModel ?? null;
|
|
217
239
|
const verdict = aggregateVerdict({
|
|
218
240
|
model: opts.model,
|
|
@@ -250,6 +272,8 @@ export async function runVerification(opts) {
|
|
|
250
272
|
detectedModel,
|
|
251
273
|
totalUsage: sumUsage(results.map((r) => r.usage)),
|
|
252
274
|
resolvedProvider,
|
|
275
|
+
...(signature ? { signature } : {}),
|
|
276
|
+
...(tokenTruth ? { tokenTruth } : {}),
|
|
253
277
|
connectivityError: null,
|
|
254
278
|
};
|
|
255
279
|
}
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources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AAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;QAClD,SAAS,EAAE,EAAE,CAAC,IAAI;QAClB,WAAW;QACX,aAAa;QACb,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACjD,gBAAgB;QAChB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SignatureResult } from "./detectors/thinking-signature";
|
|
2
|
+
import type { TokenTruthResult } from "./detectors/token-truth";
|
|
1
3
|
export type VerifyProvider = "anthropic" | "openai" | "gemini";
|
|
2
4
|
export type VerifyVerdict = "genuine" | "suspicious" | "unverified";
|
|
3
5
|
export type ProbeLabel = "emotional" | "creative" | "identity" | "model-name";
|
|
@@ -38,6 +40,10 @@ export type VerifyResult = {
|
|
|
38
40
|
detectedModel: string | null;
|
|
39
41
|
totalUsage: ProbeUsage | null;
|
|
40
42
|
resolvedProvider: VerifyProvider;
|
|
43
|
+
/** Present only when the signature check was requested and could run. */
|
|
44
|
+
signature?: SignatureResult;
|
|
45
|
+
/** Present only when the token-accounting check was requested. */
|
|
46
|
+
tokenTruth?: TokenTruthResult;
|
|
41
47
|
connectivityError: "cors-needs-backend" | "unreachable" | "invalid-key" | "no-format" | null;
|
|
42
48
|
};
|
|
43
49
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"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|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Authenticity and capability checks for AI API relays: is this endpoint really the Claude / GPT / Gemini model it claims?",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"gemini"
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
|
-
"files": [
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
22
24
|
"exports": {
|
|
23
25
|
".": {
|
|
24
26
|
"types": "./dist/index.d.ts",
|