Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let precommits = []
let time = new Date(header.time).getTime()
for (let i = 0; i < validators.length; i++) {
let validator = validators[i]
let precommit = {
validator_address: validator.address,
validator_index: String(i),
height: header.height,
round: '0',
timestamp: new Date(time + Math.random() * 1000).toISOString(),
type: 2,
block_id: blockId
}
let signBytes = Buffer.from(getVoteSignBytes(header.chain_id, precommit))
let pub = Buffer.from(validator.pub_key.value, 'base64')
let signature = ed25519.sign(signBytes, pub, validator.priv_key)
precommit.signature = {
type: 'tendermint/SignatureEd25519',
value: signature.toString('base64')
}
precommits.push(precommit)
}
return {
block_id: blockId,
precommits
}
}
sign (msg: string): string {
const message = new Buffer(sha3_256(msg));
return supercop.sign(message, this.publicKey, this.privateKey).toString("base64");
}
}
sign: buf => ed.sign(buf, this.keypair.publicKey, this.keypair.secretKey),
};
exports.sign = function(message, extendedPrivateKey) {
const privKey = extendedPrivateKey.getSecretKey() //extendedPrivateKey.substr(0, 128);
const pubKey = extendedPrivateKey.getPublicKey() //substr(128, 64);
const messageToSign = new Buffer(message, 'hex')
return ed25519
.sign(messageToSign, new Buffer(pubKey, 'hex'), new Buffer(privKey, 'hex'))
.toString('hex')
}
export function sign (opt: { publicKey: string, privateKey: string, message: string }): string {
const publicKey = new Buffer(opt.publicKey, "base64");
const privateKey = new Buffer(opt.privateKey, "base64");
const sha3Message = new Buffer(sha3_256(opt.message));
const sig = supercop.sign(
sha3Message,
publicKey,
privateKey
).toString("base64");
return sig;
}
function getSignature(req) {
return ed
.sign(
Buffer.isBuffer(req.body) ? req.body : Buffer.from(stringify(req.body)),
req.keypair.publicKey,
req.keypair.secretKey
)
.toString('base64')
}
expressApp.post('/sign', ensureKey, (req, res) => {
exports.sign = function(message, extendedPrivateKey) {
const privKey = extendedPrivateKey.getSecretKey() //extendedPrivateKey.substr(0, 128);
const pubKey = extendedPrivateKey.getPublicKey() //substr(128, 64);
const messageToSign = new Buffer(message, 'hex')
return ed25519
.sign(messageToSign, new Buffer(pubKey, 'hex'), new Buffer(privKey, 'hex'))
.toString('hex')
}