# Epoch Key And Proof

* An epoch key is the only way that a user can receive reputation.
* A user can generate an epoch key with a nonce, the nonce should be less than `numEpochKeyNoncePerEpoch`.
* A user generates the epoch key with a circom circuit and the epoch key and proof can be verified by attesters and other users.

## `genEpochKeyAndProof`

```
npx ts-node cli/index.ts genEpochKeyAndProof 
                  [-h] 
                  [-e ETH_PROVIDER] 
                  -id IDENTITY 
                  -n EPOCH_KEY_NONCE 
                  -x CONTRACT
```

* epoch key and base64url encoded epoch key proof and public signals will be printed
* A string with `Unirep.epk.proof` prefix is the proof of this epoch key
* A string with `Unirep.epk.publicSignals` prefix is the public signals of this proof The public signals includes
  * the current epoch
  * the epoch key
  * the global state tree root.
* Attesters and other users can verify if the epoch key is in the current epoch and if the user has a leaf in the global state tree.

### Options

```
  -e ETH_PROVIDER, --eth-provider ETH_PROVIDER
                        A connection string to an Ethereum provider. Default: http://localhost:8545
  -id IDENTITY, --identity IDENTITY
                        The (serialized) user's identity
  -n EPOCH_KEY_NONCE, --epoch-key-nonce EPOCH_KEY_NONCE
                        The epoch key nonce
  -x CONTRACT, --contract CONTRACT
                        The Unirep contract address
```

#### Options inherited from parent commands <a href="#options-inherited-from-parent-commands" id="options-inherited-from-parent-commands"></a>

```
  -h, --help            Show this help message and exit.
```

{% hint style="info" %}
source: [core/cli/genEpochKeyAndProof.ts](https://github.com/Unirep/Unirep/blob/main/packages/core/cli/genEpochKeyAndProof.ts)
{% endhint %}

## `verifyEpochKeyProof`

```
npx ts-node cli/index.ts verifyEpochKeyProof 
                  [-h] 
                  [-e ETH_PROVIDER] 
                  -p PUBLIC_SIGNALS 
                  -pf PROOF 
                  -x CONTRACT
```

* This command will help other users with an epoch key proof with `Unirep.epk.proof` prefix and it public signals with `Unirep.epk.publicSignals` prefix to call the Unirep smart contract to verify the proof.

### Options

```
  -e ETH_PROVIDER, --eth-provider ETH_PROVIDER
                        A connection string to an Ethereum provider. Default: http://localhost:8545
  -p PUBLIC_SIGNALS, --public-signals PUBLIC_SIGNALS
                        The snark public signals of the user's epoch key
  -pf PROOF, --proof PROOF
                        The snark proof of the user's epoch key
  -x CONTRACT, --contract CONTRACT
                        The Unirep contract address
```

#### Options inherited from parent commands <a href="#options-inherited-from-parent-commands" id="options-inherited-from-parent-commands"></a>

```
  -h, --help            Show this help message and exit.
```

{% hint style="info" %}
source: [core/cli/verifyEpochKeyProof.ts](https://github.com/Unirep/Unirep/blob/main/packages/core/cli/verifyEpochKeyProof.ts)
{% endhint %}

## `submitEpochKeyProof`

```
npx ts-node cli/index.ts submitEpochKeyProof 
                  [-h] 
                  [-e ETH_PROVIDER] 
                  -p PUBLIC_SIGNALS 
                  -pf PROOF 
                  -x CONTRACT 
                  -d ETH_PRIVKEY
```

* Epoch key proof should be submitted to UniRep and get the index of the proof.
* Then the attester can submit attestation to the epoch key with a valid proof index.
* Only if the epoch key proof is valid, the attestation can be processed.

### Options

```
  -e ETH_PROVIDER, --eth-provider ETH_PROVIDER
                        A connection string to an Ethereum provider. Default: http://localhost:8545
  -p PUBLIC_SIGNALS, --public-signals PUBLIC_SIGNALS
                        The snark public signals of the user's epoch key
  -pf PROOF, --proof PROOF
                        The snark proof of the user's epoch key
  -x CONTRACT, --contract CONTRACT
                        The Unirep contract address
  -d ETH_PRIVKEY, --eth-privkey ETH_PRIVKEY
                        The attester's Ethereum private key
```

#### Options inherited from parent commands <a href="#options-inherited-from-parent-commands" id="options-inherited-from-parent-commands"></a>

```
  -h, --help            Show this help message and exit.
```

{% hint style="info" %}
source: [core/cli/submitEpochKeyProof.ts](https://github.com/Unirep/Unirep/blob/main/packages/core/cli/submitEpochKeyProof.ts)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unirep.gitbook.io/unirep/package/cli/epoch-key-and-proof.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
