enigma-memory 0.1.17 → 0.1.18

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 (34) hide show
  1. package/README.md +18 -12
  2. package/apps/cli/bin/enigma.mjs +3341 -3263
  3. package/deploy/SIMULATION.md +14 -9
  4. package/deploy/docker-compose.local-production-simulation.yml +18 -12
  5. package/docs/benchmark-attestation-network.md +487 -487
  6. package/docs/benchmark-reproducibility.md +289 -289
  7. package/docs/blockchain-only-mechanisms.md +400 -400
  8. package/docs/client-connectors.md +1 -1
  9. package/docs/demo-proof-network.md +275 -275
  10. package/docs/developer-proof-quickstart.md +325 -325
  11. package/docs/enigma-memory-ready-conformance.md +376 -376
  12. package/docs/install-anywhere.md +3 -2
  13. package/docs/memory-benchmarks.md +1 -1
  14. package/docs/memory-drive-health-model.md +690 -690
  15. package/docs/proof-network-build-notes.md +240 -240
  16. package/docs/proof-network.md +339 -339
  17. package/docs/sdk-api.md +324 -324
  18. package/docs/solana-proof-rail.md +453 -453
  19. package/package.json +279 -278
  20. package/packages/core/src/index.js +1 -1
  21. package/packages/mcp-server/src/index.js +1185 -1185
  22. package/packages/passport/src/index.js +10 -6
  23. package/packages/vault/src/index.js +187 -25
  24. package/scripts/build-hosted-api-key-lifecycle.mjs +274 -274
  25. package/scripts/build-hosted-customer-lifecycle.mjs +476 -476
  26. package/scripts/build-installer-assets.mjs +389 -389
  27. package/scripts/build-production-unblocker.mjs +1 -1
  28. package/scripts/build-proof-network-packet.mjs +213 -213
  29. package/scripts/check.mjs +8 -1
  30. package/scripts/release-audit.mjs +9 -6
  31. package/scripts/release-provenance.mjs +6 -2
  32. package/scripts/run-standard-memory-benchmarks.mjs +1354 -1352
  33. package/scripts/scan-secrets.mjs +177 -0
  34. package/scripts/simulate-production-env.mjs +64 -8
@@ -4,7 +4,7 @@ import { dirname, resolve } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
 
6
6
  export const PRODUCTION_UNBLOCKER_SCHEMA = 'enigma.production_unblocker.v1';
7
- export const CURRENT_PUBLIC_PACKAGE_VERSION = '0.1.16';
7
+ export const CURRENT_PUBLIC_PACKAGE_VERSION = '0.1.18';
8
8
 
9
9
  const STATUS_VALUES = Object.freeze([
10
10
  'ready_now',
@@ -1,213 +1,213 @@
1
- #!/usr/bin/env node
2
- import { createHash } from 'node:crypto';
3
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
- import { dirname, isAbsolute, resolve } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
-
7
- import {
8
- assertNoPrivateProofPayload,
9
- createBenchmarkAttestation,
10
- createProofNetworkAnchorBatch,
11
- createProofNetworkPacket,
12
- sha256Json,
13
- validateBenchmarkAttestation,
14
- validateProofNetworkAnchorBatch,
15
- validateProofNetworkPacket,
16
- } from '../packages/proof-network/src/index.js';
17
-
18
- export const PROOF_NETWORK_PACKET_RELEASE_TARGET = '0.1.17';
19
-
20
- const HASH_RE = /^(?:sha256:)?[a-f0-9]{64}$/iu;
21
- const SECRET_VALUE_RE = /(?:Bearer\s+[A-Za-z0-9._~+/=-]{12,}|Basic\s+[A-Za-z0-9+/=-]{12,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|https?:\/\/[^\s/@]+:[^\s/@]+@|sk-[A-Za-z0-9_-]{16,}|AKIA[0-9A-Z]{16}|\b(?:raw[\s_-]*memory|plaintext[\s_-]*prompts?|plain[\s_-]*text[\s_-]*prompts?|private[\s_-]*prompts?|provider[\s_-]*responses?|full[\s_-]*transcript|decrypted[\s_-]*memory|credentials?|secrets?|passwords?|private[\s_-]*keys?|api[\s_-]*key[\s_-]*(?:secret|material|value)|api[\s_-]*secrets?|access[\s_-]*tokens?|refresh[\s_-]*tokens?|token[\s_-]*values?|credential[\s_-]*material|tenant[\s_-]*names?)\b)/iu;
22
- const ABSOLUTE_LOCAL_PATH_RE = /^(?:[A-Za-z]:[\\/]|\\\\|\/(?:Users|home|tmp|var|etc|mnt|Volumes)\b)/u;
23
-
24
- class UsageError extends Error {
25
- constructor(message) {
26
- super(message);
27
- this.name = 'UsageError';
28
- }
29
- }
30
-
31
- function readRequiredValue(argv, index, flag) {
32
- const value = argv[index + 1];
33
- if (value === undefined || value.startsWith('--')) throw new UsageError(`${flag} requires a value`);
34
- return value;
35
- }
36
-
37
- function assertPublicSafeString(value, label) {
38
- if (typeof value !== 'string' || value.trim() === '') throw new UsageError(`${label} must be a non-empty public ref or hash`);
39
- const normalized = value.trim();
40
- if (SECRET_VALUE_RE.test(normalized)) throw new UsageError(`${label} contains private or secret material`);
41
- return normalized;
42
- }
43
-
44
- function assertPublicHash(value, label) {
45
- const normalized = assertPublicSafeString(value, label);
46
- if (!HASH_RE.test(normalized)) throw new UsageError(`${label} must be a sha256 hash as 64 hex characters or sha256:<64 hex>`);
47
- return normalized.toLowerCase().startsWith('sha256:') ? normalized.toLowerCase() : `sha256:${normalized.toLowerCase()}`;
48
- }
49
-
50
- function assertRelativeOutFile(value) {
51
- const normalized = assertPublicSafeString(value, 'output file');
52
- if (isAbsolute(normalized) || ABSOLUTE_LOCAL_PATH_RE.test(normalized)) throw new UsageError('output file must be a relative path');
53
- return normalized;
54
- }
55
-
56
- export function parseArgs(argv = process.argv.slice(2)) {
57
- const args = {
58
- activeRoot: undefined,
59
- receiptRoot: undefined,
60
- benchmarkReport: undefined,
61
- datasetHash: undefined,
62
- runnerHash: undefined,
63
- operatorRef: undefined,
64
- out: undefined,
65
- help: false,
66
- };
67
-
68
- for (let index = 0; index < argv.length; index += 1) {
69
- const raw = argv[index];
70
- const equalsIndex = raw.indexOf('=');
71
- const flag = equalsIndex > 0 ? raw.slice(0, equalsIndex) : raw;
72
- const inlineValue = equalsIndex > 0 ? raw.slice(equalsIndex + 1) : undefined;
73
- const value = () => {
74
- if (inlineValue !== undefined) return inlineValue;
75
- const next = readRequiredValue(argv, index, flag);
76
- index += 1;
77
- return next;
78
- };
79
-
80
- if (flag === '--help' || flag === '-h') args.help = true;
81
- else if (flag === '--active-root') args.activeRoot = assertPublicHash(value(), 'active root');
82
- else if (flag === '--receipt-root') args.receiptRoot = assertPublicHash(value(), 'receipt root');
83
- else if (flag === '--benchmark-report') args.benchmarkReport = value();
84
- else if (flag === '--dataset-hash') args.datasetHash = assertPublicHash(value(), 'dataset hash');
85
- else if (flag === '--runner-hash') args.runnerHash = assertPublicHash(value(), 'runner hash');
86
- else if (flag === '--operator-ref') args.operatorRef = assertPublicSafeString(value(), 'operator ref');
87
- else if (flag === '--out') args.out = assertRelativeOutFile(value());
88
- else throw new UsageError(`unknown option ${raw}; use --help`);
89
- }
90
- return args;
91
- }
92
-
93
- export function usage() {
94
- return `Usage: node scripts/build-proof-network-packet.mjs --active-root <sha256> --receipt-root <sha256> --benchmark-report <file> --dataset-hash <sha256> --runner-hash <sha256> --operator-ref <ref> [--out <file>]
95
-
96
- Builds a public-safe proof-network packet from local refs and hashes. The benchmark report file is hashed only; its body and path are never copied into the packet. This script does not call a network, deploy contracts, create accounts, sign transactions, or write raw memory, prompts, transcripts, completions, embeddings, ACL bodies, tenant names, private keys, API keys, seed phrases, or provider responses.
97
- `;
98
- }
99
-
100
- function requireArgs(args) {
101
- const required = [
102
- ['--active-root', args.activeRoot],
103
- ['--receipt-root', args.receiptRoot],
104
- ['--benchmark-report', args.benchmarkReport],
105
- ['--dataset-hash', args.datasetHash],
106
- ['--runner-hash', args.runnerHash],
107
- ['--operator-ref', args.operatorRef],
108
- ];
109
- const missing = required.filter(([, value]) => value === undefined).map(([name]) => name);
110
- if (missing.length > 0) throw new UsageError(`missing required option(s): ${missing.join(', ')}`);
111
- }
112
-
113
- function sha256Buffer(buffer) {
114
- return `sha256:${createHash('sha256').update(buffer).digest('hex')}`;
115
- }
116
-
117
- function withBoundaryFlags(packet) {
118
- return {
119
- transaction_submitted: false,
120
- raw_memory_on_chain: false,
121
- ...packet,
122
- transaction_submitted: false,
123
- raw_memory_on_chain: false,
124
- };
125
- }
126
-
127
- function assertValidation(validation, label) {
128
- if (validation?.ok !== true) throw new Error(`${label} validation failed: ${(validation?.errors ?? ['unknown error']).join('; ')}`);
129
- }
130
-
131
- export async function buildProofNetworkPacket(args, options = {}) {
132
- requireArgs(args);
133
- const generatedAt = options.generated_at ?? options.generatedAt ?? new Date().toISOString();
134
- const reportBytes = await readFile(args.benchmarkReport);
135
- const reportHash = sha256Buffer(reportBytes);
136
- const packageRef = `npm:enigma-memory@${PROOF_NETWORK_PACKET_RELEASE_TARGET}`;
137
-
138
- const publicInputs = {
139
- active_root: args.activeRoot,
140
- receipt_root: args.receiptRoot,
141
- report_hash: reportHash,
142
- dataset_ref: args.datasetHash,
143
- runner_ref: args.runnerHash,
144
- operator_ref: args.operatorRef,
145
- package_ref: packageRef,
146
- transaction_submitted: false,
147
- raw_memory_on_chain: false,
148
- };
149
- assertNoPrivateProofPayload(publicInputs);
150
-
151
- const operatorSignatureRef = `signature:${sha256Json(args.operatorRef).slice('sha256:'.length)}`;
152
- const benchmarkAttestation = createBenchmarkAttestation({
153
- report_hash: reportHash,
154
- dataset_ref: args.datasetHash,
155
- runner_ref: args.runnerHash,
156
- package_ref: packageRef,
157
- benchmark_ref: `benchmark-report:${reportHash}`,
158
- signature_ref: operatorSignatureRef,
159
- attested_at: generatedAt,
160
- });
161
- assertValidation(validateBenchmarkAttestation(benchmarkAttestation), 'benchmark attestation');
162
-
163
- const anchorBatch = createProofNetworkAnchorBatch({
164
- chain: 'solana',
165
- generated_at: generatedAt,
166
- anchor_ref: `anchor:${sha256Json([args.activeRoot, args.receiptRoot, reportHash]).slice('sha256:'.length, 'sha256:'.length + 32)}`,
167
- commitments: [
168
- { kind: 'active_root', root: args.activeRoot, ref: 'active-root' },
169
- { kind: 'receipt_root', root: args.receiptRoot, ref: 'receipt-root' },
170
- { kind: 'benchmark_report', root: reportHash, ref: 'benchmark-report' },
171
- { kind: 'benchmark_attestation', root: benchmarkAttestation.benchmark_attestation_hash, ref: 'benchmark-attestation' },
172
- { kind: 'operator_ref', root: sha256Json(args.operatorRef), ref: args.operatorRef },
173
- ],
174
- });
175
- assertValidation(validateProofNetworkAnchorBatch(anchorBatch), 'anchor batch');
176
-
177
- const packet = withBoundaryFlags(createProofNetworkPacket({
178
- anchor_batches: [anchorBatch],
179
- attestations: [benchmarkAttestation],
180
- packet_ref: `proof-network-packet:${sha256Json([anchorBatch.anchor_batch_hash, benchmarkAttestation.benchmark_attestation_hash]).slice('sha256:'.length, 'sha256:'.length + 32)}`,
181
- created_at: generatedAt,
182
- }));
183
- assertNoPrivateProofPayload(packet);
184
- assertValidation(validateProofNetworkPacket(packet), 'proof-network packet');
185
- return packet;
186
- }
187
-
188
- export async function main(argv = process.argv.slice(2)) {
189
- const args = parseArgs(argv);
190
- if (args.help) {
191
- process.stdout.write(usage());
192
- return 0;
193
- }
194
- const packet = await buildProofNetworkPacket(args);
195
- const json = `${JSON.stringify(packet, null, 2)}\n`;
196
- if (args.out) {
197
- try {
198
- await mkdir(dirname(args.out), { recursive: true });
199
- await writeFile(args.out, json, 'utf8');
200
- } catch {
201
- throw new Error('failed to write proof-network packet output');
202
- }
203
- }
204
- process.stdout.write(json);
205
- return 0;
206
- }
207
-
208
- if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
209
- main().catch((error) => {
210
- process.stderr.write(`${error.name ?? 'Error'}: ${error.message ?? 'failed to build proof-network packet'}\n`);
211
- process.exitCode = 1;
212
- });
213
- }
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { dirname, isAbsolute, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import {
8
+ assertNoPrivateProofPayload,
9
+ createBenchmarkAttestation,
10
+ createProofNetworkAnchorBatch,
11
+ createProofNetworkPacket,
12
+ sha256Json,
13
+ validateBenchmarkAttestation,
14
+ validateProofNetworkAnchorBatch,
15
+ validateProofNetworkPacket,
16
+ } from '../packages/proof-network/src/index.js';
17
+
18
+ export const PROOF_NETWORK_PACKET_RELEASE_TARGET = '0.1.17';
19
+
20
+ const HASH_RE = /^(?:sha256:)?[a-f0-9]{64}$/iu;
21
+ const SECRET_VALUE_RE = /(?:Bearer\s+[A-Za-z0-9._~+/=-]{12,}|Basic\s+[A-Za-z0-9+/=-]{12,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|https?:\/\/[^\s/@]+:[^\s/@]+@|sk-[A-Za-z0-9_-]{16,}|AKIA[0-9A-Z]{16}|\b(?:raw[\s_-]*memory|plaintext[\s_-]*prompts?|plain[\s_-]*text[\s_-]*prompts?|private[\s_-]*prompts?|provider[\s_-]*responses?|full[\s_-]*transcript|decrypted[\s_-]*memory|credentials?|secrets?|passwords?|private[\s_-]*keys?|api[\s_-]*key[\s_-]*(?:secret|material|value)|api[\s_-]*secrets?|access[\s_-]*tokens?|refresh[\s_-]*tokens?|token[\s_-]*values?|credential[\s_-]*material|tenant[\s_-]*names?)\b)/iu;
22
+ const ABSOLUTE_LOCAL_PATH_RE = /^(?:[A-Za-z]:[\\/]|\\\\|\/(?:Users|home|tmp|var|etc|mnt|Volumes)\b)/u;
23
+
24
+ class UsageError extends Error {
25
+ constructor(message) {
26
+ super(message);
27
+ this.name = 'UsageError';
28
+ }
29
+ }
30
+
31
+ function readRequiredValue(argv, index, flag) {
32
+ const value = argv[index + 1];
33
+ if (value === undefined || value.startsWith('--')) throw new UsageError(`${flag} requires a value`);
34
+ return value;
35
+ }
36
+
37
+ function assertPublicSafeString(value, label) {
38
+ if (typeof value !== 'string' || value.trim() === '') throw new UsageError(`${label} must be a non-empty public ref or hash`);
39
+ const normalized = value.trim();
40
+ if (SECRET_VALUE_RE.test(normalized)) throw new UsageError(`${label} contains private or secret material`);
41
+ return normalized;
42
+ }
43
+
44
+ function assertPublicHash(value, label) {
45
+ const normalized = assertPublicSafeString(value, label);
46
+ if (!HASH_RE.test(normalized)) throw new UsageError(`${label} must be a sha256 hash as 64 hex characters or sha256:<64 hex>`);
47
+ return normalized.toLowerCase().startsWith('sha256:') ? normalized.toLowerCase() : `sha256:${normalized.toLowerCase()}`;
48
+ }
49
+
50
+ function assertRelativeOutFile(value) {
51
+ const normalized = assertPublicSafeString(value, 'output file');
52
+ if (isAbsolute(normalized) || ABSOLUTE_LOCAL_PATH_RE.test(normalized)) throw new UsageError('output file must be a relative path');
53
+ return normalized;
54
+ }
55
+
56
+ export function parseArgs(argv = process.argv.slice(2)) {
57
+ const args = {
58
+ activeRoot: undefined,
59
+ receiptRoot: undefined,
60
+ benchmarkReport: undefined,
61
+ datasetHash: undefined,
62
+ runnerHash: undefined,
63
+ operatorRef: undefined,
64
+ out: undefined,
65
+ help: false,
66
+ };
67
+
68
+ for (let index = 0; index < argv.length; index += 1) {
69
+ const raw = argv[index];
70
+ const equalsIndex = raw.indexOf('=');
71
+ const flag = equalsIndex > 0 ? raw.slice(0, equalsIndex) : raw;
72
+ const inlineValue = equalsIndex > 0 ? raw.slice(equalsIndex + 1) : undefined;
73
+ const value = () => {
74
+ if (inlineValue !== undefined) return inlineValue;
75
+ const next = readRequiredValue(argv, index, flag);
76
+ index += 1;
77
+ return next;
78
+ };
79
+
80
+ if (flag === '--help' || flag === '-h') args.help = true;
81
+ else if (flag === '--active-root') args.activeRoot = assertPublicHash(value(), 'active root');
82
+ else if (flag === '--receipt-root') args.receiptRoot = assertPublicHash(value(), 'receipt root');
83
+ else if (flag === '--benchmark-report') args.benchmarkReport = value();
84
+ else if (flag === '--dataset-hash') args.datasetHash = assertPublicHash(value(), 'dataset hash');
85
+ else if (flag === '--runner-hash') args.runnerHash = assertPublicHash(value(), 'runner hash');
86
+ else if (flag === '--operator-ref') args.operatorRef = assertPublicSafeString(value(), 'operator ref');
87
+ else if (flag === '--out') args.out = assertRelativeOutFile(value());
88
+ else throw new UsageError(`unknown option ${raw}; use --help`);
89
+ }
90
+ return args;
91
+ }
92
+
93
+ export function usage() {
94
+ return `Usage: node scripts/build-proof-network-packet.mjs --active-root <sha256> --receipt-root <sha256> --benchmark-report <file> --dataset-hash <sha256> --runner-hash <sha256> --operator-ref <ref> [--out <file>]
95
+
96
+ Builds a public-safe proof-network packet from local refs and hashes. The benchmark report file is hashed only; its body and path are never copied into the packet. This script does not call a network, deploy contracts, create accounts, sign transactions, or write raw memory, prompts, transcripts, completions, embeddings, ACL bodies, tenant names, private keys, API keys, seed phrases, or provider responses.
97
+ `;
98
+ }
99
+
100
+ function requireArgs(args) {
101
+ const required = [
102
+ ['--active-root', args.activeRoot],
103
+ ['--receipt-root', args.receiptRoot],
104
+ ['--benchmark-report', args.benchmarkReport],
105
+ ['--dataset-hash', args.datasetHash],
106
+ ['--runner-hash', args.runnerHash],
107
+ ['--operator-ref', args.operatorRef],
108
+ ];
109
+ const missing = required.filter(([, value]) => value === undefined).map(([name]) => name);
110
+ if (missing.length > 0) throw new UsageError(`missing required option(s): ${missing.join(', ')}`);
111
+ }
112
+
113
+ function sha256Buffer(buffer) {
114
+ return `sha256:${createHash('sha256').update(buffer).digest('hex')}`;
115
+ }
116
+
117
+ function withBoundaryFlags(packet) {
118
+ return {
119
+ transaction_submitted: false,
120
+ raw_memory_on_chain: false,
121
+ ...packet,
122
+ transaction_submitted: false,
123
+ raw_memory_on_chain: false,
124
+ };
125
+ }
126
+
127
+ function assertValidation(validation, label) {
128
+ if (validation?.ok !== true) throw new Error(`${label} validation failed: ${(validation?.errors ?? ['unknown error']).join('; ')}`);
129
+ }
130
+
131
+ export async function buildProofNetworkPacket(args, options = {}) {
132
+ requireArgs(args);
133
+ const generatedAt = options.generated_at ?? options.generatedAt ?? new Date().toISOString();
134
+ const reportBytes = await readFile(args.benchmarkReport);
135
+ const reportHash = sha256Buffer(reportBytes);
136
+ const packageRef = `npm:enigma-memory@${PROOF_NETWORK_PACKET_RELEASE_TARGET}`;
137
+
138
+ const publicInputs = {
139
+ active_root: args.activeRoot,
140
+ receipt_root: args.receiptRoot,
141
+ report_hash: reportHash,
142
+ dataset_ref: args.datasetHash,
143
+ runner_ref: args.runnerHash,
144
+ operator_ref: args.operatorRef,
145
+ package_ref: packageRef,
146
+ transaction_submitted: false,
147
+ raw_memory_on_chain: false,
148
+ };
149
+ assertNoPrivateProofPayload(publicInputs);
150
+
151
+ const operatorSignatureRef = `signature:${sha256Json(args.operatorRef).slice('sha256:'.length)}`;
152
+ const benchmarkAttestation = createBenchmarkAttestation({
153
+ report_hash: reportHash,
154
+ dataset_ref: args.datasetHash,
155
+ runner_ref: args.runnerHash,
156
+ package_ref: packageRef,
157
+ benchmark_ref: `benchmark-report:${reportHash}`,
158
+ signature_ref: operatorSignatureRef,
159
+ attested_at: generatedAt,
160
+ });
161
+ assertValidation(validateBenchmarkAttestation(benchmarkAttestation), 'benchmark attestation');
162
+
163
+ const anchorBatch = createProofNetworkAnchorBatch({
164
+ chain: 'solana',
165
+ generated_at: generatedAt,
166
+ anchor_ref: `anchor:${sha256Json([args.activeRoot, args.receiptRoot, reportHash]).slice('sha256:'.length, 'sha256:'.length + 32)}`,
167
+ commitments: [
168
+ { kind: 'active_root', root: args.activeRoot, ref: 'active-root' },
169
+ { kind: 'receipt_root', root: args.receiptRoot, ref: 'receipt-root' },
170
+ { kind: 'benchmark_report', root: reportHash, ref: 'benchmark-report' },
171
+ { kind: 'benchmark_attestation', root: benchmarkAttestation.benchmark_attestation_hash, ref: 'benchmark-attestation' },
172
+ { kind: 'operator_ref', root: sha256Json(args.operatorRef), ref: args.operatorRef },
173
+ ],
174
+ });
175
+ assertValidation(validateProofNetworkAnchorBatch(anchorBatch), 'anchor batch');
176
+
177
+ const packet = withBoundaryFlags(createProofNetworkPacket({
178
+ anchor_batches: [anchorBatch],
179
+ attestations: [benchmarkAttestation],
180
+ packet_ref: `proof-network-packet:${sha256Json([anchorBatch.anchor_batch_hash, benchmarkAttestation.benchmark_attestation_hash]).slice('sha256:'.length, 'sha256:'.length + 32)}`,
181
+ created_at: generatedAt,
182
+ }));
183
+ assertNoPrivateProofPayload(packet);
184
+ assertValidation(validateProofNetworkPacket(packet), 'proof-network packet');
185
+ return packet;
186
+ }
187
+
188
+ export async function main(argv = process.argv.slice(2)) {
189
+ const args = parseArgs(argv);
190
+ if (args.help) {
191
+ process.stdout.write(usage());
192
+ return 0;
193
+ }
194
+ const packet = await buildProofNetworkPacket(args);
195
+ const json = `${JSON.stringify(packet, null, 2)}\n`;
196
+ if (args.out) {
197
+ try {
198
+ await mkdir(dirname(args.out), { recursive: true });
199
+ await writeFile(args.out, json, 'utf8');
200
+ } catch {
201
+ throw new Error('failed to write proof-network packet output');
202
+ }
203
+ }
204
+ process.stdout.write(json);
205
+ return 0;
206
+ }
207
+
208
+ if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
209
+ main().catch((error) => {
210
+ process.stderr.write(`${error.name ?? 'Error'}: ${error.message ?? 'failed to build proof-network packet'}\n`);
211
+ process.exitCode = 1;
212
+ });
213
+ }
package/scripts/check.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
-
4
+ import { scanForSecrets } from './scan-secrets.mjs';
5
5
  const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
6
6
  const packageJsonPath = process.env.ENIGMA_CHECK_PACKAGE_JSON_OVERRIDE
7
7
  ? path.resolve(process.env.ENIGMA_CHECK_PACKAGE_JSON_OVERRIDE)
@@ -417,5 +417,12 @@ for (const name of fs.readdirSync(specsDir)) {
417
417
  }
418
418
  validateSchemaNode(name, parsed, parsed);
419
419
  }
420
+ const secretFindings = scanForSecrets(root);
421
+ if (secretFindings.length > 0) {
422
+ throw new Error(
423
+ `secret-scan detected ${secretFindings.length} unapproved secret-like value(s):\n` +
424
+ secretFindings.map((f) => `${f.file}:${f.line} ${f.type}`).join('\n')
425
+ );
426
+ }
420
427
 
421
428
  console.log('enigma check ok');
@@ -574,6 +574,7 @@ async function runCommandGate(name, command, args, options = {}) {
574
574
  }
575
575
 
576
576
  async function runJsonCommandStatus(command, args, expectedStatus, validate) {
577
+ const allowedStatuses = Array.isArray(expectedStatus) ? expectedStatus : [expectedStatus];
577
578
  const started = Date.now();
578
579
  const result = {
579
580
  command: commandLabel(command, args),
@@ -608,8 +609,8 @@ async function runJsonCommandStatus(command, args, expectedStatus, validate) {
608
609
  result.stderr_bytes = Buffer.byteLength(stderr);
609
610
  result.stdout_bytes = Buffer.byteLength(stdout);
610
611
  try {
611
- if (result.status !== expectedStatus) {
612
- throw new Error(`Expected status ${expectedStatus}, got ${result.status}`);
612
+ if (!allowedStatuses.includes(result.status)) {
613
+ throw new Error(`Expected status ${allowedStatuses.join(' or ')}, got ${result.status}`);
613
614
  }
614
615
  const parsed = parseJson(stdout);
615
616
  result.evidence = validate(parsed);
@@ -617,7 +618,7 @@ async function runJsonCommandStatus(command, args, expectedStatus, validate) {
617
618
  delete result.error;
618
619
  } catch (error) {
619
620
  result.error ??= {
620
- code: result.status === expectedStatus ? 'OUTPUT_VALIDATION_FAILED' : 'COMMAND_FAILED',
621
+ code: allowedStatuses.includes(result.status) ? 'OUTPUT_VALIDATION_FAILED' : 'COMMAND_FAILED',
621
622
  message: error.message,
622
623
  };
623
624
  } finally {
@@ -640,9 +641,11 @@ export async function runDirectBinSmokes() {
640
641
  return { usage: json.usage, command_count: json.commands.length, has_claim_boundaries: typeof json.claim_boundaries === 'string' };
641
642
  }));
642
643
 
643
- checks.push(await runJsonCommand(node, ['apps/cli/bin/enigma.mjs', 'doctor'], (json) => {
644
- requireJsonField(json, ['ok'], (value) => value === true, 'Doctor did not report ok: true.');
645
- return { package_bins_ok: json.package_bins?.ok === true, schema_count: json.schema_count };
644
+ checks.push(await runJsonCommandStatus(node, ['apps/cli/bin/enigma.mjs', 'doctor'], [0, 1], (json) => {
645
+ requireJsonField(json, ['package_bins', 'ok'], (value) => value === true, 'Doctor did not report package_bins ok.');
646
+ requireJsonField(json, ['node', 'ok'], (value) => value === true, 'Doctor did not report node ok.');
647
+ requireJsonField(json, ['schema_count'], (value) => typeof value === 'number' && value > 0, 'Doctor did not report schemas.');
648
+ return { package_bins_ok: json.package_bins?.ok === true, schema_count: json.schema_count, doctor_ok: json.ok === true };
646
649
  }));
647
650
 
648
651
  checks.push(await runJsonCommand(node, [
@@ -19,6 +19,10 @@ const PUBLIC_SITE_MANIFEST_CANDIDATES = Object.freeze([
19
19
  'site/public/public-site-manifest.json',
20
20
  'site/public/manifest.json'
21
21
  ]);
22
+ const KNOWN_SAFE_PATHS = new Set([
23
+ 'scripts/scan-secrets.mjs',
24
+ ]);
25
+
22
26
 
23
27
  function normalizeRel(rel) {
24
28
  return String(rel).replace(/\\/g, '/').replace(/^\.\//, '').replace(/\/+/g, '/');
@@ -37,12 +41,12 @@ function safeProjectPath(rel) {
37
41
  }
38
42
 
39
43
  function assertSafeEvidencePath(rel) {
40
- const normalized = normalizeRel(rel);
44
+ const normalized = normalizeRel(rel).replace(/^!+/, '');
45
+ if (KNOWN_SAFE_PATHS.has(normalized)) return;
41
46
  if (SECRET_OR_LOCAL_BUNDLE_PATH.test(normalized) || SECRET_EXTENSION.test(normalized) || PRIVATE_PUBLIC_SITE_COLLATERAL.test(normalized)) {
42
47
  throw new Error(`Refusing release provenance over sensitive or private path: ${normalized}`);
43
48
  }
44
49
  }
45
-
46
50
  function sortedObject(value) {
47
51
  if (value === null || typeof value !== 'object' || Array.isArray(value)) return value;
48
52
  return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortedObject(value[key])]));