Socket
Socket
Sign inDemoInstall

@zk-kit/poseidon-cipher

Package Overview
Dependencies
2
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

10

dist/types/poseidonCipher.d.ts

@@ -19,1 +19,11 @@ import { CipherText, EncryptionKey, Nonce, PlainText } from "./types";

export declare const poseidonDecrypt: (ciphertext: CipherText<bigint>, key: EncryptionKey<bigint>, nonce: Nonce<bigint>, length: number) => PlainText<bigint>;
/**
* Decrypt some ciphertext using poseidon encryption
* @dev Do not throw if the plaintext is invalid
* @param ciphertext the ciphertext to decrypt
* @param key the key to decrypt with
* @param nonce the nonce used to encrypt
* @param length the length of the plaintext
* @returns the plaintext
*/
export declare const poseidonDecryptWithoutCheck: (ciphertext: CipherText<bigint>, key: EncryptionKey<bigint>, nonce: Nonce<bigint>, length: number) => PlainText<bigint>;

5

package.json
{
"name": "@zk-kit/poseidon-cipher",
"version": "0.1.1",
"version": "0.2.0",
"description": "Poseidon encryption and decryption in TypeScript.",

@@ -50,4 +50,5 @@ "license": "MIT",

"dependencies": {
"@zk-kit/baby-jubjub": "0.1.0"
"@zk-kit/baby-jubjub": "0.1.1",
"@zk-kit/utils": "0.1.0"
}
}

@@ -128,1 +128,42 @@ // https://github.com/weijiekoh/circomlib/blob/feat/poseidon-encryption/

}
/**
* Decrypt some ciphertext using poseidon encryption
* @dev Do not throw if the plaintext is invalid
* @param ciphertext the ciphertext to decrypt
* @param key the key to decrypt with
* @param nonce the nonce used to encrypt
* @param length the length of the plaintext
* @returns the plaintext
*/
export const poseidonDecryptWithoutCheck = (
ciphertext: CipherText<bigint>,
key: EncryptionKey<bigint>,
nonce: Nonce<bigint>,
length: number
): PlainText<bigint> => {
// Create the initial state
// S = (0, kS[0], kS[1], N + l ∗ 2^128).
let state = [Fr.zero, Fr.e(key[0]), Fr.e(key[1]), Fr.add(Fr.e(nonce), Fr.mul(Fr.e(BigInt(length)), two128))]
const message = []
const n = Math.floor(ciphertext.length / 3)
for (let i = 0; i < n; i += 1) {
// Iterate Poseidon on the state
state = poseidonPerm(state)
// Release three elements of the message
message.push(Fr.sub(ciphertext[i * 3], state[1]))
message.push(Fr.sub(ciphertext[i * 3 + 1], state[2]))
message.push(Fr.sub(ciphertext[i * 3 + 2], state[3]))
// Modify the state
state[1] = ciphertext[i * 3]
state[2] = ciphertext[i * 3 + 1]
state[3] = ciphertext[i * 3 + 2]
}
return message.slice(0, length)
}
dist/index.js

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc