https://github.com/valtech-commerce/tweetnacl
TweetNaCl wrapper
https://github.com/valtech-commerce/tweetnacl
nacl npm-package secretbox tweetnacl
Last synced: about 2 months ago
JSON representation
TweetNaCl wrapper
- Host: GitHub
- URL: https://github.com/valtech-commerce/tweetnacl
- Owner: valtech-commerce
- License: mit
- Created: 2023-02-06T16:36:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-06T17:27:32.000Z (over 3 years ago)
- Last Synced: 2025-11-23T17:03:10.533Z (7 months ago)
- Topics: nacl, npm-package, secretbox, tweetnacl
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @valtech-commerce/tweetnacl
[](https://www.npmjs.com/package/@valtech-commerce/tweetnacl)
[](https://david-dm.org/valtech-commerce/tweetnacl-js)
[](https://npms.io/search?q=%40valtech-commerce%2Ftweetnacl)
[](https://travis-ci.com/valtech-commerce/tweetnacl-js/builds)
[](https://github.com/valtech-commerce/eslint-config)
> [TweetNaCl](https://tweetnacl.js.org) wrapper
Wrap TweetNaCl functionalities
## Install
```shell
$ npm install @valtech-commerce/tweetnacl
```
## Usage
```js
// 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`](https://github.com/dchest/tweetnacl-js/blob/master/README.md#naclsecretboxmessage-nonce-key) 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`](https://github.com/dchest/tweetnacl-js/blob/master/README.md#naclsecretboxopenbox-nonce-key) 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.](https://www.valtech.ca/)