@nexart/mcp-server 0.0.0-stage → 0.1.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/CONTRIBUTING.md +56 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +14 -0
  5. package/README.md +340 -2
  6. package/SECURITY.md +76 -0
  7. package/THIRD_PARTY_NOTICES.md +111 -0
  8. package/dist/adapters.d.ts +16 -0
  9. package/dist/adapters.js +48 -0
  10. package/dist/approve-public.d.ts +2 -0
  11. package/dist/approve-public.js +65 -0
  12. package/dist/contracts.d.ts +48 -0
  13. package/dist/contracts.js +34 -0
  14. package/dist/create-confidential.d.ts +2 -0
  15. package/dist/create-confidential.js +34 -0
  16. package/dist/instrumentation/openai-worker.d.ts +1 -0
  17. package/dist/instrumentation/openai-worker.js +26 -0
  18. package/dist/instrumentation/openai.d.ts +51 -0
  19. package/dist/instrumentation/openai.js +197 -0
  20. package/dist/limits.d.ts +15 -0
  21. package/dist/limits.js +62 -0
  22. package/dist/lookup/contracts.d.ts +38 -0
  23. package/dist/lookup/contracts.js +22 -0
  24. package/dist/lookup/verify.d.ts +54 -0
  25. package/dist/lookup/verify.js +110 -0
  26. package/dist/network/client.d.ts +26 -0
  27. package/dist/network/client.js +188 -0
  28. package/dist/network/contracts.d.ts +104 -0
  29. package/dist/network/contracts.js +54 -0
  30. package/dist/network-tools.d.ts +5 -0
  31. package/dist/network-tools.js +32 -0
  32. package/dist/owner/create.d.ts +52 -0
  33. package/dist/owner/create.js +117 -0
  34. package/dist/owner/custody.d.ts +33 -0
  35. package/dist/owner/custody.js +200 -0
  36. package/dist/owner/host.d.ts +10 -0
  37. package/dist/owner/host.js +70 -0
  38. package/dist/owner/publisher.d.ts +21 -0
  39. package/dist/owner/publisher.js +27 -0
  40. package/dist/owner/reconcile.d.ts +16 -0
  41. package/dist/owner/reconcile.js +109 -0
  42. package/dist/receipts/contracts.d.ts +72 -0
  43. package/dist/receipts/contracts.js +33 -0
  44. package/dist/receipts/verify.d.ts +4 -0
  45. package/dist/receipts/verify.js +104 -0
  46. package/dist/record/contracts.d.ts +281 -0
  47. package/dist/record/contracts.js +70 -0
  48. package/dist/record/customer.d.ts +40 -0
  49. package/dist/record/customer.js +99 -0
  50. package/dist/record/policy.d.ts +46 -0
  51. package/dist/record/policy.js +67 -0
  52. package/dist/record/publication.d.ts +23 -0
  53. package/dist/record/publication.js +148 -0
  54. package/dist/record/record.d.ts +12 -0
  55. package/dist/record/record.js +93 -0
  56. package/dist/record/state.d.ts +44 -0
  57. package/dist/record/state.js +84 -0
  58. package/dist/record-tools.d.ts +10 -0
  59. package/dist/record-tools.js +85 -0
  60. package/dist/recover-confidential.d.ts +2 -0
  61. package/dist/recover-confidential.js +13 -0
  62. package/dist/results.d.ts +8 -0
  63. package/dist/results.js +83 -0
  64. package/dist/server.d.ts +2 -0
  65. package/dist/server.js +39 -0
  66. package/dist/stdio.d.ts +2 -0
  67. package/dist/stdio.js +104 -0
  68. package/dist/trust/lifecycle.d.ts +13 -0
  69. package/dist/trust/lifecycle.js +42 -0
  70. package/dist/trust/policy.d.ts +14 -0
  71. package/dist/trust/policy.js +6 -0
  72. package/dist/verify.d.ts +3 -0
  73. package/dist/verify.js +56 -0
  74. package/dist/write/approval.d.ts +5 -0
  75. package/dist/write/approval.js +95 -0
  76. package/dist/write/attest.d.ts +14 -0
  77. package/dist/write/attest.js +140 -0
  78. package/dist/write/config.d.ts +11 -0
  79. package/dist/write/config.js +12 -0
  80. package/dist/write/contracts.d.ts +229 -0
  81. package/dist/write/contracts.js +61 -0
  82. package/dist/write/post.d.ts +11 -0
  83. package/dist/write/post.js +105 -0
  84. package/dist/write/profile.d.ts +19 -0
  85. package/dist/write/profile.js +114 -0
  86. package/dist/write/seal.d.ts +3 -0
  87. package/dist/write/seal.js +49 -0
  88. package/dist/write-tools.d.ts +4 -0
  89. package/dist/write-tools.js +36 -0
  90. package/docs/age-version-compatibility.md +46 -0
  91. package/docs/architecture.md +72 -0
  92. package/docs/compatibility.md +163 -0
  93. package/docs/contracts.md +127 -0
  94. package/docs/examples/customer-claude-desktop.json +14 -0
  95. package/docs/examples/customer-consent.json +15 -0
  96. package/docs/examples/customer-custody.json +8 -0
  97. package/docs/examples/customer-policy.json +43 -0
  98. package/docs/licensing-review.md +109 -0
  99. package/docs/milestone-1-validation.md +110 -0
  100. package/docs/milestone-2.md +291 -0
  101. package/docs/milestone-3.2.md +291 -0
  102. package/docs/milestone-3.md +274 -0
  103. package/docs/milestone-4a.md +221 -0
  104. package/docs/milestone-4b1.md +220 -0
  105. package/docs/milestone-4b2.md +260 -0
  106. package/docs/public-default.md +263 -0
  107. package/docs/recording-schema-compatibility.md +46 -0
  108. package/docs/release.md +311 -0
  109. package/docs/security-fixes.md +47 -0
  110. package/docs/security.md +195 -0
  111. package/docs/standalone-acceptance.md +81 -0
  112. package/docs/validation.md +85 -0
  113. package/package.json +51 -4
  114. package/server.json +20 -0
