dce-reactkit 3.12.1-beta-cross-server.4 → 3.12.1-beta-cross-server.5
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 +30 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +30 -3
- package/dist/esm/index.js.map +1 -1
- package/genEncodedSecret.ts +30 -5
- package/package.json +2 -1
- package/src/helpers/dataSigner.ts +46 -5
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,6 @@ 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';
|
|
8
7
|
import qs from 'qs';
|
|
9
8
|
import punycode from 'punycode';
|
|
10
9
|
|
|
@@ -14700,6 +14699,24 @@ const getOauthLib = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14700
14699
|
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);
|
|
14701
14700
|
}
|
|
14702
14701
|
});
|
|
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
|
+
// @ts-ignore
|
|
14713
|
+
const crypto = yield import('crypto-browserify');
|
|
14714
|
+
return crypto;
|
|
14715
|
+
}
|
|
14716
|
+
catch (err) {
|
|
14717
|
+
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);
|
|
14718
|
+
}
|
|
14719
|
+
});
|
|
14703
14720
|
/*------------------------------------------------------------------------*/
|
|
14704
14721
|
/* ------------------------------- Helpers ------------------------------ */
|
|
14705
14722
|
/*------------------------------------------------------------------------*/
|
|
@@ -14740,14 +14757,24 @@ const genSignature = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14740
14757
|
* @return the decrypted string
|
|
14741
14758
|
*/
|
|
14742
14759
|
const decrypt = (encryptedPack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14760
|
+
// Decryption process based on:
|
|
14761
|
+
// https://medium.com/@tony.infisical/guide-to-nodes-crypto-module-for-encryption-decryption-65c077176980
|
|
14743
14762
|
// Get the encryption secret
|
|
14744
14763
|
const { REACTKIT_CRED_ENCODING_SALT } = process.env;
|
|
14745
14764
|
if (!REACTKIT_CRED_ENCODING_SALT) {
|
|
14746
14765
|
throw new ErrorWithCode('Could not decrypt a string because the encryption salt was not set.', ReactKitErrorCode$1.CrossServerNoCredentialEncodingSalt);
|
|
14747
14766
|
}
|
|
14767
|
+
// Get the crypto library
|
|
14768
|
+
const crypto = yield getCryptoLib();
|
|
14769
|
+
// Separate encrypted pack
|
|
14770
|
+
const { ciphertext, iv, tag, } = JSON.parse(decodeURIComponent(encryptedPack));
|
|
14771
|
+
// Parse the encrypted data
|
|
14772
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(REACTKIT_CRED_ENCODING_SALT, 'base64'), Buffer.from(iv, 'base64'));
|
|
14773
|
+
// Set the authentication tag
|
|
14774
|
+
decipher.setAuthTag(Buffer.from(tag, 'base64'));
|
|
14748
14775
|
// Decrypt the string
|
|
14749
|
-
|
|
14750
|
-
|
|
14776
|
+
let str = decipher.update(ciphertext, 'base64', 'utf8');
|
|
14777
|
+
str += decipher.final('utf8');
|
|
14751
14778
|
// Return the decrypted string
|
|
14752
14779
|
return str;
|
|
14753
14780
|
});
|