@nexart/mcp-server 0.0.0-stage → 0.2.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/CHANGELOG.md +108 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +356 -2
- package/SECURITY.md +77 -0
- package/THIRD_PARTY_NOTICES.md +111 -0
- package/dist/adapters.d.ts +16 -0
- package/dist/adapters.js +48 -0
- package/dist/approve-public.d.ts +2 -0
- package/dist/approve-public.js +65 -0
- package/dist/contracts.d.ts +48 -0
- package/dist/contracts.js +35 -0
- package/dist/create-confidential.d.ts +2 -0
- package/dist/create-confidential.js +34 -0
- package/dist/instrumentation/openai-worker.d.ts +1 -0
- package/dist/instrumentation/openai-worker.js +26 -0
- package/dist/instrumentation/openai.d.ts +51 -0
- package/dist/instrumentation/openai.js +197 -0
- package/dist/json-schema.d.ts +9 -0
- package/dist/json-schema.js +20 -0
- package/dist/limits.d.ts +15 -0
- package/dist/limits.js +62 -0
- package/dist/lookup/contracts.d.ts +38 -0
- package/dist/lookup/contracts.js +23 -0
- package/dist/lookup/verify.d.ts +54 -0
- package/dist/lookup/verify.js +110 -0
- package/dist/network/client.d.ts +26 -0
- package/dist/network/client.js +188 -0
- package/dist/network/contracts.d.ts +104 -0
- package/dist/network/contracts.js +54 -0
- package/dist/network-tools.d.ts +5 -0
- package/dist/network-tools.js +32 -0
- package/dist/owner/create.d.ts +52 -0
- package/dist/owner/create.js +117 -0
- package/dist/owner/custody.d.ts +36 -0
- package/dist/owner/custody.js +210 -0
- package/dist/owner/host.d.ts +10 -0
- package/dist/owner/host.js +70 -0
- package/dist/owner/publisher.d.ts +21 -0
- package/dist/owner/publisher.js +27 -0
- package/dist/owner/reconcile.d.ts +16 -0
- package/dist/owner/reconcile.js +109 -0
- package/dist/protocol-safety.d.ts +3 -0
- package/dist/protocol-safety.js +16 -0
- package/dist/receipts/contracts.d.ts +72 -0
- package/dist/receipts/contracts.js +34 -0
- package/dist/receipts/verify.d.ts +4 -0
- package/dist/receipts/verify.js +104 -0
- package/dist/record/contracts.d.ts +323 -0
- package/dist/record/contracts.js +75 -0
- package/dist/record/customer.d.ts +40 -0
- package/dist/record/customer.js +99 -0
- package/dist/record/policy.d.ts +46 -0
- package/dist/record/policy.js +67 -0
- package/dist/record/publication.d.ts +23 -0
- package/dist/record/publication.js +148 -0
- package/dist/record/record.d.ts +15 -0
- package/dist/record/record.js +97 -0
- package/dist/record/state.d.ts +44 -0
- package/dist/record/state.js +84 -0
- package/dist/record-tools.d.ts +13 -0
- package/dist/record-tools.js +95 -0
- package/dist/recover-confidential.d.ts +2 -0
- package/dist/recover-confidential.js +13 -0
- package/dist/results.d.ts +8 -0
- package/dist/results.js +83 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +39 -0
- package/dist/stdio.d.ts +2 -0
- package/dist/stdio.js +88 -0
- package/dist/trust/lifecycle.d.ts +13 -0
- package/dist/trust/lifecycle.js +42 -0
- package/dist/trust/policy.d.ts +14 -0
- package/dist/trust/policy.js +6 -0
- package/dist/verify.d.ts +3 -0
- package/dist/verify.js +56 -0
- package/dist/write/approval.d.ts +5 -0
- package/dist/write/approval.js +95 -0
- package/dist/write/attest.d.ts +17 -0
- package/dist/write/attest.js +141 -0
- package/dist/write/config.d.ts +11 -0
- package/dist/write/config.js +12 -0
- package/dist/write/contracts.d.ts +229 -0
- package/dist/write/contracts.js +61 -0
- package/dist/write/post.d.ts +11 -0
- package/dist/write/post.js +105 -0
- package/dist/write/profile.d.ts +19 -0
- package/dist/write/profile.js +114 -0
- package/dist/write/seal.d.ts +3 -0
- package/dist/write/seal.js +49 -0
- package/dist/write-tools.d.ts +4 -0
- package/dist/write-tools.js +36 -0
- package/docs/consumer-guide.md +133 -0
- package/docs/examples/customer-claude-desktop.json +14 -0
- package/docs/examples/customer-consent.json +15 -0
- package/docs/examples/customer-custody.json +8 -0
- package/docs/examples/customer-policy.json +43 -0
- package/package.json +58 -4
- package/server.json +20 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NodeNetwork } from '../network/client.js';
|
|
2
|
+
import { type LookupOutput } from './contracts.js';
|
|
3
|
+
export declare function resolveCer(hash: string, network: NodeNetwork, signal: AbortSignal): Promise<{
|
|
4
|
+
artifactType: "cer";
|
|
5
|
+
certificateHash: string;
|
|
6
|
+
identity: {
|
|
7
|
+
certificate_hash: string;
|
|
8
|
+
bundle_type: string;
|
|
9
|
+
};
|
|
10
|
+
proof: {
|
|
11
|
+
certificate_hash: string;
|
|
12
|
+
};
|
|
13
|
+
verification: {
|
|
14
|
+
receipt: Record<string, unknown>;
|
|
15
|
+
receiptSignature: string;
|
|
16
|
+
verificationEnvelope: Record<string, unknown>;
|
|
17
|
+
verificationEnvelopeSignature: string;
|
|
18
|
+
};
|
|
19
|
+
context: unknown;
|
|
20
|
+
bundle: Record<string, unknown>;
|
|
21
|
+
ok: true;
|
|
22
|
+
schemaVersion: "1.0";
|
|
23
|
+
links: {
|
|
24
|
+
self: string;
|
|
25
|
+
keyManifest: string;
|
|
26
|
+
humanVerifier: string;
|
|
27
|
+
verify?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
canonical?: {
|
|
30
|
+
certificate?: {
|
|
31
|
+
hash?: string | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
} | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function resolveProject(hash: string, network: NodeNetwork, signal: AbortSignal): Promise<{
|
|
36
|
+
artifactType: "project_bundle";
|
|
37
|
+
projectHash: string;
|
|
38
|
+
proof: {
|
|
39
|
+
projectHash: string;
|
|
40
|
+
};
|
|
41
|
+
bundle: Record<string, unknown> | null;
|
|
42
|
+
nodeReceipt: {
|
|
43
|
+
projectHash: string;
|
|
44
|
+
} | null;
|
|
45
|
+
ok: true;
|
|
46
|
+
schemaVersion: "1.0";
|
|
47
|
+
links: {
|
|
48
|
+
self: string;
|
|
49
|
+
keyManifest: string;
|
|
50
|
+
humanVerifier: string;
|
|
51
|
+
verify?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
export declare function lookup(project: boolean, args: unknown, network: NodeNetwork, signal?: AbortSignal): Promise<LookupOutput>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { NodeNetwork, NetworkFailure, safeFailure } from '../network/client.js';
|
|
2
|
+
import { cerResponseSchema, projectResponseSchema, parseResponse } from '../network/contracts.js';
|
|
3
|
+
import { checkInput, isObject, LIMITS } from '../limits.js';
|
|
4
|
+
import { verify } from '../verify.js';
|
|
5
|
+
import { lookupCerInput, lookupProjectInput } from './contracts.js';
|
|
6
|
+
export async function resolveCer(hash, network, signal) {
|
|
7
|
+
const result = parseResponse(cerResponseSchema, await network.json(`/v1/resolve/cer/${encodeURIComponent(hash)}`, signal));
|
|
8
|
+
if ([result.certificateHash, result.identity.certificate_hash, result.proof.certificate_hash,
|
|
9
|
+
result.bundle.certificateHash, result.verification.receipt.certificateHash].some(value => value !== hash) ||
|
|
10
|
+
result.identity.bundle_type !== result.bundle.bundleType) {
|
|
11
|
+
throw new NetworkFailure('HASH_IDENTITY_MISMATCH');
|
|
12
|
+
}
|
|
13
|
+
const envelope = result.verification.verificationEnvelope;
|
|
14
|
+
const embedded = isObject(envelope.bundle) ? envelope.bundle : {};
|
|
15
|
+
const attestation = isObject(envelope.attestation) ? envelope.attestation : {};
|
|
16
|
+
for (const value of [envelope.certificateHash, embedded.certificateHash,
|
|
17
|
+
attestation.certificateHash, result.canonical?.certificate?.hash]) {
|
|
18
|
+
if (value !== undefined && value !== hash)
|
|
19
|
+
throw new NetworkFailure('HASH_IDENTITY_MISMATCH');
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
export async function resolveProject(hash, network, signal) {
|
|
24
|
+
const result = parseResponse(projectResponseSchema, await network.json(`/v1/resolve/project/${encodeURIComponent(hash)}`, signal));
|
|
25
|
+
const integrity = result.bundle && isObject(result.bundle.integrity) ? result.bundle.integrity : null;
|
|
26
|
+
if ([result.projectHash, result.proof.projectHash].some(value => value !== hash) ||
|
|
27
|
+
(result.bundle !== null && integrity?.projectHash !== hash) ||
|
|
28
|
+
(result.nodeReceipt !== null && result.nodeReceipt.projectHash !== hash)) {
|
|
29
|
+
throw new NetworkFailure('HASH_IDENTITY_MISMATCH');
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
const familyTools = {
|
|
34
|
+
'cer.ai.execution.v1': 'nexart_verify_ai_cer', 'cer.ai.execution.v2': 'nexart_verify_ai_cer',
|
|
35
|
+
'cer.consequential.execution.v1': 'nexart_verify_consequential_cer',
|
|
36
|
+
'cer.governed.execution.v1': 'nexart_verify_governed_execution',
|
|
37
|
+
'cer.project.bundle.v1': 'nexart_verify_project_bundle',
|
|
38
|
+
};
|
|
39
|
+
function projectionIncomplete(bundle) {
|
|
40
|
+
if (bundle.bundleType === 'cer.ai.execution.v1' || bundle.bundleType === 'cer.ai.execution.v2') {
|
|
41
|
+
return !isObject(bundle.snapshot) || bundle.snapshot.input === undefined || bundle.snapshot.output === undefined;
|
|
42
|
+
}
|
|
43
|
+
if (bundle.bundleType === 'cer.consequential.execution.v1') {
|
|
44
|
+
return !isObject(bundle.snapshot) || bundle.snapshot.request === undefined || bundle.snapshot.result === undefined;
|
|
45
|
+
}
|
|
46
|
+
return isObject(bundle.embeddedBundles) &&
|
|
47
|
+
Object.values(bundle.embeddedBundles).some(value => isObject(value) && projectionIncomplete(value));
|
|
48
|
+
}
|
|
49
|
+
export async function lookup(project, args, network, signal) {
|
|
50
|
+
const output = {
|
|
51
|
+
contractVersion: '1', lookup: 'rejected', reasonCode: 'INVALID_ARGUMENTS', family: null,
|
|
52
|
+
integrity: 'not_performed', integrityScope: 'returned_bundle', sdk: null, receiptPresent: false,
|
|
53
|
+
nodeSignature: 'not_performed', signerTrust: 'not_established',
|
|
54
|
+
limitations: [
|
|
55
|
+
'Lookup availability is not independent integrity or signature verification.',
|
|
56
|
+
'Private, hidden, deleted and unknown evidence are indistinguishable.',
|
|
57
|
+
'Public projections may omit material needed to verify the original artifact.',
|
|
58
|
+
'No canonical content, receipt, account metadata or raw evidence is disclosed.',
|
|
59
|
+
'Confidential openings, trusted timestamps and completeness are not checked.',
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const limit = checkInput(args);
|
|
63
|
+
if (limit)
|
|
64
|
+
return { ...output, reasonCode: limit };
|
|
65
|
+
const parsed = (project ? lookupProjectInput : lookupCerInput).safeParse(args);
|
|
66
|
+
if (!parsed.success)
|
|
67
|
+
return output;
|
|
68
|
+
const hash = 'projectHash' in parsed.data ? parsed.data.projectHash : parsed.data.certificateHash;
|
|
69
|
+
try {
|
|
70
|
+
const value = await network.run(signal, async (active) => {
|
|
71
|
+
const resolved = project ? await resolveProject(hash, network, active) : await resolveCer(hash, network, active);
|
|
72
|
+
output.lookup = 'found';
|
|
73
|
+
output.receiptPresent = 'nodeReceipt' in resolved ? resolved.nodeReceipt !== null : true;
|
|
74
|
+
const bundle = resolved.bundle;
|
|
75
|
+
if (!bundle)
|
|
76
|
+
return { ...output, reasonCode: 'PUBLIC_PROJECTION_INCOMPLETE' };
|
|
77
|
+
const tool = typeof bundle.bundleType === 'string' && Object.hasOwn(familyTools, bundle.bundleType)
|
|
78
|
+
? familyTools[bundle.bundleType] : undefined;
|
|
79
|
+
if (!tool || (project && tool !== 'nexart_verify_project_bundle') ||
|
|
80
|
+
(!project && tool === 'nexart_verify_project_bundle')) {
|
|
81
|
+
return { ...output, reasonCode: 'UNSUPPORTED_RECORD_FAMILY' };
|
|
82
|
+
}
|
|
83
|
+
const result = verify(tool, { bundle }, active);
|
|
84
|
+
output.family = result.family;
|
|
85
|
+
output.sdk = result.sdk;
|
|
86
|
+
output.reasonCode = result.reasonCode;
|
|
87
|
+
output.integrity = result.artifactIntegrity;
|
|
88
|
+
if (result.artifactIntegrity === 'invalid' &&
|
|
89
|
+
(projectionIncomplete(bundle) || ['SCHEMA_ERROR', 'CANONICALIZATION_ERROR'].includes(result.reasonCode))) {
|
|
90
|
+
output.integrity = 'indeterminate';
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
});
|
|
94
|
+
if (Buffer.byteLength(JSON.stringify(value)) > LIMITS.outputBytes) {
|
|
95
|
+
return { ...output, reasonCode: 'OUTPUT_LIMIT_EXCEEDED', integrity: 'not_performed', sdk: null };
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
const code = safeFailure(error);
|
|
101
|
+
return {
|
|
102
|
+
...output, sdk: null, integrity: 'not_performed', family: null, receiptPresent: false,
|
|
103
|
+
reasonCode: code,
|
|
104
|
+
lookup: code === 'NOT_FOUND_OR_NOT_PUBLIC' ? 'not_found_or_not_public'
|
|
105
|
+
: ['HASH_IDENTITY_MISMATCH', 'INVALID_RESPONSE_CONTRACT', 'REDIRECT_REJECTED'].includes(code)
|
|
106
|
+
? 'rejected' : 'unavailable',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const NODE_ORIGIN: "https://node.nexart.io";
|
|
2
|
+
export declare const NETWORK_LIMITS: Readonly<{
|
|
3
|
+
timeoutMs: 5000;
|
|
4
|
+
responseBytes: 1048576;
|
|
5
|
+
manifestBytes: 65536;
|
|
6
|
+
concurrency: 2;
|
|
7
|
+
queued: 8;
|
|
8
|
+
keys: 32;
|
|
9
|
+
receiptBytes: 16384;
|
|
10
|
+
}>;
|
|
11
|
+
export declare class NetworkFailure extends Error {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
constructor(code: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function safeFailure(error: unknown): string;
|
|
16
|
+
/** Injection is a library/testing dependency, never an MCP argument or environment override. */
|
|
17
|
+
export declare class NodeNetwork {
|
|
18
|
+
private readonly request;
|
|
19
|
+
private readonly timeoutMs;
|
|
20
|
+
private active;
|
|
21
|
+
private waiting;
|
|
22
|
+
constructor(request?: typeof fetch, timeoutMs?: number);
|
|
23
|
+
private acquire;
|
|
24
|
+
run<T>(signal: AbortSignal | undefined, work: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
25
|
+
json(path: string, signal: AbortSignal, manifest?: boolean): Promise<unknown>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { checkInput, LIMITS } from '../limits.js';
|
|
2
|
+
export const NODE_ORIGIN = 'https://node.nexart.io';
|
|
3
|
+
export const NETWORK_LIMITS = Object.freeze({
|
|
4
|
+
timeoutMs: 5_000, responseBytes: 1_048_576, manifestBytes: 65_536,
|
|
5
|
+
concurrency: 2, queued: 8, keys: 32, receiptBytes: 16_384,
|
|
6
|
+
});
|
|
7
|
+
export class NetworkFailure extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code) {
|
|
10
|
+
super(code);
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function safeFailure(error) {
|
|
15
|
+
return error instanceof NetworkFailure ? error.code : 'UPSTREAM_UNAVAILABLE';
|
|
16
|
+
}
|
|
17
|
+
/** Limits lexical depth before JSON.parse; no JSON-RPC line framing here. */
|
|
18
|
+
function parseBoundedJson(text) {
|
|
19
|
+
let quoted = false, escaped = false, depth = 0;
|
|
20
|
+
for (const char of text) {
|
|
21
|
+
if (quoted) {
|
|
22
|
+
if (escaped)
|
|
23
|
+
escaped = false;
|
|
24
|
+
else if (char === '\\')
|
|
25
|
+
escaped = true;
|
|
26
|
+
else if (char === '"')
|
|
27
|
+
quoted = false;
|
|
28
|
+
}
|
|
29
|
+
else if (char === '"')
|
|
30
|
+
quoted = true;
|
|
31
|
+
else if (char === '{' || char === '[') {
|
|
32
|
+
if (++depth > LIMITS.depth)
|
|
33
|
+
throw new NetworkFailure('RESPONSE_TOO_COMPLEX');
|
|
34
|
+
}
|
|
35
|
+
else if (char === '}' || char === ']')
|
|
36
|
+
depth--;
|
|
37
|
+
}
|
|
38
|
+
let value;
|
|
39
|
+
try {
|
|
40
|
+
value = JSON.parse(text);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new NetworkFailure('MALFORMED_RESPONSE');
|
|
44
|
+
}
|
|
45
|
+
if (checkInput(value))
|
|
46
|
+
throw new NetworkFailure('RESPONSE_TOO_COMPLEX');
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
/** Injection is a library/testing dependency, never an MCP argument or environment override. */
|
|
50
|
+
export class NodeNetwork {
|
|
51
|
+
request;
|
|
52
|
+
timeoutMs;
|
|
53
|
+
active = 0;
|
|
54
|
+
waiting = [];
|
|
55
|
+
constructor(request = globalThis.fetch, timeoutMs = NETWORK_LIMITS.timeoutMs) {
|
|
56
|
+
this.request = request;
|
|
57
|
+
this.timeoutMs = timeoutMs;
|
|
58
|
+
}
|
|
59
|
+
async acquire(signal) {
|
|
60
|
+
signal.throwIfAborted();
|
|
61
|
+
if (this.active < NETWORK_LIMITS.concurrency) {
|
|
62
|
+
this.active++;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this.waiting.length >= NETWORK_LIMITS.queued)
|
|
66
|
+
throw new NetworkFailure('NETWORK_BUSY');
|
|
67
|
+
await new Promise((resolve, reject) => {
|
|
68
|
+
const ready = () => { signal.removeEventListener('abort', abort); resolve(); };
|
|
69
|
+
const abort = () => {
|
|
70
|
+
this.waiting = this.waiting.filter(item => item !== ready);
|
|
71
|
+
reject(signal.reason);
|
|
72
|
+
};
|
|
73
|
+
this.waiting.push(ready);
|
|
74
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async run(signal, work) {
|
|
78
|
+
const timer = new AbortController();
|
|
79
|
+
const timeout = setTimeout(() => timer.abort(new NetworkFailure('TIMEOUT')), this.timeoutMs);
|
|
80
|
+
const combined = signal ? AbortSignal.any([signal, timer.signal]) : timer.signal;
|
|
81
|
+
let acquired = false;
|
|
82
|
+
try {
|
|
83
|
+
await this.acquire(combined);
|
|
84
|
+
acquired = true;
|
|
85
|
+
combined.throwIfAborted();
|
|
86
|
+
const value = await work(combined);
|
|
87
|
+
combined.throwIfAborted();
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (signal?.aborted)
|
|
92
|
+
throw new NetworkFailure('CANCELLED');
|
|
93
|
+
if (timer.signal.aborted)
|
|
94
|
+
throw new NetworkFailure('TIMEOUT');
|
|
95
|
+
if (error instanceof NetworkFailure)
|
|
96
|
+
throw error;
|
|
97
|
+
throw new NetworkFailure('UPSTREAM_UNAVAILABLE');
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
if (acquired) {
|
|
102
|
+
const next = this.waiting.shift();
|
|
103
|
+
if (next)
|
|
104
|
+
next();
|
|
105
|
+
else
|
|
106
|
+
this.active--;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async json(path, signal, manifest = false) {
|
|
111
|
+
if (!/^\/v1\/resolve\/(cer|project)\/sha256%3A[0-9a-f]{64}$/.test(path) &&
|
|
112
|
+
path !== '/.well-known/nexart-node.json')
|
|
113
|
+
throw new NetworkFailure('TARGET_REJECTED');
|
|
114
|
+
const response = await this.request(NODE_ORIGIN + path, {
|
|
115
|
+
method: 'GET', redirect: 'manual', credentials: 'omit', cache: 'no-store', signal,
|
|
116
|
+
headers: { Accept: 'application/json', 'Cache-Control': 'no-cache' },
|
|
117
|
+
});
|
|
118
|
+
const fail = async (code) => {
|
|
119
|
+
try {
|
|
120
|
+
await response.body?.cancel();
|
|
121
|
+
}
|
|
122
|
+
catch { /* no diagnostics */ }
|
|
123
|
+
throw new NetworkFailure(code);
|
|
124
|
+
};
|
|
125
|
+
if (response.status >= 300 && response.status < 400) {
|
|
126
|
+
return fail(response.status === 304 ? 'UNEXPECTED_NOT_MODIFIED' : 'REDIRECT_REJECTED');
|
|
127
|
+
}
|
|
128
|
+
if (response.status !== 200 && response.status !== 409) {
|
|
129
|
+
// HTTP errors are classified without reading or echoing untrusted diagnostic bodies.
|
|
130
|
+
if (response.status === 404)
|
|
131
|
+
return fail(manifest ? 'KEY_MANIFEST_UNAVAILABLE' : 'NOT_FOUND_OR_NOT_PUBLIC');
|
|
132
|
+
if (response.status === 429)
|
|
133
|
+
return fail('RATE_LIMITED');
|
|
134
|
+
return fail(response.status >= 500 ? 'UPSTREAM_UNAVAILABLE' : 'UPSTREAM_REQUEST_REJECTED');
|
|
135
|
+
}
|
|
136
|
+
if (!/^application\/json(?:\s*;|$)/i.test(response.headers.get('content-type') ?? '')) {
|
|
137
|
+
return fail('UNEXPECTED_CONTENT_TYPE');
|
|
138
|
+
}
|
|
139
|
+
const cap = response.status === 409 ? 8_192
|
|
140
|
+
: manifest ? NETWORK_LIMITS.manifestBytes : NETWORK_LIMITS.responseBytes;
|
|
141
|
+
const declared = response.headers.get('content-length');
|
|
142
|
+
if (declared && Number(declared) > cap)
|
|
143
|
+
return fail('RESPONSE_TOO_LARGE');
|
|
144
|
+
const reader = response.body?.getReader();
|
|
145
|
+
if (!reader)
|
|
146
|
+
throw new NetworkFailure('MALFORMED_RESPONSE');
|
|
147
|
+
const abort = () => { void reader.cancel().catch(() => { }); };
|
|
148
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
149
|
+
const chunks = [];
|
|
150
|
+
let bytes = 0;
|
|
151
|
+
try {
|
|
152
|
+
while (true) {
|
|
153
|
+
signal.throwIfAborted();
|
|
154
|
+
const { done, value } = await reader.read();
|
|
155
|
+
if (done)
|
|
156
|
+
break;
|
|
157
|
+
bytes += value.byteLength;
|
|
158
|
+
if (bytes > cap)
|
|
159
|
+
throw new NetworkFailure('RESPONSE_TOO_LARGE');
|
|
160
|
+
chunks.push(value);
|
|
161
|
+
}
|
|
162
|
+
signal.throwIfAborted();
|
|
163
|
+
let text;
|
|
164
|
+
try {
|
|
165
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks));
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new NetworkFailure('MALFORMED_RESPONSE');
|
|
169
|
+
}
|
|
170
|
+
const data = parseBoundedJson(text);
|
|
171
|
+
if (response.status === 409) {
|
|
172
|
+
const code = typeof data === 'object' && data !== null && 'code' in data ? data.code : null;
|
|
173
|
+
throw new NetworkFailure(code === 'INCOMPLETE_PROOF' ? 'UPSTREAM_INCOMPLETE_PROOF'
|
|
174
|
+
: code === 'INTEGRITY_MISMATCH' ? 'UPSTREAM_INTEGRITY_MISMATCH' : 'UPSTREAM_PROOF_CONFLICT');
|
|
175
|
+
}
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
signal.removeEventListener('abort', abort);
|
|
180
|
+
try {
|
|
181
|
+
await reader.cancel();
|
|
182
|
+
}
|
|
183
|
+
catch { /* no diagnostics */ }
|
|
184
|
+
reader.releaseLock();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
export declare const hashSchema: z.ZodString;
|
|
3
|
+
export declare const boundedString: z.ZodString;
|
|
4
|
+
export declare const cerResponseSchema: z.ZodObject<{
|
|
5
|
+
artifactType: z.ZodLiteral<"cer">;
|
|
6
|
+
certificateHash: z.ZodString;
|
|
7
|
+
identity: z.ZodObject<{
|
|
8
|
+
certificate_hash: z.ZodString;
|
|
9
|
+
bundle_type: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
proof: z.ZodObject<{
|
|
12
|
+
certificate_hash: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
verification: z.ZodObject<{
|
|
15
|
+
receipt: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
16
|
+
receiptSignature: z.ZodString;
|
|
17
|
+
verificationEnvelope: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
18
|
+
verificationEnvelopeSignature: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
context: z.ZodUnknown;
|
|
21
|
+
bundle: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
22
|
+
canonical: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
certificate: z.ZodOptional<z.ZodObject<{
|
|
24
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
ok: z.ZodLiteral<true>;
|
|
28
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
29
|
+
links: z.ZodObject<{
|
|
30
|
+
self: z.ZodString;
|
|
31
|
+
keyManifest: z.ZodString;
|
|
32
|
+
humanVerifier: z.ZodString;
|
|
33
|
+
verify: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
export declare const projectResponseSchema: z.ZodObject<{
|
|
37
|
+
artifactType: z.ZodLiteral<"project_bundle">;
|
|
38
|
+
projectHash: z.ZodString;
|
|
39
|
+
proof: z.ZodObject<{
|
|
40
|
+
projectHash: z.ZodString;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
bundle: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
43
|
+
nodeReceipt: z.ZodNullable<z.ZodObject<{
|
|
44
|
+
projectHash: z.ZodString;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
ok: z.ZodLiteral<true>;
|
|
47
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
48
|
+
links: z.ZodObject<{
|
|
49
|
+
self: z.ZodString;
|
|
50
|
+
keyManifest: z.ZodString;
|
|
51
|
+
humanVerifier: z.ZodString;
|
|
52
|
+
verify: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export declare const keySchema: z.ZodObject<{
|
|
56
|
+
kid: z.ZodString;
|
|
57
|
+
alg: z.ZodLiteral<"Ed25519">;
|
|
58
|
+
use: z.ZodOptional<z.ZodLiteral<"sig">>;
|
|
59
|
+
publicKeyJwk: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
kty: z.ZodLiteral<"OKP">;
|
|
61
|
+
crv: z.ZodLiteral<"Ed25519">;
|
|
62
|
+
x: z.ZodString;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
65
|
+
publicKeySpkiB64: z.ZodOptional<z.ZodString>;
|
|
66
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
67
|
+
deprecated: "deprecated";
|
|
68
|
+
active: "active";
|
|
69
|
+
revoked: "revoked";
|
|
70
|
+
}>>;
|
|
71
|
+
revoked: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
73
|
+
notAfter: z.ZodOptional<z.ZodString>;
|
|
74
|
+
validFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
|
+
validTo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export declare const manifestSchema: z.ZodObject<{
|
|
78
|
+
nodeId: z.ZodString;
|
|
79
|
+
activeKid: z.ZodOptional<z.ZodString>;
|
|
80
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
81
|
+
kid: z.ZodString;
|
|
82
|
+
alg: z.ZodLiteral<"Ed25519">;
|
|
83
|
+
use: z.ZodOptional<z.ZodLiteral<"sig">>;
|
|
84
|
+
publicKeyJwk: z.ZodOptional<z.ZodObject<{
|
|
85
|
+
kty: z.ZodLiteral<"OKP">;
|
|
86
|
+
crv: z.ZodLiteral<"Ed25519">;
|
|
87
|
+
x: z.ZodString;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
90
|
+
publicKeySpkiB64: z.ZodOptional<z.ZodString>;
|
|
91
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
92
|
+
deprecated: "deprecated";
|
|
93
|
+
active: "active";
|
|
94
|
+
revoked: "revoked";
|
|
95
|
+
}>>;
|
|
96
|
+
revoked: z.ZodOptional<z.ZodBoolean>;
|
|
97
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
98
|
+
notAfter: z.ZodOptional<z.ZodString>;
|
|
99
|
+
validFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
100
|
+
validTo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
export type ManifestKey = z.infer<typeof keySchema>;
|
|
104
|
+
export declare function parseResponse<T>(schema: z.ZodType<T>, value: unknown): T;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { NETWORK_LIMITS, NetworkFailure } from './client.js';
|
|
3
|
+
export const hashSchema = z.string().regex(/^sha256:[0-9a-f]{64}$/);
|
|
4
|
+
export const boundedString = z.string().min(1).max(256);
|
|
5
|
+
const record = z.record(z.string(), z.unknown());
|
|
6
|
+
const signature = z.string().min(1).max(128);
|
|
7
|
+
const link = z.string().max(2_048);
|
|
8
|
+
const common = {
|
|
9
|
+
ok: z.literal(true), schemaVersion: z.literal('1.0'),
|
|
10
|
+
links: z.object({ self: link, keyManifest: link, humanVerifier: link, verify: link.optional() }),
|
|
11
|
+
};
|
|
12
|
+
export const cerResponseSchema = z.object({
|
|
13
|
+
...common, artifactType: z.literal('cer'), certificateHash: hashSchema,
|
|
14
|
+
identity: z.object({ certificate_hash: hashSchema, bundle_type: boundedString }),
|
|
15
|
+
proof: z.object({ certificate_hash: hashSchema }),
|
|
16
|
+
verification: z.object({
|
|
17
|
+
receipt: record, receiptSignature: signature,
|
|
18
|
+
verificationEnvelope: record, verificationEnvelopeSignature: signature,
|
|
19
|
+
}),
|
|
20
|
+
context: z.unknown(), bundle: record,
|
|
21
|
+
canonical: z.object({
|
|
22
|
+
certificate: z.object({ hash: hashSchema.optional() }).optional(),
|
|
23
|
+
}).optional(),
|
|
24
|
+
});
|
|
25
|
+
export const projectResponseSchema = z.object({
|
|
26
|
+
...common, artifactType: z.literal('project_bundle'), projectHash: hashSchema,
|
|
27
|
+
proof: z.object({ projectHash: hashSchema }),
|
|
28
|
+
bundle: record.nullable(),
|
|
29
|
+
nodeReceipt: z.object({ projectHash: hashSchema }).nullable(),
|
|
30
|
+
});
|
|
31
|
+
export const keySchema = z.object({
|
|
32
|
+
kid: boundedString, alg: z.literal('Ed25519'), use: z.literal('sig').optional(),
|
|
33
|
+
publicKeyJwk: z.object({
|
|
34
|
+
kty: z.literal('OKP'), crv: z.literal('Ed25519'),
|
|
35
|
+
x: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
36
|
+
}).optional(),
|
|
37
|
+
publicKey: z.string().max(128).optional(),
|
|
38
|
+
publicKeySpkiB64: z.string().max(256).optional(),
|
|
39
|
+
status: z.enum(['active', 'deprecated', 'revoked']).optional(),
|
|
40
|
+
revoked: z.boolean().optional(),
|
|
41
|
+
notBefore: z.string().max(64).optional(), notAfter: z.string().max(64).optional(),
|
|
42
|
+
validFrom: z.string().max(64).nullable().optional(), validTo: z.string().max(64).nullable().optional(),
|
|
43
|
+
});
|
|
44
|
+
export const manifestSchema = z.object({
|
|
45
|
+
nodeId: boundedString, activeKid: boundedString.optional(),
|
|
46
|
+
keys: z.array(keySchema).max(NETWORK_LIMITS.keys),
|
|
47
|
+
});
|
|
48
|
+
export function parseResponse(schema, value) {
|
|
49
|
+
const parsed = schema.safeParse(value);
|
|
50
|
+
if (!parsed.success)
|
|
51
|
+
throw new NetworkFailure('INVALID_RESPONSE_CONTRACT');
|
|
52
|
+
return parsed.data;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { NodeNetwork } from './network/client.js';
|
|
3
|
+
import { type TrustPolicy } from './trust/policy.js';
|
|
4
|
+
export declare const NETWORK_TOOL_NAMES: readonly ["nexart_lookup_cer", "nexart_lookup_project_bundle", "nexart_verify_node_receipt"];
|
|
5
|
+
export declare function registerNetworkTools(server: McpServer, network?: NodeNetwork, policy?: TrustPolicy): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NodeNetwork } from './network/client.js';
|
|
2
|
+
import { LOOKUP_NAMES, lookupCerInput, lookupProjectInput, lookupOutput } from './lookup/contracts.js';
|
|
3
|
+
import { lookup } from './lookup/verify.js';
|
|
4
|
+
import { RECEIPT_TOOL, receiptInput, receiptOutput } from './receipts/contracts.js';
|
|
5
|
+
import { verifyReceipt } from './receipts/verify.js';
|
|
6
|
+
import { TRUST_POLICY } from './trust/policy.js';
|
|
7
|
+
export const NETWORK_TOOL_NAMES = [...LOOKUP_NAMES, RECEIPT_TOOL];
|
|
8
|
+
export function registerNetworkTools(server, network = new NodeNetwork(), policy = TRUST_POLICY) {
|
|
9
|
+
const description = 'Look up one exact public NexArt hash. Return safe summaries and local returned-bundle integrity, not raw evidence or attestation authenticity.';
|
|
10
|
+
const annotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
|
11
|
+
server.registerTool(LOOKUP_NAMES[0], {
|
|
12
|
+
description, inputSchema: lookupCerInput, outputSchema: lookupOutput, annotations,
|
|
13
|
+
}, async (args, context) => {
|
|
14
|
+
const result = await lookup(false, args, network, context.mcpReq.signal);
|
|
15
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
|
|
16
|
+
});
|
|
17
|
+
server.registerTool(LOOKUP_NAMES[1], {
|
|
18
|
+
description, inputSchema: lookupProjectInput, outputSchema: lookupOutput, annotations,
|
|
19
|
+
}, async (args, context) => {
|
|
20
|
+
const result = await lookup(true, args, network, context.mcpReq.signal);
|
|
21
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
|
|
22
|
+
});
|
|
23
|
+
server.registerTool(RECEIPT_TOOL, {
|
|
24
|
+
description: 'Verify a CER receipt Ed25519 signature with the published SDK. Signature, binding, lifecycle and server-pinned trust are separate; Project receipts are unsupported.',
|
|
25
|
+
inputSchema: receiptInput, outputSchema: receiptOutput,
|
|
26
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
27
|
+
}, async (args, context) => {
|
|
28
|
+
const result = await verifyReceipt(args, network, policy, context.mcpReq.signal);
|
|
29
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=network-tools.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Local filesystem protection, NOT isolation from an agent with this UID.
|
|
2
|
+
* Call only on a genuinely isolated owner host. No MCP registration/import.
|
|
3
|
+
*/
|
|
4
|
+
export declare function ownerDirectory(path: string): string;
|
|
5
|
+
export declare function readOwnerInput(path: string): unknown;
|
|
6
|
+
/** Owner expressly accepts plaintext + openings custody before calling.
|
|
7
|
+
* Fail closed: no CER export until recovery material is durably retained.
|
|
8
|
+
* On failure preserve private partial files for owner recovery, never delete.
|
|
9
|
+
*/
|
|
10
|
+
export declare function prepareOwnerConfidential(raw: unknown): {
|
|
11
|
+
cer: import("@nexart/ai-execution").CerAiExecutionBundleV2;
|
|
12
|
+
openings: import("@nexart/ai-execution").OpeningV2[];
|
|
13
|
+
execution: {
|
|
14
|
+
executionId: string;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
provider: string;
|
|
17
|
+
model: string;
|
|
18
|
+
input: string | Record<string, unknown>;
|
|
19
|
+
output: string | Record<string, unknown>;
|
|
20
|
+
parameters: {
|
|
21
|
+
temperature: number;
|
|
22
|
+
maxTokens: number;
|
|
23
|
+
topP: number | null;
|
|
24
|
+
seed: number | null;
|
|
25
|
+
};
|
|
26
|
+
executionRole: "advisory" | "operative" | "unspecified";
|
|
27
|
+
instruction?: string | undefined;
|
|
28
|
+
instructionKind?: "system" | "derived" | "label" | undefined;
|
|
29
|
+
decisionRefs?: unknown[] | undefined;
|
|
30
|
+
modelEvidence?: Record<string, unknown> | undefined;
|
|
31
|
+
identity?: {
|
|
32
|
+
provider: string;
|
|
33
|
+
sub: string;
|
|
34
|
+
assertionHash: string;
|
|
35
|
+
verified: boolean;
|
|
36
|
+
emailHash?: string | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
toolCalls?: unknown[] | undefined;
|
|
39
|
+
runId?: string | undefined;
|
|
40
|
+
stepId?: string | undefined;
|
|
41
|
+
stepIndex?: number | undefined;
|
|
42
|
+
workflowId?: string | undefined;
|
|
43
|
+
conversationId?: string | undefined;
|
|
44
|
+
prevStepHash?: string | undefined;
|
|
45
|
+
sdkVersion?: string | undefined;
|
|
46
|
+
appId?: string | undefined;
|
|
47
|
+
ext?: Record<string, unknown> | undefined;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare function createOwnerConfidential(raw: unknown, custody: string): {
|
|
51
|
+
certificateHash: string;
|
|
52
|
+
};
|