@broxus/locklift-verifier
Version:
Locklift plugin for integration with Everscan contract verification service
99 lines (98 loc) • 4.96 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVerificationApp = exports.VerificationCli = void 0;
const env_paths_1 = __importDefault(require("env-paths"));
const utils_1 = require("./utils");
const path_1 = __importDefault(require("path"));
const fs = __importStar(require("fs-extra"));
const child_process_1 = require("child_process");
class VerificationCli {
pathToBinary;
compilerHash;
linkerVersion;
apiKey;
secret;
license;
constructor(pathToBinary, compilerHash, linkerVersion, apiKey, secret, license) {
this.pathToBinary = pathToBinary;
this.compilerHash = compilerHash;
this.linkerVersion = linkerVersion;
this.apiKey = apiKey;
this.secret = secret;
this.license = license;
}
verify = async ({ contractsPath, restParams }) => {
const cliCommand = `${this.pathToBinary} verify -i ${contractsPath || "contracts"} --license ${this.license} --api-key ${this.apiKey} --secret ${this.secret} --compiler-version ${this.compilerHash} --linker-version ${this.linkerVersion} -I ${(0, utils_1.tryToGetNodeModules)() || "node_modules"} --compile-all --assume-yes ${restParams.join(" ")}`;
const child = (0, child_process_1.exec)(cliCommand);
await new Promise((r, e) => {
child.stdout?.on("data", (data) => {
if (data.includes("Waiting for verification")) {
process.stdout.moveCursor(0, -1);
process.stdout.clearLine(1);
}
console.log(data);
});
child.stderr?.on("error", e);
child.stdout?.on("close", r);
});
};
}
exports.VerificationCli = VerificationCli;
const getVerificationApp = async ({ version, compilerVersion, linkerVersion, secret, apiKey, license, }) => {
const verificationPathsRootPath = (0, env_paths_1.default)("loclift_verification").cache;
fs.ensureDirSync(verificationPathsRootPath);
const releases = await (0, utils_1.getVerificationAppReleases)();
const verificationVersion = version === "latest" ? releases[0] : releases.find((el) => el === version);
if (!verificationVersion) {
throw new Error(`Not found verification app version ${version}\n supported versions: ${releases.join(", ")}`);
}
// Check compiler
const compilerToHashMapPath = path_1.default.resolve(verificationPathsRootPath, "compiler-to-commit.json");
const compilerHash = await (0, utils_1.getCompilerHash)({ compilerToHashMapPath, compilerVersion });
const { compilers, linkers } = await (0, utils_1.getSupportedCompilers)().catch((e) => {
throw new Error(`Fetch supported compilers error ${e}`);
});
const isCompilerSupported = compilers.some((compiler) => compiler === compilerHash);
if (!isCompilerSupported) {
throw new Error(`Compiler ${compilerVersion} not supported\n supported compilers: ${compilers.join(", ")}`);
}
const isLinkerSupported = linkers.some((linker) => linker === linkerVersion);
if (!isLinkerSupported) {
throw new Error(`Linker ${linkerVersion} not supported\n supported linkers: ${linkers.join(", ")}`);
}
const platform = (0, utils_1.getPlatform)();
const pathToVerificationApp = path_1.default.resolve(`${verificationPathsRootPath}/${verificationVersion}/${platform}`);
fs.ensureDirSync(`${verificationPathsRootPath}/${verificationVersion}`);
const pathToBinaries = await (0, utils_1.getPathToBinaries)({
pathToVerificationApp: pathToVerificationApp,
version: verificationVersion,
});
return new VerificationCli(pathToBinaries, compilerHash, linkerVersion, apiKey, secret, license);
};
exports.getVerificationApp = getVerificationApp;