Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-crypto-random

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-crypto-random - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

dist/jscrandom.bundle.js

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("crypto")):"function"==typeof define&&define.amd?define(["crypto"],e):"object"==typeof exports?exports.jscrandom=e(require("crypto")):t.jscrandom=e(t.crypto)}(this,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="/Users/jun/ProjectJavaScript/js_crypto_random/dist",r(r.s=2)}([function(t,e,r){t.exports=r(3)},function(t,e){function r(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var a=t.apply(e,n);function u(t){r(a,o,i,u,c,"next",t)}function c(t){r(a,o,i,u,c,"throw",t)}u(void 0)})}}},function(t,e,r){t.exports=r(6)},function(t,e,r){var n=function(){return this||"object"==typeof self&&self}()||Function("return this")(),o=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,i=o&&n.regeneratorRuntime;if(n.regeneratorRuntime=void 0,t.exports=r(4),o)n.regeneratorRuntime=i;else try{delete n.regeneratorRuntime}catch(t){n.regeneratorRuntime=void 0}},function(t,e){!function(e){"use strict";var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag",f="object"==typeof t,s=e.regeneratorRuntime;if(s)f&&(t.exports=s);else{(s=e.regeneratorRuntime=f?t.exports:{}).wrap=x;var l="suspendedStart",h="suspendedYield",p="executing",y="completed",d={},v={};v[a]=function(){return this};var m=Object.getPrototypeOf,g=m&&m(m(N([])));g&&g!==n&&o.call(g,a)&&(v=g);var w=E.prototype=j.prototype=Object.create(v);L.prototype=w.constructor=E,E.constructor=L,E[c]=L.displayName="GeneratorFunction",s.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===L||"GeneratorFunction"===(e.displayName||e.name))},s.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(w),t},s.awrap=function(t){return{__await:t}},_(O.prototype),O.prototype[u]=function(){return this},s.AsyncIterator=O,s.async=function(t,e,r,n){var o=new O(x(t,e,r,n));return s.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},_(w),w[c]="Generator",w[a]=function(){return this},w.toString=function(){return"[object Generator]"},s.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},s.values=N,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return u.type="throw",u.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(c&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:N(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),d}}}function x(t,e,r,n){var o=e&&e.prototype instanceof j?e:j,i=Object.create(o.prototype),a=new k(n||[]);return i._invoke=function(t,e,r){var n=l;return function(o,i){if(n===p)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return G()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=P(a,r);if(u){if(u===d)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var c=b(t,e,r);if("normal"===c.type){if(n=r.done?y:h,c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=y,r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function b(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function j(){}function L(){}function E(){}function _(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function O(t){var e;this._invoke=function(r,n){function i(){return new Promise(function(e,i){!function e(r,n,i,a){var u=b(t[r],t,n);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&o.call(f,"__await")?Promise.resolve(f.__await).then(function(t){e("next",t,i,a)},function(t){e("throw",t,i,a)}):Promise.resolve(f).then(function(t){c.value=t,i(c)},function(t){return e("throw",t,i,a)})}a(u.arg)}(r,n,e,i)})}return e=e?e.then(i,i):i()}}function P(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,P(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=b(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function R(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function N(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:G}}function G(){return{value:r,done:!0}}}(function(){return this||"object"==typeof self&&self}()||Function("return this")())},function(e,r){e.exports=t},function(t,e,r){"use strict";r.r(e);var n=r(0),o=r.n(n),i=r(1),a=r.n(i);function u(){if("undefined"!=typeof window)return window.crypto?window.crypto:window.msCrypto?window.msCrypto:void 0}function c(t){return f.apply(this,arguments)}function f(){return(f=a()(o.a.mark(function t(e){var r,n,i;return o.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(e);case 2:for(r=t.sent,n="",i=0;i<e;i++)r[i]=r[i]%94+32,n+=String.fromCharCode(r[i]);return t.abrupt("return",n);case 6:case"end":return t.stop()}},t,this)}))).apply(this,arguments)}function s(t){return l.apply(this,arguments)}function l(){return(l=a()(o.a.mark(function t(e){var n,i,a;return o.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=u(),i="undefined"!=typeof window?void 0:r(5),a=new Uint8Array(e),void 0===n||"function"!=typeof n.getRandomValues){t.next=7;break}n.getRandomValues(a),t.next=12;break;case 7:if(void 0===i){t.next=11;break}a=new Uint8Array(i.randomBytes(e)),t.next=12;break;case 11:throw new Error("UnsupportedEnvironment");case 12:return t.abrupt("return",a);case 13:case"end":return t.stop()}},t,this)}))).apply(this,arguments)}r.d(e,"getRandomBytes",function(){return s}),r.d(e,"getRandomAsciiString",function(){return c});e.default={getRandomBytes:s,getRandomAsciiString:c}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("crypto")):"function"==typeof define&&define.amd?define(["crypto"],t):"object"==typeof exports?exports.jscrandom=t(require("crypto")):e.jscrandom=t(e.crypto)}(this,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/Users/jun/ProjectJavaScript/js_crypto_random/dist",n(n.s=0)}([function(e,t,n){e.exports=n(2)},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){for(var t=o(e),n="",r=0;r<e;r++)t[r]=t[r]%94+32,n+=String.fromCharCode(t[r]);return n}function o(e){var t,r=function(){if("undefined"!=typeof window)return window.crypto?window.crypto:window.msCrypto?window.msCrypto:void 0}(),o="undefined"!=typeof window?void 0:n(1);if(void 0!==r&&"function"==typeof r.getRandomValues)t=new Uint8Array(e),r.getRandomValues(t);else{if(void 0===o)throw new Error("UnsupportedEnvironment");t=new Uint8Array(o.randomBytes(e))}return t}n.r(t),n.d(t,"getRandomBytes",function(){return o}),n.d(t,"getRandomAsciiString",function(){return r});t.default={getRandomBytes:o,getRandomAsciiString:r}}])});

