
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@zklx/crypto
Advanced tools
Cryptographic functions provider and example repository.
This module provides encryption and decryption functions for handling both binary data and strings using public and private keys. It utilizes ecies-wasm for the underlying cryptographic operations.
Package available on npm: https://www.npmjs.com/package/@zklx/crypto
encryptFile(publicKey: Key, fileName: string, data: Uint8Array): Uint8ArrayEncrypts the given binary data for the recipient using the public key. The file name is included in the encrypted data.
publicKey: The recipient's public key.fileName: The name of the file being encrypted.data: The plaintext data as a Uint8Array.Returns the ciphertext as a Uint8Array.
decryptFile(privateKey: Key, data: Uint8Array): { data: Uint8Array, fileName: string }Decrypts the given ciphertext using the recipient's private key. Returns the decrypted data and the original file name.
privateKey: The recipient's private key.data: The ciphertext data as a Uint8Array.Returns an object containing the plaintext data and the original file name.
encryptString(publicKey: Key, string: string): stringEncrypts the given string for the recipient using their public key. Returns the ciphertext as a hexadecimal string.
publicKey: The recipient's public key.string: The plaintext string.decryptString(privateKey: Key, string: string): stringDecrypts the given ciphertext string (in hexadecimal format) using the recipient's private key. Returns the plaintext string.
privateKey: The recipient's private key.string: The ciphertext string in hexadecimal format.import { Key } from "@zklx/kds";
import { encryptString, decryptString, encryptFile, decryptFile } from "@zklx/crypto";
// Example usage:
const publicKey = new Key(/* ... */);
const privateKey = new Key(/* ... */);
// Encrypt a string
const plaintext = "Hello, World!";
const encryptedString = encryptString(publicKey, plaintext);
// Decrypt the string
const decryptedString = decryptString(privateKey, encryptedString);
console.log(decryptedString); // "Hello, World!"
// Encrypt binary data
const fileName = "document.txt";
const data = new Uint8Array([/* ... */]);
const encryptedData = encryptFile(publicKey, fileName, data);
// Decrypt the binary data
const { data: decryptedData, fileName: decryptedFileName } = decryptFile(privateKey, encryptedData);
console.log(decryptedFileName); // "document.txt"
console.log(decryptedData); // Uint8Array
To launch the example webpage:
pnpm install
npx webpack # use npx, pnpm - webpack integration is broken
This module performs type checks on its inputs. It throws TypeError if arguments are not of the expected types. Additionally, the decryptString function issues a warning if the provided ciphertext string does not appear to be a valid hexadecimal string.
asHexString method is added to Uint8Array.prototype if it does not already exist. This method converts a Uint8Array to a hexadecimal string representation.Key class provided by zkl-kds/key.This project is licensed under the GNU Lesser General Public License, version 2.1.
Authored by Yigid BALABAN, fyb@fybx.dev
2024 © zk-Lokomotive team
FAQs
zk-Lokomotive cryptographic applications provider
We found that @zklx/crypto demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.