#!/usr/bin/env node // Refresh the verbatim `chain.v1` copies from the platform repo and // record their hashes. // // Usage: node scripts/sync-proto.mjs [path-to-platform-repo] // Default: ../fai_chain, or $CHAIN_PLATFORM_REPO. import { createHash } from 'node:crypto'; import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const here = dirname(fileURLToPath(import.meta.url)); const root = resolve(here, '..'); const files = [ 'chain/v1/common.proto', 'chain/v1/hub.proto', 'chain/v1/module.proto', 'chain/v1/federation.proto', ]; const platform = resolve( process.argv[2] ?? process.env.CHAIN_PLATFORM_REPO ?? join(root, '..', 'fai_chain'), ); if (!existsSync(join(platform, 'proto', 'chain', 'v1', 'hub.proto'))) { console.error(`no proto/chain/v1 under ${platform}`); process.exit(1); } const lines = []; for (const file of files) { const from = join(platform, 'proto', file); const to = join(root, 'proto', file); copyFileSync(from, to); const hash = createHash('sha256').update(readFileSync(to)).digest('hex'); lines.push(`${hash} ${file}`); console.log(`${file} <- ${from}`); } writeFileSync(join(root, 'proto', 'CHECKSUMS'), `${lines.join('\n')}\n`, 'utf8'); console.log('proto/CHECKSUMS written');