Skip to content

Commit

Permalink
chore: moving docs repo into the monorepo (#848)
Browse files Browse the repository at this point in the history
Co-authored-by: isk <0xisk>
  • Loading branch information
0xisk authored Sep 11, 2023
1 parent 29b211b commit 5fc7090
Show file tree
Hide file tree
Showing 20 changed files with 669 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy
name: Deploy demo
on:
push:
branches: [main]
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/deployDocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy docs
on:
push:
branches: [main]
paths:
- "docs/**"

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 'latest'

- name: Setup Pages
id: pages
uses: actions/configure-pages@v3

- name: Change to Docs Directory
run: cd docs

- name: Build with mdBook
run: mdbook build

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./book

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
29 changes: 29 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
description: (formerly ZK Keeper)
---

# 👋 Welcome to CryptKeeper

## Quick links

{% content-ref url="what-is-cryptkeeper/overview.md" %}
[overview.md](what-is-cryptkeeper/overview.md)
{% endcontent-ref %}

{% content-ref url="what-is-cryptkeeper/features.md" %}
[features.md](what-is-cryptkeeper/features.md)
{% endcontent-ref %}

{% embed url="https://github.com/privacy-scaling-explorations/crypt-keeper-extension" %}

## Guides

We've put together some helpful guides for you to get setup quickly and easily.

{% content-ref url="guides/quick-setup.md" %}
[quick-setup.md](guides/quick-setup.md)
{% endcontent-ref %}

{% content-ref url="guides/integrating-cryptkeeper/" %}
[integrating-cryptkeeper](guides/integrating-cryptkeeper/)
{% endcontent-ref %}
23 changes: 23 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Table of contents

* [👋 Welcome to CryptKeeper](README.md)

## What is CryptKeeper?

* [💡 Overview](what-is-cryptkeeper/overview.md)
* [✨ Features](what-is-cryptkeeper/features.md)

## Guides

* [🛠 Quick setup](guides/quick-setup.md)
* [🧱 Integrating CryptKeeper](guides/integrating-cryptkeeper/README.md)
* [🔌 Connect to extension](guides/integrating-cryptkeeper/connect-to-extension.md)
* [🎯 Inject client](guides/integrating-cryptkeeper/inject-client.md)
* [🆔 Create identity](guides/integrating-cryptkeeper/create-identity.md)
* [⚡ Generate proof](guides/integrating-cryptkeeper/generate-proof.md)
* [🐰 Zkitter examples](guides/integrating-cryptkeeper/zkitter-examples.md)

## References

* [📘 Terms](references/terms.md)
* [🤔 FAQ](references/faq.md)
9 changes: 9 additions & 0 deletions docs/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[book]
authors = ["AtHeartEngineer", "0xIsk", "0xmad"]
language = "en"
multilingual = false
src = "src"
title = "CryptKeeper Documentation"

[build]
create-missing = true
16 changes: 16 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Summary

- [Cryptkeeper](cryptkeeper/_intro.md)
- [Features](cryptkeeper/features.md)
- [Overview](cryptkeeper/overview.md)
- [Guides](guides/_intro.md)
- [Contributing](guides/contributing.md)
- [Integration](guides/integration/_intro.md)
- [Connect to Extension](guides/integration/connect-to-extension.md)
- [Create Identity](guides/integration/create-identity.md)
- [Generate Proof](guides/integration/generate-proof.md)
- [Inject Client](guides/integration/inject-client.md)
- [Zkitter Examples](guides/integration/zkitter-examples.md)
- [References](references/_intro.md)
- [Faq](references/faq.md)
- [Terms](references/terms.md)
3 changes: 3 additions & 0 deletions docs/src/cryptkeeper/_intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CryptKeeper

Welcome to CryptKeeper, a simple, easy to use, and secure zk identity manager
12 changes: 12 additions & 0 deletions docs/src/cryptkeeper/features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ✨ Features

The following features are supported currently:

* Identity secret and Identity commitment generation
* Semaphore ZK-Proof generation
* RLN ZK-Proof generation

Proof generation is enabled in two ways:

* by providing Merkle witness (Merkle tree components) directly as a [structured input](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/817ec0e1f336ab61c9c70f4918853e7c279dd21d/src/types/index.ts#L56):&#x20;
* by providing a secure service (i.e. smart contract) address from which the Merkle witness should be obtained
9 changes: 9 additions & 0 deletions docs/src/cryptkeeper/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 💡 Overview

CryptKeeper is a browser extension for managing zero-knowledge identities. It securely separates ZK identity and ZK proof generation from the application layer. Specifically, it manages identities created using the [Semaphore](https://semaphore.appliedzkp.org/) protocol and allows proof generation from [RLN](https://github.com/Rate-Limiting-Nullifier/) and Semaphore.

&#x20;This plugin is still in development and uses the [zk-kit library](https://github.com/appliedzkp/zk-kit).

## Video overview

{% embed url="https://www.youtube.com/watch?index=16&list=PLV91V4b0yVqRQ62Mv0nUgWxJhi4E67XSY&v=F5ic66_eNAs" %}
1 change: 1 addition & 0 deletions docs/src/guides/_intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Guides
7 changes: 7 additions & 0 deletions docs/src/guides/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 🛠 Quick setup

## Development

1. Install the necessary packages by running the command `npm install` in your terminal.
2. Start the development server by running the command `npm run dev`
3. In your browser, navigate to the extensions settings and load the `dist` directory as an unpacked extension.
1 change: 1 addition & 0 deletions docs/src/guides/integration/_intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Integrations
41 changes: 41 additions & 0 deletions docs/src/guides/integration/connect-to-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 🔌 Connect to extension

## Connect to extension

Use `zkpr.connect` to access the extension.

Initialize the `zkpr.connect` function, which returns a promise that resolves to the client object.

&#x20;Once you have the client object, you can use it to make RPC calls to the extension.

&#x20;[@src/contentscripts/injected.ts](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/master/src/contentscripts/injected.ts)

```typescript
async function connect() {
let result
try {
const approved = await tryInject(window.location.origin)

if (approved) {
await addHost(window.location.origin)
result = client
}
} catch (err) {
// eslint-disable-next-line no-console
console.log('Err: ', err)
result = null
}

await post({ method: RPCAction.CLOSE_POPUP })

return result
}

declare global {
interface Window {
zkpr: {
connect: () => any
}
}
}// Some code
```
59 changes: 59 additions & 0 deletions docs/src/guides/integration/create-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 🆔 Create identity

By default, CryptKeeper uses MetaMask to create a new Semaphore Identity \[link].

1. In MetaMask, a user signs a message with the private key of their Ethereum account.
2. In your dapp, the user creates a deterministic identity \[link] with the signed message.
3. The user can now recreate their Semaphore identity whenever they want by signing the same message with their Ethereum account in Metamask.

Semaphore identities can also be created using other data (such as web2 reputations from [Interep](https://interep.link/)) or using random numbers.

[@src/background/zk-keeper.ts](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/master/src/background/zk-keeper.ts)

```typescript
this.add(
RPCAction.CREATE_IDENTITY,
LockService.ensure,
async (payload: NewIdentityRequest) => {
try {
const { strategy, messageSignature, options } = payload
if (!strategy) throw new Error('strategy not provided')

const numOfIdentites = await this.identityService.getNumOfIdentites()
const config: any = {
...options,
name: options?.name || `Account # ${numOfIdentites}`
}

if (strategy === 'interrep') {
console.log("CREATE_IDENTITY: 1")
config.messageSignature = messageSignature;
console.log("CREATE_IDENTITY: 2")
}

const identity: ZkIdentityWrapper | undefined = await identityFactory(strategy, config)
console.log("CREATE_IDENTITY: 4", identity);

if (!identity) {
throw new Error('Identity not created, make sure to check strategy')
}

await this.identityService.insert(identity)

return true
} catch (error: any) {
console.log("CREATE_IDENTITY: Error", error);
throw new Error(error.message)
}
}
)
```

&#x20;

1. Import the `ZkKeeperController` class and initialize an instance of it.
2. Use the `RPCAction.CREATE_IDENTITY` method, which is a function provided by the `ZkKeeperController` class, and pass in the necessary parameters as the payload. The payload should include a `strategy`, `messageSignature`, and `options` object.
3. The `strategy` parameter is a string that specifies the type of identity you want to create.
4. The `messageSignature` parameter is a string that is the signature of some message that is used to verify the authenticity of the client.
5. The `options` object contains additional options for creating the identity including an `identityName` field which is a string that sets the name of the newly created identity.
6. The function returns a promise that resolves to the new identity's commitment. Once the identity is created, it can be used to generate ZK proofs
70 changes: 70 additions & 0 deletions docs/src/guides/integration/generate-proof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ⚡ Generate proof

CryptKeeper lets dapps outsource ZK proof generation via the Semaphore and RLN protocols. This section will review Semaphore proofs.

&#x20;[@src/contentscripts/injected.ts](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/master/src/contentscripts/injected.ts)

```typescript
async function semaphoreProof(
externalNullifier: string,
signal: string,
circuitFilePath: string,
zkeyFilePath: string,
merkleProofArtifactsOrStorageAddress: string | MerkleProofArtifacts,
merkleProof?: MerkleProof
) {
```
&#x20;The `semaphoreProof` function allows the user to create a proof of a signal to be sent to the Semaphore contract. CryptKeeper uses values provided by the dapp and the private user values to generate the proof and returns it to the dapp for verification. &#x20;
Your dapp should pass in public values (`externalNullifier` and `signal`).
Any circuit files (`circuitFilePath` and `zkeyFilePath`) can be used, but ready-to-use and audited circuit files can be found [here](http://www.trusted-setup-pse.org/) and [here](https://drive.google.com/file/d/1Yi14jwly70VwMSuqJrPCc3j15MWeE7mc/view?usp=sharing).
Merkle witness or Merkle tree components (`merkleProofArtifactsOrStorageAddress` can be provided by a smart contract or as a structured input:&#x20;
* `StorageAddress` points to a Merkle tree on-chain
* `merkleProofArtifact` is a Merkle tree in a specific format
* [@src/types/index.ts](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/817ec0e1f336ab61c9c70f4918853e7c279dd21d/src/types/index.ts#L56)
* ```typescript
export type MerkleProofArtifacts = {
leaves: string[]
depth: number
leavesPerNode: number
}
```
`SemaphoreProof` requires the following arguments:
`externalNullifier`
* a unique identifier for the signal to prevent double signaling
* public input provided by dapp
`signal`
* hash of the content of the message
* public input provided by dapp
`circuitFilePath`
* location of the circuit file
* used to generate the ZK proof in the browser
`zkeyFilePath`
* the zkeyFile contains the trusted setup \[link] files and is the starting point for creating a circuit
* location of the zkey file
`merkleProofArtifactsOrStorageAddress`
* object providing Merkle witness <mark style="color:blue;"></mark> directly (`merkleProofArtifact`) or the secure service address from which the Merkle witness should be obtained (`merkleStorageAddress`)&#x20;
* To generate a proof, a user must provide the Merkle path that leads to the user’s identity in the Merkle tree&#x20;
&#x20;
**RLN Proofs**
[RLN (Rate-Limiting Nullifier)](https://rate-limiting-nullifier.github.io/rln-docs/) is a ZK gadget or mechanism that enables spam prevention for anonymous environments. RLN Proofs are the same as Semaphore proofs except they generate proofs for a specific epoch (time period) and require an additional argument: `rlnIdentifier`.
45 changes: 45 additions & 0 deletions docs/src/guides/integration/inject-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 🎯 Inject client

CryptKeeper injects an object called `zkpr` into the browser. This is similar to how

MetaMask injects a [global API](https://docs.metamask.io/guide/ethereum-provider.html#ethereum-provider-api) into websites visited by its users at `window.ethereum` (formerly [window.web3](https://docs.metamask.io/guide/provider-migration.html#replacing-window-web3))

The injected client serves as bridge between frontend and backend processes. It is passed into the web page by the extension through an API allows the web page to make calls to CryptKeeper. From here you can manually generate and verify proofs, create identities, and set permissions.

You should be able to access the injected client’s functions and permissions once connected:

* `getIdentityCommitments`: Retrieves the commitments of the current identity.
* `getActiveIdentity`: Retrieves the currently active identity.
* `getHostPermissions`: Retrieves the permissions for the specified host.
* `setHostPermissions`: Sets the permissions for the specified host.
* `createIdentity`: Creates a new identity and returns the result.
* `createDummyRequest`: Creates a dummy request and returns the result.
* `semaphoreProof`: Sends a Semaphore proof request and returns the result.
* `rlnProof`: Sends a RLN proof request and returns the result.
* `clearApproved`: Clears the approved list of requests.
* `getApproved`: Retrieves the approved list of requests.
* `openPopup`: Opens the extension's popup window.
* `closePopup`: Closes the extension's popup window.
* `post`: Sends a request to the extension and returns the result.

[@src/contentscripts/injected.ts](https://github.com/privacy-scaling-explorations/crypt-keeper-extension/blob/817ec0e1f336ab61c9c70f4918853e7c279dd21d/src/contentscripts/injected.ts)

```typescript
const client = {
openPopup,
getIdentityCommitments,
getActiveIdentity,
createIdentity,
getHostPermissions,
setHostPermissions,
semaphoreProof,
rlnProof,
on,
off,
// dev-only
clearApproved,
createDummyRequest
}

```

Loading

0 comments on commit 5fc7090

Please sign in to comment.