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

@zklx/crypto

v1.0.0

Published

zk-Lokomotive cryptographic applications provider

Downloads

2

Readme

zkl-crypto

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

Functions

encryptFile(publicKey: Key, fileName: string, data: Uint8Array): Uint8Array

Encrypts 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): string

Encrypts 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): string

Decrypts 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.

Usage

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

Example

To launch the example webpage:

pnpm install
npx webpack # use npx, pnpm - webpack integration is broken

Error Handling

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.

Notes

  • The asHexString method is added to Uint8Array.prototype if it does not already exist. This method converts a Uint8Array to a hexadecimal string representation.
  • Ensure that your public and private keys are instances of the Key class provided by zkl-kds/key.

License

This project is licensed under the GNU Lesser General Public License, version 2.1.

Authored by Yigid BALABAN, [email protected]

2024 © zk-Lokomotive team

https://zk-lokomotive.xyz/