How to use the minimalistic-crypto-utils.encode function in minimalistic-crypto-utils

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 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);
};
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, 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');
    // build tx
    const tx = encodeTx(
      msgs,
      new Array(key.getPublic(true, 'hex')),
      new Array(sigDERHex),
      this._maxFeeInCoin
    );
    return tx;
  }
github lino-network / lino-js / src / util / index.ts View on Github external
export function signWithSha256(msg: any, privKeyHex: string): string {
  // private key from hex
  var ec = new EC('secp256k1');
  var key = ec.keyFromPrivate(decodePrivKey(privKeyHex), 'hex');
  const signByte = shajs('sha256')
    .update(msg)
    .digest();
  // sign to get signature
  const sig = key.sign(signByte, { canonical: true });
  const sigDERHex = utils.encode(sig.r.toArray().concat(sig.s.toArray()), 'hex');
  return sigDERHex;
}
github habitlab / habitlab / src / jspm_packages / npm / hmac-drbg@1.0.1 / 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