From 138945bfdcd0a9c59f2b7fe20dff8bcf70a353da Mon Sep 17 00:00:00 2001 From: Jordi Date: Tue, 12 Feb 2019 12:19:17 +0100 Subject: [PATCH] Overcome undefined "Web3.utils" on web3@1.0.0-beta41 --- src/evmasm.js | 6 +++--- src/mimc7.js | 16 ++++++++-------- src/mimc_gencontract.js | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/evmasm.js b/src/evmasm.js index d68f791..351201b 100644 --- a/src/evmasm.js +++ b/src/evmasm.js @@ -3,7 +3,7 @@ // -const Web3 = require("web3"); +const Web3Utils = require("web3-utils"); const assert = require("assert"); class Contract { @@ -39,7 +39,7 @@ class Contract { genLoadedLength = C.code.length; } - return Web3.utils.bytesToHex(C.code.concat(this.code)); + return Web3Utils.bytesToHex(C.code.concat(this.code)); } stop() { this.code.push(0x00); } @@ -149,7 +149,7 @@ class Contract { } push(data) { - const d = Web3.utils.hexToBytes(Web3.utils.toHex(data)); + const d = Web3Utils.hexToBytes(Web3Utils.toHex(data)); assert(d.length>0); assert(d.length<=32); this.code = this.code.concat([0x5F + d.length], d); diff --git a/src/mimc7.js b/src/mimc7.js index dda4b07..47291d8 100644 --- a/src/mimc7.js +++ b/src/mimc7.js @@ -1,6 +1,6 @@ const bn128 = require("snarkjs").bn128; const bigInt = require("snarkjs").bigInt; -const Web3 = require("web3"); +const Web3Utils = require("web3-utils"); const F = bn128.Fr; const SEED = "mimc"; @@ -8,8 +8,8 @@ const NROUNDS = 91; exports.getIV = (seed) => { if (typeof seed === "undefined") seed = SEED; - const c = Web3.utils.keccak256(seed+"_iv"); - const cn = bigInt(Web3.utils.toBN(c).toString()); + const c = Web3Utils.keccak256(seed+"_iv"); + const cn = bigInt(Web3Utils.toBN(c).toString()); const iv = cn.mod(F.q); return iv; }; @@ -18,13 +18,13 @@ exports.getConstants = (seed, nRounds) => { if (typeof seed === "undefined") seed = SEED; if (typeof nRounds === "undefined") nRounds = NROUNDS; const cts = new Array(nRounds); - let c = Web3.utils.keccak256(SEED); + let c = Web3Utils.keccak256(SEED); for (let i=1; i