How to use minimalistic-crypto-utils - 10 common examples

To help you get started, we’ve selected a few minimalistic-crypto-utils 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 lino-network / lino-js / src / transport / index.ts View on Github external
var ec = new EC('secp256k1');
    var key = ec.keyFromPrivate(decodePrivKey(privKeyHex), 'hex');

    // XXX: side effect on msg
    convertMsg(msg);
    const stdMsg: StdMsg = {
      type: msgType,
      value: encodeMsg(msg)
    };

    // signmsg
    var msgs = new Array(stdMsg);
    const signMsgHash = encodeSignMsg(msgs, this._chainId, seq, 100000);
    // sign to get signature
    const sig = key.sign(signMsgHash, { canonical: true });
    const sigDERHex = utils.encode(sig.r.toArray('be', 32).concat(sig.s.toArray('be', 32)), 'hex');
    // build tx
    const tx = encodeTx(
      msgs,
      new Array(key.getPublic(true, 'hex')),
      new Array(sigDERHex),
      100000
    );
    // return broadcast
    return this._rpc.broadcastTxCommit(tx).then(result => {
      if (result.check_tx.code !== undefined) {
        throw new BroadcastError(
          BroadCastErrorEnum.CheckTx,
          result.check_tx.log,
          result.check_tx.code
        );
      } else if (result.deliver_tx.code !== undefined) {
github sx1989827 / DOClever / Client / node_modules / hmac-drbg / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  // Optional entropy enc
  if (typeof entropyEnc !== 'string') {
    addEnc = add;
    add = entropyEnc;
    entropyEnc = null;
  }

  entropy = utils.toArray(entropy, entropyEnc);
  add = utils.toArray(add, addEnc);

  assert(entropy.length >= (this.minEntropy / 8),
         'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');

  this._update(entropy.concat(add || []));
  this._reseed = 1;
};
github habitlab / habitlab / src / jspm_packages / npm / hmac-drbg@1.0.1 / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  if (this._reseed > this.reseedInterval)
    throw new Error('Reseed is required');

  // Optional encoding
  if (typeof enc !== 'string') {
    addEnc = add;
    add = enc;
    enc = null;
  }

  // Optional additional data
  if (add) {
    add = utils.toArray(add, addEnc || 'hex');
    this._update(add);
  }

  var temp = [];
  while (temp.length < len) {
    this.V = this._hmac().update(this.V).digest();
    temp = temp.concat(this.V);
  }

  var res = temp.slice(0, len);
  this._update(add);
  this._reseed++;
  return utils.encode(res, enc);
};
github sx1989827 / DOClever / Client / node_modules / hmac-drbg / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  if (this._reseed > this.reseedInterval)
    throw new Error('Reseed is required');

  // Optional encoding
  if (typeof enc !== 'string') {
    addEnc = add;
    add = enc;
    enc = null;
  }

  // Optional additional data
  if (add) {
    add = utils.toArray(add, addEnc || 'hex');
    this._update(add);
  }

  var temp = [];
  while (temp.length < len) {
    this.V = this._hmac().update(this.V).digest();
    temp = temp.concat(this.V);
  }

  var res = temp.slice(0, len);
  this._update(add);
  this._reseed++;
  return utils.encode(res, enc);
};
github habitlab / habitlab / src / jspm_packages / npm / hmac-drbg@1.0.1 / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  // Optional entropy enc
  if (typeof entropyEnc !== 'string') {
    addEnc = add;
    add = entropyEnc;
    entropyEnc = null;
  }

  entropy = utils.toArray(entropy, entropyEnc);
  add = utils.toArray(add, addEnc);

  assert(entropy.length >= (this.minEntropy / 8),
         'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');

  this._update(entropy.concat(add || []));
  this._reseed = 1;
};
github sx1989827 / DOClever / Client / node_modules / hmac-drbg / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  // Optional entropy enc
  if (typeof entropyEnc !== 'string') {
    addEnc = add;
    add = entropyEnc;
    entropyEnc = null;
  }

  entropy = utils.toArray(entropy, entropyEnc);
  add = utils.toArray(add, addEnc);

  assert(entropy.length >= (this.minEntropy / 8),
         'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');

  this._update(entropy.concat(add || []));
  this._reseed = 1;
};
github habitlab / habitlab / src / jspm_packages / npm / hmac-drbg@1.0.1 / lib / hmac-drbg.js View on Github external
HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  // Optional entropy enc
  if (typeof entropyEnc !== 'string') {
    addEnc = add;
    add = entropyEnc;
    entropyEnc = null;
  }

  entropy = utils.toArray(entropy, entropyEnc);
  add = utils.toArray(add, addEnc);

  assert(entropy.length >= (this.minEntropy / 8),
         'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');

  this._update(entropy.concat(add || []));
  this._reseed = 1;
};
github lino-network / lino-js / src / lino.ts View on Github external
check_tx: null,
              deliver_tx: null,
              height: txSeq.tx.height,
              hash: txSeq.tx.hash
            };
            return [response, txSeq.tx.hash];
          }
          seqs.push(txSeq.sequence);
        }
      }
    }
    var tx = f(seqs);
    const hashResult = shajs('sha256')
      .update(ByteBuffer.atob(tx))
      .digest() as string;
    const txHash = utils.encode(hashResult, 'hex').toUpperCase();
    var res: ResultBroadcastTx;
    try {
      res = await this._broadcast.broadcastRawMsgBytesSync(tx);
    } catch (err) {
      if (err.data && err.data.indexOf('Tx already exists in cache') >= 0) {
        // do nothing
      } else if (err.code && err.message) {
        if (err.code === 155) {
          var seqstr = err.message.substring(err.message.indexOf('seq:') + 4);
          var correctSeq = Number(seqstr.substring(0, seqstr.indexOf('"')));
          if (correctSeq === seqs[0]) {
            throw new BroadcastError(BroadCastErrorEnum.CheckTx, err.message, err.code);
          } else {
            return [null, txHash];
          }
        }
github lino-network / lino-js / src / transport / index.ts View on Github external
var ec = new EC('secp256k1');
      var key = ec.keyFromPrivate(decodePrivKey(privKey), 'hex');
      pubkeys.push(key.getPublic(true, 'hex'));

      // XXX: side effect on msg
      convertMsg(msg);
      const stdMsg: StdMsg = {
        type: msgType,
        value: encodeMsg(msg)
      };
      msgs.push(stdMsg);

      const signMsgHash = encodeSignMsg(msgs, this._chainId, seq[_i], this._maxFeeInCoin);
      // sign to get signature
      const sig = key.sign(signMsgHash, { canonical: true });
      const sigDERHex = utils.encode(
        sig.r.toArray('be', 32).concat(sig.s.toArray('be', 32)),
        'hex'
      );
      sigs.push(sigDERHex);
    }
    // build tx
    const tx = encodeTx(msgs, pubkeys, sigs, this._maxFeeInCoin);
    return tx;
  }
}
github sx1989827 / DOClever / Client / node_modules / hmac-drbg / lib / hmac-drbg.js View on Github external
// Optional additional data
  if (add) {
    add = utils.toArray(add, addEnc || 'hex');
    this._update(add);
  }

  var temp = [];
  while (temp.length < len) {
    this.V = this._hmac().update(this.V).digest();
    temp = temp.concat(this.V);
  }

  var res = temp.slice(0, len);
  this._update(add);
  this._reseed++;
  return utils.encode(res, enc);
};

minimalistic-crypto-utils

Minimalistic tools for JS crypto modules

MIT
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis