How to use the big-integer.fromArray 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 weijiekoh / zkmm / mastermind / src / test_mastermind.ts View on Github external
const genSalt = (): bigInt.BigInteger => {
    const buf = crypto.randomBytes(54)
    const salt = bigInt.fromArray(Array.from(buf), 256, false).minus(340)

    // 4 * (4^3) + 4 * (4^2) + 4 * (4^1) + 4 * (4^0) = 340
    // Only return values greater than the largest possible solution
    if (salt.lt(340)) {
        return genSalt()
    }

    return salt
}
github amzn / ion-js / src / IonLongInt.ts View on Github external
public static fromUIntBytes(bytes : number[]) : LongInt {
        return new LongInt(bigInt.fromArray(bytes, 256, false));
    }
github amzn / ion-js / src / IonLongInt.ts View on Github external
public static fromVarUIntBytes(bytes : number[]) : LongInt {
        return new LongInt(bigInt.fromArray(bytes, 128, false));
    }
github tilk / digitaljs / src / joint.js View on Github external
function sig2bigint(sig, signed) {
    const sign = signed && sig.slice(-1)[0] == 1;
    const j = bigInt.fromArray(sig.slice().reverse().map(x => (x+1)>>1), 2);
    return sign ? j.minus(bigInt.one.shiftLeft(sig.length)) : j;
}
github amzn / ion-js / src / IonLongInt.ts View on Github external
public static fromVarIntBytes(bytes : number[], isNegative : boolean) : LongInt {
        return new LongInt(bigInt.fromArray(bytes, 128, isNegative));
    }
github umegaya / pb3sol / src / soltype-pb / index.js View on Github external
toBigint: function () {
        if (this.type == "biguint") {
            return Bigint.fromArray(this.data, 256);
        } else {
            var val = Bigint.fromArray(this.data, 256);
            var tmp = this.data[0];
            if (tmp > 0x80) {
                switch (this.data.length) {
                case 16:
                    return val.subtract(MaxUint128Plus1);
                case 32:
                    return val.subtract(MaxUint256Plus1);
                default:
                    throw new Error("invalid array length:" + this.data.length);
                }
            } else {
                return val;
            }
        }
    },
    isBytes: function() {