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/cjs/index.js
CHANGED
|
@@ -7,7 +7,6 @@ var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
|
|
|
7
7
|
var reactFontawesome = require('@fortawesome/react-fontawesome');
|
|
8
8
|
var ReactDOM = require('react-dom');
|
|
9
9
|
var freeRegularSvgIcons = require('@fortawesome/free-regular-svg-icons');
|
|
10
|
-
var Cryptr = require('cryptr');
|
|
11
10
|
var qs = require('qs');
|
|
12
11
|
var punycode = require('punycode');
|
|
13
12
|
|
|
@@ -49,7 +48,6 @@ function _mergeNamespaces(n, m) {
|
|
|
49
48
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
50
49
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
51
50
|
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
52
|
-
var Cryptr__default = /*#__PURE__*/_interopDefaultLegacy(Cryptr);
|
|
53
51
|
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
54
52
|
var punycode__default = /*#__PURE__*/_interopDefaultLegacy(punycode);
|
|
55
53
|
|
|
@@ -14730,6 +14728,24 @@ const getOauthLib = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14730
14728
|
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);
|
|
14731
14729
|
}
|
|
14732
14730
|
});
|
|
14731
|
+
/**
|
|
14732
|
+
* Get a copy of the crypto lib
|
|
14733
|
+
* @author Gabe Abrams
|
|
14734
|
+
* @return the crypto lib
|
|
14735
|
+
*/
|
|
14736
|
+
const getCryptoLib = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14737
|
+
// Get the crypto library (included on the server)
|
|
14738
|
+
// Ignore because this is assumed to be included with typescript
|
|
14739
|
+
// @ts-ignore
|
|
14740
|
+
try {
|
|
14741
|
+
// @ts-ignore
|
|
14742
|
+
const crypto = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('crypto-browserify')); });
|
|
14743
|
+
return crypto;
|
|
14744
|
+
}
|
|
14745
|
+
catch (err) {
|
|
14746
|
+
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);
|
|
14747
|
+
}
|
|
14748
|
+
});
|
|
14733
14749
|
/*------------------------------------------------------------------------*/
|
|
14734
14750
|
/* ------------------------------- Helpers ------------------------------ */
|
|
14735
14751
|
/*------------------------------------------------------------------------*/
|
|
@@ -14770,14 +14786,24 @@ const genSignature = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
14770
14786
|
* @return the decrypted string
|
|
14771
14787
|
*/
|
|
14772
14788
|
const decrypt = (encryptedPack) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14789
|
+
// Decryption process based on:
|
|
14790
|
+
// https://medium.com/@tony.infisical/guide-to-nodes-crypto-module-for-encryption-decryption-65c077176980
|
|
14773
14791
|
// Get the encryption secret
|
|
14774
14792
|
const { REACTKIT_CRED_ENCODING_SALT } = process.env;
|
|
14775
14793
|
if (!REACTKIT_CRED_ENCODING_SALT) {
|
|
14776
14794
|
throw new ErrorWithCode('Could not decrypt a string because the encryption salt was not set.', ReactKitErrorCode$1.CrossServerNoCredentialEncodingSalt);
|
|
14777
14795
|
}
|
|
14796
|
+
// Get the crypto library
|
|
14797
|
+
const crypto = yield getCryptoLib();
|
|
14798
|
+
// Separate encrypted pack
|
|
14799
|
+
const { ciphertext, iv, tag, } = JSON.parse(decodeURIComponent(encryptedPack));
|
|
14800
|
+
// Parse the encrypted data
|
|
14801
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(REACTKIT_CRED_ENCODING_SALT, 'base64'), Buffer.from(iv, 'base64'));
|
|
14802
|
+
// Set the authentication tag
|
|
14803
|
+
decipher.setAuthTag(Buffer.from(tag, 'base64'));
|
|
14778
14804
|
// Decrypt the string
|
|
14779
|
-
|
|
14780
|
-
|
|
14805
|
+
let str = decipher.update(ciphertext, 'base64', 'utf8');
|
|
14806
|
+
str += decipher.final('utf8');
|
|
14781
14807
|
// Return the decrypted string
|
|
14782
14808
|
return str;
|
|
14783
14809
|
});
|