MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / verifyChecksum

Function verifyChecksum

scripts/npm-shim.js:209–229  ·  view source on GitHub ↗
(archivePath, asset, base, version)

Source from the content-addressed store, hash-verified

207// arrived from GitHub over TLS. So tampering/corruption is caught, while a
208// missing checksum never breaks an install.
209async function verifyChecksum(archivePath, asset, base, version) {
210 var sumsPath = archivePath + '.SHA256SUMS';
211 try {
212 await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
213 } catch (e) {
214 return; // not published / unreachable → skip
215 }
216 var expected = null;
217 var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
218 for (var i = 0; i < lines.length; i++) {
219 var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
220 if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
221 }
222 if (!expected) return; // asset not listed → nothing to check
223 var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
224 if (actual !== expected) {
225 throw new Error('checksum mismatch for ' + asset +
226 ' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
227 }
228 process.stderr.write('codegraph: checksum verified.\n');
229}
230
231// Extract via the system tar — present on macOS, Linux, and Windows 10+
232// (bsdtar reads .zip too). No third-party dependency in the shim.

Callers 1

selfHealBundleFunction · 0.85

Calls 3

updateMethod · 0.80
downloadFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected