Merge pull request #61 from 0xtsukino/ensure-buffer

ensure leInt2Buff return Buffer
This commit is contained in:
Jordi Baylina 2021-09-24 17:13:05 +02:00 committed by GitHub
commit 32ce5475a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -23,6 +23,11 @@ exports.unpackSignature = unpackSignature;
exports.pruneBuffer = pruneBuffer;
function ensureBuffer(_buff) {
if (Buffer.isBuffer(_buff)) return buff;
return Buffer.from(_buff);
}
function pruneBuffer(_buff) {
const buff = Buffer.from(_buff);
buff[0] = buff[0] & 0xF8;
@ -66,7 +71,7 @@ function signMiMC(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));
const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);
@ -86,7 +91,7 @@ function signMiMCSponge(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));
const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);
@ -106,7 +111,7 @@ function signPoseidon(prv, msg) {
const s = utils.leBuff2int(sBuff);
const A = babyJub.mulPointEscalar(babyJub.Base8, Scalar.shr(s, 3));
const msgBuff = utils.leInt2Buff(msg, 32);
const msgBuff = ensureBuffer(utils.leInt2Buff(msg, 32));
const rBuff = createBlakeHash("blake512").update(Buffer.concat([h1.slice(32,64), msgBuff])).digest();
let r = utils.leBuff2int(rBuff);
const Fr = new F1Field(babyJub.subOrder);