@abyss-project/probe 2.0.0 → 2.0.1
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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +22 -22
- package/package.json +10 -15
- package/src/api/index.ts +6 -6
- package/src/api/probe-scan.api.test.ts +47 -47
- package/src/api/probe-scan.api.ts +203 -203
- package/src/api/probe-scan.application.api.test.ts +35 -35
- package/src/api/probe-scan.application.api.ts +157 -157
- package/src/api/probe-usage.api.ts +47 -47
- package/src/api/probe-usage.application.api.ts +25 -25
- package/src/api/probe-webhook.api.test.ts +17 -17
- package/src/api/probe-webhook.api.ts +119 -119
- package/src/api/probe-webhook.application.api.test.ts +18 -18
- package/src/api/probe-webhook.application.api.ts +141 -141
- package/src/constants/index.ts +1 -1
- package/src/index.ts +205 -205
- package/src/types/enum/api-error.enum.ts +33 -33
- package/src/types/enum/index.ts +2 -2
- package/src/types/enum/probe-scan.enum.ts +44 -44
- package/src/types/index.ts +2 -2
- package/src/types/interface/api/index.ts +5 -5
- package/src/types/interface/api/requests/index.ts +3 -3
- package/src/types/interface/api/requests/probe-scan.request.ts +54 -54
- package/src/types/interface/api/requests/probe-usage.request.ts +7 -7
- package/src/types/interface/api/requests/probe-webhook.request.ts +33 -33
- package/src/types/interface/api/responses/index.ts +3 -3
- package/src/types/interface/api/responses/probe-scan.response.ts +45 -45
- package/src/types/interface/api/responses/probe-usage.response.ts +25 -25
- package/src/types/interface/api/responses/probe-webhook.response.ts +24 -24
- package/src/types/interface/api/type-message/api-error.ts +7 -7
- package/src/types/interface/api/type-message/base-paginate.ts +11 -11
- package/src/types/interface/api/type-message/response.ts +6 -6
- package/src/types/interface/index.ts +2 -2
- package/src/types/interface/models/index.ts +3 -3
- package/src/types/interface/models/probe-scan.dto.ts +67 -67
- package/src/types/interface/models/probe-webhook-delivery.dto.ts +73 -73
- package/src/types/interface/models/probe-webhook.dto.ts +29 -29
- package/src/types/tests/probe.dto.test.ts +156 -156
- package/src/utils/enum.utils.ts +1 -1
- package/src/utils/error.utils.ts +30 -30
- package/src/utils/index.ts +4 -4
- package/src/utils/probe-scan-cost.utils.ts +101 -101
- package/src/utils/probe-webhook-signature.utils.ts +56 -56
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +36 -36
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
// ──────────────────────────────────────────────
|
|
2
|
-
// AbyssProbe scan cost model — pure, shared (client + server, no endpoint).
|
|
3
|
-
//
|
|
4
|
-
// Ported from abyss-storage's OWN weighted AV-scan cost model
|
|
5
|
-
// (`apps/api/src/services/av-scan-usage.ts#computeAvScanCost`, introduced in
|
|
6
|
-
// storage commit 317e4a0 "wire the weighted AV-scan quota", since made dead
|
|
7
|
-
// code there by the AV v3 Phase 3b-2 hand-off — "storage never bills —
|
|
8
|
-
// AbyssProbe does" — but the FORMULA itself is exactly what AbyssProbe's own
|
|
9
|
-
// weighted billing needs, so it is ported here verbatim rather than
|
|
10
|
-
// reinvented):
|
|
11
|
-
//
|
|
12
|
-
// cost = round( (BASE + K_MB * ceil(sizeOctet / 1 MiB)) * MODE_WEIGHT[mode] )
|
|
13
|
-
//
|
|
14
|
-
// ASYNC costs LESS than SYNC (MODE_WEIGHT.async=1 < MODE_WEIGHT.sync=3) — a
|
|
15
|
-
// synchronous scan holds the caller's request (and an engine worker) until
|
|
16
|
-
// the verdict and cannot be batched/load-balanced, so it costs more than an
|
|
17
|
-
// asynchronous (queued) scan of the SAME bytes. This is the numeric backing
|
|
18
|
-
// for the scanner UI's "l'analyse en arrière-plan économise des tokens"
|
|
19
|
-
// tooltip (WS1).
|
|
20
|
-
//
|
|
21
|
-
// PURE + DETERMINISTIC + no I/O: this is the SINGLE source of truth for
|
|
22
|
-
// AbyssProbe's scan cost, used on BOTH sides of the wire —
|
|
23
|
-
// - server (apps/api/src/services/probe-scan.service.ts): the REAL cost
|
|
24
|
-
// billed via recordProbeScanUsage and persisted on probe_scans.costUnits
|
|
25
|
-
// once a scan reaches a verdict (DONE).
|
|
26
|
-
// - client (the AbyssProbe UI, or any external caller): a cost PREVIEW
|
|
27
|
-
// before scanning — call this with the picked file's size and the
|
|
28
|
-
// intended mode to show the estimated token cost, matching exactly what
|
|
29
|
-
// the server will bill (no separate "estimate" formula to drift out of
|
|
30
|
-
// sync with the real one — same function, same constants, both sides).
|
|
31
|
-
//
|
|
32
|
-
// Deliberately NOT exposed as an HTTP endpoint (no `POST /scan/estimate`):
|
|
33
|
-
// the whole point of a pure function is that the client can compute it
|
|
34
|
-
// locally, instantly, with zero round-trip — see this package's root README
|
|
35
|
-
// note on `sdk.probe.*`'s HTTP-call-only convention; a helper like this one
|
|
36
|
-
// (and `verifyProbeWebhookSignature` before it) is instead a plain top-level
|
|
37
|
-
// export, not a `sdk.probe.*` method.
|
|
38
|
-
// ──────────────────────────────────────────────
|
|
39
|
-
|
|
40
|
-
import { ProbeScanMode } from '../types';
|
|
41
|
-
|
|
42
|
-
/** Flat floor every scanned file pays (the "one scan" cost). Tunable. */
|
|
43
|
-
export const PROBE_SCAN_COST_BASE = 1;
|
|
44
|
-
|
|
45
|
-
/** Additional units per (ceil'd) mebibyte of scanned bytes. Tunable. */
|
|
46
|
-
export const PROBE_SCAN_COST_K_MB = 1;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Per-mode cost multiplier. A synchronous scan blocks the caller's request
|
|
50
|
-
* (and an engine worker) until the verdict and cannot be queued/batched, so
|
|
51
|
-
* it costs strictly MORE than an asynchronous scan of the same bytes —
|
|
52
|
-
* ASYNC < SYNC is a load-bearing invariant relied on by the scanner UI's
|
|
53
|
-
* "background analysis saves tokens" messaging (WS1). Tunable, but this
|
|
54
|
-
* ordering must never be inverted.
|
|
55
|
-
*/
|
|
56
|
-
export const PROBE_SCAN_COST_MODE_WEIGHT: Record<ProbeScanMode, number> = {
|
|
57
|
-
[ProbeScanMode.ASYNC]: 1,
|
|
58
|
-
[ProbeScanMode.SYNC]: 3,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/** One mebibyte, the unit the per-MB term is quantised to. */
|
|
62
|
-
const ONE_MB = 1024 * 1024;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Weighted cost of one AbyssProbe scan, in `ACCOUNT_AV_SCAN_UNITS` ("tokens"
|
|
66
|
-
* in the UI). Pure + deterministic — same inputs always produce the same
|
|
67
|
-
* output, no I/O, safe to call from a browser or a server.
|
|
68
|
-
*
|
|
69
|
-
* Returns `0` for a non-finite / non-positive `sizeOctet` (nothing to scan,
|
|
70
|
-
* nothing to bill) rather than throwing — a defensive, never-crash contract
|
|
71
|
-
* appropriate for a client-side cost preview that might run ahead of full
|
|
72
|
-
* input validation (e.g. while a file is still being selected).
|
|
73
|
-
*
|
|
74
|
-
* `mode` defaults to the (cheaper) ASYNC weight when given an unrecognised
|
|
75
|
-
* value, mirroring the ported formula's own `MODE_WEIGHT[mode] ?? MODE_WEIGHT.async`
|
|
76
|
-
* fallback — never silently the MORE expensive weight.
|
|
77
|
-
*
|
|
78
|
-
* `mode`'s type is widened to `| 'sync' | 'async'` alongside the enum
|
|
79
|
-
* itself, NOT just `ProbeScanMode`: apps/api's own server-side
|
|
80
|
-
* `database/probe-scan.enum.ts#ProbeScanMode` is a SEPARATE TypeScript enum
|
|
81
|
-
* declaration (kept server-local — see that file's header comment on why —
|
|
82
|
-
* with the identical 'sync'/'async' runtime values, so the wire format never
|
|
83
|
-
* drifts). TypeScript string enums are nominal: a same-valued member of that
|
|
84
|
-
* OTHER enum is not directly assignable to THIS package's `ProbeScanMode`
|
|
85
|
-
* parameter type, but IS assignable to a plain string-literal type matching
|
|
86
|
-
* its value — so the server can call this exact function (`scan.mode`,
|
|
87
|
-
* `estimateProbeScanCost`'s whole reason for living being ONE shared formula
|
|
88
|
-
* on both sides of the wire, see this file's header comment) without a cast.
|
|
89
|
-
*/
|
|
90
|
-
export const estimateProbeScanCost = (
|
|
91
|
-
sizeOctet: number,
|
|
92
|
-
mode: ProbeScanMode | 'sync' | 'async',
|
|
93
|
-
): number => {
|
|
94
|
-
if (!Number.isFinite(sizeOctet) || sizeOctet <= 0) {
|
|
95
|
-
return 0;
|
|
96
|
-
}
|
|
97
|
-
const megabytes = Math.ceil(sizeOctet / ONE_MB);
|
|
98
|
-
const weight =
|
|
99
|
-
PROBE_SCAN_COST_MODE_WEIGHT[mode] ?? PROBE_SCAN_COST_MODE_WEIGHT[ProbeScanMode.ASYNC];
|
|
100
|
-
return Math.round((PROBE_SCAN_COST_BASE + PROBE_SCAN_COST_K_MB * megabytes) * weight);
|
|
101
|
-
};
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe scan cost model — pure, shared (client + server, no endpoint).
|
|
3
|
+
//
|
|
4
|
+
// Ported from abyss-storage's OWN weighted AV-scan cost model
|
|
5
|
+
// (`apps/api/src/services/av-scan-usage.ts#computeAvScanCost`, introduced in
|
|
6
|
+
// storage commit 317e4a0 "wire the weighted AV-scan quota", since made dead
|
|
7
|
+
// code there by the AV v3 Phase 3b-2 hand-off — "storage never bills —
|
|
8
|
+
// AbyssProbe does" — but the FORMULA itself is exactly what AbyssProbe's own
|
|
9
|
+
// weighted billing needs, so it is ported here verbatim rather than
|
|
10
|
+
// reinvented):
|
|
11
|
+
//
|
|
12
|
+
// cost = round( (BASE + K_MB * ceil(sizeOctet / 1 MiB)) * MODE_WEIGHT[mode] )
|
|
13
|
+
//
|
|
14
|
+
// ASYNC costs LESS than SYNC (MODE_WEIGHT.async=1 < MODE_WEIGHT.sync=3) — a
|
|
15
|
+
// synchronous scan holds the caller's request (and an engine worker) until
|
|
16
|
+
// the verdict and cannot be batched/load-balanced, so it costs more than an
|
|
17
|
+
// asynchronous (queued) scan of the SAME bytes. This is the numeric backing
|
|
18
|
+
// for the scanner UI's "l'analyse en arrière-plan économise des tokens"
|
|
19
|
+
// tooltip (WS1).
|
|
20
|
+
//
|
|
21
|
+
// PURE + DETERMINISTIC + no I/O: this is the SINGLE source of truth for
|
|
22
|
+
// AbyssProbe's scan cost, used on BOTH sides of the wire —
|
|
23
|
+
// - server (apps/api/src/services/probe-scan.service.ts): the REAL cost
|
|
24
|
+
// billed via recordProbeScanUsage and persisted on probe_scans.costUnits
|
|
25
|
+
// once a scan reaches a verdict (DONE).
|
|
26
|
+
// - client (the AbyssProbe UI, or any external caller): a cost PREVIEW
|
|
27
|
+
// before scanning — call this with the picked file's size and the
|
|
28
|
+
// intended mode to show the estimated token cost, matching exactly what
|
|
29
|
+
// the server will bill (no separate "estimate" formula to drift out of
|
|
30
|
+
// sync with the real one — same function, same constants, both sides).
|
|
31
|
+
//
|
|
32
|
+
// Deliberately NOT exposed as an HTTP endpoint (no `POST /scan/estimate`):
|
|
33
|
+
// the whole point of a pure function is that the client can compute it
|
|
34
|
+
// locally, instantly, with zero round-trip — see this package's root README
|
|
35
|
+
// note on `sdk.probe.*`'s HTTP-call-only convention; a helper like this one
|
|
36
|
+
// (and `verifyProbeWebhookSignature` before it) is instead a plain top-level
|
|
37
|
+
// export, not a `sdk.probe.*` method.
|
|
38
|
+
// ──────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
import { ProbeScanMode } from '../types';
|
|
41
|
+
|
|
42
|
+
/** Flat floor every scanned file pays (the "one scan" cost). Tunable. */
|
|
43
|
+
export const PROBE_SCAN_COST_BASE = 1;
|
|
44
|
+
|
|
45
|
+
/** Additional units per (ceil'd) mebibyte of scanned bytes. Tunable. */
|
|
46
|
+
export const PROBE_SCAN_COST_K_MB = 1;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Per-mode cost multiplier. A synchronous scan blocks the caller's request
|
|
50
|
+
* (and an engine worker) until the verdict and cannot be queued/batched, so
|
|
51
|
+
* it costs strictly MORE than an asynchronous scan of the same bytes —
|
|
52
|
+
* ASYNC < SYNC is a load-bearing invariant relied on by the scanner UI's
|
|
53
|
+
* "background analysis saves tokens" messaging (WS1). Tunable, but this
|
|
54
|
+
* ordering must never be inverted.
|
|
55
|
+
*/
|
|
56
|
+
export const PROBE_SCAN_COST_MODE_WEIGHT: Record<ProbeScanMode, number> = {
|
|
57
|
+
[ProbeScanMode.ASYNC]: 1,
|
|
58
|
+
[ProbeScanMode.SYNC]: 3,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** One mebibyte, the unit the per-MB term is quantised to. */
|
|
62
|
+
const ONE_MB = 1024 * 1024;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Weighted cost of one AbyssProbe scan, in `ACCOUNT_AV_SCAN_UNITS` ("tokens"
|
|
66
|
+
* in the UI). Pure + deterministic — same inputs always produce the same
|
|
67
|
+
* output, no I/O, safe to call from a browser or a server.
|
|
68
|
+
*
|
|
69
|
+
* Returns `0` for a non-finite / non-positive `sizeOctet` (nothing to scan,
|
|
70
|
+
* nothing to bill) rather than throwing — a defensive, never-crash contract
|
|
71
|
+
* appropriate for a client-side cost preview that might run ahead of full
|
|
72
|
+
* input validation (e.g. while a file is still being selected).
|
|
73
|
+
*
|
|
74
|
+
* `mode` defaults to the (cheaper) ASYNC weight when given an unrecognised
|
|
75
|
+
* value, mirroring the ported formula's own `MODE_WEIGHT[mode] ?? MODE_WEIGHT.async`
|
|
76
|
+
* fallback — never silently the MORE expensive weight.
|
|
77
|
+
*
|
|
78
|
+
* `mode`'s type is widened to `| 'sync' | 'async'` alongside the enum
|
|
79
|
+
* itself, NOT just `ProbeScanMode`: apps/api's own server-side
|
|
80
|
+
* `database/probe-scan.enum.ts#ProbeScanMode` is a SEPARATE TypeScript enum
|
|
81
|
+
* declaration (kept server-local — see that file's header comment on why —
|
|
82
|
+
* with the identical 'sync'/'async' runtime values, so the wire format never
|
|
83
|
+
* drifts). TypeScript string enums are nominal: a same-valued member of that
|
|
84
|
+
* OTHER enum is not directly assignable to THIS package's `ProbeScanMode`
|
|
85
|
+
* parameter type, but IS assignable to a plain string-literal type matching
|
|
86
|
+
* its value — so the server can call this exact function (`scan.mode`,
|
|
87
|
+
* `estimateProbeScanCost`'s whole reason for living being ONE shared formula
|
|
88
|
+
* on both sides of the wire, see this file's header comment) without a cast.
|
|
89
|
+
*/
|
|
90
|
+
export const estimateProbeScanCost = (
|
|
91
|
+
sizeOctet: number,
|
|
92
|
+
mode: ProbeScanMode | 'sync' | 'async',
|
|
93
|
+
): number => {
|
|
94
|
+
if (!Number.isFinite(sizeOctet) || sizeOctet <= 0) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
const megabytes = Math.ceil(sizeOctet / ONE_MB);
|
|
98
|
+
const weight =
|
|
99
|
+
PROBE_SCAN_COST_MODE_WEIGHT[mode] ?? PROBE_SCAN_COST_MODE_WEIGHT[ProbeScanMode.ASYNC];
|
|
100
|
+
return Math.round((PROBE_SCAN_COST_BASE + PROBE_SCAN_COST_K_MB * megabytes) * weight);
|
|
101
|
+
};
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
// ──────────────────────────────────────────────
|
|
2
|
-
// AbyssProbe webhook signature verification (helper for RECEIVERS of a
|
|
3
|
-
// webhook delivery — the abyss-main UI/abyss-storage/any external
|
|
4
|
-
// integrator that registered a callbackUrl).
|
|
5
|
-
//
|
|
6
|
-
// Mirrors this package's own extraction-webhook.utils.ts
|
|
7
|
-
// (verifyExtractionWebhook) — the same package's own precedent for this
|
|
8
|
-
// exact problem — adapted to AbyssProbe's actual wire format: the signature
|
|
9
|
-
// header (see PROBE_WEBHOOK_SIGNATURE_HEADER in this package's root index)
|
|
10
|
-
// carries the RAW hex HMAC digest with no `sha256=` prefix (unlike
|
|
11
|
-
// the extraction signature header `x-rcb-signature: sha256=<hex>`) — see
|
|
12
|
-
// apps/api/src/services/probe-webhook-delivery.service.ts's `sign()`.
|
|
13
|
-
//
|
|
14
|
-
// Lazy-requires `crypto` so the SDK stays browser-compatible when this
|
|
15
|
-
// utility is never invoked (a browser page is never the receiving end of a
|
|
16
|
-
// server-to-server webhook).
|
|
17
|
-
// ──────────────────────────────────────────────
|
|
18
|
-
|
|
19
|
-
export interface VerifyProbeWebhookSignatureInput {
|
|
20
|
-
/** The exact bytes/string the receiver's HTTP framework handed it — must be the RAW body, not a re-serialized JSON.parse/stringify round trip (whitespace/key-order would change the HMAC). */
|
|
21
|
-
rawBody: string | Buffer;
|
|
22
|
-
/** The incoming `x-probe-signature` header value. */
|
|
23
|
-
signatureHeader: string | undefined;
|
|
24
|
-
/** This webhook registration's secret (re-displayable on IProbeWebhook). */
|
|
25
|
-
secret: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Recompute the HMAC-SHA256 of `rawBody` with `secret` and constant-time
|
|
30
|
-
* compare it against `signatureHeader`. Returns `false` (never throws) for
|
|
31
|
-
* any malformed input — a hostile/truncated header must not crash the
|
|
32
|
-
* receiver.
|
|
33
|
-
*/
|
|
34
|
-
export function verifyProbeWebhookSignature(input: VerifyProbeWebhookSignatureInput): boolean {
|
|
35
|
-
if (!input.signatureHeader || !input.secret) return false;
|
|
36
|
-
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
-
const crypto = require('crypto');
|
|
39
|
-
const computed: string = crypto
|
|
40
|
-
.createHmac('sha256', input.secret)
|
|
41
|
-
.update(input.rawBody)
|
|
42
|
-
.digest('hex');
|
|
43
|
-
|
|
44
|
-
if (input.signatureHeader.length !== computed.length) return false;
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
return crypto.timingSafeEqual(
|
|
48
|
-
Buffer.from(input.signatureHeader, 'hex'),
|
|
49
|
-
Buffer.from(computed, 'hex'),
|
|
50
|
-
);
|
|
51
|
-
} catch {
|
|
52
|
-
// Buffer.from(..., 'hex') on a non-hex string yields a shorter buffer,
|
|
53
|
-
// which would otherwise make timingSafeEqual throw on a length mismatch.
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe webhook signature verification (helper for RECEIVERS of a
|
|
3
|
+
// webhook delivery — the abyss-main UI/abyss-storage/any external
|
|
4
|
+
// integrator that registered a callbackUrl).
|
|
5
|
+
//
|
|
6
|
+
// Mirrors this package's own extraction-webhook.utils.ts
|
|
7
|
+
// (verifyExtractionWebhook) — the same package's own precedent for this
|
|
8
|
+
// exact problem — adapted to AbyssProbe's actual wire format: the signature
|
|
9
|
+
// header (see PROBE_WEBHOOK_SIGNATURE_HEADER in this package's root index)
|
|
10
|
+
// carries the RAW hex HMAC digest with no `sha256=` prefix (unlike
|
|
11
|
+
// the extraction signature header `x-rcb-signature: sha256=<hex>`) — see
|
|
12
|
+
// apps/api/src/services/probe-webhook-delivery.service.ts's `sign()`.
|
|
13
|
+
//
|
|
14
|
+
// Lazy-requires `crypto` so the SDK stays browser-compatible when this
|
|
15
|
+
// utility is never invoked (a browser page is never the receiving end of a
|
|
16
|
+
// server-to-server webhook).
|
|
17
|
+
// ──────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
export interface VerifyProbeWebhookSignatureInput {
|
|
20
|
+
/** The exact bytes/string the receiver's HTTP framework handed it — must be the RAW body, not a re-serialized JSON.parse/stringify round trip (whitespace/key-order would change the HMAC). */
|
|
21
|
+
rawBody: string | Buffer;
|
|
22
|
+
/** The incoming `x-probe-signature` header value. */
|
|
23
|
+
signatureHeader: string | undefined;
|
|
24
|
+
/** This webhook registration's secret (re-displayable on IProbeWebhook). */
|
|
25
|
+
secret: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Recompute the HMAC-SHA256 of `rawBody` with `secret` and constant-time
|
|
30
|
+
* compare it against `signatureHeader`. Returns `false` (never throws) for
|
|
31
|
+
* any malformed input — a hostile/truncated header must not crash the
|
|
32
|
+
* receiver.
|
|
33
|
+
*/
|
|
34
|
+
export function verifyProbeWebhookSignature(input: VerifyProbeWebhookSignatureInput): boolean {
|
|
35
|
+
if (!input.signatureHeader || !input.secret) return false;
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
+
const crypto = require('crypto');
|
|
39
|
+
const computed: string = crypto
|
|
40
|
+
.createHmac('sha256', input.secret)
|
|
41
|
+
.update(input.rawBody)
|
|
42
|
+
.digest('hex');
|
|
43
|
+
|
|
44
|
+
if (input.signatureHeader.length !== computed.length) return false;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
return crypto.timingSafeEqual(
|
|
48
|
+
Buffer.from(input.signatureHeader, 'hex'),
|
|
49
|
+
Buffer.from(computed, 'hex'),
|
|
50
|
+
);
|
|
51
|
+
} catch {
|
|
52
|
+
// Buffer.from(..., 'hex') on a non-hex string yields a shorter buffer,
|
|
53
|
+
// which would otherwise make timingSafeEqual throw on a length mismatch.
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/tsconfig.check.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Perimetre de VERIFICATION, distinct de celui du build.
|
|
3
|
-
//
|
|
4
|
-
// `tsconfig.json` exclut `src/**/*.spec.ts` parce qu'il sert a emettre `dist/`, ou une spec
|
|
5
|
-
// n'a rien a faire. Mais eslint s'appuie sur ce meme fichier via `parserOptions.project` :
|
|
6
|
-
// les cinq specs du paquet sortaient donc en « Parsing error: that TSConfig does not include
|
|
7
|
-
// this file », mesure du 2026-09-09, et n'etaient lintees par personne.
|
|
8
|
-
//
|
|
9
|
-
// Ce fichier sert uniquement a eslint. Il n'emet rien et ne change pas ce que `build` produit.
|
|
10
|
-
"extends": "./tsconfig.json",
|
|
11
|
-
"compilerOptions": {
|
|
12
|
-
"noEmit": true
|
|
13
|
-
},
|
|
14
|
-
"exclude": ["./dist/**/*"]
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// Perimetre de VERIFICATION, distinct de celui du build.
|
|
3
|
+
//
|
|
4
|
+
// `tsconfig.json` exclut `src/**/*.spec.ts` parce qu'il sert a emettre `dist/`, ou une spec
|
|
5
|
+
// n'a rien a faire. Mais eslint s'appuie sur ce meme fichier via `parserOptions.project` :
|
|
6
|
+
// les cinq specs du paquet sortaient donc en « Parsing error: that TSConfig does not include
|
|
7
|
+
// this file », mesure du 2026-09-09, et n'etaient lintees par personne.
|
|
8
|
+
//
|
|
9
|
+
// Ce fichier sert uniquement a eslint. Il n'emet rien et ne change pas ce que `build` produit.
|
|
10
|
+
"extends": "./tsconfig.json",
|
|
11
|
+
"compilerOptions": {
|
|
12
|
+
"noEmit": true
|
|
13
|
+
},
|
|
14
|
+
"exclude": ["./dist/**/*"]
|
|
15
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"incremental": false,
|
|
4
|
-
"target": "es2021",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"es2021"
|
|
8
|
-
],
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"emitDecoratorMetadata": true,
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"rootDir": "src",
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"allowJs": true,
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"sourceMap": true,
|
|
18
|
-
"outDir": "./dist",
|
|
19
|
-
"removeComments": true,
|
|
20
|
-
"allowSyntheticDefaultImports": true,
|
|
21
|
-
"esModuleInterop": true,
|
|
22
|
-
"forceConsistentCasingInFileNames": true,
|
|
23
|
-
"strict": true,
|
|
24
|
-
"strictNullChecks": true,
|
|
25
|
-
"strictFunctionTypes": true,
|
|
26
|
-
"strictPropertyInitialization": false,
|
|
27
|
-
"skipLibCheck": true
|
|
28
|
-
},
|
|
29
|
-
"include": [
|
|
30
|
-
"./src"
|
|
31
|
-
],
|
|
32
|
-
"exclude": [
|
|
33
|
-
"./dist/**/*",
|
|
34
|
-
"./src/**/*.spec.ts"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"incremental": false,
|
|
4
|
+
"target": "es2021",
|
|
5
|
+
"lib": [
|
|
6
|
+
"dom",
|
|
7
|
+
"es2021"
|
|
8
|
+
],
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"emitDecoratorMetadata": true,
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"rootDir": "src",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"allowJs": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"outDir": "./dist",
|
|
19
|
+
"removeComments": true,
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"forceConsistentCasingInFileNames": true,
|
|
23
|
+
"strict": true,
|
|
24
|
+
"strictNullChecks": true,
|
|
25
|
+
"strictFunctionTypes": true,
|
|
26
|
+
"strictPropertyInitialization": false,
|
|
27
|
+
"skipLibCheck": true
|
|
28
|
+
},
|
|
29
|
+
"include": [
|
|
30
|
+
"./src"
|
|
31
|
+
],
|
|
32
|
+
"exclude": [
|
|
33
|
+
"./dist/**/*",
|
|
34
|
+
"./src/**/*.spec.ts"
|
|
35
|
+
]
|
|
36
|
+
}
|