@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,188 @@
1
+ import { checkInput, LIMITS } from '../limits.js';
2
+ export const NODE_ORIGIN = 'https://node.nexart.io';
3
+ export const NETWORK_LIMITS = Object.freeze({
4
+ timeoutMs: 5_000, responseBytes: 1_048_576, manifestBytes: 65_536,
5
+ concurrency: 2, queued: 8, keys: 32, receiptBytes: 16_384,
6
+ });
7
+ export class NetworkFailure extends Error {
8
+ code;
9
+ constructor(code) {
10
+ super(code);
11
+ this.code = code;
12
+ }
13
+ }
14
+ export function safeFailure(error) {
15
+ return error instanceof NetworkFailure ? error.code : 'UPSTREAM_UNAVAILABLE';
16
+ }
17
+ /** Limits lexical depth before JSON.parse; no JSON-RPC line framing here. */
18
+ function parseBoundedJson(text) {
19
+ let quoted = false, escaped = false, depth = 0;
20
+ for (const char of text) {
21
+ if (quoted) {
22
+ if (escaped)
23
+ escaped = false;
24
+ else if (char === '\\')
25
+ escaped = true;
26
+ else if (char === '"')
27
+ quoted = false;
28
+ }
29
+ else if (char === '"')
30
+ quoted = true;
31
+ else if (char === '{' || char === '[') {
32
+ if (++depth > LIMITS.depth)
33
+ throw new NetworkFailure('RESPONSE_TOO_COMPLEX');
34
+ }
35
+ else if (char === '}' || char === ']')
36
+ depth--;
37
+ }
38
+ let value;
39
+ try {
40
+ value = JSON.parse(text);
41
+ }
42
+ catch {
43
+ throw new NetworkFailure('MALFORMED_RESPONSE');
44
+ }
45
+ if (checkInput(value))
46
+ throw new NetworkFailure('RESPONSE_TOO_COMPLEX');
47
+ return value;
48
+ }
49
+ /** Injection is a library/testing dependency, never an MCP argument or environment override. */
50
+ export class NodeNetwork {
51
+ request;
52
+ timeoutMs;
53
+ active = 0;
54
+ waiting = [];
55
+ constructor(request = globalThis.fetch, timeoutMs = NETWORK_LIMITS.timeoutMs) {
56
+ this.request = request;
57
+ this.timeoutMs = timeoutMs;
58
+ }
59
+ async acquire(signal) {
60
+ signal.throwIfAborted();
61
+ if (this.active < NETWORK_LIMITS.concurrency) {
62
+ this.active++;
63
+ return;
64
+ }
65
+ if (this.waiting.length >= NETWORK_LIMITS.queued)
66
+ throw new NetworkFailure('NETWORK_BUSY');
67
+ await new Promise((resolve, reject) => {
68
+ const ready = () => { signal.removeEventListener('abort', abort); resolve(); };
69
+ const abort = () => {
70
+ this.waiting = this.waiting.filter(item => item !== ready);
71
+ reject(signal.reason);
72
+ };
73
+ this.waiting.push(ready);
74
+ signal.addEventListener('abort', abort, { once: true });
75
+ });
76
+ }
77
+ async run(signal, work) {
78
+ const timer = new AbortController();
79
+ const timeout = setTimeout(() => timer.abort(new NetworkFailure('TIMEOUT')), this.timeoutMs);
80
+ const combined = signal ? AbortSignal.any([signal, timer.signal]) : timer.signal;
81
+ let acquired = false;
82
+ try {
83
+ await this.acquire(combined);
84
+ acquired = true;
85
+ combined.throwIfAborted();
86
+ const value = await work(combined);
87
+ combined.throwIfAborted();
88
+ return value;
89
+ }
90
+ catch (error) {
91
+ if (signal?.aborted)
92
+ throw new NetworkFailure('CANCELLED');
93
+ if (timer.signal.aborted)
94
+ throw new NetworkFailure('TIMEOUT');
95
+ if (error instanceof NetworkFailure)
96
+ throw error;
97
+ throw new NetworkFailure('UPSTREAM_UNAVAILABLE');
98
+ }
99
+ finally {
100
+ clearTimeout(timeout);
101
+ if (acquired) {
102
+ const next = this.waiting.shift();
103
+ if (next)
104
+ next();
105
+ else
106
+ this.active--;
107
+ }
108
+ }
109
+ }
110
+ async json(path, signal, manifest = false) {
111
+ if (!/^\/v1\/resolve\/(cer|project)\/sha256%3A[0-9a-f]{64}$/.test(path) &&
112
+ path !== '/.well-known/nexart-node.json')
113
+ throw new NetworkFailure('TARGET_REJECTED');
114
+ const response = await this.request(NODE_ORIGIN + path, {
115
+ method: 'GET', redirect: 'manual', credentials: 'omit', cache: 'no-store', signal,
116
+ headers: { Accept: 'application/json', 'Cache-Control': 'no-cache' },
117
+ });
118
+ const fail = async (code) => {
119
+ try {
120
+ await response.body?.cancel();
121
+ }
122
+ catch { /* no diagnostics */ }
123
+ throw new NetworkFailure(code);
124
+ };
125
+ if (response.status >= 300 && response.status < 400) {
126
+ return fail(response.status === 304 ? 'UNEXPECTED_NOT_MODIFIED' : 'REDIRECT_REJECTED');
127
+ }
128
+ if (response.status !== 200 && response.status !== 409) {
129
+ // HTTP errors are classified without reading or echoing untrusted diagnostic bodies.
130
+ if (response.status === 404)
131
+ return fail(manifest ? 'KEY_MANIFEST_UNAVAILABLE' : 'NOT_FOUND_OR_NOT_PUBLIC');
132
+ if (response.status === 429)
133
+ return fail('RATE_LIMITED');
134
+ return fail(response.status >= 500 ? 'UPSTREAM_UNAVAILABLE' : 'UPSTREAM_REQUEST_REJECTED');
135
+ }
136
+ if (!/^application\/json(?:\s*;|$)/i.test(response.headers.get('content-type') ?? '')) {
137
+ return fail('UNEXPECTED_CONTENT_TYPE');
138
+ }
139
+ const cap = response.status === 409 ? 8_192
140
+ : manifest ? NETWORK_LIMITS.manifestBytes : NETWORK_LIMITS.responseBytes;
141
+ const declared = response.headers.get('content-length');
142
+ if (declared && Number(declared) > cap)
143
+ return fail('RESPONSE_TOO_LARGE');
144
+ const reader = response.body?.getReader();
145
+ if (!reader)
146
+ throw new NetworkFailure('MALFORMED_RESPONSE');
147
+ const abort = () => { void reader.cancel().catch(() => { }); };
148
+ signal.addEventListener('abort', abort, { once: true });
149
+ const chunks = [];
150
+ let bytes = 0;
151
+ try {
152
+ while (true) {
153
+ signal.throwIfAborted();
154
+ const { done, value } = await reader.read();
155
+ if (done)
156
+ break;
157
+ bytes += value.byteLength;
158
+ if (bytes > cap)
159
+ throw new NetworkFailure('RESPONSE_TOO_LARGE');
160
+ chunks.push(value);
161
+ }
162
+ signal.throwIfAborted();
163
+ let text;
164
+ try {
165
+ text = new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks));
166
+ }
167
+ catch {
168
+ throw new NetworkFailure('MALFORMED_RESPONSE');
169
+ }
170
+ const data = parseBoundedJson(text);
171
+ if (response.status === 409) {
172
+ const code = typeof data === 'object' && data !== null && 'code' in data ? data.code : null;
173
+ throw new NetworkFailure(code === 'INCOMPLETE_PROOF' ? 'UPSTREAM_INCOMPLETE_PROOF'
174
+ : code === 'INTEGRITY_MISMATCH' ? 'UPSTREAM_INTEGRITY_MISMATCH' : 'UPSTREAM_PROOF_CONFLICT');
175
+ }
176
+ return data;
177
+ }
178
+ finally {
179
+ signal.removeEventListener('abort', abort);
180
+ try {
181
+ await reader.cancel();
182
+ }
183
+ catch { /* no diagnostics */ }
184
+ reader.releaseLock();
185
+ }
186
+ }
187
+ }
188
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,104 @@
1
+ import * as z from 'zod/v4';
2
+ export declare const hashSchema: z.ZodString;
3
+ export declare const boundedString: z.ZodString;
4
+ export declare const cerResponseSchema: z.ZodObject<{
5
+ artifactType: z.ZodLiteral<"cer">;
6
+ certificateHash: z.ZodString;
7
+ identity: z.ZodObject<{
8
+ certificate_hash: z.ZodString;
9
+ bundle_type: z.ZodString;
10
+ }, z.core.$strip>;
11
+ proof: z.ZodObject<{
12
+ certificate_hash: z.ZodString;
13
+ }, z.core.$strip>;
14
+ verification: z.ZodObject<{
15
+ receipt: z.ZodRecord<z.ZodString, z.ZodUnknown>;
16
+ receiptSignature: z.ZodString;
17
+ verificationEnvelope: z.ZodRecord<z.ZodString, z.ZodUnknown>;
18
+ verificationEnvelopeSignature: z.ZodString;
19
+ }, z.core.$strip>;
20
+ context: z.ZodUnknown;
21
+ bundle: z.ZodRecord<z.ZodString, z.ZodUnknown>;
22
+ canonical: z.ZodOptional<z.ZodObject<{
23
+ certificate: z.ZodOptional<z.ZodObject<{
24
+ hash: z.ZodOptional<z.ZodString>;
25
+ }, z.core.$strip>>;
26
+ }, z.core.$strip>>;
27
+ ok: z.ZodLiteral<true>;
28
+ schemaVersion: z.ZodLiteral<"1.0">;
29
+ links: z.ZodObject<{
30
+ self: z.ZodString;
31
+ keyManifest: z.ZodString;
32
+ humanVerifier: z.ZodString;
33
+ verify: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strip>;
35
+ }, z.core.$strip>;
36
+ export declare const projectResponseSchema: z.ZodObject<{
37
+ artifactType: z.ZodLiteral<"project_bundle">;
38
+ projectHash: z.ZodString;
39
+ proof: z.ZodObject<{
40
+ projectHash: z.ZodString;
41
+ }, z.core.$strip>;
42
+ bundle: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
43
+ nodeReceipt: z.ZodNullable<z.ZodObject<{
44
+ projectHash: z.ZodString;
45
+ }, z.core.$strip>>;
46
+ ok: z.ZodLiteral<true>;
47
+ schemaVersion: z.ZodLiteral<"1.0">;
48
+ links: z.ZodObject<{
49
+ self: z.ZodString;
50
+ keyManifest: z.ZodString;
51
+ humanVerifier: z.ZodString;
52
+ verify: z.ZodOptional<z.ZodString>;
53
+ }, z.core.$strip>;
54
+ }, z.core.$strip>;
55
+ export declare const keySchema: z.ZodObject<{
56
+ kid: z.ZodString;
57
+ alg: z.ZodLiteral<"Ed25519">;
58
+ use: z.ZodOptional<z.ZodLiteral<"sig">>;
59
+ publicKeyJwk: z.ZodOptional<z.ZodObject<{
60
+ kty: z.ZodLiteral<"OKP">;
61
+ crv: z.ZodLiteral<"Ed25519">;
62
+ x: z.ZodString;
63
+ }, z.core.$strip>>;
64
+ publicKey: z.ZodOptional<z.ZodString>;
65
+ publicKeySpkiB64: z.ZodOptional<z.ZodString>;
66
+ status: z.ZodOptional<z.ZodEnum<{
67
+ active: "active";
68
+ deprecated: "deprecated";
69
+ revoked: "revoked";
70
+ }>>;
71
+ revoked: z.ZodOptional<z.ZodBoolean>;
72
+ notBefore: z.ZodOptional<z.ZodString>;
73
+ notAfter: z.ZodOptional<z.ZodString>;
74
+ validFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
75
+ validTo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
76
+ }, z.core.$strip>;
77
+ export declare const manifestSchema: z.ZodObject<{
78
+ nodeId: z.ZodString;
79
+ activeKid: z.ZodOptional<z.ZodString>;
80
+ keys: z.ZodArray<z.ZodObject<{
81
+ kid: z.ZodString;
82
+ alg: z.ZodLiteral<"Ed25519">;
83
+ use: z.ZodOptional<z.ZodLiteral<"sig">>;
84
+ publicKeyJwk: z.ZodOptional<z.ZodObject<{
85
+ kty: z.ZodLiteral<"OKP">;
86
+ crv: z.ZodLiteral<"Ed25519">;
87
+ x: z.ZodString;
88
+ }, z.core.$strip>>;
89
+ publicKey: z.ZodOptional<z.ZodString>;
90
+ publicKeySpkiB64: z.ZodOptional<z.ZodString>;
91
+ status: z.ZodOptional<z.ZodEnum<{
92
+ active: "active";
93
+ deprecated: "deprecated";
94
+ revoked: "revoked";
95
+ }>>;
96
+ revoked: z.ZodOptional<z.ZodBoolean>;
97
+ notBefore: z.ZodOptional<z.ZodString>;
98
+ notAfter: z.ZodOptional<z.ZodString>;
99
+ validFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
100
+ validTo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
101
+ }, z.core.$strip>>;
102
+ }, z.core.$strip>;
103
+ export type ManifestKey = z.infer<typeof keySchema>;
104
+ export declare function parseResponse<T>(schema: z.ZodType<T>, value: unknown): T;
@@ -0,0 +1,54 @@
1
+ import * as z from 'zod/v4';
2
+ import { NETWORK_LIMITS, NetworkFailure } from './client.js';
3
+ export const hashSchema = z.string().regex(/^sha256:[0-9a-f]{64}$/);
4
+ export const boundedString = z.string().min(1).max(256);
5
+ const record = z.record(z.string(), z.unknown());
6
+ const signature = z.string().min(1).max(128);
7
+ const link = z.string().max(2_048);
8
+ const common = {
9
+ ok: z.literal(true), schemaVersion: z.literal('1.0'),
10
+ links: z.object({ self: link, keyManifest: link, humanVerifier: link, verify: link.optional() }),
11
+ };
12
+ export const cerResponseSchema = z.object({
13
+ ...common, artifactType: z.literal('cer'), certificateHash: hashSchema,
14
+ identity: z.object({ certificate_hash: hashSchema, bundle_type: boundedString }),
15
+ proof: z.object({ certificate_hash: hashSchema }),
16
+ verification: z.object({
17
+ receipt: record, receiptSignature: signature,
18
+ verificationEnvelope: record, verificationEnvelopeSignature: signature,
19
+ }),
20
+ context: z.unknown(), bundle: record,
21
+ canonical: z.object({
22
+ certificate: z.object({ hash: hashSchema.optional() }).optional(),
23
+ }).optional(),
24
+ });
25
+ export const projectResponseSchema = z.object({
26
+ ...common, artifactType: z.literal('project_bundle'), projectHash: hashSchema,
27
+ proof: z.object({ projectHash: hashSchema }),
28
+ bundle: record.nullable(),
29
+ nodeReceipt: z.object({ projectHash: hashSchema }).nullable(),
30
+ });
31
+ export const keySchema = z.object({
32
+ kid: boundedString, alg: z.literal('Ed25519'), use: z.literal('sig').optional(),
33
+ publicKeyJwk: z.object({
34
+ kty: z.literal('OKP'), crv: z.literal('Ed25519'),
35
+ x: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
36
+ }).optional(),
37
+ publicKey: z.string().max(128).optional(),
38
+ publicKeySpkiB64: z.string().max(256).optional(),
39
+ status: z.enum(['active', 'deprecated', 'revoked']).optional(),
40
+ revoked: z.boolean().optional(),
41
+ notBefore: z.string().max(64).optional(), notAfter: z.string().max(64).optional(),
42
+ validFrom: z.string().max(64).nullable().optional(), validTo: z.string().max(64).nullable().optional(),
43
+ });
44
+ export const manifestSchema = z.object({
45
+ nodeId: boundedString, activeKid: boundedString.optional(),
46
+ keys: z.array(keySchema).max(NETWORK_LIMITS.keys),
47
+ });
48
+ export function parseResponse(schema, value) {
49
+ const parsed = schema.safeParse(value);
50
+ if (!parsed.success)
51
+ throw new NetworkFailure('INVALID_RESPONSE_CONTRACT');
52
+ return parsed.data;
53
+ }
54
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1,5 @@
1
+ import type { McpServer } from '@modelcontextprotocol/server';
2
+ import { NodeNetwork } from './network/client.js';
3
+ import { type TrustPolicy } from './trust/policy.js';
4
+ export declare const NETWORK_TOOL_NAMES: readonly ["nexart_lookup_cer", "nexart_lookup_project_bundle", "nexart_verify_node_receipt"];
5
+ export declare function registerNetworkTools(server: McpServer, network?: NodeNetwork, policy?: TrustPolicy): void;
@@ -0,0 +1,32 @@
1
+ import { NodeNetwork } from './network/client.js';
2
+ import { LOOKUP_NAMES, lookupCerInput, lookupProjectInput, lookupOutput } from './lookup/contracts.js';
3
+ import { lookup } from './lookup/verify.js';
4
+ import { RECEIPT_TOOL, receiptInput, receiptOutput } from './receipts/contracts.js';
5
+ import { verifyReceipt } from './receipts/verify.js';
6
+ import { TRUST_POLICY } from './trust/policy.js';
7
+ export const NETWORK_TOOL_NAMES = [...LOOKUP_NAMES, RECEIPT_TOOL];
8
+ export function registerNetworkTools(server, network = new NodeNetwork(), policy = TRUST_POLICY) {
9
+ const description = 'Look up one exact public NexArt hash. Return safe summaries and local returned-bundle integrity, not raw evidence or attestation authenticity.';
10
+ const annotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
11
+ server.registerTool(LOOKUP_NAMES[0], {
12
+ description, inputSchema: lookupCerInput, outputSchema: lookupOutput, annotations,
13
+ }, async (args, context) => {
14
+ const result = await lookup(false, args, network, context.mcpReq.signal);
15
+ return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
16
+ });
17
+ server.registerTool(LOOKUP_NAMES[1], {
18
+ description, inputSchema: lookupProjectInput, outputSchema: lookupOutput, annotations,
19
+ }, async (args, context) => {
20
+ const result = await lookup(true, args, network, context.mcpReq.signal);
21
+ return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
22
+ });
23
+ server.registerTool(RECEIPT_TOOL, {
24
+ description: 'Verify a CER receipt Ed25519 signature with the published SDK. Signature, binding, lifecycle and server-pinned trust are separate; Project receipts are unsupported.',
25
+ inputSchema: receiptInput, outputSchema: receiptOutput,
26
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
27
+ }, async (args, context) => {
28
+ const result = await verifyReceipt(args, network, policy, context.mcpReq.signal);
29
+ return { content: [{ type: 'text', text: JSON.stringify(result) }], structuredContent: result };
30
+ });
31
+ }
32
+ //# sourceMappingURL=network-tools.js.map
@@ -0,0 +1,52 @@
1
+ /** Local filesystem protection, NOT isolation from an agent with this UID.
2
+ * Call only on a genuinely isolated owner host. No MCP registration/import.
3
+ */
4
+ export declare function ownerDirectory(path: string): string;
5
+ export declare function readOwnerInput(path: string): unknown;
6
+ /** Owner expressly accepts plaintext + openings custody before calling.
7
+ * Fail closed: no CER export until recovery material is durably retained.
8
+ * On failure preserve private partial files for owner recovery, never delete.
9
+ */
10
+ export declare function prepareOwnerConfidential(raw: unknown): {
11
+ cer: import("@nexart/ai-execution").CerAiExecutionBundleV2;
12
+ openings: import("@nexart/ai-execution").OpeningV2[];
13
+ execution: {
14
+ executionId: string;
15
+ timestamp: string;
16
+ provider: string;
17
+ model: string;
18
+ input: string | Record<string, unknown>;
19
+ output: string | Record<string, unknown>;
20
+ parameters: {
21
+ temperature: number;
22
+ maxTokens: number;
23
+ topP: number | null;
24
+ seed: number | null;
25
+ };
26
+ executionRole: "advisory" | "operative" | "unspecified";
27
+ instruction?: string | undefined;
28
+ instructionKind?: "system" | "derived" | "label" | undefined;
29
+ decisionRefs?: unknown[] | undefined;
30
+ modelEvidence?: Record<string, unknown> | undefined;
31
+ identity?: {
32
+ provider: string;
33
+ sub: string;
34
+ assertionHash: string;
35
+ verified: boolean;
36
+ emailHash?: string | undefined;
37
+ } | undefined;
38
+ toolCalls?: unknown[] | undefined;
39
+ runId?: string | undefined;
40
+ stepId?: string | undefined;
41
+ stepIndex?: number | undefined;
42
+ workflowId?: string | undefined;
43
+ conversationId?: string | undefined;
44
+ prevStepHash?: string | undefined;
45
+ sdkVersion?: string | undefined;
46
+ appId?: string | undefined;
47
+ ext?: Record<string, unknown> | undefined;
48
+ };
49
+ };
50
+ export declare function createOwnerConfidential(raw: unknown, custody: string): {
51
+ certificateHash: string;
52
+ };
@@ -0,0 +1,117 @@
1
+ import { constants, openSync, fstatSync, closeSync, readFileSync, writeFileSync, lstatSync, realpathSync, mkdirSync, fsyncSync, } from 'node:fs';
2
+ import { isAbsolute, resolve, join, dirname } from 'node:path';
3
+ import * as z from 'zod/v4';
4
+ import { createSnapshotV2, sealConfidentialV2, verifyCerV2, verifyConfidentialV2 } from '@nexart/ai-execution';
5
+ import { sealInput } from '../write/contracts.js';
6
+ import { WRITE_LIMITS, boundedInput } from '../write/profile.js';
7
+ const options = z.strictObject({
8
+ execution: z.record(z.string(), z.unknown()), createdAt: z.string().min(1),
9
+ protectInstruction: z.boolean().optional(),
10
+ decisionRefIndexes: z.array(z.number().int().nonnegative()).optional(),
11
+ });
12
+ /** Local filesystem protection, NOT isolation from an agent with this UID.
13
+ * Call only on a genuinely isolated owner host. No MCP registration/import.
14
+ */
15
+ export function ownerDirectory(path) {
16
+ if (!isAbsolute(path) || realpathSync(path) !== resolve(path))
17
+ throw Error('UNSAFE_CUSTODY');
18
+ let parent = path;
19
+ while (true) {
20
+ const stat = lstatSync(parent);
21
+ // Root-owned sticky temporary ancestors cannot be renamed by other users;
22
+ // the actual vault itself must still be an exact owner-only 0700 directory.
23
+ const rootSticky = stat.uid === 0 && (stat.mode & 0o1000) !== 0;
24
+ if (stat.isSymbolicLink() || !stat.isDirectory() || ((stat.mode & 0o022) !== 0 && !rootSticky))
25
+ throw Error('UNSAFE_CUSTODY');
26
+ if (parent === dirname(parent))
27
+ break;
28
+ parent = dirname(parent);
29
+ }
30
+ const stat = lstatSync(path);
31
+ if (stat.uid !== process.getuid?.() || (stat.mode & 0o777) !== 0o700)
32
+ throw Error('UNSAFE_CUSTODY');
33
+ return path;
34
+ }
35
+ export function readOwnerInput(path) {
36
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
37
+ try {
38
+ const stat = fstatSync(fd);
39
+ if (!stat.isFile() || stat.nlink !== 1 || stat.uid !== process.getuid?.()
40
+ || (stat.mode & 0o777) !== 0o600 || stat.size > WRITE_LIMITS.inputBytes)
41
+ throw Error('UNSAFE_INPUT');
42
+ return JSON.parse(readFileSync(fd, 'utf8'));
43
+ }
44
+ finally {
45
+ closeSync(fd);
46
+ }
47
+ }
48
+ function durableFile(path, value) {
49
+ const fd = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
50
+ try {
51
+ writeFileSync(fd, JSON.stringify(value));
52
+ fsyncSync(fd);
53
+ }
54
+ finally {
55
+ closeSync(fd);
56
+ }
57
+ }
58
+ /** Owner expressly accepts plaintext + openings custody before calling.
59
+ * Fail closed: no CER export until recovery material is durably retained.
60
+ * On failure preserve private partial files for owner recovery, never delete.
61
+ */
62
+ export function prepareOwnerConfidential(raw) {
63
+ if (boundedInput(raw))
64
+ throw Error('INPUT_LIMIT');
65
+ const parsed = options.parse(raw);
66
+ const execution = sealInput.parse({
67
+ mode: 'from_execution', execution: parsed.execution, createdAt: parsed.createdAt,
68
+ });
69
+ if (execution.mode !== 'from_execution')
70
+ throw Error('INPUT');
71
+ if (parsed.protectInstruction && execution.execution.instruction === undefined)
72
+ throw Error('INSTRUCTION_ABSENT');
73
+ const snapshot = createSnapshotV2(execution.execution);
74
+ // No salt option is exposed. SDK 1.4.0 supplies fresh CSPRNG salts.
75
+ const { cer, openings } = sealConfidentialV2(snapshot, {
76
+ confidential: true, fields: parsed.protectInstruction ? ['input', 'output', 'instruction'] : ['input', 'output'],
77
+ decisionRefIndexes: parsed.decisionRefIndexes ?? [], createdAt: parsed.createdAt,
78
+ });
79
+ if (!verifyCerV2(cer).ok || verifyConfidentialV2(cer).state !== 'AUTHENTIC')
80
+ throw Error('SDK_VERIFICATION');
81
+ return { cer, openings, execution: execution.execution };
82
+ }
83
+ export function createOwnerConfidential(raw, custody) {
84
+ ownerDirectory(custody);
85
+ const { cer, openings, execution } = prepareOwnerConfidential(raw);
86
+ const dir = join(custody, cer.certificateHash.replace(':', '-'));
87
+ mkdirSync(dir, { mode: 0o700 }); // Exclusive transaction directory, no overwrites.
88
+ durableFile(join(dir, 'recovery.json'), {
89
+ format: 'nexart-owner-recovery-v1', certificateHash: cer.certificateHash,
90
+ // SDK openings contain salts, not content. Both are needed for later disclosure.
91
+ execution, openings,
92
+ });
93
+ const fd = openSync(dir, constants.O_RDONLY);
94
+ try {
95
+ fsyncSync(fd);
96
+ }
97
+ finally {
98
+ closeSync(fd);
99
+ }
100
+ durableFile(join(dir, 'cer.json'), cer);
101
+ const committed = openSync(dir, constants.O_RDONLY);
102
+ try {
103
+ fsyncSync(committed);
104
+ }
105
+ finally {
106
+ closeSync(committed);
107
+ }
108
+ const parent = openSync(custody, constants.O_RDONLY);
109
+ try {
110
+ fsyncSync(parent);
111
+ }
112
+ finally {
113
+ closeSync(parent);
114
+ }
115
+ return { certificateHash: cer.certificateHash };
116
+ }
117
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1,33 @@
1
+ import { type CerAiExecutionBundleV2, type OpeningV2 } from '@nexart/ai-execution';
2
+ /** Trusted host configuration only. No private identity is accepted here. */
3
+ export interface EncryptedCustody {
4
+ directory: string;
5
+ ageExecutable: string;
6
+ recipient: string;
7
+ ownerApproved: true;
8
+ decryptionIdentityExcluded: true;
9
+ }
10
+ export declare class EncryptedCustodyError extends Error {
11
+ readonly reasonCode: 'ENCRYPTED_CUSTODY_CONFIGURATION_REQUIRED' | 'RECOVERY_ENCRYPTION_FAILED' | 'ENCRYPTED_CUSTODY_DURABILITY_FAILED' | 'RECOVERY_BINDING_FAILED' | 'AGE_VERSION_UNSUPPORTED' | 'AGE_VERSION_CHECK_FAILED';
12
+ constructor(reasonCode: 'ENCRYPTED_CUSTODY_CONFIGURATION_REQUIRED' | 'RECOVERY_ENCRYPTION_FAILED' | 'ENCRYPTED_CUSTODY_DURABILITY_FAILED' | 'RECOVERY_BINDING_FAILED' | 'AGE_VERSION_UNSUPPORTED' | 'AGE_VERSION_CHECK_FAILED');
13
+ }
14
+ export declare function checkEncryptedCustody(config: EncryptedCustody): void;
15
+ /** Check actual recipient parsing/executable before a paid provider call. */
16
+ export declare function preflightEncryptedCustody(config: EncryptedCustody): void;
17
+ /** Verifies every protected domain, not just a selectively supplied subset. */
18
+ export declare function verifyRecovery(bundle: CerAiExecutionBundleV2, recovery: {
19
+ format: string;
20
+ certificateHash: string;
21
+ snapshot: Record<string, unknown>;
22
+ openings: OpeningV2[];
23
+ }): void;
24
+ /** No plaintext files. Partial ciphertext is preserved, never overwritten/retried. */
25
+ export declare function retainEncrypted(bundle: CerAiExecutionBundleV2, snapshot: Record<string, unknown>, openings: OpeningV2[], config: EncryptedCustody): void;
26
+ export declare function createEncryptedConfidential(raw: unknown, config: EncryptedCustody): CerAiExecutionBundleV2;
27
+ /** Owner-side only. Run away from the agent; identity is never an MCP/config field.
28
+ * Returns verification summary only, never decrypted recovery content. */
29
+ export declare function recoverEncrypted(directory: string, identityFile: string, ageExecutable: string): {
30
+ certificateHash: string;
31
+ openings: 'verified';
32
+ custody: 'encrypted_owner_recipient';
33
+ };