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

dhole-crypto

v0.7.2

Published

JavaScript port of soatok/dhole-cryptography from PHP

Downloads

21

Readme

DholeCrypto.js

Support on Patreon Travis CI npm version

JavaScript port of Dhole Cryptography (PHP).

Libsodium wrapper for Soatok's JavaScript projects. Released under the very permissive ISC license.

Important: Until version v1.0.0 is released, please don't deploy this library in any production systems. I'll tag v1.0.0 when I'm confident in the correctness and security of the implementation.

Installation

npm install dhole-crypto

Usage

Asymmetric Cryptography

Digital Signatures

const { 
    Asymmetric, 
    AsymmetricSecretKey
} = require('dhole-crypto');

(async function () {
    let wolfSecret = await AsymmetricSecretKey.generate();
    let wolfPublic = wolfSecret.getPublicKey();
    
    let message = "Your $350 awoo fine has been paid UwU";
    
    let signature = await Asymmetric.sign(message, wolfSecret);
    if (!await Asymmetric.verify(message, wolfPublic, signature)) {
        console.log("Invalid signature. Awoo not authorized.");
    }
})();

Authenticated Public-Key Encryption

const { 
    Asymmetric, 
    AsymmetricSecretKey
} = require('dhole-crypto');

(async function () {
    let foxSecret = await AsymmetricSecretKey.generate();
    let foxPublic = foxSecret.getPublicKey();
    
    let wolfSecret = await AsymmetricSecretKey.generate();
    let wolfPublic = wolfSecret.getPublicKey();
    
    let message = "Encrypt me UwU";
    let encrypted = await Asymmetric.encrypt(message, foxPublic, wolfSecret);
    let decrypted = await Asymmetric.decrypt(encrypted, foxSecret, wolfPublic);
    console.log(decrypted.toString()); // "Encrypt me UwU"
})();

Anonymous Public-Key Encryption

const { 
    Asymmetric, 
    AsymmetricSecretKey
} = require('dhole-crypto');

(async function () {
    let foxSecret = await AsymmetricSecretKey.generate();
    let foxPublic = foxSecret.getPublicKey();
    
    let message = "Encrypt me UwU";
    let encrypted = await Asymmetric.seal(message, foxPublic);
    let decrypted = await Asymmetric.unseal(encrypted, foxSecret);
    console.log(decrypted.toString()); // "Encrypt me UwU"
})();

Symmetric Cryptography

Encryption

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
let symmetricKey = await SymmetricKey.generate();

let message = "Encrypt me UwU";
let encrypted = await Symmetric.encrypt(message, symmetricKey);
let decrypted = await Symmetric.decrypt(encrypted, symmetricKey);
console.log(decrypted); // "Encrypt me UwU"
})();

Encryption with Additional Data

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
    let symmetricKey = await SymmetricKey.generate();
    
    let message = "Encrypt me UwU";
    let publicData = "OwO? UwU";
    let encrypted = await Symmetric.encryptWithAd(message, symmetricKey, publicData);
    let decrypted = await Symmetric.decryptWithAd(encrypted, symmetricKey, publicData);
    console.log(decrypted); // "Encrypt me UwU"
})();

Unencrypted Message Authentication

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
    let symmetricKey = await SymmetricKey.generate();
    
    let message = "AWOOOOOOOOOOOO";
    let mac = await Symmetric.auth(message, symmetricKey);
    if (!await Symmetric.verify(message, mac, symmetricKey)) {
        console.log("Unauthorized Awoo. $350 fine incoming");
    }
})();

Password Storage

const {
    Password,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
    let symmetricKey = await SymmetricKey.generate();
    let pwHandler = new Password(symmetricKey);
    
    let password = 'cowwect howse battewy staple UwU';
    let pwhash = await pwHandler.hash(password);
    if (!await pwHandler.verify(password, pwhash)) {
        console.log("access denied");    
    }
})();

Keyring

You can serialize any key by using the Keyring class.

const {
    AsymmetricSecretKey,
    Keyring,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
    let foxSecret = await AsymmetricSecretKey.generate();
    let foxPublic = foxSecret.getPublicKey();
    let symmetric = await SymmetricKey.generate();
    // Load a serializer
    let ring = new Keyring();
    
    // Serialize to string
    let sk = await ring.save(foxSecret);
    let pk = await ring.save(foxPublic);
    let key = await ring.save(symmetric);
    
    // Load from string
    let loadSk = await ring.load(sk);
    let loadPk = await ring.load(pk);
    let loadSym = await ring.load(key);
})();

The Keyring class also supports keywrap. Simply pass a separate SymmetricKey instance to the constructor to get wrapped keys.

const {
    AsymmetricSecretKey,
    Keyring,
    SymmetricKey
} = require('dhole-crypto');

(async function () {
    // Keywrap key...
    let wrap = await SymemtricKey.generate();
    
    let foxSecret = await AsymmetricSecretKey.generate();
    let foxPublic = foxSecret.getPublicKey();
    let symmetric = await SymmetricKey.generate();
    
    // Load a serializer
    let ring = new Keyring(wrap);
    
    // Serialize to string
    let sk = await ring.save(foxSecret);
    let pk = await ring.save(foxPublic);
    let key = await ring.save(symmetric);
    
    // Load from string
    let loadSk = await ring.load(sk);
    let loadPk = await ring.load(pk);
    let loadSym = await ring.load(key);
})();

Support

If you run into any trouble using this library, or something breaks, feel free to file a Github issue.

If you need help with integration, Soatok is available for freelance work.