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/TinyCrypto.js
CHANGED
|
@@ -7692,16 +7692,17 @@ module.exports = pbkdf2
|
|
|
7692
7692
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7693
7693
|
|
|
7694
7694
|
"use strict";
|
|
7695
|
+
var __webpack_unused_export__;
|
|
7695
7696
|
|
|
7696
7697
|
|
|
7697
7698
|
// eslint-disable-next-line no-multi-assign
|
|
7698
|
-
exports.
|
|
7699
|
+
exports.po = __webpack_unused_export__ = __webpack_unused_export__ = /* unused reexport */ __webpack_require__(3209);
|
|
7699
7700
|
|
|
7700
7701
|
// eslint-disable-next-line no-multi-assign
|
|
7701
|
-
|
|
7702
|
+
__webpack_unused_export__ = /* unused reexport */ __webpack_require__(7108);
|
|
7702
7703
|
|
|
7703
7704
|
// eslint-disable-next-line no-multi-assign
|
|
7704
|
-
|
|
7705
|
+
__webpack_unused_export__ = /* unused reexport */ __webpack_require__(3507);
|
|
7705
7706
|
|
|
7706
7707
|
var algos = __webpack_require__(5715);
|
|
7707
7708
|
var algoKeys = Object.keys(algos);
|
|
@@ -7715,50 +7716,50 @@ var hashes = [
|
|
|
7715
7716
|
'rmd160'
|
|
7716
7717
|
].concat(algoKeys);
|
|
7717
7718
|
|
|
7718
|
-
|
|
7719
|
+
__webpack_unused_export__ = function () {
|
|
7719
7720
|
return hashes;
|
|
7720
7721
|
};
|
|
7721
7722
|
|
|
7722
7723
|
var p = __webpack_require__(8396);
|
|
7723
|
-
|
|
7724
|
-
|
|
7724
|
+
__webpack_unused_export__ = p.pbkdf2;
|
|
7725
|
+
__webpack_unused_export__ = p.pbkdf2Sync;
|
|
7725
7726
|
|
|
7726
7727
|
var aes = __webpack_require__(125);
|
|
7727
7728
|
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
exports.
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
exports.
|
|
7736
|
-
|
|
7737
|
-
|
|
7729
|
+
__webpack_unused_export__ = aes.Cipher;
|
|
7730
|
+
__webpack_unused_export__ = aes.createCipher;
|
|
7731
|
+
__webpack_unused_export__ = aes.Cipheriv;
|
|
7732
|
+
exports.Tt = aes.createCipheriv;
|
|
7733
|
+
__webpack_unused_export__ = aes.Decipher;
|
|
7734
|
+
__webpack_unused_export__ = aes.createDecipher;
|
|
7735
|
+
__webpack_unused_export__ = aes.Decipheriv;
|
|
7736
|
+
exports._7 = aes.createDecipheriv;
|
|
7737
|
+
__webpack_unused_export__ = aes.getCiphers;
|
|
7738
|
+
__webpack_unused_export__ = aes.listCiphers;
|
|
7738
7739
|
|
|
7739
7740
|
var dh = __webpack_require__(5380);
|
|
7740
7741
|
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7742
|
+
__webpack_unused_export__ = dh.DiffieHellmanGroup;
|
|
7743
|
+
__webpack_unused_export__ = dh.createDiffieHellmanGroup;
|
|
7744
|
+
__webpack_unused_export__ = dh.getDiffieHellman;
|
|
7745
|
+
__webpack_unused_export__ = dh.createDiffieHellman;
|
|
7746
|
+
__webpack_unused_export__ = dh.DiffieHellman;
|
|
7746
7747
|
|
|
7747
7748
|
var sign = __webpack_require__(20);
|
|
7748
7749
|
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7750
|
+
__webpack_unused_export__ = sign.createSign;
|
|
7751
|
+
__webpack_unused_export__ = sign.Sign;
|
|
7752
|
+
__webpack_unused_export__ = sign.createVerify;
|
|
7753
|
+
__webpack_unused_export__ = sign.Verify;
|
|
7753
7754
|
|
|
7754
|
-
|
|
7755
|
+
/* unused reexport */ __webpack_require__(1324);
|
|
7755
7756
|
|
|
7756
7757
|
var publicEncrypt = __webpack_require__(7168);
|
|
7757
7758
|
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7759
|
+
__webpack_unused_export__ = publicEncrypt.publicEncrypt;
|
|
7760
|
+
__webpack_unused_export__ = publicEncrypt.privateEncrypt;
|
|
7761
|
+
__webpack_unused_export__ = publicEncrypt.publicDecrypt;
|
|
7762
|
+
__webpack_unused_export__ = publicEncrypt.privateDecrypt;
|
|
7762
7763
|
|
|
7763
7764
|
// the least I can do is make error messages for the rest of the node.js/crypto api.
|
|
7764
7765
|
// [
|
|
@@ -7771,14 +7772,14 @@ exports.privateDecrypt = publicEncrypt.privateDecrypt;
|
|
|
7771
7772
|
|
|
7772
7773
|
var rf = __webpack_require__(6983);
|
|
7773
7774
|
|
|
7774
|
-
|
|
7775
|
-
|
|
7775
|
+
__webpack_unused_export__ = rf.randomFill;
|
|
7776
|
+
__webpack_unused_export__ = rf.randomFillSync;
|
|
7776
7777
|
|
|
7777
|
-
|
|
7778
|
+
__webpack_unused_export__ = function () {
|
|
7778
7779
|
throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
|
|
7779
7780
|
};
|
|
7780
7781
|
|
|
7781
|
-
|
|
7782
|
+
__webpack_unused_export__ = {
|
|
7782
7783
|
DH_CHECK_P_NOT_SAFE_PRIME: 2,
|
|
7783
7784
|
DH_CHECK_P_NOT_PRIME: 1,
|
|
7784
7785
|
DH_UNABLE_TO_CHECK_GENERATOR: 4,
|
|
@@ -47326,6 +47327,9 @@ const typeValidator = {
|
|
|
47326
47327
|
/** Checks if the value is a Buffer. */
|
|
47327
47328
|
buffer: (val) => typeof buffer.Buffer !== 'undefined' && buffer.Buffer.isBuffer(val),
|
|
47328
47329
|
|
|
47330
|
+
/** Checks if the value is a File. */
|
|
47331
|
+
file: (val) => typeof File !== 'undefined' && val instanceof File,
|
|
47332
|
+
|
|
47329
47333
|
/** Checks if the value is a Html Element. */
|
|
47330
47334
|
htmlelement: (val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
47331
47335
|
|
|
@@ -47345,6 +47349,7 @@ const typeValidator = {
|
|
|
47345
47349
|
'function',
|
|
47346
47350
|
'array',
|
|
47347
47351
|
'buffer',
|
|
47352
|
+
'file',
|
|
47348
47353
|
'date',
|
|
47349
47354
|
'regexp',
|
|
47350
47355
|
'map',
|
|
@@ -47531,8 +47536,8 @@ class TinyCrypto {
|
|
|
47531
47536
|
*
|
|
47532
47537
|
* @param {Object} [options={}] - Configuration options for encryption and decryption.
|
|
47533
47538
|
* @param {string} [options.algorithm='aes-256-gcm'] - The encryption algorithm to use. Recommended: 'aes-256-gcm' for authenticated encryption.
|
|
47534
|
-
* @param {
|
|
47535
|
-
* @param {
|
|
47539
|
+
* @param {BufferEncoding} [options.outputEncoding='hex'] - The encoding used when returning encrypted data (e.g., 'hex', 'base64').
|
|
47540
|
+
* @param {BufferEncoding} [options.inputEncoding='utf8'] - The encoding used for plaintext inputs (e.g., 'utf8').
|
|
47536
47541
|
* @param {number} [options.authTagLength=16] - The length of the authentication tag used in GCM mode. Usually 16 for AES-256-GCM.
|
|
47537
47542
|
* @param {Buffer} [options.key] - Optional 32-byte cryptographic key. If not provided, a random key is generated.
|
|
47538
47543
|
*
|
|
@@ -47542,15 +47547,17 @@ class TinyCrypto {
|
|
|
47542
47547
|
* const crypto = new CryptoManager({
|
|
47543
47548
|
* algorithm: 'aes-256-gcm',
|
|
47544
47549
|
* outputEncoding: 'base64',
|
|
47545
|
-
* key:
|
|
47550
|
+
* key: randomBytes(32),
|
|
47546
47551
|
* });
|
|
47547
47552
|
*/
|
|
47548
47553
|
constructor(options = {}) {
|
|
47549
47554
|
this.algorithm = options.algorithm || 'aes-256-gcm';
|
|
47550
|
-
this.outputEncoding = options.outputEncoding || 'hex';
|
|
47551
|
-
this.inputEncoding = options.inputEncoding || 'utf8';
|
|
47552
47555
|
this.authTagLength = options.authTagLength || 16;
|
|
47553
47556
|
this.key = options.key || this.generateKey();
|
|
47557
|
+
/** @type {BufferEncoding} */
|
|
47558
|
+
this.outputEncoding = options.outputEncoding || 'hex';
|
|
47559
|
+
/** @type {BufferEncoding} */
|
|
47560
|
+
this.inputEncoding = options.inputEncoding || 'utf8';
|
|
47554
47561
|
}
|
|
47555
47562
|
|
|
47556
47563
|
/**
|
|
@@ -47564,7 +47571,7 @@ class TinyCrypto {
|
|
|
47564
47571
|
* const customKey = cryptoManager.generateKey(16); // Generates a 16-byte key (e.g. for AES-128)
|
|
47565
47572
|
*/
|
|
47566
47573
|
generateKey(value = 32) {
|
|
47567
|
-
return crypto_browserify
|
|
47574
|
+
return (0,crypto_browserify/* randomBytes */.po)(value); // 256-bit
|
|
47568
47575
|
}
|
|
47569
47576
|
|
|
47570
47577
|
/**
|
|
@@ -47578,7 +47585,7 @@ class TinyCrypto {
|
|
|
47578
47585
|
* const customIV = cryptoManager.generateIV(16); // Generates a 16-byte IV if needed for other algorithms
|
|
47579
47586
|
*/
|
|
47580
47587
|
generateIV(value = 12) {
|
|
47581
|
-
return crypto_browserify
|
|
47588
|
+
return (0,crypto_browserify/* randomBytes */.po)(value); // 96-bit padrão para GCM
|
|
47582
47589
|
}
|
|
47583
47590
|
|
|
47584
47591
|
/**
|
|
@@ -47588,10 +47595,7 @@ class TinyCrypto {
|
|
|
47588
47595
|
*
|
|
47589
47596
|
* @param {*} data - The data to encrypt. Can be of any supported type (string, number, boolean, Date, JSON, etc.).
|
|
47590
47597
|
* @param {Buffer} [iv=this.generateIV()] - Optional Initialization Vector (IV). If not provided, a secure random IV is generated.
|
|
47591
|
-
* @returns {
|
|
47592
|
-
* - `iv` {string} - The IV used, encoded with the output encoding.
|
|
47593
|
-
* - `encrypted` {string} - The encrypted payload.
|
|
47594
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the ciphertext.
|
|
47598
|
+
* @returns {EncryptedDataParams} An object containing the encrypted data.
|
|
47595
47599
|
*
|
|
47596
47600
|
* @example
|
|
47597
47601
|
* const result = cryptoManager.encrypt('Hello, world!');
|
|
@@ -47604,31 +47608,41 @@ class TinyCrypto {
|
|
|
47604
47608
|
encrypt(data, iv = this.generateIV()) {
|
|
47605
47609
|
const plainText = this.#serialize(data);
|
|
47606
47610
|
|
|
47607
|
-
const cipher = crypto_browserify
|
|
47611
|
+
const cipher = (0,crypto_browserify/* createCipheriv */.Tt)(this.algorithm, this.key, iv, {
|
|
47612
|
+
// @ts-ignore
|
|
47608
47613
|
authTagLength: this.authTagLength,
|
|
47609
47614
|
});
|
|
47610
47615
|
|
|
47616
|
+
// @ts-ignore
|
|
47611
47617
|
let encrypted = cipher.update(plainText, this.inputEncoding);
|
|
47618
|
+
// @ts-ignore
|
|
47612
47619
|
encrypted = buffer.Buffer.concat([encrypted, cipher.final()]);
|
|
47613
47620
|
const authTag = cipher.getAuthTag();
|
|
47614
47621
|
|
|
47615
47622
|
return {
|
|
47623
|
+
// @ts-ignore
|
|
47616
47624
|
iv: iv.toString(this.outputEncoding),
|
|
47625
|
+
// @ts-ignore
|
|
47617
47626
|
encrypted: encrypted.toString(this.outputEncoding),
|
|
47627
|
+
// @ts-ignore
|
|
47618
47628
|
authTag: authTag.toString(this.outputEncoding),
|
|
47619
47629
|
};
|
|
47620
47630
|
}
|
|
47621
47631
|
|
|
47632
|
+
/**
|
|
47633
|
+
* @typedef {Object} EncryptedDataParams
|
|
47634
|
+
* @property {string} iv - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
47635
|
+
* @property {string} encrypted - The encrypted data to decrypt, encoded with the output encoding.
|
|
47636
|
+
* @property {string} authTag - The authentication tag used to verify the integrity of the encrypted data.
|
|
47637
|
+
*/
|
|
47638
|
+
|
|
47622
47639
|
/**
|
|
47623
47640
|
* Decrypts a previously encrypted value.
|
|
47624
47641
|
*
|
|
47625
47642
|
* The method checks the integrity of the data using the authentication tag (`authTag`) and ensures the data is properly decrypted.
|
|
47626
47643
|
* After decryption, it automatically deserializes the data back to its original type.
|
|
47627
47644
|
*
|
|
47628
|
-
* @param {
|
|
47629
|
-
* - `iv` {string} - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
47630
|
-
* - `encrypted` {string} - The encrypted data to decrypt, encoded with the output encoding.
|
|
47631
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the encrypted data.
|
|
47645
|
+
* @param {EncryptedDataParams} params - An object containing the encrypted data.
|
|
47632
47646
|
* @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.
|
|
47633
47647
|
* @returns {*} The decrypted value, which will be the original type of the data before encryption.
|
|
47634
47648
|
* @throws {Error} Throws if the authentication tag doesn't match or the data has been tampered with.
|
|
@@ -47648,13 +47662,17 @@ class TinyCrypto {
|
|
|
47648
47662
|
const encryptedBuffer = buffer.Buffer.from(encrypted, this.outputEncoding);
|
|
47649
47663
|
const authTagBuffer = buffer.Buffer.from(authTag, this.outputEncoding);
|
|
47650
47664
|
|
|
47651
|
-
const decipher = crypto_browserify
|
|
47665
|
+
const decipher = (0,crypto_browserify/* createDecipheriv */._7)(this.algorithm, this.key, ivBuffer, {
|
|
47666
|
+
// @ts-ignore
|
|
47652
47667
|
authTagLength: this.authTagLength,
|
|
47653
47668
|
});
|
|
47654
47669
|
|
|
47655
47670
|
decipher.setAuthTag(authTagBuffer);
|
|
47656
47671
|
|
|
47672
|
+
/** @type {string} */
|
|
47673
|
+
// @ts-ignore
|
|
47657
47674
|
let decrypted = decipher.update(encryptedBuffer, null, this.inputEncoding);
|
|
47675
|
+
// @ts-ignore
|
|
47658
47676
|
decrypted += decipher.final(this.inputEncoding);
|
|
47659
47677
|
const { value, type } = this.#deserialize(decrypted);
|
|
47660
47678
|
|
|
@@ -47668,10 +47686,7 @@ class TinyCrypto {
|
|
|
47668
47686
|
* This method decrypts the encrypted data and extracts its type information without fully deserializing the value.
|
|
47669
47687
|
* It is useful when you need to verify the type of the encrypted data before fully decrypting it.
|
|
47670
47688
|
*
|
|
47671
|
-
* @param {
|
|
47672
|
-
* - `iv` {string} - The Initialization Vector (IV) used in encryption, encoded with the output encoding.
|
|
47673
|
-
* - `encrypted` {string} - The encrypted data to decrypt, encoded with the output encoding.
|
|
47674
|
-
* - `authTag` {string} - The authentication tag used to verify the integrity of the encrypted data.
|
|
47689
|
+
* @param {EncryptedDataParams} params - An object containing the encrypted data.
|
|
47675
47690
|
* @returns {string} The type of the original data (e.g., 'string', 'number', 'date', etc.).
|
|
47676
47691
|
*
|
|
47677
47692
|
* @example
|
|
@@ -47688,13 +47703,16 @@ class TinyCrypto {
|
|
|
47688
47703
|
const encryptedBuffer = buffer.Buffer.from(encrypted, this.outputEncoding);
|
|
47689
47704
|
const authTagBuffer = buffer.Buffer.from(authTag, this.outputEncoding);
|
|
47690
47705
|
|
|
47691
|
-
const decipher = crypto_browserify
|
|
47706
|
+
const decipher = (0,crypto_browserify/* createDecipheriv */._7)(this.algorithm, this.key, ivBuffer, {
|
|
47707
|
+
// @ts-ignore
|
|
47692
47708
|
authTagLength: this.authTagLength,
|
|
47693
47709
|
});
|
|
47694
47710
|
|
|
47695
47711
|
decipher.setAuthTag(authTagBuffer);
|
|
47696
47712
|
|
|
47713
|
+
// @ts-ignore
|
|
47697
47714
|
let decrypted = decipher.update(encryptedBuffer, null, this.inputEncoding);
|
|
47715
|
+
// @ts-ignore
|
|
47698
47716
|
decrypted += decipher.final(this.inputEncoding);
|
|
47699
47717
|
|
|
47700
47718
|
const { type } = this.#deserialize(decrypted);
|
|
@@ -47784,10 +47802,12 @@ class TinyCrypto {
|
|
|
47784
47802
|
async loadConfigFromFile(file) {
|
|
47785
47803
|
if (isBrowser) {
|
|
47786
47804
|
return new Promise((resolve, reject) => {
|
|
47805
|
+
if (!(file instanceof File))
|
|
47806
|
+
return reject(new Error('In browser, the file must be a File object'));
|
|
47787
47807
|
const reader = new FileReader();
|
|
47788
47808
|
reader.onload = () => {
|
|
47789
47809
|
try {
|
|
47790
|
-
const config = JSON.parse(reader.result);
|
|
47810
|
+
const config = typeof reader.result === 'string' ? JSON.parse(reader.result) : {};
|
|
47791
47811
|
resolve(this.importConfig(config));
|
|
47792
47812
|
} catch (err) {
|
|
47793
47813
|
reject(new Error('Invalid config JSON file'));
|
|
@@ -47797,7 +47817,7 @@ class TinyCrypto {
|
|
|
47797
47817
|
reader.readAsText(file);
|
|
47798
47818
|
});
|
|
47799
47819
|
} else {
|
|
47800
|
-
const raw = fs_ignored_.readFileSync(file, 'utf8');
|
|
47820
|
+
const raw = fs_ignored_.readFileSync(/** @type {string} */ (file), 'utf8');
|
|
47801
47821
|
const config = JSON.parse(raw);
|
|
47802
47822
|
return this.importConfig(config);
|
|
47803
47823
|
}
|
|
@@ -47829,9 +47849,11 @@ class TinyCrypto {
|
|
|
47829
47849
|
async loadKeyFromFile(file) {
|
|
47830
47850
|
if (isBrowser) {
|
|
47831
47851
|
return new Promise((resolve, reject) => {
|
|
47852
|
+
if (!(file instanceof File))
|
|
47853
|
+
return reject(new Error('In browser, the file must be a File object'));
|
|
47832
47854
|
const reader = new FileReader();
|
|
47833
47855
|
reader.onload = () => {
|
|
47834
|
-
const hexKey = reader.result.trim();
|
|
47856
|
+
const hexKey = typeof reader.result === 'string' ? reader.result.trim() : '';
|
|
47835
47857
|
const keyBuffer = buffer.Buffer.from(hexKey, 'hex');
|
|
47836
47858
|
this.key = keyBuffer;
|
|
47837
47859
|
resolve(keyBuffer);
|
|
@@ -47840,7 +47862,7 @@ class TinyCrypto {
|
|
|
47840
47862
|
reader.readAsText(file);
|
|
47841
47863
|
});
|
|
47842
47864
|
} else {
|
|
47843
|
-
const hexKey = fs_ignored_.readFileSync(file, 'utf8');
|
|
47865
|
+
const hexKey = fs_ignored_.readFileSync(/** @type {string} */ (file), 'utf8');
|
|
47844
47866
|
const keyBuffer = buffer.Buffer.from(hexKey, 'hex');
|
|
47845
47867
|
this.key = keyBuffer;
|
|
47846
47868
|
return keyBuffer;
|
|
@@ -47886,8 +47908,8 @@ class TinyCrypto {
|
|
|
47886
47908
|
*
|
|
47887
47909
|
* @param {Object} config - The configuration object to import.
|
|
47888
47910
|
* @param {string} config.algorithm - The encryption algorithm (e.g., 'aes-256-gcm').
|
|
47889
|
-
* @param {
|
|
47890
|
-
* @param {
|
|
47911
|
+
* @param {BufferEncoding} config.outputEncoding - The output encoding format (e.g., 'hex').
|
|
47912
|
+
* @param {BufferEncoding} config.inputEncoding - The input encoding format (e.g., 'utf8').
|
|
47891
47913
|
* @param {number} config.authTagLength - The authentication tag length (e.g., 16).
|
|
47892
47914
|
* @param {string} config.key - The cryptographic key in hexadecimal string format.
|
|
47893
47915
|
*
|
|
@@ -47934,7 +47956,7 @@ class TinyCrypto {
|
|
|
47934
47956
|
* Each key corresponds to a specific data type (e.g., 'number', 'date', 'buffer', etc.),
|
|
47935
47957
|
* and the value is a function that serializes the data to a specific format.
|
|
47936
47958
|
*
|
|
47937
|
-
* @type {
|
|
47959
|
+
* @type {Record<string, (data: any) => string>}
|
|
47938
47960
|
* @property {Function} weakmap - Throws an error as WeakMap cannot be serialized.
|
|
47939
47961
|
* @property {Function} weakset - Throws an error as WeakSet cannot be serialized.
|
|
47940
47962
|
* @property {Function} promise - Throws an error as Promise cannot be serialized.
|
|
@@ -47975,8 +47997,8 @@ class TinyCrypto {
|
|
|
47975
47997
|
number: (data) => JSON.stringify({ __type: 'number', value: data }),
|
|
47976
47998
|
boolean: (data) => JSON.stringify({ __type: 'boolean', value: data }),
|
|
47977
47999
|
string: (data) => JSON.stringify({ __type: 'string', value: data }),
|
|
47978
|
-
null: (
|
|
47979
|
-
undefined: (
|
|
48000
|
+
null: () => JSON.stringify({ __type: 'null' }),
|
|
48001
|
+
undefined: () => JSON.stringify({ __type: 'undefined' }),
|
|
47980
48002
|
map: (data) =>
|
|
47981
48003
|
JSON.stringify({
|
|
47982
48004
|
__type: 'map',
|
|
@@ -48001,7 +48023,7 @@ class TinyCrypto {
|
|
|
48001
48023
|
* Each key corresponds to a specific data type (e.g., 'Date', 'BigInt', 'Buffer', etc.),
|
|
48002
48024
|
* and the value is a function that deserializes the value to its original format.
|
|
48003
48025
|
*
|
|
48004
|
-
* @type {
|
|
48026
|
+
* @type {Record<string, (data: any) => any>}
|
|
48005
48027
|
* @property {Function} regexp - Deserializes a regular expression from its string representation (e.g., `/pattern/flags`).
|
|
48006
48028
|
* @property {Function} htmlelement - Deserializes an HTML element from its serialized outerHTML string (only works in browser environments).
|
|
48007
48029
|
* @property {Function} date - Deserializes a date from its ISO string representation.
|
|
@@ -48028,14 +48050,14 @@ class TinyCrypto {
|
|
|
48028
48050
|
throw new Error('HTMLElement deserialization is only supported in browsers');
|
|
48029
48051
|
const div = document.createElement('div');
|
|
48030
48052
|
div.innerHTML = value;
|
|
48031
|
-
return div
|
|
48053
|
+
return div;
|
|
48032
48054
|
},
|
|
48033
48055
|
date: (value) => new Date(value),
|
|
48034
48056
|
bigint: (value) => BigInt(value),
|
|
48035
48057
|
number: (value) => Number(value),
|
|
48036
48058
|
boolean: (value) => Boolean(value),
|
|
48037
|
-
null: (
|
|
48038
|
-
undefined: (
|
|
48059
|
+
null: () => null,
|
|
48060
|
+
undefined: () => undefined,
|
|
48039
48061
|
map: (value) => new Map(value),
|
|
48040
48062
|
set: (value) => new Set(value),
|
|
48041
48063
|
symbol: (value) => Symbol(value),
|
|
@@ -48056,7 +48078,8 @@ class TinyCrypto {
|
|
|
48056
48078
|
*/
|
|
48057
48079
|
#serialize(data) {
|
|
48058
48080
|
const type = objType(data) || 'undefined';
|
|
48059
|
-
if (
|
|
48081
|
+
if (typeof type === 'string' && this.#valueConvertTypes[type])
|
|
48082
|
+
return this.#valueConvertTypes[type](data);
|
|
48060
48083
|
throw new Error(`Unsupported data type for encryption: ${type}`);
|
|
48061
48084
|
}
|
|
48062
48085
|
|