How to use the circomlib.mimc7.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 / app / utils / generate_circuit_input.js View on Github external
const txHash = mimc7.multiHash(
  [tx.from[0], tx.from[1], BigInt(tx.detail), tx.updated_pubkey[0], tx.updated_pubkey[1]]
)
const signature = eddsa.signMiMC(alicePrvKey, txHash)

// update Alice account
const newAlice = {
  pubkey: tx.updated_pubkey,
  detail: BigInt(tx.detail)
}
const newAliceHash = mimc7.multiHash(
  [newAlice.pubkey[0], newAlice.pubkey[1], BigInt(newAlice.detail)]
)

// update root
const final_root = mimc7.multiHash([newAliceHash, bobHash])

// console.log('tree_root: ' + tree_root.toString())
// console.log('final_root: ' + final_root.toString())
// console.log('accounts_pubkeys Alice.pubkey[0]: ' + Alice.pubkey[0].toString())
// console.log('accounts_pubkeys Alice.pubkey[1]: ' + Alice.pubkey[1].toString())
// console.log('accounts_detail: ' + final_root.toString())
// console.log('sender_detail: ' + Alice.detail.toString())
// console.log('sender_updated_pubkey[0]: ' + newAlice.pubkey[0].toString())
// console.log('sender_updated_pubkey[1]: ' + newAlice.pubkey[1].toString())
// console.log('sender_updated_detail: ' + newAlice.detail.toString())
// console.log("signature['R8'][0]: " + signature.R8[0].toString())
// console.log("signature['R8'][1]: " + signature.R8[1].toString())
// console.log("signature['S']: " + signature.S.toString())
// console.log('aliceHash: ' + aliceHash.toString())
// console.log('bobHash: ' + bobHash.toString())
// console.log('newAliceHash: ' + newAliceHash.toString())
github barryWhiteHat / maci / app / interact.js View on Github external
console.log('Submitted initial message')

  // Wait 10 seconds
  console.log('Sleeping 10 seconds...')
  await sleep(10000)
  console.log('Woken up')

  // Construct 2nd message
  const userSecondMessage = [
    ...userPosition,
    ...userPubKey,
    1n // New position
  ]

  const userSecondMessageHash = mimc7.multiHash(userSecondMessage)

  const secondSignature: MiMicSignature = eddsa.signMiMC(
    userPrvKey.toString(),
    userSecondMessageHash
  )

  // Insert signature into tx
  const userSecondMessage2 = [
    ...userSecondMessage,
    secondSignature.R8[0],
    secondSignature.R8[1],
    secondSignature.S
  ]

  const userSecondEncryptedMessage = encrypt(
    userSecondMessage2,
github barryWhiteHat / maci / app / utils / generate_circuit_input.js View on Github external
detail: 0,
  updated_pubkey: Alice.pubkey
}

// Alice sign tx
const txHash = mimc7.multiHash(
  [tx.from[0], tx.from[1], BigInt(tx.detail), tx.updated_pubkey[0], tx.updated_pubkey[1]]
)
const signature = eddsa.signMiMC(alicePrvKey, txHash)

// update Alice account
const newAlice = {
  pubkey: tx.updated_pubkey,
  detail: BigInt(tx.detail)
}
const newAliceHash = mimc7.multiHash(
  [newAlice.pubkey[0], newAlice.pubkey[1], BigInt(newAlice.detail)]
)

// update root
const final_root = mimc7.multiHash([newAliceHash, bobHash])

// console.log('tree_root: ' + tree_root.toString())
// console.log('final_root: ' + final_root.toString())
// console.log('accounts_pubkeys Alice.pubkey[0]: ' + Alice.pubkey[0].toString())
// console.log('accounts_pubkeys Alice.pubkey[1]: ' + Alice.pubkey[1].toString())
// console.log('accounts_detail: ' + final_root.toString())
// console.log('sender_detail: ' + Alice.detail.toString())
// console.log('sender_updated_pubkey[0]: ' + newAlice.pubkey[0].toString())
// console.log('sender_updated_pubkey[1]: ' + newAlice.pubkey[1].toString())
// console.log('sender_updated_detail: ' + newAlice.detail.toString())
// console.log("signature['R8'][0]: " + signature.R8[0].toString())
github iden3 / iden3js / src / crypto / mimc7.js View on Github external
function multiHash(arr) {
  // TODO check bigints inside finite field
  return mimc7.multiHash(arr);
}
github barryWhiteHat / maci / app / utils / generate_circuit_input.js View on Github external
const { Circuit } = require('snarkjs')
const zkSnark = require('snarkjs').original
const { unstringifyBigInts } = require('snarkjs/src/stringifybigint')

