-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from privacy-scaling-explorations/feat/eddsa-p…
…oseidon JS EdDSA Poseidon implementation
- Loading branch information
Showing
22 changed files
with
1,055 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Ethereum Foundation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<p align="center"> | ||
<h1 align="center"> | ||
EdDSA Poseidon | ||
</h1> | ||
<p align="center">A JavaScript EdDSA library for secure signing and verification using <a href="https://www.poseidon-hash.info">Poseidon</a> and the <a href="https://eips.ethereum.org/EIPS/eip-2494">Baby Jubjub</a> elliptic curve.</p> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/privacy-scaling-explorations/zk-kit"> | ||
<img src="https://img.shields.io/badge/project-zk--kit-blue.svg?style=flat-square"> | ||
</a> | ||
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/eddsa-poseidon/LICENSE"> | ||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40zk-kit%2Feddsa-poseidon?style=flat-square"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@zk-kit/eddsa-poseidon"> | ||
<img alt="NPM version" src="https://img.shields.io/npm/v/@zk-kit/eddsa-poseidon?style=flat-square" /> | ||
</a> | ||
<a href="https://npmjs.org/package/@zk-kit/eddsa-poseidon"> | ||
<img alt="Downloads" src="https://img.shields.io/npm/dm/@zk-kit/eddsa-poseidon.svg?style=flat-square" /> | ||
</a> | ||
<a href="https://bundlephobia.com/package/@zk-kit/eddsa-poseidon"> | ||
<img alt="npm bundle size (scoped)" src="https://img.shields.io/bundlephobia/minzip/@zk-kit/eddsa-poseidon" /> | ||
</a> | ||
<a href="https://eslint.org/"> | ||
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" /> | ||
</a> | ||
<a href="https://prettier.io/"> | ||
<img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier" /> | ||
</a> | ||
</p> | ||
|
||
<div align="center"> | ||
<h4> | ||
<a href="https://appliedzkp.org/discord"> | ||
🗣️ Chat & Support | ||
</a> | ||
<span> | </span> | ||
<a href="https://zkkit.pse.dev/modules/_zk_kit_eddsa_poseidon.html"> | ||
📘 Docs | ||
</a> | ||
</h4> | ||
</div> | ||
|
||
| This package offers a simplified JavaScript codebase essential for creating and validating digital signatures using EdDSA and Poseidon. It's built upon the Baby Jubjub elliptic curve, ensuring seamless integration with [Circom](https://github.com/iden3/circom) and enhancing the developer experience. | | ||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
|
||
- Super lightweight: [**~33kB**](https://bundlephobia.com/package/@zk-kit/eddsa-poseidon) (minified) | ||
- Compatible with browsers and NodeJS | ||
- TS type support | ||
- Comprehensive code [documentation](https://zkkit.pse.dev/modules/_zk_kit_eddsa_poseidon.html) | ||
- Full test coverage | ||
|
||
👾 Would you like to try it now? Explore it now on [Ceditor](https://ceditor.cedoor.dev/52787e4ad57d2f2076648d509efc3448)! | ||
|
||
> [!WARNING] | ||
> This library has **not** been audited. | ||
## 🛠 Install | ||
|
||
### npm or yarn | ||
|
||
Install the `@zk-kit/eddsa-poseidon` package and its peer dependencies with npm: | ||
|
||
```bash | ||
npm i @zk-kit/eddsa-poseidon | ||
``` | ||
|
||
or yarn: | ||
|
||
```bash | ||
yarn add @zk-kit/eddsa-poseidon | ||
``` | ||
|
||
### CDN | ||
|
||
You can also load it using a `script` tag using [unpkg](https://unpkg.com/): | ||
|
||
```html | ||
<script src="https://unpkg.com/@zk-kit/eddsa-poseidon"></script> | ||
``` | ||
|
||
or [JSDelivr](https://www.jsdelivr.com/): | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@zk-kit/eddsa-poseidon"></script> | ||
``` | ||
|
||
## 📜 Usage | ||
|
||
\# **derivePublicKey**(privateKey: _BigNumberish_): _Point\<string>_ | ||
|
||
```typescript | ||
import { derivePublicKey } from "@zk-kit/eddsa-poseidon" | ||
|
||
const privateKey = "secret" | ||
const publicKey = derivePublicKey(privateKey) | ||
|
||
console.log(publicKey) | ||
/* | ||
[ | ||
'17191193026255111087474416516591393721975640005415762645730433950079177536248', | ||
'13751717961795090314625781035919035073474308127816403910435238282697898234143' | ||
] | ||
*/ | ||
``` | ||
|
||
\# **signMessage**(privateKey: _BigNumberish_, message: _BigNumberish_): _Signature\<string>_ | ||
|
||
```typescript | ||
import { derivePublicKey, signMessage } from "@zk-kit/eddsa-poseidon" | ||
|
||
const privateKey = "secret" | ||
const publicKey = derivePublicKey(privateKey) | ||
|
||
const message = "message" | ||
const signature = signMessage(privateKey, message) | ||
|
||
console.log(signature) | ||
/* | ||
{ | ||
R8: [ | ||
'12949573675545142400102669657964360005184873166024880859462384824349649539693', | ||
'18253636630408169174294927826710424418689461166073329946402765380454102840608' | ||
], | ||
S: '701803947557694254685424075312408605924670918868054593580245088593184746870' | ||
} | ||
*/ | ||
``` | ||
|
||
\# **verifySignature**(message: _BigNumberish_, signature: _Signature_, publicKey: _Point_): _boolean_ | ||
|
||
```typescript | ||
import { derivePublicKey, signMessage, verifySignature } from "@zk-kit/eddsa-poseidon" | ||
|
||
const privateKey = "secret" | ||
const publicKey = derivePublicKey(privateKey) | ||
|
||
const message = "message" | ||
const signature = signMessage(privateKey, message) | ||
|
||
const response = verifySignature(message, signature, publicKey) | ||
|
||
console.log(response) // true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"declarationDir": "dist/types" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@zk-kit/eddsa-poseidon", | ||
"version": "0.2.0", | ||
"description": "A JavaScript EdDSA library for secure signing and verification using Poseidon the Baby Jubjub elliptic curve.", | ||
"license": "MIT", | ||
"iife": "dist/index.js", | ||
"unpkg": "dist/index.min.js", | ||
"jsdelivr": "dist/index.min.js", | ||
"main": "dist/index.node.js", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.node.js", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"types": "dist/types/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"src/", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"repository": "https://github.com/privacy-scaling-explorations/zk-kit", | ||
"homepage": "https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/eddsa-poseidon", | ||
"bugs": { | ||
"url": "https://github.com/privacy-scaling-explorations/zk-kit.git/issues" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript && yarn build:iife", | ||
"build:iife": "rollup -c rollup.iife.config.ts --configPlugin typescript", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"blake-hash": "2.0.0", | ||
"circomlibjs": "0.0.8", | ||
"poseidon-lite": "0.2.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-polyfill-node": "^0.13.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.31.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import commonjs from "@rollup/plugin-commonjs" | ||
import { nodeResolve } from "@rollup/plugin-node-resolve" | ||
import fs from "fs" | ||
import cleanup from "rollup-plugin-cleanup" | ||
import typescript from "rollup-plugin-typescript2" | ||
|
||
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")) | ||
const banner = `/** | ||
* @module ${pkg.name} | ||
* @version ${pkg.version} | ||
* @file ${pkg.description} | ||
* @copyright Ethereum Foundation ${new Date().getFullYear()} | ||
* @license ${pkg.license} | ||
* @see [Github]{@link ${pkg.homepage}} | ||
*/` | ||
|
||
export default { | ||
input: "src/index.ts", | ||
output: [ | ||
{ file: pkg.exports.require, format: "cjs", banner }, | ||
{ file: pkg.exports.import, format: "es", banner } | ||
], | ||
external: [], | ||
plugins: [ | ||
typescript({ tsconfig: "./build.tsconfig.json", useTsconfigDeclarationDir: true }), | ||
commonjs(), | ||
nodeResolve({ | ||
preferBuiltins: true | ||
}), | ||
cleanup({ comments: "jsdoc" }) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import commonjs from "@rollup/plugin-commonjs" | ||
import { nodeResolve } from "@rollup/plugin-node-resolve" | ||
import fs from "fs" | ||
import nodePolyfills from "rollup-plugin-polyfill-node" | ||
import cleanup from "rollup-plugin-cleanup" | ||
import { terser } from "rollup-plugin-terser" | ||
import typescript from "rollup-plugin-typescript2" | ||
|
||
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")) | ||
const banner = `/** | ||
* @module ${pkg.name} | ||
* @version ${pkg.version} | ||
* @file ${pkg.description} | ||
* @copyright Ethereum Foundation ${new Date().getFullYear()} | ||
* @license ${pkg.license} | ||
* @see [Github]{@link ${pkg.homepage}} | ||
*/` | ||
|
||
const name = pkg.name.split("/")[1].replace(/[-/]./g, (x: string) => x.toUpperCase()[1]) | ||
|
||
export default { | ||
input: "src/index.ts", | ||
output: [ | ||
{ | ||
file: pkg.iife, | ||
name, | ||
format: "iife", | ||
banner | ||
}, | ||
{ | ||
file: pkg.unpkg, | ||
name, | ||
format: "iife", | ||
plugins: [terser({ output: { preamble: banner } })] | ||
} | ||
], | ||
external: [], | ||
plugins: [ | ||
typescript({ tsconfig: "./build.tsconfig.json", useTsconfigDeclarationDir: true }), | ||
commonjs(), | ||
nodeResolve({ | ||
preferBuiltins: true | ||
}), | ||
nodePolyfills({ include: null }), | ||
cleanup({ comments: "jsdoc" }) | ||
] | ||
} |
Oops, something went wrong.