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

Function verifyChecksum

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

Source from the content-addressed store, hash-verified

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

Callers 1

selfHealBundleFunction · 0.85

Calls 2

downloadFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected