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mDAEf,CACD,MAAM,EAAM,KAAK,WACX,eACN,EAAI,aAAa,EAAI,MACrB,EAAI,cAAc,GAClB,EAAI,cAAc,EACtB,CACJ,CACA,KAAK,gBAAiB,CAzBtB,CA0BJ,CAWA,cAAM,CAAS,GAEX,aADM,KAAK,OACJ,WAAW,QAAQ,KAAK,KAAxB,CAA8B,EACzC,CAUA,WAAM,CAAM,GAER,aADM,KAAK,OACJ,QAAQ,QAAQ,KAAK,KAArB,CAA2B,EACtC,CAQA,aAAM,CAAQ,GAEV,aADM,KAAK,OACJ,UAAU,QAAQ,KAAK,KAAvB,CAA6B,EACxC,CAKA,gBAAA,GACI,OAAO,EAAI,UAAU,iBAAiB,KAAK,QAC/C,CAIA,IAAA,GACI,OAAO,IAAI,GAAG,CACV,aAAc,KAAK,aAAa,OAChC,WAAY,KAAK,WACjB,OAAQ,KAAK,QACb,QAAS,KAAK,SAEtB,EAEJ,QAAQ,GAAK","file":"/npm/@rei-network/vm@3.0.4/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@rei-network/vm@3.0.4/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.VM = void 0;\nconst ethereumjs_util_1 = require(\"ethereumjs-util\");\nconst common_1 = require(\"@rei-network/common\");\nconst binding_1 = require(\"./binding\");\nconst runCall_1 = __importDefault(require(\"./runCall\"));\nconst runTx_1 = __importDefault(require(\"./runTx\"));\nconst runBlock_1 = __importDefault(require(\"./runBlock\"));\nconst evm_1 = require(\"./evm/evm\");\nconst opcodes_1 = require(\"./evm/opcodes\");\nconst precompiles_1 = require(\"./evm/precompiles\");\nconst AsyncEventEmitter = require('async-eventemitter');\nconst promisify = require('util.promisify');\n// very ugly way to detect if we are running in a browser\nconst isBrowser = new Function('try {return this===window;}catch(e){ return false;}');\nlet mcl;\nlet mclInitPromise;\nif (!isBrowser()) {\n    mcl = require('mcl-wasm');\n    mclInitPromise = mcl.init(mcl.BLS12_381);\n}\n/**\n * Execution engine which can be used to run a blockchain, individual\n * blocks, individual transactions, or snippets of EVM bytecode.\n *\n * This class is an AsyncEventEmitter, please consult the README to learn how to use it.\n */\nclass VM extends AsyncEventEmitter {\n    /**\n     * VM async constructor. Creates engine instance and initializes it.\n     *\n     * @param opts VM engine constructor options\n     */\n    static async create(opts) {\n        const vm = new this(opts);\n        await vm.init();\n        return vm;\n    }\n    /**\n     * Instantiates a new {@link VM} Object.\n     * @param opts\n     */\n    constructor(opts) {\n        var _a, _b, _c;\n        super();\n        this._isInitialized = false;\n        /**\n         * VM is run in DEBUG mode (default: false)\n         * Taken from DEBUG environment variable\n         *\n         * Safeguards on debug() calls are added for\n         * performance reasons to avoid string literal evaluation\n         * @hidden\n         */\n        this.DEBUG = false;\n        this._opts = opts;\n        this._getMiner = opts.getMiner;\n        // Throw on chain or hardfork options removed in latest major release\n        // to prevent implicit chain setup on a wrong chain\n        if ('chain' in opts || 'hardfork' in opts) {\n            throw new Error('Chain/hardfork options are not allowed any more on initialization');\n        }\n        if (opts.common) {\n            //EIPs\n            const supportedEIPs = [\n                1559, 2315, 2537, 2565, 2718, 2929, 2930, 3198, 3529, 3541\n            ];\n            for (const eip of opts.common.eips()) {\n                if (!supportedEIPs.includes(eip) && eip < 100000) {\n                    throw new Error(`${eip} is not supported by the VM`);\n                }\n            }\n            this._common = opts.common;\n        }\n        else {\n            const DEFAULT_CHAIN = common_1.Chain.Mainnet;\n            const supportedHardforks = [\n                'chainstart',\n                'homestead',\n                'dao',\n                'tangerineWhistle',\n                'spuriousDragon',\n                'byzantium',\n                'constantinople',\n                'petersburg',\n                'istanbul',\n                'muirGlacier',\n                'berlin'\n            ];\n            this._common = new common_1.Common({\n                chain: DEFAULT_CHAIN,\n                supportedHardforks\n            });\n        }\n        if (opts.listenHardforkChanged) {\n            this._common.on('hardforkChanged', () => {\n                this._opcodes = (0, opcodes_1.getOpcodesForHF)(this._common);\n            });\n        }\n        // Set list of opcodes based on HF\n        // TODO: make this EIP-friendly\n        this._opcodes = (0, opcodes_1.getOpcodesForHF)(this._common);\n        this.stateManager = opts.stateManager;\n        this.blockchain = opts.blockchain;\n        this._allowUnlimitedContractSize = (_a = opts.allowUnlimitedContractSize) !== null && _a !== void 0 ? _a : false;\n        this._hardforkByBlockNumber = (_b = opts.hardforkByBlockNumber) !== null && _b !== void 0 ? _b : false;\n        if (this._common.isActivatedEIP(2537)) {\n            if (isBrowser()) {\n                throw new Error('EIP-2537 is currently not supported in browsers');\n            }\n            else {\n                this._mcl = mcl;\n            }\n        }\n        // Safeguard if \"process\" is not available (browser)\n        if (process !== undefined && process.env.DEBUG) {\n            this.DEBUG = true;\n        }\n        // We cache this promisified function as it's called from the main execution loop, and\n        // promisifying each time has a huge performance impact.\n        this._emit = promisify(this.emit.bind(this));\n        // Save leveldb pointer\n        this.exposed = opts.exposed;\n        // Save evm work mode\n        this.mode = (_c = opts.mode) !== null && _c !== void 0 ? _c : evm_1.EVMWorkMode.JS;\n        if (this.exposed && this.mode === evm_1.EVMWorkMode.Binding) {\n            // Constructor binding object if pointer exists\n            this.binding = (0, binding_1.createBinding)(this.exposed, this._common.chainId());\n        }\n    }\n    async init() {\n        if (this._isInitialized) {\n            return;\n        }\n        await this.blockchain.initPromise;\n        if (this._opts.activatePrecompiles && !this._opts.stateManager) {\n            await this.stateManager.checkpoint();\n            // put 1 wei in each of the precompiles in order to make the accounts non-empty and thus not have them deduct `callNewAccount` gas.\n            await Promise.all(Object.keys(precompiles_1.precompiles)\n                .map((k) => new ethereumjs_util_1.Address(Buffer.from(k, 'hex')))\n                .map(async (address) => {\n                const account = ethereumjs_util_1.Account.fromAccountData({ balance: 1 });\n                await this.stateManager.putAccount(address, account);\n            }));\n            await this.stateManager.commit();\n        }\n        if (this._common.isActivatedEIP(2537)) {\n            if (isBrowser()) {\n                throw new Error('EIP-2537 is currently not supported in browsers');\n            }\n            else {\n                const mcl = this._mcl;\n                await mclInitPromise; // ensure that mcl is initialized.\n                mcl.setMapToMode(mcl.IRTF); // set the right map mode; otherwise mapToG2 will return wrong values.\n                mcl.verifyOrderG1(1); // subgroup checks for G1\n                mcl.verifyOrderG2(1); // subgroup checks for G2\n            }\n        }\n        this._isInitialized = true;\n    }\n    /**\n     * Processes the `block` running all of the transactions it contains and updating the miner's account\n     *\n     * This method modifies the state. If `generate` is `true`, the state modifications will be\n     * reverted if an exception is raised. If it's `false`, it won't revert if the block's header is\n     * invalid. If an error is thrown from an event handler, the state may or may not be reverted.\n     *\n     * @param {RunBlockOpts} opts - Default values for options:\n     *  - `generate`: false\n     */\n    async runBlock(opts) {\n        await this.init();\n        return runBlock_1.default.bind(this)(opts);\n    }\n    /**\n     * Process a transaction. Run the vm. Transfers eth. Checks balances.\n     *\n     * This method modifies the state. If an error is thrown, the modifications are reverted, except\n     * when the error is thrown from an event handler. In the latter case the state may or may not be\n     * reverted.\n     *\n     * @param {RunTxOpts} opts\n     */\n    async runTx(opts) {\n        await this.init();\n        return runTx_1.default.bind(this)(opts);\n    }\n    /**\n     * runs a call (or create) operation.\n     *\n     * This method modifies the state.\n     *\n     * @param {RunCallOpts} opts\n     */\n    async runCall(opts) {\n        await this.init();\n        return runCall_1.default.bind(this)(opts);\n    }\n    /**\n     * Returns a list with the currently activated opcodes\n     * available for VM execution\n     */\n    getActiveOpcodes() {\n        return (0, opcodes_1.getOpcodesForHF)(this._common);\n    }\n    /**\n     * Returns a copy of the {@link VM} instance.\n     */\n    copy() {\n        return new VM({\n            stateManager: this.stateManager.copy(),\n            blockchain: this.blockchain,\n            common: this._common,\n            exposed: this.exposed\n        });\n    }\n}\nexports.VM = VM;\n"]}