Merge pull request #20 from appliedzkp/fix/tests

Fix/tests

Former-commit-id: 4aa9032c32bfc6b3125336b22a1bf49a7d4574d5 [formerly cb68f56c02e5ee45df692c3e24bc6c7a35fe0a0b] [formerly d50bd365978164196f2aede9b504430293352cf0 [formerly 5683ce1549c5532aada5ad1ad01cb8c29280b4df]] [formerly 4548d56cc3f7e81909638ecbd0f44626898f1e49 [formerly c79ecdcc9cc7dcf119b47826a4f8cf519038feba] [formerly e2ada685a7905cce09b2725492000f1d660af75e [formerly 4f54d842c5]]]
Former-commit-id: 461bdcd0590bc60e142230d25f10b74fa8b14d8e [formerly ce6e412722328eedc9652b1dd66f945f76a7c5c0] [formerly 43df39d27296f506064ae617c4b63021490d42f2 [formerly d0502d181477e10cd5b0117a0129e393395eecaf]]
Former-commit-id: 75adce660021bf84f98594fbe9aea88725b2b9e0 [formerly d4364969c8c1768ac72ae1d20458da869fa72e87]
Former-commit-id: ca8a9f2153c495d67303b354bd239afad9d85d43
This commit is contained in:
Omar Desogus
2022-02-23 12:09:59 +01:00
committed by GitHub
2 changed files with 5 additions and 26 deletions

View File

@@ -4,7 +4,6 @@ import * as fs from "fs"
import * as path from "path"
import { RLN } from "../src"
import { generateMerkleProof, genExternalNullifier, genSignalHash } from "../src/utils"
import { RLNPublicSignals } from "../src/types"
describe("RLN", () => {
const zkeyFiles = "./packages/protocols/zkeyFiles"
@@ -79,7 +78,7 @@ describe("RLN", () => {
})
// eslint-disable-next-line jest/no-disabled-tests
it.skip("Should generate rln proof and verify it", async () => {
it.skip("Should generate and verify RLN proof", async () => {
const identity = new ZkIdentity()
const secretHash = identity.getSecretHash()
const identityCommitment = identity.genIdentityCommitment()
@@ -88,23 +87,12 @@ describe("RLN", () => {
leaves.push(identityCommitment)
const signal = "hey hey"
const signalHash = genSignalHash(signal)
const epoch = genExternalNullifier("test-epoch")
const rlnIdentifier = RLN.genIdentifier()
const merkleProof = generateMerkleProof(15, BigInt(0), 2, leaves, identityCommitment)
const witness = RLN.genWitness(secretHash, merkleProof, epoch, signal, rlnIdentifier)
const [y, nullifier] = RLN.calculateOutput(secretHash, BigInt(epoch), rlnIdentifier, signalHash)
const publicSignals: RLNPublicSignals = {
yShare: y,
merkleRoot: merkleProof.root,
internalNullifier: nullifier,
signalHash,
epoch,
rlnIdentifier
}
const vkeyPath = path.join(zkeyFiles, "rln", "verification_key.json")
const vKey = JSON.parse(fs.readFileSync(vkeyPath, "utf-8"))
@@ -113,7 +101,7 @@ describe("RLN", () => {
const finalZkeyPath = path.join(zkeyFiles, "rln", "rln_final.zkey")
const fullProof = await RLN.genProof(witness, wasmFilePath, finalZkeyPath)
const response = await RLN.verifyProof(vKey, { proof: fullProof.proof, publicSignals })
const response = await RLN.verifyProof(vKey, fullProof )
expect(response).toBe(true)
}, 30000)

View File

@@ -3,8 +3,7 @@ import { getCurveFromName } from "ffjavascript"
import fs from "fs"
import path from "path"
import { Semaphore } from "../src"
import { SemaphorePublicSignals } from "../src/types"
import { generateMerkleProof, genExternalNullifier, genSignalHash } from "../src/utils"
import { generateMerkleProof, genExternalNullifier } from "../src/utils"
describe("Semaphore", () => {
const zkeyFiles = "./packages/protocols/zkeyFiles"
@@ -41,7 +40,7 @@ describe("Semaphore", () => {
})
// eslint-disable-next-line jest/no-disabled-tests
it.skip("Should generate Semaphore full proof", async () => {
it.skip("Should generate and verify Semaphore proof", async () => {
const identity = new ZkIdentity()
const identityCommitment = identity.genIdentityCommitment()
const externalNullifier = genExternalNullifier("voting_1")
@@ -64,16 +63,8 @@ describe("Semaphore", () => {
const vkeyPath = path.join("./packages/protocols/zkeyFiles", "semaphore", "verification_key.json")
const vKey = JSON.parse(fs.readFileSync(vkeyPath, "utf-8"))
const nullifierHash = Semaphore.genNullifierHash(externalNullifier, identity.getNullifier())
const publicSignals: SemaphorePublicSignals = {
merkleRoot: merkleProof.root.toString(),
nullifierHash,
signalHash: genSignalHash(signal),
externalNullifier
}
const response = await Semaphore.verifyProof(vKey, { proof: fullProof.proof, publicSignals })
const response = await Semaphore.verifyProof(vKey, fullProof)
expect(response).toBe(true)
}, 30000)