npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zk-kit/poseidon-cipher

v0.3.0

Published

Poseidon encryption and decryption in TypeScript.

Downloads

3,220

Readme

This package implements encryption and decryption using the Poseidon hash function. This is a rewrite of the original implementation.

References

  1. Dmitry Khovratovich. Encryption with Poseidon. 2019-12-26. https://drive.google.com/file/d/1EVrP3DzoGbmzkRmYnyEDcIQcXVU7GlOd/view.

🛠 Install

npm or yarn

You can install @zk-kit/poseidon-cipher package with npm:

npm i @zk-kit/poseidon-cipher --save

or yarn:

yarn add @zk-kit/poseidon-cipher

CDN

You can also load it using a script tag using unpkg:

<script src="https://unpkg.com/@zk-kit/poseidon-cipher"></script>

or JSDelivr:

<script src="https://cdn.jsdelivr.net/npm/@zk-kit/poseidon-cipher"></script>

📜 Usage

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)