How to use the @arkecosystem/crypto.Bignum function in @arkecosystem/crypto

To help you get started, we’ve selected a few @arkecosystem/crypto 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 ArkEcosystem / core / packages / core-tester-cli / lib / utils / parse-fee.js View on Github external
module.exports = (fee) => {
  if (typeof fee === 'string' && fee.indexOf('-') !== -1) {
    const feeRange = fee.split('-').map(f => new Bignum(f))
    if (feeRange[1] < feeRange[0]) {
      return feeRange[0]
    }

    return new Bignum(randomFee(feeRange[0], feeRange[1]))
  }

  return new Bignum(fee)
}
github ArkEcosystem / core / packages / core-tester-cli / lib / utils / parse-fee.js View on Github external
module.exports = (fee) => {
  if (typeof fee === 'string' && fee.indexOf('-') !== -1) {
    const feeRange = fee.split('-').map(f => new Bignum(f))
    if (feeRange[1] < feeRange[0]) {
      return feeRange[0]
    }

    return new Bignum(randomFee(feeRange[0], feeRange[1]))
  }

  return new Bignum(fee)
}
github ArkEcosystem / core / packages / core-tester-cli / lib / commands / transfer.js View on Github external
wallets,
      null,
      true,
    )
    for (const transaction of transactions) {
      totalDeductions = totalDeductions
        .plus(transactionAmount)
        .plus(transaction.fee)
    }

    if (this.options.copy) {
      this.copyToClipboard(transactions)
      return
    }

    const expectedSenderBalance = new Bignum(walletBalance).minus(
      totalDeductions,
    )
    if (!this.options.skipValidation) {
      logger.info(
        `Sender expected ending balance: ${Command.__arktoshiToArk(
          expectedSenderBalance,
        )}`,
      )
    }

    const runOptions = {
      primaryAddress,
      transactions,
      wallets,
      transactionAmount,
      expectedSenderBalance,
github ArkEcosystem / core / packages / core-deployer / src / builder / genesis-block.ts View on Github external
public __getBlockId(block) {
        const hash = this.__getHash(block);
        const blockBuffer = Buffer.alloc(8);
        for (let i = 0; i < 8; i++) {
            blockBuffer[i] = hash[7 - i];
        }

        return new Bignum(blockBuffer.toString("hex"), 16).toString();
    }
github ArkEcosystem / core / packages / core-database-postgres / lib / connection.js View on Github external
Object.keys(wallet).forEach(key => {
            if (['balance'].indexOf(key) !== -1) {
              return
            }

            coldWallet[key] =
              key !== 'voteBalance' ? wallet[key] : new Bignum(wallet[key])
          })
        }
github ArkEcosystem / core / packages / core-database / lib / repositories / utils / delegate-calculator.js View on Github external
exports.calculateApproval = (delegate, height) => {
  const constants = config.getConstants(height)
  const totalSupply = new Bignum(config.genesisBlock.totalAmount).plus((height - constants.height) * constants.reward)

  return delegate.balance.times(100).dividedBy(totalSupply).toNumber().toFixed(2)
}
github ArkEcosystem / core / packages / core-database-postgres / src / connection.ts View on Github external
Object.keys(wallet).forEach(key => {
                        if (["balance"].indexOf(key) !== -1) {
                            return;
                        }

                        coldWallet[key] = key !== "voteBalance" ? wallet[key] : new Bignum(wallet[key]);
                    });
                }
github ArkEcosystem / core / packages / core-utils / lib / delegate-calculator.js View on Github external
exports.calculateApproval = (delegate, height) => {
  const config = app.resolvePlugin('config')

  if (!height) {
    height = app.resolvePlugin('blockchain').getLastBlock().data.height
  }

  const constants = config.getConstants(height)
  const totalSupply = new Bignum(config.genesisBlock.totalAmount).plus(
    (height - constants.height) * constants.reward,
  )
  const voteBalance = new Bignum(delegate.voteBalance)

  return +voteBalance
    .times(100)
    .dividedBy(totalSupply)
    .toFixed(2)
}
github ArkEcosystem / core / packages / core-deployer / src / builder / genesis-block.ts View on Github external
public __getBytes(block) {
        const size = 4 + 4 + 4 + 8 + 4 + 4 + 8 + 8 + 4 + 4 + 4 + 32 + 32 + 64;

        try {
            const byteBuffer = new ByteBuffer(size, true);
            byteBuffer.writeInt(block.version);
            byteBuffer.writeInt(block.timestamp);
            byteBuffer.writeInt(block.height);

            if (block.previousBlock) {
                const previousBlock = Buffer.from(new Bignum(block.previousBlock).toString(16), "hex");

                for (let i = 0; i < 8; i++) {
                    byteBuffer.writeByte(previousBlock[i]);
                }
            } else {
                for (let i = 0; i < 8; i++) {
                    byteBuffer.writeByte(0);
                }
            }

            byteBuffer.writeInt(block.numberOfTransactions);
            byteBuffer.writeLong(block.totalAmount);
            byteBuffer.writeLong(block.totalFee);
            byteBuffer.writeLong(block.reward);

            byteBuffer.writeInt(block.payloadLength);