How to use bn - 10 common examples

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 unstoppabledomains / browseth / src / explorer.ts View on Github external
function checkIfString(val: string | number) {
  if (typeof val === 'string') {
    if (/[g-z]/i.test(val)) {
      // if 'latest' 'earliest' 'pending'
      return val;
    }
    return /^0x/i.test(val) ? val : '0x' + new BN(val).toString(16);
  }
  return '0x' + val.toString(16);
}
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 warren-bank / ethereumjs-tx-sign / tests / 05_EIP_155 / js / compare_output.js View on Github external
const clean_input = function(str) {
  if ((typeof str === 'number') || (str.isBigNumber === true) || BN.isBN(str)) str = `${ str.toString(16) }`
  if ((!str) || (typeof str !== 'string') || (str === '0x')) str = '00'
  if (str.indexOf('0x') === 0) str = str.substr(2)
  if (str.length % 2 === 1) str = `0${str}`
  return `0x${str}`
}
github warren-bank / ethereumjs-tx-sign / tests / 02_deploy_and_validate / js / deploy_and_validate.js View on Github external
const clean_input = function(str) {
  if ((typeof str === 'number') || (str.isBigNumber === true) || BN.isBN(str)) str = `${ str.toString(16) }`
  if ((!str) || (typeof str !== 'string') || (str === '0x')) str = '00'
  if (str.indexOf('0x') === 0) str = str.substr(2)
  if (str.length % 2 === 1) str = `0${str}`
  return `0x${str}`
}
github gnosis / dex-contracts / test / resources / math.js View on Github external
function feeSubtracted(x, n = 1) {
  assert(BN.isBN(x), "x is not a bignum")
  assert(Number.isInteger(n) && n > 0, "n is not a valid integer")

  const result = x.mul(FEE_DENOMINATOR_MINUS_ONE).div(FEE_DENOMINATOR)
  return n === 1 ? result : feeSubtracted(result, n - 1)
}
github gnosis / dex-contracts / test / resources / auction_examples.js View on Github external
function feeAdded(x) {
  assert(BN.isBN(x))
  return x.mul(feeDenominator).div(feeDenominatorMinusOne)
}
github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
async printCurrentState() {
    for (let i = 0; i < Object.keys(this.reputations).length; i += 1) {
      const key = Object.keys(this.reputations)[i];
      const decimalValue = new BN(this.reputations[key].slice(2, 66), 16);
      const keyElements = ReputationMiner.breakKeyInToElements(key);
      const [colonyAddress, , userAddress] = keyElements;
      const skillId = parseInt(keyElements[1], 16);

      console.log("colonyAddress", colonyAddress);
      console.log("userAddress", userAddress);
      console.log("skillId", skillId);
      console.log("value", decimalValue.toString());
      console.log("---------");
    }
  }
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
}

bn

JS Bigint import

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

50 / 100
Full package analysis

Popular bn functions