Skip to content
Some string encoding utilities
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Add browser test; also validate encoding in browser Mar 19, 2017
.gitignore Initial commit Feb 19, 2016
.npmignore Add yarn.lock to .npmignore Feb 22, 2017
.travis.yml Add .travis.yml Mar 19, 2017
AUTHORS.md Use The Unlicense for public domain dedication Dec 9, 2016
LICENSE Use The Unlicense for public domain dedication Dec 9, 2016
README.md README: add link to StableLib repo May 25, 2017
bower.json
nacl-util.d.ts Typings: add missing new line at the end of file Dec 9, 2016
nacl-util.js Add browser test; also validate encoding in browser Mar 19, 2017
nacl-util.min.js Build Mar 19, 2017
package.json v0.15.0 Mar 19, 2017
yarn.lock Add browser test; also validate encoding in browser Mar 19, 2017

README.md

tweetnacl-util-js

String encoding utilities extracted from early versions of https://github.com/dchest/tweetnacl-js

Notice

Encoding/decoding functions in this package are correct, however their performance and wide compatibility with uncommon runtimes is not something that is considered important compared to the simplicity and size of implementation. For example, they don't work under React Native.

Instead of this package, I strongly recommend using my StableLib packages:

  • @stablelib/utf8 for UTF-8 encoding/decoding (note that the names of operations are reversed compared to this package): npm install @stablelib/utf8

  • @stablelib/base64 for constant-time Base64 encoding/decoding: npm install @stablelib/base64

Installation

Use a package manager:

Bower:

$ bower install tweetnacl-util

NPM:

$ npm install tweetnacl-util

or download source code.

Usage

To make keep backward compatibility with code that used nacl.util previously included with TweetNaCl.js, just include it as usual:

<script src="nacl.min.js"></script>
<script src="nacl-util.min.js"></script>
<script>
  // nacl.util functions are now available, e.g.:
  // nacl.util.decodeUTF8
</script>

When using CommonJS:

var nacl = require('tweetnacl');
nacl.util = require('tweetnacl-util');

Documentation

nacl.util.decodeUTF8(string)

Decodes string and returns Uint8Array of bytes.

nacl.util.encodeUTF8(array)

Encodes Uint8Array or Array of bytes into string.

nacl.util.decodeBase64(string)

Decodes Base-64 encoded string and returns Uint8Array of bytes.

nacl.util.encodeBase64(array)

Encodes Uint8Array or Array of bytes into string using Base-64 encoding.

You can’t perform that action at this time.