Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (precommit == null) continue
if (!precommit.block_id.hash) continue
let validator = validatorsByAddress[precommit.validator_address]
// skip if this validator isn't in the set
// (we allow precommits from validators not in the set,
// because we sometimes check the commit against older
// validator sets)
if (!validator) continue
let signature = Buffer.from(precommit.signature, 'base64')
let signBytes = getVoteSignBytes(header.chain_id, precommit)
let pubKey = Buffer.from(validator.pub_key.value, 'base64')
if (!ed25519.verify(signature, signBytes, pubKey)) {
throw Error('Invalid precommit signature')
}
// count this validator's voting power
committedVotingPower += safeParseInt(validator.voting_power)
}
// sum all validators' voting power
let totalVotingPower = validators.reduce(
(sum, v) => sum + safeParseInt(v.voting_power), 0)
// JS numbers have no loss of precision up to 2^53, but we
// error at over 2^52 since we have to do arithmetic. apps
// should be able to keep voting power lower than this anyway
if (totalVotingPower > 2 ** 52) {
throw Error('Total voting power must be less than 2^52')
}
onSpend ({ pubkey, signature }, { sigHash }) {
// verify signature
if (!ed25519.verify(signature, sigHash, pubkey)) {
throw Error('Invalid signature')
}
}
}
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')
}
checkForKeys() {
if (!Settings.getValue('dht25519pub')) {
const keypair = ed.createKeyPair(ed.createSeed());
Settings.setValue('dht25519pub', keypair.publicKey.toString('hex'));
Settings.setValue('dht25519priv', keypair.secretKey.toString('hex'));
Settings.save();
this.keypair = keypair;
return;
}
this.keypair = {
publicKey: Buffer.from(Settings.getValue('dht25519pub'), 'hex'),
secretKey: Buffer.from(Settings.getValue('dht25519priv'), 'hex'),
};
}