UNPKG

@runonflux/aa-schnorr-multisig-sdk

Version:

Account Abstraction Schnorr Multi-Signatures SDK

60 lines (59 loc) 2.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.compile = compile; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); // solc js doesn't support typescript so we hack it let _solc = null; function getSolc() { if (!_solc) _solc = require("solc"); return _solc; } // a function that compiles a contract at run time as long // as that contract and all its includes are in the /contracts folder // // contractName - the name of the contract, not the file name // options // - fileName - if the name of the file is different than the name // of the contract, it should be passed along as we cannot guess it function compile(contractName, options = {}) { const fileName = options.fileName ? options.fileName : `${contractName}.sol`; const contractsFolder = options.contractsFolder ? options.contractsFolder : "contracts"; const contractPath = path_1.default.resolve(`${__dirname}../../`, contractsFolder, fileName); const contractSource = fs_1.default.readFileSync(contractPath, { encoding: "utf8" }); const input = { language: "Solidity", sources: { [contractName]: { content: contractSource, }, }, settings: { viaIR: true, optimizer: { enabled: true, runs: 1000, }, outputSelection: { "*": { "*": ["*"], }, }, }, }; function findImports(libPath) { return { contents: fs_1.default.readFileSync(path_1.default.resolve(`${__dirname}../../../../`, "contracts", libPath), { encoding: "utf8" }), }; } const output = JSON.parse(getSolc().compile(JSON.stringify(input), { import: findImports })); return { abi: output.contracts[contractName][contractName].abi, bytecode: `0x${output.contracts[contractName][contractName].evm.bytecode.object}`, // bin deployBytecode: `0x${output.contracts[contractName][contractName].evm.deployedBytecode.object}`, // binRuntime }; }