From 815ea7c4e59792c46d995402180c9f596abb819f Mon Sep 17 00:00:00 2001 From: Theo Date: Tue, 12 Sep 2023 01:51:08 -0700 Subject: [PATCH] Change dependency resolving & package name to use in self-hosted registry --- .npmrc | 1 + build/websnark.js | 3507 ++++++++++++++++++++++++++++++------------- example/websnark.js | 3507 ++++++++++++++++++++++++++++++------------- package-lock.json | 467 +++--- package.json | 76 +- src/utils.js | 40 +- test/bn128.js | 20 +- test/fft.js | 106 +- test/groth16.js | 17 +- 9 files changed, 5341 insertions(+), 2400 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..05ba80e --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@tornado:registry=https://git.tornado.ws/api/packages/tornado-packages/npm/ \ No newline at end of file diff --git a/build/websnark.js b/build/websnark.js index d90e0c5..b5dbdbd 100644 --- a/build/websnark.js +++ b/build/websnark.js @@ -6,7 +6,7 @@ exports.pr = 1768; }).call(this,require("buffer").Buffer) -},{"buffer":9}],2:[function(require,module,exports){ +},{"buffer":14}],2:[function(require,module,exports){ /* Copyright 2019 0KIMS association. @@ -61,7 +61,2473 @@ buildGroth16().then((groth16) => { } }; }); -},{"./src/groth16":17,"./src/utils":18}],3:[function(require,module,exports){ +},{"./src/groth16":18,"./src/utils":19}],3:[function(require,module,exports){ +var bigInt = (function (undefined) { + "use strict"; + + var BASE = 1e7, + LOG_BASE = 7, + MAX_INT = 9007199254740992, + MAX_INT_ARR = smallToArray(MAX_INT), + DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"; + + var supportsNativeBigInt = typeof BigInt === "function"; + + function Integer(v, radix, alphabet, caseSensitive) { + if (typeof v === "undefined") return Integer[0]; + if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive); + return parseValue(v); + } + + function BigInteger(value, sign) { + this.value = value; + this.sign = sign; + this.isSmall = false; + } + BigInteger.prototype = Object.create(Integer.prototype); + + function SmallInteger(value) { + this.value = value; + this.sign = value < 0; + this.isSmall = true; + } + SmallInteger.prototype = Object.create(Integer.prototype); + + function NativeBigInt(value) { + this.value = value; + } + NativeBigInt.prototype = Object.create(Integer.prototype); + + function isPrecise(n) { + return -MAX_INT < n && n < MAX_INT; + } + + function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes + if (n < 1e7) + return [n]; + if (n < 1e14) + return [n % 1e7, Math.floor(n / 1e7)]; + return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)]; + } + + function arrayToSmall(arr) { // If BASE changes this function may need to change + trim(arr); + var length = arr.length; + if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) { + switch (length) { + case 0: return 0; + case 1: return arr[0]; + case 2: return arr[0] + arr[1] * BASE; + default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE; + } + } + return arr; + } + + function trim(v) { + var i = v.length; + while (v[--i] === 0); + v.length = i + 1; + } + + function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger + var x = new Array(length); + var i = -1; + while (++i < length) { + x[i] = 0; + } + return x; + } + + function truncate(n) { + if (n > 0) return Math.floor(n); + return Math.ceil(n); + } + + function add(a, b) { // assumes a and b are arrays with a.length >= b.length + var l_a = a.length, + l_b = b.length, + r = new Array(l_a), + carry = 0, + base = BASE, + sum, i; + for (i = 0; i < l_b; i++) { + sum = a[i] + b[i] + carry; + carry = sum >= base ? 1 : 0; + r[i] = sum - carry * base; + } + while (i < l_a) { + sum = a[i] + carry; + carry = sum === base ? 1 : 0; + r[i++] = sum - carry * base; + } + if (carry > 0) r.push(carry); + return r; + } + + function addAny(a, b) { + if (a.length >= b.length) return add(a, b); + return add(b, a); + } + + function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT + var l = a.length, + r = new Array(l), + base = BASE, + sum, i; + for (i = 0; i < l; i++) { + sum = a[i] - base + carry; + carry = Math.floor(sum / base); + r[i] = sum - carry * base; + carry += 1; + } + while (carry > 0) { + r[i++] = carry % base; + carry = Math.floor(carry / base); + } + return r; + } + + BigInteger.prototype.add = function (v) { + var n = parseValue(v); + if (this.sign !== n.sign) { + return this.subtract(n.negate()); + } + var a = this.value, b = n.value; + if (n.isSmall) { + return new BigInteger(addSmall(a, Math.abs(b)), this.sign); + } + return new BigInteger(addAny(a, b), this.sign); + }; + BigInteger.prototype.plus = BigInteger.prototype.add; + + SmallInteger.prototype.add = function (v) { + var n = parseValue(v); + var a = this.value; + if (a < 0 !== n.sign) { + return this.subtract(n.negate()); + } + var b = n.value; + if (n.isSmall) { + if (isPrecise(a + b)) return new SmallInteger(a + b); + b = smallToArray(Math.abs(b)); + } + return new BigInteger(addSmall(b, Math.abs(a)), a < 0); + }; + SmallInteger.prototype.plus = SmallInteger.prototype.add; + + NativeBigInt.prototype.add = function (v) { + return new NativeBigInt(this.value + parseValue(v).value); + } + NativeBigInt.prototype.plus = NativeBigInt.prototype.add; + + function subtract(a, b) { // assumes a and b are arrays with a >= b + var a_l = a.length, + b_l = b.length, + r = new Array(a_l), + borrow = 0, + base = BASE, + i, difference; + for (i = 0; i < b_l; i++) { + difference = a[i] - borrow - b[i]; + if (difference < 0) { + difference += base; + borrow = 1; + } else borrow = 0; + r[i] = difference; + } + for (i = b_l; i < a_l; i++) { + difference = a[i] - borrow; + if (difference < 0) difference += base; + else { + r[i++] = difference; + break; + } + r[i] = difference; + } + for (; i < a_l; i++) { + r[i] = a[i]; + } + trim(r); + return r; + } + + function subtractAny(a, b, sign) { + var value; + if (compareAbs(a, b) >= 0) { + value = subtract(a, b); + } else { + value = subtract(b, a); + sign = !sign; + } + value = arrayToSmall(value); + if (typeof value === "number") { + if (sign) value = -value; + return new SmallInteger(value); + } + return new BigInteger(value, sign); + } + + function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT + var l = a.length, + r = new Array(l), + carry = -b, + base = BASE, + i, difference; + for (i = 0; i < l; i++) { + difference = a[i] + carry; + carry = Math.floor(difference / base); + difference %= base; + r[i] = difference < 0 ? difference + base : difference; + } + r = arrayToSmall(r); + if (typeof r === "number") { + if (sign) r = -r; + return new SmallInteger(r); + } return new BigInteger(r, sign); + } + + BigInteger.prototype.subtract = function (v) { + var n = parseValue(v); + if (this.sign !== n.sign) { + return this.add(n.negate()); + } + var a = this.value, b = n.value; + if (n.isSmall) + return subtractSmall(a, Math.abs(b), this.sign); + return subtractAny(a, b, this.sign); + }; + BigInteger.prototype.minus = BigInteger.prototype.subtract; + + SmallInteger.prototype.subtract = function (v) { + var n = parseValue(v); + var a = this.value; + if (a < 0 !== n.sign) { + return this.add(n.negate()); + } + var b = n.value; + if (n.isSmall) { + return new SmallInteger(a - b); + } + return subtractSmall(b, Math.abs(a), a >= 0); + }; + SmallInteger.prototype.minus = SmallInteger.prototype.subtract; + + NativeBigInt.prototype.subtract = function (v) { + return new NativeBigInt(this.value - parseValue(v).value); + } + NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract; + + BigInteger.prototype.negate = function () { + return new BigInteger(this.value, !this.sign); + }; + SmallInteger.prototype.negate = function () { + var sign = this.sign; + var small = new SmallInteger(-this.value); + small.sign = !sign; + return small; + }; + NativeBigInt.prototype.negate = function () { + return new NativeBigInt(-this.value); + } + + BigInteger.prototype.abs = function () { + return new BigInteger(this.value, false); + }; + SmallInteger.prototype.abs = function () { + return new SmallInteger(Math.abs(this.value)); + }; + NativeBigInt.prototype.abs = function () { + return new NativeBigInt(this.value >= 0 ? this.value : -this.value); + } + + + function multiplyLong(a, b) { + var a_l = a.length, + b_l = b.length, + l = a_l + b_l, + r = createArray(l), + base = BASE, + product, carry, i, a_i, b_j; + for (i = 0; i < a_l; ++i) { + a_i = a[i]; + for (var j = 0; j < b_l; ++j) { + b_j = b[j]; + product = a_i * b_j + r[i + j]; + carry = Math.floor(product / base); + r[i + j] = product - carry * base; + r[i + j + 1] += carry; + } + } + trim(r); + return r; + } + + function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE + var l = a.length, + r = new Array(l), + base = BASE, + carry = 0, + product, i; + for (i = 0; i < l; i++) { + product = a[i] * b + carry; + carry = Math.floor(product / base); + r[i] = product - carry * base; + } + while (carry > 0) { + r[i++] = carry % base; + carry = Math.floor(carry / base); + } + return r; + } + + function shiftLeft(x, n) { + var r = []; + while (n-- > 0) r.push(0); + return r.concat(x); + } + + function multiplyKaratsuba(x, y) { + var n = Math.max(x.length, y.length); + + if (n <= 30) return multiplyLong(x, y); + n = Math.ceil(n / 2); + + var b = x.slice(n), + a = x.slice(0, n), + d = y.slice(n), + c = y.slice(0, n); + + var ac = multiplyKaratsuba(a, c), + bd = multiplyKaratsuba(b, d), + abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); + + var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); + trim(product); + return product; + } + + // The following function is derived from a surface fit of a graph plotting the performance difference + // between long multiplication and karatsuba multiplication versus the lengths of the two arrays. + function useKaratsuba(l1, l2) { + return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0; + } + + BigInteger.prototype.multiply = function (v) { + var n = parseValue(v), + a = this.value, b = n.value, + sign = this.sign !== n.sign, + abs; + if (n.isSmall) { + if (b === 0) return Integer[0]; + if (b === 1) return this; + if (b === -1) return this.negate(); + abs = Math.abs(b); + if (abs < BASE) { + return new BigInteger(multiplySmall(a, abs), sign); + } + b = smallToArray(abs); + } + if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes + return new BigInteger(multiplyKaratsuba(a, b), sign); + return new BigInteger(multiplyLong(a, b), sign); + }; + + BigInteger.prototype.times = BigInteger.prototype.multiply; + + function multiplySmallAndArray(a, b, sign) { // a >= 0 + if (a < BASE) { + return new BigInteger(multiplySmall(b, a), sign); + } + return new BigInteger(multiplyLong(b, smallToArray(a)), sign); + } + SmallInteger.prototype._multiplyBySmall = function (a) { + if (isPrecise(a.value * this.value)) { + return new SmallInteger(a.value * this.value); + } + return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign); + }; + BigInteger.prototype._multiplyBySmall = function (a) { + if (a.value === 0) return Integer[0]; + if (a.value === 1) return this; + if (a.value === -1) return this.negate(); + return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign); + }; + SmallInteger.prototype.multiply = function (v) { + return parseValue(v)._multiplyBySmall(this); + }; + SmallInteger.prototype.times = SmallInteger.prototype.multiply; + + NativeBigInt.prototype.multiply = function (v) { + return new NativeBigInt(this.value * parseValue(v).value); + } + NativeBigInt.prototype.times = NativeBigInt.prototype.multiply; + + function square(a) { + //console.assert(2 * BASE * BASE < MAX_INT); + var l = a.length, + r = createArray(l + l), + base = BASE, + product, carry, i, a_i, a_j; + for (i = 0; i < l; i++) { + a_i = a[i]; + carry = 0 - a_i * a_i; + for (var j = i; j < l; j++) { + a_j = a[j]; + product = 2 * (a_i * a_j) + r[i + j] + carry; + carry = Math.floor(product / base); + r[i + j] = product - carry * base; + } + r[i + l] = carry; + } + trim(r); + return r; + } + + BigInteger.prototype.square = function () { + return new BigInteger(square(this.value), false); + }; + + SmallInteger.prototype.square = function () { + var value = this.value * this.value; + if (isPrecise(value)) return new SmallInteger(value); + return new BigInteger(square(smallToArray(Math.abs(this.value))), false); + }; + + NativeBigInt.prototype.square = function (v) { + return new NativeBigInt(this.value * this.value); + } + + function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes. + var a_l = a.length, + b_l = b.length, + base = BASE, + result = createArray(b.length), + divisorMostSignificantDigit = b[b_l - 1], + // normalization + lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), + remainder = multiplySmall(a, lambda), + divisor = multiplySmall(b, lambda), + quotientDigit, shift, carry, borrow, i, l, q; + if (remainder.length <= a_l) remainder.push(0); + divisor.push(0); + divisorMostSignificantDigit = divisor[b_l - 1]; + for (shift = a_l - b_l; shift >= 0; shift--) { + quotientDigit = base - 1; + if (remainder[shift + b_l] !== divisorMostSignificantDigit) { + quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit); + } + // quotientDigit <= base - 1 + carry = 0; + borrow = 0; + l = divisor.length; + for (i = 0; i < l; i++) { + carry += quotientDigit * divisor[i]; + q = Math.floor(carry / base); + borrow += remainder[shift + i] - (carry - q * base); + carry = q; + if (borrow < 0) { + remainder[shift + i] = borrow + base; + borrow = -1; + } else { + remainder[shift + i] = borrow; + borrow = 0; + } + } + while (borrow !== 0) { + quotientDigit -= 1; + carry = 0; + for (i = 0; i < l; i++) { + carry += remainder[shift + i] - base + divisor[i]; + if (carry < 0) { + remainder[shift + i] = carry + base; + carry = 0; + } else { + remainder[shift + i] = carry; + carry = 1; + } + } + borrow += carry; + } + result[shift] = quotientDigit; + } + // denormalization + remainder = divModSmall(remainder, lambda)[0]; + return [arrayToSmall(result), arrayToSmall(remainder)]; + } + + function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/ + // Performs faster than divMod1 on larger input sizes. + var a_l = a.length, + b_l = b.length, + result = [], + part = [], + base = BASE, + guess, xlen, highx, highy, check; + while (a_l) { + part.unshift(a[--a_l]); + trim(part); + if (compareAbs(part, b) < 0) { + result.push(0); + continue; + } + xlen = part.length; + highx = part[xlen - 1] * base + part[xlen - 2]; + highy = b[b_l - 1] * base + b[b_l - 2]; + if (xlen > b_l) { + highx = (highx + 1) * base; + } + guess = Math.ceil(highx / highy); + do { + check = multiplySmall(b, guess); + if (compareAbs(check, part) <= 0) break; + guess--; + } while (guess); + result.push(guess); + part = subtract(part, check); + } + result.reverse(); + return [arrayToSmall(result), arrayToSmall(part)]; + } + + function divModSmall(value, lambda) { + var length = value.length, + quotient = createArray(length), + base = BASE, + i, q, remainder, divisor; + remainder = 0; + for (i = length - 1; i >= 0; --i) { + divisor = remainder * base + value[i]; + q = truncate(divisor / lambda); + remainder = divisor - q * lambda; + quotient[i] = q | 0; + } + return [quotient, remainder | 0]; + } + + function divModAny(self, v) { + var value, n = parseValue(v); + if (supportsNativeBigInt) { + return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)]; + } + var a = self.value, b = n.value; + var quotient; + if (b === 0) throw new Error("Cannot divide by zero"); + if (self.isSmall) { + if (n.isSmall) { + return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)]; + } + return [Integer[0], self]; + } + if (n.isSmall) { + if (b === 1) return [self, Integer[0]]; + if (b == -1) return [self.negate(), Integer[0]]; + var abs = Math.abs(b); + if (abs < BASE) { + value = divModSmall(a, abs); + quotient = arrayToSmall(value[0]); + var remainder = value[1]; + if (self.sign) remainder = -remainder; + if (typeof quotient === "number") { + if (self.sign !== n.sign) quotient = -quotient; + return [new SmallInteger(quotient), new SmallInteger(remainder)]; + } + return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)]; + } + b = smallToArray(abs); + } + var comparison = compareAbs(a, b); + if (comparison === -1) return [Integer[0], self]; + if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; + + // divMod1 is faster on smaller input sizes + if (a.length + b.length <= 200) + value = divMod1(a, b); + else value = divMod2(a, b); + + quotient = value[0]; + var qSign = self.sign !== n.sign, + mod = value[1], + mSign = self.sign; + if (typeof quotient === "number") { + if (qSign) quotient = -quotient; + quotient = new SmallInteger(quotient); + } else quotient = new BigInteger(quotient, qSign); + if (typeof mod === "number") { + if (mSign) mod = -mod; + mod = new SmallInteger(mod); + } else mod = new BigInteger(mod, mSign); + return [quotient, mod]; + } + + BigInteger.prototype.divmod = function (v) { + var result = divModAny(this, v); + return { + quotient: result[0], + remainder: result[1] + }; + }; + NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod; + + + BigInteger.prototype.divide = function (v) { + return divModAny(this, v)[0]; + }; + NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function (v) { + return new NativeBigInt(this.value / parseValue(v).value); + }; + SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide; + + BigInteger.prototype.mod = function (v) { + return divModAny(this, v)[1]; + }; + NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function (v) { + return new NativeBigInt(this.value % parseValue(v).value); + }; + SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod; + + BigInteger.prototype.pow = function (v) { + var n = parseValue(v), + a = this.value, + b = n.value, + value, x, y; + if (b === 0) return Integer[1]; + if (a === 0) return Integer[0]; + if (a === 1) return Integer[1]; + if (a === -1) return n.isEven() ? Integer[1] : Integer[-1]; + if (n.sign) { + return Integer[0]; + } + if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large."); + if (this.isSmall) { + if (isPrecise(value = Math.pow(a, b))) + return new SmallInteger(truncate(value)); + } + x = this; + y = Integer[1]; + while (true) { + if (b & 1 === 1) { + y = y.times(x); + --b; + } + if (b === 0) break; + b /= 2; + x = x.square(); + } + return y; + }; + SmallInteger.prototype.pow = BigInteger.prototype.pow; + + NativeBigInt.prototype.pow = function (v) { + var n = parseValue(v); + var a = this.value, b = n.value; + var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2); + if (b === _0) return Integer[1]; + if (a === _0) return Integer[0]; + if (a === _1) return Integer[1]; + if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1]; + if (n.isNegative()) return new NativeBigInt(_0); + var x = this; + var y = Integer[1]; + while (true) { + if ((b & _1) === _1) { + y = y.times(x); + --b; + } + if (b === _0) break; + b /= _2; + x = x.square(); + } + return y; + } + + BigInteger.prototype.modPow = function (exp, mod) { + exp = parseValue(exp); + mod = parseValue(mod); + if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0"); + var r = Integer[1], + base = this.mod(mod); + if (exp.isNegative()) { + exp = exp.multiply(Integer[-1]); + base = base.modInv(mod); + } + while (exp.isPositive()) { + if (base.isZero()) return Integer[0]; + if (exp.isOdd()) r = r.multiply(base).mod(mod); + exp = exp.divide(2); + base = base.square().mod(mod); + } + return r; + }; + NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow; + + function compareAbs(a, b) { + if (a.length !== b.length) { + return a.length > b.length ? 1 : -1; + } + for (var i = a.length - 1; i >= 0; i--) { + if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1; + } + return 0; + } + + BigInteger.prototype.compareAbs = function (v) { + var n = parseValue(v), + a = this.value, + b = n.value; + if (n.isSmall) return 1; + return compareAbs(a, b); + }; + SmallInteger.prototype.compareAbs = function (v) { + var n = parseValue(v), + a = Math.abs(this.value), + b = n.value; + if (n.isSmall) { + b = Math.abs(b); + return a === b ? 0 : a > b ? 1 : -1; + } + return -1; + }; + NativeBigInt.prototype.compareAbs = function (v) { + var a = this.value; + var b = parseValue(v).value; + a = a >= 0 ? a : -a; + b = b >= 0 ? b : -b; + return a === b ? 0 : a > b ? 1 : -1; + } + + BigInteger.prototype.compare = function (v) { + // See discussion about comparison with Infinity: + // https://github.com/peterolson/BigInteger.js/issues/61 + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + + var n = parseValue(v), + a = this.value, + b = n.value; + if (this.sign !== n.sign) { + return n.sign ? 1 : -1; + } + if (n.isSmall) { + return this.sign ? -1 : 1; + } + return compareAbs(a, b) * (this.sign ? -1 : 1); + }; + BigInteger.prototype.compareTo = BigInteger.prototype.compare; + + SmallInteger.prototype.compare = function (v) { + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + + var n = parseValue(v), + a = this.value, + b = n.value; + if (n.isSmall) { + return a == b ? 0 : a > b ? 1 : -1; + } + if (a < 0 !== n.sign) { + return a < 0 ? -1 : 1; + } + return a < 0 ? 1 : -1; + }; + SmallInteger.prototype.compareTo = SmallInteger.prototype.compare; + + NativeBigInt.prototype.compare = function (v) { + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + var a = this.value; + var b = parseValue(v).value; + return a === b ? 0 : a > b ? 1 : -1; + } + NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare; + + BigInteger.prototype.equals = function (v) { + return this.compare(v) === 0; + }; + NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals; + + BigInteger.prototype.notEquals = function (v) { + return this.compare(v) !== 0; + }; + NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals; + + BigInteger.prototype.greater = function (v) { + return this.compare(v) > 0; + }; + NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater; + + BigInteger.prototype.lesser = function (v) { + return this.compare(v) < 0; + }; + NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser; + + BigInteger.prototype.greaterOrEquals = function (v) { + return this.compare(v) >= 0; + }; + NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals; + + BigInteger.prototype.lesserOrEquals = function (v) { + return this.compare(v) <= 0; + }; + NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals; + + BigInteger.prototype.isEven = function () { + return (this.value[0] & 1) === 0; + }; + SmallInteger.prototype.isEven = function () { + return (this.value & 1) === 0; + }; + NativeBigInt.prototype.isEven = function () { + return (this.value & BigInt(1)) === BigInt(0); + } + + BigInteger.prototype.isOdd = function () { + return (this.value[0] & 1) === 1; + }; + SmallInteger.prototype.isOdd = function () { + return (this.value & 1) === 1; + }; + NativeBigInt.prototype.isOdd = function () { + return (this.value & BigInt(1)) === BigInt(1); + } + + BigInteger.prototype.isPositive = function () { + return !this.sign; + }; + SmallInteger.prototype.isPositive = function () { + return this.value > 0; + }; + NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive; + + BigInteger.prototype.isNegative = function () { + return this.sign; + }; + SmallInteger.prototype.isNegative = function () { + return this.value < 0; + }; + NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative; + + BigInteger.prototype.isUnit = function () { + return false; + }; + SmallInteger.prototype.isUnit = function () { + return Math.abs(this.value) === 1; + }; + NativeBigInt.prototype.isUnit = function () { + return this.abs().value === BigInt(1); + } + + BigInteger.prototype.isZero = function () { + return false; + }; + SmallInteger.prototype.isZero = function () { + return this.value === 0; + }; + NativeBigInt.prototype.isZero = function () { + return this.value === BigInt(0); + } + + BigInteger.prototype.isDivisibleBy = function (v) { + var n = parseValue(v); + if (n.isZero()) return false; + if (n.isUnit()) return true; + if (n.compareAbs(2) === 0) return this.isEven(); + return this.mod(n).isZero(); + }; + NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy; + + function isBasicPrime(v) { + var n = v.abs(); + if (n.isUnit()) return false; + if (n.equals(2) || n.equals(3) || n.equals(5)) return true; + if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false; + if (n.lesser(49)) return true; + // we don't know if it's prime: let the other functions figure it out + } + + function millerRabinTest(n, a) { + var nPrev = n.prev(), + b = nPrev, + r = 0, + d, t, i, x; + while (b.isEven()) b = b.divide(2), r++; + next: for (i = 0; i < a.length; i++) { + if (n.lesser(a[i])) continue; + x = bigInt(a[i]).modPow(b, n); + if (x.isUnit() || x.equals(nPrev)) continue; + for (d = r - 1; d != 0; d--) { + x = x.square().mod(n); + if (x.isUnit()) return false; + if (x.equals(nPrev)) continue next; + } + return false; + } + return true; + } + + // Set "strict" to true to force GRH-supported lower bound of 2*log(N)^2 + BigInteger.prototype.isPrime = function (strict) { + var isPrime = isBasicPrime(this); + if (isPrime !== undefined) return isPrime; + var n = this.abs(); + var bits = n.bitLength(); + if (bits <= 64) + return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]); + var logN = Math.log(2) * bits.toJSNumber(); + var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN); + for (var a = [], i = 0; i < t; i++) { + a.push(bigInt(i + 2)); + } + return millerRabinTest(n, a); + }; + NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime; + + BigInteger.prototype.isProbablePrime = function (iterations, rng) { + var isPrime = isBasicPrime(this); + if (isPrime !== undefined) return isPrime; + var n = this.abs(); + var t = iterations === undefined ? 5 : iterations; + for (var a = [], i = 0; i < t; i++) { + a.push(bigInt.randBetween(2, n.minus(2), rng)); + } + return millerRabinTest(n, a); + }; + NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime; + + BigInteger.prototype.modInv = function (n) { + var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; + while (!newR.isZero()) { + q = r.divide(newR); + lastT = t; + lastR = r; + t = newT; + r = newR; + newT = lastT.subtract(q.multiply(newT)); + newR = lastR.subtract(q.multiply(newR)); + } + if (!r.isUnit()) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); + if (t.compare(0) === -1) { + t = t.add(n); + } + if (this.isNegative()) { + return t.negate(); + } + return t; + }; + + NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv; + + BigInteger.prototype.next = function () { + var value = this.value; + if (this.sign) { + return subtractSmall(value, 1, this.sign); + } + return new BigInteger(addSmall(value, 1), this.sign); + }; + SmallInteger.prototype.next = function () { + var value = this.value; + if (value + 1 < MAX_INT) return new SmallInteger(value + 1); + return new BigInteger(MAX_INT_ARR, false); + }; + NativeBigInt.prototype.next = function () { + return new NativeBigInt(this.value + BigInt(1)); + } + + BigInteger.prototype.prev = function () { + var value = this.value; + if (this.sign) { + return new BigInteger(addSmall(value, 1), true); + } + return subtractSmall(value, 1, this.sign); + }; + SmallInteger.prototype.prev = function () { + var value = this.value; + if (value - 1 > -MAX_INT) return new SmallInteger(value - 1); + return new BigInteger(MAX_INT_ARR, true); + }; + NativeBigInt.prototype.prev = function () { + return new NativeBigInt(this.value - BigInt(1)); + } + + var powersOfTwo = [1]; + while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]); + var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1]; + + function shift_isSmall(n) { + return Math.abs(n) <= BASE; + } + + BigInteger.prototype.shiftLeft = function (v) { + var n = parseValue(v).toJSNumber(); + if (!shift_isSmall(n)) { + throw new Error(String(n) + " is too large for shifting."); + } + if (n < 0) return this.shiftRight(-n); + var result = this; + if (result.isZero()) return result; + while (n >= powers2Length) { + result = result.multiply(highestPower2); + n -= powers2Length - 1; + } + return result.multiply(powersOfTwo[n]); + }; + NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft; + + BigInteger.prototype.shiftRight = function (v) { + var remQuo; + var n = parseValue(v).toJSNumber(); + if (!shift_isSmall(n)) { + throw new Error(String(n) + " is too large for shifting."); + } + if (n < 0) return this.shiftLeft(-n); + var result = this; + while (n >= powers2Length) { + if (result.isZero() || (result.isNegative() && result.isUnit())) return result; + remQuo = divModAny(result, highestPower2); + result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; + n -= powers2Length - 1; + } + remQuo = divModAny(result, powersOfTwo[n]); + return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; + }; + NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight; + + function bitwise(x, y, fn) { + y = parseValue(y); + var xSign = x.isNegative(), ySign = y.isNegative(); + var xRem = xSign ? x.not() : x, + yRem = ySign ? y.not() : y; + var xDigit = 0, yDigit = 0; + var xDivMod = null, yDivMod = null; + var result = []; + while (!xRem.isZero() || !yRem.isZero()) { + xDivMod = divModAny(xRem, highestPower2); + xDigit = xDivMod[1].toJSNumber(); + if (xSign) { + xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers + } + + yDivMod = divModAny(yRem, highestPower2); + yDigit = yDivMod[1].toJSNumber(); + if (ySign) { + yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers + } + + xRem = xDivMod[0]; + yRem = yDivMod[0]; + result.push(fn(xDigit, yDigit)); + } + var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); + for (var i = result.length - 1; i >= 0; i -= 1) { + sum = sum.multiply(highestPower2).add(bigInt(result[i])); + } + return sum; + } + + BigInteger.prototype.not = function () { + return this.negate().prev(); + }; + NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not; + + BigInteger.prototype.and = function (n) { + return bitwise(this, n, function (a, b) { return a & b; }); + }; + NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and; + + BigInteger.prototype.or = function (n) { + return bitwise(this, n, function (a, b) { return a | b; }); + }; + NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or; + + BigInteger.prototype.xor = function (n) { + return bitwise(this, n, function (a, b) { return a ^ b; }); + }; + NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor; + + var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I; + function roughLOB(n) { // get lowestOneBit (rough) + // SmallInteger: return Min(lowestOneBit(n), 1 << 30) + // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7] + var v = n.value, + x = typeof v === "number" ? v | LOBMASK_I : + typeof v === "bigint" ? v | BigInt(LOBMASK_I) : + v[0] + v[1] * BASE | LOBMASK_BI; + return x & -x; + } + + function integerLogarithm(value, base) { + if (base.compareTo(value) <= 0) { + var tmp = integerLogarithm(value, base.square(base)); + var p = tmp.p; + var e = tmp.e; + var t = p.multiply(base); + return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 }; + } + return { p: bigInt(1), e: 0 }; + } + + BigInteger.prototype.bitLength = function () { + var n = this; + if (n.compareTo(bigInt(0)) < 0) { + n = n.negate().subtract(bigInt(1)); + } + if (n.compareTo(bigInt(0)) === 0) { + return bigInt(0); + } + return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1)); + } + NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength; + + function max(a, b) { + a = parseValue(a); + b = parseValue(b); + return a.greater(b) ? a : b; + } + function min(a, b) { + a = parseValue(a); + b = parseValue(b); + return a.lesser(b) ? a : b; + } + function gcd(a, b) { + a = parseValue(a).abs(); + b = parseValue(b).abs(); + if (a.equals(b)) return a; + if (a.isZero()) return b; + if (b.isZero()) return a; + var c = Integer[1], d, t; + while (a.isEven() && b.isEven()) { + d = min(roughLOB(a), roughLOB(b)); + a = a.divide(d); + b = b.divide(d); + c = c.multiply(d); + } + while (a.isEven()) { + a = a.divide(roughLOB(a)); + } + do { + while (b.isEven()) { + b = b.divide(roughLOB(b)); + } + if (a.greater(b)) { + t = b; b = a; a = t; + } + b = b.subtract(a); + } while (!b.isZero()); + return c.isUnit() ? a : a.multiply(c); + } + function lcm(a, b) { + a = parseValue(a).abs(); + b = parseValue(b).abs(); + return a.divide(gcd(a, b)).multiply(b); + } + function randBetween(a, b, rng) { + a = parseValue(a); + b = parseValue(b); + var usedRNG = rng || Math.random; + var low = min(a, b), high = max(a, b); + var range = high.subtract(low).add(1); + if (range.isSmall) return low.add(Math.floor(usedRNG() * range)); + var digits = toBase(range, BASE).value; + var result = [], restricted = true; + for (var i = 0; i < digits.length; i++) { + var top = restricted ? digits[i] + (i + 1 < digits.length ? digits[i + 1] / BASE : 0) : BASE; + var digit = truncate(usedRNG() * top); + result.push(digit); + if (digit < digits[i]) restricted = false; + } + return low.add(Integer.fromArray(result, BASE, false)); + } + + var parseBase = function (text, base, alphabet, caseSensitive) { + alphabet = alphabet || DEFAULT_ALPHABET; + text = String(text); + if (!caseSensitive) { + text = text.toLowerCase(); + alphabet = alphabet.toLowerCase(); + } + var length = text.length; + var i; + var absBase = Math.abs(base); + var alphabetValues = {}; + for (i = 0; i < alphabet.length; i++) { + alphabetValues[alphabet[i]] = i; + } + for (i = 0; i < length; i++) { + var c = text[i]; + if (c === "-") continue; + if (c in alphabetValues) { + if (alphabetValues[c] >= absBase) { + if (c === "1" && absBase === 1) continue; + throw new Error(c + " is not a valid digit in base " + base + "."); + } + } + } + base = parseValue(base); + var digits = []; + var isNegative = text[0] === "-"; + for (i = isNegative ? 1 : 0; i < text.length; i++) { + var c = text[i]; + if (c in alphabetValues) digits.push(parseValue(alphabetValues[c])); + else if (c === "<") { + var start = i; + do { i++; } while (text[i] !== ">" && i < text.length); + digits.push(parseValue(text.slice(start + 1, i))); + } + else throw new Error(c + " is not a valid character"); + } + return parseBaseFromArray(digits, base, isNegative); + }; + + function parseBaseFromArray(digits, base, isNegative) { + var val = Integer[0], pow = Integer[1], i; + for (i = digits.length - 1; i >= 0; i--) { + val = val.add(digits[i].times(pow)); + pow = pow.times(base); + } + return isNegative ? val.negate() : val; + } + + function stringify(digit, alphabet) { + alphabet = alphabet || DEFAULT_ALPHABET; + if (digit < alphabet.length) { + return alphabet[digit]; + } + return "<" + digit + ">"; + } + + function toBase(n, base) { + base = bigInt(base); + if (base.isZero()) { + if (n.isZero()) return { value: [0], isNegative: false }; + throw new Error("Cannot convert nonzero numbers to base 0."); + } + if (base.equals(-1)) { + if (n.isZero()) return { value: [0], isNegative: false }; + if (n.isNegative()) + return { + value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber())) + .map(Array.prototype.valueOf, [1, 0]) + ), + isNegative: false + }; + + var arr = Array.apply(null, Array(n.toJSNumber() - 1)) + .map(Array.prototype.valueOf, [0, 1]); + arr.unshift([1]); + return { + value: [].concat.apply([], arr), + isNegative: false + }; + } + + var neg = false; + if (n.isNegative() && base.isPositive()) { + neg = true; + n = n.abs(); + } + if (base.isUnit()) { + if (n.isZero()) return { value: [0], isNegative: false }; + + return { + value: Array.apply(null, Array(n.toJSNumber())) + .map(Number.prototype.valueOf, 1), + isNegative: neg + }; + } + var out = []; + var left = n, divmod; + while (left.isNegative() || left.compareAbs(base) >= 0) { + divmod = left.divmod(base); + left = divmod.quotient; + var digit = divmod.remainder; + if (digit.isNegative()) { + digit = base.minus(digit).abs(); + left = left.next(); + } + out.push(digit.toJSNumber()); + } + out.push(left.toJSNumber()); + return { value: out.reverse(), isNegative: neg }; + } + + function toBaseString(n, base, alphabet) { + var arr = toBase(n, base); + return (arr.isNegative ? "-" : "") + arr.value.map(function (x) { + return stringify(x, alphabet); + }).join(''); + } + + BigInteger.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + SmallInteger.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + NativeBigInt.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + BigInteger.prototype.toString = function (radix, alphabet) { + if (radix === undefined) radix = 10; + if (radix !== 10) return toBaseString(this, radix, alphabet); + var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; + while (--l >= 0) { + digit = String(v[l]); + str += zeros.slice(digit.length) + digit; + } + var sign = this.sign ? "-" : ""; + return sign + str; + }; + + SmallInteger.prototype.toString = function (radix, alphabet) { + if (radix === undefined) radix = 10; + if (radix != 10) return toBaseString(this, radix, alphabet); + return String(this.value); + }; + + NativeBigInt.prototype.toString = SmallInteger.prototype.toString; + + NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); } + + BigInteger.prototype.valueOf = function () { + return parseInt(this.toString(), 10); + }; + BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf; + + SmallInteger.prototype.valueOf = function () { + return this.value; + }; + SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf; + NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () { + return parseInt(this.toString(), 10); + } + + function parseStringValue(v) { + if (isPrecise(+v)) { + var x = +v; + if (x === truncate(x)) + return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x); + throw new Error("Invalid integer: " + v); + } + var sign = v[0] === "-"; + if (sign) v = v.slice(1); + var split = v.split(/e/i); + if (split.length > 2) throw new Error("Invalid integer: " + split.join("e")); + if (split.length === 2) { + var exp = split[1]; + if (exp[0] === "+") exp = exp.slice(1); + exp = +exp; + if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent."); + var text = split[0]; + var decimalPlace = text.indexOf("."); + if (decimalPlace >= 0) { + exp -= text.length - decimalPlace - 1; + text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1); + } + if (exp < 0) throw new Error("Cannot include negative exponent part for integers"); + text += (new Array(exp + 1)).join("0"); + v = text; + } + var isValid = /^([0-9][0-9]*)$/.test(v); + if (!isValid) throw new Error("Invalid integer: " + v); + if (supportsNativeBigInt) { + return new NativeBigInt(BigInt(sign ? "-" + v : v)); + } + var r = [], max = v.length, l = LOG_BASE, min = max - l; + while (max > 0) { + r.push(+v.slice(min, max)); + min -= l; + if (min < 0) min = 0; + max -= l; + } + trim(r); + return new BigInteger(r, sign); + } + + function parseNumberValue(v) { + if (supportsNativeBigInt) { + return new NativeBigInt(BigInt(v)); + } + if (isPrecise(v)) { + if (v !== truncate(v)) throw new Error(v + " is not an integer."); + return new SmallInteger(v); + } + return parseStringValue(v.toString()); + } + + function parseValue(v) { + if (typeof v === "number") { + return parseNumberValue(v); + } + if (typeof v === "string") { + return parseStringValue(v); + } + if (typeof v === "bigint") { + return new NativeBigInt(v); + } + return v; + } + // Pre-define numbers in range [-999,999] + for (var i = 0; i < 1000; i++) { + Integer[i] = parseValue(i); + if (i > 0) Integer[-i] = parseValue(-i); + } + // Backwards compatibility + Integer.one = Integer[1]; + Integer.zero = Integer[0]; + Integer.minusOne = Integer[-1]; + Integer.max = max; + Integer.min = min; + Integer.gcd = gcd; + Integer.lcm = lcm; + Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; }; + Integer.randBetween = randBetween; + + Integer.fromArray = function (digits, base, isNegative) { + return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative); + }; + + return Integer; +})(); + +// Node.js check +if (typeof module !== "undefined" && module.hasOwnProperty("exports")) { + module.exports = bigInt; +} + +//amd check +if (typeof define === "function" && define.amd) { + define( function () { + return bigInt; + }); +} + +},{}],4:[function(require,module,exports){ +(function (Buffer){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +/* global BigInt */ +const bigInt = require("big-integer"); + +let wBigInt; + +if (typeof(BigInt) != "undefined") { + wBigInt = BigInt; + wBigInt.one = wBigInt(1); + wBigInt.zero = wBigInt(0); + + // Affine + wBigInt.genAffine = (q) => { + const nq = -q; + return (a) => { + let aux = a; + if (aux < 0) { + if (aux <= nq) { + aux = aux % q; + } + if (aux < wBigInt.zero) { + aux = aux + q; + } + } else { + if (aux >= q) { + aux = aux % q; + } + } + return aux.valueOf(); + }; + }; + + + // Inverse + wBigInt.genInverse = (q) => { + return (a) => { + let t = wBigInt.zero; + let r = q; + let newt = wBigInt.one; + let newr = wBigInt.affine(a, q); + while (newr!=wBigInt.zero) { + let q = r/newr; + [t, newt] = [newt, t-q*newt]; + [r, newr] = [newr, r-q*newr]; + } + if (t { + if (q) { + return (a,b) => (a+b) % q; + } else { + return (a,b) => a+b; + } + }; + + // Sub + wBigInt.genSub = (q) => { + if (q) { + return (a,b) => (a-b) % q; + } else { + return (a,b) => a-b; + } + }; + + + // Neg + wBigInt.genNeg = (q) => { + if (q) { + return (a) => (-a) % q; + } else { + return (a) => -a; + } + }; + + // Mul + wBigInt.genMul = (q) => { + if (q) { + return (a,b) => (a*b) % q; + } else { + return (a,b) => a*b; + } + }; + + // Shr + wBigInt.genShr = () => { + return (a,b) => a >> wBigInt(b); + }; + + // Shl + wBigInt.genShl = (q) => { + if (q) { + return (a,b) => (a << wBigInt(b)) % q; + } else { + return (a,b) => a << wBigInt(b); + } + }; + + // Equals + wBigInt.genEquals = (q) => { + if (q) { + return (a,b) => (a.affine(q) == b.affine(q)); + } else { + return (a,b) => a == b; + } + }; + + // Square + wBigInt.genSquare = (q) => { + if (q) { + return (a) => (a*a) %q; + } else { + return (a) => a*a; + } + }; + + + // Double + wBigInt.genDouble = (q) => { + if (q) { + return (a) => (a+a) %q; + } else { + return (a) => a+a; + } + }; + + // IsZero + wBigInt.genIsZero = (q) => { + if (q) { + return (a) => (a.affine(q) == wBigInt.zero); + } else { + return (a) => a == wBigInt.zero; + } + }; + + + // Other minor functions + wBigInt.prototype.isOdd = function() { + return (this & wBigInt.one) == wBigInt(1); + }; + + wBigInt.prototype.isNegative = function() { + return this < wBigInt.zero; + }; + + wBigInt.prototype.and = function(m) { + return this & m; + }; + + wBigInt.prototype.div = function(c) { + return this / c; + }; + + wBigInt.prototype.mod = function(c) { + return this % c; + }; + + wBigInt.prototype.pow = function(c) { + return this ** c; + }; + + wBigInt.prototype.abs = function() { + return (this > wBigInt.zero) ? this : -this; + }; + + wBigInt.prototype.modPow = function(e, m) { + let acc = wBigInt.one; + let exp = this; + let rem = e; + while (rem) { + if (rem & wBigInt.one) { + acc = (acc * exp) %m; + } + exp = (exp * exp) % m; + rem = rem >> wBigInt.one; + } + return acc; + }; + + wBigInt.prototype.greaterOrEquals = function(b) { + return this >= b; + }; + + wBigInt.prototype.greater = function(b) { + return this > b; + }; + wBigInt.prototype.gt = wBigInt.prototype.greater; + + wBigInt.prototype.lesserOrEquals = function(b) { + return this <= b; + }; + + wBigInt.prototype.lesser = function(b) { + return this < b; + }; + wBigInt.prototype.lt = wBigInt.prototype.lesser; + + wBigInt.prototype.equals = function(b) { + return this == b; + }; + wBigInt.prototype.eq = wBigInt.prototype.equals; + + wBigInt.prototype.neq = function(b) { + return this != b; + }; + + wBigInt.prototype.toJSNumber = function() { + return Number(this); + }; + + +} else { + + var oldProto = bigInt.prototype; + wBigInt = function(a) { + if ((typeof a == "string") && (a.slice(0,2) == "0x")) { + return bigInt(a.slice(2), 16); + } else { + return bigInt(a); + } + }; + wBigInt.one = bigInt.one; + wBigInt.zero = bigInt.zero; + wBigInt.prototype = oldProto; + + wBigInt.prototype.div = function(c) { + return this.divide(c); + }; + + // Affine + wBigInt.genAffine = (q) => { + const nq = wBigInt.zero.minus(q); + return (a) => { + let aux = a; + if (aux.isNegative()) { + if (aux.lesserOrEquals(nq)) { + aux = aux.mod(q); + } + if (aux.isNegative()) { + aux = aux.add(q); + } + } else { + if (aux.greaterOrEquals(q)) { + aux = aux.mod(q); + } + } + return aux; + }; + }; + + + // Inverse + wBigInt.genInverse = (q) => { + return (a) => a.affine(q).modInv(q); + }; + + // Add + wBigInt.genAdd = (q) => { + if (q) { + return (a,b) => { + const r = a.add(b); + return r.greaterOrEquals(q) ? r.minus(q) : r; + }; + } else { + return (a,b) => a.add(b); + } + }; + + // Sub + wBigInt.genSub = (q) => { + if (q) { + return (a,b) => a.greaterOrEquals(b) ? a.minus(b) : a.minus(b).add(q); + } else { + return (a,b) => a.minus(b); + } + }; + + wBigInt.genNeg = (q) => { + if (q) { + return (a) => a.isZero() ? a : q.minus(a); + } else { + return (a) => wBigInt.zero.minus(a); + } + }; + + // Mul + wBigInt.genMul = (q) => { + if (q) { + return (a,b) => a.times(b).mod(q); + } else { + return (a,b) => a.times(b); + } + }; + + // Shr + wBigInt.genShr = () => { + return (a,b) => a.shiftRight(wBigInt(b).value); + }; + + // Shr + wBigInt.genShl = (q) => { + if (q) { + return (a,b) => a.shiftLeft(wBigInt(b).value).mod(q); + } else { + return (a,b) => a.shiftLeft(wBigInt(b).value); + } + }; + + // Square + wBigInt.genSquare = (q) => { + if (q) { + return (a) => a.square().mod(q); + } else { + return (a) => a.square(); + } + }; + + // Double + wBigInt.genDouble = (q) => { + if (q) { + return (a) => a.add(a).mod(q); + } else { + return (a) => a.add(a); + } + }; + + // Equals + wBigInt.genEquals = (q) => { + if (q) { + return (a,b) => a.affine(q).equals(b.affine(q)); + } else { + return (a,b) => a.equals(b); + } + }; + + // IsZero + wBigInt.genIsZero = (q) => { + if (q) { + return (a) => (a.affine(q).isZero()); + } else { + return (a) => a.isZero(); + } + }; +} + + + +wBigInt.affine = function(a, q) { + return wBigInt.genAffine(q)(a); +}; + +wBigInt.prototype.affine = function (q) { + return wBigInt.affine(this, q); +}; + +wBigInt.inverse = function(a, q) { + return wBigInt.genInverse(q)(a); +}; + +wBigInt.prototype.inverse = function (q) { + return wBigInt.genInverse(q)(this); +}; + +wBigInt.add = function(a, b, q) { + return wBigInt.genAdd(q)(a,b); +}; + +wBigInt.prototype.add = function (a, q) { + return wBigInt.genAdd(q)(this, a); +}; + +wBigInt.sub = function(a, b, q) { + return wBigInt.genSub(q)(a,b); +}; + +wBigInt.prototype.sub = function (a, q) { + return wBigInt.genSub(q)(this, a); +}; + +wBigInt.neg = function(a, q) { + return wBigInt.genNeg(q)(a); +}; + +wBigInt.prototype.neg = function (q) { + return wBigInt.genNeg(q)(this); +}; + +wBigInt.mul = function(a, b, q) { + return wBigInt.genMul(q)(a,b); +}; + +wBigInt.prototype.mul = function (a, q) { + return wBigInt.genMul(q)(this, a); +}; + +wBigInt.shr = function(a, b, q) { + return wBigInt.genShr(q)(a,b); +}; + +wBigInt.prototype.shr = function (a, q) { + return wBigInt.genShr(q)(this, a); +}; + +wBigInt.shl = function(a, b, q) { + return wBigInt.genShl(q)(a,b); +}; + +wBigInt.prototype.shl = function (a, q) { + return wBigInt.genShl(q)(this, a); +}; + +wBigInt.equals = function(a, b, q) { + return wBigInt.genEquals(q)(a,b); +}; + +wBigInt.prototype.equals = function (a, q) { + return wBigInt.genEquals(q)(this, a); +}; + +wBigInt.square = function(a, q) { + return wBigInt.genSquare(q)(a); +}; + +wBigInt.prototype.square = function (q) { + return wBigInt.genSquare(q)(this); +}; + +wBigInt.double = function(a, q) { + return wBigInt.genDouble(q)(a); +}; + +wBigInt.prototype.double = function (q) { + return wBigInt.genDouble(q)(this); +}; + +wBigInt.isZero = function(a, q) { + return wBigInt.genIsZero(q)(a); +}; + +wBigInt.prototype.isZero = function (q) { + return wBigInt.genIsZero(q)(this); +}; + +wBigInt.leBuff2int = function(buff) { + let res = wBigInt.zero; + for (let i=0; i=0)) { + let c = Number(r.and(wBigInt("255"))); + buff[o] = c; + o--; + r = r.shr(8); + } + if (r.greater(wBigInt.zero)) throw new Error("Number does not feed in buffer"); + return buff; +}; + +wBigInt.prototype.beInt2Buff = function (len) { + return wBigInt.beInt2Buff(this,len); +}; + +module.exports = wBigInt; + + +}).call(this,require("buffer").Buffer) +},{"big-integer":3,"buffer":14}],5:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint"); + +module.exports = calculateWitness; + +function calculateWitness(circuit, inputSignals, options) { + options = options || {}; + if (!options.logFunction) options.logFunction = console.log; + const ctx = new RTCtx(circuit, options); + + function iterateSelector(values, sels, cb) { + if (!Array.isArray(values)) { + return cb(sels, values); + } + for (let i=0; i " + ctx.witness[i].toString()); + } + return ctx.witness.slice(0, circuit.nVars); +// return ctx.witness; +} + +class RTCtx { + constructor(circuit, options) { + this.options = options; + this.scopes = []; + this.circuit = circuit; + this.witness = new Array(circuit.nSignals); + this.notInitSignals = {}; + for (let c in this.circuit.components) { + this.notInitSignals[c] = this.circuit.components[c].inputSignals; + } + } + + _sels2str(sels) { + let res = ""; + for (let i=0; i { + if (this.notInitSignals[c] == 0) this.triggerComponent(c); + }); + return this.witness[sId]; + } + + setVar(name, sels, value) { + function setVarArray(a, sels2, value) { + if (sels2.length == 1) { + a[sels2[0]] = value; + } else { + if (typeof(a[sels2[0]]) == "undefined") a[sels2[0]] = []; + setVarArray(a[sels2[0]], sels2.slice(1), value); + } + } + const scope = this.scopes[this.scopes.length-1]; + if (sels.length == 0) { + scope[name] = value; + } else { + if (typeof(scope[name]) == "undefined") scope[name] = []; + setVarArray(scope[name], sels, value); + } + return value; + } + + getVar(name, sels) { + function select(a, sels2) { + return (sels2.length == 0) ? a : select(a[sels2[0]], sels2.slice(1)); + } + for (let i=this.scopes.length-1; i>=0; i--) { + if (typeof(this.scopes[i][name]) != "undefined") return select(this.scopes[i][name], sels); + } + throw new Error("Variable not defined: " + name); + } + + getSignal(name, sels) { + let fullName = name=="one" ? "one" : this.currentComponent + "." + name; + fullName += this._sels2str(sels); + return this.getSignalFullName(fullName); + } + + + getPin(componentName, componentSels, signalName, signalSels) { + let fullName = componentName=="one" ? "one" : this.currentComponent + "." + componentName; + fullName += this._sels2str(componentSels) + + "."+ + signalName+ + this._sels2str(signalSels); + return this.getSignalFullName(fullName); + } + + getSignalFullName(fullName) { + const sId = this.circuit.getSignalIdx(fullName); + if (typeof(this.witness[sId]) == "undefined") { + throw new Error("Signal not initialized: "+fullName); + } + if (this.options.logGet) this.options.logFunction("get --->" + fullName + " = " + this.witness[sId].toString() ); + return this.witness[sId]; + } + + assert(a,b,errStr) { + const ba = bigInt(a); + const bb = bigInt(b); + if (!ba.equals(bb)) { + throw new Error("Constraint doesn't match "+ this.currentComponent+": "+ errStr + " -> "+ ba.toString() + " != " + bb.toString()); + } + } +} + +},{"./bigint":4}],6:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint.js"); + +const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); +const __MASK__ = bigInt("28948022309329048855892746252171976963317496166410141009864396001978282409983"); // 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +const calculateWitness = require("./calculateWitness.js"); + +module.exports = class Circuit { + constructor(circuitDef) { + this.nPubInputs = circuitDef.nPubInputs; + this.nPrvInputs = circuitDef.nPrvInputs; + this.nInputs = circuitDef.nInputs; + this.nOutputs = circuitDef.nOutputs; + this.nVars = circuitDef.nVars; + this.nSignals = circuitDef.nSignals; + this.nConstants = circuitDef.nConstants; + + this.nConstraints = circuitDef.constraints.length; + + this.signalName2Idx = circuitDef.signalName2Idx; + this.components = circuitDef.components; + this.componentName2Idx = circuitDef.componentName2Idx; + this.signals = circuitDef.signals; + this.constraints = circuitDef.constraints; + + this.templates = {}; + for (let t in circuitDef.templates) { + this.templates[t] = eval(" const __f= " +circuitDef.templates[t] + "\n__f"); + } + + this.functions = {}; + for (let f in circuitDef.functions) { + this.functions[f] = { + params: circuitDef.functions[f].params, + func: eval(" const __f= " +circuitDef.functions[f].func + "\n__f;") + }; + } + } + + calculateWitness(input, log) { + return calculateWitness(this, input, log); + } + + checkWitness(w) { + const evalLC = (lc, w) => { + let acc = bigInt(0); + for (let k in lc) { + acc= acc.add(bigInt(w[k]).mul(bigInt(lc[k]))).mod(__P__); + } + return acc; + } + + const checkConstraint = (ct, w) => { + const a=evalLC(ct[0],w); + const b=evalLC(ct[1],w); + const c=evalLC(ct[2],w); + const res = (a.mul(b).sub(c)).affine(__P__); + if (!res.isZero()) return false; + return true; + } + + + for (let i=0; i { + let S = ""; + for (let k in lc) { + let name = this.signals[k].names[0]; + if (name == "one") name = ""; + let v = bigInt(lc[k]); + let vs; + if (!v.lesserOrEquals(__P__.shr(bigInt(1)))) { + v = __P__.sub(v); + vs = "-"+v.toString(); + } else { + if (S!="") { + vs = "+"+v.toString(); + } else { + vs = ""; + } + if (vs!="1") { + vs = vs + v.toString();; + } + } + + S= S + " " + vs + name; + } + return S; + }; + const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ] = 0`; + console.log(S); + } + + printConstraints() { + for (let i=0; i=this.nOutputs) throw new Error("Accessing an invalid output: "+i); + return i+1; + } + + // returns the index of the i'th input + inputIdx(i) { + if (i>=this.nInputs) throw new Error("Accessing an invalid input: "+i); + return this.nOutputs + 1 + i; + } + + // returns the index of the i'th public input + pubInputIdx(i) { + if (i>=this.nPubInputs) throw new Error("Accessing an invalid pubInput: "+i); + return this.inputIdx(i); + } + + // returns the index of the i'th private input + prvInputIdx(i) { + if (i>=this.nPrvInputs) throw new Error("Accessing an invalid prvInput: "+i); + return this.inputIdx(this.nPubInputs + i); + } + + // returns the index of the i'th variable + varIdx(i) { + if (i>=this.nVars) throw new Error("Accessing an invalid variable: "+i); + return i; + } + + // returns the index of the i'th constant + constantIdx(i) { + if (i>=this.nConstants) throw new Error("Accessing an invalid constant: "+i); + return this.nVars + i; + } + + // returns the index of the i'th signal + signalIdx(i) { + if (i>=this.nSignls) throw new Error("Accessing an invalid signal: "+i); + return i; + } + + signalNames(i) { + return this.signals[ this.getSignalIdx(i) ].names.join(", "); + } + + a(constraint, signalIdx) { + return bigInt(this.constraints[constraint][0][signalIdx] || 0 ); + } + + b(constraint, signalIdx) { + return bigInt(this.constraints[constraint][1][signalIdx] || 0); + } + + c(constraint, signalIdx) { + return bigInt(this.constraints[constraint][2][signalIdx] || 0); + } +}; + +},{"./bigint.js":4,"./calculateWitness.js":5}],7:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint.js"); + +module.exports.stringifyBigInts = stringifyBigInts; +module.exports.unstringifyBigInts = unstringifyBigInts; + +function stringifyBigInts(o) { + if ((typeof(o) == "bigint") || o.isZero !== undefined) { + return o.toString(10); + } else if (Array.isArray(o)) { + return o.map(stringifyBigInts); + } else if (typeof o == "object") { + const res = {}; + for (let k in o) { + res[k] = stringifyBigInts(o[k]); + } + return res; + } else { + return o; + } +} + +function unstringifyBigInts(o) { + if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) { + return bigInt(o); + } else if (Array.isArray(o)) { + return o.map(unstringifyBigInts); + } else if (typeof o == "object") { + const res = {}; + for (let k in o) { + res[k] = unstringifyBigInts(o[k]); + } + return res; + } else { + return o; + } +} + +},{"./bigint.js":4}],8:[function(require,module,exports){ (function (global){ 'use strict'; @@ -571,7 +3037,7 @@ var objectKeys = Object.keys || function (obj) { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"object-assign":11,"util/":6}],4:[function(require,module,exports){ +},{"object-assign":16,"util/":11}],9:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -596,14 +3062,14 @@ if (typeof Object.create === 'function') { } } -},{}],5:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],6:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -1193,7 +3659,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":5,"_process":12,"inherits":4}],7:[function(require,module,exports){ +},{"./support/isBuffer":10,"_process":17,"inherits":9}],12:[function(require,module,exports){ 'use strict' exports.byteLength = byteLength @@ -1346,7 +3812,7 @@ function fromByteArray (uint8) { return parts.join('') } -},{}],8:[function(require,module,exports){ +},{}],13:[function(require,module,exports){ var bigInt = (function (undefined) { "use strict"; @@ -2796,7 +5262,7 @@ if (typeof define === "function" && define.amd) { }); } -},{}],9:[function(require,module,exports){ +},{}],14:[function(require,module,exports){ (function (Buffer){ /*! * The buffer module from node.js, for the browser. @@ -4577,7 +7043,7 @@ function numberIsNaN (obj) { } }).call(this,require("buffer").Buffer) -},{"base64-js":7,"buffer":9,"ieee754":10}],10:[function(require,module,exports){ +},{"base64-js":12,"buffer":14,"ieee754":15}],15:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = (nBytes * 8) - mLen - 1 @@ -4663,7 +7129,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],11:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ /* object-assign (c) Sindre Sorhus @@ -4755,7 +7221,7 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) { return to; }; -},{}],12:[function(require,module,exports){ +},{}],17:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -4941,977 +7407,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],13:[function(require,module,exports){ -(function (Buffer){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -/* global BigInt */ -const bigInt = require("big-integer"); - -let wBigInt; - -if (typeof(BigInt) != "undefined") { - wBigInt = BigInt; - wBigInt.one = wBigInt(1); - wBigInt.zero = wBigInt(0); - - // Affine - wBigInt.genAffine = (q) => { - const nq = -q; - return (a) => { - let aux = a; - if (aux < 0) { - if (aux <= nq) { - aux = aux % q; - } - if (aux < wBigInt.zero) { - aux = aux + q; - } - } else { - if (aux >= q) { - aux = aux % q; - } - } - return aux.valueOf(); - }; - }; - - - // Inverse - wBigInt.genInverse = (q) => { - return (a) => { - let t = wBigInt.zero; - let r = q; - let newt = wBigInt.one; - let newr = wBigInt.affine(a, q); - while (newr!=wBigInt.zero) { - let q = r/newr; - [t, newt] = [newt, t-q*newt]; - [r, newr] = [newr, r-q*newr]; - } - if (t { - if (q) { - return (a,b) => (a+b) % q; - } else { - return (a,b) => a+b; - } - }; - - // Sub - wBigInt.genSub = (q) => { - if (q) { - return (a,b) => (a-b) % q; - } else { - return (a,b) => a-b; - } - }; - - - // Neg - wBigInt.genNeg = (q) => { - if (q) { - return (a) => (-a) % q; - } else { - return (a) => -a; - } - }; - - // Mul - wBigInt.genMul = (q) => { - if (q) { - return (a,b) => (a*b) % q; - } else { - return (a,b) => a*b; - } - }; - - // Shr - wBigInt.genShr = () => { - return (a,b) => a >> wBigInt(b); - }; - - // Shl - wBigInt.genShl = (q) => { - if (q) { - return (a,b) => (a << wBigInt(b)) % q; - } else { - return (a,b) => a << wBigInt(b); - } - }; - - // Equals - wBigInt.genEquals = (q) => { - if (q) { - return (a,b) => (a.affine(q) == b.affine(q)); - } else { - return (a,b) => a == b; - } - }; - - // Square - wBigInt.genSquare = (q) => { - if (q) { - return (a) => (a*a) %q; - } else { - return (a) => a*a; - } - }; - - - // Double - wBigInt.genDouble = (q) => { - if (q) { - return (a) => (a+a) %q; - } else { - return (a) => a+a; - } - }; - - // IsZero - wBigInt.genIsZero = (q) => { - if (q) { - return (a) => (a.affine(q) == wBigInt.zero); - } else { - return (a) => a == wBigInt.zero; - } - }; - - - // Other minor functions - wBigInt.prototype.isOdd = function() { - return (this & wBigInt.one) == wBigInt(1); - }; - - wBigInt.prototype.isNegative = function() { - return this < wBigInt.zero; - }; - - wBigInt.prototype.and = function(m) { - return this & m; - }; - - wBigInt.prototype.div = function(c) { - return this / c; - }; - - wBigInt.prototype.mod = function(c) { - return this % c; - }; - - wBigInt.prototype.modPow = function(e, m) { - let acc = wBigInt.one; - let exp = this; - let rem = e; - while (rem) { - if (rem & wBigInt.one) { - acc = (acc * exp) %m; - } - exp = (exp * exp) % m; - rem = rem >> wBigInt.one; - } - return acc; - }; - - wBigInt.prototype.greaterOrEquals = function(b) { - return this >= b; - }; - - wBigInt.prototype.greater = function(b) { - return this > b; - }; - wBigInt.prototype.gt = wBigInt.prototype.greater; - - wBigInt.prototype.lesserOrEquals = function(b) { - return this <= b; - }; - - wBigInt.prototype.lesser = function(b) { - return this < b; - }; - wBigInt.prototype.lt = wBigInt.prototype.lesser; - - wBigInt.prototype.equals = function(b) { - return this == b; - }; - wBigInt.prototype.eq = wBigInt.prototype.equals; - - wBigInt.prototype.neq = function(b) { - return this != b; - }; - -} else { - - var oldProto = bigInt.prototype; - wBigInt = function(a) { - if ((typeof a == "string") && (a.slice(0,2) == "0x")) { - return bigInt(a.slice(2), 16); - } else { - return bigInt(a); - } - }; - wBigInt.one = bigInt.one; - wBigInt.zero = bigInt.zero; - wBigInt.prototype = oldProto; - - wBigInt.prototype.div = function(c) { - return this.divide(c); - }; - - // Affine - wBigInt.genAffine = (q) => { - const nq = wBigInt.zero.minus(q); - return (a) => { - let aux = a; - if (aux.isNegative()) { - if (aux.lesserOrEquals(nq)) { - aux = aux.mod(q); - } - if (aux.isNegative()) { - aux = aux.add(q); - } - } else { - if (aux.greaterOrEquals(q)) { - aux = aux.mod(q); - } - } - return aux; - }; - }; - - - // Inverse - wBigInt.genInverse = (q) => { - return (a) => a.affine(q).modInv(q); - }; - - // Add - wBigInt.genAdd = (q) => { - if (q) { - return (a,b) => { - const r = a.add(b); - return r.greaterOrEquals(q) ? r.minus(q) : r; - }; - } else { - return (a,b) => a.add(b); - } - }; - - // Sub - wBigInt.genSub = (q) => { - if (q) { - return (a,b) => a.greaterOrEquals(b) ? a.minus(b) : a.minus(b).add(q); - } else { - return (a,b) => a.minus(b); - } - }; - - wBigInt.genNeg = (q) => { - if (q) { - return (a) => a.isZero() ? a : q.minus(a); - } else { - return (a) => wBigInt.zero.minus(a); - } - }; - - // Mul - wBigInt.genMul = (q) => { - if (q) { - return (a,b) => a.times(b).mod(q); - } else { - return (a,b) => a.times(b); - } - }; - - // Shr - wBigInt.genShr = () => { - return (a,b) => a.shiftRight(wBigInt(b).value); - }; - - // Shr - wBigInt.genShl = (q) => { - if (q) { - return (a,b) => a.shiftLeft(wBigInt(b).value).mod(q); - } else { - return (a,b) => a.shiftLeft(wBigInt(b).value); - } - }; - - // Square - wBigInt.genSquare = (q) => { - if (q) { - return (a) => a.square().mod(q); - } else { - return (a) => a.square(); - } - }; - - // Double - wBigInt.genDouble = (q) => { - if (q) { - return (a) => a.add(a).mod(q); - } else { - return (a) => a.add(a); - } - }; - - // Equals - wBigInt.genEquals = (q) => { - if (q) { - return (a,b) => a.affine(q).equals(b.affine(q)); - } else { - return (a,b) => a.equals(b); - } - }; - - // IsZero - wBigInt.genIsZero = (q) => { - if (q) { - return (a) => (a.affine(q).isZero()); - } else { - return (a) => a.isZero(); - } - }; -} - - - -wBigInt.affine = function(a, q) { - return wBigInt.genAffine(q)(a); -}; - -wBigInt.prototype.affine = function (q) { - return wBigInt.affine(this, q); -}; - -wBigInt.inverse = function(a, q) { - return wBigInt.genInverse(q)(a); -}; - -wBigInt.prototype.inverse = function (q) { - return wBigInt.genInverse(q)(this); -}; - -wBigInt.add = function(a, b, q) { - return wBigInt.genAdd(q)(a,b); -}; - -wBigInt.prototype.add = function (a, q) { - return wBigInt.genAdd(q)(this, a); -}; - -wBigInt.sub = function(a, b, q) { - return wBigInt.genSub(q)(a,b); -}; - -wBigInt.prototype.sub = function (a, q) { - return wBigInt.genSub(q)(this, a); -}; - -wBigInt.neg = function(a, q) { - return wBigInt.genNeg(q)(a); -}; - -wBigInt.prototype.neg = function (q) { - return wBigInt.genNeg(q)(this); -}; - -wBigInt.mul = function(a, b, q) { - return wBigInt.genMul(q)(a,b); -}; - -wBigInt.prototype.mul = function (a, q) { - return wBigInt.genMul(q)(this, a); -}; - -wBigInt.shr = function(a, b, q) { - return wBigInt.genShr(q)(a,b); -}; - -wBigInt.prototype.shr = function (a, q) { - return wBigInt.genShr(q)(this, a); -}; - -wBigInt.shl = function(a, b, q) { - return wBigInt.genShl(q)(a,b); -}; - -wBigInt.prototype.shl = function (a, q) { - return wBigInt.genShl(q)(this, a); -}; - -wBigInt.equals = function(a, b, q) { - return wBigInt.genEquals(q)(a,b); -}; - -wBigInt.prototype.equals = function (a, q) { - return wBigInt.genEquals(q)(this, a); -}; - -wBigInt.square = function(a, q) { - return wBigInt.genSquare(q)(a); -}; - -wBigInt.prototype.square = function (q) { - return wBigInt.genSquare(q)(this); -}; - -wBigInt.double = function(a, q) { - return wBigInt.genDouble(q)(a); -}; - -wBigInt.prototype.double = function (q) { - return wBigInt.genDouble(q)(this); -}; - -wBigInt.isZero = function(a, q) { - return wBigInt.genIsZero(q)(a); -}; - -wBigInt.prototype.isZero = function (q) { - return wBigInt.genIsZero(q)(this); -}; - -wBigInt.leBuff2int = function(buff) { - let res = wBigInt.zero; - for (let i=0; i. -*/ - -const bigInt = require("./bigint"); - -module.exports = calculateWitness; - -function calculateWitness(circuit, inputSignals, log) { - log = log || (() => {}); - const ctx = new RTCtx(circuit, log); - - function iterateSelector(values, sels, cb) { - if (!Array.isArray(values)) { - return cb(sels, values); - } - for (let i=0; i " + ctx.witness[i].toString()); - } - return ctx.witness.slice(0, circuit.nVars); -// return ctx.witness; -} - -class RTCtx { - constructor(circuit, log) { - this.log = log || function() {}; - this.scopes = []; - this.circuit = circuit; - this.witness = new Array(circuit.nSignals); - this.notInitSignals = {}; - for (let c in this.circuit.components) { - this.notInitSignals[c] = this.circuit.components[c].inputSignals; - } - } - - _sels2str(sels) { - let res = ""; - for (let i=0; i { - if (this.notInitSignals[c] == 0) this.triggerComponent(c); - }); - return this.witness[sId]; - } - - setVar(name, sels, value) { - function setVarArray(a, sels2, value) { - if (sels2.length == 1) { - a[sels2[0]] = value; - } else { - if (typeof(a[sels2[0]]) == "undefined") a[sels2[0]] = []; - setVarArray(a[sels2[0]], sels2.slice(1), value); - } - } - const scope = this.scopes[this.scopes.length-1]; - if (sels.length == 0) { - scope[name] = value; - } else { - if (typeof(scope[name]) == "undefined") scope[name] = []; - setVarArray(scope[name], sels, value); - } - return value; - } - - getVar(name, sels) { - function select(a, sels2) { - return (sels2.length == 0) ? a : select(a[sels2[0]], sels2.slice(1)); - } - for (let i=this.scopes.length-1; i>=0; i--) { - if (typeof(this.scopes[i][name]) != "undefined") return select(this.scopes[i][name], sels); - } - throw new Error("Variable not defined: " + name); - } - - getSignal(name, sels) { - let fullName = name=="one" ? "one" : this.currentComponent + "." + name; - fullName += this._sels2str(sels); - return this.getSignalFullName(fullName); - } - - - getPin(componentName, componentSels, signalName, signalSels) { - let fullName = componentName=="one" ? "one" : this.currentComponent + "." + componentName; - fullName += this._sels2str(componentSels) + - "."+ - signalName+ - this._sels2str(signalSels); - return this.getSignalFullName(fullName); - } - - getSignalFullName(fullName) { - const sId = this.circuit.getSignalIdx(fullName); - if (typeof(this.witness[sId]) == "undefined") { - throw new Error("Signal not initialized: "+fullName); - } - this.log("get --->" + fullName + " = " + this.witness[sId].toString() ); - return this.witness[sId]; - } - - assert(a,b) { - const ba = bigInt(a); - const bb = bigInt(b); - if (!ba.equals(bb)) { - throw new Error("Constraint doesn't match: " + ba.toString() + " != " + bb.toString()); - } - } -} - -},{"./bigint":13}],15:[function(require,module,exports){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -const bigInt = require("./bigint.js"); - -const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); -const __MASK__ = bigInt("28948022309329048855892746252171976963317496166410141009864396001978282409983"); // 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -const calculateWitness = require("./calculateWitness.js"); - -module.exports = class Circuit { - constructor(circuitDef) { - this.nPubInputs = circuitDef.nPubInputs; - this.nPrvInputs = circuitDef.nPrvInputs; - this.nInputs = circuitDef.nInputs; - this.nOutputs = circuitDef.nOutputs; - this.nVars = circuitDef.nVars; - this.nSignals = circuitDef.nSignals; - this.nConstants = circuitDef.nConstants; - - this.nConstraints = circuitDef.constraints.length; - - this.signalName2Idx = circuitDef.signalName2Idx; - this.components = circuitDef.components; - this.componentName2Idx = circuitDef.componentName2Idx; - this.signals = circuitDef.signals; - this.constraints = circuitDef.constraints; - - this.templates = {}; - for (let t in circuitDef.templates) { - this.templates[t] = eval(" const __f= " +circuitDef.templates[t] + "\n__f"); - } - - this.functions = {}; - for (let f in circuitDef.functions) { - this.functions[f] = { - params: circuitDef.functions[f].params, - func: eval(" const __f= " +circuitDef.functions[f].func + "\n__f;") - }; - } - } - - calculateWitness(input, log) { - return calculateWitness(this, input, log); - } - - checkWitness(w) { - const evalLC = (lc, w) => { - let acc = bigInt(0); - for (let k in lc) { - acc= acc.add(bigInt(w[k]).mul(bigInt(lc[k]))).mod(__P__); - } - return acc; - } - - const checkConstraint = (ct, w) => { - const a=evalLC(ct[0],w); - const b=evalLC(ct[1],w); - const c=evalLC(ct[2],w); - const res = (a.mul(b).sub(c)).affine(__P__); - if (!res.isZero()) return false; - return true; - } - - - for (let i=0; i { - let S = ""; - for (let k in lc) { - let name = this.signals[k].names[0]; - if (name == "one") name = ""; - let v = bigInt(lc[k]); - let vs; - if (!v.lesserOrEquals(__P__.shr(bigInt(1)))) { - v = __P__.sub(v); - vs = "-"+v.toString(); - } else { - if (S!="") { - vs = "+"+v.toString(); - } else { - vs = ""; - } - if (vs!="1") { - vs = vs + v.toString();; - } - } - - S= S + " " + vs + name; - } - return S; - }; - const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ] = 0`; - console.log(S); - } - - printConstraints() { - for (let i=0; i=this.nOutputs) throw new Error("Accessing an invalid output: "+i); - return i+1; - } - - // returns the index of the i'th input - inputIdx(i) { - if (i>=this.nInputs) throw new Error("Accessing an invalid input: "+i); - return this.nOutputs + 1 + i; - } - - // returns the index of the i'th public input - pubInputIdx(i) { - if (i>=this.nPubInputs) throw new Error("Accessing an invalid pubInput: "+i); - return this.inputIdx(i); - } - - // returns the index of the i'th private input - prvInputIdx(i) { - if (i>=this.nPrvInputs) throw new Error("Accessing an invalid prvInput: "+i); - return this.inputIdx(this.nPubInputs + i); - } - - // returns the index of the i'th variable - varIdx(i) { - if (i>=this.nVars) throw new Error("Accessing an invalid variable: "+i); - return i; - } - - // returns the index of the i'th constant - constantIdx(i) { - if (i>=this.nConstants) throw new Error("Accessing an invalid constant: "+i); - return this.nVars + i; - } - - // returns the index of the i'th signal - signalIdx(i) { - if (i>=this.nSignls) throw new Error("Accessing an invalid signal: "+i); - return i; - } - - signalNames(i) { - return this.signals[ this.getSignalIdx(i) ].names.join(", "); - } - - a(constraint, signalIdx) { - return bigInt(this.constraints[constraint][0][signalIdx] || 0 ); - } - - b(constraint, signalIdx) { - return bigInt(this.constraints[constraint][1][signalIdx] || 0); - } - - c(constraint, signalIdx) { - return bigInt(this.constraints[constraint][2][signalIdx] || 0); - } -}; - -},{"./bigint.js":13,"./calculateWitness.js":14}],16:[function(require,module,exports){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -const bigInt = require("./bigint.js"); - -module.exports.stringifyBigInts = stringifyBigInts; -module.exports.unstringifyBigInts = unstringifyBigInts; - -function stringifyBigInts(o) { - if ((typeof(o) == "bigint") || (o instanceof bigInt)) { - return o.toString(10); - } else if (Array.isArray(o)) { - return o.map(stringifyBigInts); - } else if (typeof o == "object") { - const res = {}; - for (let k in o) { - res[k] = stringifyBigInts(o[k]); - } - return res; - } else { - return o; - } -} - -function unstringifyBigInts(o) { - if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) { - return bigInt(o); - } else if (Array.isArray(o)) { - return o.map(unstringifyBigInts); - } else if (typeof o == "object") { - const res = {}; - for (let k in o) { - res[k] = unstringifyBigInts(o[k]); - } - return res; - } else { - return o; - } -} - -},{"./bigint.js":13}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ (function (process){ /* Copyright 2019 0KIMS association. @@ -6526,7 +8022,7 @@ class Groth16 { module.exports = build; }).call(this,require('_process')) -},{"../build/groth16_wasm.js":1,"_process":12,"assert":3,"big-integer":8,"crypto":undefined,"worker_threads":undefined}],18:[function(require,module,exports){ +},{"../build/groth16_wasm.js":1,"_process":17,"assert":8,"big-integer":13,"crypto":undefined,"worker_threads":undefined}],19:[function(require,module,exports){ /* Copyright 2019 0KIMS association. @@ -6547,20 +8043,20 @@ module.exports = build; */ const bigInt = require("big-integer"); -const Circuit = require("snarkjs/src/circuit"); -const bigInt2 = require("snarkjs/src/bigint"); +const Circuit = require("@tornado/snarkjs/src/circuit"); +const bigInt2 = require("@tornado/snarkjs/src/bigint"); const hexifyBigInts = require("../tools/stringifybigint").hexifyBigInts; const unhexifyBigInts = require("../tools/stringifybigint").unhexifyBigInts; const stringifyBigInts = require("../tools/stringifybigint").stringifyBigInts; const unstringifyBigInts = require("../tools/stringifybigint").unstringifyBigInts; -const stringifyBigInts2 = require("snarkjs/src/stringifybigint").stringifyBigInts; -const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts; +const stringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").stringifyBigInts; +const unstringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").unstringifyBigInts; function bigInt2BytesLE(_a, len) { const b = Array(len); let v = bigInt(_a); - for (let i=0; i toHex32(x)).join("") + proof: "0x" + flatProof.map((x) => toHex32(x)).join(""), }; if (proof.publicSignals) { result.publicSignals = hexifyBigInts(unstringifyBigInts(proof.publicSignals)); @@ -6616,11 +8116,11 @@ function toSolidityInput(proof) { return result; } -function genWitness(input, circuitJson) { +function genWitness(input, circuitJson) { const circuit = new Circuit(unstringifyBigInts2(circuitJson)); const witness = circuit.calculateWitness(unstringifyBigInts2(input)); const publicSignals = witness.slice(1, circuit.nPubInputs + circuit.nOutputs + 1); - return {witness, publicSignals}; + return { witness, publicSignals }; } async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { @@ -6631,8 +8131,9 @@ async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { return result; } -module.exports = {bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve}; -},{"../tools/stringifybigint":19,"big-integer":8,"snarkjs/src/bigint":13,"snarkjs/src/circuit":15,"snarkjs/src/stringifybigint":16}],19:[function(require,module,exports){ +module.exports = { bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve }; + +},{"../tools/stringifybigint":20,"@tornado/snarkjs/src/bigint":4,"@tornado/snarkjs/src/circuit":6,"@tornado/snarkjs/src/stringifybigint":7,"big-integer":13}],20:[function(require,module,exports){ /* Copyright 2018 0kims association. @@ -6726,4 +8227,4 @@ function unhexifyBigInts(o) { } } -},{"big-integer":8}]},{},[2]); +},{"big-integer":13}]},{},[2]); diff --git a/example/websnark.js b/example/websnark.js index d90e0c5..b5dbdbd 100644 --- a/example/websnark.js +++ b/example/websnark.js @@ -6,7 +6,7 @@ exports.pr = 1768; }).call(this,require("buffer").Buffer) -},{"buffer":9}],2:[function(require,module,exports){ +},{"buffer":14}],2:[function(require,module,exports){ /* Copyright 2019 0KIMS association. @@ -61,7 +61,2473 @@ buildGroth16().then((groth16) => { } }; }); -},{"./src/groth16":17,"./src/utils":18}],3:[function(require,module,exports){ +},{"./src/groth16":18,"./src/utils":19}],3:[function(require,module,exports){ +var bigInt = (function (undefined) { + "use strict"; + + var BASE = 1e7, + LOG_BASE = 7, + MAX_INT = 9007199254740992, + MAX_INT_ARR = smallToArray(MAX_INT), + DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"; + + var supportsNativeBigInt = typeof BigInt === "function"; + + function Integer(v, radix, alphabet, caseSensitive) { + if (typeof v === "undefined") return Integer[0]; + if (typeof radix !== "undefined") return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive); + return parseValue(v); + } + + function BigInteger(value, sign) { + this.value = value; + this.sign = sign; + this.isSmall = false; + } + BigInteger.prototype = Object.create(Integer.prototype); + + function SmallInteger(value) { + this.value = value; + this.sign = value < 0; + this.isSmall = true; + } + SmallInteger.prototype = Object.create(Integer.prototype); + + function NativeBigInt(value) { + this.value = value; + } + NativeBigInt.prototype = Object.create(Integer.prototype); + + function isPrecise(n) { + return -MAX_INT < n && n < MAX_INT; + } + + function smallToArray(n) { // For performance reasons doesn't reference BASE, need to change this function if BASE changes + if (n < 1e7) + return [n]; + if (n < 1e14) + return [n % 1e7, Math.floor(n / 1e7)]; + return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)]; + } + + function arrayToSmall(arr) { // If BASE changes this function may need to change + trim(arr); + var length = arr.length; + if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) { + switch (length) { + case 0: return 0; + case 1: return arr[0]; + case 2: return arr[0] + arr[1] * BASE; + default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE; + } + } + return arr; + } + + function trim(v) { + var i = v.length; + while (v[--i] === 0); + v.length = i + 1; + } + + function createArray(length) { // function shamelessly stolen from Yaffle's library https://github.com/Yaffle/BigInteger + var x = new Array(length); + var i = -1; + while (++i < length) { + x[i] = 0; + } + return x; + } + + function truncate(n) { + if (n > 0) return Math.floor(n); + return Math.ceil(n); + } + + function add(a, b) { // assumes a and b are arrays with a.length >= b.length + var l_a = a.length, + l_b = b.length, + r = new Array(l_a), + carry = 0, + base = BASE, + sum, i; + for (i = 0; i < l_b; i++) { + sum = a[i] + b[i] + carry; + carry = sum >= base ? 1 : 0; + r[i] = sum - carry * base; + } + while (i < l_a) { + sum = a[i] + carry; + carry = sum === base ? 1 : 0; + r[i++] = sum - carry * base; + } + if (carry > 0) r.push(carry); + return r; + } + + function addAny(a, b) { + if (a.length >= b.length) return add(a, b); + return add(b, a); + } + + function addSmall(a, carry) { // assumes a is array, carry is number with 0 <= carry < MAX_INT + var l = a.length, + r = new Array(l), + base = BASE, + sum, i; + for (i = 0; i < l; i++) { + sum = a[i] - base + carry; + carry = Math.floor(sum / base); + r[i] = sum - carry * base; + carry += 1; + } + while (carry > 0) { + r[i++] = carry % base; + carry = Math.floor(carry / base); + } + return r; + } + + BigInteger.prototype.add = function (v) { + var n = parseValue(v); + if (this.sign !== n.sign) { + return this.subtract(n.negate()); + } + var a = this.value, b = n.value; + if (n.isSmall) { + return new BigInteger(addSmall(a, Math.abs(b)), this.sign); + } + return new BigInteger(addAny(a, b), this.sign); + }; + BigInteger.prototype.plus = BigInteger.prototype.add; + + SmallInteger.prototype.add = function (v) { + var n = parseValue(v); + var a = this.value; + if (a < 0 !== n.sign) { + return this.subtract(n.negate()); + } + var b = n.value; + if (n.isSmall) { + if (isPrecise(a + b)) return new SmallInteger(a + b); + b = smallToArray(Math.abs(b)); + } + return new BigInteger(addSmall(b, Math.abs(a)), a < 0); + }; + SmallInteger.prototype.plus = SmallInteger.prototype.add; + + NativeBigInt.prototype.add = function (v) { + return new NativeBigInt(this.value + parseValue(v).value); + } + NativeBigInt.prototype.plus = NativeBigInt.prototype.add; + + function subtract(a, b) { // assumes a and b are arrays with a >= b + var a_l = a.length, + b_l = b.length, + r = new Array(a_l), + borrow = 0, + base = BASE, + i, difference; + for (i = 0; i < b_l; i++) { + difference = a[i] - borrow - b[i]; + if (difference < 0) { + difference += base; + borrow = 1; + } else borrow = 0; + r[i] = difference; + } + for (i = b_l; i < a_l; i++) { + difference = a[i] - borrow; + if (difference < 0) difference += base; + else { + r[i++] = difference; + break; + } + r[i] = difference; + } + for (; i < a_l; i++) { + r[i] = a[i]; + } + trim(r); + return r; + } + + function subtractAny(a, b, sign) { + var value; + if (compareAbs(a, b) >= 0) { + value = subtract(a, b); + } else { + value = subtract(b, a); + sign = !sign; + } + value = arrayToSmall(value); + if (typeof value === "number") { + if (sign) value = -value; + return new SmallInteger(value); + } + return new BigInteger(value, sign); + } + + function subtractSmall(a, b, sign) { // assumes a is array, b is number with 0 <= b < MAX_INT + var l = a.length, + r = new Array(l), + carry = -b, + base = BASE, + i, difference; + for (i = 0; i < l; i++) { + difference = a[i] + carry; + carry = Math.floor(difference / base); + difference %= base; + r[i] = difference < 0 ? difference + base : difference; + } + r = arrayToSmall(r); + if (typeof r === "number") { + if (sign) r = -r; + return new SmallInteger(r); + } return new BigInteger(r, sign); + } + + BigInteger.prototype.subtract = function (v) { + var n = parseValue(v); + if (this.sign !== n.sign) { + return this.add(n.negate()); + } + var a = this.value, b = n.value; + if (n.isSmall) + return subtractSmall(a, Math.abs(b), this.sign); + return subtractAny(a, b, this.sign); + }; + BigInteger.prototype.minus = BigInteger.prototype.subtract; + + SmallInteger.prototype.subtract = function (v) { + var n = parseValue(v); + var a = this.value; + if (a < 0 !== n.sign) { + return this.add(n.negate()); + } + var b = n.value; + if (n.isSmall) { + return new SmallInteger(a - b); + } + return subtractSmall(b, Math.abs(a), a >= 0); + }; + SmallInteger.prototype.minus = SmallInteger.prototype.subtract; + + NativeBigInt.prototype.subtract = function (v) { + return new NativeBigInt(this.value - parseValue(v).value); + } + NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract; + + BigInteger.prototype.negate = function () { + return new BigInteger(this.value, !this.sign); + }; + SmallInteger.prototype.negate = function () { + var sign = this.sign; + var small = new SmallInteger(-this.value); + small.sign = !sign; + return small; + }; + NativeBigInt.prototype.negate = function () { + return new NativeBigInt(-this.value); + } + + BigInteger.prototype.abs = function () { + return new BigInteger(this.value, false); + }; + SmallInteger.prototype.abs = function () { + return new SmallInteger(Math.abs(this.value)); + }; + NativeBigInt.prototype.abs = function () { + return new NativeBigInt(this.value >= 0 ? this.value : -this.value); + } + + + function multiplyLong(a, b) { + var a_l = a.length, + b_l = b.length, + l = a_l + b_l, + r = createArray(l), + base = BASE, + product, carry, i, a_i, b_j; + for (i = 0; i < a_l; ++i) { + a_i = a[i]; + for (var j = 0; j < b_l; ++j) { + b_j = b[j]; + product = a_i * b_j + r[i + j]; + carry = Math.floor(product / base); + r[i + j] = product - carry * base; + r[i + j + 1] += carry; + } + } + trim(r); + return r; + } + + function multiplySmall(a, b) { // assumes a is array, b is number with |b| < BASE + var l = a.length, + r = new Array(l), + base = BASE, + carry = 0, + product, i; + for (i = 0; i < l; i++) { + product = a[i] * b + carry; + carry = Math.floor(product / base); + r[i] = product - carry * base; + } + while (carry > 0) { + r[i++] = carry % base; + carry = Math.floor(carry / base); + } + return r; + } + + function shiftLeft(x, n) { + var r = []; + while (n-- > 0) r.push(0); + return r.concat(x); + } + + function multiplyKaratsuba(x, y) { + var n = Math.max(x.length, y.length); + + if (n <= 30) return multiplyLong(x, y); + n = Math.ceil(n / 2); + + var b = x.slice(n), + a = x.slice(0, n), + d = y.slice(n), + c = y.slice(0, n); + + var ac = multiplyKaratsuba(a, c), + bd = multiplyKaratsuba(b, d), + abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); + + var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); + trim(product); + return product; + } + + // The following function is derived from a surface fit of a graph plotting the performance difference + // between long multiplication and karatsuba multiplication versus the lengths of the two arrays. + function useKaratsuba(l1, l2) { + return -0.012 * l1 - 0.012 * l2 + 0.000015 * l1 * l2 > 0; + } + + BigInteger.prototype.multiply = function (v) { + var n = parseValue(v), + a = this.value, b = n.value, + sign = this.sign !== n.sign, + abs; + if (n.isSmall) { + if (b === 0) return Integer[0]; + if (b === 1) return this; + if (b === -1) return this.negate(); + abs = Math.abs(b); + if (abs < BASE) { + return new BigInteger(multiplySmall(a, abs), sign); + } + b = smallToArray(abs); + } + if (useKaratsuba(a.length, b.length)) // Karatsuba is only faster for certain array sizes + return new BigInteger(multiplyKaratsuba(a, b), sign); + return new BigInteger(multiplyLong(a, b), sign); + }; + + BigInteger.prototype.times = BigInteger.prototype.multiply; + + function multiplySmallAndArray(a, b, sign) { // a >= 0 + if (a < BASE) { + return new BigInteger(multiplySmall(b, a), sign); + } + return new BigInteger(multiplyLong(b, smallToArray(a)), sign); + } + SmallInteger.prototype._multiplyBySmall = function (a) { + if (isPrecise(a.value * this.value)) { + return new SmallInteger(a.value * this.value); + } + return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign); + }; + BigInteger.prototype._multiplyBySmall = function (a) { + if (a.value === 0) return Integer[0]; + if (a.value === 1) return this; + if (a.value === -1) return this.negate(); + return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign); + }; + SmallInteger.prototype.multiply = function (v) { + return parseValue(v)._multiplyBySmall(this); + }; + SmallInteger.prototype.times = SmallInteger.prototype.multiply; + + NativeBigInt.prototype.multiply = function (v) { + return new NativeBigInt(this.value * parseValue(v).value); + } + NativeBigInt.prototype.times = NativeBigInt.prototype.multiply; + + function square(a) { + //console.assert(2 * BASE * BASE < MAX_INT); + var l = a.length, + r = createArray(l + l), + base = BASE, + product, carry, i, a_i, a_j; + for (i = 0; i < l; i++) { + a_i = a[i]; + carry = 0 - a_i * a_i; + for (var j = i; j < l; j++) { + a_j = a[j]; + product = 2 * (a_i * a_j) + r[i + j] + carry; + carry = Math.floor(product / base); + r[i + j] = product - carry * base; + } + r[i + l] = carry; + } + trim(r); + return r; + } + + BigInteger.prototype.square = function () { + return new BigInteger(square(this.value), false); + }; + + SmallInteger.prototype.square = function () { + var value = this.value * this.value; + if (isPrecise(value)) return new SmallInteger(value); + return new BigInteger(square(smallToArray(Math.abs(this.value))), false); + }; + + NativeBigInt.prototype.square = function (v) { + return new NativeBigInt(this.value * this.value); + } + + function divMod1(a, b) { // Left over from previous version. Performs faster than divMod2 on smaller input sizes. + var a_l = a.length, + b_l = b.length, + base = BASE, + result = createArray(b.length), + divisorMostSignificantDigit = b[b_l - 1], + // normalization + lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), + remainder = multiplySmall(a, lambda), + divisor = multiplySmall(b, lambda), + quotientDigit, shift, carry, borrow, i, l, q; + if (remainder.length <= a_l) remainder.push(0); + divisor.push(0); + divisorMostSignificantDigit = divisor[b_l - 1]; + for (shift = a_l - b_l; shift >= 0; shift--) { + quotientDigit = base - 1; + if (remainder[shift + b_l] !== divisorMostSignificantDigit) { + quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit); + } + // quotientDigit <= base - 1 + carry = 0; + borrow = 0; + l = divisor.length; + for (i = 0; i < l; i++) { + carry += quotientDigit * divisor[i]; + q = Math.floor(carry / base); + borrow += remainder[shift + i] - (carry - q * base); + carry = q; + if (borrow < 0) { + remainder[shift + i] = borrow + base; + borrow = -1; + } else { + remainder[shift + i] = borrow; + borrow = 0; + } + } + while (borrow !== 0) { + quotientDigit -= 1; + carry = 0; + for (i = 0; i < l; i++) { + carry += remainder[shift + i] - base + divisor[i]; + if (carry < 0) { + remainder[shift + i] = carry + base; + carry = 0; + } else { + remainder[shift + i] = carry; + carry = 1; + } + } + borrow += carry; + } + result[shift] = quotientDigit; + } + // denormalization + remainder = divModSmall(remainder, lambda)[0]; + return [arrayToSmall(result), arrayToSmall(remainder)]; + } + + function divMod2(a, b) { // Implementation idea shamelessly stolen from Silent Matt's library http://silentmatt.com/biginteger/ + // Performs faster than divMod1 on larger input sizes. + var a_l = a.length, + b_l = b.length, + result = [], + part = [], + base = BASE, + guess, xlen, highx, highy, check; + while (a_l) { + part.unshift(a[--a_l]); + trim(part); + if (compareAbs(part, b) < 0) { + result.push(0); + continue; + } + xlen = part.length; + highx = part[xlen - 1] * base + part[xlen - 2]; + highy = b[b_l - 1] * base + b[b_l - 2]; + if (xlen > b_l) { + highx = (highx + 1) * base; + } + guess = Math.ceil(highx / highy); + do { + check = multiplySmall(b, guess); + if (compareAbs(check, part) <= 0) break; + guess--; + } while (guess); + result.push(guess); + part = subtract(part, check); + } + result.reverse(); + return [arrayToSmall(result), arrayToSmall(part)]; + } + + function divModSmall(value, lambda) { + var length = value.length, + quotient = createArray(length), + base = BASE, + i, q, remainder, divisor; + remainder = 0; + for (i = length - 1; i >= 0; --i) { + divisor = remainder * base + value[i]; + q = truncate(divisor / lambda); + remainder = divisor - q * lambda; + quotient[i] = q | 0; + } + return [quotient, remainder | 0]; + } + + function divModAny(self, v) { + var value, n = parseValue(v); + if (supportsNativeBigInt) { + return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)]; + } + var a = self.value, b = n.value; + var quotient; + if (b === 0) throw new Error("Cannot divide by zero"); + if (self.isSmall) { + if (n.isSmall) { + return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)]; + } + return [Integer[0], self]; + } + if (n.isSmall) { + if (b === 1) return [self, Integer[0]]; + if (b == -1) return [self.negate(), Integer[0]]; + var abs = Math.abs(b); + if (abs < BASE) { + value = divModSmall(a, abs); + quotient = arrayToSmall(value[0]); + var remainder = value[1]; + if (self.sign) remainder = -remainder; + if (typeof quotient === "number") { + if (self.sign !== n.sign) quotient = -quotient; + return [new SmallInteger(quotient), new SmallInteger(remainder)]; + } + return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)]; + } + b = smallToArray(abs); + } + var comparison = compareAbs(a, b); + if (comparison === -1) return [Integer[0], self]; + if (comparison === 0) return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; + + // divMod1 is faster on smaller input sizes + if (a.length + b.length <= 200) + value = divMod1(a, b); + else value = divMod2(a, b); + + quotient = value[0]; + var qSign = self.sign !== n.sign, + mod = value[1], + mSign = self.sign; + if (typeof quotient === "number") { + if (qSign) quotient = -quotient; + quotient = new SmallInteger(quotient); + } else quotient = new BigInteger(quotient, qSign); + if (typeof mod === "number") { + if (mSign) mod = -mod; + mod = new SmallInteger(mod); + } else mod = new BigInteger(mod, mSign); + return [quotient, mod]; + } + + BigInteger.prototype.divmod = function (v) { + var result = divModAny(this, v); + return { + quotient: result[0], + remainder: result[1] + }; + }; + NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod; + + + BigInteger.prototype.divide = function (v) { + return divModAny(this, v)[0]; + }; + NativeBigInt.prototype.over = NativeBigInt.prototype.divide = function (v) { + return new NativeBigInt(this.value / parseValue(v).value); + }; + SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide; + + BigInteger.prototype.mod = function (v) { + return divModAny(this, v)[1]; + }; + NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = function (v) { + return new NativeBigInt(this.value % parseValue(v).value); + }; + SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod; + + BigInteger.prototype.pow = function (v) { + var n = parseValue(v), + a = this.value, + b = n.value, + value, x, y; + if (b === 0) return Integer[1]; + if (a === 0) return Integer[0]; + if (a === 1) return Integer[1]; + if (a === -1) return n.isEven() ? Integer[1] : Integer[-1]; + if (n.sign) { + return Integer[0]; + } + if (!n.isSmall) throw new Error("The exponent " + n.toString() + " is too large."); + if (this.isSmall) { + if (isPrecise(value = Math.pow(a, b))) + return new SmallInteger(truncate(value)); + } + x = this; + y = Integer[1]; + while (true) { + if (b & 1 === 1) { + y = y.times(x); + --b; + } + if (b === 0) break; + b /= 2; + x = x.square(); + } + return y; + }; + SmallInteger.prototype.pow = BigInteger.prototype.pow; + + NativeBigInt.prototype.pow = function (v) { + var n = parseValue(v); + var a = this.value, b = n.value; + var _0 = BigInt(0), _1 = BigInt(1), _2 = BigInt(2); + if (b === _0) return Integer[1]; + if (a === _0) return Integer[0]; + if (a === _1) return Integer[1]; + if (a === BigInt(-1)) return n.isEven() ? Integer[1] : Integer[-1]; + if (n.isNegative()) return new NativeBigInt(_0); + var x = this; + var y = Integer[1]; + while (true) { + if ((b & _1) === _1) { + y = y.times(x); + --b; + } + if (b === _0) break; + b /= _2; + x = x.square(); + } + return y; + } + + BigInteger.prototype.modPow = function (exp, mod) { + exp = parseValue(exp); + mod = parseValue(mod); + if (mod.isZero()) throw new Error("Cannot take modPow with modulus 0"); + var r = Integer[1], + base = this.mod(mod); + if (exp.isNegative()) { + exp = exp.multiply(Integer[-1]); + base = base.modInv(mod); + } + while (exp.isPositive()) { + if (base.isZero()) return Integer[0]; + if (exp.isOdd()) r = r.multiply(base).mod(mod); + exp = exp.divide(2); + base = base.square().mod(mod); + } + return r; + }; + NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow; + + function compareAbs(a, b) { + if (a.length !== b.length) { + return a.length > b.length ? 1 : -1; + } + for (var i = a.length - 1; i >= 0; i--) { + if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1; + } + return 0; + } + + BigInteger.prototype.compareAbs = function (v) { + var n = parseValue(v), + a = this.value, + b = n.value; + if (n.isSmall) return 1; + return compareAbs(a, b); + }; + SmallInteger.prototype.compareAbs = function (v) { + var n = parseValue(v), + a = Math.abs(this.value), + b = n.value; + if (n.isSmall) { + b = Math.abs(b); + return a === b ? 0 : a > b ? 1 : -1; + } + return -1; + }; + NativeBigInt.prototype.compareAbs = function (v) { + var a = this.value; + var b = parseValue(v).value; + a = a >= 0 ? a : -a; + b = b >= 0 ? b : -b; + return a === b ? 0 : a > b ? 1 : -1; + } + + BigInteger.prototype.compare = function (v) { + // See discussion about comparison with Infinity: + // https://github.com/peterolson/BigInteger.js/issues/61 + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + + var n = parseValue(v), + a = this.value, + b = n.value; + if (this.sign !== n.sign) { + return n.sign ? 1 : -1; + } + if (n.isSmall) { + return this.sign ? -1 : 1; + } + return compareAbs(a, b) * (this.sign ? -1 : 1); + }; + BigInteger.prototype.compareTo = BigInteger.prototype.compare; + + SmallInteger.prototype.compare = function (v) { + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + + var n = parseValue(v), + a = this.value, + b = n.value; + if (n.isSmall) { + return a == b ? 0 : a > b ? 1 : -1; + } + if (a < 0 !== n.sign) { + return a < 0 ? -1 : 1; + } + return a < 0 ? 1 : -1; + }; + SmallInteger.prototype.compareTo = SmallInteger.prototype.compare; + + NativeBigInt.prototype.compare = function (v) { + if (v === Infinity) { + return -1; + } + if (v === -Infinity) { + return 1; + } + var a = this.value; + var b = parseValue(v).value; + return a === b ? 0 : a > b ? 1 : -1; + } + NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare; + + BigInteger.prototype.equals = function (v) { + return this.compare(v) === 0; + }; + NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals; + + BigInteger.prototype.notEquals = function (v) { + return this.compare(v) !== 0; + }; + NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals; + + BigInteger.prototype.greater = function (v) { + return this.compare(v) > 0; + }; + NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater; + + BigInteger.prototype.lesser = function (v) { + return this.compare(v) < 0; + }; + NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser; + + BigInteger.prototype.greaterOrEquals = function (v) { + return this.compare(v) >= 0; + }; + NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals; + + BigInteger.prototype.lesserOrEquals = function (v) { + return this.compare(v) <= 0; + }; + NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals; + + BigInteger.prototype.isEven = function () { + return (this.value[0] & 1) === 0; + }; + SmallInteger.prototype.isEven = function () { + return (this.value & 1) === 0; + }; + NativeBigInt.prototype.isEven = function () { + return (this.value & BigInt(1)) === BigInt(0); + } + + BigInteger.prototype.isOdd = function () { + return (this.value[0] & 1) === 1; + }; + SmallInteger.prototype.isOdd = function () { + return (this.value & 1) === 1; + }; + NativeBigInt.prototype.isOdd = function () { + return (this.value & BigInt(1)) === BigInt(1); + } + + BigInteger.prototype.isPositive = function () { + return !this.sign; + }; + SmallInteger.prototype.isPositive = function () { + return this.value > 0; + }; + NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive; + + BigInteger.prototype.isNegative = function () { + return this.sign; + }; + SmallInteger.prototype.isNegative = function () { + return this.value < 0; + }; + NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative; + + BigInteger.prototype.isUnit = function () { + return false; + }; + SmallInteger.prototype.isUnit = function () { + return Math.abs(this.value) === 1; + }; + NativeBigInt.prototype.isUnit = function () { + return this.abs().value === BigInt(1); + } + + BigInteger.prototype.isZero = function () { + return false; + }; + SmallInteger.prototype.isZero = function () { + return this.value === 0; + }; + NativeBigInt.prototype.isZero = function () { + return this.value === BigInt(0); + } + + BigInteger.prototype.isDivisibleBy = function (v) { + var n = parseValue(v); + if (n.isZero()) return false; + if (n.isUnit()) return true; + if (n.compareAbs(2) === 0) return this.isEven(); + return this.mod(n).isZero(); + }; + NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy; + + function isBasicPrime(v) { + var n = v.abs(); + if (n.isUnit()) return false; + if (n.equals(2) || n.equals(3) || n.equals(5)) return true; + if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false; + if (n.lesser(49)) return true; + // we don't know if it's prime: let the other functions figure it out + } + + function millerRabinTest(n, a) { + var nPrev = n.prev(), + b = nPrev, + r = 0, + d, t, i, x; + while (b.isEven()) b = b.divide(2), r++; + next: for (i = 0; i < a.length; i++) { + if (n.lesser(a[i])) continue; + x = bigInt(a[i]).modPow(b, n); + if (x.isUnit() || x.equals(nPrev)) continue; + for (d = r - 1; d != 0; d--) { + x = x.square().mod(n); + if (x.isUnit()) return false; + if (x.equals(nPrev)) continue next; + } + return false; + } + return true; + } + + // Set "strict" to true to force GRH-supported lower bound of 2*log(N)^2 + BigInteger.prototype.isPrime = function (strict) { + var isPrime = isBasicPrime(this); + if (isPrime !== undefined) return isPrime; + var n = this.abs(); + var bits = n.bitLength(); + if (bits <= 64) + return millerRabinTest(n, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]); + var logN = Math.log(2) * bits.toJSNumber(); + var t = Math.ceil((strict === true) ? (2 * Math.pow(logN, 2)) : logN); + for (var a = [], i = 0; i < t; i++) { + a.push(bigInt(i + 2)); + } + return millerRabinTest(n, a); + }; + NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime; + + BigInteger.prototype.isProbablePrime = function (iterations, rng) { + var isPrime = isBasicPrime(this); + if (isPrime !== undefined) return isPrime; + var n = this.abs(); + var t = iterations === undefined ? 5 : iterations; + for (var a = [], i = 0; i < t; i++) { + a.push(bigInt.randBetween(2, n.minus(2), rng)); + } + return millerRabinTest(n, a); + }; + NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime; + + BigInteger.prototype.modInv = function (n) { + var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; + while (!newR.isZero()) { + q = r.divide(newR); + lastT = t; + lastR = r; + t = newT; + r = newR; + newT = lastT.subtract(q.multiply(newT)); + newR = lastR.subtract(q.multiply(newR)); + } + if (!r.isUnit()) throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); + if (t.compare(0) === -1) { + t = t.add(n); + } + if (this.isNegative()) { + return t.negate(); + } + return t; + }; + + NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv; + + BigInteger.prototype.next = function () { + var value = this.value; + if (this.sign) { + return subtractSmall(value, 1, this.sign); + } + return new BigInteger(addSmall(value, 1), this.sign); + }; + SmallInteger.prototype.next = function () { + var value = this.value; + if (value + 1 < MAX_INT) return new SmallInteger(value + 1); + return new BigInteger(MAX_INT_ARR, false); + }; + NativeBigInt.prototype.next = function () { + return new NativeBigInt(this.value + BigInt(1)); + } + + BigInteger.prototype.prev = function () { + var value = this.value; + if (this.sign) { + return new BigInteger(addSmall(value, 1), true); + } + return subtractSmall(value, 1, this.sign); + }; + SmallInteger.prototype.prev = function () { + var value = this.value; + if (value - 1 > -MAX_INT) return new SmallInteger(value - 1); + return new BigInteger(MAX_INT_ARR, true); + }; + NativeBigInt.prototype.prev = function () { + return new NativeBigInt(this.value - BigInt(1)); + } + + var powersOfTwo = [1]; + while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE) powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]); + var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1]; + + function shift_isSmall(n) { + return Math.abs(n) <= BASE; + } + + BigInteger.prototype.shiftLeft = function (v) { + var n = parseValue(v).toJSNumber(); + if (!shift_isSmall(n)) { + throw new Error(String(n) + " is too large for shifting."); + } + if (n < 0) return this.shiftRight(-n); + var result = this; + if (result.isZero()) return result; + while (n >= powers2Length) { + result = result.multiply(highestPower2); + n -= powers2Length - 1; + } + return result.multiply(powersOfTwo[n]); + }; + NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft; + + BigInteger.prototype.shiftRight = function (v) { + var remQuo; + var n = parseValue(v).toJSNumber(); + if (!shift_isSmall(n)) { + throw new Error(String(n) + " is too large for shifting."); + } + if (n < 0) return this.shiftLeft(-n); + var result = this; + while (n >= powers2Length) { + if (result.isZero() || (result.isNegative() && result.isUnit())) return result; + remQuo = divModAny(result, highestPower2); + result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; + n -= powers2Length - 1; + } + remQuo = divModAny(result, powersOfTwo[n]); + return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; + }; + NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight; + + function bitwise(x, y, fn) { + y = parseValue(y); + var xSign = x.isNegative(), ySign = y.isNegative(); + var xRem = xSign ? x.not() : x, + yRem = ySign ? y.not() : y; + var xDigit = 0, yDigit = 0; + var xDivMod = null, yDivMod = null; + var result = []; + while (!xRem.isZero() || !yRem.isZero()) { + xDivMod = divModAny(xRem, highestPower2); + xDigit = xDivMod[1].toJSNumber(); + if (xSign) { + xDigit = highestPower2 - 1 - xDigit; // two's complement for negative numbers + } + + yDivMod = divModAny(yRem, highestPower2); + yDigit = yDivMod[1].toJSNumber(); + if (ySign) { + yDigit = highestPower2 - 1 - yDigit; // two's complement for negative numbers + } + + xRem = xDivMod[0]; + yRem = yDivMod[0]; + result.push(fn(xDigit, yDigit)); + } + var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); + for (var i = result.length - 1; i >= 0; i -= 1) { + sum = sum.multiply(highestPower2).add(bigInt(result[i])); + } + return sum; + } + + BigInteger.prototype.not = function () { + return this.negate().prev(); + }; + NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not; + + BigInteger.prototype.and = function (n) { + return bitwise(this, n, function (a, b) { return a & b; }); + }; + NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and; + + BigInteger.prototype.or = function (n) { + return bitwise(this, n, function (a, b) { return a | b; }); + }; + NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or; + + BigInteger.prototype.xor = function (n) { + return bitwise(this, n, function (a, b) { return a ^ b; }); + }; + NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor; + + var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I; + function roughLOB(n) { // get lowestOneBit (rough) + // SmallInteger: return Min(lowestOneBit(n), 1 << 30) + // BigInteger: return Min(lowestOneBit(n), 1 << 14) [BASE=1e7] + var v = n.value, + x = typeof v === "number" ? v | LOBMASK_I : + typeof v === "bigint" ? v | BigInt(LOBMASK_I) : + v[0] + v[1] * BASE | LOBMASK_BI; + return x & -x; + } + + function integerLogarithm(value, base) { + if (base.compareTo(value) <= 0) { + var tmp = integerLogarithm(value, base.square(base)); + var p = tmp.p; + var e = tmp.e; + var t = p.multiply(base); + return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 }; + } + return { p: bigInt(1), e: 0 }; + } + + BigInteger.prototype.bitLength = function () { + var n = this; + if (n.compareTo(bigInt(0)) < 0) { + n = n.negate().subtract(bigInt(1)); + } + if (n.compareTo(bigInt(0)) === 0) { + return bigInt(0); + } + return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1)); + } + NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength; + + function max(a, b) { + a = parseValue(a); + b = parseValue(b); + return a.greater(b) ? a : b; + } + function min(a, b) { + a = parseValue(a); + b = parseValue(b); + return a.lesser(b) ? a : b; + } + function gcd(a, b) { + a = parseValue(a).abs(); + b = parseValue(b).abs(); + if (a.equals(b)) return a; + if (a.isZero()) return b; + if (b.isZero()) return a; + var c = Integer[1], d, t; + while (a.isEven() && b.isEven()) { + d = min(roughLOB(a), roughLOB(b)); + a = a.divide(d); + b = b.divide(d); + c = c.multiply(d); + } + while (a.isEven()) { + a = a.divide(roughLOB(a)); + } + do { + while (b.isEven()) { + b = b.divide(roughLOB(b)); + } + if (a.greater(b)) { + t = b; b = a; a = t; + } + b = b.subtract(a); + } while (!b.isZero()); + return c.isUnit() ? a : a.multiply(c); + } + function lcm(a, b) { + a = parseValue(a).abs(); + b = parseValue(b).abs(); + return a.divide(gcd(a, b)).multiply(b); + } + function randBetween(a, b, rng) { + a = parseValue(a); + b = parseValue(b); + var usedRNG = rng || Math.random; + var low = min(a, b), high = max(a, b); + var range = high.subtract(low).add(1); + if (range.isSmall) return low.add(Math.floor(usedRNG() * range)); + var digits = toBase(range, BASE).value; + var result = [], restricted = true; + for (var i = 0; i < digits.length; i++) { + var top = restricted ? digits[i] + (i + 1 < digits.length ? digits[i + 1] / BASE : 0) : BASE; + var digit = truncate(usedRNG() * top); + result.push(digit); + if (digit < digits[i]) restricted = false; + } + return low.add(Integer.fromArray(result, BASE, false)); + } + + var parseBase = function (text, base, alphabet, caseSensitive) { + alphabet = alphabet || DEFAULT_ALPHABET; + text = String(text); + if (!caseSensitive) { + text = text.toLowerCase(); + alphabet = alphabet.toLowerCase(); + } + var length = text.length; + var i; + var absBase = Math.abs(base); + var alphabetValues = {}; + for (i = 0; i < alphabet.length; i++) { + alphabetValues[alphabet[i]] = i; + } + for (i = 0; i < length; i++) { + var c = text[i]; + if (c === "-") continue; + if (c in alphabetValues) { + if (alphabetValues[c] >= absBase) { + if (c === "1" && absBase === 1) continue; + throw new Error(c + " is not a valid digit in base " + base + "."); + } + } + } + base = parseValue(base); + var digits = []; + var isNegative = text[0] === "-"; + for (i = isNegative ? 1 : 0; i < text.length; i++) { + var c = text[i]; + if (c in alphabetValues) digits.push(parseValue(alphabetValues[c])); + else if (c === "<") { + var start = i; + do { i++; } while (text[i] !== ">" && i < text.length); + digits.push(parseValue(text.slice(start + 1, i))); + } + else throw new Error(c + " is not a valid character"); + } + return parseBaseFromArray(digits, base, isNegative); + }; + + function parseBaseFromArray(digits, base, isNegative) { + var val = Integer[0], pow = Integer[1], i; + for (i = digits.length - 1; i >= 0; i--) { + val = val.add(digits[i].times(pow)); + pow = pow.times(base); + } + return isNegative ? val.negate() : val; + } + + function stringify(digit, alphabet) { + alphabet = alphabet || DEFAULT_ALPHABET; + if (digit < alphabet.length) { + return alphabet[digit]; + } + return "<" + digit + ">"; + } + + function toBase(n, base) { + base = bigInt(base); + if (base.isZero()) { + if (n.isZero()) return { value: [0], isNegative: false }; + throw new Error("Cannot convert nonzero numbers to base 0."); + } + if (base.equals(-1)) { + if (n.isZero()) return { value: [0], isNegative: false }; + if (n.isNegative()) + return { + value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber())) + .map(Array.prototype.valueOf, [1, 0]) + ), + isNegative: false + }; + + var arr = Array.apply(null, Array(n.toJSNumber() - 1)) + .map(Array.prototype.valueOf, [0, 1]); + arr.unshift([1]); + return { + value: [].concat.apply([], arr), + isNegative: false + }; + } + + var neg = false; + if (n.isNegative() && base.isPositive()) { + neg = true; + n = n.abs(); + } + if (base.isUnit()) { + if (n.isZero()) return { value: [0], isNegative: false }; + + return { + value: Array.apply(null, Array(n.toJSNumber())) + .map(Number.prototype.valueOf, 1), + isNegative: neg + }; + } + var out = []; + var left = n, divmod; + while (left.isNegative() || left.compareAbs(base) >= 0) { + divmod = left.divmod(base); + left = divmod.quotient; + var digit = divmod.remainder; + if (digit.isNegative()) { + digit = base.minus(digit).abs(); + left = left.next(); + } + out.push(digit.toJSNumber()); + } + out.push(left.toJSNumber()); + return { value: out.reverse(), isNegative: neg }; + } + + function toBaseString(n, base, alphabet) { + var arr = toBase(n, base); + return (arr.isNegative ? "-" : "") + arr.value.map(function (x) { + return stringify(x, alphabet); + }).join(''); + } + + BigInteger.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + SmallInteger.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + NativeBigInt.prototype.toArray = function (radix) { + return toBase(this, radix); + }; + + BigInteger.prototype.toString = function (radix, alphabet) { + if (radix === undefined) radix = 10; + if (radix !== 10) return toBaseString(this, radix, alphabet); + var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; + while (--l >= 0) { + digit = String(v[l]); + str += zeros.slice(digit.length) + digit; + } + var sign = this.sign ? "-" : ""; + return sign + str; + }; + + SmallInteger.prototype.toString = function (radix, alphabet) { + if (radix === undefined) radix = 10; + if (radix != 10) return toBaseString(this, radix, alphabet); + return String(this.value); + }; + + NativeBigInt.prototype.toString = SmallInteger.prototype.toString; + + NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); } + + BigInteger.prototype.valueOf = function () { + return parseInt(this.toString(), 10); + }; + BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf; + + SmallInteger.prototype.valueOf = function () { + return this.value; + }; + SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf; + NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () { + return parseInt(this.toString(), 10); + } + + function parseStringValue(v) { + if (isPrecise(+v)) { + var x = +v; + if (x === truncate(x)) + return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x); + throw new Error("Invalid integer: " + v); + } + var sign = v[0] === "-"; + if (sign) v = v.slice(1); + var split = v.split(/e/i); + if (split.length > 2) throw new Error("Invalid integer: " + split.join("e")); + if (split.length === 2) { + var exp = split[1]; + if (exp[0] === "+") exp = exp.slice(1); + exp = +exp; + if (exp !== truncate(exp) || !isPrecise(exp)) throw new Error("Invalid integer: " + exp + " is not a valid exponent."); + var text = split[0]; + var decimalPlace = text.indexOf("."); + if (decimalPlace >= 0) { + exp -= text.length - decimalPlace - 1; + text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1); + } + if (exp < 0) throw new Error("Cannot include negative exponent part for integers"); + text += (new Array(exp + 1)).join("0"); + v = text; + } + var isValid = /^([0-9][0-9]*)$/.test(v); + if (!isValid) throw new Error("Invalid integer: " + v); + if (supportsNativeBigInt) { + return new NativeBigInt(BigInt(sign ? "-" + v : v)); + } + var r = [], max = v.length, l = LOG_BASE, min = max - l; + while (max > 0) { + r.push(+v.slice(min, max)); + min -= l; + if (min < 0) min = 0; + max -= l; + } + trim(r); + return new BigInteger(r, sign); + } + + function parseNumberValue(v) { + if (supportsNativeBigInt) { + return new NativeBigInt(BigInt(v)); + } + if (isPrecise(v)) { + if (v !== truncate(v)) throw new Error(v + " is not an integer."); + return new SmallInteger(v); + } + return parseStringValue(v.toString()); + } + + function parseValue(v) { + if (typeof v === "number") { + return parseNumberValue(v); + } + if (typeof v === "string") { + return parseStringValue(v); + } + if (typeof v === "bigint") { + return new NativeBigInt(v); + } + return v; + } + // Pre-define numbers in range [-999,999] + for (var i = 0; i < 1000; i++) { + Integer[i] = parseValue(i); + if (i > 0) Integer[-i] = parseValue(-i); + } + // Backwards compatibility + Integer.one = Integer[1]; + Integer.zero = Integer[0]; + Integer.minusOne = Integer[-1]; + Integer.max = max; + Integer.min = min; + Integer.gcd = gcd; + Integer.lcm = lcm; + Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; }; + Integer.randBetween = randBetween; + + Integer.fromArray = function (digits, base, isNegative) { + return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative); + }; + + return Integer; +})(); + +// Node.js check +if (typeof module !== "undefined" && module.hasOwnProperty("exports")) { + module.exports = bigInt; +} + +//amd check +if (typeof define === "function" && define.amd) { + define( function () { + return bigInt; + }); +} + +},{}],4:[function(require,module,exports){ +(function (Buffer){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +/* global BigInt */ +const bigInt = require("big-integer"); + +let wBigInt; + +if (typeof(BigInt) != "undefined") { + wBigInt = BigInt; + wBigInt.one = wBigInt(1); + wBigInt.zero = wBigInt(0); + + // Affine + wBigInt.genAffine = (q) => { + const nq = -q; + return (a) => { + let aux = a; + if (aux < 0) { + if (aux <= nq) { + aux = aux % q; + } + if (aux < wBigInt.zero) { + aux = aux + q; + } + } else { + if (aux >= q) { + aux = aux % q; + } + } + return aux.valueOf(); + }; + }; + + + // Inverse + wBigInt.genInverse = (q) => { + return (a) => { + let t = wBigInt.zero; + let r = q; + let newt = wBigInt.one; + let newr = wBigInt.affine(a, q); + while (newr!=wBigInt.zero) { + let q = r/newr; + [t, newt] = [newt, t-q*newt]; + [r, newr] = [newr, r-q*newr]; + } + if (t { + if (q) { + return (a,b) => (a+b) % q; + } else { + return (a,b) => a+b; + } + }; + + // Sub + wBigInt.genSub = (q) => { + if (q) { + return (a,b) => (a-b) % q; + } else { + return (a,b) => a-b; + } + }; + + + // Neg + wBigInt.genNeg = (q) => { + if (q) { + return (a) => (-a) % q; + } else { + return (a) => -a; + } + }; + + // Mul + wBigInt.genMul = (q) => { + if (q) { + return (a,b) => (a*b) % q; + } else { + return (a,b) => a*b; + } + }; + + // Shr + wBigInt.genShr = () => { + return (a,b) => a >> wBigInt(b); + }; + + // Shl + wBigInt.genShl = (q) => { + if (q) { + return (a,b) => (a << wBigInt(b)) % q; + } else { + return (a,b) => a << wBigInt(b); + } + }; + + // Equals + wBigInt.genEquals = (q) => { + if (q) { + return (a,b) => (a.affine(q) == b.affine(q)); + } else { + return (a,b) => a == b; + } + }; + + // Square + wBigInt.genSquare = (q) => { + if (q) { + return (a) => (a*a) %q; + } else { + return (a) => a*a; + } + }; + + + // Double + wBigInt.genDouble = (q) => { + if (q) { + return (a) => (a+a) %q; + } else { + return (a) => a+a; + } + }; + + // IsZero + wBigInt.genIsZero = (q) => { + if (q) { + return (a) => (a.affine(q) == wBigInt.zero); + } else { + return (a) => a == wBigInt.zero; + } + }; + + + // Other minor functions + wBigInt.prototype.isOdd = function() { + return (this & wBigInt.one) == wBigInt(1); + }; + + wBigInt.prototype.isNegative = function() { + return this < wBigInt.zero; + }; + + wBigInt.prototype.and = function(m) { + return this & m; + }; + + wBigInt.prototype.div = function(c) { + return this / c; + }; + + wBigInt.prototype.mod = function(c) { + return this % c; + }; + + wBigInt.prototype.pow = function(c) { + return this ** c; + }; + + wBigInt.prototype.abs = function() { + return (this > wBigInt.zero) ? this : -this; + }; + + wBigInt.prototype.modPow = function(e, m) { + let acc = wBigInt.one; + let exp = this; + let rem = e; + while (rem) { + if (rem & wBigInt.one) { + acc = (acc * exp) %m; + } + exp = (exp * exp) % m; + rem = rem >> wBigInt.one; + } + return acc; + }; + + wBigInt.prototype.greaterOrEquals = function(b) { + return this >= b; + }; + + wBigInt.prototype.greater = function(b) { + return this > b; + }; + wBigInt.prototype.gt = wBigInt.prototype.greater; + + wBigInt.prototype.lesserOrEquals = function(b) { + return this <= b; + }; + + wBigInt.prototype.lesser = function(b) { + return this < b; + }; + wBigInt.prototype.lt = wBigInt.prototype.lesser; + + wBigInt.prototype.equals = function(b) { + return this == b; + }; + wBigInt.prototype.eq = wBigInt.prototype.equals; + + wBigInt.prototype.neq = function(b) { + return this != b; + }; + + wBigInt.prototype.toJSNumber = function() { + return Number(this); + }; + + +} else { + + var oldProto = bigInt.prototype; + wBigInt = function(a) { + if ((typeof a == "string") && (a.slice(0,2) == "0x")) { + return bigInt(a.slice(2), 16); + } else { + return bigInt(a); + } + }; + wBigInt.one = bigInt.one; + wBigInt.zero = bigInt.zero; + wBigInt.prototype = oldProto; + + wBigInt.prototype.div = function(c) { + return this.divide(c); + }; + + // Affine + wBigInt.genAffine = (q) => { + const nq = wBigInt.zero.minus(q); + return (a) => { + let aux = a; + if (aux.isNegative()) { + if (aux.lesserOrEquals(nq)) { + aux = aux.mod(q); + } + if (aux.isNegative()) { + aux = aux.add(q); + } + } else { + if (aux.greaterOrEquals(q)) { + aux = aux.mod(q); + } + } + return aux; + }; + }; + + + // Inverse + wBigInt.genInverse = (q) => { + return (a) => a.affine(q).modInv(q); + }; + + // Add + wBigInt.genAdd = (q) => { + if (q) { + return (a,b) => { + const r = a.add(b); + return r.greaterOrEquals(q) ? r.minus(q) : r; + }; + } else { + return (a,b) => a.add(b); + } + }; + + // Sub + wBigInt.genSub = (q) => { + if (q) { + return (a,b) => a.greaterOrEquals(b) ? a.minus(b) : a.minus(b).add(q); + } else { + return (a,b) => a.minus(b); + } + }; + + wBigInt.genNeg = (q) => { + if (q) { + return (a) => a.isZero() ? a : q.minus(a); + } else { + return (a) => wBigInt.zero.minus(a); + } + }; + + // Mul + wBigInt.genMul = (q) => { + if (q) { + return (a,b) => a.times(b).mod(q); + } else { + return (a,b) => a.times(b); + } + }; + + // Shr + wBigInt.genShr = () => { + return (a,b) => a.shiftRight(wBigInt(b).value); + }; + + // Shr + wBigInt.genShl = (q) => { + if (q) { + return (a,b) => a.shiftLeft(wBigInt(b).value).mod(q); + } else { + return (a,b) => a.shiftLeft(wBigInt(b).value); + } + }; + + // Square + wBigInt.genSquare = (q) => { + if (q) { + return (a) => a.square().mod(q); + } else { + return (a) => a.square(); + } + }; + + // Double + wBigInt.genDouble = (q) => { + if (q) { + return (a) => a.add(a).mod(q); + } else { + return (a) => a.add(a); + } + }; + + // Equals + wBigInt.genEquals = (q) => { + if (q) { + return (a,b) => a.affine(q).equals(b.affine(q)); + } else { + return (a,b) => a.equals(b); + } + }; + + // IsZero + wBigInt.genIsZero = (q) => { + if (q) { + return (a) => (a.affine(q).isZero()); + } else { + return (a) => a.isZero(); + } + }; +} + + + +wBigInt.affine = function(a, q) { + return wBigInt.genAffine(q)(a); +}; + +wBigInt.prototype.affine = function (q) { + return wBigInt.affine(this, q); +}; + +wBigInt.inverse = function(a, q) { + return wBigInt.genInverse(q)(a); +}; + +wBigInt.prototype.inverse = function (q) { + return wBigInt.genInverse(q)(this); +}; + +wBigInt.add = function(a, b, q) { + return wBigInt.genAdd(q)(a,b); +}; + +wBigInt.prototype.add = function (a, q) { + return wBigInt.genAdd(q)(this, a); +}; + +wBigInt.sub = function(a, b, q) { + return wBigInt.genSub(q)(a,b); +}; + +wBigInt.prototype.sub = function (a, q) { + return wBigInt.genSub(q)(this, a); +}; + +wBigInt.neg = function(a, q) { + return wBigInt.genNeg(q)(a); +}; + +wBigInt.prototype.neg = function (q) { + return wBigInt.genNeg(q)(this); +}; + +wBigInt.mul = function(a, b, q) { + return wBigInt.genMul(q)(a,b); +}; + +wBigInt.prototype.mul = function (a, q) { + return wBigInt.genMul(q)(this, a); +}; + +wBigInt.shr = function(a, b, q) { + return wBigInt.genShr(q)(a,b); +}; + +wBigInt.prototype.shr = function (a, q) { + return wBigInt.genShr(q)(this, a); +}; + +wBigInt.shl = function(a, b, q) { + return wBigInt.genShl(q)(a,b); +}; + +wBigInt.prototype.shl = function (a, q) { + return wBigInt.genShl(q)(this, a); +}; + +wBigInt.equals = function(a, b, q) { + return wBigInt.genEquals(q)(a,b); +}; + +wBigInt.prototype.equals = function (a, q) { + return wBigInt.genEquals(q)(this, a); +}; + +wBigInt.square = function(a, q) { + return wBigInt.genSquare(q)(a); +}; + +wBigInt.prototype.square = function (q) { + return wBigInt.genSquare(q)(this); +}; + +wBigInt.double = function(a, q) { + return wBigInt.genDouble(q)(a); +}; + +wBigInt.prototype.double = function (q) { + return wBigInt.genDouble(q)(this); +}; + +wBigInt.isZero = function(a, q) { + return wBigInt.genIsZero(q)(a); +}; + +wBigInt.prototype.isZero = function (q) { + return wBigInt.genIsZero(q)(this); +}; + +wBigInt.leBuff2int = function(buff) { + let res = wBigInt.zero; + for (let i=0; i=0)) { + let c = Number(r.and(wBigInt("255"))); + buff[o] = c; + o--; + r = r.shr(8); + } + if (r.greater(wBigInt.zero)) throw new Error("Number does not feed in buffer"); + return buff; +}; + +wBigInt.prototype.beInt2Buff = function (len) { + return wBigInt.beInt2Buff(this,len); +}; + +module.exports = wBigInt; + + +}).call(this,require("buffer").Buffer) +},{"big-integer":3,"buffer":14}],5:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint"); + +module.exports = calculateWitness; + +function calculateWitness(circuit, inputSignals, options) { + options = options || {}; + if (!options.logFunction) options.logFunction = console.log; + const ctx = new RTCtx(circuit, options); + + function iterateSelector(values, sels, cb) { + if (!Array.isArray(values)) { + return cb(sels, values); + } + for (let i=0; i " + ctx.witness[i].toString()); + } + return ctx.witness.slice(0, circuit.nVars); +// return ctx.witness; +} + +class RTCtx { + constructor(circuit, options) { + this.options = options; + this.scopes = []; + this.circuit = circuit; + this.witness = new Array(circuit.nSignals); + this.notInitSignals = {}; + for (let c in this.circuit.components) { + this.notInitSignals[c] = this.circuit.components[c].inputSignals; + } + } + + _sels2str(sels) { + let res = ""; + for (let i=0; i { + if (this.notInitSignals[c] == 0) this.triggerComponent(c); + }); + return this.witness[sId]; + } + + setVar(name, sels, value) { + function setVarArray(a, sels2, value) { + if (sels2.length == 1) { + a[sels2[0]] = value; + } else { + if (typeof(a[sels2[0]]) == "undefined") a[sels2[0]] = []; + setVarArray(a[sels2[0]], sels2.slice(1), value); + } + } + const scope = this.scopes[this.scopes.length-1]; + if (sels.length == 0) { + scope[name] = value; + } else { + if (typeof(scope[name]) == "undefined") scope[name] = []; + setVarArray(scope[name], sels, value); + } + return value; + } + + getVar(name, sels) { + function select(a, sels2) { + return (sels2.length == 0) ? a : select(a[sels2[0]], sels2.slice(1)); + } + for (let i=this.scopes.length-1; i>=0; i--) { + if (typeof(this.scopes[i][name]) != "undefined") return select(this.scopes[i][name], sels); + } + throw new Error("Variable not defined: " + name); + } + + getSignal(name, sels) { + let fullName = name=="one" ? "one" : this.currentComponent + "." + name; + fullName += this._sels2str(sels); + return this.getSignalFullName(fullName); + } + + + getPin(componentName, componentSels, signalName, signalSels) { + let fullName = componentName=="one" ? "one" : this.currentComponent + "." + componentName; + fullName += this._sels2str(componentSels) + + "."+ + signalName+ + this._sels2str(signalSels); + return this.getSignalFullName(fullName); + } + + getSignalFullName(fullName) { + const sId = this.circuit.getSignalIdx(fullName); + if (typeof(this.witness[sId]) == "undefined") { + throw new Error("Signal not initialized: "+fullName); + } + if (this.options.logGet) this.options.logFunction("get --->" + fullName + " = " + this.witness[sId].toString() ); + return this.witness[sId]; + } + + assert(a,b,errStr) { + const ba = bigInt(a); + const bb = bigInt(b); + if (!ba.equals(bb)) { + throw new Error("Constraint doesn't match "+ this.currentComponent+": "+ errStr + " -> "+ ba.toString() + " != " + bb.toString()); + } + } +} + +},{"./bigint":4}],6:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint.js"); + +const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); +const __MASK__ = bigInt("28948022309329048855892746252171976963317496166410141009864396001978282409983"); // 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +const calculateWitness = require("./calculateWitness.js"); + +module.exports = class Circuit { + constructor(circuitDef) { + this.nPubInputs = circuitDef.nPubInputs; + this.nPrvInputs = circuitDef.nPrvInputs; + this.nInputs = circuitDef.nInputs; + this.nOutputs = circuitDef.nOutputs; + this.nVars = circuitDef.nVars; + this.nSignals = circuitDef.nSignals; + this.nConstants = circuitDef.nConstants; + + this.nConstraints = circuitDef.constraints.length; + + this.signalName2Idx = circuitDef.signalName2Idx; + this.components = circuitDef.components; + this.componentName2Idx = circuitDef.componentName2Idx; + this.signals = circuitDef.signals; + this.constraints = circuitDef.constraints; + + this.templates = {}; + for (let t in circuitDef.templates) { + this.templates[t] = eval(" const __f= " +circuitDef.templates[t] + "\n__f"); + } + + this.functions = {}; + for (let f in circuitDef.functions) { + this.functions[f] = { + params: circuitDef.functions[f].params, + func: eval(" const __f= " +circuitDef.functions[f].func + "\n__f;") + }; + } + } + + calculateWitness(input, log) { + return calculateWitness(this, input, log); + } + + checkWitness(w) { + const evalLC = (lc, w) => { + let acc = bigInt(0); + for (let k in lc) { + acc= acc.add(bigInt(w[k]).mul(bigInt(lc[k]))).mod(__P__); + } + return acc; + } + + const checkConstraint = (ct, w) => { + const a=evalLC(ct[0],w); + const b=evalLC(ct[1],w); + const c=evalLC(ct[2],w); + const res = (a.mul(b).sub(c)).affine(__P__); + if (!res.isZero()) return false; + return true; + } + + + for (let i=0; i { + let S = ""; + for (let k in lc) { + let name = this.signals[k].names[0]; + if (name == "one") name = ""; + let v = bigInt(lc[k]); + let vs; + if (!v.lesserOrEquals(__P__.shr(bigInt(1)))) { + v = __P__.sub(v); + vs = "-"+v.toString(); + } else { + if (S!="") { + vs = "+"+v.toString(); + } else { + vs = ""; + } + if (vs!="1") { + vs = vs + v.toString();; + } + } + + S= S + " " + vs + name; + } + return S; + }; + const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ] = 0`; + console.log(S); + } + + printConstraints() { + for (let i=0; i=this.nOutputs) throw new Error("Accessing an invalid output: "+i); + return i+1; + } + + // returns the index of the i'th input + inputIdx(i) { + if (i>=this.nInputs) throw new Error("Accessing an invalid input: "+i); + return this.nOutputs + 1 + i; + } + + // returns the index of the i'th public input + pubInputIdx(i) { + if (i>=this.nPubInputs) throw new Error("Accessing an invalid pubInput: "+i); + return this.inputIdx(i); + } + + // returns the index of the i'th private input + prvInputIdx(i) { + if (i>=this.nPrvInputs) throw new Error("Accessing an invalid prvInput: "+i); + return this.inputIdx(this.nPubInputs + i); + } + + // returns the index of the i'th variable + varIdx(i) { + if (i>=this.nVars) throw new Error("Accessing an invalid variable: "+i); + return i; + } + + // returns the index of the i'th constant + constantIdx(i) { + if (i>=this.nConstants) throw new Error("Accessing an invalid constant: "+i); + return this.nVars + i; + } + + // returns the index of the i'th signal + signalIdx(i) { + if (i>=this.nSignls) throw new Error("Accessing an invalid signal: "+i); + return i; + } + + signalNames(i) { + return this.signals[ this.getSignalIdx(i) ].names.join(", "); + } + + a(constraint, signalIdx) { + return bigInt(this.constraints[constraint][0][signalIdx] || 0 ); + } + + b(constraint, signalIdx) { + return bigInt(this.constraints[constraint][1][signalIdx] || 0); + } + + c(constraint, signalIdx) { + return bigInt(this.constraints[constraint][2][signalIdx] || 0); + } +}; + +},{"./bigint.js":4,"./calculateWitness.js":5}],7:[function(require,module,exports){ +/* + Copyright 2018 0kims association. + + This file is part of snarkjs. + + snarkjs is a free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your option) + any later version. + + snarkjs is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + snarkjs. If not, see . +*/ + +const bigInt = require("./bigint.js"); + +module.exports.stringifyBigInts = stringifyBigInts; +module.exports.unstringifyBigInts = unstringifyBigInts; + +function stringifyBigInts(o) { + if ((typeof(o) == "bigint") || o.isZero !== undefined) { + return o.toString(10); + } else if (Array.isArray(o)) { + return o.map(stringifyBigInts); + } else if (typeof o == "object") { + const res = {}; + for (let k in o) { + res[k] = stringifyBigInts(o[k]); + } + return res; + } else { + return o; + } +} + +function unstringifyBigInts(o) { + if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) { + return bigInt(o); + } else if (Array.isArray(o)) { + return o.map(unstringifyBigInts); + } else if (typeof o == "object") { + const res = {}; + for (let k in o) { + res[k] = unstringifyBigInts(o[k]); + } + return res; + } else { + return o; + } +} + +},{"./bigint.js":4}],8:[function(require,module,exports){ (function (global){ 'use strict'; @@ -571,7 +3037,7 @@ var objectKeys = Object.keys || function (obj) { }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"object-assign":11,"util/":6}],4:[function(require,module,exports){ +},{"object-assign":16,"util/":11}],9:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -596,14 +3062,14 @@ if (typeof Object.create === 'function') { } } -},{}],5:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],6:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -1193,7 +3659,7 @@ function hasOwnProperty(obj, prop) { } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":5,"_process":12,"inherits":4}],7:[function(require,module,exports){ +},{"./support/isBuffer":10,"_process":17,"inherits":9}],12:[function(require,module,exports){ 'use strict' exports.byteLength = byteLength @@ -1346,7 +3812,7 @@ function fromByteArray (uint8) { return parts.join('') } -},{}],8:[function(require,module,exports){ +},{}],13:[function(require,module,exports){ var bigInt = (function (undefined) { "use strict"; @@ -2796,7 +5262,7 @@ if (typeof define === "function" && define.amd) { }); } -},{}],9:[function(require,module,exports){ +},{}],14:[function(require,module,exports){ (function (Buffer){ /*! * The buffer module from node.js, for the browser. @@ -4577,7 +7043,7 @@ function numberIsNaN (obj) { } }).call(this,require("buffer").Buffer) -},{"base64-js":7,"buffer":9,"ieee754":10}],10:[function(require,module,exports){ +},{"base64-js":12,"buffer":14,"ieee754":15}],15:[function(require,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = (nBytes * 8) - mLen - 1 @@ -4663,7 +7129,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],11:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ /* object-assign (c) Sindre Sorhus @@ -4755,7 +7221,7 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) { return to; }; -},{}],12:[function(require,module,exports){ +},{}],17:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -4941,977 +7407,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],13:[function(require,module,exports){ -(function (Buffer){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -/* global BigInt */ -const bigInt = require("big-integer"); - -let wBigInt; - -if (typeof(BigInt) != "undefined") { - wBigInt = BigInt; - wBigInt.one = wBigInt(1); - wBigInt.zero = wBigInt(0); - - // Affine - wBigInt.genAffine = (q) => { - const nq = -q; - return (a) => { - let aux = a; - if (aux < 0) { - if (aux <= nq) { - aux = aux % q; - } - if (aux < wBigInt.zero) { - aux = aux + q; - } - } else { - if (aux >= q) { - aux = aux % q; - } - } - return aux.valueOf(); - }; - }; - - - // Inverse - wBigInt.genInverse = (q) => { - return (a) => { - let t = wBigInt.zero; - let r = q; - let newt = wBigInt.one; - let newr = wBigInt.affine(a, q); - while (newr!=wBigInt.zero) { - let q = r/newr; - [t, newt] = [newt, t-q*newt]; - [r, newr] = [newr, r-q*newr]; - } - if (t { - if (q) { - return (a,b) => (a+b) % q; - } else { - return (a,b) => a+b; - } - }; - - // Sub - wBigInt.genSub = (q) => { - if (q) { - return (a,b) => (a-b) % q; - } else { - return (a,b) => a-b; - } - }; - - - // Neg - wBigInt.genNeg = (q) => { - if (q) { - return (a) => (-a) % q; - } else { - return (a) => -a; - } - }; - - // Mul - wBigInt.genMul = (q) => { - if (q) { - return (a,b) => (a*b) % q; - } else { - return (a,b) => a*b; - } - }; - - // Shr - wBigInt.genShr = () => { - return (a,b) => a >> wBigInt(b); - }; - - // Shl - wBigInt.genShl = (q) => { - if (q) { - return (a,b) => (a << wBigInt(b)) % q; - } else { - return (a,b) => a << wBigInt(b); - } - }; - - // Equals - wBigInt.genEquals = (q) => { - if (q) { - return (a,b) => (a.affine(q) == b.affine(q)); - } else { - return (a,b) => a == b; - } - }; - - // Square - wBigInt.genSquare = (q) => { - if (q) { - return (a) => (a*a) %q; - } else { - return (a) => a*a; - } - }; - - - // Double - wBigInt.genDouble = (q) => { - if (q) { - return (a) => (a+a) %q; - } else { - return (a) => a+a; - } - }; - - // IsZero - wBigInt.genIsZero = (q) => { - if (q) { - return (a) => (a.affine(q) == wBigInt.zero); - } else { - return (a) => a == wBigInt.zero; - } - }; - - - // Other minor functions - wBigInt.prototype.isOdd = function() { - return (this & wBigInt.one) == wBigInt(1); - }; - - wBigInt.prototype.isNegative = function() { - return this < wBigInt.zero; - }; - - wBigInt.prototype.and = function(m) { - return this & m; - }; - - wBigInt.prototype.div = function(c) { - return this / c; - }; - - wBigInt.prototype.mod = function(c) { - return this % c; - }; - - wBigInt.prototype.modPow = function(e, m) { - let acc = wBigInt.one; - let exp = this; - let rem = e; - while (rem) { - if (rem & wBigInt.one) { - acc = (acc * exp) %m; - } - exp = (exp * exp) % m; - rem = rem >> wBigInt.one; - } - return acc; - }; - - wBigInt.prototype.greaterOrEquals = function(b) { - return this >= b; - }; - - wBigInt.prototype.greater = function(b) { - return this > b; - }; - wBigInt.prototype.gt = wBigInt.prototype.greater; - - wBigInt.prototype.lesserOrEquals = function(b) { - return this <= b; - }; - - wBigInt.prototype.lesser = function(b) { - return this < b; - }; - wBigInt.prototype.lt = wBigInt.prototype.lesser; - - wBigInt.prototype.equals = function(b) { - return this == b; - }; - wBigInt.prototype.eq = wBigInt.prototype.equals; - - wBigInt.prototype.neq = function(b) { - return this != b; - }; - -} else { - - var oldProto = bigInt.prototype; - wBigInt = function(a) { - if ((typeof a == "string") && (a.slice(0,2) == "0x")) { - return bigInt(a.slice(2), 16); - } else { - return bigInt(a); - } - }; - wBigInt.one = bigInt.one; - wBigInt.zero = bigInt.zero; - wBigInt.prototype = oldProto; - - wBigInt.prototype.div = function(c) { - return this.divide(c); - }; - - // Affine - wBigInt.genAffine = (q) => { - const nq = wBigInt.zero.minus(q); - return (a) => { - let aux = a; - if (aux.isNegative()) { - if (aux.lesserOrEquals(nq)) { - aux = aux.mod(q); - } - if (aux.isNegative()) { - aux = aux.add(q); - } - } else { - if (aux.greaterOrEquals(q)) { - aux = aux.mod(q); - } - } - return aux; - }; - }; - - - // Inverse - wBigInt.genInverse = (q) => { - return (a) => a.affine(q).modInv(q); - }; - - // Add - wBigInt.genAdd = (q) => { - if (q) { - return (a,b) => { - const r = a.add(b); - return r.greaterOrEquals(q) ? r.minus(q) : r; - }; - } else { - return (a,b) => a.add(b); - } - }; - - // Sub - wBigInt.genSub = (q) => { - if (q) { - return (a,b) => a.greaterOrEquals(b) ? a.minus(b) : a.minus(b).add(q); - } else { - return (a,b) => a.minus(b); - } - }; - - wBigInt.genNeg = (q) => { - if (q) { - return (a) => a.isZero() ? a : q.minus(a); - } else { - return (a) => wBigInt.zero.minus(a); - } - }; - - // Mul - wBigInt.genMul = (q) => { - if (q) { - return (a,b) => a.times(b).mod(q); - } else { - return (a,b) => a.times(b); - } - }; - - // Shr - wBigInt.genShr = () => { - return (a,b) => a.shiftRight(wBigInt(b).value); - }; - - // Shr - wBigInt.genShl = (q) => { - if (q) { - return (a,b) => a.shiftLeft(wBigInt(b).value).mod(q); - } else { - return (a,b) => a.shiftLeft(wBigInt(b).value); - } - }; - - // Square - wBigInt.genSquare = (q) => { - if (q) { - return (a) => a.square().mod(q); - } else { - return (a) => a.square(); - } - }; - - // Double - wBigInt.genDouble = (q) => { - if (q) { - return (a) => a.add(a).mod(q); - } else { - return (a) => a.add(a); - } - }; - - // Equals - wBigInt.genEquals = (q) => { - if (q) { - return (a,b) => a.affine(q).equals(b.affine(q)); - } else { - return (a,b) => a.equals(b); - } - }; - - // IsZero - wBigInt.genIsZero = (q) => { - if (q) { - return (a) => (a.affine(q).isZero()); - } else { - return (a) => a.isZero(); - } - }; -} - - - -wBigInt.affine = function(a, q) { - return wBigInt.genAffine(q)(a); -}; - -wBigInt.prototype.affine = function (q) { - return wBigInt.affine(this, q); -}; - -wBigInt.inverse = function(a, q) { - return wBigInt.genInverse(q)(a); -}; - -wBigInt.prototype.inverse = function (q) { - return wBigInt.genInverse(q)(this); -}; - -wBigInt.add = function(a, b, q) { - return wBigInt.genAdd(q)(a,b); -}; - -wBigInt.prototype.add = function (a, q) { - return wBigInt.genAdd(q)(this, a); -}; - -wBigInt.sub = function(a, b, q) { - return wBigInt.genSub(q)(a,b); -}; - -wBigInt.prototype.sub = function (a, q) { - return wBigInt.genSub(q)(this, a); -}; - -wBigInt.neg = function(a, q) { - return wBigInt.genNeg(q)(a); -}; - -wBigInt.prototype.neg = function (q) { - return wBigInt.genNeg(q)(this); -}; - -wBigInt.mul = function(a, b, q) { - return wBigInt.genMul(q)(a,b); -}; - -wBigInt.prototype.mul = function (a, q) { - return wBigInt.genMul(q)(this, a); -}; - -wBigInt.shr = function(a, b, q) { - return wBigInt.genShr(q)(a,b); -}; - -wBigInt.prototype.shr = function (a, q) { - return wBigInt.genShr(q)(this, a); -}; - -wBigInt.shl = function(a, b, q) { - return wBigInt.genShl(q)(a,b); -}; - -wBigInt.prototype.shl = function (a, q) { - return wBigInt.genShl(q)(this, a); -}; - -wBigInt.equals = function(a, b, q) { - return wBigInt.genEquals(q)(a,b); -}; - -wBigInt.prototype.equals = function (a, q) { - return wBigInt.genEquals(q)(this, a); -}; - -wBigInt.square = function(a, q) { - return wBigInt.genSquare(q)(a); -}; - -wBigInt.prototype.square = function (q) { - return wBigInt.genSquare(q)(this); -}; - -wBigInt.double = function(a, q) { - return wBigInt.genDouble(q)(a); -}; - -wBigInt.prototype.double = function (q) { - return wBigInt.genDouble(q)(this); -}; - -wBigInt.isZero = function(a, q) { - return wBigInt.genIsZero(q)(a); -}; - -wBigInt.prototype.isZero = function (q) { - return wBigInt.genIsZero(q)(this); -}; - -wBigInt.leBuff2int = function(buff) { - let res = wBigInt.zero; - for (let i=0; i. -*/ - -const bigInt = require("./bigint"); - -module.exports = calculateWitness; - -function calculateWitness(circuit, inputSignals, log) { - log = log || (() => {}); - const ctx = new RTCtx(circuit, log); - - function iterateSelector(values, sels, cb) { - if (!Array.isArray(values)) { - return cb(sels, values); - } - for (let i=0; i " + ctx.witness[i].toString()); - } - return ctx.witness.slice(0, circuit.nVars); -// return ctx.witness; -} - -class RTCtx { - constructor(circuit, log) { - this.log = log || function() {}; - this.scopes = []; - this.circuit = circuit; - this.witness = new Array(circuit.nSignals); - this.notInitSignals = {}; - for (let c in this.circuit.components) { - this.notInitSignals[c] = this.circuit.components[c].inputSignals; - } - } - - _sels2str(sels) { - let res = ""; - for (let i=0; i { - if (this.notInitSignals[c] == 0) this.triggerComponent(c); - }); - return this.witness[sId]; - } - - setVar(name, sels, value) { - function setVarArray(a, sels2, value) { - if (sels2.length == 1) { - a[sels2[0]] = value; - } else { - if (typeof(a[sels2[0]]) == "undefined") a[sels2[0]] = []; - setVarArray(a[sels2[0]], sels2.slice(1), value); - } - } - const scope = this.scopes[this.scopes.length-1]; - if (sels.length == 0) { - scope[name] = value; - } else { - if (typeof(scope[name]) == "undefined") scope[name] = []; - setVarArray(scope[name], sels, value); - } - return value; - } - - getVar(name, sels) { - function select(a, sels2) { - return (sels2.length == 0) ? a : select(a[sels2[0]], sels2.slice(1)); - } - for (let i=this.scopes.length-1; i>=0; i--) { - if (typeof(this.scopes[i][name]) != "undefined") return select(this.scopes[i][name], sels); - } - throw new Error("Variable not defined: " + name); - } - - getSignal(name, sels) { - let fullName = name=="one" ? "one" : this.currentComponent + "." + name; - fullName += this._sels2str(sels); - return this.getSignalFullName(fullName); - } - - - getPin(componentName, componentSels, signalName, signalSels) { - let fullName = componentName=="one" ? "one" : this.currentComponent + "." + componentName; - fullName += this._sels2str(componentSels) + - "."+ - signalName+ - this._sels2str(signalSels); - return this.getSignalFullName(fullName); - } - - getSignalFullName(fullName) { - const sId = this.circuit.getSignalIdx(fullName); - if (typeof(this.witness[sId]) == "undefined") { - throw new Error("Signal not initialized: "+fullName); - } - this.log("get --->" + fullName + " = " + this.witness[sId].toString() ); - return this.witness[sId]; - } - - assert(a,b) { - const ba = bigInt(a); - const bb = bigInt(b); - if (!ba.equals(bb)) { - throw new Error("Constraint doesn't match: " + ba.toString() + " != " + bb.toString()); - } - } -} - -},{"./bigint":13}],15:[function(require,module,exports){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -const bigInt = require("./bigint.js"); - -const __P__ = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); -const __MASK__ = bigInt("28948022309329048855892746252171976963317496166410141009864396001978282409983"); // 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -const calculateWitness = require("./calculateWitness.js"); - -module.exports = class Circuit { - constructor(circuitDef) { - this.nPubInputs = circuitDef.nPubInputs; - this.nPrvInputs = circuitDef.nPrvInputs; - this.nInputs = circuitDef.nInputs; - this.nOutputs = circuitDef.nOutputs; - this.nVars = circuitDef.nVars; - this.nSignals = circuitDef.nSignals; - this.nConstants = circuitDef.nConstants; - - this.nConstraints = circuitDef.constraints.length; - - this.signalName2Idx = circuitDef.signalName2Idx; - this.components = circuitDef.components; - this.componentName2Idx = circuitDef.componentName2Idx; - this.signals = circuitDef.signals; - this.constraints = circuitDef.constraints; - - this.templates = {}; - for (let t in circuitDef.templates) { - this.templates[t] = eval(" const __f= " +circuitDef.templates[t] + "\n__f"); - } - - this.functions = {}; - for (let f in circuitDef.functions) { - this.functions[f] = { - params: circuitDef.functions[f].params, - func: eval(" const __f= " +circuitDef.functions[f].func + "\n__f;") - }; - } - } - - calculateWitness(input, log) { - return calculateWitness(this, input, log); - } - - checkWitness(w) { - const evalLC = (lc, w) => { - let acc = bigInt(0); - for (let k in lc) { - acc= acc.add(bigInt(w[k]).mul(bigInt(lc[k]))).mod(__P__); - } - return acc; - } - - const checkConstraint = (ct, w) => { - const a=evalLC(ct[0],w); - const b=evalLC(ct[1],w); - const c=evalLC(ct[2],w); - const res = (a.mul(b).sub(c)).affine(__P__); - if (!res.isZero()) return false; - return true; - } - - - for (let i=0; i { - let S = ""; - for (let k in lc) { - let name = this.signals[k].names[0]; - if (name == "one") name = ""; - let v = bigInt(lc[k]); - let vs; - if (!v.lesserOrEquals(__P__.shr(bigInt(1)))) { - v = __P__.sub(v); - vs = "-"+v.toString(); - } else { - if (S!="") { - vs = "+"+v.toString(); - } else { - vs = ""; - } - if (vs!="1") { - vs = vs + v.toString();; - } - } - - S= S + " " + vs + name; - } - return S; - }; - const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ] = 0`; - console.log(S); - } - - printConstraints() { - for (let i=0; i=this.nOutputs) throw new Error("Accessing an invalid output: "+i); - return i+1; - } - - // returns the index of the i'th input - inputIdx(i) { - if (i>=this.nInputs) throw new Error("Accessing an invalid input: "+i); - return this.nOutputs + 1 + i; - } - - // returns the index of the i'th public input - pubInputIdx(i) { - if (i>=this.nPubInputs) throw new Error("Accessing an invalid pubInput: "+i); - return this.inputIdx(i); - } - - // returns the index of the i'th private input - prvInputIdx(i) { - if (i>=this.nPrvInputs) throw new Error("Accessing an invalid prvInput: "+i); - return this.inputIdx(this.nPubInputs + i); - } - - // returns the index of the i'th variable - varIdx(i) { - if (i>=this.nVars) throw new Error("Accessing an invalid variable: "+i); - return i; - } - - // returns the index of the i'th constant - constantIdx(i) { - if (i>=this.nConstants) throw new Error("Accessing an invalid constant: "+i); - return this.nVars + i; - } - - // returns the index of the i'th signal - signalIdx(i) { - if (i>=this.nSignls) throw new Error("Accessing an invalid signal: "+i); - return i; - } - - signalNames(i) { - return this.signals[ this.getSignalIdx(i) ].names.join(", "); - } - - a(constraint, signalIdx) { - return bigInt(this.constraints[constraint][0][signalIdx] || 0 ); - } - - b(constraint, signalIdx) { - return bigInt(this.constraints[constraint][1][signalIdx] || 0); - } - - c(constraint, signalIdx) { - return bigInt(this.constraints[constraint][2][signalIdx] || 0); - } -}; - -},{"./bigint.js":13,"./calculateWitness.js":14}],16:[function(require,module,exports){ -/* - Copyright 2018 0kims association. - - This file is part of snarkjs. - - snarkjs is a free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your option) - any later version. - - snarkjs is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - snarkjs. If not, see . -*/ - -const bigInt = require("./bigint.js"); - -module.exports.stringifyBigInts = stringifyBigInts; -module.exports.unstringifyBigInts = unstringifyBigInts; - -function stringifyBigInts(o) { - if ((typeof(o) == "bigint") || (o instanceof bigInt)) { - return o.toString(10); - } else if (Array.isArray(o)) { - return o.map(stringifyBigInts); - } else if (typeof o == "object") { - const res = {}; - for (let k in o) { - res[k] = stringifyBigInts(o[k]); - } - return res; - } else { - return o; - } -} - -function unstringifyBigInts(o) { - if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) { - return bigInt(o); - } else if (Array.isArray(o)) { - return o.map(unstringifyBigInts); - } else if (typeof o == "object") { - const res = {}; - for (let k in o) { - res[k] = unstringifyBigInts(o[k]); - } - return res; - } else { - return o; - } -} - -},{"./bigint.js":13}],17:[function(require,module,exports){ +},{}],18:[function(require,module,exports){ (function (process){ /* Copyright 2019 0KIMS association. @@ -6526,7 +8022,7 @@ class Groth16 { module.exports = build; }).call(this,require('_process')) -},{"../build/groth16_wasm.js":1,"_process":12,"assert":3,"big-integer":8,"crypto":undefined,"worker_threads":undefined}],18:[function(require,module,exports){ +},{"../build/groth16_wasm.js":1,"_process":17,"assert":8,"big-integer":13,"crypto":undefined,"worker_threads":undefined}],19:[function(require,module,exports){ /* Copyright 2019 0KIMS association. @@ -6547,20 +8043,20 @@ module.exports = build; */ const bigInt = require("big-integer"); -const Circuit = require("snarkjs/src/circuit"); -const bigInt2 = require("snarkjs/src/bigint"); +const Circuit = require("@tornado/snarkjs/src/circuit"); +const bigInt2 = require("@tornado/snarkjs/src/bigint"); const hexifyBigInts = require("../tools/stringifybigint").hexifyBigInts; const unhexifyBigInts = require("../tools/stringifybigint").unhexifyBigInts; const stringifyBigInts = require("../tools/stringifybigint").stringifyBigInts; const unstringifyBigInts = require("../tools/stringifybigint").unstringifyBigInts; -const stringifyBigInts2 = require("snarkjs/src/stringifybigint").stringifyBigInts; -const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts; +const stringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").stringifyBigInts; +const unstringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").unstringifyBigInts; function bigInt2BytesLE(_a, len) { const b = Array(len); let v = bigInt(_a); - for (let i=0; i toHex32(x)).join("") + proof: "0x" + flatProof.map((x) => toHex32(x)).join(""), }; if (proof.publicSignals) { result.publicSignals = hexifyBigInts(unstringifyBigInts(proof.publicSignals)); @@ -6616,11 +8116,11 @@ function toSolidityInput(proof) { return result; } -function genWitness(input, circuitJson) { +function genWitness(input, circuitJson) { const circuit = new Circuit(unstringifyBigInts2(circuitJson)); const witness = circuit.calculateWitness(unstringifyBigInts2(input)); const publicSignals = witness.slice(1, circuit.nPubInputs + circuit.nOutputs + 1); - return {witness, publicSignals}; + return { witness, publicSignals }; } async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { @@ -6631,8 +8131,9 @@ async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { return result; } -module.exports = {bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve}; -},{"../tools/stringifybigint":19,"big-integer":8,"snarkjs/src/bigint":13,"snarkjs/src/circuit":15,"snarkjs/src/stringifybigint":16}],19:[function(require,module,exports){ +module.exports = { bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve }; + +},{"../tools/stringifybigint":20,"@tornado/snarkjs/src/bigint":4,"@tornado/snarkjs/src/circuit":6,"@tornado/snarkjs/src/stringifybigint":7,"big-integer":13}],20:[function(require,module,exports){ /* Copyright 2018 0kims association. @@ -6726,4 +8227,4 @@ function unhexifyBigInts(o) { } } -},{"big-integer":8}]},{},[2]); +},{"big-integer":13}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 8849a13..ddab825 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "websnark", + "name": "@tornado/websnark", "version": "0.0.4", "lockfileVersion": 1, "requires": true, @@ -8,7 +8,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", - "dev": true, "requires": { "@babel/highlight": "^7.0.0" } @@ -17,13 +16,84 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", - "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", "js-tokens": "^4.0.0" } }, + "@tornado/snarkjs": { + "version": "0.1.20", + "resolved": "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Fsnarkjs/-/0.1.20/snarkjs-0.1.20.tgz", + "integrity": "sha512-mn+ePoQjqOHyDyK8AMy8SXYqNSxJWVswWVmMYvuc75/9bBtJ7SNtwrTByxmfWjrf4S3BM3IrGfHqBHEXY6gR4Q==", + "requires": { + "big-integer": "^1.6.43", + "chai": "^4.2.0", + "escape-string-regexp": "^1.0.5", + "eslint": "^5.16.0", + "keccak": "^2.0.0", + "yargs": "^12.0.5" + }, + "dependencies": { + "big-integer": { + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==" + }, + "eslint": { + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.16.0.tgz", + "integrity": "sha512-S3Rz11i7c8AA5JPv7xAH+dOyq/Cu/VXHiHXBPOU1k/JAM5dXqQPt3qcrhpHSorXmrpu2g0gkIBVXAqCpzfoZIg==", + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.9.1", + "chalk": "^2.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^4.0.3", + "eslint-utils": "^1.3.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^5.0.1", + "esquery": "^1.0.1", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.7.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^6.2.2", + "js-yaml": "^3.13.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.11", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "progress": "^2.0.0", + "regexpp": "^2.0.1", + "semver": "^5.5.1", + "strip-ansi": "^4.0.0", + "strip-json-comments": "^2.0.1", + "table": "^5.2.3", + "text-table": "^0.2.0" + } + }, + "eslint-scope": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", + "integrity": "sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==", + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + } + } + }, "@webassemblyjs/ast": { "version": "1.8.4", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.4.tgz", @@ -166,8 +236,7 @@ "acorn": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.0.tgz", - "integrity": "sha512-MW/FjM+IvU9CgBzjO3UIPCE2pyEwUsoFl+VGdczOPEdxfGFjuKny/gN54mOuX7Qxmb9Rg9MCn2oKiSUeW+pjrw==", - "dev": true + "integrity": "sha512-MW/FjM+IvU9CgBzjO3UIPCE2pyEwUsoFl+VGdczOPEdxfGFjuKny/gN54mOuX7Qxmb9Rg9MCn2oKiSUeW+pjrw==" }, "acorn-dynamic-import": { "version": "4.0.0", @@ -178,8 +247,7 @@ "acorn-jsx": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", - "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", - "dev": true + "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==" }, "acorn-node": { "version": "1.7.0", @@ -211,7 +279,6 @@ "version": "6.9.1", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.9.1.tgz", "integrity": "sha512-XDN92U311aINL77ieWHmqCcNlwjoP5cHXDxIxbf2MaPYuCXOHS7gHH8jktxeK5omgd52XbSTX6a4Piwd1pQmzA==", - "dev": true, "requires": { "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", @@ -228,20 +295,17 @@ "ansi-escapes": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", - "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", - "dev": true + "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==" }, "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, "requires": { "color-convert": "^1.9.0" } @@ -250,7 +314,6 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -314,20 +377,17 @@ "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", - "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", - "dev": true + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==" }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base64-js": { "version": "1.3.0", @@ -340,6 +400,14 @@ "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.42.tgz", "integrity": "sha512-3UQFKcRMx+5Z+IK5vYTMYK2jzLRJkt+XqyDdacgWgtMjjuifKpKTFneJLEgeBElOE2/lXZ1LcMcb5s8pwG2U8Q==" }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", @@ -350,7 +418,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -571,20 +638,17 @@ "callsites": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.0.0.tgz", - "integrity": "sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw==", - "dev": true + "integrity": "sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw==" }, "camelcase": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.2.0.tgz", - "integrity": "sha512-IXFsBS2pC+X0j0N/GE7Dm7j3bsEBp+oTpb7F50dwEVX7rf3IgwO9XatnegTsDtniKCUtEJH4fSU6Asw7uoVLfQ==", - "dev": true + "integrity": "sha512-IXFsBS2pC+X0j0N/GE7Dm7j3bsEBp+oTpb7F50dwEVX7rf3IgwO9XatnegTsDtniKCUtEJH4fSU6Asw7uoVLfQ==" }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", - "dev": true, "requires": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", @@ -598,7 +662,6 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -608,14 +671,12 @@ "chardet": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", - "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", - "dev": true + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", - "dev": true + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" }, "cipher-base": { "version": "1.0.4", @@ -631,7 +692,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", - "dev": true, "requires": { "restore-cursor": "^2.0.0" } @@ -639,14 +699,12 @@ "cli-width": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", - "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", - "dev": true + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=" }, "cliui": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", - "dev": true, "requires": { "string-width": "^2.1.1", "strip-ansi": "^4.0.0", @@ -656,14 +714,12 @@ "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, "requires": { "color-name": "1.1.3" } @@ -671,8 +727,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "combine-source-map": { "version": "0.8.0", @@ -689,8 +744,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { "version": "1.6.2", @@ -772,7 +826,6 @@ "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, "requires": { "nice-try": "^1.0.4", "path-key": "^2.0.1", @@ -816,7 +869,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, "requires": { "ms": "^2.1.1" } @@ -824,14 +876,12 @@ "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", - "dev": true + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, "deep-eql": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", - "dev": true, "requires": { "type-detect": "^4.0.0" } @@ -839,8 +889,7 @@ "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", - "dev": true + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" }, "define-properties": { "version": "1.1.3", @@ -919,7 +968,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, "requires": { "esutils": "^2.0.2" } @@ -957,14 +1005,12 @@ "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", - "dev": true + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" }, "end-of-stream": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -997,8 +1043,7 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { "version": "5.14.0", @@ -1085,20 +1130,17 @@ "eslint-utils": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", - "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", - "dev": true + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==" }, "eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", - "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", - "dev": true + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==" }, "espree": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", - "dev": true, "requires": { "acorn": "^6.0.7", "acorn-jsx": "^5.0.0", @@ -1108,14 +1150,12 @@ "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, "esquery": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", - "dev": true, "requires": { "estraverse": "^4.0.0" } @@ -1124,7 +1164,6 @@ "version": "4.2.1", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", - "dev": true, "requires": { "estraverse": "^4.1.0" } @@ -1132,14 +1171,12 @@ "estraverse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", - "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", - "dev": true + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=" }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" }, "events": { "version": "2.1.0", @@ -1161,7 +1198,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "dev": true, "requires": { "cross-spawn": "^6.0.0", "get-stream": "^4.0.0", @@ -1176,7 +1212,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", - "dev": true, "requires": { "chardet": "^0.7.0", "iconv-lite": "^0.4.24", @@ -1186,26 +1221,22 @@ "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", - "dev": true + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", - "dev": true + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", - "dev": true, "requires": { "escape-string-regexp": "^1.0.5" } @@ -1214,16 +1245,19 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", - "dev": true, "requires": { "flat-cache": "^2.0.1" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "dev": true, "requires": { "locate-path": "^3.0.0" } @@ -1241,7 +1275,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", - "dev": true, "requires": { "flatted": "^2.0.0", "rimraf": "2.6.3", @@ -1251,14 +1284,12 @@ "flatted": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz", - "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==", - "dev": true + "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==" }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "function-bind": { "version": "1.1.1", @@ -1269,8 +1300,7 @@ "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", - "dev": true + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=" }, "get-assigned-identifiers": { "version": "1.2.0", @@ -1281,20 +1311,17 @@ "get-caller-file": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", - "dev": true + "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" }, "get-func-name": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", - "dev": true + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=" }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, "requires": { "pump": "^3.0.0" } @@ -1303,7 +1330,6 @@ "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -1316,8 +1342,7 @@ "globals": { "version": "11.11.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.11.0.tgz", - "integrity": "sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw==", - "dev": true + "integrity": "sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw==" }, "growl": { "version": "1.10.5", @@ -1337,8 +1362,7 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, "has-symbols": { "version": "1.0.0", @@ -1399,7 +1423,6 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -1413,14 +1436,12 @@ "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", - "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", - "dev": true + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==" }, "import-fresh": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", - "dev": true, "requires": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -1429,14 +1450,12 @@ "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", - "dev": true + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=" }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -1445,8 +1464,7 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "inline-source-map": { "version": "0.6.2", @@ -1461,7 +1479,6 @@ "version": "6.2.2", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.2.tgz", "integrity": "sha512-Z2rREiXA6cHRR9KBOarR3WuLlFzlIfAEIiB45ll5SSadMg7WqOh1MKEjjndfuH5ewXdixWCxqnVfGOQzPeiztA==", - "dev": true, "requires": { "ansi-escapes": "^3.2.0", "chalk": "^2.4.2", @@ -1481,14 +1498,12 @@ "ansi-regex": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.0.0.tgz", - "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==", - "dev": true + "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==" }, "strip-ansi": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.0.0.tgz", "integrity": "sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==", - "dev": true, "requires": { "ansi-regex": "^4.0.0" } @@ -1524,8 +1539,7 @@ "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", - "dev": true + "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" }, "is-buffer": { "version": "2.0.3", @@ -1548,14 +1562,12 @@ "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" }, "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", - "dev": true + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" }, "is-regex": { "version": "1.0.4", @@ -1569,8 +1581,7 @@ "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" }, "is-symbol": { "version": "1.0.2", @@ -1590,20 +1601,17 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", - "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -1612,8 +1620,7 @@ "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, "json-stable-stringify": { "version": "0.0.1", @@ -1627,8 +1634,7 @@ "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", - "dev": true + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=" }, "jsonify": { "version": "0.0.0", @@ -1642,6 +1648,29 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, + "keccak": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-2.1.0.tgz", + "integrity": "sha512-m1wbJRTo+gWbctZWay9i26v5fFnYkOn7D5PCxJ3fZUGUEb49dE1Pm4BREUYCt/aoO6di7jeoGmhvqN9Nzylm3Q==", + "requires": { + "bindings": "^1.5.0", + "inherits": "^2.0.4", + "nan": "^2.14.0", + "safe-buffer": "^5.2.0" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + } + } + }, "labeled-stream-splicer": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/labeled-stream-splicer/-/labeled-stream-splicer-2.0.2.tgz", @@ -1656,7 +1685,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", - "dev": true, "requires": { "invert-kv": "^2.0.0" } @@ -1665,7 +1693,6 @@ "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", - "dev": true, "requires": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -1675,7 +1702,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", - "dev": true, "requires": { "p-locate": "^3.0.0", "path-exists": "^3.0.0" @@ -1684,8 +1710,7 @@ "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, "lodash.memoize": { "version": "3.0.4", @@ -1712,7 +1737,6 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", - "dev": true, "requires": { "p-defer": "^1.0.0" } @@ -1732,7 +1756,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz", "integrity": "sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg==", - "dev": true, "requires": { "map-age-cleaner": "^0.1.1", "mimic-fn": "^1.0.0", @@ -1752,8 +1775,7 @@ "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", - "dev": true + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" }, "minimalistic-assert": { "version": "1.0.1", @@ -1771,7 +1793,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1779,14 +1800,12 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, "requires": { "minimist": "0.0.8" } @@ -1935,26 +1954,27 @@ "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", - "dev": true + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", - "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", - "dev": true + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" + }, + "nan": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", + "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==" }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", - "dev": true + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=" }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", - "dev": true + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, "node-environment-flags": { "version": "1.0.5", @@ -1978,7 +1998,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "dev": true, "requires": { "path-key": "^2.0.0" } @@ -1986,8 +2005,7 @@ "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, "object-assign": { "version": "4.1.1", @@ -2027,7 +2045,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -2036,7 +2053,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", - "dev": true, "requires": { "mimic-fn": "^1.0.0" } @@ -2045,7 +2061,6 @@ "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", - "dev": true, "requires": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.4", @@ -2065,7 +2080,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", - "dev": true, "requires": { "execa": "^1.0.0", "lcid": "^2.0.0", @@ -2075,32 +2089,27 @@ "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", - "dev": true + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, "p-defer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", - "dev": true + "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", - "dev": true + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" }, "p-is-promise": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz", - "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==", - "dev": true + "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==" }, "p-limit": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", - "dev": true, "requires": { "p-try": "^2.0.0" } @@ -2109,7 +2118,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", - "dev": true, "requires": { "p-limit": "^2.0.0" } @@ -2117,8 +2125,7 @@ "p-try": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", - "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", - "dev": true + "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==" }, "package": { "version": "1.0.1", @@ -2136,7 +2143,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.0.tgz", "integrity": "sha512-8Mf5juOMmiE4FcmzYc4IaiS9L3+9paz2KOiXzkRviCP6aDmN49Hz6EMWz0lGNp9pX80GvvAuLADtyGfW/Em3TA==", - "dev": true, "requires": { "callsites": "^3.0.0" } @@ -2173,26 +2179,22 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", - "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", - "dev": true + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=" }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", - "dev": true + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" }, "path-parse": { "version": "1.0.6", @@ -2209,8 +2211,7 @@ "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", - "dev": true + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" }, "pbkdf2": { "version": "3.0.17", @@ -2228,8 +2229,7 @@ "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", - "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", - "dev": true + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" }, "process": { "version": "0.11.10", @@ -2246,8 +2246,7 @@ "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "dev": true + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==" }, "public-encrypt": { "version": "4.0.3", @@ -2267,7 +2266,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -2276,8 +2274,7 @@ "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "dev": true + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "querystring": { "version": "0.2.0", @@ -2354,20 +2351,17 @@ "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", - "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", - "dev": true + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==" }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, "require-main-filename": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", - "dev": true + "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" }, "requireindex": { "version": "1.1.0", @@ -2387,14 +2381,12 @@ "resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, "restore-cursor": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", - "dev": true, "requires": { "onetime": "^2.0.0", "signal-exit": "^3.0.2" @@ -2404,7 +2396,6 @@ "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", - "dev": true, "requires": { "glob": "^7.1.3" } @@ -2423,7 +2414,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", - "dev": true, "requires": { "is-promise": "^2.1.0" } @@ -2432,7 +2422,6 @@ "version": "6.4.0", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz", "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", - "dev": true, "requires": { "tslib": "^1.9.0" } @@ -2446,20 +2435,17 @@ "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", - "dev": true + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==" }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "sha.js": { "version": "2.4.11", @@ -2485,7 +2471,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "dev": true, "requires": { "shebang-regex": "^1.0.0" } @@ -2493,8 +2478,7 @@ "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", - "dev": true + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" }, "shell-quote": { "version": "1.6.1", @@ -2511,8 +2495,7 @@ "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "dev": true + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, "simple-concat": { "version": "1.0.0", @@ -2524,26 +2507,12 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", - "dev": true, "requires": { "ansi-styles": "^3.2.0", "astral-regex": "^1.0.0", "is-fullwidth-code-point": "^2.0.0" } }, - "snarkjs": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.12.tgz", - "integrity": "sha512-ST/bMGAove7yTr7DuMKWYOw3WGSAIUG40YPgx/sjzp5BYT0bHZeoWDKUf3t+grnRjCF4t56uI1NhYsTSRGuNoA==", - "dev": true, - "requires": { - "big-integer": "^1.6.35", - "chai": "^4.1.2", - "escape-string-regexp": "^1.0.5", - "eslint": "^5.3.0", - "yargs": "^12.0.2" - } - }, "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", @@ -2553,8 +2522,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "stream-browserify": { "version": "2.0.2", @@ -2603,7 +2571,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^4.0.0" @@ -2622,7 +2589,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, "requires": { "ansi-regex": "^3.0.0" } @@ -2630,14 +2596,12 @@ "strip-eof": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", - "dev": true + "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "subarg": { "version": "1.0.0", @@ -2660,7 +2624,6 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, "requires": { "has-flag": "^3.0.0" } @@ -2678,7 +2641,6 @@ "version": "5.2.3", "resolved": "https://registry.npmjs.org/table/-/table-5.2.3.tgz", "integrity": "sha512-N2RsDAMvDLvYwFcwbPyF3VmVSSkuF+G1e+8inhBLtHpvwXGw4QRPEZhihQNeEN0i1up6/f6ObCJXNdlRG3YVyQ==", - "dev": true, "requires": { "ajv": "^6.9.1", "lodash": "^4.17.11", @@ -2689,14 +2651,12 @@ "ansi-regex": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.0.0.tgz", - "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==", - "dev": true + "integrity": "sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w==" }, "string-width": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.0.0.tgz", "integrity": "sha512-rr8CUxBbvOZDUvc5lNIJ+OC1nPVpz+Siw9VBtUjB9b6jZehZLFt0JMCZzShFHIsI8cbhm0EsNIfWJMFV3cu3Ew==", - "dev": true, "requires": { "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", @@ -2707,7 +2667,6 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.0.0.tgz", "integrity": "sha512-Uu7gQyZI7J7gn5qLn1Np3G9vcYGTVqB+lFTytnDJv83dd8T22aGH451P3jueT2/QemInJDfxHB5Tde5OzgG1Ow==", - "dev": true, "requires": { "ansi-regex": "^4.0.0" } @@ -2717,14 +2676,12 @@ "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", - "dev": true + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=" }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "through2": { "version": "2.0.5", @@ -2749,7 +2706,6 @@ "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", - "dev": true, "requires": { "os-tmpdir": "~1.0.2" } @@ -2763,8 +2719,7 @@ "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", - "dev": true + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" }, "tty-browserify": { "version": "0.0.1", @@ -2776,7 +2731,6 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", - "dev": true, "requires": { "prelude-ls": "~1.1.2" } @@ -2784,8 +2738,7 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" }, "typedarray": { "version": "0.0.6", @@ -2816,7 +2769,6 @@ "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", - "dev": true, "requires": { "punycode": "^2.1.0" } @@ -2881,7 +2833,6 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, "requires": { "isexe": "^2.0.0" } @@ -2889,8 +2840,7 @@ "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, "wide-align": { "version": "1.1.3", @@ -2904,14 +2854,12 @@ "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", - "dev": true + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" }, "wrap-ansi": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", - "dev": true, "requires": { "string-width": "^1.0.1", "strip-ansi": "^3.0.1" @@ -2920,14 +2868,12 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "dev": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2936,7 +2882,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "dev": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2947,7 +2892,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2957,14 +2901,12 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", - "dev": true, "requires": { "mkdirp": "^0.5.1" } @@ -2978,14 +2920,12 @@ "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", - "dev": true + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, "yargs": { "version": "12.0.5", "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", - "dev": true, "requires": { "cliui": "^4.0.0", "decamelize": "^1.2.0", @@ -3005,7 +2945,6 @@ "version": "11.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", - "dev": true, "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" diff --git a/package.json b/package.json index 2620a63..cdd1337 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,40 @@ { - "name": "websnark", - "version": "0.0.4", - "description": "big integer library to work in Zq", - "main": "index.js", - "scripts": { - "test": "mocha --experimental-worker", - "buildwasm": "node tools/buildwasm.js", - "build": "node tools/buildwasm.js; browserify main.js -o build/websnark.js --exclude worker_threads --exclude crypto; cp build/websnark.js example/websnark.js" - }, - "keywords": [ - "bigint", - "bignum", - "biginteger", - "zq", - "elliptic", - "curve", - "prime", - "field" - ], - "author": "Jordi Baylina", - "license": "GPL-3.0", - "repository": { - "type": "git", - "url": "https://github.com/iden3/websnark.git" - }, - "devDependencies": { - "browserify": "^16.2.3", - "eslint": "^5.14.0", - "eslint-plugin-mocha": "^5.3.0", - "eslint-plugin-webassembly": "^1.8.4", - "mocha": "^6.1.4", - "package": "^1.0.1", - "snarkjs": "git+https://development.tornadocash.community/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5", - "wasmbuilder": "0.0.3" - }, - "dependencies": { - "big-integer": "1.6.42" - } + "name": "@tornado/websnark", + "version": "0.0.4", + "description": "big integer library to work in Zq", + "main": "index.js", + "scripts": { + "test": "mocha --experimental-worker", + "buildwasm": "node tools/buildwasm.js", + "build": "node tools/buildwasm.js && browserify main.js -o build/websnark.js --exclude worker_threads --exclude crypto && cp build/websnark.js example/websnark.js" + }, + "keywords": [ + "bigint", + "bignum", + "biginteger", + "zq", + "elliptic", + "curve", + "prime", + "field" + ], + "author": "Jordi Baylina", + "license": "GPL-3.0", + "repository": { + "type": "git", + "url": "https://git.tornado.ws/tornado-packages/websnark" + }, + "devDependencies": { + "browserify": "^16.2.3", + "eslint": "^5.14.0", + "eslint-plugin-mocha": "^5.3.0", + "eslint-plugin-webassembly": "^1.8.4", + "mocha": "^6.1.4", + "package": "^1.0.1", + "wasmbuilder": "0.0.3" + }, + "dependencies": { + "@tornado/snarkjs": "^0.1.20", + "big-integer": "1.6.42" + } } diff --git a/src/utils.js b/src/utils.js index f599cd6..db0d8f2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,20 +18,20 @@ */ const bigInt = require("big-integer"); -const Circuit = require("snarkjs/src/circuit"); -const bigInt2 = require("snarkjs/src/bigint"); +const Circuit = require("@tornado/snarkjs/src/circuit"); +const bigInt2 = require("@tornado/snarkjs/src/bigint"); const hexifyBigInts = require("../tools/stringifybigint").hexifyBigInts; const unhexifyBigInts = require("../tools/stringifybigint").unhexifyBigInts; const stringifyBigInts = require("../tools/stringifybigint").stringifyBigInts; const unstringifyBigInts = require("../tools/stringifybigint").unstringifyBigInts; -const stringifyBigInts2 = require("snarkjs/src/stringifybigint").stringifyBigInts; -const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts; +const stringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").stringifyBigInts; +const unstringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").unstringifyBigInts; function bigInt2BytesLE(_a, len) { const b = Array(len); let v = bigInt(_a); - for (let i=0; i toHex32(x)).join("") + proof: "0x" + flatProof.map((x) => toHex32(x)).join(""), }; if (proof.publicSignals) { result.publicSignals = hexifyBigInts(unstringifyBigInts(proof.publicSignals)); @@ -87,11 +91,11 @@ function toSolidityInput(proof) { return result; } -function genWitness(input, circuitJson) { +function genWitness(input, circuitJson) { const circuit = new Circuit(unstringifyBigInts2(circuitJson)); const witness = circuit.calculateWitness(unstringifyBigInts2(input)); const publicSignals = witness.slice(1, circuit.nPubInputs + circuit.nOutputs + 1); - return {witness, publicSignals}; + return { witness, publicSignals }; } async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { @@ -102,4 +106,4 @@ async function genWitnessAndProve(groth16, input, circuitJson, provingKey) { return result; } -module.exports = {bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve}; \ No newline at end of file +module.exports = { bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve }; diff --git a/test/bn128.js b/test/bn128.js index 72aa379..a555813 100644 --- a/test/bn128.js +++ b/test/bn128.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const refBn128 = require("snarkjs").bn128; -const refBigInt = require("snarkjs").bigInt; +const refBn128 = require("@tornado/snarkjs").bn128; +const refBigInt = require("@tornado/snarkjs").bigInt; const buildBn128 = require("../index.js").buildBn128; @@ -15,7 +15,7 @@ describe("Basic tests for g1 in bn128", () => { bn128.g1_fromMontgomery(p1, p1); const d = bn128.g1_getPoint(p1); - for (let i=0; i<3; i++) { + for (let i = 0; i < 3; i++) { d[i] = refBigInt(d[i].toString()); } @@ -39,7 +39,6 @@ describe("Basic tests for g1 in bn128", () => { d[1] = refBigInt(d[1].toString()); d[2] = refBigInt(d[2].toString()); - assert(d[0].equals(refD[0])); assert(d[1].equals(refD[1])); assert(d[2].equals(1)); @@ -59,7 +58,7 @@ describe("Basic tests for g1 in bn128", () => { bn128.g1_fromMontgomery(p1, p1); const d = bn128.g1_getPoint(p1); - for (let i=0; i<3; i++) { + for (let i = 0; i < 3; i++) { d[i] = refBigInt(d[i].toString()); } @@ -96,12 +95,11 @@ describe("Basic tests for g1 in bn128", () => { bn128.g1_fromMontgomery(p2, p2); const d = bn128.g1_getPoint(p2); - for (let i=0; i<3; i++) { + for (let i = 0; i < 3; i++) { d[i] = refBigInt(d[i].toString()); } assert(refBn128.G1.equals(d, refD)); - }).timeout(10000000); it("It should do a basic point doubling in G2", async () => { const bn128 = await buildBn128(); @@ -113,8 +111,8 @@ describe("Basic tests for g1 in bn128", () => { bn128.g2_fromMontgomery(p1, p1); const d = bn128.g2_getPoint(p1); - for (let i=0; i<3; i++) { - for (let j=0; j<2; j++) { + for (let i = 0; i < 3; i++) { + for (let j = 0; j < 2; j++) { d[i][j] = refBigInt(d[i][j].toString()); } } @@ -135,8 +133,8 @@ describe("Basic tests for g1 in bn128", () => { bn128.g2_fromMontgomery(p2, p2); const d = bn128.g2_getPoint(p2); - for (let i=0; i<3; i++) { - for (let j=0; j<2; j++) { + for (let i = 0; i < 3; i++) { + for (let j = 0; j < 2; j++) { d[i][j] = refBigInt(d[i][j].toString()); assert(d[i][j].equals(refD[i][j])); } diff --git a/test/fft.js b/test/fft.js index 10f2940..dfbd914 100644 --- a/test/fft.js +++ b/test/fft.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const refBn128 = require("snarkjs").bn128; -const refBigInt = require("snarkjs").bigInt; +const refBn128 = require("@tornado/snarkjs").bn128; +const refBigInt = require("@tornado/snarkjs").bigInt; const buildBn128 = require("../index.js").buildBn128; @@ -8,11 +8,11 @@ describe("FFT tests", () => { it("create a basic FFT", async () => { const bn128 = await buildBn128(); - const N=4; + const N = 4; - const p = bn128.alloc(32*N); - for (let i=0; i { bn128.fft_ifft(p, N); bn128.fft_fromMontgomeryN(p, p, N); - for (let i=0; i { const bn128 = await buildBn128(); - const N=1024; + const N = 1024; - const p = bn128.alloc(32*N); - for (let i=0; i { bn128.fft_fft(p, N, 0); bn128.fft_fromMontgomeryN(p, p, N); - for (let i=0; i { const bn128 = await buildBn128(); - const N=1024; + const N = 1024; - const p = bn128.alloc(32*N); - for (let i=0; i { bn128.fft_fft(p, N, 0); bn128.fft_fromMontgomeryN(p, p, N); - for (let i=0; i { const bn128 = await buildBn128(); - const N=1024; + const N = 1024; - const p = bn128.alloc(32*N); - const pr1 = bn128.alloc(32*N*2); - const pr2 = bn128.alloc(32*N*2); - for (let i=0; i { const pkey32 = new Uint32Array(provingKey); const pPointsA = pkey32[5]; - const points = provingKey.slice(pPointsA, pPointsA + nSignals*64); - const signals = signalsAll.slice(0, nSignals*32); + const points = provingKey.slice(pPointsA, pPointsA + nSignals * 64); + const signals = signalsAll.slice(0, nSignals * 32); const pr1 = groth16.alloc(96); const pPoints = groth16.alloc(points.byteLength); @@ -42,11 +41,10 @@ describe("Basic tests for groth16 proof generator", () => { const r2 = groth16.bin2g1(groth16.getBin(pr1, 96)); - assert.equal(r1[0],r2[0]); - assert.equal(r1[1],r2[1]); + assert.equal(r1[0], r2[0]); + assert.equal(r1[1], r2[1]); groth16.terminate(); - }); it("It should do a basic point doubling G1", async () => { @@ -57,12 +55,13 @@ describe("Basic tests for groth16 proof generator", () => { const proofS = await groth16.proof(signals.buffer, provingKey.buffer); const proof = snarkjs.unstringifyBigInts(proofS); - const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8"))); + const verifierKey = snarkjs.unstringifyBigInts( + JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")) + ); const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8"))); assert(snarkjs.groth.isValid(verifierKey, proof, pub)); groth16.terminate(); }).timeout(10000000); - });