Files
zk-kit/packages/protocols
Omar Desogus 0de41b1689 docs(readme): update @libsem/protocols readme
Former-commit-id: 4dbbd2eeb0408153c9e02e3901053fc4cf205b2e [formerly 9d1a1b8554]
Former-commit-id: b88e1c180ad193e20374d4ae4b8f306ea6ac2c3c
2021-10-21 10:55:54 +02:00
..
2021-10-18 19:43:40 +02:00
2021-10-20 13:25:28 +02:00
2021-10-19 02:35:51 +02:00
2021-10-19 17:16:41 +02:00

Semaphore protocols

Client library for generating and verifying Semaphore & Rln ZK proofs.

Github license NPM version Downloads npm bundle size (scoped) Linter eslint Code style prettier


🛠 Install

npm or yarn

Install the @libsem/protocols package with npm:

npm i @libsem/protocols

or yarn:

yarn add @libsem/protocols

📜 Usage

Import

import { ZkIdentity, Identity } from '@libsem/identity';
import { Semaphore, MerkleProof, IProof, generateMerkleProof, genExternalNullifier, genSignalHash } from '@libsem/protocols';



const { ZkIdentity } = require('@libsem/identity');
const { Semaphore, Rln, NRln, generateMerkleProof, genExternalNullifier, genSignalHash } = require('@libsem/protocols');

Merkle Proofs Generate merkle proof for your identity given the array of registered identity commitments

const identityCommitments: Array<bigint> = [...];
const identityCommitment: bigint = ZkIdentity.genIdentityCommitment(identity);

const merkleProof: MerkleProof = generateMerkleProof(TREE_DEPTH, ZERO_VALUE, NUMBER_OF_LEAVES_PER_NODE, identityCommitments, identityCommitment);

Semaphore

In order to create semaphore proof, make sure to

const witness = Semaphore.genWitness(identity, merkleProof, externalNullifier, signal);
const fullProof = await Semaphore.genProof(witness, wasmFilePath, finalZkeyPath);

Serialization

const identity: Identity = ZkIdentity.genIdentity();
const serialized: string = ZkIdentity.serializeIdentity(identity);
const unserialized: Identity = ZkIdentity.unSerializeIdentity(serialized);

📜 Final Note

For full examples of how to integrate with contracts check https://github.com/appliedzkp/semaphore repository.

For additional info check tests directory.