npm package: @stasiacarson/zk-diff
Description: Zero-knowledge proofs for code changes
Latest version: 1.2.3

# ZK-Diff

![npm version](https://img.shields.io/npm/v/@stasiacarson/zk-diff.svg)

ZK-Diff is a tool that uses zero-knowledge proofs to verify code changes in Git repositories. It creates cryptographic proofs that demonstrate the relationship between your codebase before and after changes, without revealing the actual code.

## Why Use ZK-Diff?

- **Verify Code Integrity**: Ensure that changes to your codebase are legitimate and follow expected patterns
- **Prove Changes Without Revealing Code**: Generate cryptographic proofs that verify the relationship between old and new code states without exposing the actual code
- **Git Integration**: Seamlessly integrates with your Git workflow through pre-commit hooks
- **Powered by Sindri**: Uses Sindri's zero-knowledge proof infrastructure for reliable and efficient proof generation

## Installation

### Global Installation (recommended for CLI usage)

```
# Install globally
npm install -g @stasiacarson/zk-diff

# If you encounter permission errors, you might need to use sudo
sudo npm install -g @stasiacarson/zk-diff
```

### Local Installation (for project-specific usage)

```
# Install as a development dependency in your project
npm install --save-dev @stasiacarson/zk-diff
```

## Getting Started

1. Initialize ZK-Diff in your Git repository

```
# If installed globally
zk-diff install

# If installed locally
npx zk-diff install
```

This will:

- Create a .env.local file for your Sindri API key
- Set up Git hooks to automatically generate proofs for commits on the main branch
- Configure the necessary zero-knowledge circuit

2. Provide your Sindri API key

During installation, you'll be prompted to enter your Sindri API key. You can get a free API key by signing up at sindri.app.

Alternatively, you can set the SINDRI_API_KEY environment variable before running the install command.

## How It Works

1. **Hashing**: ZK-Diff generates cryptographic hashes of your codebase before and after changes
2. **Diffing**: It computes the differences between the two states
3. **Proof Generation**: Using Sindri's zero-knowledge infrastructure, it creates a proof that the new codebase hash can be derived from the old hash and the diff hash
4. **Verification**: The proof can be verified without revealing the actual code

## Commands

### Install

```
zk-diff install
```

Sets up ZK-Diff in your Git repository.

### Hash

```
zk-diff hash <directory>
```

Generates a cryptographic hash of the specified directory.

### Diff

```
zk-diff diff <original-dir> <modified-dir>
```

Computes and hashes the differences between two directories.

### Verify

```
zk-diff verify <original-dir> <modified-dir>
```

Generates a zero-knowledge proof that verifies the relationship between the original and modified directories.

### Force Proof

```
zk-diff force-proof <original-dir> <modified-dir>
```

Similar to verify, but continues even if there's a hash mismatch.

## Git Integration

ZK-Diff automatically sets up a pre-commit hook that generates proofs for commits on the main branch. This ensures that all changes to your main branch are cryptographically verified.

## Requirements

- Node.js 14 or higher
- Git
- A Sindri API key

## Troubleshooting

### First Commit

If you're making the first commit in a repository, ZK-Diff will automatically skip the proof generation since there's no previous state to compare against.

### Permission Issues

If you encounter permission issues when installing or running ZK-Diff, try using sudo or follow the npm permission fix instructions:

```
sudo chown -R $(whoami) ~/.npm
```

## License

MIT

## Contributing

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

## Circuit Versioning

ZK-Diff uses Sindri's circuit tagging system to ensure you always have access to the latest circuit version. When you install ZK-Diff, it will:

1. Set up your environment to use the tagged circuit (`zk-code-diff-verifier:latest`)
2. Use this tag directly when generating proofs, which Sindri automatically resolves to the latest version

This means you'll always benefit from circuit improvements without needing to update your configuration or code.