Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const encrypt = (
plaintext: Plaintext,
sharedKey: EcdhSharedKey,
): Ciphertext => {
// Generate the IV
const iv = mimcsponge.multiHash(plaintext, 0, 1)
const ciphertext: Ciphertext = {
iv,
data: plaintext.map((e: SnarkBigInt, i: Number): SnarkBigInt => {
return e + mimcsponge.multiHash(
[sharedKey],
iv + snarkjs.bigInt(i),
1,
)
}),
}
// TODO: add asserts here
return ciphertext
}
const mimcspongeHashOne = (preImage: SnarkBigInt): SnarkBigInt => {
return mimcsponge.multiHash([preImage], 0, 1)
}
data: plaintext.map((e: SnarkBigInt, i: Number): SnarkBigInt => {
return e + mimcsponge.multiHash(
[sharedKey],
iv + snarkjs.bigInt(i),
1,
)
}),
}
(e: SnarkBigInt, i: Number): SnarkBigInt => {
return e - mimcsponge.multiHash(
[sharedKey],
ciphertext.iv + snarkjs.bigInt(i),
1,
)
}
)
32
)
const rBuff = bigInt2Buffer(
mimcspongeHashOne(
buffer2BigInt(Buffer.concat(
[h1.slice(32, 64), msgBuff]
))
)
)
let r = snarkjs.bigInt.leBuff2int(rBuff)
r = r.mod(babyJub.subOrder)
const R8 = babyJub.mulPointEscalar(babyJub.Base8, r)
const hm = mimcsponge.multiHash([R8[0], R8[1], A[0], A[1], plaintext], 0, 1)
const S = r.add(hm.mul(s)).mod(babyJub.subOrder)
const signature: Signature = { R8, S }
return signature
}
const hash = (plaintext: Plaintext): SnarkBigInt => {
return mimcsponge.multiHash(plaintext, 0, 1)
}
const multiHash = (arr: Array, key: ?BigInt, outputs: ?number): BigInt => {
const ret = mimcsponge.multiHash(arr, key, outputs)
if (Array.isArray(ret)) {
return ret.map((x: Any): BigInt => bigInt(x))
}
return bigInt(ret)
}