How to use the bn.js function in bn

To help you get started, we’ve selected a few bn 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 matter-labs / RSAAccumulator / test / testRSAAccumulator.js View on Github external
function accumulatorToBN(accumulator, numLimbs) {
        const shift = 256;
        let newBN = (new BN(accumulator[0].toString(16), 16))
        for (let i = 1; i < numLimbs; i++) {
            newBN.iushln(shift);
            const limb = (new BN(accumulator[i].toString(16), 16))
            newBN.iadd(limb);
        }
        return newBN;
    }
github centrehq / centre-tokens / test / TokenTestUtils.js View on Github external
function newBigNumber(value) {
    var hex = new BigNumber(value).toString(16);
    return new BN(hex, 16);
}
github ethers-io / ethers.js / tests / make-tests / make-contract-events.js View on Github external
value: function(extra) {
                        var value = new BN(utils.randomHexString(seed + '-numberValue-' + extra, 1, size / 8).substring(2), 16);
                        if (sign) {
                            var signBit = (new BN(1)).shln(size - 1);
                            if (!signBit.and(value).isZero()) {
                                value = value.maskn(size - 1).mul(new BN(-1));
                            }
                        }
                        if (value.isNeg()) {
                            return '-0x' + value.toString('hex').substring(1);
                        }
                        return '0x' + value.toString('hex');
                    }
                }
github andrerfneves / lightning-decoder / src / lib / bolt11.js View on Github external
function hrpToSat (hrpString, outputString) {
  let millisatoshisBN = hrpToMillisat(hrpString, false)
  if (!millisatoshisBN.mod(new BN(1000, 10)).eq(new BN(0, 10))) {
    throw new Error('Amount is outside of valid range')
  }
  let result = millisatoshisBN.div(new BN(1000, 10))
  return outputString ? result.toString() : result
}
github bitcoinjs / bolt11 / payreq.js View on Github external
function hrpToSat (hrpString, outputString) {
  let millisatoshisBN = hrpToMillisat(hrpString, false)
  if (!millisatoshisBN.mod(new BN(1000, 10)).eq(new BN(0, 10))) {
    throw new Error('Amount is outside of valid range')
  }
  let result = millisatoshisBN.div(new BN(1000, 10))
  return outputString ? result.toString() : result
}
github andrerfneves / lightning-decoder / src / lib / bolt11.js View on Github external
function satToHrp (satoshis) {
  if (!satoshis.toString().match(/^\d+$/)) {
    throw new Error('satoshis must be an integer')
  }
  let millisatoshisBN = new BN(satoshis, 10)
  return millisatToHrp(millisatoshisBN.mul(new BN(1000, 10)))
}
github AztecProtocol / AZTEC / packages / aztec.js / src / proof / base / epoch0 / verifier.js View on Github external
hexToGroupScalar(hex, canBeZero = false) {
        const hexBN = new BN(hex.slice(2), 16);
        if (!hexBN.lt(bn128.curve.n)) {
            this.errors.push(errors.codes.SCALAR_TOO_BIG);
        }
        if (!canBeZero && hexBN.eq(ZERO_BN)) {
            this.errors.push(errors.codes.SCALAR_IS_ZERO);
        }
        return hexBN.toRed(bn128.groupReduction);
    }
}
github OriginTrail / ot-node / modules / ZK.js View on Github external
constructor(ctx) {
        this.zero = new BN(0);
        this.one = new BN(1);
        this.n = new BN('14fef784d91e20718aee8ef1', 16);
        this.nSquare = this.n.mul(this.n);
        this.red = BN.red(this.n);
        this.redSquare = BN.red(this.nSquare);
        this.g = this.n.add(this.one).toRed(this.redSquare);

        this.log = ctx.logger || console;
    }
github ArcBlock / forge-js / forge / forge-util / lib / index.js View on Github external
const toBN = number => {
  try {
    if (typeof number === 'number' && number > 0) {
      const numStr = Number(number).toLocaleString('fullwide', { useGrouping: false });
      return new BN(numStr, 10);
    }
    return numberToBN(number);
  } catch (error) {
    throw new Error(`${error} Given value: "${number}"`);
  }
};
github atvanguard / ethsingapore-zk-dai / ethereum / scripts / zokcmd.js View on Github external
function getHexPayload(from, amount) {
  let paddedAddress = new BN(from, 16).toString(16, 64);
  let paddedAmount = new BN(amount, 16).toString(16, 64);
  return paddedAddress + paddedAmount;
}

bn

JS Bigint import

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

50 / 100
Full package analysis

Popular bn functions