How to use the big-integer.isInstance 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 p2p-today / p2p-project / js_src / types.js View on Github external
function determine_type(x)  {
    if (Buffer.isBuffer(x)) {
        return types.types.buffer;
    }
    else if (typeof x === 'string' || x instanceof String)  {
        return types.types.string;
    }
    else if (x instanceof Array)    {
        return types.types.array;
    }
    else if (BigInt.isInstance(x))  {
        return determine_int_subtype(x);
    }
    else if (Number(parseFloat(x))===x) {
        return determine_int_subtype(new BigInt(x));
    }
    return types.types.buffer;
}
github p2p-today / p2p-project / js_src / base.js View on Github external
base.pack_value = function pack_value(len, i) {
    /**
    * .. js:function:: js2p.base.pack_value(len, i)
    *
    *     This function packs an integer i into a buffer of length len
    *
    *     :param len:   An integral value
    *     :param i:     An integeral value
    *
    *     :returns: A big endian buffer of length len
    */
    var arr = new Buffer(new Array(len));
    if (!BigInt.isInstance(i))  {
        i = BigInt(i);
    }
    for (let j = 0; j < len && i.compare(0); j++)    {
        arr[len - j - 1] = i.and(0xff).valueOf();
        i = i.shiftRight(8);
    }
    return arr;
}
github p2p-today / p2p-project / js_src / mesh.js View on Github external
this.waterfalls.some(function(entry)    {
            if (!BigInt.isInstance(entry[1])) {
                entry[1] = new BigInt(entry[1]);
            }
            if (!Buffer.compare(entry[0], id) && entry[1].equals(time))   {
                contained = true;
                return true;
            }
        });
        return contained;
github p2p-today / p2p-project / js_src / chord.js View on Github external
get id_10() {
        if (this.id === null)   {
            return null;
        }
        else if (!BigInt.isInstance(this.__id_10))   {
            this.__id_10 = base.from_base_58(this.id);
        }
        return this.__id_10;
    }
};
github p2p-today / p2p-project / js_src / base.js View on Github external
base.to_base_58 = function to_base_58(i) {
    /**
    * .. js:function:: js2p.base.to_base_58(i)
    *
    *     Takes an integer and returns its corresponding base_58 string
    *
    *     :param i: An integral value
    *
    *     :returns: the corresponding base_58 string
    */
    var string = "";
    if (!BigInt.isInstance(i)) {
        i = new BigInt(i);
    }
    while (i.notEquals(0)) {
        string = base.base_58[i.mod(58)] + string;
        i = i.divide(58);
    }
    if (!string)    {
        string = "1";
    }
    return string;
};