const alicePrvKey = Buffer.from('1'.toString().padStart(64, '0'), 'hex')
const alicePubKey = eddsa.prv2pub(alicePrvKey)
const bobPrvKey = Buffer.from('2'.toString().padStart(64, '0'), 'hex')
const bobPubKey = eddsa.prv2pub(bobPrvKey)

// accounts (1 = Yes, 0 = No)
const Alice = {
  pubkey: alicePubKey,
  detail: 1
}

const aliceHash = mimc7.multiHash(
  [Alice.pubkey[0], Alice.pubkey[1], BigInt(Alice.detail)]
)

const Bob = {
  pubkey: bobPubKey,
  detail: 0
}
const bobHash = mimc7.multiHash(
  [Bob.pubkey[0], Bob.pubkey[1], BigInt(Bob.detail)]
)

const tree_root = mimc7.multiHash([aliceHash, bobHash])

// transaction
const tx = {
  from: Alice.pubkey,
github barryWhiteHat / maci / app / interact.js View on Github external
const main = async () => {
  const pk = stringifyBigInts(userPubKey)

  // First message (insert new user)
  const userPosition: Array = [
    ...userPubKey,
    0n // Action
  ]

  const userInitialMessage = [
    ...userPosition,
    0n, 0n, 0n
  ]

  const userMessageHash = mimc7.multiHash(userInitialMessage)

  const signature: MiMicSignature = eddsa.signMiMC(
    userPrvKey.toString(),
    userMessageHash
  )

  // Insert signature into tx
  const userInitialMessage2 = [
    ...userInitialMessage,
    signature.R8[0],
    signature.R8[1],
    signature.S
  ]

  const userInitialEncryptedMessage = encrypt(
    userInitialMessage2,
github barryWhiteHat / maci / app / utils / generate_circuit_input.js View on Github external
// accounts (1 = Yes, 0 = No)
const Alice = {
  pubkey: alicePubKey,
  detail: 1
}

const aliceHash = mimc7.multiHash(
  [Alice.pubkey[0], Alice.pubkey[1], BigInt(Alice.detail)]
)

const Bob = {
  pubkey: bobPubKey,
  detail: 0
}
const bobHash = mimc7.multiHash(
  [Bob.pubkey[0], Bob.pubkey[1], BigInt(Bob.detail)]
)

const tree_root = mimc7.multiHash([aliceHash, bobHash])

// transaction
const tx = {
  from: Alice.pubkey,
  detail: 0,
  updated_pubkey: Alice.pubkey
}

// Alice sign tx
const txHash = mimc7.multiHash(
  [tx.from[0], tx.from[1], BigInt(tx.detail), tx.updated_pubkey[0], tx.updated_pubkey[1]]
)
github barryWhiteHat / maci / app / utils / crypto.js View on Github external
const encrypt = (
  msg: Array,
  priv: BigInt,
  pub: Tuple
): Array => {
  // Encrypts a message
  const sharedKey = ecdh(priv, pub)
  const iv = mimc7.multiHash(msg, BigInt(0))
  return [
    iv, ...msg.map((e: BigInt, i: Number): BigInt => {
      return e + mimc7.hash(sharedKey, iv + bigInt(i))
    })
  ]
}
github barryWhiteHat / maci / app / utils / generate_circuit_input.js View on Github external
detail: 1
}

const aliceHash = mimc7.multiHash(
  [Alice.pubkey[0], Alice.pubkey[1], BigInt(Alice.detail)]
)

const Bob = {
  pubkey: bobPubKey,
  detail: 0
}
const bobHash = mimc7.multiHash(
  [Bob.pubkey[0], Bob.pubkey[1], BigInt(Bob.detail)]
)

const tree_root = mimc7.multiHash([aliceHash, bobHash])

// transaction
const tx = {
  from: Alice.pubkey,
  detail: 0,
  updated_pubkey: Alice.pubkey
}

// Alice sign tx
const txHash = mimc7.multiHash(
  [tx.from[0], tx.from[1], BigInt(tx.detail), tx.updated_pubkey[0], tx.updated_pubkey[1]]
)
const signature = eddsa.signMiMC(alicePrvKey, txHash)

// update Alice account
const newAlice = {