diff --git a/package-lock.json b/package-lock.json index 6a0585e1..e6fbd4ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rlnjs", - "version": "2.0.5", + "version": "2.0.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rlnjs", - "version": "2.0.5", + "version": "2.0.6", "license": "MIT", "dependencies": { "@ethersproject/bytes": "^5.6.1", diff --git a/package.json b/package.json index de2b9bf0..fb9904e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rlnjs", - "version": "2.0.6", + "version": "2.0.7", "description": "Client library for generating and using RLN ZK proofs.", "license": "MIT", "repository": "https://github.com/Rate-Limiting-Nullifier/rlnjs", @@ -93,4 +93,4 @@ "tslib": "^2.5.0", "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/src/cache.ts b/src/cache.ts index 847d2241..fd335b03 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,12 +3,12 @@ import { RLNFullProof, StrBigInt } from './types' import RLN from './rln' import { isSameProof } from './utils' -type EpochCacheT = { - [nullifier: string]: RLNFullProof[]; +type EpochCache = { + [nullifier: string]: RLNFullProof[] } -type CacheT = { - [epoch: string]: EpochCacheT; +type CacheMap = { + [epoch: string]: EpochCache } export enum Status { @@ -32,7 +32,7 @@ export default class Cache { rlnIdentifier: bigint - cache: CacheT + cache: CacheMap epochs: string[] diff --git a/src/index.ts b/src/index.ts index 6d73e9f6..0f9fa31a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,4 +16,8 @@ export { RLNFullProof, Proof, RLNPublicSignals, + RLNSNARKProof, + VerificationKey, + RLNWitness, + CircuitParamsFilePath, } from './types' \ No newline at end of file diff --git a/src/rln.ts b/src/rln.ts index deb8226c..3cd63976 100644 --- a/src/rln.ts +++ b/src/rln.ts @@ -8,7 +8,7 @@ import poseidon from 'poseidon-lite' import { Identity } from '@semaphore-protocol/identity' // Types -import { RLNFullProof, RLNSNARKProof, RLNWitnessT, StrBigInt, VerificationKeyT } from './types' +import { RLNFullProof, RLNSNARKProof, RLNWitness, StrBigInt, VerificationKey } from './types' import { instantiateBn254, deserializeJSRLNProof, serializeJSRLNProof } from './waku' @@ -29,7 +29,7 @@ export default class RLN { finalZkeyPath: string - verificationKey: VerificationKeyT + verificationKey: VerificationKey rlnIdentifier: bigint @@ -39,7 +39,7 @@ export default class RLN { secretIdentity: bigint - constructor(wasmFilePath: string, finalZkeyPath: string, verificationKey: VerificationKeyT, rlnIdentifier?: bigint, identity?: string) { + constructor(wasmFilePath: string, finalZkeyPath: string, verificationKey: VerificationKey, rlnIdentifier?: bigint, identity?: string) { this.wasmFilePath = wasmFilePath this.finalZkeyPath = finalZkeyPath this.verificationKey = verificationKey @@ -75,7 +75,7 @@ export default class RLN { */ public async _genProof( epoch: bigint, - witness: RLNWitnessT, + witness: RLNWitness, ): Promise { const snarkProof: RLNSNARKProof = await RLN._genSNARKProof(witness, this.wasmFilePath, this.finalZkeyPath) return { @@ -93,7 +93,7 @@ export default class RLN { * @returns The full SnarkJS proof. */ public static async _genSNARKProof( - witness: RLNWitnessT, wasmFilePath: string, finalZkeyPath: string, + witness: RLNWitness, wasmFilePath: string, finalZkeyPath: string, ): Promise { const { proof, publicSignals } = await groth16.fullProve( witness, @@ -136,7 +136,7 @@ export default class RLN { * @param fullProof The SnarkJS full proof. * @returns True if the proof is valid, false otherwise. */ - public static async verifySNARKProof(verificationKey: VerificationKeyT, + public static async verifySNARKProof(verificationKey: VerificationKey, { proof, publicSignals }: RLNSNARKProof, ): Promise { return groth16.verify( @@ -165,7 +165,7 @@ export default class RLN { epoch: StrBigInt, signal: string, shouldHash = true, - ): RLNWitnessT { + ): RLNWitness { return { identitySecret: this.secretIdentity, pathElements: merkleProof.siblings, diff --git a/src/types.ts b/src/types.ts index fcd35508..b0367b7d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -42,8 +42,7 @@ export type RLNFullProof = { rlnIdentifier: bigint } - -export type VerificationKeyT = { +export type VerificationKey = { protocol: string, curve: string, nPublic: number, @@ -55,8 +54,7 @@ export type VerificationKeyT = { IC: string[][], } - -export type RLNWitnessT = { +export type RLNWitness = { identitySecret: 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 @@ -65,8 +63,7 @@ export type RLNWitnessT = { externalNullifier: bigint, } - -export type CircuitParamsFilePathT = { +export type CircuitParamsFilePath = { vkeyPath: string, wasmFilePath: string, finalZkeyPath: string, diff --git a/src/utils.ts b/src/utils.ts index 50973852..5c8729e9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import { ZqField } from 'ffjavascript' -import { RLNFullProof, VerificationKeyT } from './types' +import { RLNFullProof, VerificationKey } from './types' /* This is the "Baby Jubjub" curve described here: @@ -23,7 +23,7 @@ export function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array { } -export function parseVerificationKeyJSON(json: string): VerificationKeyT { +export function parseVerificationKeyJSON(json: string): VerificationKey { const o = JSON.parse(json) // NOTE: This is not a complete check, to do better we can check values are of the correct type if (!o.protocol) throw new Error('Verification key has no protocol') diff --git a/src/waku.ts b/src/waku.ts index 1d90422d..c6b7b97c 100644 --- a/src/waku.ts +++ b/src/waku.ts @@ -127,7 +127,7 @@ function deserializePointCompressed(curve: CurveT, bytesLE: Uint8Array, sizeComp if (bytesLE.length !== sizeCompressed) { throw new Error( 'bytes length is not equal to `sizeCompressed: ' + - `bytesLE.length=${bytesLE.length}, sizeCompressed=${sizeCompressed}`, + `bytesLE.length=${bytesLE.length}, sizeCompressed=${sizeCompressed}`, ) } if (!isCompressionValid(bytesLE)) { diff --git a/tests/configs.ts b/tests/configs.ts index 9d94ca67..ef58d69a 100644 --- a/tests/configs.ts +++ b/tests/configs.ts @@ -1,11 +1,11 @@ import * as path from "path" -import { CircuitParamsFilePathT } from "../src/types"; +import { CircuitParamsFilePath } from "../src/types" const thisFileDirname = __dirname -function getParamsPath(paramsDir: string): CircuitParamsFilePathT { +function getParamsPath(paramsDir: string): CircuitParamsFilePath { return { vkeyPath: path.join(paramsDir, "verification_key.json"), wasmFilePath: path.join(paramsDir, "rln.wasm"), @@ -14,8 +14,8 @@ function getParamsPath(paramsDir: string): CircuitParamsFilePathT { } -const defaultParamsDirname = path.join(thisFileDirname, "..", "zkeyFiles", "rln"); -const jsRLNParamsDirname = path.join(thisFileDirname, "..", "zkeyFiles", "js-rln"); +const defaultParamsDirname = path.join(thisFileDirname, "..", "zkeyFiles", "rln") +const jsRLNParamsDirname = path.join(thisFileDirname, "..", "zkeyFiles", "js-rln") export const defaultParamsPath = getParamsPath(defaultParamsDirname) export const jsRLNParamsPath = getParamsPath(jsRLNParamsDirname) diff --git a/tests/factories.ts b/tests/factories.ts index be7145f4..9106066d 100644 --- a/tests/factories.ts +++ b/tests/factories.ts @@ -1,12 +1,12 @@ -import * as fs from "fs"; -import { RLN } from "../src"; -import { CircuitParamsFilePathT } from "../src/types"; -import { Fq, parseVerificationKeyJSON } from "../src/utils"; -import { defaultParamsPath } from "./configs"; +import * as fs from "fs" +import { RLN } from "../src" +import { CircuitParamsFilePath } from "../src/types" +import { Fq, parseVerificationKeyJSON } from "../src/utils" +import { defaultParamsPath } from "./configs" -export function rlnInstanceFactory ( - paramsPath: CircuitParamsFilePathT = defaultParamsPath, +export function rlnInstanceFactory( + paramsPath: CircuitParamsFilePath = defaultParamsPath, rlnIdentifier?: bigint, identity?: string, ) {