-
Notifications
You must be signed in to change notification settings - Fork 88
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 #109 from privacy-scaling-explorations/feat/baby-j…
…ubjub New packages: Baby Jubjub and Utils
- Loading branch information
Showing
40 changed files
with
860 additions
and
142 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
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,138 @@ | ||
<p align="center"> | ||
<h1 align="center"> | ||
Baby Jubjub | ||
</h1> | ||
<p align="center">A JavaScript library for adding points to the <a href="https://eips.ethereum.org/EIPS/eip-2494">Baby Jubjub</a> 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/baby-jubjub/LICENSE"> | ||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40zk-kit%2Fbaby-jubjub?style=flat-square"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@zk-kit/baby-jubjub"> | ||
<img alt="NPM version" src="https://img.shields.io/npm/v/@zk-kit/baby-jubjub?style=flat-square" /> | ||
</a> | ||
<a href="https://npmjs.org/package/@zk-kit/baby-jubjub"> | ||
<img alt="Downloads" src="https://img.shields.io/npm/dm/@zk-kit/baby-jubjub.svg?style=flat-square" /> | ||
</a> | ||
<a href="https://bundlephobia.com/package/@zk-kit/baby-jubjub"> | ||
<img alt="npm bundle size (scoped)" src="https://img.shields.io/bundlephobia/minzip/@zk-kit/baby-jubjub" /> | ||
</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_baby_jubjub.html"> | ||
📘 Docs | ||
</a> | ||
</h4> | ||
</div> | ||
|
||
> [!WARNING] | ||
> This library has **not** been audited. | ||
## 🛠 Install | ||
|
||
### npm or yarn | ||
|
||
Install the `@zk-kit/baby-jubjub` package and its peer dependencies with npm: | ||
|
||
```bash | ||
npm i @zk-kit/baby-jubjub | ||
``` | ||
|
||
or yarn: | ||
|
||
```bash | ||
yarn add @zk-kit/baby-jubjub | ||
``` | ||
|
||
### CDN | ||
|
||
You can also load it using a `script` tag using [unpkg](https://unpkg.com/): | ||
|
||
```html | ||
<script src="https://unpkg.com/@zk-kit/baby-jubjub"></script> | ||
``` | ||
|
||
or [JSDelivr](https://www.jsdelivr.com/): | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@zk-kit/baby-jubjub"></script> | ||
``` | ||
|
||
## 📜 Usage | ||
|
||
\# **addPoint**(p1: _Point\<bigint>_, p2: _Point\<bigint>_): _bigint_ | ||
|
||
```typescript | ||
import { addPoint } from "@zk-kit/baby-jubjub" | ||
|
||
const p1: Point<bigint> = [BigInt(0), BigInt(1)] | ||
|
||
const newPoint = addPoint(p1, Base8) | ||
``` | ||
|
||
\# **mulPointEscalar**(base: _Point\<bigint>_, e: _bigint_): _Point\<bigint>_ | ||
|
||
```typescript | ||
import { Base8, mulPointEscalar } from "@zk-kit/baby-jubjub" | ||
|
||
const secretScalar = BigInt(324) | ||
|
||
const publicKey = mulPointEscalar(Base8, secretScalar) | ||
``` | ||
|
||
\# **mulPointEscalar**(base: _Point\<bigint>_, e: _bigint_): _Point\<bigint>_ | ||
|
||
```typescript | ||
import { inCurve, Base8, mulPointEscalar } from "@zk-kit/baby-jubjub" | ||
|
||
const secretScalar = BigInt(324) | ||
|
||
const publicKey = mulPointEscalar(Base8, secretScalar) | ||
|
||
const isInCurve = inCurve(publicKey) | ||
``` | ||
|
||
\# **packPoint**(unpackedPoint: _Point\<bigint>_): _bigint_ | ||
|
||
```typescript | ||
import { packPoint, Base8, mulPointEscalar } from "@zk-kit/baby-jubjub" | ||
|
||
const secretScalar = BigInt(324) | ||
|
||
const publicKey = mulPointEscalar(Base8, secretScalar) | ||
|
||
const packedPoint = packPoint(publicKey) | ||
``` | ||
|
||
\# **unpackPoint**(packedPoint: _bigint_): _Point\<bigint>_ | _null_ | ||
|
||
```typescript | ||
import { packPoint, unpackPoint, Base8, mulPointEscalar } from "@zk-kit/baby-jubjub" | ||
|
||
const secretScalar = BigInt(324) | ||
|
||
const publicKey = mulPointEscalar(Base8, secretScalar) | ||
|
||
const packedPoint = packPoint(publicKey) | ||
|
||
const unpackedPoint = unpackPoint(packedPoint) | ||
|
||
console.log(publicKey[0] === unpackedPoint[0]) // true | ||
console.log(publicKey[1] === unpackedPoint[1]) // 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,47 @@ | ||
{ | ||
"name": "@zk-kit/baby-jubjub", | ||
"version": "0.1.0", | ||
"description": "A JavaScript library for adding points to the 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/baby-jubjub", | ||
"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", | ||
"circomlibjs": "0.0.8", | ||
"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" | ||
}, | ||
"dependencies": { | ||
"@zk-kit/utils": "0.1.0" | ||
} | ||
} |
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,26 @@ | ||
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: Object.keys(pkg.dependencies), | ||
plugins: [ | ||
typescript({ tsconfig: "./build.tsconfig.json", useTsconfigDeclarationDir: 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.