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

Function verifyChecksum

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

Source from the content-addressed store, hash-verified

219// arrived from GitHub over TLS. So tampering/corruption is caught, while a
220// missing checksum never breaks an install.
221async function verifyChecksum(archivePath, asset, base, version) {
222 var sumsPath = archivePath + '.SHA256SUMS';
223 try {
224 await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
225 } catch (e) {
226 return; // not published / unreachable → skip
227 }
228 var expected = null;
229 var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
230 for (var i = 0; i < lines.length; i++) {
231 var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
232 if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
233 }
234 if (!expected) return; // asset not listed → nothing to check
235 var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
236 if (actual !== expected) {
237 throw new Error('checksum mismatch for ' + asset +
238 ' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
239 }
240 process.stderr.write('codegraph: checksum verified.\n');
241}
242
243// Extract via the system tar — present on macOS, Linux, and Windows 10+
244// (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