sealcode 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.
package/src/verify.js ADDED
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { open, sha256Hex } = require('./crypto');
6
+ const { readManifest } = require('./manifest');
7
+
8
+ async function runVerify({ projectRoot, config, K, log = () => {} }) {
9
+ const manifest = readManifest(projectRoot, config.lockedDir, K);
10
+ const lockedRoot = path.join(projectRoot, config.lockedDir);
11
+ const issues = [];
12
+ let okCount = 0;
13
+
14
+ for (const entry of manifest.files) {
15
+ const lockedAbs = path.join(lockedRoot, entry.l);
16
+ if (!fs.existsSync(lockedAbs)) {
17
+ issues.push({ path: entry.p, kind: 'missing-blob', detail: entry.l });
18
+ continue;
19
+ }
20
+ let plain;
21
+ try {
22
+ plain = open(fs.readFileSync(lockedAbs), K);
23
+ } catch (err) {
24
+ issues.push({ path: entry.p, kind: 'decrypt-failed', detail: err.message });
25
+ continue;
26
+ }
27
+ const actual = sha256Hex(plain);
28
+ if (actual !== entry.h) {
29
+ issues.push({
30
+ path: entry.p,
31
+ kind: 'hash-mismatch',
32
+ detail: `expected ${entry.h}, got ${actual}`,
33
+ });
34
+ continue;
35
+ }
36
+ if (typeof entry.s === 'number' && plain.length !== entry.s) {
37
+ issues.push({
38
+ path: entry.p,
39
+ kind: 'size-mismatch',
40
+ detail: `expected ${entry.s} bytes, got ${plain.length}`,
41
+ });
42
+ continue;
43
+ }
44
+ okCount++;
45
+ log(` ok ${entry.p}`);
46
+ }
47
+
48
+ return { ok: issues.length === 0, total: manifest.files.length, okCount, issues };
49
+ }
50
+
51
+ module.exports = { runVerify };