diff --git a/packages/protocols/README.md b/packages/protocols/README.md index bfa3110..4a0a440 100644 --- a/packages/protocols/README.md +++ b/packages/protocols/README.md @@ -66,7 +66,7 @@ import { generateMerkleProof } from "@zk-kit/protocols" const depth = 20 const zeroValue = BigInt(0) -const arity = 5 +const arity = 2 const identity = new ZkIdentity() const identityCommitment = identity.genIdentityCommitment() const identityCommitments = [BigInt(1), identityCommitment, BigInt(2)] diff --git a/packages/protocols/src/semaphore.ts b/packages/protocols/src/semaphore.ts index d49d9f3..03e6bd7 100644 --- a/packages/protocols/src/semaphore.ts +++ b/packages/protocols/src/semaphore.ts @@ -24,12 +24,12 @@ export default class Semaphore extends ZkProtocol { shouldHash = true ): SemaphoreWitness { return { - identity_nullifier: identityNullifier, - identity_trapdoor: identityTrapdoor, - identity_path_index: merkleProof.pathIndices, - path_elements: merkleProof.siblings, - external_nullifier: externalNullifier, - signal_hash: shouldHash ? genSignalHash(signal) : signal + identityNullifier, + identityTrapdoor, + treePathIndices: merkleProof.pathIndices, + treeSiblings: merkleProof.siblings, + externalNullifier, + signalHash: shouldHash ? genSignalHash(signal) : signal } } diff --git a/packages/protocols/src/types/index.ts b/packages/protocols/src/types/index.ts index cedefa7..2d75845 100644 --- a/packages/protocols/src/types/index.ts +++ b/packages/protocols/src/types/index.ts @@ -16,10 +16,10 @@ export type FullProof = { export type SolidityProof = StrBigInt[] export type SemaphoreWitness = { - identity_nullifier: StrBigInt - identity_trapdoor: StrBigInt - path_elements: StrBigInt[] - identity_path_index: number[] - external_nullifier: StrBigInt - signal_hash: StrBigInt + identityNullifier: StrBigInt + identityTrapdoor: StrBigInt + treeSiblings: StrBigInt[] + treePathIndices: number[] + externalNullifier: StrBigInt + signalHash: StrBigInt } diff --git a/packages/protocols/src/utils.ts b/packages/protocols/src/utils.ts index 3b63c83..2ff9f6d 100644 --- a/packages/protocols/src/utils.ts +++ b/packages/protocols/src/utils.ts @@ -72,5 +72,12 @@ export function generateMerkleProof( throw new Error("The leaf does not exists") } - return tree.createProof(leafIndex) + const merkleProof = tree.createProof(leafIndex) + + if (arity === 2) { + // It makes it compatible with the parameter in the contracts. + merkleProof.siblings = merkleProof.siblings.map((s) => s[0]) + } + + return merkleProof } diff --git a/packages/protocols/tests/semaphore.test.ts b/packages/protocols/tests/semaphore.test.ts index 373a6dc..29f27ea 100644 --- a/packages/protocols/tests/semaphore.test.ts +++ b/packages/protocols/tests/semaphore.test.ts @@ -26,7 +26,7 @@ describe("Semaphore", () => { const leaves = [BigInt(3), BigInt(2), identityCommitment, BigInt(4)] const signal = "0x111" - const merkleProof = generateMerkleProof(20, BigInt(0), 5, leaves, identityCommitment) + const merkleProof = generateMerkleProof(20, BigInt(0), 2, leaves, identityCommitment) const witness = Semaphore.genWitness( identity.getTrapdoor(), @@ -47,7 +47,7 @@ describe("Semaphore", () => { const leaves = [BigInt(3), BigInt(2), identityCommitment, BigInt(4)] const signal = "0x111" - const merkleProof = generateMerkleProof(20, BigInt(0), 5, leaves, identityCommitment) + const merkleProof = generateMerkleProof(20, BigInt(0), 2, leaves, identityCommitment) const witness = Semaphore.genWitness( identity.getTrapdoor(), diff --git a/packages/protocols/zkeyFiles.zip.REMOVED.git-id b/packages/protocols/zkeyFiles.zip.REMOVED.git-id index a3a7d2f..e8f0da3 100644 --- a/packages/protocols/zkeyFiles.zip.REMOVED.git-id +++ b/packages/protocols/zkeyFiles.zip.REMOVED.git-id @@ -1 +1 @@ -2daec67f953ad6155f56d4c0c16ac1b67eb97a94 \ No newline at end of file +83a3802ca5e94bb251704b767deab0b7202c3ecd \ No newline at end of file