How to use the circomlib.mimcsponge.multiHash function in circomlib

To help you get started, we’ve selected a few circomlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
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
}
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
const mimcspongeHashOne = (preImage: SnarkBigInt): SnarkBigInt => {

    return mimcsponge.multiHash([preImage], 0, 1)
}
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
data: plaintext.map((e: SnarkBigInt, i: Number): SnarkBigInt => {
            return e + mimcsponge.multiHash(
                [sharedKey], 
                iv + snarkjs.bigInt(i),
                1,
            )
        }),
    }
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
(e: SnarkBigInt, i: Number): SnarkBigInt => {
            return e - mimcsponge.multiHash(
                [sharedKey],
                ciphertext.iv + snarkjs.bigInt(i),
                1,
            )
        }
    )
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
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
}
github barryWhiteHat / maci / boilerplate / crypto / ts / index.ts View on Github external
const hash = (plaintext: Plaintext): SnarkBigInt => {

    return mimcsponge.multiHash(plaintext, 0, 1)
}
github barryWhiteHat / maci / app / utils / crypto.js View on Github external
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)
}