Socket
Socket
Sign inDemoInstall

tweetnacl-util

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.14.0 to 0.15.0

52

nacl-util.js

@@ -16,2 +16,8 @@ // Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri.

function validateBase64(s) {
if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) {
throw new TypeError('invalid encoding');
}
}
util.decodeUTF8 = function(s) {

@@ -30,24 +36,48 @@ if (typeof s !== 'string') throw new TypeError('expected string');

util.encodeBase64 = function(arr) {
if (typeof btoa === 'undefined') {
return (new Buffer(arr)).toString('base64');
if (typeof atob === 'undefined') {
// Node.js
if (typeof Buffer.from !== 'undefined') {
// Node v6 and later
util.encodeBase64 = function (arr) { // v6 and later
return Buffer.from(arr).toString('base64');
};
util.decodeBase64 = function (s) {
validateBase64(s);
return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0));
};
} else {
// Node earlier than v6
util.encodeBase64 = function (arr) { // v6 and later
return (new Buffer(arr)).toString('base64');
};
util.decodeBase64 = function(s) {
validateBase64(s);
return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0));
};
}
} else {
// Browsers
util.encodeBase64 = function(arr) {
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 {
util.decodeBase64 = function(s) {
validateBase64(s);
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;
}));

@@ -1,1 +0,1 @@

!function(e,n){"use strict";"undefined"!=typeof module&&module.exports?module.exports=n():e.nacl?e.nacl.util=n():(e.nacl={},e.nacl.util=n())}(this,function(){"use strict";var e={};return e.decodeUTF8=function(e){if("string"!=typeof e)throw new TypeError("expected string");var n,r=unescape(encodeURIComponent(e)),t=new Uint8Array(r.length);for(n=0;n<r.length;n++)t[n]=r.charCodeAt(n);return t},e.encodeUTF8=function(e){var n,r=[];for(n=0;n<e.length;n++)r.push(String.fromCharCode(e[n]));return decodeURIComponent(escape(r.join("")))},e.encodeBase64=function(e){if("undefined"==typeof btoa)return new Buffer(e).toString("base64");var n,r=[],t=e.length;for(n=0;n<t;n++)r.push(String.fromCharCode(e[n]));return btoa(r.join(""))},e.decodeBase64=function(e){if("undefined"==typeof atob)return new Uint8Array(Array.prototype.slice.call(new Buffer(e,"base64"),0));var n,r=atob(e),t=new Uint8Array(r.length);for(n=0;n<r.length;n++)t[n]=r.charCodeAt(n);return t},e});
!function(e,n){"use strict";"undefined"!=typeof module&&module.exports?module.exports=n():e.nacl?e.nacl.util=n():(e.nacl={},e.nacl.util=n())}(this,function(){"use strict";function e(e){if(!/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(e))throw new TypeError("invalid encoding")}var n={};return n.decodeUTF8=function(e){if("string"!=typeof e)throw new TypeError("expected string");var n,r=unescape(encodeURIComponent(e)),t=new Uint8Array(r.length);for(n=0;n<r.length;n++)t[n]=r.charCodeAt(n);return t},n.encodeUTF8=function(e){var n,r=[];for(n=0;n<e.length;n++)r.push(String.fromCharCode(e[n]));return decodeURIComponent(escape(r.join("")))},"undefined"==typeof atob?"undefined"!=typeof Buffer.from?(n.encodeBase64=function(e){return Buffer.from(e).toString("base64")},n.decodeBase64=function(n){return e(n),new Uint8Array(Array.prototype.slice.call(Buffer.from(n,"base64"),0))}):(n.encodeBase64=function(e){return new Buffer(e).toString("base64")},n.decodeBase64=function(n){return e(n),new Uint8Array(Array.prototype.slice.call(new Buffer(n,"base64"),0))}):(n.encodeBase64=function(e){var n,r=[],t=e.length;for(n=0;n<t;n++)r.push(String.fromCharCode(e[n]));return btoa(r.join(""))},n.decodeBase64=function(n){e(n);var r,t=atob(n),o=new Uint8Array(t.length);for(r=0;r<t.length;r++)o[r]=t.charCodeAt(r);return o}),n});
{
"name": "tweetnacl-util",
"version": "0.14.0",
"version": "0.15.0",
"description": "String encoding utilitlies extracted from TweetNaCl.js",

@@ -8,3 +8,5 @@ "main": "nacl-util.js",

"scripts": {
"build": "uglifyjs nacl-util.js -c -m -o nacl-util.min.js"
"build": "uglifyjs nacl-util.js -c -m -o nacl-util.min.js",
"test": "tape test/*.js; yarn run build-browser-test",
"build-browser-test": "browserify test/test.js > test/browser/bundle.js"
},

@@ -28,2 +30,4 @@ "repository": {

"devDependencies": {
"browserify": "^14.1.0",
"tape": "^4.6.3",
"uglify-js": "^2.6.1"

@@ -30,0 +34,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc