-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b7102aa
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
tweetnacl-util-js | ||
================= | ||
|
||
String encoding utilities extracted from <https://github.com/dchest/tweetnacl-js> | ||
|
||
Encoding/decoding functions are provided for convenience. They 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. **Please use better third-party libraries if you need to.** | ||
|
||
Installation | ||
------------ | ||
|
||
Use a package manager: | ||
|
||
[Bower](http://bower.io): | ||
|
||
$ bower install tweetnacl-util | ||
|
||
[NPM](https://www.npmjs.org/): | ||
|
||
$ npm install tweetnacl-util | ||
|
||
or [download source code](https://github.com/dchest/tweetnacl-util-js/releases). | ||
|
||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "tweetnacl-util", | ||
"version": "0.13.3", | ||
"homepage": "https://dchest.github.io/tweetnacl-util-js", | ||
"authors": [ | ||
"TweetNaCl.js Contributors" | ||
], | ||
"description": "String encoding utilitlies extracted from TweetNaCl.js", | ||
"main": "nacl-util.js", | ||
"moduleType": [ | ||
"globals", | ||
"node" | ||
], | ||
"keywords": [ | ||
"base64", | ||
"utf8", | ||
"string", | ||
"encoding" | ||
], | ||
"license": "Public domain", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"package.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. | ||
// Public domain. | ||
(function(root, f) { | ||
'use strict'; | ||
if (typeof module !== 'undefined' && module.exports) module.exports = f(); | ||
else if (root.nacl) root.nacl.util = f(); | ||
else { | ||
root.nacl = {}; | ||
root.nacl.util = f(); | ||
} | ||
}(this, function() { | ||
'use strict'; | ||
|
||
var util = {}; | ||
|
||
util.decodeUTF8 = function(s) { | ||
var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); | ||
for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); | ||
return b; | ||
}; | ||
|
||
util.encodeUTF8 = function(arr) { | ||
var i, s = []; | ||
for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); | ||
return decodeURIComponent(escape(s.join(''))); | ||
}; | ||
|
||
util.encodeBase64 = function(arr) { | ||
if (typeof btoa === 'undefined') { | ||
return (new Buffer(arr)).toString('base64'); | ||
} else { | ||
var i, s = [], len = arr.length; | ||
for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); | ||
return btoa(s.join('')); | ||
} | ||
}; | ||
|
||
util.decodeBase64 = function(s) { | ||
if (typeof atob === 'undefined') { | ||
return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); | ||
} else { | ||
var i, d = atob(s), b = new Uint8Array(d.length); | ||
for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); | ||
return b; | ||
} | ||
}; | ||
|
||
return util; | ||
|
||
})); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "tweetnacl-util", | ||
"version": "0.13.3", | ||
"description": "String encoding utilitlies extracted from TweetNaCl.js", | ||
"main": "nacl-util.js", | ||
"scripts": { | ||
"build": "uglifyjs nacl-util.js -c -m -o nacl-util.min.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dchest/tweetnacl-util-js.git" | ||
}, | ||
"keywords": [ | ||
"base64", | ||
"utf8", | ||
"string", | ||
"encoding" | ||
], | ||
"author": "TweetNaCl-js contributors", | ||
"license": "Public domain", | ||
"bugs": { | ||
"url": "https://github.com/dchest/tweetnacl-util-js/issues" | ||
}, | ||
"homepage": "https://github.com/dchest/tweetnacl-util-js", | ||
"devDependencies": { | ||
"uglify-js": "^2.6.1" | ||
}, | ||
"browser": { | ||
"buffer": false | ||
} | ||
} |