Skip to content

Commit

Permalink
Merge pull request #75 from Rate-Limiting-Nullifier/types/export
Browse files Browse the repository at this point in the history
Update Type Exports
  • Loading branch information
mhchia authored Jun 26, 2023
2 parents 90705af + f7c55f5 commit 30eda57
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 53 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "rlnjs",
"version": "3.1.0",
"version": "3.1.1",
"description": "Client library for generating and using RLN ZK proofs.",
"license": "MIT",
"repository": "https://github.com/Rate-Limiting-Nullifier/rlnjs",
"homepage": "https://github.com/Rate-Limiting-Nullifier/rlnjs",
"author": {
"name": "AtHeartEngineer",
"email": "atheartengineer@gmail.com"
},
"contributors": [
{
"name": "AtHeartEngineer"
},
{
"name": "Mai-Hsuan (Kevin) Chia"
},
Expand Down Expand Up @@ -98,4 +97,4 @@
"tslib": "^2.5.0",
"typescript": "^4.9.5"
}
}
}
82 changes: 39 additions & 43 deletions src/circuit-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import { calculateExternalNullifier } from './common'
/**
* Public signals of the SNARK proof.
*/
type RLNPublicSignals = {
x: StrBigInt,
externalNullifier: StrBigInt,
y: StrBigInt,
root: StrBigInt,
nullifier: StrBigInt,
export type RLNPublicSignals = {
x: StrBigInt;
externalNullifier: StrBigInt;
y: StrBigInt;
root: StrBigInt;
nullifier: StrBigInt;
}

/**
* SNARK proof that contains both proof and public signals.
* Can be verified directly by a SNARK verifier.
*/
type RLNSNARKProof = {
proof: Proof
publicSignals: RLNPublicSignals
export type RLNSNARKProof = {
proof: Proof;
publicSignals: RLNPublicSignals;
}

/**
Expand All @@ -31,23 +31,23 @@ type RLNSNARKProof = {
* and the snarkProof is valid.
*/
export type RLNFullProof = {
snarkProof: RLNSNARKProof
epoch: bigint
rlnIdentifier: bigint
snarkProof: RLNSNARKProof;
epoch: bigint;
rlnIdentifier: bigint;
}

/**
* RLN witness that contains all the inputs needed for proof generation.
*/
type RLNWitness = {
identitySecret: bigint,
userMessageLimit: bigint,
messageId: bigint,
export type RLNWitness = {
identitySecret: bigint;
userMessageLimit: bigint;
messageId: bigint;
// Ignore `no-explicit-any` because the type of `identity_path_elements` in zk-kit is `any[]`
pathElements: any[], // eslint-disable-line @typescript-eslint/no-explicit-any
identityPathIndex: number[],
x: string | bigint,
externalNullifier: bigint,
pathElements: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any
identityPathIndex: number[];
x: string | bigint;
externalNullifier: bigint;
}

/**
Expand All @@ -74,12 +74,12 @@ export class RLNProver {
* @returns The full SnarkJS proof.
*/
public async generateProof(args: {
identitySecret: bigint,
userMessageLimit: bigint,
messageId: bigint,
merkleProof: MerkleProof,
x: bigint,
epoch: bigint,
identitySecret: bigint;
userMessageLimit: bigint;
messageId: bigint;
merkleProof: MerkleProof;
x: bigint;
epoch: bigint;
}): Promise<RLNFullProof> {
const witness: RLNWitness = {
identitySecret: args.identitySecret,
Expand Down Expand Up @@ -130,11 +130,11 @@ export class RLNVerifier {
}

/**
* Verifies a RLN full proof.
* @param fullProof The SnarkJS full proof.
* @returns True if the proof is valid, false otherwise.
* @throws Error if the proof is using different parameters.
*/
* Verifies a RLN full proof.
* @param fullProof The SnarkJS full proof.
* @returns True if the proof is valid, false otherwise.
* @throws Error if the proof is using different parameters.
*/
public async verifyProof(rlnRullProof: RLNFullProof): Promise<boolean> {
const expectedExternalNullifier = calculateExternalNullifier(
BigInt(rlnRullProof.epoch),
Expand All @@ -144,8 +144,8 @@ export class RLNVerifier {
if (expectedExternalNullifier !== BigInt(actualExternalNullifier)) {
throw new Error(
`External nullifier does not match: expectedExternalNullifier=${expectedExternalNullifier}, ` +
`actualExternalNullifier=${actualExternalNullifier}, epoch=${rlnRullProof.epoch}, ` +
`this.rlnIdentifier=${this.rlnIdentifier}`,
`actualExternalNullifier=${actualExternalNullifier}, epoch=${rlnRullProof.epoch}, ` +
`this.rlnIdentifier=${this.rlnIdentifier}`,
)
}

Expand All @@ -165,8 +165,8 @@ export class RLNVerifier {
}

type SNARKProof = {
proof: Proof
publicSignals: StrBigInt[]
proof: Proof;
publicSignals: StrBigInt[];
}

/**
Expand All @@ -182,13 +182,13 @@ export class WithdrawProver {
this.finalZkeyPath = finalZkeyPath
}

async generateProof(args: { identitySecret: bigint, address: bigint }): Promise<SNARKProof> {
return await groth16.fullProve(
async generateProof(args: { identitySecret: bigint; address: bigint }): Promise<SNARKProof> {
return (await groth16.fullProve(
args,
this.wasmFilePath,
this.finalZkeyPath,
null,
) as SNARKProof
)) as SNARKProof
}
}

Expand All @@ -204,10 +204,6 @@ export class WithdrawVerifier {
}

async verifyProof(proof: SNARKProof): Promise<boolean> {
return groth16.verify(
this.verificationKey,
proof.publicSignals,
proof.proof,
)
return groth16.verify(this.verificationKey, proof.publicSignals, proof.proof)
}
}
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Imports
export { IRLN, RLN } from './rln'
export { IRLNRegistry, ContractRLNRegistry } from './registry'
export { IRLNRegistry, ContractRLNRegistry } from './registry'
export { ICache, MemoryCache, CachedProof, Status } from './cache'
export { IMessageIDCounter } from './message-id-counter'

export * from './types'

export {
RLNFullProof,
} from './circuit-wrapper'
export { RLNFullProof, RLNSNARKProof, RLNWitness, RLNPublicSignals } from './circuit-wrapper'

0 comments on commit 30eda57

Please sign in to comment.