@mcpose/testing 2.0.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/LICENSE +21 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Amir Gorji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AuditEvent, ReplayManifest } from '@mcpose/audit';
|
|
2
|
+
import type { Identity } from 'mcpose';
|
|
3
|
+
export type { AuditEvent, ReplayManifest };
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that an ordered sequence of audit events forms a valid HMAC chain.
|
|
6
|
+
* Verifies that each event's chainHash is consistent with its position
|
|
7
|
+
* (i.e. that no entry has been inserted, removed, or tampered).
|
|
8
|
+
*
|
|
9
|
+
* Does NOT re-compute the HMAC (the signing key is not available here) —
|
|
10
|
+
* instead checks that the chainHash changes with each entry (chain is live)
|
|
11
|
+
* and that the `replayManifestPosition` values are sequential.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertAuditChainIntegrity(events: AuditEvent[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Asserts that every Merkle proof in a ReplayManifest verifies against the root.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertReplayManifestValid(events: AuditEvent[], manifest: ReplayManifest): void;
|
|
18
|
+
/**
|
|
19
|
+
* Asserts that a high-sensitivity audit event does not contain plaintext
|
|
20
|
+
* input or output matching any of the given patterns.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertPiiRedacted(event: AuditEvent, patterns: RegExp[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Asserts that a delegation chain is non-empty and each entry has a valid sub.
|
|
25
|
+
*/
|
|
26
|
+
export declare function assertDelegationHonored(chain: Identity[]): void;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAwBpE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,UAAU,EAAE,EACpB,QAAQ,EAAE,cAAc,GACvB,IAAI,CAiBN;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAU7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAS/D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { verifyMerkleProof } from '@mcpose/audit';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that an ordered sequence of audit events forms a valid HMAC chain.
|
|
4
|
+
* Verifies that each event's chainHash is consistent with its position
|
|
5
|
+
* (i.e. that no entry has been inserted, removed, or tampered).
|
|
6
|
+
*
|
|
7
|
+
* Does NOT re-compute the HMAC (the signing key is not available here) —
|
|
8
|
+
* instead checks that the chainHash changes with each entry (chain is live)
|
|
9
|
+
* and that the `replayManifestPosition` values are sequential.
|
|
10
|
+
*/
|
|
11
|
+
export function assertAuditChainIntegrity(events) {
|
|
12
|
+
if (events.length === 0)
|
|
13
|
+
return;
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
for (let i = 0; i < events.length; i++) {
|
|
16
|
+
const event = events[i];
|
|
17
|
+
if (event.replayManifestPosition !== i) {
|
|
18
|
+
throw new Error(`Audit chain broken at index ${i}: replayManifestPosition is ${event.replayManifestPosition}, expected ${i}`);
|
|
19
|
+
}
|
|
20
|
+
if (!event.chainHash || event.chainHash.length === 0) {
|
|
21
|
+
throw new Error(`Audit chain broken at index ${i}: chainHash is empty`);
|
|
22
|
+
}
|
|
23
|
+
if (seen.has(event.chainHash)) {
|
|
24
|
+
throw new Error(`Audit chain broken at index ${i}: duplicate chainHash "${event.chainHash}" — chain has been tampered`);
|
|
25
|
+
}
|
|
26
|
+
seen.add(event.chainHash);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Asserts that every Merkle proof in a ReplayManifest verifies against the root.
|
|
31
|
+
*/
|
|
32
|
+
export function assertReplayManifestValid(events, manifest) {
|
|
33
|
+
if (manifest.eventCount !== events.length) {
|
|
34
|
+
throw new Error(`ReplayManifest eventCount (${manifest.eventCount}) does not match events array length (${events.length})`);
|
|
35
|
+
}
|
|
36
|
+
for (let i = 0; i < events.length; i++) {
|
|
37
|
+
const valid = verifyMerkleProof(events[i].chainHash, manifest.merkleProofs[i], manifest.merkleRoot);
|
|
38
|
+
if (!valid) {
|
|
39
|
+
throw new Error(`Merkle proof for event at index ${i} does not verify against root`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Asserts that a high-sensitivity audit event does not contain plaintext
|
|
45
|
+
* input or output matching any of the given patterns.
|
|
46
|
+
*/
|
|
47
|
+
export function assertPiiRedacted(event, patterns) {
|
|
48
|
+
if (event.sensitivityTier !== 'high') {
|
|
49
|
+
const lowOrMed = event;
|
|
50
|
+
const raw = JSON.stringify({ inputRaw: lowOrMed.inputRaw, outputRaw: lowOrMed.outputRaw });
|
|
51
|
+
for (const pattern of patterns) {
|
|
52
|
+
if (pattern.test(raw)) {
|
|
53
|
+
throw new Error(`PII pattern ${pattern} found in audit event for tool "${event.tool}"`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Asserts that a delegation chain is non-empty and each entry has a valid sub.
|
|
60
|
+
*/
|
|
61
|
+
export function assertDelegationHonored(chain) {
|
|
62
|
+
if (chain.length === 0) {
|
|
63
|
+
throw new Error('Delegation chain is empty — expected at least one delegating identity');
|
|
64
|
+
}
|
|
65
|
+
for (let i = 0; i < chain.length; i++) {
|
|
66
|
+
if (!chain[i].sub) {
|
|
67
|
+
throw new Error(`Delegation chain entry at index ${i} has no sub`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70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KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,aAAa,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcpose/testing",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Compliance testing utilities for mcpose — audit chain assertions, scenario harness",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"testing",
|
|
21
|
+
"compliance",
|
|
22
|
+
"audit",
|
|
23
|
+
"fintech"
|
|
24
|
+
],
|
|
25
|
+
"author": "Amir Gorji",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/amir-gorji/mcpose.git",
|
|
30
|
+
"directory": "packages/testing"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"mcpose": ">=2.0.0",
|
|
34
|
+
"@mcpose/audit": ">=2.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.0.0",
|
|
38
|
+
"typescript": "^5.0.0",
|
|
39
|
+
"vitest": "^3.0.0",
|
|
40
|
+
"mcpose": "2.0.1",
|
|
41
|
+
"@mcpose/audit": "2.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.build.json",
|
|
45
|
+
"ts:ci": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run --passWithNoTests"
|
|
47
|
+
}
|
|
48
|
+
}
|