|
| 1 | +<p align="center"> |
| 2 | + <h1 align="center"> |
| 3 | + HeyAuthn |
| 4 | + </h1> |
| 5 | + <p align="center">A library to allow developers to create and manage Semaphore identities using WebAuthn.</p> |
| 6 | +</p> |
| 7 | + |
| 8 | +<p align="center"> |
| 9 | + <a href="https://github.com/semaphore-protocol"> |
| 10 | + <img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square"> |
| 11 | + </a> |
| 12 | + <a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE"> |
| 13 | + <img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square"> |
| 14 | + </a> |
| 15 | + <a href="https://www.npmjs.com/package/@semaphore-protocol/heyauthn"> |
| 16 | + <img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/heyauthn?style=flat-square" /> |
| 17 | + </a> |
| 18 | + <a href="https://npmjs.org/package/@semaphore-protocol/heyauthn"> |
| 19 | + <img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/heyauthn.svg?style=flat-square" /> |
| 20 | + </a> |
| 21 | + <a href="https://eslint.org/"> |
| 22 | + <img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" /> |
| 23 | + </a> |
| 24 | + <a href="https://prettier.io/"> |
| 25 | + <img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier" /> |
| 26 | + </a> |
| 27 | +</p> |
| 28 | + |
| 29 | +<div align="center"> |
| 30 | + <h4> |
| 31 | + <a href="https://github.com/semaphore-protocol/semaphore/blob/main/CONTRIBUTING.md"> |
| 32 | + 👥 Contributing |
| 33 | + </a> |
| 34 | + <span> | </span> |
| 35 | + <a href="https://github.com/semaphore-protocol/semaphore/blob/main/CODE_OF_CONDUCT.md"> |
| 36 | + 🤝 Code of conduct |
| 37 | + </a> |
| 38 | + <span> | </span> |
| 39 | + <a href="https://github.com/semaphore-protocol/semaphore/contribute"> |
| 40 | + 🔎 Issues |
| 41 | + </a> |
| 42 | + <span> | </span> |
| 43 | + <a href="https://semaphore.appliedzkp.org/discord"> |
| 44 | + 🗣️ Chat & Support |
| 45 | + </a> |
| 46 | + </h4> |
| 47 | +</div> |
| 48 | + |
| 49 | +| This library allows developers to create and manage Semaphore identities using [WebAuthn](https://webauthn.io/) as a cross-device biometric authentication in a way that is more convenient, smoother and secure than localStorage, Chrome extensions, or password manager based solutions. | |
| 50 | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 51 | + |
| 52 | +## 🛠 Install |
| 53 | + |
| 54 | +### npm or yarn |
| 55 | + |
| 56 | +Install the `@semaphore-protocol/heyauthn` package with npm: |
| 57 | + |
| 58 | +```bash |
| 59 | +npm i @semaphore-protocol/heyauthn |
| 60 | +``` |
| 61 | + |
| 62 | +or yarn: |
| 63 | + |
| 64 | +```bash |
| 65 | +yarn add @semaphore-protocol/heyauthn |
| 66 | +``` |
| 67 | + |
| 68 | +## 📜 Usage |
| 69 | + |
| 70 | +```typescript |
| 71 | +import { HeyAuthn } from "@semaphore-protocol/heyauthn" |
| 72 | + |
| 73 | +// STEP 1: Configure WebAuthn options. |
| 74 | + |
| 75 | +const options = { |
| 76 | + rpName: "my-app", |
| 77 | + rpID: window.location.hostname, |
| 78 | + userID: "my-id", |
| 79 | + userName: "my-name" |
| 80 | +} |
| 81 | + |
| 82 | +// STEP 2: Register a new WebAuthn credential and get its Semaphore identity. |
| 83 | + |
| 84 | +const { identity } = await HeyAuthn.fromRegister(options) |
| 85 | + |
| 86 | +// Now you could also save the identity commitment in your DB (pseudocode). |
| 87 | +fetch("/api/register" /* Replace this with your endpoint */, { |
| 88 | + identity.commmitment |
| 89 | + // ... |
| 90 | +}) |
| 91 | + |
| 92 | +// STEP 3: Authenticate existing WebAuthn credential and signal. |
| 93 | + |
| 94 | +const { identity } = await HeyAuthn.fromRegister(options) |
| 95 | + |
| 96 | +// Get existing group and signal anonymously (pseudocode). |
| 97 | +import { Group } from "@semaphore-protocol/group" |
| 98 | +import { generateProof } from "@semaphore-protocol/proof" |
| 99 | +import { utils } from "ethers" |
| 100 | + |
| 101 | +const group = new Group("42") |
| 102 | + |
| 103 | +group.addMembers(memberList) |
| 104 | + |
| 105 | +const signal = utils.formatBytes32String("Hey anon!") |
| 106 | + |
| 107 | +generateProof(identity, group, group.id, "42", { |
| 108 | + zkeyFilePath: "./semaphore.zkey", |
| 109 | + wasmFilePath: "./semaphore.wasm" |
| 110 | +}) |
| 111 | +``` |
0 commit comments