proposal-31-finalize-decent.../scripts/test/calculateENSNodes.ts
2023-10-18 08:11:34 -07:00

51 lines
1.7 KiB
TypeScript

import fs from "fs";
import path from "path";
// @ts-ignore
import { hash } from "@ensdomains/eth-ens-namehash";
import { keccak_256 } from "js-sha3";
import { DeclCalculator } from "../utils";
// Different domain for Goerli testing
const rootTornadoDomain = "tornadotest.eth";
const sourcesDomain = "sources." + rootTornadoDomain;
const ensDomains = {
rootTornadoDomain,
sourcesDomain,
docsDomain: "docs." + rootTornadoDomain,
relayersUiSiteDomain: "relayers-ui." + rootTornadoDomain,
relayersUiSiteOldDomain: "relayers-network." + rootTornadoDomain,
downloadScriptSourceDomain: "download." + sourcesDomain,
ipfsHostHelpScriptSourceDomain: "help." + sourcesDomain,
docsSourceDomain: "docs." + sourcesDomain,
relayersUISourceDomain: "relayers-ui." + sourcesDomain,
relayerSoftwareSource: "relayer." + sourcesDomain,
};
const getLabelhashFromDomain = (ensDomain: string) => "0x" + keccak_256(ensDomain.split(".")[0]);
const solidityInContractPadding = " ".repeat(4);
const { calculateDecl: calculateNodeDecl } = new DeclCalculator(
"bytes32 internal constant",
solidityInContractPadding,
hash,
(name: string) => name + "Node"
);
const { calculateDecl: calculateLabelDecl } = new DeclCalculator(
"bytes32 internal constant",
solidityInContractPadding,
getLabelhashFromDomain,
(name: string) => name + "Labelhash"
);
const solidityCode =
Object.entries(ensDomains)
.map((e) => calculateNodeDecl(e))
.join("") +
"\n" +
Object.entries(ensDomains)
.map((e) => calculateLabelDecl(e))
.join("");
fs.writeFileSync(path.join("data", "test", "ensNodesDeclarations.txt"), solidityCode);