Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
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];
}
}
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;
}
}
// 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);
};
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;
}
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;
}
// 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);
};