@@ -5,4 +5,2 @@ "use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -14,6 +12,2 @@ value: true

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var util = _interopRequireWildcard(require("./util.js"));

@@ -28,6 +22,14 @@

* @param len
* @return {Promise<string>}
* @return {string}
*/
function getRandomAsciiString(_x) {
return _getRandomAsciiString.apply(this, arguments);
function getRandomAsciiString(len) {
var array = getRandomBytes(len);
var finalString = ''; // Ascii code excluding control characters are in 0x20 -- 0x7e
for (var i = 0; i < len; i++) {
array[i] = array[i] % 0x5e + 0x20;
finalString += String.fromCharCode(array[i]);
}
return finalString;
}

@@ -37,93 +39,24 @@ /**

* @param len
* @return {Promise<Uint8Array>}
* @return {Uint8Array}
*/
function _getRandomAsciiString() {
_getRandomAsciiString = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(len) {
var array, finalString, i;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return getRandomBytes(len);
function getRandomBytes(len) {
var webCrypto = util.getWebCryptoAll(); // web crypto api or ms crypto
case 2:
array = _context.sent;
finalString = ''; // Ascii code excluding control characters are in 0x20 -- 0x7e
var nodeCrypto = util.getNodeCrypto(); // implementation on node.js
for (i = 0; i < len; i++) {
array[i] = array[i] % 0x5e + 0x20;
finalString += String.fromCharCode(array[i]);
}
var array;
return _context.abrupt("return", finalString);
if (typeof webCrypto !== 'undefined' && typeof webCrypto.getRandomValues === 'function') {
array = new Uint8Array(len);
webCrypto.getRandomValues(array); // for modern browsers or legacy ie 11
} else if (typeof nodeCrypto !== 'undefined') {
// for node
array = new Uint8Array(nodeCrypto.randomBytes(len));
} else {
throw new Error('UnsupportedEnvironment');
}
case 6:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return _getRandomAsciiString.apply(this, arguments);
}
function getRandomBytes(_x2) {
return _getRandomBytes.apply(this, arguments);
}
function _getRandomBytes() {
_getRandomBytes = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee2(len) {
var webCrypto, nodeCrypto, array;
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
webCrypto = util.getWebCryptoAll(); // web crypto api or ms crypto
nodeCrypto = util.getNodeCrypto(); // implementation on node.js
array = new Uint8Array(len);
if (!(typeof webCrypto !== 'undefined' && typeof webCrypto.getRandomValues === 'function')) {
_context2.next = 7;
break;
}
webCrypto.getRandomValues(array); // for modern browsers or legacy ie 11
_context2.next = 12;
break;
case 7:
if (!(typeof nodeCrypto !== 'undefined')) {
_context2.next = 11;
break;
}
// for node
array = new Uint8Array(nodeCrypto.randomBytes(len));
_context2.next = 12;
break;
case 11:
throw new Error('UnsupportedEnvironment');
case 12:
return _context2.abrupt("return", array);
case 13:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
return _getRandomBytes.apply(this, arguments);
return array;
}
{
"name": "js-crypto-random",
"version": "0.1.2",
"version": "0.1.3",
"description": "Universal Module for Secure Random Generator in JavaScript",

@@ -9,4 +9,10 @@ "main": "dist/jscrandom.bundle.js",

"karma": "./node_modules/.bin/karma start",
"webpack": "./node_modules/.bin/webpack --optimize-minimize --mode production",
"build": "NODE_ENV=production ./node_modules/.bin/babel src -d dist/ --keep-file-extension && npm run webpack"
"html": "npm run html:source && npm run html:bundle",
"html:source": "cross-env TEST_ENV=source ./node_modules/.bin/webpack --mode development",
"test:bundle": "npm run webpack && cross-env TEST_ENV=bundle npm run test",
"karma:bundle": "npm run webpack && cross-env TEST_ENV=bundle npm run karma",
"html:bundle": "cross-env TEST_ENV=bundle ./node_modules/.bin/webpack --mode development",
"webpack": "./node_modules/.bin/webpack --optimize-minimize --mode development",
"webpack:prod": "cross-env NODE_ENV=production ./node_modules/.bin/webpack --optimize-minimize --mode production",
"build": "cross-env NODE_ENV=production ./node_modules/.bin/babel src -d dist/ --keep-file-extension && npm run webpack:prod"
},

@@ -37,4 +43,5 @@ "author": "Jun Kurihara",

"babel-plugin-istanbul": "5.1.0",
"chai": "^4.1.2",
"eslint": "5.6.1",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"eslint": "5.7.0",
"karma": "3.0.0",

@@ -49,3 +56,3 @@ "karma-chrome-launcher": "^2.2.0",

"mocha-sinon": "^2.1.0",
"webpack": "^4.20.2",
"webpack": "^4.22.0",
"webpack-cli": "^3.1.2"

@@ -52,0 +59,0 @@ },

@@ -32,5 +32,4 @@ Universal Module for Secure Random Generator in JavaScript

```javascript
random.getRandomBytes(32).then( (rb) => {
// now you get an Uint8Array of 32 bytes filled with randomly generated values
});
// now you get an Uint8Array of 32 bytes filled with randomly generated values
const randomBytes = random.getRandomBytes(32);
```

@@ -40,5 +39,4 @@

```javascript
random.getRandomAsciiString(32)( (ra) => {
// now you get a string of 32 ASCII characters generated in a cryptographically random manner
});
// now you get a string of 32 ASCII characters generated in a cryptographically random manner
const randomAscii = random.getRandomAsciiString(32);
```

@@ -45,0 +43,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc