@zk-kit/poseidon-cipher
Advanced tools
Comparing version 0.2.1 to 0.3.0
export declare const two128: bigint; | ||
export declare const N_ROUNDS_F = 8; | ||
export declare const N_ROUNDS_P: number[]; |
export declare const C_RAW: string[][]; | ||
export declare const M_RAW: string[][][]; |
export * from "./utils"; | ||
export * from "./types"; | ||
export { poseidonEncrypt, poseidonDecrypt, poseidonDecryptWithoutCheck } from "./poseidonCipher"; |
@@ -0,0 +0,0 @@ import { CipherText, EncryptionKey, Nonce, PlainText } from "./types"; |
@@ -0,0 +0,0 @@ import { BigNumber } from "@zk-kit/utils"; |
@@ -0,0 +0,0 @@ import { StringifiedInput, BigIntOutput, Nonce } from "./types"; |
{ | ||
"name": "@zk-kit/poseidon-cipher", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Poseidon encryption and decryption in TypeScript.", | ||
"type": "module", | ||
"license": "MIT", | ||
@@ -15,12 +16,14 @@ "keywords": [ | ||
], | ||
"iife": "dist/index.js", | ||
"unpkg": "dist/index.min.js", | ||
"jsdelivr": "dist/index.min.js", | ||
"main": "dist/index.node.js", | ||
"iife": "dist/index.iife.js", | ||
"unpkg": "dist/index.iife.min.js", | ||
"jsdelivr": "dist/index.iife.min.js", | ||
"main": "dist/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.node.js", | ||
"types": "./dist/types/index.d.ts" | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"types": "dist/types/index.d.ts", | ||
"files": [ | ||
@@ -35,5 +38,3 @@ "dist/", | ||
"scripts": { | ||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript", | ||
"build:iife": "rollup -c rollup.iife.config.ts --configPlugin typescript", | ||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript && yarn build:iife", | ||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript", | ||
"prepublishOnly": "yarn build" | ||
@@ -45,12 +46,13 @@ }, | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@zk-kit/eddsa-poseidon": "0.1.0", | ||
"circomlibjs": "^0.0.8", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.32.1" | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.12.0", | ||
"rollup-plugin-cleanup": "^3.2.1" | ||
}, | ||
"dependencies": { | ||
"@zk-kit/baby-jubjub": "0.1.1", | ||
"@zk-kit/utils": "0.1.0" | ||
"@zk-kit/baby-jubjub": "0.2.0", | ||
"@zk-kit/utils": "0.3.0" | ||
} | ||
} |
@@ -5,3 +5,3 @@ <p align="center"> | ||
</h1> | ||
<p align="center">Poseidon Encryption and Decryption implementation in TypeScript.</p> | ||
<p align="center">Poseidon Hash function Encryption and Decryption implementation in TypeScript.</p> | ||
</p> | ||
@@ -45,12 +45,11 @@ | ||
This package implements encryption and decryption using the Poseidon hash function, and following the paper available [at](https://drive.google.com/file/d/1EVrP3DzoGbmzkRmYnyEDcIQcXVU7GlOd/view). | ||
This package implements encryption and decryption using the Poseidon hash function. This is a rewrite of the [original implementation](https://github.com/weijiekoh/circomlib/tree/feat/poseidon-encryption/src). | ||
## References | ||
1. Poseidon Cipher [Paper](https://drive.google.com/file/d/1EVrP3DzoGbmzkRmYnyEDcIQcXVU7GlOd/view) | ||
2. Original Implementation's [repo](https://github.com/weijiekoh/circomlib/tree/feat/poseidon-encryption/src) | ||
1. Dmitry Khovratovich. _Encryption with Poseidon_. 2019-12-26. https://drive.google.com/file/d/1EVrP3DzoGbmzkRmYnyEDcIQcXVU7GlOd/view. | ||
--- | ||
## Install | ||
## 🛠 Install | ||
@@ -84,1 +83,78 @@ ### npm or yarn | ||
``` | ||
## 📜 Usage | ||
```typescript | ||
import { poseidonEncrypt, poseidonDecrypt, poseidonDecryptWithoutCheck } from "@zk-kit/poseidon-cipher" | ||
// BabyJubJub random value used as private key. | ||
const privateKey = BigInt("10108149867830299554549347844489388280570828384194562713227904027271736843407") | ||
console.log(privateKey) | ||
// The BabyJubJub public key derived from the private key. | ||
const publicKey = [ | ||
BigInt("15100511232447817691325643662379962541629809665246870882117771367990737816375"), | ||
BigInt("16289853525630400225782441139722681929418024277641315637394850958390724375621") | ||
] | ||
/** | ||
[ | ||
15100511232447817691325643662379962541629809665246870882117771367990737816375n, | ||
16289853525630400225782441139722681929418024277641315637394850958390724375621n | ||
] | ||
*/ | ||
console.log(publicKey) | ||
/** | ||
* The Elliptic-Curve Diffie–Hellman (ECDH) shared key from the private and public key. | ||
* Learn more at https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman. | ||
*/ | ||
const encryptionKey = [ | ||
BigInt("18215233274609902892566361706948385597370728108990013889912246034099844508236"), | ||
BigInt("14884395706232754242497822954958766875005771827082919466711779658153477561231") | ||
] | ||
/** | ||
[ | ||
18215233274609902892566361706948385597370728108990013889912246034099844508236n, | ||
14884395706232754242497822954958766875005771827082919466711779658153477561231n | ||
] | ||
*/ | ||
console.log(encryptionKey) | ||
// The plaintext to be encrypted. | ||
const plainText = [BigInt(0), BigInt(1)] | ||
// The unique random value. | ||
const nonce = BigInt(5) | ||
// Compute the encryption. | ||
const encrypted = poseidonEncrypt(plainText, encryptionKey, nonce) | ||
/* | ||
[ | ||
13027563531333274777964504528445510545245985419061604793949748860800093661040n, | ||
21542829407417339379457427303368865281142518080970543920113508599380643597111n, | ||
334052772696549592017166610161467257195783602071397160212931200489386609812n, | ||
9075054520224362422769554641603717496449971372103870041485347221024944155182n | ||
] | ||
*/ | ||
console.log(encrypted) | ||
// Compute the decryption. | ||
const decrypted = poseidonDecrypt(encrypted, encryptionKey, nonce, plainText.length) | ||
/* | ||
[ | ||
0n, | ||
1n | ||
] | ||
*/ | ||
console.log(decrypted) | ||
// Compute the decryption without check. | ||
const decryptedWithoutCheck = poseidonDecryptWithoutCheck(encrypted, encryptionKey, nonce, plainText.length) | ||
/* | ||
[ | ||
0n, | ||
1n | ||
] | ||
*/ | ||
console.log(decryptedWithoutCheck) | ||
``` |
Sorry, the diff of this file is too big to display
158
Yes
3031327
6
17
39871
+ Added@zk-kit/baby-jubjub@0.2.0(transitive)
+ Added@zk-kit/utils@0.3.0(transitive)
- Removed@zk-kit/baby-jubjub@0.1.1(transitive)
- Removed@zk-kit/utils@0.1.0(transitive)
Updated@zk-kit/baby-jubjub@0.2.0
Updated@zk-kit/utils@0.3.0