@@ -0,0 +1,197 @@
1
+ import { Worker } from 'node:worker_threads';
2
+ import * as z from 'zod/v4';
3
+ import { createSnapshotV2, sealCerV2, verifyCerV2 } from '@nexart/ai-execution';
4
+ import {} from '@nexart/ai-execution/providers/openaiV2';
5
+ import { recordExecution } from '../record/record.js';
6
+ import {} from '../record/contracts.js';
7
+ import { boundedInput, disclosureEligible, OPENAI_DISCLOSURE } from '../write/profile.js';
8
+ import { preflightEncryptedCustody, retainEncrypted, EncryptedCustodyError } from '../owner/custody.js';
9
+ import { mcpRecordInput } from '../record/contracts.js';
10
+ const paramsSchema = z.strictObject({
11
+ instruction: z.string(), input: z.string(), model: z.string().min(1).max(128).optional(),
12
+ parameters: z.strictObject({
13
+ temperature: z.number().optional(), maxTokens: z.number().int().positive().optional(),
14
+ topP: z.number().nullable().optional(), seed: z.number().nullable().optional(),
15
+ }).optional(),
16
+ executionRole: z.enum(['advisory', 'operative', 'unspecified']).optional(),
17
+ decisionRefs: z.array(z.unknown()).max(16).optional(),
18
+ });
19
+ const inputSchema = z.strictObject({
20
+ params: paramsSchema,
21
+ certification: mcpRecordInput.options[1].shape.certification,
22
+ });
23
+ const LIMIT = 65_536;
24
+ const TIMEOUT = 10_000;
25
+ async function runOnce(params, request) {
26
+ return new Promise((resolve, reject) => {
27
+ const controller = new AbortController();
28
+ const worker = new Worker(new URL('./openai-worker.js', import.meta.url), {
29
+ workerData: params, execArgv: [], stdout: true, stderr: true,
30
+ resourceLimits: { maxOldGenerationSizeMb: 128 },
31
+ });
32
+ // Deliberately discard any worker diagnostics; never copy raw SDK errors.
33
+ worker.stdout.resume();
34
+ worker.stderr.resume();
35
+ let finished = false, requests = 0;
36
+ const finish = (result) => {
37
+ if (finished)
38
+ return;
39
+ finished = true;
40
+ clearTimeout(timer);
41
+ controller.abort();
42
+ void worker.terminate();
43
+ if (result)
44
+ resolve(result);
45
+ else
46
+ reject(Error('PROVIDER_CALL_FAILED_OR_OUTCOME_UNKNOWN'));
47
+ };
48
+ const timer = setTimeout(() => finish(), TIMEOUT);
49
+ worker.on('error', () => finish());
50
+ worker.on('exit', () => { if (!finished)
51
+ finish(); });
52
+ worker.on('message', async (message) => {
53
+ if (finished)
54
+ return;
55
+ if (message.type === 'failed')
56
+ return finish();
57
+ if (message.type === 'result') {
58
+ if (Buffer.byteLength(JSON.stringify(message.result)) > LIMIT * 4)
59
+ return finish();
60
+ return finish(message.result);
61
+ }
62
+ if (message.type !== 'request' || ++requests !== 1 ||
63
+ message.url !== 'https://api.openai.com/v1/chat/completions' ||
64
+ message.init?.method !== 'POST')
65
+ return finish();
66
+ try {
67
+ if (Buffer.byteLength(message.init.body) > LIMIT)
68
+ return finish();
69
+ const response = await request(message.url, {
70
+ ...message.init, redirect: 'error', signal: controller.signal,
71
+ });
72
+ if (finished)
73
+ return;
74
+ if (!response.ok || response.status !== 200 || !response.body ||
75
+ !/^application\/json(?:;|$)/i.test(response.headers.get('content-type') ?? '') ||
76
+ Number(response.headers.get('content-length') ?? 0) > LIMIT) {
77
+ void response.body?.cancel().catch(() => { });
78
+ return finish();
79
+ }
80
+ const reader = response.body.getReader(), chunks = [];
81
+ let size = 0;
82
+ try {
83
+ while (true) {
84
+ const { done, value } = await reader.read();
85
+ if (done)
86
+ break;
87
+ size += value.byteLength;
88
+ if (size > LIMIT || finished) {
89
+ await reader.cancel();
90
+ return finish();
91
+ }
92
+ chunks.push(value);
93
+ }
94
+ }
95
+ finally {
96
+ reader.releaseLock();
97
+ }
98
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks));
99
+ // Reject malformed/deep JSON and unsupported text shapes before SDK parsing.
100
+ let depth = 0, quoted = false, escaped = false;
101
+ for (const c of text) {
102
+ if (quoted) {
103
+ if (escaped)
104
+ escaped = false;
105
+ else if (c === '\\')
106
+ escaped = true;
107
+ else if (c === '"')
108
+ quoted = false;
109
+ }
110
+ else if (c === '"')
111
+ quoted = true;
112
+ else if (c === '{' || c === '[') {
113
+ if (++depth > 32)
114
+ throw Error('DEPTH');
115
+ }
116
+ else if (c === '}' || c === ']')
117
+ depth--;
118
+ }
119
+ const data = JSON.parse(text);
120
+ if (!Array.isArray(data.choices) || data.choices.length !== 1 ||
121
+ typeof data.choices[0]?.message?.content !== 'string' ||
122
+ data.choices[0]?.message?.tool_calls !== undefined ||
123
+ data.choices[0]?.message?.function_call !== undefined ||
124
+ data.choices[0]?.message?.refusal)
125
+ return finish();
126
+ if (!finished)
127
+ worker.postMessage({ type: 'response', body: text, status: 200 });
128
+ }
129
+ catch {
130
+ finish();
131
+ }
132
+ });
133
+ });
134
+ }
135
+ /** Real SDK wrapper, called once. No provider key from model arguments and no
136
+ * ambient Node credential discovery. Plaintext output goes only to its calling app. */
137
+ export async function runOpenAIRecorded(raw, runtime) {
138
+ let state = 'not_started';
139
+ let output = null;
140
+ // Initialize with the same separately reported default intent as orchestration.
141
+ let recording = await recordExecution({ kind: 'cer', bundle: {},
142
+ ...(raw && typeof raw === 'object' && 'certification' in raw ? { certification: raw.certification } : {}),
143
+ }, { captureSource: 'instrumented_provider_call' });
144
+ try {
145
+ if (boundedInput(raw))
146
+ throw Error('INPUT');
147
+ const parsed = inputSchema.parse(raw), p = parsed.params;
148
+ recording = { ...recording, evidence: 'not_created', localIntegrity: 'not_performed', reasonCode: 'PROVIDER_SETUP_REQUIRED' };
149
+ preflightEncryptedCustody(runtime.custody);
150
+ const key = runtime.apiKey();
151
+ if (!key || key.length > 4096 || /[\r\n]/.test(key))
152
+ throw Error('KEY');
153
+ // Validate SDK decision refs before any provider request, without changing a returned CER.
154
+ const probe = createSnapshotV2({
155
+ executionId: 'recording-preflight', provider: 'openai', model: p.model ?? 'gpt-4o',
156
+ input: p.input, output: '', instruction: p.instruction, instructionKind: 'system',
157
+ parameters: { temperature: p.parameters?.temperature ?? 0.7, maxTokens: p.parameters?.maxTokens ?? 1024,
158
+ topP: p.parameters?.topP ?? null, seed: p.parameters?.seed ?? null },
159
+ executionRole: p.executionRole ?? 'unspecified',
160
+ ...(p.decisionRefs ? { decisionRefs: p.decisionRefs } : {}),
161
+ });
162
+ if (!verifyCerV2(sealCerV2(probe)).ok)
163
+ throw Error('SDK_INPUT');
164
+ const params = {
165
+ ...p, apiKey: key, confidentialFields: ['input', 'output', 'instruction'],
166
+ confidentialDecisionRefIndexes: (p.decisionRefs ?? []).map((_, i) => i),
167
+ };
168
+ state = 'failed_or_outcome_unknown';
169
+ const result = await runOnce(params, runtime.request ?? globalThis.fetch);
170
+ state = 'completed';
171
+ output = result.output;
172
+ const bundle = result.bundle;
173
+ const eligible = disclosureEligible(bundle, 'public', OPENAI_DISCLOSURE);
174
+ recording = { ...recording, evidence: 'custody_failed', reasonCode: 'ENCRYPTED_CUSTODY_FAILED' };
175
+ retainEncrypted(bundle, result.snapshot, result.openings, runtime.custody);
176
+ recording = await recordExecution({
177
+ kind: 'cer', bundle, ...(parsed.certification ? { certification: parsed.certification } : {}),
178
+ }, {
179
+ captureSource: 'instrumented_provider_call',
180
+ ...(runtime.publish && eligible ? { publish: runtime.publish } : {}),
181
+ });
182
+ recording = { ...recording, custody: 'encrypted_owner_recipient' };
183
+ if (!eligible && recording.certificationIntent === 'node')
184
+ recording = {
185
+ ...recording, policyAuthorization: 'authorization_denied', reasonCode: 'PROVIDER_DISCLOSURE_PROFILE_REJECTED',
186
+ };
187
+ }
188
+ catch (error) {
189
+ // No raw exception, response body, SDK diagnostics, input or key is returned.
190
+ if (state === 'failed_or_outcome_unknown')
191
+ recording = { ...recording, reasonCode: 'PROVIDER_CALL_FAILED_OR_OUTCOME_UNKNOWN' };
192
+ else if (error instanceof EncryptedCustodyError)
193
+ recording = { ...recording, evidence: 'custody_failed', reasonCode: error.reasonCode };
194
+ }
195
+ return { providerCall: state, output, recording };
196
+ }
197
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1,15 @@
1
+ /** Policy limits, not NexArt protocol limits. Never truncate input evidence. */
2
+ export declare const LIMITS: Readonly<{
3
+ inputBytes: 1048576;
4
+ frameBytes: 1081344;
5
+ depth: 64;
6
+ nodes: 25000;
7
+ objectKeys: 4096;
8
+ arrayItems: 4096;
9
+ projectSteps: 100;
10
+ outputBytes: 262144;
11
+ }>;
12
+ export type LimitCode = 'INPUT_TOO_LARGE' | 'JSON_TOO_DEEP' | 'JSON_TOO_COMPLEX' | 'PROJECT_STEP_LIMIT' | 'NON_JSON_INPUT';
13
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
14
+ /** Iterative traversal avoids recursion and rejects cycles/non-JSON library callers. */
15
+ export declare function checkInput(input: unknown): LimitCode | undefined;
package/dist/limits.js ADDED
@@ -0,0 +1,62 @@
1
+ /** Policy limits, not NexArt protocol limits. Never truncate input evidence. */
2
+ export const LIMITS = Object.freeze({
3
+ inputBytes: 1_048_576,
4
+ frameBytes: 1_081_344,
5
+ depth: 64,
6
+ nodes: 25_000,
7
+ objectKeys: 4_096,
8
+ arrayItems: 4_096,
9
+ projectSteps: 100,
10
+ outputBytes: 262_144,
11
+ });
12
+ export function isObject(value) {
13
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ }
15
+ /** Iterative traversal avoids recursion and rejects cycles/non-JSON library callers. */
16
+ export function checkInput(input) {
17
+ const queue = [{ value: input, depth: 0 }];
18
+ const seen = new WeakSet();
19
+ let count = 0;
20
+ while (queue.length) {
21
+ const { value, depth } = queue.pop();
22
+ if (++count > LIMITS.nodes)
23
+ return 'JSON_TOO_COMPLEX';
24
+ if (depth > LIMITS.depth)
25
+ return 'JSON_TOO_DEEP';
26
+ if (typeof value === 'number' && !Number.isFinite(value))
27
+ return 'NON_JSON_INPUT';
28
+ if (value === null || ['string', 'boolean', 'number'].includes(typeof value))
29
+ continue;
30
+ if (typeof value !== 'object')
31
+ return 'NON_JSON_INPUT';
32
+ if (seen.has(value))
33
+ return 'NON_JSON_INPUT';
34
+ seen.add(value);
35
+ if (Array.isArray(value)) {
36
+ if (value.length > LIMITS.arrayItems)
37
+ return 'JSON_TOO_COMPLEX';
38
+ for (const child of value)
39
+ queue.push({ value: child, depth: depth + 1 });
40
+ }
41
+ else {
42
+ if (Object.getPrototypeOf(value) !== Object.prototype &&
43
+ Object.getPrototypeOf(value) !== null)
44
+ return 'NON_JSON_INPUT';
45
+ const keys = Object.keys(value);
46
+ if (keys.length > LIMITS.objectKeys)
47
+ return 'JSON_TOO_COMPLEX';
48
+ for (const key of keys) {
49
+ const property = Object.getOwnPropertyDescriptor(value, key);
50
+ if (!property || !('value' in property))
51
+ return 'NON_JSON_INPUT';
52
+ queue.push({ value: property.value, depth: depth + 1 });
53
+ }
54
+ }
55
+ if (queue.length + count > LIMITS.nodes)
56
+ return 'JSON_TOO_COMPLEX';
57
+ }
58
+ return Buffer.byteLength(JSON.stringify(input), 'utf8') > LIMITS.inputBytes
59
+ ? 'INPUT_TOO_LARGE'
60
+ : undefined;
61
+ }
62
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1,38 @@
1
+ import * as z from 'zod/v4';
2
+ export declare const LOOKUP_NAMES: readonly ["nexart_lookup_cer", "nexart_lookup_project_bundle"];
3
+ export declare const lookupCerInput: z.ZodObject<{
4
+ certificateHash: z.ZodString;
5
+ }, z.core.$strict>;
6
+ export declare const lookupProjectInput: z.ZodObject<{
7
+ projectHash: z.ZodString;
8
+ }, z.core.$strict>;
9
+ export declare const lookupOutput: z.ZodObject<{
10
+ contractVersion: z.ZodLiteral<"1">;
11
+ lookup: z.ZodEnum<{
12
+ unavailable: "unavailable";
13
+ rejected: "rejected";
14
+ found: "found";
15
+ not_found_or_not_public: "not_found_or_not_public";
16
+ }>;
17
+ reasonCode: z.ZodString;
18
+ family: z.ZodNullable<z.ZodEnum<{
19
+ "cer.ai.execution.v1": "cer.ai.execution.v1";
20
+ "cer.ai.execution.v2": "cer.ai.execution.v2";
21
+ "cer.consequential.execution.v1": "cer.consequential.execution.v1";
22
+ "cer.governed.execution.v1": "cer.governed.execution.v1";
23
+ "cer.project.bundle.v1": "cer.project.bundle.v1";
24
+ }>>;
25
+ integrity: z.ZodEnum<{
26
+ valid: "valid";
27
+ invalid: "invalid";
28
+ not_performed: "not_performed";
29
+ indeterminate: "indeterminate";
30
+ }>;
31
+ integrityScope: z.ZodLiteral<"returned_bundle">;
32
+ sdk: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
+ receiptPresent: z.ZodBoolean;
34
+ nodeSignature: z.ZodLiteral<"not_performed">;
35
+ signerTrust: z.ZodLiteral<"not_established">;
36
+ limitations: z.ZodArray<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ export type LookupOutput = z.infer<typeof lookupOutput>;
@@ -0,0 +1,22 @@
1
+ import * as z from 'zod/v4';
2
+ import { hashSchema } from '../network/contracts.js';
3
+ export const LOOKUP_NAMES = ['nexart_lookup_cer', 'nexart_lookup_project_bundle'];
4
+ export const lookupCerInput = z.strictObject({ certificateHash: hashSchema });
5
+ export const lookupProjectInput = z.strictObject({ projectHash: hashSchema });
6
+ export const lookupOutput = z.strictObject({
7
+ contractVersion: z.literal('1'),
8
+ lookup: z.enum(['found', 'not_found_or_not_public', 'unavailable', 'rejected']),
9
+ reasonCode: z.string().max(96),
10
+ family: z.enum([
11
+ 'cer.ai.execution.v1', 'cer.ai.execution.v2', 'cer.consequential.execution.v1',
12
+ 'cer.governed.execution.v1', 'cer.project.bundle.v1',
13
+ ]).nullable(),
14
+ integrity: z.enum(['valid', 'invalid', 'not_performed', 'indeterminate']),
15
+ integrityScope: z.literal('returned_bundle'),
16
+ sdk: z.record(z.string(), z.unknown()).nullable(),
17
+ receiptPresent: z.boolean(),
18
+ nodeSignature: z.literal('not_performed'),
19
+ signerTrust: z.literal('not_established'),
20
+ limitations: z.array(z.string().max(256)).max(12),
21
+ });
22
+ //# sourceMappingURL=contracts.js.map
@@ -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
+ }