Overcome undefined "Web3.utils" on web3@1.0.0-beta41
Jordi ledfusion@users.noreply.github.com
Tue, 12 Feb 2019 12:19:17 +0100
3 files changed,
14 insertions(+),
14 deletions(-)
M
src/evmasm.js
→
src/evmasm.js
@@ -3,7 +3,7 @@ // License: LGPL-3.0+
// -const Web3 = require("web3"); +const Web3Utils = require("web3-utils"); const assert = require("assert"); class Contract {@@ -39,7 +39,7 @@ C.return();
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 @@ this._fillLabel(name);
} 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);
M
src/mimc7.js
→
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<nRounds; i++) { - c = Web3.utils.keccak256(c); + c = Web3Utils.keccak256(c); - const n1 = Web3.utils.toBN(c).mod(Web3.utils.toBN(F.q.toString())); - const c2 = Web3.utils.padLeft(Web3.utils.toHex(n1), 64); - cts[i] = bigInt(Web3.utils.toBN(c2).toString()); + const n1 = Web3Utils.toBN(c).mod(Web3Utils.toBN(F.q.toString())); + const c2 = Web3Utils.padLeft(Web3Utils.toHex(n1), 64); + cts[i] = bigInt(Web3Utils.toBN(c2).toString()); } cts[0] = bigInt(0); return cts;
M
src/mimc_gencontract.js
→
src/mimc_gencontract.js
@@ -2,13 +2,13 @@ // Copyright (c) 2018 Jordi Baylina
// License: LGPL-3.0+ // -const Web3 = require("web3"); +const Web3Utils = require("web3-utils"); const Contract = require("./evmasm"); function createCode(seed, n) { - let ci = Web3.utils.keccak256(seed); + let ci = Web3Utils.keccak256(seed); const C = new Contract();@@ -51,7 +51,7 @@ C.mulmod(); // c=t^6 t q k q
C.mulmod(); // r=t^7 k q for (let i=0; i<n-1; i++) { - ci = Web3.utils.keccak256(ci); + ci = Web3Utils.keccak256(ci); C.dup(2); // q r k q C.dup(0); // q q r k q C.dup(0); // q q q r k q