tiny-essentials 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TinyBasicsEs.js +51 -14
- package/dist/TinyBasicsEs.min.js +1 -1
- package/dist/TinyCertCrypto.js +26497 -71362
- package/dist/TinyCertCrypto.min.js +1 -1
- package/dist/TinyCertCrypto.min.js.LICENSE.txt +0 -2
- package/dist/TinyCrypto.js +93 -70
- package/dist/TinyCrypto.min.js +1 -1
- package/dist/TinyEssentials.js +232 -136
- package/dist/TinyEssentials.min.js +1 -1
- package/dist/TinyLevelUp.js +9 -9
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/default.cjs +2 -0
- package/dist/legacy/crypto/default.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +2 -1
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/crypto/index.cjs +1 -1
- package/dist/legacy/crypto/index.mjs +1 -0
- package/dist/legacy/firebase/cookieSession.cjs +2 -0
- package/dist/legacy/firebase/cookieSession.mjs +1 -0
- package/dist/legacy/firebase/database/index.cjs +3 -0
- package/dist/legacy/firebase/database/index.mjs +1 -0
- package/dist/legacy/firebase/database/presence.cjs +3 -0
- package/dist/legacy/firebase/database/presence.mjs +1 -0
- package/dist/legacy/firebase/database/saveAsync.cjs +2 -0
- package/dist/legacy/firebase/database/saveAsync.mjs +1 -0
- package/dist/legacy/firebase/databaseEscape.cjs +3 -0
- package/dist/legacy/firebase/databaseEscape.mjs +1 -0
- package/dist/legacy/firebase/databaseLogger.cjs +3 -0
- package/dist/legacy/firebase/databaseLogger.mjs +1 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.cjs +3 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getToken.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUser.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUser.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.mjs +1 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +3 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +1 -0
- package/dist/legacy/firebase/discord/api/index.cjs +3 -0
- package/dist/legacy/firebase/discord/api/index.mjs +1 -0
- package/dist/legacy/firebase/discord/api/refreshToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/refreshToken.mjs +1 -0
- package/dist/legacy/firebase/discord/api/revokeToken.cjs +3 -0
- package/dist/legacy/firebase/discord/api/revokeToken.mjs +1 -0
- package/dist/legacy/firebase/discord/config.cjs +2 -0
- package/dist/legacy/firebase/discord/config.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +3 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +2 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +1 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +2 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +1 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +3 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +1 -0
- package/dist/legacy/firebase/discord/get/cookie-session.cjs +3 -0
- package/dist/legacy/firebase/discord/get/cookie-session.mjs +1 -0
- package/dist/legacy/firebase/discord/get/credentials.cjs +2 -0
- package/dist/legacy/firebase/discord/get/credentials.mjs +1 -0
- package/dist/legacy/firebase/discord/get/errorValidator.cjs +3 -0
- package/dist/legacy/firebase/discord/get/errorValidator.mjs +1 -0
- package/dist/legacy/firebase/discord/get/index.cjs +3 -0
- package/dist/legacy/firebase/discord/get/index.mjs +1 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.cjs +3 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.mjs +1 -0
- package/dist/legacy/firebase/discord/http/index.cjs +3 -0
- package/dist/legacy/firebase/discord/http/index.mjs +1 -0
- package/dist/legacy/firebase/discord/http/login.cjs +3 -0
- package/dist/legacy/firebase/discord/http/login.mjs +1 -0
- package/dist/legacy/firebase/discord/http/logout.cjs +3 -0
- package/dist/legacy/firebase/discord/http/logout.mjs +1 -0
- package/dist/legacy/firebase/discord/http/redirect.cjs +3 -0
- package/dist/legacy/firebase/discord/http/redirect.mjs +1 -0
- package/dist/legacy/firebase/discord/http/refreshToken.cjs +3 -0
- package/dist/legacy/firebase/discord/http/refreshToken.mjs +1 -0
- package/dist/legacy/firebase/discord/index.cjs +3 -0
- package/dist/legacy/firebase/discord/index.mjs +1 -0
- package/dist/legacy/firebase/discord/template/cookie-session.cjs +3 -0
- package/dist/legacy/firebase/discord/template/cookie-session.mjs +1 -0
- package/dist/legacy/firebase/domainRedirect.cjs +2 -0
- package/dist/legacy/firebase/domainRedirect.mjs +1 -0
- package/dist/legacy/firebase/escape.cjs +2 -0
- package/dist/legacy/firebase/escape.mjs +1 -0
- package/dist/legacy/firebase/getDBAsync.cjs +2 -0
- package/dist/legacy/firebase/getDBAsync.mjs +1 -0
- package/dist/legacy/firebase/getDBData.cjs +3 -0
- package/dist/legacy/firebase/getDBData.mjs +1 -0
- package/dist/legacy/firebase/getDBValue.cjs +2 -0
- package/dist/legacy/firebase/getDBValue.mjs +1 -0
- package/dist/legacy/firebase/index.cjs +3 -0
- package/dist/legacy/firebase/index.mjs +1 -0
- package/dist/legacy/firebase/isEmulator.cjs +2 -0
- package/dist/legacy/firebase/isEmulator.mjs +1 -0
- package/dist/legacy/firebase/logger.cjs +3 -0
- package/dist/legacy/firebase/logger.mjs +1 -0
- package/dist/legacy/firebase/mySQL.cjs +3 -0
- package/dist/legacy/firebase/mySQL.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/create.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/create.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/index.cjs +3 -0
- package/dist/legacy/firebase/mysqlConnector/index.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.cjs +2 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.mjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +3 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +1 -0
- package/dist/legacy/firebase/transactionDBAsync.cjs +2 -0
- package/dist/legacy/firebase/transactionDBAsync.mjs +1 -0
- package/dist/legacy/get/countObj.cjs +3 -0
- package/dist/legacy/get/countObj.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +3 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/objType.cjs +2 -0
- package/dist/legacy/get/objType.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +3 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +2 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +2 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +3 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +2 -1
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +1 -0
- package/dist/legacy/http/auth.cjs +2 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +2 -0
- package/dist/legacy/http/check_domain.mjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +2 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +3 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +2 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +3 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +3 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +3 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +3 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +3 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/index.cjs +3 -0
- package/dist/legacy/index.mjs +1 -0
- package/dist/legacy/libs/arraySortPositions.cjs +2 -0
- package/dist/legacy/libs/arraySortPositions.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +2 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +1 -0
- package/dist/legacy/libs/custom_module_loader.cjs +3 -0
- package/dist/legacy/libs/custom_module_loader.mjs +1 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +1 -0
- package/dist/legacy/libs/markdown.cjs +2 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +2 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +1 -0
- package/dist/legacy/libs/replaceAsync.cjs +3 -0
- package/dist/legacy/libs/replaceAsync.mjs +3 -0
- package/dist/legacy/libs/rule3.cjs +2 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/libs/userLevel.cjs +9 -9
- package/dist/legacy/libs/userLevel.d.mts +39 -16
- package/dist/legacy/libs/userLevel.mjs +9 -9
- package/dist/legacy/momentjs/getAge.cjs +3 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/index.cjs +1 -1
- package/dist/legacy/momentjs/index.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +3 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/index.cjs +1 -1
- package/dist/legacy/socket.io/antiFlood/index.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +3 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +3 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +2 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +3 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/legacy/socket.io/index.cjs +3 -0
- package/dist/legacy/socket.io/index.mjs +1 -0
- package/dist/v1/basics/clock.cjs +43 -13
- package/dist/v1/basics/clock.mjs +31 -13
- package/dist/v1/basics/objFilter.cjs +4 -0
- package/dist/v1/basics/objFilter.mjs +3 -0
- package/dist/v1/basics/simpleMath.cjs +1 -1
- package/dist/v1/basics/simpleMath.mjs +1 -1
- package/dist/v1/libs/TinyCertCrypto.cjs +104 -45
- package/dist/v1/libs/TinyCertCrypto.d.mts +18 -16
- package/dist/v1/libs/TinyCertCrypto.mjs +68 -37
- package/dist/v1/libs/TinyCrypto.cjs +70 -33
- package/dist/v1/libs/TinyCrypto.d.mts +64 -26
- package/dist/v1/libs/TinyCrypto.mjs +54 -38
- package/package.json +1 -1
- package/webpack.config.mjs +0 -69
package/dist/TinyEssentials.js
CHANGED
|
@@ -9183,16 +9183,17 @@ pss.create = function(options) {
|
|
|
9183
9183
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
9184
9184
|
|
|
9185
9185
|
"use strict";
|
|
9186
|
+
var __webpack_unused_export__;
|
|
9186
9187
|
|
|
9187
9188
|
|
|
9188
9189
|
// eslint-disable-next-line no-multi-assign
|
|
9189
|
-
exports.
|
|
9190
|
+
exports.po = __webpack_unused_export__ = __webpack_unused_export__ = /* unused reexport */ __webpack_require__(3209);
|
|
9190
9191
|
|
|
9191
9192
|
// eslint-disable-next-line no-multi-assign
|
|
9192
|
-
|
|
9193
|
+
__webpack_unused_export__ = /* unused reexport */ __webpack_require__(7108);
|
|
9193
9194
|
|
|
9194
9195
|
// eslint-disable-next-line no-multi-assign
|
|
9195
|
-
|
|
9196
|
+
__webpack_unused_export__ = /* unused reexport */ __webpack_require__(3507);
|
|
9196
9197
|
|
|
9197
9198
|
var algos = __webpack_require__(5715);
|
|
9198
9199
|
var algoKeys = Object.keys(algos);
|
|
@@ -9206,50 +9207,50 @@ var hashes = [
|
|
|
9206
9207
|
'rmd160'
|
|
9207
9208
|
].concat(algoKeys);
|
|
9208
9209
|
|
|
9209
|
-
|
|
9210
|
+
__webpack_unused_export__ = function () {
|
|
9210
9211
|
return hashes;
|
|
9211
9212
|
};
|
|
9212
9213
|
|
|
9213
9214
|
var p = __webpack_require__(8396);
|
|
9214
|
-
|
|
9215
|
-
|
|
9215
|
+
__webpack_unused_export__ = p.pbkdf2;
|
|
9216
|
+
__webpack_unused_export__ = p.pbkdf2Sync;
|
|
9216
9217
|
|
|
9217
9218
|
var aes = __webpack_require__(125);
|
|
9218
9219
|
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
exports.
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
exports.
|
|
9227
|
-
|
|
9228
|
-
|
|
9220
|
+
__webpack_unused_export__ = aes.Cipher;
|
|
9221
|
+
__webpack_unused_export__ = aes.createCipher;
|
|
9222
|
+
__webpack_unused_export__ = aes.Cipheriv;
|
|
9223
|
+
exports.Tt = aes.createCipheriv;
|
|
9224
|
+
__webpack_unused_export__ = aes.Decipher;
|
|
9225
|
+
__webpack_unused_export__ = aes.createDecipher;
|
|
9226
|
+
__webpack_unused_export__ = aes.Decipheriv;
|
|
9227
|
+
exports._7 = aes.createDecipheriv;
|
|
9228
|
+
__webpack_unused_export__ = aes.getCiphers;
|
|
9229
|
+
__webpack_unused_export__ = aes.listCiphers;
|
|
9229
9230
|
|
|
9230
9231
|
var dh = __webpack_require__(5380);
|
|
9231
9232
|
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9233
|
+
__webpack_unused_export__ = dh.DiffieHellmanGroup;
|
|
9234
|
+
__webpack_unused_export__ = dh.createDiffieHellmanGroup;
|
|
9235
|
+
__webpack_unused_export__ = dh.getDiffieHellman;
|
|
9236
|
+
__webpack_unused_export__ = dh.createDiffieHellman;
|
|
9237
|
+
__webpack_unused_export__ = dh.DiffieHellman;
|
|
9237
9238
|
|
|
9238
9239
|
var sign = __webpack_require__(20);
|
|
9239
9240
|
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9241
|
+
__webpack_unused_export__ = sign.createSign;
|
|
9242
|
+
__webpack_unused_export__ = sign.Sign;
|
|
9243
|
+
__webpack_unused_export__ = sign.createVerify;
|
|
9244
|
+
__webpack_unused_export__ = sign.Verify;
|
|
9244
9245
|
|
|
9245
|
-
|
|
9246
|
+
/* unused reexport */ __webpack_require__(1324);
|
|
9246
9247
|
|
|
9247
9248
|
var publicEncrypt = __webpack_require__(7168);
|
|
9248
9249
|
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9250
|
+
__webpack_unused_export__ = publicEncrypt.publicEncrypt;
|
|
9251
|
+
__webpack_unused_export__ = publicEncrypt.privateEncrypt;
|
|
9252
|
+
__webpack_unused_export__ = publicEncrypt.publicDecrypt;
|
|
9253
|
+
__webpack_unused_export__ = publicEncrypt.privateDecrypt;
|
|
9253
9254
|
|
|
9254
9255
|
// the least I can do is make error messages for the rest of the node.js/crypto api.
|
|
9255
9256
|
// [
|
|
@@ -9262,14 +9263,14 @@ exports.privateDecrypt = publicEncrypt.privateDecrypt;
|
|
|
9262
9263
|
|
|
9263
9264
|
var rf = __webpack_require__(6983);
|
|
9264
9265
|
|
|
9265
|
-
|
|
9266
|
-
|
|
9266
|
+
__webpack_unused_export__ = rf.randomFill;
|
|
9267
|
+
__webpack_unused_export__ = rf.randomFillSync;
|
|
9267
9268
|
|
|
9268
|
-
|
|
9269
|
+
__webpack_unused_export__ = function () {
|
|
9269
9270
|
throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
|
|
9270
9271
|
};
|
|
9271
9272
|
|
|
9272
|
-
|
|
9273
|
+
__webpack_unused_export__ = {
|
|
9273
9274
|
DH_CHECK_P_NOT_SAFE_PRIME: 2,
|
|
9274
9275
|
DH_CHECK_P_NOT_PRIME: 1,
|
|
9275
9276
|
DH_UNABLE_TO_CHECK_GENERATOR: 4,
|
|
@@ -75733,6 +75734,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
75733
75734
|
* });
|
|
75734
75735
|
*/
|
|
75735
75736
|
async function asyncReplace(str, regex, asyncFn) {
|
|
75737
|
+
/**
|
|
75738
|
+
* @type {any[]}
|
|
75739
|
+
*/
|
|
75736
75740
|
const promises = [];
|
|
75737
75741
|
|
|
75738
75742
|
// Collect promises
|
|
@@ -75764,7 +75768,7 @@ class TinyLevelUp {
|
|
|
75764
75768
|
|
|
75765
75769
|
/**
|
|
75766
75770
|
* Validates and adjusts the user's level based on their current experience.
|
|
75767
|
-
* @param {
|
|
75771
|
+
* @param {{ exp: number, level: number, totalExp: any }} user - The user object containing experience and level properties.
|
|
75768
75772
|
* @returns {Object} The updated user object.
|
|
75769
75773
|
*/
|
|
75770
75774
|
expValidator(user) {
|
|
@@ -75794,7 +75798,7 @@ class TinyLevelUp {
|
|
|
75794
75798
|
|
|
75795
75799
|
/**
|
|
75796
75800
|
* Calculates the total experience based on the user's level.
|
|
75797
|
-
* @param {
|
|
75801
|
+
* @param {{ exp: number, level: number }} user - The user object containing experience and level properties.
|
|
75798
75802
|
* @returns {number} The total experience of the user.
|
|
75799
75803
|
*/
|
|
75800
75804
|
getTotalExp(user) {
|
|
@@ -75815,7 +75819,7 @@ class TinyLevelUp {
|
|
|
75815
75819
|
|
|
75816
75820
|
/**
|
|
75817
75821
|
* Gets the experience points required to reach the next level.
|
|
75818
|
-
* @param {
|
|
75822
|
+
* @param {{ level: number }} user - The user object containing the level.
|
|
75819
75823
|
* @returns {number} The experience required for the next level.
|
|
75820
75824
|
*/
|
|
75821
75825
|
progress(user) {
|
|
@@ -75824,7 +75828,7 @@ class TinyLevelUp {
|
|
|
75824
75828
|
|
|
75825
75829
|
/**
|
|
75826
75830
|
* Gets the experience points required to reach the next level.
|
|
75827
|
-
* @param {
|
|
75831
|
+
* @param {{ level: number }} user - The user object containing the level.
|
|
75828
75832
|
* @returns {number} The experience required for the next level.
|
|
75829
75833
|
*/
|
|
75830
75834
|
getProgress(user) {
|
|
@@ -75833,7 +75837,7 @@ class TinyLevelUp {
|
|
|
75833
75837
|
|
|
75834
75838
|
/**
|
|
75835
75839
|
* Sets the experience value for the user, adjusting their level if necessary.
|
|
75836
|
-
* @param {
|
|
75840
|
+
* @param {{ exp: number, level: number, totalExp: any }} user - The user object.
|
|
75837
75841
|
* @param {number} value - The new experience value to set.
|
|
75838
75842
|
* @returns {Object} The updated user object.
|
|
75839
75843
|
*/
|
|
@@ -75846,9 +75850,9 @@ class TinyLevelUp {
|
|
|
75846
75850
|
|
|
75847
75851
|
/**
|
|
75848
75852
|
* Adds experience to the user, adjusting their level if necessary.
|
|
75849
|
-
* @param {
|
|
75853
|
+
* @param {{ exp: number, level: number, totalExp: any }} user - The user object.
|
|
75850
75854
|
* @param {number} extraExp - Additional experience to be added.
|
|
75851
|
-
* @param {
|
|
75855
|
+
* @param {'add' | 'extra'} type - Type of addition ('add' or 'extra').
|
|
75852
75856
|
* @param {number} multi - Multiplier for experience generation.
|
|
75853
75857
|
* @returns {Object} The updated user object.
|
|
75854
75858
|
*/
|
|
@@ -75863,9 +75867,9 @@ class TinyLevelUp {
|
|
|
75863
75867
|
|
|
75864
75868
|
/**
|
|
75865
75869
|
* Removes experience from the user, adjusting their level if necessary.
|
|
75866
|
-
* @param {
|
|
75870
|
+
* @param {{ exp: number, level: number, totalExp: any }} user - The user object.
|
|
75867
75871
|
* @param {number} extraExp - Experience to remove.
|
|
75868
|
-
* @param {
|
|
75872
|
+
* @param {'add' | 'extra'} type - Type of removal ('add' or 'extra').
|
|
75869
75873
|
* @param {number} multi - Multiplier for experience generation.
|
|
75870
75874
|
* @returns {Object} The updated user object.
|
|
75871
75875
|
*/
|
|
@@ -75922,7 +75926,8 @@ function shuffleArray(items) {
|
|
|
75922
75926
|
function getTimeDuration(timeData = new Date(), durationType = 'asSeconds', now = null) {
|
|
75923
75927
|
if (timeData instanceof Date) {
|
|
75924
75928
|
const currentTime = now instanceof Date ? now : new Date();
|
|
75925
|
-
|
|
75929
|
+
/** @type {number} */
|
|
75930
|
+
const diffMs = timeData.getTime() - currentTime.getTime();
|
|
75926
75931
|
|
|
75927
75932
|
switch (durationType) {
|
|
75928
75933
|
case 'asMilliseconds':
|
|
@@ -75967,6 +75972,17 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
75967
75972
|
seconds: index >= 0,
|
|
75968
75973
|
};
|
|
75969
75974
|
|
|
75975
|
+
/**
|
|
75976
|
+
* @type {{
|
|
75977
|
+
* years: number|NaN,
|
|
75978
|
+
* months: number|NaN,
|
|
75979
|
+
* days: number|NaN,
|
|
75980
|
+
* hours: number|NaN,
|
|
75981
|
+
* minutes: number|NaN,
|
|
75982
|
+
* seconds: number|NaN,
|
|
75983
|
+
* total: number|NaN
|
|
75984
|
+
* }}
|
|
75985
|
+
*/
|
|
75970
75986
|
const parts = {
|
|
75971
75987
|
years: include.years ? 0 : NaN,
|
|
75972
75988
|
months: include.months ? 0 : NaN,
|
|
@@ -75987,8 +76003,11 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
75987
76003
|
// Years
|
|
75988
76004
|
if (include.years) {
|
|
75989
76005
|
while (
|
|
75990
|
-
new Date(
|
|
75991
|
-
|
|
76006
|
+
new Date(
|
|
76007
|
+
workingDate.getFullYear() + 1,
|
|
76008
|
+
workingDate.getMonth(),
|
|
76009
|
+
workingDate.getDate(),
|
|
76010
|
+
).getTime() <= targetDate.getTime()
|
|
75992
76011
|
) {
|
|
75993
76012
|
workingDate.setFullYear(workingDate.getFullYear() + 1);
|
|
75994
76013
|
parts.years++;
|
|
@@ -75998,8 +76017,11 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
75998
76017
|
// Months
|
|
75999
76018
|
if (include.months) {
|
|
76000
76019
|
while (
|
|
76001
|
-
new Date(
|
|
76002
|
-
|
|
76020
|
+
new Date(
|
|
76021
|
+
workingDate.getFullYear(),
|
|
76022
|
+
workingDate.getMonth() + 1,
|
|
76023
|
+
workingDate.getDate(),
|
|
76024
|
+
).getTime() <= targetDate.getTime()
|
|
76003
76025
|
) {
|
|
76004
76026
|
workingDate.setMonth(workingDate.getMonth() + 1);
|
|
76005
76027
|
parts.months++;
|
|
@@ -76009,15 +76031,18 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
76009
76031
|
// Days
|
|
76010
76032
|
if (include.days) {
|
|
76011
76033
|
while (
|
|
76012
|
-
new Date(
|
|
76013
|
-
|
|
76034
|
+
new Date(
|
|
76035
|
+
workingDate.getFullYear(),
|
|
76036
|
+
workingDate.getMonth(),
|
|
76037
|
+
workingDate.getDate() + 1,
|
|
76038
|
+
).getTime() <= targetDate.getTime()
|
|
76014
76039
|
) {
|
|
76015
76040
|
workingDate.setDate(workingDate.getDate() + 1);
|
|
76016
76041
|
parts.days++;
|
|
76017
76042
|
}
|
|
76018
76043
|
}
|
|
76019
76044
|
|
|
76020
|
-
remaining = Math.floor((targetDate - workingDate) / 1000);
|
|
76045
|
+
remaining = Math.floor((targetDate.getTime() - workingDate.getTime()) / 1000);
|
|
76021
76046
|
}
|
|
76022
76047
|
|
|
76023
76048
|
if (include.hours) {
|
|
@@ -76046,7 +76071,16 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
76046
76071
|
|
|
76047
76072
|
parts.total = +(totalMap[level] || 0).toFixed(2).replace(/\.00$/, '');
|
|
76048
76073
|
|
|
76049
|
-
|
|
76074
|
+
/**
|
|
76075
|
+
* Pads a number to ensure it is at least two digits long, using leading zeros if necessary.
|
|
76076
|
+
*
|
|
76077
|
+
* @param {number|string} n - The number or string to pad.
|
|
76078
|
+
* @returns {string} The padded string.
|
|
76079
|
+
*/
|
|
76080
|
+
const pad = (n) => {
|
|
76081
|
+
const num = typeof n === 'string' ? parseInt(n) : n;
|
|
76082
|
+
return Number.isNaN(num) ? 'NaN' : String(num).padStart(2, '0');
|
|
76083
|
+
};
|
|
76050
76084
|
|
|
76051
76085
|
const timeString = [
|
|
76052
76086
|
include.hours ? pad(parts.hours) : null,
|
|
@@ -76057,14 +76091,14 @@ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
|
|
|
76057
76091
|
.join(':');
|
|
76058
76092
|
|
|
76059
76093
|
return format
|
|
76060
|
-
.replace(/\{years\}/g, parts.years)
|
|
76061
|
-
.replace(/\{months\}/g, parts.months)
|
|
76062
|
-
.replace(/\{days\}/g, parts.days)
|
|
76094
|
+
.replace(/\{years\}/g, String(parts.years))
|
|
76095
|
+
.replace(/\{months\}/g, String(parts.months))
|
|
76096
|
+
.replace(/\{days\}/g, String(parts.days))
|
|
76063
76097
|
.replace(/\{hours\}/g, pad(parts.hours))
|
|
76064
76098
|
.replace(/\{minutes\}/g, pad(parts.minutes))
|
|
76065
76099
|
.replace(/\{seconds\}/g, pad(parts.seconds))
|
|
76066
76100
|
.replace(/\{time\}/g, timeString)
|
|
76067
|
-
.replace(/\{total\}/g, parts.total)
|
|
76101
|
+
.replace(/\{total\}/g, String(parts.total))
|
|
76068
76102
|
.trim();
|
|
76069
76103
|
}
|
|
76070
76104
|
|
|
@@ -76169,6 +76203,9 @@ const typeValidator = {
|
|
|
76169
76203
|
/** Checks if the value is a Buffer. */
|
|
76170
76204
|
buffer: (val) => typeof buffer.Buffer !== 'undefined' && buffer.Buffer.isBuffer(val),
|
|
76171
76205
|
|
|
76206
|
+
/** Checks if the value is a File. */
|
|
76207
|
+
file: (val) => typeof File !== 'undefined' && val instanceof File,
|
|
76208
|
+
|
|
76172
76209
|
/** Checks if the value is a Html Element. */
|
|
76173
76210
|
htmlelement: (val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
76174
76211
|
|
|
@@ -76188,6 +76225,7 @@ const typeValidator = {
|
|
|
76188
76225
|
'function',
|
|
76189
76226
|
'array',
|
|
76190
76227
|
'buffer',
|
|
76228
|
+
'file',
|
|
76191
76229
|
'date',
|
|
76192
76230
|
'regexp',
|
|
76193
76231
|
'map',
|
|
@@ -76406,7 +76444,7 @@ function getSimplePerc(price, percentage) {
|
|
|
76406
76444
|
function getAge(timeData = 0, now = null) {
|
|
76407
76445
|
if (typeof timeData !== 'undefined' && timeData !== null && timeData !== 0) {
|
|
76408
76446
|
const birthDate = new Date(timeData);
|
|
76409
|
-
if (isNaN(birthDate)) return null;
|
|
76447
|
+
if (Number.isNaN(birthDate.getTime())) return null;
|
|
76410
76448
|
|
|
76411
76449
|
const currentDate = now instanceof Date ? now : new Date();
|
|
76412
76450
|
|
|
@@ -76493,8 +76531,8 @@ class TinyCrypto {
|
|
|
76493
76531
|
*
|
|
76494
76532
|
* @param {Object} [options={}] - Configuration options for encryption and decryption.
|
|
76495
76533
|
* @param {string} [options.algorithm='aes-256-gcm'] - The encryption algorithm to use. Recommended: 'aes-256-gcm' for authenticated encryption.
|
|
76496
|
-
* @param {
|
|
76497
|
-
* @param {
|
|
76534
|
+
* @param {BufferEncoding} [options.outputEncoding='hex'] - The encoding used when returning encrypted data (e.g., 'hex', 'base64').
|
|
76535
|
+
* @param {BufferEncoding} [options.inputEncoding='utf8'] - The encoding used for plaintext inputs (e.g., 'utf8').
|
|
76498
76536
|
* @param {number} [options.authTagLength=16] - The length of the authentication tag used in GCM mode. Usually 16 for AES-256-GCM.
|
|
76499
76537
|
* @param {Buffer} [options.key] - Optional 32-byte cryptographic key. If not provided, a random key is generated.
|
|
76500
76538
|
*
|
|
@@ -76504,15 +76542,17 @@ class TinyCrypto {
|
|
|
76504
76542
|
* const crypto = new CryptoManager({
|
|
76505
76543
|
* algorithm: 'aes-256-gcm',
|
|
76506
76544
|
* outputEncoding: 'base64',
|
|
76507
|
-
* key:
|
|
76545
|
+
* key: randomBytes(32),
|
|
76508
76546
|
* });
|
|
76509
76547
|
*/
|
|
76510
76548
|
constructor(options = {}) {
|
|
76511
76549
|
this.algorithm = options.algorithm || 'aes-256-gcm';
|
|
76512
|
-
this.outputEncoding = options.outputEncoding || 'hex';
|
|
76513
|
-
this.inputEncoding = options.inputEncoding || 'utf8';
|
|
76514
76550
|
this.authTagLength = options.authTagLength || 16;
|
|
76515
76551
|
this.key = options.key || this.generateKey();
|
|
76552
|
+
/** @type {BufferEncoding} */
|
|
76553
|
+
this.outputEncoding = options.outputEncoding || 'hex';
|
|
76554
|
+
/** @type {BufferEncoding} */
|
|
76555
|
+
this.inputEncoding = options.inputEncoding || 'utf8';
|
|
76516
76556
|
}
|
|
76517
76557
|
|
|
76518
76558
|
/**
|
|
@@ -76526,7 +76566,7 @@ class TinyCrypto {
|
|
|
76526
76566
|
* const customKey = cryptoManager.generateKey(16); // Generates a 16-byte key (e.g. for AES-128)
|
|
76527
76567
|
*/
|
|
76528
76568
|
generateKey(value = 32) {
|
|
76529
|
-
return crypto_browserify
|
|
76569
|
+
return (0,crypto_browserify/* randomBytes */.po)(value); // 256-bit
|
|
76530
76570
|
}
|
|
76531
76571
|
|
|
76532
76572
|
/**
|
|
@@ -76540,7 +76580,7 @@ class TinyCrypto {
|
|
|
76540
76580
|
* const customIV = cryptoManager.generateIV(16); // Generates a 16-byte IV if needed for other algorithms
|
|
76541
76581
|
*/
|
|
76542
76582
|
generateIV(value = 12) {
|
|
76543
|
-
return crypto_browserify
|
|
76583
|
+
return (0,crypto_browserify/* randomBytes */.po)(value); // 96-bit padrão para GCM
|
|
76544
76584
|
}
|
|
76545
76585
|
|
|
76546
76586
|
/**
|
|
@@ -76550,10 +76590,7 @@ class TinyCrypto {
|
|
|
76550
76590
|
*
|
|
76551
76591
|
* @param {*} data - The data to encrypt. Can be of any supported type (string, number, boolean, Date, JSON, etc.).
|
|
76552
76592
|
* @param {Buffer} [iv=this.generateIV()] - Optional Initialization Vector (IV). If not provided, a secure random IV is generated.
|
|
76553
|
-
* @returns {
|
|
76554
|
-
* - `iv` {string} - The IV used, encoded with the output encoding.
|
|
76555
|
-
* - `encrypted` {string} - The encrypted payload.
|
|
76556
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the ciphertext.
|
|
76593
|
+
* @returns {EncryptedDataParams} An object containing the encrypted data.
|
|
76557
76594
|
*
|
|
76558
76595
|
* @example
|
|
76559
76596
|
* const result = cryptoManager.encrypt('Hello, world!');
|
|
@@ -76566,31 +76603,41 @@ class TinyCrypto {
|
|
|
76566
76603
|
encrypt(data, iv = this.generateIV()) {
|
|
76567
76604
|
const plainText = this.#serialize(data);
|
|
76568
76605
|
|
|
76569
|
-
const cipher = crypto_browserify
|
|
76606
|
+
const cipher = (0,crypto_browserify/* createCipheriv */.Tt)(this.algorithm, this.key, iv, {
|
|
76607
|
+
// @ts-ignore
|
|
76570
76608
|
authTagLength: this.authTagLength,
|
|
76571
76609
|
});
|
|
76572
76610
|
|
|
76611
|
+
// @ts-ignore
|
|
76573
76612
|
let encrypted = cipher.update(plainText, this.inputEncoding);
|
|
76613
|
+
// @ts-ignore
|
|
76574
76614
|
encrypted = buffer.Buffer.concat([encrypted, cipher.final()]);
|
|
76575
76615
|
const authTag = cipher.getAuthTag();
|
|
76576
76616
|
|
|
76577
76617
|
return {
|
|
76618
|
+
// @ts-ignore
|
|
76578
76619
|
iv: iv.toString(this.outputEncoding),
|
|
76620
|
+
// @ts-ignore
|
|
76579
76621
|
encrypted: encrypted.toString(this.outputEncoding),
|
|
76622
|
+
// @ts-ignore
|
|
76580
76623
|
authTag: authTag.toString(this.outputEncoding),
|
|
76581
76624
|
};
|
|
76582
76625
|
}
|
|
76583
76626
|
|
|
76627
|
+
/**
|
|
76628
|
+
* @typedef {Object} EncryptedDataParams
|
|
76629
|
+
* @property {string} iv - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
76630
|
+
* @property {string} encrypted - The encrypted data to decrypt, encoded with the output encoding.
|
|
76631
|
+
* @property {string} authTag - The authentication tag used to verify the integrity of the encrypted data.
|
|
76632
|
+
*/
|
|
76633
|
+
|
|
76584
76634
|
/**
|
|
76585
76635
|
* Decrypts a previously encrypted value.
|
|
76586
76636
|
*
|
|
76587
76637
|
* The method checks the integrity of the data using the authentication tag (`authTag`) and ensures the data is properly decrypted.
|
|
76588
76638
|
* After decryption, it automatically deserializes the data back to its original type.
|
|
76589
76639
|
*
|
|
76590
|
-
* @param {
|
|
76591
|
-
* - `iv` {string} - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
76592
|
-
* - `encrypted` {string} - The encrypted data to decrypt, encoded with the output encoding.
|
|
76593
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the encrypted data.
|
|
76640
|
+
* @param {EncryptedDataParams} params - An object containing the encrypted data.
|
|
76594
76641
|
* @param {string|null} [expectedType=null] - Optionally specify the expected type of the decrypted data. If provided, the method will validate the type of the deserialized value.
|
|
76595
76642
|
* @returns {*} The decrypted value, which will be the original type of the data before encryption.
|
|
76596
76643
|
* @throws {Error} Throws if the authentication tag doesn't match or the data has been tampered with.
|
|
@@ -76610,13 +76657,17 @@ class TinyCrypto {
|
|
|
76610
76657
|
const encryptedBuffer = buffer.Buffer.from(encrypted, this.outputEncoding);
|
|
76611
76658
|
const authTagBuffer = buffer.Buffer.from(authTag, this.outputEncoding);
|
|
76612
76659
|
|
|
76613
|
-
const decipher = crypto_browserify
|
|
76660
|
+
const decipher = (0,crypto_browserify/* createDecipheriv */._7)(this.algorithm, this.key, ivBuffer, {
|
|
76661
|
+
// @ts-ignore
|
|
76614
76662
|
authTagLength: this.authTagLength,
|
|
76615
76663
|
});
|
|
76616
76664
|
|
|
76617
76665
|
decipher.setAuthTag(authTagBuffer);
|
|
76618
76666
|
|
|
76667
|
+
/** @type {string} */
|
|
76668
|
+
// @ts-ignore
|
|
76619
76669
|
let decrypted = decipher.update(encryptedBuffer, null, this.inputEncoding);
|
|
76670
|
+
// @ts-ignore
|
|
76620
76671
|
decrypted += decipher.final(this.inputEncoding);
|
|
76621
76672
|
const { value, type } = this.#deserialize(decrypted);
|
|
76622
76673
|
|
|
@@ -76630,10 +76681,7 @@ class TinyCrypto {
|
|
|
76630
76681
|
* This method decrypts the encrypted data and extracts its type information without fully deserializing the value.
|
|
76631
76682
|
* It is useful when you need to verify the type of the encrypted data before fully decrypting it.
|
|
76632
76683
|
*
|
|
76633
|
-
* @param {
|
|
76634
|
-
* - `iv` {string} - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
76635
|
-
* - `encrypted` {string} - The encrypted data to decrypt, encoded with the output encoding.
|
|
76636
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the encrypted data.
|
|
76684
|
+
* @param {EncryptedDataParams} params - An object containing the encrypted data.
|
|
76637
76685
|
* @returns {string} The type of the original data (e.g., 'string', 'number', 'date', etc.).
|
|
76638
76686
|
*
|
|
76639
76687
|
* @example
|
|
@@ -76650,13 +76698,16 @@ class TinyCrypto {
|
|
|
76650
76698
|
const encryptedBuffer = buffer.Buffer.from(encrypted, this.outputEncoding);
|
|
76651
76699
|
const authTagBuffer = buffer.Buffer.from(authTag, this.outputEncoding);
|
|
76652
76700
|
|
|
76653
|
-
const decipher = crypto_browserify
|
|
76701
|
+
const decipher = (0,crypto_browserify/* createDecipheriv */._7)(this.algorithm, this.key, ivBuffer, {
|
|
76702
|
+
// @ts-ignore
|
|
76654
76703
|
authTagLength: this.authTagLength,
|
|
76655
76704
|
});
|
|
76656
76705
|
|
|
76657
76706
|
decipher.setAuthTag(authTagBuffer);
|
|
76658
76707
|
|
|
76708
|
+
// @ts-ignore
|
|
76659
76709
|
let decrypted = decipher.update(encryptedBuffer, null, this.inputEncoding);
|
|
76710
|
+
// @ts-ignore
|
|
76660
76711
|
decrypted += decipher.final(this.inputEncoding);
|
|
76661
76712
|
|
|
76662
76713
|
const { type } = this.#deserialize(decrypted);
|
|
@@ -76746,10 +76797,12 @@ class TinyCrypto {
|
|
|
76746
76797
|
async loadConfigFromFile(file) {
|
|
76747
76798
|
if (isBrowser) {
|
|
76748
76799
|
return new Promise((resolve, reject) => {
|
|
76800
|
+
if (!(file instanceof File))
|
|
76801
|
+
return reject(new Error('In browser, the file must be a File object'));
|
|
76749
76802
|
const reader = new FileReader();
|
|
76750
76803
|
reader.onload = () => {
|
|
76751
76804
|
try {
|
|
76752
|
-
const config = JSON.parse(reader.result);
|
|
76805
|
+
const config = typeof reader.result === 'string' ? JSON.parse(reader.result) : {};
|
|
76753
76806
|
resolve(this.importConfig(config));
|
|
76754
76807
|
} catch (err) {
|
|
76755
76808
|
reject(new Error('Invalid config JSON file'));
|
|
@@ -76759,7 +76812,7 @@ class TinyCrypto {
|
|
|
76759
76812
|
reader.readAsText(file);
|
|
76760
76813
|
});
|
|
76761
76814
|
} else {
|
|
76762
|
-
const raw = fs_ignored_.readFileSync(file, 'utf8');
|
|
76815
|
+
const raw = fs_ignored_.readFileSync(/** @type {string} */ (file), 'utf8');
|
|
76763
76816
|
const config = JSON.parse(raw);
|
|
76764
76817
|
return this.importConfig(config);
|
|
76765
76818
|
}
|
|
@@ -76791,9 +76844,11 @@ class TinyCrypto {
|
|
|
76791
76844
|
async loadKeyFromFile(file) {
|
|
76792
76845
|
if (isBrowser) {
|
|
76793
76846
|
return new Promise((resolve, reject) => {
|
|
76847
|
+
if (!(file instanceof File))
|
|
76848
|
+
return reject(new Error('In browser, the file must be a File object'));
|
|
76794
76849
|
const reader = new FileReader();
|
|
76795
76850
|
reader.onload = () => {
|
|
76796
|
-
const hexKey = reader.result.trim();
|
|
76851
|
+
const hexKey = typeof reader.result === 'string' ? reader.result.trim() : '';
|
|
76797
76852
|
const keyBuffer = buffer.Buffer.from(hexKey, 'hex');
|
|
76798
76853
|
this.key = keyBuffer;
|
|
76799
76854
|
resolve(keyBuffer);
|
|
@@ -76802,7 +76857,7 @@ class TinyCrypto {
|
|
|
76802
76857
|
reader.readAsText(file);
|
|
76803
76858
|
});
|
|
76804
76859
|
} else {
|
|
76805
|
-
const hexKey = fs_ignored_.readFileSync(file, 'utf8');
|
|
76860
|
+
const hexKey = fs_ignored_.readFileSync(/** @type {string} */ (file), 'utf8');
|
|
76806
76861
|
const keyBuffer = buffer.Buffer.from(hexKey, 'hex');
|
|
76807
76862
|
this.key = keyBuffer;
|
|
76808
76863
|
return keyBuffer;
|
|
@@ -76848,8 +76903,8 @@ class TinyCrypto {
|
|
|
76848
76903
|
*
|
|
76849
76904
|
* @param {Object} config - The configuration object to import.
|
|
76850
76905
|
* @param {string} config.algorithm - The encryption algorithm (e.g., 'aes-256-gcm').
|
|
76851
|
-
* @param {
|
|
76852
|
-
* @param {
|
|
76906
|
+
* @param {BufferEncoding} config.outputEncoding - The output encoding format (e.g., 'hex').
|
|
76907
|
+
* @param {BufferEncoding} config.inputEncoding - The input encoding format (e.g., 'utf8').
|
|
76853
76908
|
* @param {number} config.authTagLength - The authentication tag length (e.g., 16).
|
|
76854
76909
|
* @param {string} config.key - The cryptographic key in hexadecimal string format.
|
|
76855
76910
|
*
|
|
@@ -76896,7 +76951,7 @@ class TinyCrypto {
|
|
|
76896
76951
|
* Each key corresponds to a specific data type (e.g., 'number', 'date', 'buffer', etc.),
|
|
76897
76952
|
* and the value is a function that serializes the data to a specific format.
|
|
76898
76953
|
*
|
|
76899
|
-
* @type {
|
|
76954
|
+
* @type {Record<string, (data: any) => string>}
|
|
76900
76955
|
* @property {Function} weakmap - Throws an error as WeakMap cannot be serialized.
|
|
76901
76956
|
* @property {Function} weakset - Throws an error as WeakSet cannot be serialized.
|
|
76902
76957
|
* @property {Function} promise - Throws an error as Promise cannot be serialized.
|
|
@@ -76937,8 +76992,8 @@ class TinyCrypto {
|
|
|
76937
76992
|
number: (data) => JSON.stringify({ __type: 'number', value: data }),
|
|
76938
76993
|
boolean: (data) => JSON.stringify({ __type: 'boolean', value: data }),
|
|
76939
76994
|
string: (data) => JSON.stringify({ __type: 'string', value: data }),
|
|
76940
|
-
null: (
|
|
76941
|
-
undefined: (
|
|
76995
|
+
null: () => JSON.stringify({ __type: 'null' }),
|
|
76996
|
+
undefined: () => JSON.stringify({ __type: 'undefined' }),
|
|
76942
76997
|
map: (data) =>
|
|
76943
76998
|
JSON.stringify({
|
|
76944
76999
|
__type: 'map',
|
|
@@ -76963,7 +77018,7 @@ class TinyCrypto {
|
|
|
76963
77018
|
* Each key corresponds to a specific data type (e.g., 'Date', 'BigInt', 'Buffer', etc.),
|
|
76964
77019
|
* and the value is a function that deserializes the value to its original format.
|
|
76965
77020
|
*
|
|
76966
|
-
* @type {
|
|
77021
|
+
* @type {Record<string, (data: any) => any>}
|
|
76967
77022
|
* @property {Function} regexp - Deserializes a regular expression from its string representation (e.g., `/pattern/flags`).
|
|
76968
77023
|
* @property {Function} htmlelement - Deserializes an HTML element from its serialized outerHTML string (only works in browser environments).
|
|
76969
77024
|
* @property {Function} date - Deserializes a date from its ISO string representation.
|
|
@@ -76990,14 +77045,14 @@ class TinyCrypto {
|
|
|
76990
77045
|
throw new Error('HTMLElement deserialization is only supported in browsers');
|
|
76991
77046
|
const div = document.createElement('div');
|
|
76992
77047
|
div.innerHTML = value;
|
|
76993
|
-
return div
|
|
77048
|
+
return div;
|
|
76994
77049
|
},
|
|
76995
77050
|
date: (value) => new Date(value),
|
|
76996
77051
|
bigint: (value) => BigInt(value),
|
|
76997
77052
|
number: (value) => Number(value),
|
|
76998
77053
|
boolean: (value) => Boolean(value),
|
|
76999
|
-
null: (
|
|
77000
|
-
undefined: (
|
|
77054
|
+
null: () => null,
|
|
77055
|
+
undefined: () => undefined,
|
|
77001
77056
|
map: (value) => new Map(value),
|
|
77002
77057
|
set: (value) => new Set(value),
|
|
77003
77058
|
symbol: (value) => Symbol(value),
|
|
@@ -77018,7 +77073,8 @@ class TinyCrypto {
|
|
|
77018
77073
|
*/
|
|
77019
77074
|
#serialize(data) {
|
|
77020
77075
|
const type = objType(data) || 'undefined';
|
|
77021
|
-
if (
|
|
77076
|
+
if (typeof type === 'string' && this.#valueConvertTypes[type])
|
|
77077
|
+
return this.#valueConvertTypes[type](data);
|
|
77022
77078
|
throw new Error(`Unsupported data type for encryption: ${type}`);
|
|
77023
77079
|
}
|
|
77024
77080
|
|
|
@@ -77069,7 +77125,6 @@ class TinyCrypto {
|
|
|
77069
77125
|
|
|
77070
77126
|
|
|
77071
77127
|
|
|
77072
|
-
|
|
77073
77128
|
/**
|
|
77074
77129
|
* Determines if the environment is a browser.
|
|
77075
77130
|
*
|
|
@@ -77099,7 +77154,6 @@ class TinyCertCrypto {
|
|
|
77099
77154
|
* It supports multi-line content.
|
|
77100
77155
|
*
|
|
77101
77156
|
* @type {RegExp}
|
|
77102
|
-
* @private
|
|
77103
77157
|
*/
|
|
77104
77158
|
#certRegex = /-----BEGIN CERTIFICATE-----([\s\S]+?)-----END CERTIFICATE-----/;
|
|
77105
77159
|
|
|
@@ -77112,7 +77166,6 @@ class TinyCertCrypto {
|
|
|
77112
77166
|
* It captures the key type (PUBLIC|PRIVATE) and the base64 content.
|
|
77113
77167
|
*
|
|
77114
77168
|
* @type {RegExp}
|
|
77115
|
-
* @private
|
|
77116
77169
|
*/
|
|
77117
77170
|
#keyRegex =
|
|
77118
77171
|
/-----BEGIN\s+(?:RSA\s+)?(PUBLIC|PRIVATE)\s+KEY-----([\s\S]+?)-----END\s+(?:RSA\s+)?\1\s+KEY-----/;
|
|
@@ -77180,10 +77233,10 @@ class TinyCertCrypto {
|
|
|
77180
77233
|
* This method is private and should not be called directly from outside.
|
|
77181
77234
|
*
|
|
77182
77235
|
* @returns {Promise<Object>} The loaded `node-forge` module.
|
|
77183
|
-
* @private
|
|
77184
77236
|
*/
|
|
77185
77237
|
async #fetchNodeForge() {
|
|
77186
77238
|
if (!this.forge) {
|
|
77239
|
+
// @ts-ignore
|
|
77187
77240
|
const forge = await Promise.resolve(/* import() eager */).then(__webpack_require__.t.bind(__webpack_require__, 9547, 19));
|
|
77188
77241
|
this.forge = forge.default;
|
|
77189
77242
|
}
|
|
@@ -77205,7 +77258,6 @@ class TinyCertCrypto {
|
|
|
77205
77258
|
* Assumes the module has already been loaded.
|
|
77206
77259
|
*
|
|
77207
77260
|
* @returns {Object} The `node-forge` module.
|
|
77208
|
-
* @private
|
|
77209
77261
|
*/
|
|
77210
77262
|
#getNodeForge() {
|
|
77211
77263
|
return this.forge;
|
|
@@ -77228,13 +77280,12 @@ class TinyCertCrypto {
|
|
|
77228
77280
|
* or `'unknown'` if the format is not recognized.
|
|
77229
77281
|
*
|
|
77230
77282
|
* @param {string} pemString - The PEM string to inspect.
|
|
77231
|
-
* @returns {
|
|
77232
|
-
* @private
|
|
77283
|
+
* @returns {string} The detected PEM type.
|
|
77233
77284
|
*/
|
|
77234
77285
|
#detectPemType(pemString) {
|
|
77235
77286
|
if (this.#certRegex.test(pemString)) return 'certificate';
|
|
77236
77287
|
const keyMatch = this.#keyRegex.exec(pemString);
|
|
77237
|
-
if (keyMatch) return keyMatch[1].toLowerCase() + '_key'; // "public_key" or "private_key"
|
|
77288
|
+
if (keyMatch && typeof keyMatch[1] === 'string') return keyMatch[1].toLowerCase() + '_key'; // "public_key" or "private_key"
|
|
77238
77289
|
return 'unknown';
|
|
77239
77290
|
}
|
|
77240
77291
|
|
|
@@ -77244,13 +77295,9 @@ class TinyCertCrypto {
|
|
|
77244
77295
|
* This method can only be used in Node.js environments. It throws an error if a certificate
|
|
77245
77296
|
* or key is already loaded into the instance.
|
|
77246
77297
|
*
|
|
77247
|
-
* @param {Object} subjectFields - An object representing the subject fields of the certificate (e.g., CN, O, C).
|
|
77298
|
+
* @param {Object<string, string>} subjectFields - An object representing the subject fields of the certificate (e.g., CN, O, C).
|
|
77248
77299
|
* @param {Object} [options={}] - Optional configuration for key and certificate generation.
|
|
77249
77300
|
* @param {number} [options.modulusLength=2048] - Length of the RSA key in bits.
|
|
77250
|
-
* @param {Object} [options.publicKeyEncoding={ type: 'spki', format: 'pem' }] - Options for public key encoding.
|
|
77251
|
-
* @param {Object} [options.privateKeyEncoding={ type: 'pkcs8', format: 'pem' }] - Options for private key encoding.
|
|
77252
|
-
* @param {string} [options.publicKeyType] - Overrides `publicKeyEncoding.type` if provided.
|
|
77253
|
-
* @param {string} [options.privateKeyType] - Overrides `privateKeyEncoding.type` if provided.
|
|
77254
77301
|
* @param {number} [options.validityInYears=1] - Number of years the certificate will be valid.
|
|
77255
77302
|
* @param {number} [options.randomBytesLength=16] - Number of random bytes to use for serial number generation.
|
|
77256
77303
|
*
|
|
@@ -77263,34 +77310,26 @@ class TinyCertCrypto {
|
|
|
77263
77310
|
throw new Error('A certificate is already loaded into the instance.');
|
|
77264
77311
|
|
|
77265
77312
|
// Prepare cert
|
|
77313
|
+
/** @type {any} */
|
|
77266
77314
|
const { pki } = await this.#fetchNodeForge();
|
|
77267
|
-
const {
|
|
77268
|
-
modulusLength = 2048,
|
|
77269
|
-
publicKeyEncoding = { type: 'spki', format: 'pem' },
|
|
77270
|
-
privateKeyEncoding = { type: 'pkcs8', format: 'pem' },
|
|
77271
|
-
validityInYears = 1,
|
|
77272
|
-
randomBytesLength = 16,
|
|
77273
|
-
} = options;
|
|
77274
|
-
|
|
77275
|
-
// Value types
|
|
77276
|
-
const publicKeyType = options.publicKeyType || publicKeyEncoding.type;
|
|
77277
|
-
const privateKeyType = options.privateKeyType || privateKeyEncoding.type;
|
|
77278
77315
|
|
|
77279
|
-
|
|
77280
|
-
|
|
77316
|
+
/**
|
|
77317
|
+
* @property {number} [modulusLength=2048] - The length of the RSA modulus (in bits). Default is 2048.
|
|
77318
|
+
* @property {number} [validityInYears=1] - The validity period of the key pair in years. Default is 1 year.
|
|
77319
|
+
* @property {number} [randomBytesLength=16] - The length of random bytes used in key generation. Default is 16 bytes.
|
|
77320
|
+
*/
|
|
77321
|
+
const { modulusLength = 2048, validityInYears = 1, randomBytesLength = 16 } = options;
|
|
77281
77322
|
|
|
77282
77323
|
// Generate keys
|
|
77283
|
-
const { publicKey, privateKey } =
|
|
77284
|
-
|
|
77285
|
-
|
|
77286
|
-
privateKeyEncoding: { ...privateKeyEncoding, type: privateKeyType },
|
|
77287
|
-
});
|
|
77324
|
+
const { publicKey, privateKey } = pki.rsa.generateKeyPair(modulusLength);
|
|
77325
|
+
const encodedPublicKey = pki.publicKeyToPem(publicKey);
|
|
77326
|
+
const encodedPrivateKey = pki.privateKeyToPem(privateKey);
|
|
77288
77327
|
|
|
77289
77328
|
// Get pem files
|
|
77290
77329
|
const { cert, publicPem, privatePem } = this.#generateCertificate(
|
|
77291
77330
|
subjectFields,
|
|
77292
|
-
|
|
77293
|
-
|
|
77331
|
+
encodedPublicKey,
|
|
77332
|
+
encodedPrivateKey,
|
|
77294
77333
|
validityInYears,
|
|
77295
77334
|
randomBytesLength,
|
|
77296
77335
|
);
|
|
@@ -77302,26 +77341,33 @@ class TinyCertCrypto {
|
|
|
77302
77341
|
this.publicCertPath = 'MEMORY';
|
|
77303
77342
|
this.privateKeyPath = 'MEMORY';
|
|
77304
77343
|
this.source = 'memory';
|
|
77305
|
-
this.publicCertBuffer =
|
|
77306
|
-
this.privateKeyBuffer =
|
|
77344
|
+
this.publicCertBuffer = buffer.Buffer.from(encodedPublicKey);
|
|
77345
|
+
this.privateKeyBuffer = buffer.Buffer.from(encodedPrivateKey);
|
|
77307
77346
|
|
|
77308
77347
|
this.#loadX509Certificate(cert);
|
|
77309
|
-
return { publicKey, privateKey, cert };
|
|
77348
|
+
return { publicKey: encodedPublicKey, privateKey: encodedPrivateKey, cert };
|
|
77310
77349
|
}
|
|
77311
77350
|
|
|
77351
|
+
/**
|
|
77352
|
+
* @typedef {Object} CertificateDetails
|
|
77353
|
+
* @property {string} cert - The certificate in PEM format.
|
|
77354
|
+
* @property {string} publicPem - The public key in PEM format.
|
|
77355
|
+
* @property {string} privatePem - The private key in PEM format.
|
|
77356
|
+
*/
|
|
77357
|
+
|
|
77312
77358
|
/**
|
|
77313
77359
|
* Generates a self-signed X.509 certificate using the given public and private RSA keys.
|
|
77314
77360
|
*
|
|
77315
77361
|
* This method creates a certificate, assigns the subject and issuer fields,
|
|
77316
77362
|
* sets the validity period, and signs it with the private key.
|
|
77317
77363
|
*
|
|
77318
|
-
* @param {Object} subject - An object representing the subject/issuer fields (e.g., { CN: 'example.com' }).
|
|
77364
|
+
* @param {Object<string, string>} subject - An object representing the subject/issuer fields (e.g., { CN: 'example.com' }).
|
|
77319
77365
|
* @param {string} publicKey - The public key in PEM format.
|
|
77320
77366
|
* @param {string} privateKey - The private key in PEM format.
|
|
77321
77367
|
* @param {number} validityInYears - Number of years the certificate will remain valid.
|
|
77322
77368
|
* @param {number} randomBytesLength - Number of random bytes used to generate the serial number.
|
|
77323
77369
|
*
|
|
77324
|
-
* @returns {
|
|
77370
|
+
* @returns {CertificateDetails} An object containing:
|
|
77325
77371
|
* - {string} cert: The generated certificate in PEM format.
|
|
77326
77372
|
* - {Object} publicPem: The parsed public key object (from node-forge).
|
|
77327
77373
|
* - {Object} privatePem: The parsed private key object (from node-forge).
|
|
@@ -77333,7 +77379,9 @@ class TinyCertCrypto {
|
|
|
77333
77379
|
const privatePem = pki.privateKeyFromPem(privateKey);
|
|
77334
77380
|
|
|
77335
77381
|
cert.publicKey = publicPem;
|
|
77336
|
-
cert.serialNumber = buffer.Buffer.from(
|
|
77382
|
+
cert.serialNumber = buffer.Buffer.from(this.forge.random.getBytesSync(randomBytesLength)).toString(
|
|
77383
|
+
'hex',
|
|
77384
|
+
);
|
|
77337
77385
|
cert.validity.notBefore = new Date();
|
|
77338
77386
|
cert.validity.notAfter = new Date();
|
|
77339
77387
|
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + validityInYears);
|
|
@@ -77374,8 +77422,21 @@ class TinyCertCrypto {
|
|
|
77374
77422
|
|
|
77375
77423
|
// Load public key
|
|
77376
77424
|
this.metadata = {};
|
|
77425
|
+
/** @type {any} */
|
|
77377
77426
|
const { pki } = await this.#fetchNodeForge();
|
|
77427
|
+
|
|
77428
|
+
/**
|
|
77429
|
+
* Loads the public key from a PEM-encoded certificate or public key.
|
|
77430
|
+
*
|
|
77431
|
+
* @param {string|null} publicPem - The PEM-encoded public key or certificate.
|
|
77432
|
+
* @throws {Error} If the PEM string is not recognized or if the key cannot be parsed.
|
|
77433
|
+
*/
|
|
77378
77434
|
const loadPublicKey = (publicPem) => {
|
|
77435
|
+
if (typeof publicPem !== 'string')
|
|
77436
|
+
throw new Error(
|
|
77437
|
+
'Expected publicPem to be a string containing a PEM-encoded key or certificate.',
|
|
77438
|
+
);
|
|
77439
|
+
|
|
77379
77440
|
// File type
|
|
77380
77441
|
const fileType = this.#detectPemType(publicPem);
|
|
77381
77442
|
|
|
@@ -77391,12 +77452,29 @@ class TinyCertCrypto {
|
|
|
77391
77452
|
else throw new Error('Public key is required to initialize');
|
|
77392
77453
|
};
|
|
77393
77454
|
|
|
77455
|
+
/**
|
|
77456
|
+
* Loads the private key from a PEM-encoded private key.
|
|
77457
|
+
*
|
|
77458
|
+
* @param {string|null} privatePem - The PEM-encoded private key.
|
|
77459
|
+
* @throws {Error} If the PEM string is not recognized or if the key cannot be parsed.
|
|
77460
|
+
*/
|
|
77394
77461
|
const loadPrivateKey = (privatePem) => {
|
|
77462
|
+
if (typeof privatePem !== 'string')
|
|
77463
|
+
throw new Error('Expected privatePem to be a string containing a PEM-encoded private key.');
|
|
77395
77464
|
const fileType = this.#detectPemType(privatePem);
|
|
77396
77465
|
if (fileType === 'private_key') this.privateKey = pki.privateKeyFromPem(privatePem);
|
|
77397
77466
|
else throw new Error('Private key is required to initialize');
|
|
77398
77467
|
};
|
|
77399
77468
|
|
|
77469
|
+
if (typeof this.publicCertPath !== 'string')
|
|
77470
|
+
throw new TypeError(
|
|
77471
|
+
`Expected 'publicCertPath' to be a string, but got ${typeof this.publicCertPath}`,
|
|
77472
|
+
);
|
|
77473
|
+
if (typeof this.privateKeyPath !== 'string')
|
|
77474
|
+
throw new TypeError(
|
|
77475
|
+
`Expected 'privateKeyPath' to be a string, but got ${typeof this.privateKeyPath}`,
|
|
77476
|
+
);
|
|
77477
|
+
|
|
77400
77478
|
// Nodejs
|
|
77401
77479
|
if (!TinyCertCrypto_isBrowser) {
|
|
77402
77480
|
const usedPublicBuffer = !!this.publicCertBuffer;
|
|
@@ -77406,7 +77484,9 @@ class TinyCertCrypto {
|
|
|
77406
77484
|
const publicPem = usedPublicBuffer
|
|
77407
77485
|
? typeof this.publicCertBuffer === 'string'
|
|
77408
77486
|
? this.publicCertBuffer
|
|
77409
|
-
: this.publicCertBuffer
|
|
77487
|
+
: buffer.Buffer.isBuffer(this.publicCertBuffer)
|
|
77488
|
+
? this.publicCertBuffer.toString('utf-8')
|
|
77489
|
+
: null
|
|
77410
77490
|
: fs_ignored_.readFileSync(this.publicCertPath, 'utf-8');
|
|
77411
77491
|
loadPublicKey(publicPem);
|
|
77412
77492
|
|
|
@@ -77415,7 +77495,9 @@ class TinyCertCrypto {
|
|
|
77415
77495
|
const privatePem = usedPrivateBuffer
|
|
77416
77496
|
? typeof this.privateKeyBuffer === 'string'
|
|
77417
77497
|
? this.privateKeyBuffer
|
|
77418
|
-
: this.privateKeyBuffer
|
|
77498
|
+
: buffer.Buffer.isBuffer(this.privateKeyBuffer)
|
|
77499
|
+
? this.privateKeyBuffer.toString('utf-8')
|
|
77500
|
+
: null
|
|
77419
77501
|
: fs_ignored_.readFileSync(this.privateKeyPath, 'utf-8');
|
|
77420
77502
|
|
|
77421
77503
|
loadPrivateKey(privatePem);
|
|
@@ -77457,7 +77539,6 @@ class TinyCertCrypto {
|
|
|
77457
77539
|
* This method supports both PEM strings and already-parsed Forge certificate objects.
|
|
77458
77540
|
* The parsed certificate is saved to `this.publicCert` and its metadata is extracted to `this.metadata`.
|
|
77459
77541
|
*
|
|
77460
|
-
* @private
|
|
77461
77542
|
* @param {string|object} certPem - A PEM-encoded certificate string or a `forge.pki.Certificate` object.
|
|
77462
77543
|
* @throws {Error} If the certificate cannot be parsed or processed.
|
|
77463
77544
|
*/
|
|
@@ -77467,8 +77548,21 @@ class TinyCertCrypto {
|
|
|
77467
77548
|
const cert = typeof certPem === 'string' ? pki.certificateFromPem(certPem) : certPem;
|
|
77468
77549
|
this.publicCert = cert;
|
|
77469
77550
|
|
|
77551
|
+
/**
|
|
77552
|
+
* @typedef {Object} Attribute
|
|
77553
|
+
* @property {string} name - The name of the attribute.
|
|
77554
|
+
* @property {string} shortName - The short name of the attribute.
|
|
77555
|
+
* @property {string} value - The value of the attribute.
|
|
77556
|
+
*/
|
|
77557
|
+
|
|
77558
|
+
/**
|
|
77559
|
+
* @param {Array<Attribute>} attributes - The list of attributes, each containing `name`, `shortName`, and `value`.
|
|
77560
|
+
* @returns {{names: { [key: string]: string }, shortNames: { [key: string]: string }, raw: string}} The processed data containing the organized attributes.
|
|
77561
|
+
*/
|
|
77470
77562
|
const insertData = (attributes) => {
|
|
77563
|
+
/** @type {{[key: string]: string}} */
|
|
77471
77564
|
const names = {};
|
|
77565
|
+
/** @type {{[key: string]: string}} */
|
|
77472
77566
|
const shortNames = {};
|
|
77473
77567
|
const raw = attributes.map((attr) => `${attr.shortName}=${attr.value}`).join(',');
|
|
77474
77568
|
for (const item of attributes) {
|
|
@@ -77486,7 +77580,9 @@ class TinyCertCrypto {
|
|
|
77486
77580
|
validTo: cert.validity.notAfter,
|
|
77487
77581
|
};
|
|
77488
77582
|
} catch (err) {
|
|
77489
|
-
throw new Error(
|
|
77583
|
+
throw new Error(
|
|
77584
|
+
`Failed to parse X.509 certificate in browser: ${err instanceof Error && typeof err.message === 'string' ? err.message : 'Unknown error'}`,
|
|
77585
|
+
);
|
|
77490
77586
|
}
|
|
77491
77587
|
}
|
|
77492
77588
|
|