This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getRandomBytes", {
enumerable: true,
get: function get() {
return _random.getRandomBytes;
}
});
Object.defineProperty(exports, "getRandomAsciiString", {
enumerable: true,
get: function get() {
return _random.getRandomAsciiString;
}
});
Object.defineProperty(exports, "getRandomString", {
enumerable: true,
get: function get() {
return _random.getRandomString;
}
});
Object.defineProperty(exports, "getRandomSampledString", {
enumerable: true,
get: function get() {
return _random.getRandomSampledString;
}
});
exports.default = void 0;
var _random = require("./random.js");
/**
* index.js
*/
var _default = {
getRandomBytes: _random.getRandomBytes,
getRandomAsciiString: _random.getRandomAsciiString,
getRandomString: _random.getRandomString,
getRandomSampledString: _random.getRandomSampledString
};
exports.default = _default;
+1
View File
@@ -0,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 o(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="/home/circleci/repo/packages/js-crypto-random/dist",o(o.s=1)}([function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getRootWebCryptoAll=e.getWebCryptoAll=e.getMsCrypto=e.getWebCrypto=e.getNodeCrypto=e.default=void 0;var r=function(){return"undefined"!=typeof window?void 0:o(2)};e.getNodeCrypto=r;var n=function(){if("undefined"!=typeof window)return window.crypto?window.crypto.subtle:void 0};e.getWebCrypto=n;var i=function(){if("undefined"!=typeof window)return window.msCrypto?window.msCrypto.subtle:window.crypto?window.crypto.subtle:void 0};e.getWebCryptoAll=i;var u=function(){if("undefined"!=typeof window)return window.msCrypto?window.msCrypto:window.crypto?window.crypto:void 0};e.getRootWebCryptoAll=u;var d=function(){if("undefined"!=typeof window&&!window.crypto)return window.msCrypto?window.msCrypto.subtle:void 0};e.getMsCrypto=d;var f={getNodeCrypto:r,getWebCrypto:n,getMsCrypto:d,getWebCryptoAll:i,getRootWebCryptoAll:u};e.default=f},function(t,e,o){t.exports=o(3)},function(e,o){e.exports=t},function(t,e,o){"use strict";o.r(e);var r=o(0),n=function(t){for(var e=d(t),o=d(t),r="",n=0;n<t;n++)o[n]=o[n]%3,e[n]=0===o[n]?e[n]%10+48:e[n]%26+(1===o[n]?65:97),r+=String.fromCharCode(e[n]);return r},i=function(t){for(var e=d(t),o="",r=0;r<t;r++)e[r]=e[r]%94+32,o+=String.fromCharCode(e[r]);return o},u=function(t,e){var o=e.length;if(0===o)return"";for(var r=d(t),n="",i=0;i<t;i++)n+=e[r[i]%o];return n},d=function(t){var e,o=r.getRootWebCryptoAll(),n=r.getNodeCrypto();if(void 0!==o&&"function"==typeof o.getRandomValues)e=new Uint8Array(t),o.getRandomValues(e);else{if(void 0===n)throw new Error("UnsupportedEnvironment");e=new Uint8Array(n.randomBytes(t))}return e};o.d(e,"getRandomBytes",function(){return d}),o.d(e,"getRandomAsciiString",function(){return i}),o.d(e,"getRandomString",function(){return n}),o.d(e,"getRandomSampledString",function(){return u});e.default={getRandomBytes:d,getRandomAsciiString:i,getRandomString:n,getRandomSampledString:u}}])});
+112
View File
@@ -0,0 +1,112 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRandomBytes = exports.getRandomSampledString = exports.getRandomAsciiString = exports.getRandomString = void 0;
var util = _interopRequireWildcard(require("js-crypto-env"));
/**
* random.js
*/
/**
* Secure random string generator based on getRandomBytes,
* which is composed of uppercase or lowercase alphanumeric characters;
* @param {Number} len - Length of string.
* @return {String} - Generated random ASCII string.
*/
var getRandomString = function getRandomString(len) {
var array = getRandomBytes(len);
var types = getRandomBytes(len); // indicating alphanumeric, upper, lower
var finalString = ''; // Ascii code
// 1-0: 0x30 -- 0x39, 10 chars
// A-Z: 0x41 -- 0x5a,
// a-z: 0x61 -- 0x7a
for (var i = 0; i < len; i++) {
types[i] = types[i] % 3;
array[i] = types[i] === 0 ? array[i] % 10 + 0x30 : array[i] % 26 + (types[i] === 1 ? 0x41 : 0x61);
finalString += String.fromCharCode(array[i]);
}
return finalString;
};
/**
* Secure random 'ASCII' string generator based on getRandomBytes;
* @param {Number} len - Length of ASCII string.
* @return {String} - Generated random ASCII string.
*/
exports.getRandomString = getRandomString;
var getRandomAsciiString = 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;
};
/**
* Secure random string generator based on getRandomBytes,
* which is composed of givin character candidates;
* @param {Number} len - Length of string.
* @param {String} candidates - Candidates string to sample randomly.
* @return {String} - Generated random string.
*/
exports.getRandomAsciiString = getRandomAsciiString;
var getRandomSampledString = function getRandomSampledString(len, candidates) {
var candidate_len = candidates.length;
if (candidate_len === 0) return '';
var array = getRandomBytes(len);
var finalString = '';
for (var i = 0; i < len; i++) {
finalString += candidates[array[i] % candidate_len];
}
return finalString;
};
/**
* Secure random generator that returns a byte array filled with cryptographically secure random bytes
* @param {Number} len - Byte length of random sequence.
* @return {Uint8Array} - Generated random sequence.
* @throws {Error} - Throws if UnsupportedEnvironment.
*/
exports.getRandomSampledString = getRandomSampledString;
var getRandomBytes = function getRandomBytes(len) {
var webCrypto = util.getRootWebCryptoAll(); // web crypto api or ms crypto
var nodeCrypto = util.getNodeCrypto(); // implementation on node.js
var array;
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');
}
return array;
};
exports.getRandomBytes = getRandomBytes;