How to use the big-integer.zero function in big-integer

To help you get started, we’ve selected a few big-integer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iden3 / websnark / test / f1.js View on Github external
it("It should do various test in zq Snarks modules", async () => {
        const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
        const f1 = await buildF1(q);
        const v= [
            q.minus(1),
            q.minus(2),
            q.minus(1).shiftRight(1),
            q.minus(1).shiftRight(1).add(1),
            q.minus(1).shiftRight(1).add(2),
            q.minus(1).shiftRight(1).minus(1),
            q.minus(1).shiftRight(1).minus(2),
            bigInt(2),
            bigInt.one,
            bigInt.zero
        ];

        const pA = f1.allocInt();
        const pB = f1.allocInt();
        const pC = f1.allocInt();
        let c;

        for (let i=0; i
github Cryptonomic / ConseilJS / src / chain / tezos / lexer / Micheline.js View on Github external
const writeSignedInt = value => {
        if (value === 0) { return '00'; }

        const n = bigInt(value).abs();
        const l = n.bitLength().toJSNumber();
        let arr = [];
        let v = n;
        for (let i = 0; i < l; i += 7) {
            let byte = bigInt.zero;

            if (i === 0) {
                byte = v.and(0x3f); // first byte makes room for sign flag
                v = v.shiftRight(6);
            } else {
                byte = v.and(0x7f); // NOT base128 encoded
                v = v.shiftRight(7);
            }

            if (value < 0 && i === 0) { byte = byte.or(0x40); } // set sign flag

            if (i + 7 < l) { byte = byte.or(0x80); } // set next byte flag
            arr.push(byte.toJSNumber());
        }

        if (l % 7 === 0) {
github jeffijoe / snicket / src / subscriptions / all-subscription.ts View on Github external
async function getStartPositionForEnd() {
    try {
      const head = await store.readHeadPosition()
      // Edge case where start position is 0 (beginning of time) and the stream is empty.
      if (head === '0') {
        return BigInteger.zero
      }
      return BigInteger(head).plus(1)
    } catch (error) {
      logger.error(
        'Unable to get stream information. Dropping subscription and disposing.',
        error
      )
      await dropAndDispose()
      return BigInteger(-1)
    }
  }
github iden3 / snarkjs / src / bigint.js View on Github external
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()) {
github noobaa / noobaa-core / src / util / size_utils.js View on Github external
'reserved',
    'unavailable_free',
    'unavailable_used',
    'limit',
    'alloc',
    'real',
];

BigInteger.PETABYTE = new BigInteger(PETABYTE);

// We are overriding BigInteger.prototype.toJSON to make sure that JSON.stringify({ size: bigint }) will behave nicely
// however BigInteger creates 3 prototypes internally (Integer, SmallInteger, BigInteger)
// and writes the 'toJSON' property explicitly for all of them, we have to overwrite all 3.
const IntegerPrototype = BigInteger.prototype;
const BigIntegerPrototype = Object.getPrototypeOf(BigInteger.PETABYTE.multiply(BigInteger.PETABYTE));
const SmallIntegerPrototype = Object.getPrototypeOf(BigInteger.zero);
IntegerPrototype.toJSON = bigint_to_json_method;
BigIntegerPrototype.toJSON = bigint_to_json_method;
SmallIntegerPrototype.toJSON = bigint_to_json_method;

/**
 * @this {BigInteger}
 */
function bigint_to_json_method() {
    return bigint_to_json(this);
}

/**
 * take a BigInteger object and convert to json {peta:.., n: ..} format if needed
 */
function bigint_to_json(bi) {
    const dm = bi.divmod(BigInteger.PETABYTE);
github tilk / digitaljs / src / cells / arith.js View on Github external
    arithop: i => bigInt.zero.minus(i)
});
github opporty-com / Plasma-Cash / plasma-core / lib / bls / index.js View on Github external
static lagrange(vec, Et) {
    let S = new Array(vec.length)
    for (let i = 0; i < vec.length; i++) {
      S[i] = vec[i].id
    }
    let delta = BLSPolynomial.calcDelta(S)
    let r
    if (vec[0].s) {
      r = bigInt.zero
    } else {
      r = new Point2(Et)
    }
    for (let i = 0; i < delta.length; i++) {
      if (vec[i].s) {
        r = r.add(vec[i].s.multiply(delta[i]))
      } else {
        r = r.add(vec[i].sH.multiply(delta[i]))
      }
    }
    return r
  }
}
github p2p-today / p2p-project / js_src / base.js View on Github external
base.unpack_value = function unpack_value(str)  {
    /**
    * .. js:function:: js2p.base.unpack_value(str)
    *
    *     This function unpacks a string into its corresponding big endian value
    *
    *     :param str: The string you want to unpack
    *
    *     :returns: A big-integer
    */
    str = new Buffer(str, 'ascii');
    var val = BigInt.zero;
    for (let i = 0; i < str.length; i++)    {
        val = val.shiftLeft(8);
        val = val.add(str[i]);
    }
    return val;
}
github Cryptonomic / ConseilJS / src / chain / tezos / TezosMessageUtil.ts View on Github external
export function readSignedInt(hex: string): number {
        const positive = (Buffer.from(hex.slice(0, 2), 'hex')[0] & 0x40) ? false : true;
        //@ts-ignore
        const arr = Buffer.from(hex, 'hex').map((v, i) => i === 0 ? v & 0x3f : v & 0x7f);
        let n = bigInt.zero;
        for (let i = arr.length - 1; i >= 0; i--) {
            if (i === 0) {
                n = n.or(arr[i]);
            } else {
                n = n.or(bigInt(arr[i]).shiftLeft(7 * i - 1));
            }
        }

        return positive ? n.toJSNumber() : n.negate().toJSNumber();
    }