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

databridges-nacl-wrapper

v1.0.1

Published

DataBridges Node.js NaCl wrapper for databridges library.

Downloads

3

Readme

Databridges NodeJS NaCl Wrapper Library

Databridges NACL wrapper gives you a simple write and read function using implementation of the secretbox encryption standard defined in NaCl.

Databridges NACL wrapper is available for

The above wrappers can be used to send encrypted messages between them.

The Databridges NACL wrapper for NodeJS Language binding uses tweetnacl to deliver implementation of the secretbox encryption standard defined in NaCl.

Usage Overview

The following topics are covered:

Supported platforms

Node.js version 10 or newer. (The current Long Term Support (LTS) release is an ideal starting point).

Installation.

You can use NPM package manager to install the package.

npm install databridges-nacl-wrapper --save

Initialization

const dbNaClWrapper = require('databridges-nacl-wrapper');
const secretData = new dbNaClWrapper();

Global Configuration

Required

The following is the required properties before using to dataBridges NaCl wrapper.

secretData.secret = '32 char alphanumeric string';

| Properties | Description | | ---------- | ------------------------------------------------------------ | | secret | (string) 32 char alpha numeric string. NaCl encryption secret. |

Encrypt data

To encrypt data using NaCl, databridges wrapper exposes a method named write, This will return encrypted data if successful else it will throw error.

write()

try {
    const encData = secretData.write("Your Data..");
    console.log('Encrypted:', encData);
} catch (err) {
    console.log('Errors:', err.source, err.code, err.message);
}

| Parameter | Description | | --------- | ---------------------------------- | | data | (string) data to be encrypted. |

| Return Values | Description | | ------------- | ------------------ | | string | Encrypted string. |

Exceptions:

| Source | Code | Description | | ------------------ | -------------- | ---------------------------------------------- | | DBLIB_NACL_WRAPPER | INVALID_SECRET | secret is not set with the wrapper instance. | | DBLIB_NACL_WRAPPER | INVALID_DATA | If data is not passed to the function. | | DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |

Decrypt data

To decrypt data using NaCl, databridges wrapper exposes a method named read, This will return decrypted data if successful else it will throw error.

read()

try {
    const decData = secretData.read("<Encrypted data.>");
    console.log('Decrypted:', decData);
} catch (err) {
    console.log('Errors', err.source, err.code, err.message);
}

| Parameter | Description | | --------- | ---------------------------------- | | data | (string) data to be encrypted. |

| Return Values | Description | | ------------- | ------------------ | | string | Encrypted string. |

Exceptions:

| Source | Code | Description | | ------------------ | ------------------- | ------------------------------------------------------------ | | DBLIB_NACL_WRAPPER | INVALID_SECRET | secret is not set with the wrapper instance. | | DBLIB_NACL_WRAPPER | INVALID_DATA | If data is not passed to the function OR data is not a valid encrypted string. | | DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. | | DBLIB_NACL_WRAPPER | NACL_DECRYPT_FAILED | If decryption fails due to invalid secret or manipulated data. |

How to use with Databridges Nodejs Library

Below code shows how to integrate the NaCl wrapper with the Databridges library. After initialize you can use the wrapper library to encrypt and decrypt the data when publishing and receiving events.

// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
const dBridges = require('databridges-sio-client-lib');
const dbNaClWrapper = require('databridges-nacl-wrapper');

const dbridge = new dBridges();
const secretData = new dbNaClWrapper();
secretData.secret = "Your32 char secret.";

// .... Your databridges code comes here.

// On Subscription success event.
subscribeChannel.bind("dbridges:subscribe.success", (payload, metadata) => {
    console.log('Channel subscribe => bind', metadata.eventname, payload, JSON.stringify(metadata));
    try {
        // Encrypt data to publish.
        const encData = secretData.write("Your Data.."); 
        subscribeChannel.publish("eventName", encData, "1") 
    } catch (err) {
        console.log('Error:', err.source, err.code, err.message);
    }
});

// On payload Received event.
subscribeChannel.bind("eventName", (payload, metadata) => {
    console.log('eventName=> bind', metadata.eventname, payload, JSON.stringify(metadata));
    try {
        // Decrypt data received in the event.
        const decData = secretData.read(payload);
        console.log('Decrypted:', decData);
    } catch (err) {
        console.log('Error:', err.source, err.code, err.message);
    }
});

Change Log

License

DataBridges NaCl Wrapper is released under the MIT license.

    Copyright 2022 Optomate Technologies Private Limited.

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.