@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.
Files changed (100) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/CONTRIBUTING.md +58 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +14 -0
  5. package/README.md +356 -2
  6. package/SECURITY.md +77 -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 +35 -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/json-schema.d.ts +9 -0
  21. package/dist/json-schema.js +20 -0
  22. package/dist/limits.d.ts +15 -0
  23. package/dist/limits.js +62 -0
  24. package/dist/lookup/contracts.d.ts +38 -0
  25. package/dist/lookup/contracts.js +23 -0
  26. package/dist/lookup/verify.d.ts +54 -0
  27. package/dist/lookup/verify.js +110 -0
  28. package/dist/network/client.d.ts +26 -0
  29. package/dist/network/client.js +188 -0
  30. package/dist/network/contracts.d.ts +104 -0
  31. package/dist/network/contracts.js +54 -0
  32. package/dist/network-tools.d.ts +5 -0
  33. package/dist/network-tools.js +32 -0
  34. package/dist/owner/create.d.ts +52 -0
  35. package/dist/owner/create.js +117 -0
  36. package/dist/owner/custody.d.ts +36 -0
  37. package/dist/owner/custody.js +210 -0
  38. package/dist/owner/host.d.ts +10 -0
  39. package/dist/owner/host.js +70 -0
  40. package/dist/owner/publisher.d.ts +21 -0
  41. package/dist/owner/publisher.js +27 -0
  42. package/dist/owner/reconcile.d.ts +16 -0
  43. package/dist/owner/reconcile.js +109 -0
  44. package/dist/protocol-safety.d.ts +3 -0
  45. package/dist/protocol-safety.js +16 -0
  46. package/dist/receipts/contracts.d.ts +72 -0
  47. package/dist/receipts/contracts.js +34 -0
  48. package/dist/receipts/verify.d.ts +4 -0
  49. package/dist/receipts/verify.js +104 -0
  50. package/dist/record/contracts.d.ts +323 -0
  51. package/dist/record/contracts.js +75 -0
  52. package/dist/record/customer.d.ts +40 -0
  53. package/dist/record/customer.js +99 -0
  54. package/dist/record/policy.d.ts +46 -0
  55. package/dist/record/policy.js +67 -0
  56. package/dist/record/publication.d.ts +23 -0
  57. package/dist/record/publication.js +148 -0
  58. package/dist/record/record.d.ts +15 -0
  59. package/dist/record/record.js +97 -0
  60. package/dist/record/state.d.ts +44 -0
  61. package/dist/record/state.js +84 -0
  62. package/dist/record-tools.d.ts +13 -0
  63. package/dist/record-tools.js +95 -0
  64. package/dist/recover-confidential.d.ts +2 -0
  65. package/dist/recover-confidential.js +13 -0
  66. package/dist/results.d.ts +8 -0
  67. package/dist/results.js +83 -0
  68. package/dist/server.d.ts +12 -0
  69. package/dist/server.js +39 -0
  70. package/dist/stdio.d.ts +2 -0
  71. package/dist/stdio.js +88 -0
  72. package/dist/trust/lifecycle.d.ts +13 -0
  73. package/dist/trust/lifecycle.js +42 -0
  74. package/dist/trust/policy.d.ts +14 -0
  75. package/dist/trust/policy.js +6 -0
  76. package/dist/verify.d.ts +3 -0
  77. package/dist/verify.js +56 -0
  78. package/dist/write/approval.d.ts +5 -0
  79. package/dist/write/approval.js +95 -0
  80. package/dist/write/attest.d.ts +17 -0
  81. package/dist/write/attest.js +141 -0
  82. package/dist/write/config.d.ts +11 -0
  83. package/dist/write/config.js +12 -0
  84. package/dist/write/contracts.d.ts +229 -0
  85. package/dist/write/contracts.js +61 -0
  86. package/dist/write/post.d.ts +11 -0
  87. package/dist/write/post.js +105 -0
  88. package/dist/write/profile.d.ts +19 -0
  89. package/dist/write/profile.js +114 -0
  90. package/dist/write/seal.d.ts +3 -0
  91. package/dist/write/seal.js +49 -0
  92. package/dist/write-tools.d.ts +4 -0
  93. package/dist/write-tools.js +36 -0
  94. package/docs/consumer-guide.md +133 -0
  95. package/docs/examples/customer-claude-desktop.json +14 -0
  96. package/docs/examples/customer-consent.json +15 -0
  97. package/docs/examples/customer-custody.json +8 -0
  98. package/docs/examples/customer-policy.json +43 -0
  99. package/package.json +58 -4
  100. package/server.json +20 -0
@@ -0,0 +1,141 @@
1
+ import * as z from 'zod/v4';
2
+ import { NodeNetwork, safeFailure } from '../network/client.js';
3
+ import { boundedString, hashSchema } from '../network/contracts.js';
4
+ import { receiptSchema } from '../receipts/contracts.js';
5
+ import { verifyReceipt } from '../receipts/verify.js';
6
+ import { TRUST_POLICY } from '../trust/policy.js';
7
+ import { attestInput } from './contracts.js';
8
+ import { boundedInput, validV2, disclosureEligible, LEGACY_DISCLOSURE, WRITE_LIMITS } from './profile.js';
9
+ import { consumeApproval } from './approval.js';
10
+ import { AttestPoster, SubmissionFailure } from './post.js';
11
+ const signature = z.string().regex(/^[A-Za-z0-9_-]{86}$/);
12
+ const responseSchema = z.object({
13
+ ok: z.literal(true), bundleType: z.literal('cer.ai.execution.v2'),
14
+ certificateHash: hashSchema, attestationId: boundedString,
15
+ nodeRuntimeHash: hashSchema, protocolVersion: z.literal('1.3.1'),
16
+ issuedAt: z.string().min(1).max(64), kid: boundedString, attestorKeyId: boundedString,
17
+ visibility: z.enum(['private', 'public']), receipt: receiptSchema,
18
+ signature,
19
+ attestation: z.object({
20
+ attestationId: boundedString, attestedAt: z.string().min(1).max(64),
21
+ certificateHash: hashSchema, bundleType: z.literal('cer.ai.execution.v2'),
22
+ nodeRuntimeHash: hashSchema, protocolVersion: z.literal('1.3.1'),
23
+ }),
24
+ verificationEnvelope: z.object({
25
+ algorithm: z.literal('Ed25519'), canonicalization: z.literal('jcs'),
26
+ envelopeType: z.literal('nexart.verification.envelope.v2'), kid: boundedString,
27
+ attestation: z.object({
28
+ attestationId: boundedString, attestedAt: z.string().min(1).max(64), kid: boundedString,
29
+ nodeRuntimeHash: hashSchema, protocolVersion: z.literal('1.3.1'),
30
+ }),
31
+ }),
32
+ verificationEnvelopeSignature: signature,
33
+ });
34
+ export async function attest(args, config, dependencies = {}, signal) {
35
+ let output = {
36
+ contractVersion: '1', reasonCode: 'INVALID_ARGUMENTS', submission: 'not_sent',
37
+ artifactIntegrity: 'not_performed', confidentialProfile: 'not_performed',
38
+ commitments: 'not_performed', requestedVisibility: null, nodeConfirmedVisibility: null,
39
+ publicationAuthorization: 'not_required', independentVerification: 'not_checked',
40
+ identity: 'absent', certificateHash: null, receipt: null, verificationEnvelopeSignature: 'not_performed',
41
+ limitations: [
42
+ 'Node-reported persistence and visibility are operational assertions, not signed visibility guarantees.',
43
+ 'No openings are submitted; protected plaintext is not verified against commitments.',
44
+ 'Producer identity is declared, not authenticated; Node API-key auth is not producer authentication.',
45
+ 'Signature validity, key lifecycle, signer trust and execution truth are separate.',
46
+ 'Public responses may be cached or copied permanently; later hiding cannot recall them.',
47
+ 'A timeout or invalid response can follow a committed write; never retry automatically.',
48
+ ],
49
+ };
50
+ if (!config.attestEnabled)
51
+ return { ...output, reasonCode: 'WRITE_DISABLED' };
52
+ const limit = boundedInput(args);
53
+ if (limit)
54
+ return { ...output, reasonCode: limit };
55
+ const parsed = attestInput.safeParse(args);
56
+ if (!parsed.success)
57
+ return output;
58
+ const input = parsed.data;
59
+ output.requestedVisibility = input.visibility;
60
+ output.publicationAuthorization = input.visibility === 'public' ? 'denied' : 'not_required';
61
+ if (!validV2(input.bundle))
62
+ return { ...output, reasonCode: 'INVALID_AI_V2_CER', artifactIntegrity: 'invalid' };
63
+ const bundle = input.bundle;
64
+ output.artifactIntegrity = 'valid';
65
+ if (input.certificateHash !== bundle.certificateHash)
66
+ return { ...output, reasonCode: 'CERTIFICATE_HASH_MISMATCH' };
67
+ output.certificateHash = input.certificateHash;
68
+ output.identity = bundle.snapshot.identity ? 'producer_declared_not_authenticated' : 'absent';
69
+ if (!disclosureEligible(bundle, 'private', dependencies.disclosureProfile ?? LEGACY_DISCLOSURE)) {
70
+ return { ...output, reasonCode: 'CONFIDENTIAL_PROFILE_REQUIRED', confidentialProfile: 'ineligible' };
71
+ }
72
+ output.confidentialProfile = 'eligible';
73
+ output.commitments = 'authentic_without_openings';
74
+ if (input.visibility === 'public') {
75
+ if (!config.publicEnabled)
76
+ return { ...output, reasonCode: 'PUBLIC_CERTIFICATION_DISABLED' };
77
+ if (!disclosureEligible(bundle, 'public', dependencies.disclosureProfile ?? LEGACY_DISCLOSURE))
78
+ return { ...output, reasonCode: 'PUBLIC_DISCLOSURE_PROFILE_REJECTED' };
79
+ }
80
+ const key = config.apiKey();
81
+ if (!key || /[\r\n]/.test(key))
82
+ return { ...output, reasonCode: 'NODE_CREDENTIAL_UNAVAILABLE' };
83
+ const body = JSON.stringify(bundle); // Original CER, unchanged; no projection/resealing.
84
+ const network = dependencies.network ?? new NodeNetwork(undefined, WRITE_LIMITS.timeoutMs);
85
+ const poster = dependencies.poster ?? new AttestPoster();
86
+ let started = false;
87
+ let received;
88
+ try {
89
+ output = await network.run(signal, async (active) => {
90
+ active.throwIfAborted();
91
+ if (input.visibility === 'public') {
92
+ if (!(dependencies.consumePublicApproval
93
+ ? dependencies.consumePublicApproval(body, key) : consumeApproval(config, body, key)))
94
+ return { ...output, reasonCode: 'PUBLIC_OWNER_APPROVAL_REQUIRED' };
95
+ output.publicationAuthorization = 'approved';
96
+ }
97
+ active.throwIfAborted();
98
+ started = true;
99
+ const raw = await poster.submit(body, input.visibility, key, active);
100
+ const result = responseSchema.safeParse(raw);
101
+ if (!result.success)
102
+ throw new SubmissionFailure('INVALID_ATTEST_RESPONSE', 'outcome_unknown');
103
+ const data = result.data, r = data.receipt, a = data.attestation, e = data.verificationEnvelope.attestation;
104
+ if (data.certificateHash !== input.certificateHash || r.certificateHash !== input.certificateHash ||
105
+ a.certificateHash !== input.certificateHash ||
106
+ data.visibility !== input.visibility ||
107
+ [r.attestationId, a.attestationId, e.attestationId].some(id => id !== data.attestationId) ||
108
+ [r.nodeRuntimeHash, a.nodeRuntimeHash, e.nodeRuntimeHash].some(hash => hash !== data.nodeRuntimeHash) ||
109
+ [r.attestorKeyId, e.kid, data.attestorKeyId, data.verificationEnvelope.kid].some(kid => kid !== data.kid) ||
110
+ r.protocolVersion !== data.protocolVersion ||
111
+ [r.attestedAt, a.attestedAt, e.attestedAt].some(time => time !== data.issuedAt) ||
112
+ !Number.isFinite(Date.parse(data.issuedAt))) {
113
+ throw new SubmissionFailure('ATTEST_RESPONSE_BINDING_MISMATCH', 'outcome_unknown');
114
+ }
115
+ received = { receipt: r, signature: data.signature };
116
+ return { ...output, submission: 'node_reported_accepted',
117
+ nodeConfirmedVisibility: data.visibility, reasonCode: 'NODE_REPORTED_ACCEPTED',
118
+ independentVerification: data.visibility === 'private'
119
+ ? 'not_public_under_reported_visibility' : 'not_checked',
120
+ receipt: null };
121
+ });
122
+ // Receipt verification uses its own bounded GET operation after the POST
123
+ // slot is released. Never lose reported persistence if this second phase fails.
124
+ if (received) {
125
+ const checked = await verifyReceipt({
126
+ source: 'inline', certificateHash: input.certificateHash,
127
+ receipt: received.receipt, signatureB64Url: received.signature,
128
+ }, network, dependencies.policy ?? TRUST_POLICY, signal);
129
+ output = { ...output, receipt: checked, reasonCode: checked.signature === 'valid'
130
+ && checked.hashBinding === 'match' ? 'NODE_REPORTED_ACCEPTED' : 'ACCEPTED_RECEIPT_NOT_VERIFIED' };
131
+ }
132
+ return output;
133
+ }
134
+ catch (error) {
135
+ if (error instanceof SubmissionFailure)
136
+ return { ...output, reasonCode: error.code, submission: error.outcome };
137
+ return { ...output, reasonCode: started ? 'SUBMISSION_OUTCOME_UNKNOWN' : safeFailure(error),
138
+ submission: started ? 'outcome_unknown' : 'not_sent' };
139
+ }
140
+ }
141
+ //# sourceMappingURL=attest.js.map
@@ -0,0 +1,11 @@
1
+ /** Host configuration is never part of MCP tool arguments. All writes default OFF. */
2
+ export interface WriteConfig {
3
+ sealEnabled: boolean;
4
+ attestEnabled: boolean;
5
+ discloseCer: boolean;
6
+ publicEnabled: boolean;
7
+ approvalDirectory: string | undefined;
8
+ accountContext: string | undefined;
9
+ apiKey: () => string | undefined;
10
+ }
11
+ export declare function writeConfig(env?: NodeJS.ProcessEnv): WriteConfig;
@@ -0,0 +1,12 @@
1
+ export function writeConfig(env = process.env) {
2
+ return Object.freeze({
3
+ sealEnabled: env.NEXART_ENABLE_SEAL === 'true',
4
+ attestEnabled: env.NEXART_ENABLE_ATTEST === 'true',
5
+ discloseCer: env.NEXART_DISCLOSE_CER === 'true',
6
+ publicEnabled: env.NEXART_ENABLE_PUBLIC_ATTEST === 'true',
7
+ approvalDirectory: env.NEXART_PUBLIC_APPROVAL_DIRECTORY,
8
+ accountContext: env.NEXART_NODE_ACCOUNT_CONTEXT,
9
+ apiKey: () => env.NEXART_NODE_API_KEY,
10
+ });
11
+ }
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,229 @@
1
+ import * as z from 'zod/v4';
2
+ export declare const WRITE_TOOL_NAMES: readonly ["nexart_seal_ai_v2", "nexart_attest_cer"];
3
+ export declare const identitySchema: z.ZodObject<{
4
+ provider: z.ZodString;
5
+ sub: z.ZodString;
6
+ assertionHash: z.ZodString;
7
+ emailHash: z.ZodOptional<z.ZodString>;
8
+ verified: z.ZodBoolean;
9
+ }, z.core.$strict>;
10
+ export declare const executionSchema: z.ZodObject<{
11
+ executionId: z.ZodString;
12
+ timestamp: z.ZodString;
13
+ provider: z.ZodString;
14
+ model: z.ZodString;
15
+ input: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
16
+ output: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
17
+ parameters: z.ZodObject<{
18
+ temperature: z.ZodNumber;
19
+ maxTokens: z.ZodNumber;
20
+ topP: z.ZodNullable<z.ZodNumber>;
21
+ seed: z.ZodNullable<z.ZodNumber>;
22
+ }, z.core.$strict>;
23
+ executionRole: z.ZodEnum<{
24
+ advisory: "advisory";
25
+ operative: "operative";
26
+ unspecified: "unspecified";
27
+ }>;
28
+ instruction: z.ZodOptional<z.ZodString>;
29
+ instructionKind: z.ZodOptional<z.ZodEnum<{
30
+ system: "system";
31
+ derived: "derived";
32
+ label: "label";
33
+ }>>;
34
+ decisionRefs: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
35
+ modelEvidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
36
+ identity: z.ZodOptional<z.ZodObject<{
37
+ provider: z.ZodString;
38
+ sub: z.ZodString;
39
+ assertionHash: z.ZodString;
40
+ emailHash: z.ZodOptional<z.ZodString>;
41
+ verified: z.ZodBoolean;
42
+ }, z.core.$strict>>;
43
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
44
+ runId: z.ZodOptional<z.ZodString>;
45
+ stepId: z.ZodOptional<z.ZodString>;
46
+ stepIndex: z.ZodOptional<z.ZodNumber>;
47
+ workflowId: z.ZodOptional<z.ZodString>;
48
+ conversationId: z.ZodOptional<z.ZodString>;
49
+ prevStepHash: z.ZodOptional<z.ZodString>;
50
+ sdkVersion: z.ZodOptional<z.ZodString>;
51
+ appId: z.ZodOptional<z.ZodString>;
52
+ ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ }, z.core.$strict>;
54
+ export declare const sealInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
55
+ mode: z.ZodLiteral<"from_execution">;
56
+ execution: z.ZodObject<{
57
+ executionId: z.ZodString;
58
+ timestamp: z.ZodString;
59
+ provider: z.ZodString;
60
+ model: z.ZodString;
61
+ input: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
62
+ output: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
63
+ parameters: z.ZodObject<{
64
+ temperature: z.ZodNumber;
65
+ maxTokens: z.ZodNumber;
66
+ topP: z.ZodNullable<z.ZodNumber>;
67
+ seed: z.ZodNullable<z.ZodNumber>;
68
+ }, z.core.$strict>;
69
+ executionRole: z.ZodEnum<{
70
+ advisory: "advisory";
71
+ operative: "operative";
72
+ unspecified: "unspecified";
73
+ }>;
74
+ instruction: z.ZodOptional<z.ZodString>;
75
+ instructionKind: z.ZodOptional<z.ZodEnum<{
76
+ system: "system";
77
+ derived: "derived";
78
+ label: "label";
79
+ }>>;
80
+ decisionRefs: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
81
+ modelEvidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
82
+ identity: z.ZodOptional<z.ZodObject<{
83
+ provider: z.ZodString;
84
+ sub: z.ZodString;
85
+ assertionHash: z.ZodString;
86
+ emailHash: z.ZodOptional<z.ZodString>;
87
+ verified: z.ZodBoolean;
88
+ }, z.core.$strict>>;
89
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
90
+ runId: z.ZodOptional<z.ZodString>;
91
+ stepId: z.ZodOptional<z.ZodString>;
92
+ stepIndex: z.ZodOptional<z.ZodNumber>;
93
+ workflowId: z.ZodOptional<z.ZodString>;
94
+ conversationId: z.ZodOptional<z.ZodString>;
95
+ prevStepHash: z.ZodOptional<z.ZodString>;
96
+ sdkVersion: z.ZodOptional<z.ZodString>;
97
+ appId: z.ZodOptional<z.ZodString>;
98
+ ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
99
+ }, z.core.$strict>;
100
+ createdAt: z.ZodString;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ mode: z.ZodLiteral<"from_snapshot">;
103
+ snapshot: z.ZodRecord<z.ZodString, z.ZodUnknown>;
104
+ createdAt: z.ZodString;
105
+ }, z.core.$strict>], "mode">;
106
+ export declare const attestInput: z.ZodObject<{
107
+ certificateHash: z.ZodString;
108
+ bundle: z.ZodRecord<z.ZodString, z.ZodUnknown>;
109
+ visibility: z.ZodDefault<z.ZodEnum<{
110
+ private: "private";
111
+ public: "public";
112
+ }>>;
113
+ }, z.core.$strict>;
114
+ export declare const sealOutput: z.ZodObject<{
115
+ contractVersion: z.ZodLiteral<"1">;
116
+ reasonCode: z.ZodString;
117
+ artifactIntegrity: z.ZodEnum<{
118
+ valid: "valid";
119
+ invalid: "invalid";
120
+ not_performed: "not_performed";
121
+ }>;
122
+ certificateHash: z.ZodNullable<z.ZodString>;
123
+ confidential: z.ZodBoolean;
124
+ identity: z.ZodEnum<{
125
+ absent: "absent";
126
+ producer_declared_not_authenticated: "producer_declared_not_authenticated";
127
+ }>;
128
+ disclosure: z.ZodEnum<{
129
+ not_performed: "not_performed";
130
+ summary_only: "summary_only";
131
+ full_cer: "full_cer";
132
+ }>;
133
+ bundle: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
134
+ limitations: z.ZodArray<z.ZodString>;
135
+ }, z.core.$strict>;
136
+ export declare const attestOutput: z.ZodObject<{
137
+ contractVersion: z.ZodLiteral<"1">;
138
+ reasonCode: z.ZodString;
139
+ submission: z.ZodEnum<{
140
+ rejected: "rejected";
141
+ not_sent: "not_sent";
142
+ node_reported_accepted: "node_reported_accepted";
143
+ outcome_unknown: "outcome_unknown";
144
+ }>;
145
+ artifactIntegrity: z.ZodEnum<{
146
+ valid: "valid";
147
+ invalid: "invalid";
148
+ not_performed: "not_performed";
149
+ }>;
150
+ confidentialProfile: z.ZodEnum<{
151
+ not_performed: "not_performed";
152
+ eligible: "eligible";
153
+ ineligible: "ineligible";
154
+ }>;
155
+ commitments: z.ZodEnum<{
156
+ invalid: "invalid";
157
+ not_performed: "not_performed";
158
+ authentic_without_openings: "authentic_without_openings";
159
+ }>;
160
+ requestedVisibility: z.ZodNullable<z.ZodEnum<{
161
+ private: "private";
162
+ public: "public";
163
+ }>>;
164
+ nodeConfirmedVisibility: z.ZodNullable<z.ZodEnum<{
165
+ private: "private";
166
+ public: "public";
167
+ }>>;
168
+ publicationAuthorization: z.ZodEnum<{
169
+ not_required: "not_required";
170
+ approved: "approved";
171
+ denied: "denied";
172
+ }>;
173
+ independentVerification: z.ZodEnum<{
174
+ not_checked: "not_checked";
175
+ not_public_under_reported_visibility: "not_public_under_reported_visibility";
176
+ }>;
177
+ identity: z.ZodEnum<{
178
+ absent: "absent";
179
+ producer_declared_not_authenticated: "producer_declared_not_authenticated";
180
+ }>;
181
+ certificateHash: z.ZodNullable<z.ZodString>;
182
+ receipt: z.ZodNullable<z.ZodObject<{
183
+ contractVersion: z.ZodLiteral<"1">;
184
+ reasonCode: z.ZodString;
185
+ signature: z.ZodEnum<{
186
+ valid: "valid";
187
+ invalid: "invalid";
188
+ not_performed: "not_performed";
189
+ }>;
190
+ hashBinding: z.ZodEnum<{
191
+ not_performed: "not_performed";
192
+ match: "match";
193
+ mismatch: "mismatch";
194
+ }>;
195
+ nodeIdentity: z.ZodEnum<{
196
+ not_established: "not_established";
197
+ match: "match";
198
+ mismatch: "mismatch";
199
+ }>;
200
+ keyStatus: z.ZodEnum<{
201
+ deprecated: "deprecated";
202
+ unknown: "unknown";
203
+ active: "active";
204
+ revoked: "revoked";
205
+ unavailable: "unavailable";
206
+ }>;
207
+ keyLifecycle: z.ZodEnum<{
208
+ unknown: "unknown";
209
+ valid: "valid";
210
+ invalid: "invalid";
211
+ }>;
212
+ lifecycleCode: z.ZodString;
213
+ signerTrust: z.ZodEnum<{
214
+ not_established: "not_established";
215
+ trusted_under_policy: "trusted_under_policy";
216
+ rejected: "rejected";
217
+ }>;
218
+ artifactIntegrity: z.ZodLiteral<"not_performed">;
219
+ sdk: z.ZodNullable<z.ZodObject<{
220
+ ok: z.ZodBoolean;
221
+ code: z.ZodString;
222
+ }, z.core.$strict>>;
223
+ limitations: z.ZodArray<z.ZodString>;
224
+ }, z.core.$strict>>;
225
+ verificationEnvelopeSignature: z.ZodLiteral<"not_performed">;
226
+ limitations: z.ZodArray<z.ZodString>;
227
+ }, z.core.$strict>;
228
+ export type SealOutput = z.infer<typeof sealOutput>;
229
+ export type AttestOutput = z.infer<typeof attestOutput>;
@@ -0,0 +1,61 @@
1
+ import * as z from 'zod/v4';
2
+ import { hashSchema } from '../network/contracts.js';
3
+ import { receiptOutput } from '../receipts/contracts.js';
4
+ export const WRITE_TOOL_NAMES = ['nexart_seal_ai_v2', 'nexart_attest_cer'];
5
+ const jsonObject = z.record(z.string(), z.unknown());
6
+ const text = z.string().min(1);
7
+ // Mirror the published SDK schema, including boolean false and its prefix-only
8
+ // assertion hash check. An SDK-declared "verified" flag is NOT MCP authentication.
9
+ export const identitySchema = z.strictObject({
10
+ provider: text, sub: text, assertionHash: z.string().startsWith('sha256:'),
11
+ emailHash: z.string().startsWith('sha256:').optional(), verified: z.boolean(),
12
+ });
13
+ export const executionSchema = z.strictObject({
14
+ executionId: text, timestamp: text, provider: text, model: text,
15
+ input: z.union([z.string(), jsonObject]), output: z.union([z.string(), jsonObject]),
16
+ parameters: z.strictObject({
17
+ temperature: z.number(), maxTokens: z.number(),
18
+ topP: z.number().nullable(), seed: z.number().nullable(),
19
+ }),
20
+ executionRole: z.enum(['advisory', 'operative', 'unspecified']),
21
+ instruction: z.string().optional(),
22
+ instructionKind: z.enum(['system', 'derived', 'label']).optional(),
23
+ decisionRefs: z.array(z.unknown()).optional(), modelEvidence: jsonObject.optional(),
24
+ identity: identitySchema.optional(), toolCalls: z.array(z.unknown()).min(1).optional(),
25
+ runId: text.optional(), stepId: text.optional(), stepIndex: z.number().optional(),
26
+ workflowId: text.optional(), conversationId: text.optional(), prevStepHash: text.optional(),
27
+ sdkVersion: text.optional(), appId: text.optional(), ext: jsonObject.optional(),
28
+ });
29
+ export const sealInput = z.discriminatedUnion('mode', [
30
+ z.strictObject({ mode: z.literal('from_execution'), execution: executionSchema, createdAt: text }),
31
+ z.strictObject({ mode: z.literal('from_snapshot'), snapshot: jsonObject, createdAt: text }),
32
+ ]);
33
+ export const attestInput = z.strictObject({
34
+ certificateHash: hashSchema, bundle: jsonObject,
35
+ visibility: z.enum(['private', 'public']).default('public'),
36
+ });
37
+ export const sealOutput = z.strictObject({
38
+ contractVersion: z.literal('1'), reasonCode: z.string().max(96),
39
+ artifactIntegrity: z.enum(['valid', 'invalid', 'not_performed']),
40
+ certificateHash: hashSchema.nullable(), confidential: z.boolean(),
41
+ identity: z.enum(['absent', 'producer_declared_not_authenticated']),
42
+ disclosure: z.enum(['summary_only', 'full_cer', 'not_performed']),
43
+ bundle: jsonObject.nullable(), limitations: z.array(z.string().max(256)).max(12),
44
+ });
45
+ export const attestOutput = z.strictObject({
46
+ contractVersion: z.literal('1'), reasonCode: z.string().max(96),
47
+ submission: z.enum(['not_sent', 'rejected', 'node_reported_accepted', 'outcome_unknown']),
48
+ artifactIntegrity: z.enum(['valid', 'invalid', 'not_performed']),
49
+ confidentialProfile: z.enum(['eligible', 'ineligible', 'not_performed']),
50
+ commitments: z.enum(['authentic_without_openings', 'invalid', 'not_performed']),
51
+ requestedVisibility: z.enum(['private', 'public']).nullable(),
52
+ nodeConfirmedVisibility: z.enum(['private', 'public']).nullable(),
53
+ publicationAuthorization: z.enum(['not_required', 'approved', 'denied']),
54
+ independentVerification: z.enum(['not_checked', 'not_public_under_reported_visibility']),
55
+ identity: z.enum(['absent', 'producer_declared_not_authenticated']),
56
+ certificateHash: hashSchema.nullable(),
57
+ receipt: receiptOutput.nullable(),
58
+ verificationEnvelopeSignature: z.literal('not_performed'),
59
+ limitations: z.array(z.string().max(256)).max(12),
60
+ });
61
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1,11 @@
1
+ import { NetworkFailure } from '../network/client.js';
2
+ export declare class SubmissionFailure extends NetworkFailure {
3
+ readonly outcome: 'rejected' | 'outcome_unknown';
4
+ constructor(code: string, outcome: 'rejected' | 'outcome_unknown');
5
+ }
6
+ /** Dedicated write adapter. Does not expand the existing GET-only network client. */
7
+ export declare class AttestPoster {
8
+ private readonly request;
9
+ constructor(request?: typeof fetch);
10
+ submit(body: string, visibility: 'private' | 'public', key: string, signal: AbortSignal): Promise<unknown>;
11
+ }
@@ -0,0 +1,105 @@
1
+ import { checkInput, LIMITS } from '../limits.js';
2
+ import { NODE_ORIGIN, NetworkFailure } from '../network/client.js';
3
+ import { WRITE_LIMITS } from './profile.js';
4
+ export class SubmissionFailure extends NetworkFailure {
5
+ outcome;
6
+ constructor(code, outcome) {
7
+ super(code);
8
+ this.outcome = outcome;
9
+ }
10
+ }
11
+ /** Dedicated write adapter. Does not expand the existing GET-only network client. */
12
+ export class AttestPoster {
13
+ request;
14
+ constructor(request = globalThis.fetch) {
15
+ this.request = request;
16
+ }
17
+ async submit(body, visibility, key, signal) {
18
+ try {
19
+ const response = await this.request(`${NODE_ORIGIN}/api/attest`, {
20
+ method: 'POST', redirect: 'manual', credentials: 'omit', cache: 'no-store', signal,
21
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json',
22
+ Authorization: `Bearer ${key}`, 'X-NexArt-Visibility': visibility },
23
+ body,
24
+ });
25
+ const cancel = async () => { try {
26
+ await response.body?.cancel();
27
+ }
28
+ catch { /* no diagnostics */ } };
29
+ if (response.status !== 200) {
30
+ await cancel();
31
+ const rejected = {
32
+ 400: 'NODE_REQUEST_REJECTED', 401: 'NODE_AUTH_REJECTED', 403: 'NODE_AUTH_REJECTED',
33
+ 404: 'NODE_RECORD_NOT_ACCESSIBLE', 409: 'NODE_PROOF_OR_VISIBILITY_CONFLICT',
34
+ 413: 'NODE_REQUEST_TOO_LARGE', 422: 'NODE_CONFIDENTIAL_PROFILE_REJECTED', 429: 'NODE_QUOTA_OR_RATE_LIMITED',
35
+ };
36
+ // No error body is consumed, forwarded, or logged. 5xx/redirect outcomes
37
+ // cannot establish that a write did not occur.
38
+ throw new SubmissionFailure(rejected[response.status] ?? 'NODE_SUBMISSION_OUTCOME_UNKNOWN', rejected[response.status] ? 'rejected' : 'outcome_unknown');
39
+ }
40
+ if (!/^application\/json(?:\s*;|$)/i.test(response.headers.get('content-type') ?? '') ||
41
+ Number(response.headers.get('content-length') ?? 0) > WRITE_LIMITS.responseBytes) {
42
+ await cancel();
43
+ throw new SubmissionFailure('INVALID_ATTEST_RESPONSE', 'outcome_unknown');
44
+ }
45
+ const reader = response.body?.getReader();
46
+ if (!reader)
47
+ throw new SubmissionFailure('INVALID_ATTEST_RESPONSE', 'outcome_unknown');
48
+ const chunks = [];
49
+ let size = 0;
50
+ const abort = () => { void reader.cancel().catch(() => { }); };
51
+ signal.addEventListener('abort', abort, { once: true });
52
+ try {
53
+ while (true) {
54
+ signal.throwIfAborted();
55
+ const item = await reader.read();
56
+ if (item.done)
57
+ break;
58
+ size += item.value.byteLength;
59
+ if (size > WRITE_LIMITS.responseBytes)
60
+ throw Error('LIMIT');
61
+ chunks.push(item.value);
62
+ }
63
+ signal.throwIfAborted();
64
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks));
65
+ let depth = 0, quoted = false, escaped = false;
66
+ for (const c of text) {
67
+ if (quoted) {
68
+ if (escaped)
69
+ escaped = false;
70
+ else if (c === '\\')
71
+ escaped = true;
72
+ else if (c === '"')
73
+ quoted = false;
74
+ }
75
+ else if (c === '"')
76
+ quoted = true;
77
+ else if (c === '[' || c === '{') {
78
+ if (++depth > LIMITS.depth)
79
+ throw Error('LIMIT');
80
+ }
81
+ else if (c === ']' || c === '}')
82
+ depth--;
83
+ }
84
+ const data = JSON.parse(text);
85
+ if (checkInput(data))
86
+ throw Error('LIMIT');
87
+ return data;
88
+ }
89
+ finally {
90
+ signal.removeEventListener('abort', abort);
91
+ try {
92
+ await reader.cancel();
93
+ }
94
+ catch { /* no diagnostics */ }
95
+ reader.releaseLock();
96
+ }
97
+ }
98
+ catch (error) {
99
+ if (error instanceof SubmissionFailure)
100
+ throw error;
101
+ throw new SubmissionFailure(signal.aborted ? 'SUBMISSION_INTERRUPTED' : 'INVALID_OR_UNAVAILABLE_ATTEST_RESPONSE', 'outcome_unknown');
102
+ }
103
+ }
104
+ }
105
+ //# sourceMappingURL=post.js.map
@@ -0,0 +1,19 @@
1
+ import { type CerAiExecutionBundleV2 } from '@nexart/ai-execution';
2
+ export declare const WRITE_LIMITS: Readonly<{
3
+ inputBytes: 65536;
4
+ responseBytes: 65536;
5
+ timeoutMs: 10000;
6
+ }>;
7
+ export declare const PUBLIC_PROFILE = "nexart.mcp.ai-v2.public-disclosure.v1";
8
+ export declare const LEGACY_DISCLOSURE = "ai-v2-resolver-reviewed-2026-11";
9
+ export declare const OPENAI_DISCLOSURE = "ai-v2-openai-disclosure-v1";
10
+ export type DisclosureProfile = typeof LEGACY_DISCLOSURE | typeof OPENAI_DISCLOSURE;
11
+ export declare function boundedInput(value: unknown): string | undefined;
12
+ export declare function validV2(value: unknown): value is CerAiExecutionBundleV2;
13
+ export declare function confidentialProfile(bundle: CerAiExecutionBundleV2): boolean;
14
+ /** Every accepted readable value is disclosed, including identity and IO hashes.
15
+ * No arbitrary metadata/extension/tool/context bags. Owner approval remains mandatory.
16
+ */
17
+ export declare function publicProfile(bundle: CerAiExecutionBundleV2): boolean;
18
+ /** Additive profile. No rewriting/deleting fields and no wildcard metadata. */
19
+ export declare function disclosureEligible(bundle: CerAiExecutionBundleV2, visibility: 'public' | 'private', profile?: DisclosureProfile): boolean;