@josfox/jos 4.0.7 → 4.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.
@@ -0,0 +1,41 @@
1
+ const crypto = require('crypto');
2
+ const fs = require('fs');
3
+
4
+ /**
5
+ * Calculate SHA-256 checksum of detailed content
6
+ * @param {string} content
7
+ * @returns {string} Hex digest
8
+ */
9
+ exports.calculateChecksum = (content) => {
10
+ return crypto.createHash('sha256').update(content).digest('hex');
11
+ };
12
+
13
+ /**
14
+ * Verify artifact integrity
15
+ * @param {object} artifact Parsed JSON artifact
16
+ * @param {string} rawContent Raw file content string
17
+ * @returns {boolean} True if valid
18
+ */
19
+ exports.verifyIntegrity = (artifact, rawContent) => {
20
+ const expected = artifact.meta?.checksum;
21
+ if (!expected) return false;
22
+
23
+ // To verify, we need to reproduce how the checksum was calculated.
24
+ // Standard JOS: Checksum is of the minified JSON structure *excluding* the checksum field itself.
25
+ // For simplicity in this v0.0.7 alpha, we'll assume it's a file-hash if provided externally,
26
+ // OR we just trust the meta if we aren't doing strict reproduction yet.
27
+
28
+ // STRICT MODE:
29
+ // 1. Remove meta.checksum from object
30
+ // 2. Canonicalize JSON
31
+ // 3. Hash
32
+
33
+ const clone = JSON.parse(JSON.stringify(artifact));
34
+ if (clone.meta) delete clone.meta.checksum;
35
+
36
+ // Canonical stringify (basic)
37
+ const canonical = JSON.stringify(clone);
38
+ const calculated = exports.calculateChecksum(canonical);
39
+
40
+ return calculated === expected;
41
+ };
@@ -0,0 +1,41 @@
1
+ const https = require('https');
2
+ const http = require('http');
3
+
4
+ /**
5
+ * Shared HTTP Request Helper
6
+ */
7
+ exports.apiRequest = async (url, method, body, apiKey) => {
8
+ return new Promise((resolve, reject) => {
9
+ const urlObj = new URL(url);
10
+ const client = urlObj.protocol === 'https:' ? https : http;
11
+
12
+ const options = {
13
+ hostname: urlObj.hostname,
14
+ port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
15
+ path: urlObj.pathname,
16
+ method: method,
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ 'User-Agent': 'jos-cli/1.0'
20
+ }
21
+ };
22
+
23
+ if (apiKey) options.headers['Authorization'] = `Bearer ${apiKey}`;
24
+
25
+ const req = client.request(options, (res) => {
26
+ let data = '';
27
+ res.on('data', chunk => data += chunk);
28
+ res.on('end', () => {
29
+ try {
30
+ resolve({ status: res.statusCode, data: JSON.parse(data) });
31
+ } catch {
32
+ resolve({ status: res.statusCode, data: data });
33
+ }
34
+ });
35
+ });
36
+
37
+ req.on('error', reject);
38
+ if (body) req.write(JSON.stringify(body));
39
+ req.end();
40
+ });
41
+ };
package/src/index.js DELETED
File without changes