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