proposal-30-decentralize-so.../scripts/calculateENSNodes.ts

36 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

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";
import { ensDomains } from "./constants";
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", "ensNodesDeclarations.txt"), solidityCode);