/** * Check a version of the AI.info policy archive from the page as the company's server answered it * (the version's .raw file): the archive's own reader, run on those bytes, prints the text it keeps * and its SHA-256, which must be the one the version's page and /policies.json print. * * node verify.ts "" [''] [--text] * * The content type and the extract are the version's, from /policies.json ("content_type" of its * raw copy, "extract" of its document; omit the extract or pass null when it has none). * Node 22.18 or later runs this file as it is; Deno too (deno run --allow-read verify.ts …). * policyText.ts and charset.ts beside it are the files the daily job runs, byte for byte. */ import { readFileSync } from 'node:fs'; import { createHash } from 'node:crypto'; import { decodePage } from './charset.ts'; import { readPolicy } from './policyText.ts'; const args = process.argv.slice(2); const showText = args.includes('--text'); const [file, contentType = 'text/html', extract = 'null'] = args.filter(a => a !== '--text'); if (!file) { console.error('usage: node verify.ts "" [\'\'] [--text]'); process.exit(2); } const bytes = new Uint8Array(readFileSync(file)); const read = readPolicy(decodePage(bytes, contentType), contentType, JSON.parse(extract)); if (!read.text) { console.error(`not a reading: ${read.error}`); process.exit(1); } if (showText) process.stdout.write(`${read.text}\n\n`); console.log(createHash('sha256').update(read.text, 'utf8').digest('hex'));