npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@aintivirus-ai/snarkjs-to-solana

v1.0.3

Published

A comprehensive toolkit for converting snarkjs artifacts to Solana-compatible formats. This package provides both CLI tools and programmatic APIs for converting zero-knowledge proofs and verification keys from snarkjs to formats that work with Solana's gr

Readme

@aintivirus-ai/snarkjs-to-solana

A comprehensive toolkit for converting snarkjs artifacts to Solana-compatible formats. This package provides both CLI tools and programmatic APIs for converting zero-knowledge proofs and verification keys from snarkjs to formats that work with Solana's groth16 verifier.

Features

  • Triple-target WASM compilation: Optimized for web, bundler, and Node.js/CommonJS environments
  • CLI interface: Convert verification keys directly from the command line
  • Programmatic API: Integrate proof conversion into your applications
  • Automatic environment detection: Seamlessly works in Node.js, browsers, and bundlers
  • TypeScript support: Full type definitions included
  • CommonJS and ESM compatibility: Works with both module systems

Installation

Global Installation (Recommended for CLI usage)

npm install -g @aintivirus-ai/snarkjs-to-solana

Local Installation

npm install @aintivirus-ai/snarkjs-to-solana

If installed locally, you can run CLI commands using npx:

npx snarkjs-to-solana verification-key-to-rust verification_key.json

CLI Usage

Convert Verification Key to Rust

Convert a snarkjs verification key JSON file to a Rust file compatible with Solana's groth16 verifier.

Usage:

snarkjs-to-solana verification-key-to-rust <verification-key-path> [options]

Arguments:

  • <verification-key-path>: Path to the verification key JSON file generated by snarkjs

Options:

  • -o, --output <directory>: Output directory (defaults to current directory)
  • -h, --help: Display help for the command

Examples:

# Convert verification key to current directory
snarkjs-to-solana verification-key-to-rust verification_key.json

# Convert verification key to specific directory
snarkjs-to-solana verification-key-to-rust verification_key.json --output ./rust_files

# Short form
snarkjs-to-solana verification-key-to-rust verification_key.json -o ./rust_files

# Show help
snarkjs-to-solana verification-key-to-rust --help

Output: The command generates a verifying_key.rs file containing:

  • A Rust struct compatible with groth16_solana::groth16::Groth16Verifyingkey
  • All verification key parameters properly formatted for Solana
  • Ready-to-use constants for your Solana verification program

Programmatic Usage

Node.js / CommonJS Environment

// Works with both CommonJS (require) and ESM (import) in Node.js
const {
  getSolanaCompatibleProof,
} = require("@aintivirus-ai/snarkjs-to-solana");
// OR
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana";

// This automatically uses the Node.js-targeted WASM package (CommonJS compatible)
const result = await getSolanaCompatibleProof(proof);

Modern Bundler Environment (Webpack, Vite, etc.)

// In bundler environments like Webpack, Vite, Rollup, etc.
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana";

// This automatically uses the bundler-targeted WASM package
const result = await getSolanaCompatibleProof(proof);

Browser Environment

// In a browser environment, the package automatically uses the web-targeted WASM
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana";

// This automatically uses the web-targeted WASM package
const result = await getSolanaCompatibleProof(proof);

Manual Target Selection

// If you need to explicitly control which target to use:

// For bundler environments (Node.js, Webpack, Vite, etc.)
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana/dist/index.js";

// For web environments (browsers)
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana/dist/index.browser.js";

Complete Example

Here's a full example showing how to generate proofs with snarkjs and convert them for Solana:

import * as snarkjs from "snarkjs";
import { getSolanaCompatibleProof } from "@aintivirus-ai/snarkjs-to-solana";

// 1. Generate proof using snarkjs
const { proof: circuitProof, publicSignals } = await snarkjs.groth16.fullProve(
  circuitInputs,
  "../circom/ethDepositProof_js/ethDepositProof.wasm",
  "../circom/ethDepositProof_js/1_0000.zkey"
);

// 2. Convert proof to Solana-compatible format
const { proofA, proofB, proofC } = await getSolanaCompatibleProof(circuitProof);

// 3. Use proofA, proofB, proofC in your Solana on-chain instruction
// These can now be passed to your Solana program for verification

Integration with snarkjs Workflow

  1. Generate your circuit and verification key with snarkjs:

    snarkjs groth16 setup circuit.r1cs powersOfTau28_hez_final_10.ptau circuit_0000.zkey
    snarkjs zkey export verificationkey circuit_0000.zkey verification_key.json
  2. Convert verification key to Rust format:

    snarkjs-to-solana verification-key-to-rust verification_key.json
  3. Generate and convert proofs in your application:

    // Generate proof with snarkjs
    const { proof: circuitProof, publicSignals } =
      await snarkjs.groth16.fullProve(
        circuitInputs,
        "circuit.wasm",
        "circuit.zkey"
      );
    
    // Convert for Solana
    const { proofA, proofB, proofC } = await getSolanaCompatibleProof(
      circuitProof
    );
  4. Use in your Solana program:

    use groth16_solana::groth16::Groth16Verifyingkey;
    
    // Include the generated verification key file
    mod verifying_key;
    use verifying_key::VERIFYINGKEY;
    
    // Verify the proof on-chain
    groth16_solana::groth16::verify(&VERIFYINGKEY, &proof, &public_inputs)?;
  5. Call Solana on-chain instruction with converted proofs: The proofA, proofB, and proofC values from step 3 are passed to your Solana program instruction for on-chain verification.

How It Works

The package automatically detects the environment and loads the appropriate WASM target:

  • Bundler Target: Optimized for Node.js and bundler environments (Webpack, Vite, Rollup, etc.)
  • Web Target: Optimized for direct browser usage with proper ES6 module support

The conditional exports in package.json ensure that:

  • Modern bundlers get the bundler-optimized version
  • Browsers get the web-optimized version
  • The appropriate WASM files are loaded dynamically

Build Process

The package uses a dual-target build system:

  1. WASM Compilation: Rust code is compiled to two WASM targets using wasm-pack
  2. Unified Package: Both targets are combined into a single package structure
  3. Conditional Exports: Package.json exports map environments to appropriate entry points
  4. TypeScript Compilation: TypeScript code is compiled to JavaScript for both targets

Error Handling

The CLI provides clear error messages for common issues:

  • File not found: If the verification key file doesn't exist
  • Invalid JSON: If the verification key file is not valid JSON
  • Parse errors: If the verification key format is not compatible with ffjavascript
  • Permission errors: If the output directory cannot be written to

Troubleshooting

CommonJS/ESM Compatibility Issues

If you encounter module loading errors in Node.js:

// Try using require for CommonJS environments
const {
  getSolanaCompatibleProof,
} = require("@aintivirus-ai/snarkjs-to-solana");

// Or dynamic import for ESM environments
const { getSolanaCompatibleProof } = await import(
  "@aintivirus-ai/snarkjs-to-solana"
);

Command not found

If you get "command not found" error:

  1. Ensure the package is installed globally: npm install -g @aintivirus-ai/snarkjs-to-solana
  2. Or use with npx: npx @aintivirus-ai/snarkjs-to-solana

Permission denied

If you get permission errors:

  1. Check that you have write permissions to the output directory
  2. Try specifying a different output directory with -o

Invalid verification key format

Ensure your verification key was generated by snarkjs and follows the expected format:

{
  "vk_alpha_1": [...],
  "vk_beta_2": [...],
  "vk_gamma_2": [...],
  "vk_delta_2": [...],
  "IC": [...]
}

Package Structure

proof_utils/
├── pkg/
│   ├── web/           # Web-targeted WASM files
│   ├── bundler/       # Bundler-targeted WASM files
│   ├── index.js       # Main entry point (bundler)
│   ├── index-web.js   # Web entry point
│   └── package.json   # Unified package configuration
├── src/
│   ├── index.ts       # Main TypeScript entry (bundler)
│   └── index.browser.ts # Browser TypeScript entry (web)
└── dist/
    ├── index.js       # Compiled bundler version
    └── index.browser.js # Compiled web version

API Reference

getSolanaCompatibleProof(proof: any): Promise<object>

Converts a snarkjs proof to Solana-compatible format.

Parameters:

  • proof: A proof object generated by snarkjs

Returns:

  • Promise resolving to an object with proofA, proofB, and proofC properties

Dependencies

  • ffjavascript: For handling finite field arithmetic and proof parsing
  • commander: For CLI argument parsing
  • Custom WASM module for proof conversion

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Keywords

  • convert-snarkjs-proof
  • snarkjs-proof-convert
  • groth16-proof-convert
  • solana-verifier
  • verification-key-to-rust
  • cryptography
  • zero-knowledge
  • zk-proofs
  • blockchain