-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(utils)!: make snark-artifacts utility functions dynamic (#275)
* refactor(utils)!: make snark-artifacts utility functions dynamic re #272 * refactor(utils): use promise.all to fetch artifacts concurrently re #272 * refactor(utils): add more type checks to versions re #272 * refactor(utils): add list of supported snark-artifacts projects re #272 * refactor(utils): update project type re #272
- Loading branch information
Showing
14 changed files
with
158 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import F1Field from "./f1-field" | ||
import * as scalar from "./scalar" | ||
import * as conversions from "./conversions" | ||
import * as crypto from "./crypto/crypto.node" | ||
import * as errorHandlers from "./error-handlers" | ||
import F1Field from "./f1-field" | ||
import * as packing from "./proof-packing" | ||
import * as scalar from "./scalar" | ||
import maybeGetSnarkArtifacts from "./snark-artifacts/snark-artifacts.node" | ||
import * as typeChecks from "./type-checks" | ||
import * as errorHandlers from "./error-handlers" | ||
import * as crypto from "./crypto/crypto.node" | ||
|
||
export { F1Field, scalar, conversions, packing, typeChecks, errorHandlers, crypto } | ||
export * from "./types" | ||
export * from "./conversions" | ||
export * from "./error-handlers" | ||
export * from "./proof-packing" | ||
export * from "./type-checks" | ||
export * from "./error-handlers" | ||
export * from "./snark-artifacts/snark-artifacts.node" | ||
export * from "./types" | ||
export { F1Field, conversions, crypto, errorHandlers, maybeGetSnarkArtifacts, packing, scalar, typeChecks } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
enum Project { | ||
EDDSA = "eddsa", | ||
POSEIDON = "poseidon", | ||
SEMAPHORE = "semaphore" | ||
} | ||
|
||
export const projects = Object.values(Project) | ||
|
||
export default Project |
45 changes: 21 additions & 24 deletions
45
packages/utils/src/snark-artifacts/snark-artifacts.browser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
import { GetSnarkArtifactUrls } from "./config" | ||
import { Proof, SnarkArtifacts, Version } from "../types" | ||
import { BigNumber, SnarkArtifacts, Version } from "../types" | ||
import Project, { projects } from "./projects" | ||
|
||
function MaybeGetSnarkArtifacts(proof: Proof.EDDSA, version?: Version): () => Promise<SnarkArtifacts> | ||
function MaybeGetSnarkArtifacts( | ||
proof: Proof.POSEIDON, | ||
version?: Version | ||
): (numberOfInputs: number) => Promise<SnarkArtifacts> | ||
function MaybeGetSnarkArtifacts( | ||
proof: Proof.SEMAPHORE, | ||
version?: Version | ||
): (treeDepth: number) => Promise<SnarkArtifacts> | ||
function MaybeGetSnarkArtifacts(proof: Proof, version?: Version) { | ||
switch (proof) { | ||
case Proof.POSEIDON: | ||
return async (numberOfInputs: number) => GetSnarkArtifactUrls({ proof, numberOfInputs, version }) | ||
export default async function maybeGetSnarkArtifacts( | ||
project: Project, | ||
options: { | ||
parameters?: (BigNumber | number)[] | ||
version?: Version | ||
cdnUrl?: string | ||
} = {} | ||
): Promise<SnarkArtifacts> { | ||
if (!projects.includes(project)) { | ||
throw new Error(`Project '${project}' is not supported`) | ||
} | ||
|
||
case Proof.SEMAPHORE: | ||
return async (treeDepth: number) => GetSnarkArtifactUrls({ proof, treeDepth, version }) | ||
options.version ??= "latest" | ||
options.cdnUrl ??= "https://unpkg.com" | ||
|
||
case Proof.EDDSA: | ||
return async () => GetSnarkArtifactUrls({ proof, version }) | ||
const BASE_URL = `${options.cdnUrl}/@zk-kit/${project}-artifacts@${options.version}` | ||
const parameters = options.parameters ? `-${options.parameters.join("-")}` : "" | ||
|
||
default: | ||
throw new Error("Unknown proof type") | ||
return { | ||
wasm: `${BASE_URL}/${project}${parameters}.wasm`, | ||
zkey: `${BASE_URL}/${project}${parameters}.zkey` | ||
} | ||
} | ||
|
||
export const maybeGetPoseidonSnarkArtifacts = MaybeGetSnarkArtifacts(Proof.POSEIDON) | ||
export const maybeGetEdDSASnarkArtifacts = MaybeGetSnarkArtifacts(Proof.EDDSA) | ||
export const maybeGetSemaphoreSnarkArtifacts = MaybeGetSnarkArtifacts(Proof.SEMAPHORE) | ||
export { Project, projects } |
Oops, something went wrong.