Skip to content

valtech-commerce/tweetnacl

Repository files navigation

@valtech-commerce/tweetnacl

npm npm dependencies npms Travis CI Code style ESLint

TweetNaCl wrapper

Wrap TweetNaCl functionalities

Install

$ npm install @valtech-commerce/tweetnacl

Usage

// Node.js
const tweetnacl = require('@valtech-commerce/tweetnacl');

// Browser
//   Load TweetNaCl libraries
//   - /node_modules/tweetnacl/nacl-fast.js
//   - /node_modules/tweetnacl-util/nacl-util.js
const { tweetnacl } = window.kafe;


// Lock the box
const { box, key } = tweetnacl.secretbox.lock('Dirty little secret');
console.log({ box, key });

// Outputs:
// {
//   box: "ThyOjmYtUvWSGne8lxXK7sJWGc/oigJ+I51pauSN/xTLpoufdAVNcCCQmtnwHlsu/hD7xnNZr7snkW4="
//   key: "ri4kzZ4V1pMGhGLqeqQayT3m2yT8FY79e1snqp2UAFg="
// }


// Unlock the box
const message = tweetnacl.secretbox.unlock(box, key);
console.log(message);

// Outputs:
// Dirty little secret

API

secretbox.lock(message)

Wraps nacl.secretbox with autogeneration of nonce and key
Returns an Object with String properties of box and key

message

Required
Type: String
Message to lock


secretbox.unlock(box, key)

Wraps nacl.secretbox.open with autoextraction of nonce from box
Returns a String message

box

Required
Type: String
Box containing encrypted message and nonce

key

Required
Type: String
Key to unlock box



License

MIT © Valtech Canada inc.