How to use the bignum.fromBuffer function in bignum

To help you get started, we’ve selected a few bignum 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 aayanl / equihash-solomining / lib / stratum / jobManager.js View on Github external
if (soln.length !== 2694) {
            return shareError([20, 'incorrect size of solution']);
        }

        if (!job.registerSubmit(extraNonce1, extraNonce2, nTime, nonce)) {
            return shareError([22, 'duplicate share']);
        }

        var extraNonce1Buffer = new Buffer(extraNonce1, 'hex');
        var extraNonce2Buffer = new Buffer(extraNonce2, 'hex');

        var headerBuffer = job.serializeHeader(nTime, nonce); // 144 bytes (doesn't contain soln)
        var headerSolnBuffer = new Buffer.concat([headerBuffer, new Buffer(soln, 'hex')]);
        var headerHash = util.sha256d(headerSolnBuffer);
        var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});

        var blockHashInvalid;
        var blockHash;
        var blockHex;

        var shareDiff = diff1 / headerBigNum.toNumber() * shareMultiplier;
        var blockDiffAdjusted = job.difficulty * shareMultiplier;

        //check if block candidate and if the equihash solution is valid
        //if (1 === 1) {
        if (headerBigNum.le(job.target) && hashDigest(headerBuffer, new Buffer(soln.slice(6), 'hex'))) {
            blockHex = job.serializeBlock(headerBuffer, new Buffer(soln, 'hex')).toString('hex');
            blockHash = util.reverseBuffer(headerHash).toString('hex');
        }
        else {
            if (options.emitInvalidBlockHashes)
github shovon / node-speke / index.js View on Github external
SPEKE.prototype.generateKeys = function (password, algorithm) {
  algorithm = algorithm || 'md5';

  var primebigint = bigint.fromBuffer(this._prime);

  // Create the generator.
  var hash = crypto.createHash(algorithm);
  hash.update(password);
  var h = hash.digest();
  this._generator =
    bigint.fromBuffer(h).powm(bigint('2'), primebigint);

  // Create the private key.
  this._privateKey = crypto.randomBytes(this._prime.length);

  // Create the public key.
  this._publicKey = this._generator
    .powm(bigint.fromBuffer(this._privateKey), primebigint);

  return this.getPublicKey();
};
github devongovett / reader / src / utils.js View on Github external
exports.shortItemId = function(id) {
    var num = bignum(id, 16);
    
    // get a signed version if needed
    if (id[0] === 'f') {
        var buf = num.toBuffer();
        for (var j = 0; j < buf.length; j++)
            buf[j] = 0xff - buf[j];
        
        num = bignum.fromBuffer(buf).add(1).neg();
    }
    
    return num.toString(10);
};
github aayanl / equihash-solomining / lib / jobManager.js View on Github external
if (!job.registerSubmit(extraNonce1, extraNonce2, nTime, nonce)) {
            return shareError([22, 'duplicate share']);
        }


        var extraNonce1Buffer = new Buffer(extraNonce1, 'hex');
        var extraNonce2Buffer = new Buffer(extraNonce2, 'hex');

        var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
        var coinbaseHash   = util.doublesha(coinbaseBuffer);

        var merkleRoot = util.reverseBuffer(job.merkleTree.withFirst(coinbaseHash)).toString('hex');

        var headerBuffer = job.serializeHeader(merkleRoot, nTime, nonce);
        var headerHash   = hashDigest(headerBuffer, nTimeInt);
        var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});

        var blockHash;
        var blockHex;


        if (job.target.ge(headerBigNum)){
            blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
            blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
        }
        else {
            var targetUser = bignum(diffDividend / difficulty);
            if (headerBigNum.gt(targetUser)){
                return shareError([23, 'low difficulty share']);
            }
        }
        if (!!blockHex) {
github carlos8f / salty / net.js View on Github external
function handshake () {
          var nonce = bignum.fromBuffer(cnonce)
            .xor(bignum.fromBuffer(snonce))
            .toBuffer();
          input.pipe(wallet.peerStream(nonce, sid)).pipe(socket);
          socket.pipe(wallet.peerStream(nonce, sid)).pipe(output);
          socket.on('data', console.log);
          cb && cb(proxy, salty.identity(sid), nonce);
        }
      }
github carlos8f / salty / net.js View on Github external
function handshake () {
          var nonce = bignum.fromBuffer(cnonce)
            .xor(bignum.fromBuffer(snonce))
            .toBuffer();
          input.pipe(wallet.peerStream(nonce, sid)).pipe(socket);
          socket.pipe(wallet.peerStream(nonce, sid)).pipe(output);
          socket.on('data', console.log);
          cb && cb(proxy, salty.identity(sid), nonce);
        }
      }
github carlos8f / salty / net.js View on Github external
readStream(socket, function (data, unlisten) {
      if (!cid) cid = data;
      else if (!cnonce) cnonce = data;
      if (!--latch) {
        unlisten();
        var nonce = bignum.fromBuffer(cnonce)
          .xor(bignum.fromBuffer(snonce))
          .toBuffer();
        writeStream(socket, wallet.identity.toBuffer());
        writeStream(socket, snonce);
        var pe = wallet.peerStream(nonce, cid);
        var pd = wallet.peerStream(nonce, cid);
        pe.pipe(socket);
        socket.pipe(pd);
        socket.on('data', console.log);
        var dup = es.duplex(pe, pd);
        cb(dup);
      }
    });
  });
github mozilla / node-srp / lib / srp.js View on Github external
function getk(params) {
  var k_buf = crypto
    .createHash(params.hash)
    .update(padToN(params.N, params))
    .update(padToN(params.g, params))
    .digest();
  return bignum.fromBuffer(k_buf);
};
github mozilla / node-srp / lib / srp.js View on Github external
function getx(params, salt, I, P) {
  assertIsBuffer(salt, "salt (salt)");
  assertIsBuffer(I, "identity (I)");
  assertIsBuffer(P, "password (P)");
  var hashIP = crypto.createHash(params.hash)
    .update(Buffer.concat([I, new Buffer(':'), P]))
    .digest();
  var hashX = crypto.createHash(params.hash)
    .update(salt)
    .update(hashIP)
    .digest();
  return bignum.fromBuffer(hashX);
};
github joyent / manatee / lib / adm.js View on Github external
opts.zkClient.getData(p, function (err, data, stat) {
        if (err) {
            return (cb(err));
        }
        var time = bignum.fromBuffer(stat.ctime).toNumber();
        var ret = {
            'time': new Date(time),
            'state': JSON.parse(data.toString('utf8')),
            'zkSeq': fNode[1]
        };
        return (cb(null, ret));
    });
}

bignum

Arbitrary-precision integer arithmetic using OpenSSL

MIT
Latest version published 4 years ago

Package Health Score

33 / 100
Full package analysis

Popular bignum functions