@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,104 @@
1
+ import { selectNodeKey, verifyNodeReceiptSignature, } from '@nexart/ai-execution';
2
+ import { checkInput, isObject } from '../limits.js';
3
+ import { NETWORK_LIMITS, NodeNetwork, safeFailure } from '../network/client.js';
4
+ import { manifestSchema, parseResponse } from '../network/contracts.js';
5
+ import { resolveCer } from '../lookup/verify.js';
6
+ import { TRUST_POLICY } from '../trust/policy.js';
7
+ import { lifecycle } from '../trust/lifecycle.js';
8
+ import { receiptInput, receiptSchema } from './contracts.js';
9
+ export async function verifyReceipt(args, network, policy = TRUST_POLICY, signal) {
10
+ const output = {
11
+ contractVersion: '1', reasonCode: 'INVALID_ARGUMENTS', signature: 'not_performed',
12
+ hashBinding: 'not_performed', nodeIdentity: 'not_established', keyStatus: 'unavailable',
13
+ keyLifecycle: 'unknown', lifecycleCode: 'NOT_PERFORMED', signerTrust: 'not_established',
14
+ artifactIntegrity: 'not_performed', sdk: null,
15
+ limitations: [
16
+ 'Signature validity does not establish signer trust, artifact integrity or execution truth.',
17
+ 'No approved production key pins or historical exceptions are supplied by default.',
18
+ 'Node-issued receipt time is not independently trusted time or RFC 3161 verification.',
19
+ 'A current key manifest is not an authenticated historical key archive.',
20
+ ],
21
+ };
22
+ const limit = checkInput(args);
23
+ if (limit)
24
+ return { ...output, reasonCode: limit };
25
+ if (Buffer.byteLength(JSON.stringify(args)) > NETWORK_LIMITS.receiptBytes) {
26
+ return { ...output, reasonCode: 'INPUT_TOO_LARGE' };
27
+ }
28
+ const parsed = receiptInput.safeParse(args);
29
+ if (!parsed.success)
30
+ return output;
31
+ const input = parsed.data;
32
+ if ((input.source === 'inline' && (!input.receipt || !input.signatureB64Url)) ||
33
+ (input.source === 'public_lookup' && (Object.hasOwn(input, 'receipt') || Object.hasOwn(input, 'signatureB64Url')))) {
34
+ return output;
35
+ }
36
+ try {
37
+ return await network.run(signal, async (active) => {
38
+ let candidate = input.receipt, signature = input.signatureB64Url;
39
+ if (input.source === 'public_lookup') {
40
+ const resolved = await resolveCer(input.certificateHash, network, active);
41
+ candidate = resolved.verification.receipt;
42
+ signature = resolved.verification.receiptSignature;
43
+ }
44
+ if (isObject(candidate) && candidate.receiptVersion !== 'attestation.receipt.v1') {
45
+ return { ...output, reasonCode: 'UNSUPPORTED_RECEIPT_VERSION' };
46
+ }
47
+ const parsedReceipt = receiptSchema.safeParse(candidate);
48
+ if (!parsedReceipt.success || !signature)
49
+ return { ...output, reasonCode: 'INVALID_RECEIPT' };
50
+ // Strict validation accepts every current signed field; pass the complete original object.
51
+ const receipt = parsedReceipt.data;
52
+ output.hashBinding = receipt.certificateHash === input.certificateHash ? 'match' : 'mismatch';
53
+ output.nodeIdentity = receipt.nodeId === policy.expectedNodeId ? 'match' : 'mismatch';
54
+ const manifest = parseResponse(manifestSchema, await network.json('/.well-known/nexart-node.json', active, true));
55
+ if (manifest.nodeId !== policy.expectedNodeId) {
56
+ return { ...output, signerTrust: 'rejected', reasonCode: 'MANIFEST_NODE_ID_MISMATCH' };
57
+ }
58
+ const kids = manifest.keys.map(key => key.kid);
59
+ if (new Set(kids).size !== kids.length)
60
+ return { ...output, reasonCode: 'AMBIGUOUS_KEY_ID' };
61
+ const selected = selectNodeKey(manifest, receipt.attestorKeyId);
62
+ if (selected.error)
63
+ return { ...output, keyStatus: 'unknown', reasonCode: selected.error.code };
64
+ const key = selected.key;
65
+ const entry = manifest.keys.find(item => item.kid === receipt.attestorKeyId);
66
+ output.keyStatus = entry.revoked ? 'revoked' : entry.status ?? 'unknown';
67
+ const publicKey = entry.publicKeyJwk?.x ?? entry.publicKey;
68
+ const matchingPins = policy.pins.filter(pin => pin.kid === receipt.attestorKeyId);
69
+ const pin = matchingPins.length === 1 && matchingPins[0].publicKeyB64Url === publicKey
70
+ ? matchingPins[0] : undefined;
71
+ const sig = await verifyNodeReceiptSignature({
72
+ receipt: candidate, signatureB64Url: signature,
73
+ key: key.publicKeyJwk ? { jwk: key.publicKeyJwk }
74
+ : key.publicKey ? { rawB64Url: key.publicKey }
75
+ : key.publicKeySpkiB64 ? { spkiB64: key.publicKeySpkiB64 } : {},
76
+ });
77
+ active.throwIfAborted();
78
+ output.sdk = { ok: sig.ok, code: sig.code };
79
+ output.signature = sig.ok ? 'valid' : 'invalid';
80
+ const life = lifecycle(entry, receipt.attestedAt, pin);
81
+ output.keyLifecycle = life.state;
82
+ output.lifecycleCode = life.code;
83
+ if (!sig.ok)
84
+ return { ...output, reasonCode: sig.code, signerTrust: 'rejected' };
85
+ if (output.hashBinding !== 'match')
86
+ return { ...output, reasonCode: 'CERTIFICATE_HASH_MISMATCH', signerTrust: 'rejected' };
87
+ if (output.nodeIdentity !== 'match')
88
+ return { ...output, reasonCode: 'NODE_ID_MISMATCH', signerTrust: 'rejected' };
89
+ if (life.state === 'invalid')
90
+ return { ...output, reasonCode: life.code, signerTrust: 'rejected' };
91
+ if (matchingPins.length > 1)
92
+ return { ...output, reasonCode: 'AMBIGUOUS_TRUST_PIN' };
93
+ if (!pin)
94
+ return { ...output, reasonCode: matchingPins.length ? 'PIN_MISMATCH' : 'UNAPPROVED_KEY' };
95
+ if (life.state !== 'valid')
96
+ return { ...output, reasonCode: life.code };
97
+ return { ...output, reasonCode: 'OK', signerTrust: 'trusted_under_policy' };
98
+ });
99
+ }
100
+ catch (error) {
101
+ return { ...output, reasonCode: safeFailure(error), signerTrust: 'not_established' };
102
+ }
103
+ }
104
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1,281 @@
1
+ import * as z from 'zod/v4';
2
+ export declare const recordInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ kind: z.ZodLiteral<"execution">;
4
+ execution: z.ZodRecord<z.ZodString, z.ZodUnknown>;
5
+ createdAt: z.ZodString;
6
+ certification: z.ZodOptional<z.ZodObject<{
7
+ mode: z.ZodDefault<z.ZodEnum<{
8
+ local: "local";
9
+ node: "node";
10
+ }>>;
11
+ visibility: z.ZodOptional<z.ZodEnum<{
12
+ private: "private";
13
+ public: "public";
14
+ }>>;
15
+ }, z.core.$strict>>;
16
+ }, z.core.$strict>, z.ZodObject<{
17
+ kind: z.ZodLiteral<"cer">;
18
+ bundle: z.ZodRecord<z.ZodString, z.ZodUnknown>;
19
+ certification: z.ZodOptional<z.ZodObject<{
20
+ mode: z.ZodDefault<z.ZodEnum<{
21
+ local: "local";
22
+ node: "node";
23
+ }>>;
24
+ visibility: z.ZodOptional<z.ZodEnum<{
25
+ private: "private";
26
+ public: "public";
27
+ }>>;
28
+ }, z.core.$strict>>;
29
+ }, z.core.$strict>], "kind">;
30
+ /** Strict public contract; the existing library's validation behavior is retained. */
31
+ export declare const mcpRecordInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
32
+ kind: z.ZodLiteral<"execution">;
33
+ execution: z.ZodObject<{
34
+ executionId: z.ZodString;
35
+ timestamp: z.ZodString;
36
+ provider: z.ZodString;
37
+ model: z.ZodString;
38
+ input: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
39
+ output: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
40
+ parameters: z.ZodObject<{
41
+ temperature: z.ZodNumber;
42
+ maxTokens: z.ZodNumber;
43
+ topP: z.ZodNullable<z.ZodNumber>;
44
+ seed: z.ZodNullable<z.ZodNumber>;
45
+ }, z.core.$strict>;
46
+ executionRole: z.ZodEnum<{
47
+ advisory: "advisory";
48
+ operative: "operative";
49
+ unspecified: "unspecified";
50
+ }>;
51
+ instruction: z.ZodOptional<z.ZodString>;
52
+ instructionKind: z.ZodOptional<z.ZodEnum<{
53
+ system: "system";
54
+ derived: "derived";
55
+ label: "label";
56
+ }>>;
57
+ decisionRefs: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
58
+ modelEvidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
59
+ identity: z.ZodOptional<z.ZodObject<{
60
+ provider: z.ZodString;
61
+ sub: z.ZodString;
62
+ assertionHash: z.ZodString;
63
+ emailHash: z.ZodOptional<z.ZodString>;
64
+ verified: z.ZodBoolean;
65
+ }, z.core.$strict>>;
66
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
67
+ runId: z.ZodOptional<z.ZodString>;
68
+ stepId: z.ZodOptional<z.ZodString>;
69
+ stepIndex: z.ZodOptional<z.ZodNumber>;
70
+ workflowId: z.ZodOptional<z.ZodString>;
71
+ conversationId: z.ZodOptional<z.ZodString>;
72
+ prevStepHash: z.ZodOptional<z.ZodString>;
73
+ sdkVersion: z.ZodOptional<z.ZodString>;
74
+ appId: z.ZodOptional<z.ZodString>;
75
+ ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
76
+ }, z.core.$strict>;
77
+ createdAt: z.ZodString;
78
+ certification: z.ZodOptional<z.ZodObject<{
79
+ mode: z.ZodDefault<z.ZodEnum<{
80
+ local: "local";
81
+ node: "node";
82
+ }>>;
83
+ visibility: z.ZodOptional<z.ZodEnum<{
84
+ private: "private";
85
+ public: "public";
86
+ }>>;
87
+ }, z.core.$strict>>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ kind: z.ZodLiteral<"cer">;
90
+ bundle: z.ZodObject<{
91
+ bundleType: z.ZodLiteral<"cer.ai.execution.v2">;
92
+ version: z.ZodString;
93
+ createdAt: z.ZodString;
94
+ certificateHash: z.ZodString;
95
+ snapshot: z.ZodRecord<z.ZodString, z.ZodUnknown>;
96
+ protectedSet: z.ZodRecord<z.ZodString, z.ZodUnknown>;
97
+ }, z.core.$strict>;
98
+ certification: z.ZodOptional<z.ZodObject<{
99
+ mode: z.ZodDefault<z.ZodEnum<{
100
+ local: "local";
101
+ node: "node";
102
+ }>>;
103
+ visibility: z.ZodOptional<z.ZodEnum<{
104
+ private: "private";
105
+ public: "public";
106
+ }>>;
107
+ }, z.core.$strict>>;
108
+ }, z.core.$strict>], "kind">;
109
+ /** Discovery only: some hosts discard root unions. Branch requirements remain
110
+ * authoritative in mcpRecordInput, explicitly parsed by the handler.
111
+ * Standard patterns preserve prefix-only identity semantics without Zod's
112
+ * nonstandard starts_with format. Runtime identity validation is unchanged. */
113
+ export declare const recordDiscoveryInput: z.ZodObject<{
114
+ kind: z.ZodEnum<{
115
+ cer: "cer";
116
+ execution: "execution";
117
+ }>;
118
+ execution: z.ZodOptional<z.ZodObject<{
119
+ executionId: z.ZodString;
120
+ timestamp: z.ZodString;
121
+ provider: z.ZodString;
122
+ model: z.ZodString;
123
+ input: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
124
+ output: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
125
+ parameters: z.ZodObject<{
126
+ temperature: z.ZodNumber;
127
+ maxTokens: z.ZodNumber;
128
+ topP: z.ZodNullable<z.ZodNumber>;
129
+ seed: z.ZodNullable<z.ZodNumber>;
130
+ }, z.core.$strict>;
131
+ executionRole: z.ZodEnum<{
132
+ advisory: "advisory";
133
+ operative: "operative";
134
+ unspecified: "unspecified";
135
+ }>;
136
+ instruction: z.ZodOptional<z.ZodString>;
137
+ instructionKind: z.ZodOptional<z.ZodEnum<{
138
+ system: "system";
139
+ derived: "derived";
140
+ label: "label";
141
+ }>>;
142
+ decisionRefs: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
143
+ modelEvidence: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
144
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
145
+ runId: z.ZodOptional<z.ZodString>;
146
+ stepId: z.ZodOptional<z.ZodString>;
147
+ stepIndex: z.ZodOptional<z.ZodNumber>;
148
+ workflowId: z.ZodOptional<z.ZodString>;
149
+ conversationId: z.ZodOptional<z.ZodString>;
150
+ prevStepHash: z.ZodOptional<z.ZodString>;
151
+ sdkVersion: z.ZodOptional<z.ZodString>;
152
+ appId: z.ZodOptional<z.ZodString>;
153
+ ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
154
+ identity: z.ZodOptional<z.ZodObject<{
155
+ provider: z.ZodString;
156
+ sub: z.ZodString;
157
+ verified: z.ZodBoolean;
158
+ assertionHash: z.ZodString;
159
+ emailHash: z.ZodOptional<z.ZodString>;
160
+ }, z.core.$strict>>;
161
+ }, z.core.$strict>>;
162
+ bundle: z.ZodOptional<z.ZodObject<{
163
+ bundleType: z.ZodLiteral<"cer.ai.execution.v2">;
164
+ version: z.ZodString;
165
+ createdAt: z.ZodString;
166
+ certificateHash: z.ZodString;
167
+ snapshot: z.ZodRecord<z.ZodString, z.ZodUnknown>;
168
+ protectedSet: z.ZodRecord<z.ZodString, z.ZodUnknown>;
169
+ }, z.core.$strict>>;
170
+ createdAt: z.ZodOptional<z.ZodString>;
171
+ certification: z.ZodOptional<z.ZodObject<{
172
+ mode: z.ZodDefault<z.ZodEnum<{
173
+ local: "local";
174
+ node: "node";
175
+ }>>;
176
+ visibility: z.ZodOptional<z.ZodEnum<{
177
+ private: "private";
178
+ public: "public";
179
+ }>>;
180
+ }, z.core.$strict>>;
181
+ }, z.core.$strict>;
182
+ export type CaptureSource = 'producer_supplied' | 'instrumented_provider_call';
183
+ export interface RecordResult {
184
+ contractVersion: '1';
185
+ captureProvenance: CaptureSource;
186
+ evidence: 'not_created' | 'created_confidential' | 'existing_unchanged' | 'custody_failed' | 'invalid';
187
+ custody: 'not_performed' | 'unencrypted_owner_approved' | 'encrypted_owner_recipient' | 'external_existing_cer';
188
+ localIntegrity: 'valid' | 'invalid' | 'not_performed';
189
+ certificationIntent: 'node' | 'local';
190
+ policyAuthorization: 'not_required' | 'setup_required' | 'authorization_denied' | 'policy_authorized';
191
+ submission: 'not_sent' | 'rejected' | 'node_reported_accepted' | 'outcome_unknown';
192
+ requestedVisibility: 'public' | 'private' | null;
193
+ nodeConfirmedVisibility: 'public' | 'private' | null;
194
+ certificateHash: string | null;
195
+ receiptSignature: string;
196
+ hashBinding: string;
197
+ signerTrust: string;
198
+ reasonCode: string;
199
+ usage: {
200
+ authoritative: false;
201
+ accountRemaining: null;
202
+ scope: 'publisher_local';
203
+ reservedAttempts: number | null;
204
+ };
205
+ }
206
+ export declare const recordOutput: z.ZodObject<{
207
+ contractVersion: z.ZodLiteral<"1">;
208
+ captureProvenance: z.ZodEnum<{
209
+ producer_supplied: "producer_supplied";
210
+ instrumented_provider_call: "instrumented_provider_call";
211
+ }>;
212
+ evidence: z.ZodEnum<{
213
+ invalid: "invalid";
214
+ not_created: "not_created";
215
+ created_confidential: "created_confidential";
216
+ existing_unchanged: "existing_unchanged";
217
+ custody_failed: "custody_failed";
218
+ }>;
219
+ custody: z.ZodEnum<{
220
+ not_performed: "not_performed";
221
+ encrypted_owner_recipient: "encrypted_owner_recipient";
222
+ unencrypted_owner_approved: "unencrypted_owner_approved";
223
+ external_existing_cer: "external_existing_cer";
224
+ }>;
225
+ localIntegrity: z.ZodEnum<{
226
+ valid: "valid";
227
+ invalid: "invalid";
228
+ not_performed: "not_performed";
229
+ }>;
230
+ certificationIntent: z.ZodEnum<{
231
+ local: "local";
232
+ node: "node";
233
+ }>;
234
+ policyAuthorization: z.ZodEnum<{
235
+ not_required: "not_required";
236
+ setup_required: "setup_required";
237
+ authorization_denied: "authorization_denied";
238
+ policy_authorized: "policy_authorized";
239
+ }>;
240
+ submission: z.ZodEnum<{
241
+ rejected: "rejected";
242
+ not_sent: "not_sent";
243
+ node_reported_accepted: "node_reported_accepted";
244
+ outcome_unknown: "outcome_unknown";
245
+ }>;
246
+ requestedVisibility: z.ZodNullable<z.ZodEnum<{
247
+ private: "private";
248
+ public: "public";
249
+ }>>;
250
+ nodeConfirmedVisibility: z.ZodNullable<z.ZodEnum<{
251
+ private: "private";
252
+ public: "public";
253
+ }>>;
254
+ certificateHash: z.ZodNullable<z.ZodString>;
255
+ receiptSignature: z.ZodString;
256
+ hashBinding: z.ZodString;
257
+ signerTrust: z.ZodString;
258
+ reasonCode: z.ZodString;
259
+ usage: z.ZodObject<{
260
+ authoritative: z.ZodLiteral<false>;
261
+ accountRemaining: z.ZodNull;
262
+ scope: z.ZodLiteral<"publisher_local">;
263
+ reservedAttempts: z.ZodNullable<z.ZodNumber>;
264
+ }, z.core.$strict>;
265
+ }, z.core.$strict>;
266
+ export interface PreparedRecord {
267
+ body: string;
268
+ certificateHash: string;
269
+ visibility: 'public' | 'private';
270
+ captureSource: CaptureSource;
271
+ }
272
+ export interface PublicationResult {
273
+ authorization: 'setup_required' | 'authorization_denied' | 'policy_authorized';
274
+ submission: RecordResult['submission'];
275
+ nodeConfirmedVisibility: RecordResult['nodeConfirmedVisibility'];
276
+ reasonCode: string;
277
+ receiptSignature: string;
278
+ hashBinding: string;
279
+ signerTrust: string;
280
+ reservedAttempts: number | null;
281
+ }
@@ -0,0 +1,70 @@
1
+ import * as z from 'zod/v4';
2
+ import { executionSchema, identitySchema } from '../write/contracts.js';
3
+ import { hashSchema } from '../network/contracts.js';
4
+ const certification = z.strictObject({
5
+ mode: z.enum(['node', 'local']).default('node'),
6
+ visibility: z.enum(['public', 'private']).optional(),
7
+ }).superRefine((v, ctx) => {
8
+ if (v.mode === 'local' && v.visibility !== undefined)
9
+ ctx.addIssue({ code: 'custom', message: 'Local mode has no Node visibility' });
10
+ });
11
+ export const recordInput = z.discriminatedUnion('kind', [
12
+ z.strictObject({
13
+ kind: z.literal('execution'), execution: z.record(z.string(), z.unknown()),
14
+ createdAt: z.string().min(1), certification: certification.optional(),
15
+ }),
16
+ z.strictObject({
17
+ kind: z.literal('cer'), bundle: z.record(z.string(), z.unknown()),
18
+ certification: certification.optional(),
19
+ }),
20
+ ]);
21
+ /** Strict public contract; the existing library's validation behavior is retained. */
22
+ export const mcpRecordInput = z.discriminatedUnion('kind', [
23
+ z.strictObject({
24
+ kind: z.literal('execution'), execution: executionSchema,
25
+ createdAt: z.string().min(1), certification: certification.optional(),
26
+ }),
27
+ z.strictObject({
28
+ kind: z.literal('cer'), bundle: z.strictObject({
29
+ bundleType: z.literal('cer.ai.execution.v2'), version: z.string(),
30
+ createdAt: z.string(), certificateHash: hashSchema,
31
+ snapshot: z.record(z.string(), z.unknown()), protectedSet: z.record(z.string(), z.unknown()),
32
+ }),
33
+ certification: certification.optional(),
34
+ }),
35
+ ]);
36
+ /** Discovery only: some hosts discard root unions. Branch requirements remain
37
+ * authoritative in mcpRecordInput, explicitly parsed by the handler.
38
+ * Standard patterns preserve prefix-only identity semantics without Zod's
39
+ * nonstandard starts_with format. Runtime identity validation is unchanged. */
40
+ export const recordDiscoveryInput = z.strictObject({
41
+ kind: z.enum(['execution', 'cer']),
42
+ execution: executionSchema.extend({
43
+ identity: identitySchema.extend({
44
+ assertionHash: z.string().regex(/^sha256:/),
45
+ emailHash: z.string().regex(/^sha256:/).optional(),
46
+ }).optional(),
47
+ }).optional(),
48
+ bundle: mcpRecordInput.options[1].shape.bundle.optional(),
49
+ createdAt: mcpRecordInput.options[0].shape.createdAt.optional(),
50
+ certification: certification.optional(),
51
+ });
52
+ export const recordOutput = z.strictObject({
53
+ contractVersion: z.literal('1'),
54
+ captureProvenance: z.enum(['producer_supplied', 'instrumented_provider_call']),
55
+ evidence: z.enum(['not_created', 'created_confidential', 'existing_unchanged', 'custody_failed', 'invalid']),
56
+ custody: z.enum(['not_performed', 'unencrypted_owner_approved', 'encrypted_owner_recipient', 'external_existing_cer']),
57
+ localIntegrity: z.enum(['valid', 'invalid', 'not_performed']),
58
+ certificationIntent: z.enum(['node', 'local']),
59
+ policyAuthorization: z.enum(['not_required', 'setup_required', 'authorization_denied', 'policy_authorized']),
60
+ submission: z.enum(['not_sent', 'rejected', 'node_reported_accepted', 'outcome_unknown']),
61
+ requestedVisibility: z.enum(['public', 'private']).nullable(),
62
+ nodeConfirmedVisibility: z.enum(['public', 'private']).nullable(),
63
+ certificateHash: hashSchema.nullable(), receiptSignature: z.string().max(96),
64
+ hashBinding: z.string().max(96), signerTrust: z.string().max(96), reasonCode: z.string().max(96),
65
+ usage: z.strictObject({
66
+ authoritative: z.literal(false), accountRemaining: z.null(), scope: z.literal('publisher_local'),
67
+ reservedAttempts: z.number().int().nonnegative().nullable(),
68
+ }),
69
+ });
70
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1,40 @@
1
+ import * as z from 'zod/v4';
2
+ import type { AttestDependencies } from '../write/attest.js';
3
+ import type { PreparedRecord, PublicationResult } from './contracts.js';
4
+ /** Local operator assertions, not protection from a same-UID agent. */
5
+ export declare const customerConsent: z.ZodObject<{
6
+ version: z.ZodLiteral<1>;
7
+ mode: z.ZodLiteral<"customer_delegated">;
8
+ enabled: z.ZodBoolean;
9
+ automaticNodeSubmissions: z.ZodBoolean;
10
+ publicDisclosureAcknowledged: z.ZodBoolean;
11
+ quotaConsumptionAcknowledged: z.ZodBoolean;
12
+ revoked: z.ZodBoolean;
13
+ expiresAt: z.ZodISODateTime;
14
+ accountContext: z.ZodString;
15
+ credentialContext: z.ZodString;
16
+ policyFile: z.ZodString;
17
+ stateDirectory: z.ZodString;
18
+ approvalDirectory: z.ZodString;
19
+ }, z.core.$strict>;
20
+ export type CustomerConsent = z.infer<typeof customerConsent>;
21
+ /** Explicit customer delegation. No Mac isolation claim and no credential
22
+ * discovery beyond the established NEXART_NODE_API_KEY callback.
23
+ * Dependencies are trusted library injection only, never MCP input or env. */
24
+ export declare function createCustomerPublisher(consentFile: string, credential?: () => string | undefined, dependencies?: AttestDependencies): Readonly<{
25
+ publish(record: PreparedRecord): Promise<PublicationResult>;
26
+ /** Owner-invoked GET only; not exposed as a model-controlled MCP tool. */
27
+ reconcile(certificateHash: string, request?: typeof fetch): Promise<{
28
+ state: string;
29
+ certificateHash: string;
30
+ noRetry: boolean;
31
+ nodeConfirmedVisibility: any;
32
+ receiptSignature: "valid" | "invalid" | "not_performed";
33
+ hashBinding: "not_performed" | "match" | "mismatch";
34
+ signerTrust: "not_established" | "trusted_under_policy" | "rejected";
35
+ } | {
36
+ state: string;
37
+ certificateHash: string;
38
+ noRetry: boolean;
39
+ }>;
40
+ }>;
@@ -0,0 +1,99 @@
1
+ import * as z from 'zod/v4';
2
+ import { dirname, isAbsolute } from 'node:path';
3
+ import { ownerDirectory, readOwnerInput } from '../owner/create.js';
4
+ import { reconcileOwnerAttempt } from '../owner/reconcile.js';
5
+ import { writeConfig } from '../write/config.js';
6
+ import { NodeNetwork } from '../network/client.js';
7
+ import { AttestPoster } from '../write/post.js';
8
+ import { WRITE_LIMITS } from '../write/profile.js';
9
+ import { controlDigest } from './policy.js';
10
+ import { publishWithPolicy, PublicationControlError } from './publication.js';
11
+ const label = z.string().regex(/^[A-Za-z0-9._:-]{1,128}$/);
12
+ const path = z.string().min(1).refine(isAbsolute);
13
+ /** Local operator assertions, not protection from a same-UID agent. */
14
+ export const customerConsent = z.strictObject({
15
+ version: z.literal(1), mode: z.literal('customer_delegated'),
16
+ enabled: z.boolean(), automaticNodeSubmissions: z.boolean(),
17
+ publicDisclosureAcknowledged: z.boolean(), quotaConsumptionAcknowledged: z.boolean(),
18
+ revoked: z.boolean(), expiresAt: z.iso.datetime(),
19
+ accountContext: label, credentialContext: label,
20
+ policyFile: path, stateDirectory: path, approvalDirectory: path,
21
+ });
22
+ function readConsent(file) {
23
+ try {
24
+ if (!isAbsolute(file))
25
+ throw Error('PATH');
26
+ ownerDirectory(dirname(file));
27
+ const c = customerConsent.parse(readOwnerInput(file));
28
+ if (!c.enabled || !c.automaticNodeSubmissions ||
29
+ !c.publicDisclosureAcknowledged || !c.quotaConsumptionAcknowledged)
30
+ throw new PublicationControlError('CUSTOMER_CONSENT_REQUIRED');
31
+ if (c.revoked || Date.now() >= Date.parse(c.expiresAt))
32
+ throw new PublicationControlError('CUSTOMER_CONSENT_EXPIRED_OR_REVOKED');
33
+ return c;
34
+ }
35
+ catch (error) {
36
+ if (error instanceof PublicationControlError)
37
+ throw error;
38
+ throw new PublicationControlError('CUSTOMER_CERTIFICATION_CONFIG_INVALID');
39
+ }
40
+ }
41
+ function setupFailure(reasonCode) {
42
+ return { authorization: 'setup_required', submission: 'not_sent',
43
+ nodeConfirmedVisibility: null, reasonCode, receiptSignature: 'not_performed',
44
+ hashBinding: 'not_performed', signerTrust: 'not_established', reservedAttempts: null };
45
+ }
46
+ /** Explicit customer delegation. No Mac isolation claim and no credential
47
+ * discovery beyond the established NEXART_NODE_API_KEY callback.
48
+ * Dependencies are trusted library injection only, never MCP input or env. */
49
+ export function createCustomerPublisher(consentFile, credential = writeConfig().apiKey, dependencies = {}) {
50
+ // One bounded queue shared across this recording tool's calls.
51
+ const shared = { ...dependencies, network: dependencies.network ?? new NodeNetwork(undefined, WRITE_LIMITS.timeoutMs),
52
+ poster: dependencies.poster ?? new AttestPoster() };
53
+ const prepare = () => {
54
+ const consent = readConsent(consentFile);
55
+ const fingerprint = controlDigest(JSON.stringify(consent));
56
+ const recheck = () => {
57
+ if (controlDigest(JSON.stringify(readConsent(consentFile))) !== fingerprint)
58
+ throw new PublicationControlError('CUSTOMER_CONSENT_CHANGED');
59
+ };
60
+ const options = {
61
+ policyFile: consent.policyFile, stateDirectory: consent.stateDirectory,
62
+ approvalDirectory: consent.approvalDirectory, accountContext: consent.accountContext,
63
+ credentialContext: consent.credentialContext, credential,
64
+ };
65
+ return { options, recheck };
66
+ };
67
+ return Object.freeze({
68
+ async publish(record) {
69
+ try {
70
+ const { options, recheck } = prepare();
71
+ const key = credential();
72
+ if (!key || /[\r\n]/.test(key))
73
+ return setupFailure('NODE_CREDENTIAL_UNAVAILABLE');
74
+ return await publishWithPolicy(record, options, shared, { recheck });
75
+ }
76
+ catch (error) {
77
+ return setupFailure(error instanceof PublicationControlError
78
+ ? error.reasonCode : 'CUSTOMER_CERTIFICATION_CONFIG_INVALID');
79
+ }
80
+ },
81
+ /** Owner-invoked GET only; not exposed as a model-controlled MCP tool. */
82
+ async reconcile(certificateHash, request = globalThis.fetch) {
83
+ try {
84
+ const { options, recheck } = prepare();
85
+ recheck();
86
+ return await reconcileOwnerAttempt(certificateHash, options, (url, init) => {
87
+ recheck();
88
+ if (init?.method !== 'GET')
89
+ throw Error('GET_ONLY');
90
+ return request(url, init);
91
+ }, recheck);
92
+ }
93
+ catch {
94
+ throw Error('CUSTOMER_RECONCILIATION_FAILED_NO_RETRY');
95
+ }
96
+ },
97
+ });
98
+ }
99
+ //# sourceMappingURL=customer.js.map
@@ -0,0 +1,46 @@
1
+ import * as z from 'zod/v4';
2
+ import type { PreparedRecord } from './contracts.js';
3
+ export declare const ownerPolicy: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ id: z.ZodString;
6
+ revision: z.ZodNumber;
7
+ accountContext: z.ZodString;
8
+ credentialContext: z.ZodString;
9
+ credentialFingerprint: z.ZodString;
10
+ destination: z.ZodLiteral<"https://node.nexart.io/api/attest">;
11
+ evidenceTypes: z.ZodArray<z.ZodLiteral<"cer.ai.execution.v2">>;
12
+ captureSources: z.ZodArray<z.ZodEnum<{
13
+ producer_supplied: "producer_supplied";
14
+ instrumented_provider_call: "instrumented_provider_call";
15
+ }>>;
16
+ visibilities: z.ZodArray<z.ZodEnum<{
17
+ private: "private";
18
+ public: "public";
19
+ }>>;
20
+ requiredConfidentialFields: z.ZodArray<z.ZodEnum<{
21
+ output: "output";
22
+ input: "input";
23
+ instruction: "instruction";
24
+ decisionRefs: "decisionRefs";
25
+ }>>;
26
+ readableFields: z.ZodArray<z.ZodString>;
27
+ identityDisclosure: z.ZodDefault<z.ZodEnum<{
28
+ forbid: "forbid";
29
+ declared_allowlisted: "declared_allowlisted";
30
+ }>>;
31
+ nodeDisclosureProfile: z.ZodEnum<{
32
+ "ai-v2-resolver-reviewed-2026-11": "ai-v2-resolver-reviewed-2026-11";
33
+ "ai-v2-openai-disclosure-v1": "ai-v2-openai-disclosure-v1";
34
+ }>;
35
+ maximumCertifications: z.ZodNumber;
36
+ periodStartsAt: z.ZodISODateTime;
37
+ periodEndsAt: z.ZodISODateTime;
38
+ expiresAt: z.ZodISODateTime;
39
+ revoked: z.ZodBoolean;
40
+ }, z.core.$strict>;
41
+ export type OwnerPolicy = z.infer<typeof ownerPolicy>;
42
+ export declare const controlDigest: (text: string) => string;
43
+ export declare function readableLeafPaths(value: unknown, path?: string): string[];
44
+ /** A field allowlist is not a semantic PII detector. Approving readable paths
45
+ * authorizes their values; public metadata remains subject to the existing profile. */
46
+ export declare function evaluatePolicy(raw: unknown, record: PreparedRecord, account: string, credentialContext: string, key: string, now?: number): OwnerPolicy;