Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function privToScalar(privKey: Buffer): bigInt {
const h1 = createBlakeHash('blake512').update(privKey).digest();
const sBuff = eddsa.pruneBuffer(h1.slice(0, 32));
const scalar = (bigInt.leBuff2int(sBuff)).shr(3);
if (scalar >= babyJub.p) {
throw new Error('scalar generated larger than subgroup');
}
return scalar;
}
function compressPoint(pubKeyX: Buffer, pubKeyY: Buffer): Buffer {
const pubKeyXBigInt = utils.bufferToBigIntBE(pubKeyX);
if (pubKeyXBigInt.greater(babyJub.p.shr(1))) {
pubKeyY[0] |= 0x80;
}
return pubKeyY;
}
function checkElemFitsClaim(elem: Buffer) {
if (elem.length !== 32) {
throw new Error('Element is not 32 bytes length');
}
const elemBigInt = utils.bufferToBigIntBE(elem);
if (elemBigInt.greater(babyJub.p)) {
throw new Error('Element does not fit on claim element size');
}
}