dce-reactkit 3.12.1-beta-cross-server.3 → 3.12.1-beta-cross-server.4
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/cjs/index.js +4 -29
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +3 -29
- package/dist/esm/index.js.map +1 -1
- package/genEncodedSecret.ts +6 -31
- package/package.json +2 -1
- package/src/helpers/dataSigner.ts +5 -45
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { faExclamationTriangle, faHourglassEnd, faCircle, faDotCircle, faCheckSq
|
|
|
4
4
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
5
5
|
import ReactDOM, { createPortal } from 'react-dom';
|
|
6
6
|
import { faCircle as faCircle$1, faSquareMinus, faSquare } from '@fortawesome/free-regular-svg-icons';
|
|
7
|
+
import Cryptr from 'cryptr';
|
|
7
8
|
import qs from 'qs';
|
|
8
9
|
import punycode from 'punycode';
|
|
9
10
|
|
|
@@ -14699,23 +14700,6 @@ const getOauthLib = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14699
14700
|
throw new ErrorWithCode('Could not sign a cross-server request because we could not load the oauth library. Please make sure this app has caccl as one of its dependencies.', ReactKitErrorCode$1.NoOauthLib);
|
|
14700
14701
|
}
|
|
14701
14702
|
});
|
|
14702
|
-
/**
|
|
14703
|
-
* Get a copy of the crypto lib
|
|
14704
|
-
* @author Gabe Abrams
|
|
14705
|
-
* @return the crypto lib
|
|
14706
|
-
*/
|
|
14707
|
-
const getCryptoLib = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14708
|
-
// Get the crypto library (included on the server)
|
|
14709
|
-
// Ignore because this is assumed to be included with typescript
|
|
14710
|
-
// @ts-ignore
|
|
14711
|
-
try {
|
|
14712
|
-
const crypto = yield import('crypto');
|
|
14713
|
-
return crypto;
|
|
14714
|
-
}
|
|
14715
|
-
catch (err) {
|
|
14716
|
-
throw new ErrorWithCode('Could not sign a cross-server request because we could not load the crypto library. Please make sure this operation is running on the server.', ReactKitErrorCode$1.NoCryptoLib);
|
|
14717
|
-
}
|
|
14718
|
-
});
|
|
14719
14703
|
/*------------------------------------------------------------------------*/
|
|
14720
14704
|
/* ------------------------------- Helpers ------------------------------ */
|
|
14721
14705
|
/*------------------------------------------------------------------------*/
|
|
@@ -14756,24 +14740,14 @@ const genSignature = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14756
14740
|
* @return the decrypted string
|
|
14757
14741
|
*/
|
|
14758
14742
|
const decrypt = (encryptedPack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14759
|
-
// Decryption process based on:
|
|
14760
|
-
// https://medium.com/@tony.infisical/guide-to-nodes-crypto-module-for-encryption-decryption-65c077176980
|
|
14761
14743
|
// Get the encryption secret
|
|
14762
14744
|
const { REACTKIT_CRED_ENCODING_SALT } = process.env;
|
|
14763
14745
|
if (!REACTKIT_CRED_ENCODING_SALT) {
|
|
14764
14746
|
throw new ErrorWithCode('Could not decrypt a string because the encryption salt was not set.', ReactKitErrorCode$1.CrossServerNoCredentialEncodingSalt);
|
|
14765
14747
|
}
|
|
14766
|
-
// Get the crypto library
|
|
14767
|
-
const crypto = yield getCryptoLib();
|
|
14768
|
-
// Separate encrypted pack
|
|
14769
|
-
const { ciphertext, iv, tag, } = JSON.parse(decodeURIComponent(encryptedPack));
|
|
14770
|
-
// Parse the encrypted data
|
|
14771
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(REACTKIT_CRED_ENCODING_SALT, 'base64'), Buffer.from(iv, 'base64'));
|
|
14772
|
-
// Set the authentication tag
|
|
14773
|
-
decipher.setAuthTag(Buffer.from(tag, 'base64'));
|
|
14774
14748
|
// Decrypt the string
|
|
14775
|
-
|
|
14776
|
-
str
|
|
14749
|
+
const cryptr = new Cryptr(REACTKIT_CRED_ENCODING_SALT);
|
|
14750
|
+
const str = cryptr.decrypt(encryptedPack);
|
|
14777
14751
|
// Return the decrypted string
|
|
14778
14752
|
return str;
|
|
14779
14753
|
});
|