TweetNaCl wrapper
Wrap TweetNaCl functionalities
$ npm install @valtech-commerce/tweetnacl
// 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
Wraps nacl.secretbox
with autogeneration of nonce
and key
Returns an Object
with String
properties of box
and key
Required
Type: String
Message to lock
Wraps nacl.secretbox.open
with autoextraction of nonce
from box
Returns a String
message
Required
Type: String
Box containing encrypted message and nonce
Required
Type: String
Key to unlock box
MIT © Valtech Canada inc.