Skip to content

Instantly share code, notes, and snippets.

@coindegen
Created January 29, 2022 12:37
Show Gist options
  • Save coindegen/f13a2c03fb1d020d595236bda82ed61d to your computer and use it in GitHub Desktop.
Save coindegen/f13a2c03fb1d020d595236bda82ed61d to your computer and use it in GitHub Desktop.
provenance hash
const keccak256 = require("keccak256");
const fs = require("fs");
const chalk = require("chalk");
const path = require("path");
const isLocal = typeof process.pkg === "undefined";
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
console.log({ basePath });
const { buildDir } = require(path.join(basePath, "/src/config.js"));
// Read files from the build folder defined in config.
const metadata = JSON.parse(
fs.readFileSync(path.join(buildDir, `/json/_metadata.json`), "utf-8")
);
const accumulatedHashString = metadata.reduce((acc, item) => {
return acc.concat(item.imageHash);
}, []);
const provenance = keccak256(accumulatedHashString.join("")).toString("hex");
fs.writeFileSync(
`${buildDir}/_provenance.json`,
JSON.stringify(
{ provenance, concatenatedHashString: accumulatedHashString.join("") },
null,
"\t"
)
);
console.log(`\nProvenance Hash Save in !\n${buildDir}/_provenance.json\n`);
console.log(chalk.greenBright.bold(`${provenance} \n`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment