@dotenvx/primitives 0.4.0 → 0.6.0

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.
Files changed (2) hide show
  1. package/dist/index.cjs +27 -7
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -5390,7 +5390,7 @@ var require_compat = __commonJS({
5390
5390
  const isAEAD = algorithm === "aes-256-gcm" || algorithm === "chacha20-poly1305";
5391
5391
  const authTagLength = isAEAD ? AEAD_TAG_LENGTH : 0;
5392
5392
  const options = isAEAD ? { authTagLength } : void 0;
5393
- const encrypt = (plainText) => {
5393
+ const encrypt2 = (plainText) => {
5394
5394
  const cipher = (0, node_crypto_1.createCipheriv)(algorithm, key, nonce, options);
5395
5395
  if (isAEAD && AAD !== void 0) {
5396
5396
  cipher.setAAD(AAD);
@@ -5415,7 +5415,7 @@ var require_compat = __commonJS({
5415
5415
  return (0, utils_1.concatBytes)(updated, finalized);
5416
5416
  };
5417
5417
  return {
5418
- encrypt,
5418
+ encrypt: encrypt2,
5419
5419
  decrypt: decrypt2
5420
5420
  };
5421
5421
  };
@@ -5826,13 +5826,13 @@ var require_dist = __commonJS({
5826
5826
  "use strict";
5827
5827
  Object.defineProperty(exports2, "__esModule", { value: true });
5828
5828
  exports2.PublicKey = exports2.PrivateKey = exports2.ECIES_CONFIG = void 0;
5829
- exports2.encrypt = encrypt;
5829
+ exports2.encrypt = encrypt2;
5830
5830
  exports2.decrypt = decrypt2;
5831
5831
  var utils_1 = require_utils();
5832
5832
  var config_js_1 = require_config();
5833
5833
  var index_js_1 = require_keys();
5834
5834
  var index_js_2 = require_utils4();
5835
- function encrypt(receiverRawPK, data, config = config_js_1.ECIES_CONFIG) {
5835
+ function encrypt2(receiverRawPK, data, config = config_js_1.ECIES_CONFIG) {
5836
5836
  const curve = config.ellipticCurve;
5837
5837
  const ephemeralSK = new index_js_1.PrivateKey(void 0, curve);
5838
5838
  const receiverPK = receiverRawPK instanceof Uint8Array ? new index_js_1.PublicKey(receiverRawPK, curve) : index_js_1.PublicKey.fromHex(receiverRawPK, curve);
@@ -5964,8 +5964,9 @@ var require_decrypt = __commonJS({
5964
5964
  var { decrypt: eciesDecrypt } = require_dist();
5965
5965
  var Errors = require_errors();
5966
5966
  var encrypted2 = require_encrypted();
5967
- function decrypt2(privateKeyHex, encryptedValue) {
5968
- if (!encrypted2(encryptedValue)) {
5967
+ function decrypt2(privateKeyHex, encryptedValue, options = {}) {
5968
+ const value = options.prefix === false ? `${encrypted2.PREFIX}${encryptedValue}` : encryptedValue;
5969
+ if (!encrypted2(value)) {
5969
5970
  return encryptedValue;
5970
5971
  }
5971
5972
  if (!privateKeyHex || privateKeyHex.length < 1) {
@@ -5973,7 +5974,7 @@ var require_decrypt = __commonJS({
5973
5974
  }
5974
5975
  try {
5975
5976
  const privateKey = Buffer.from(privateKeyHex, "hex");
5976
- const ciphertext = Buffer.from(encryptedValue.substring(encrypted2.PREFIX.length), "base64");
5977
+ const ciphertext = Buffer.from(value.substring(encrypted2.PREFIX.length), "base64");
5977
5978
  return Buffer.from(eciesDecrypt(privateKey, ciphertext)).toString("utf8");
5978
5979
  } catch (e) {
5979
5980
  if (e.message === "Invalid private key") {
@@ -6002,6 +6003,23 @@ var require_derive = __commonJS({
6002
6003
  }
6003
6004
  });
6004
6005
 
6006
+ // src/encrypt.js
6007
+ var require_encrypt = __commonJS({
6008
+ "src/encrypt.js"(exports2, module2) {
6009
+ var { encrypt: eciesEncrypt } = require_dist();
6010
+ var { PREFIX } = require_encrypted();
6011
+ function encrypt2(publicKeyHex, value, options = {}) {
6012
+ const ciphertext = eciesEncrypt(publicKeyHex, Buffer.from(value));
6013
+ const encoded = Buffer.from(ciphertext, "hex").toString("base64");
6014
+ if (options.prefix === false) {
6015
+ return encoded;
6016
+ }
6017
+ return `${PREFIX}${encoded}`;
6018
+ }
6019
+ module2.exports = encrypt2;
6020
+ }
6021
+ });
6022
+
6005
6023
  // src/evaluate.js
6006
6024
  var require_evaluate = __commonJS({
6007
6025
  "src/evaluate.js"(exports2, module2) {
@@ -6257,6 +6275,7 @@ var require_parse = __commonJS({
6257
6275
  // src/index.js
6258
6276
  var decrypt = require_decrypt();
6259
6277
  var derive = require_derive();
6278
+ var encrypt = require_encrypt();
6260
6279
  var encrypted = require_encrypted();
6261
6280
  var evaluate = require_evaluate();
6262
6281
  var expand = require_expand();
@@ -6266,6 +6285,7 @@ var scan = require_scan();
6266
6285
  module.exports = {
6267
6286
  decrypt,
6268
6287
  derive,
6288
+ encrypt,
6269
6289
  encrypted,
6270
6290
  evaluate,
6271
6291
  expand,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.0",
2
+ "version": "0.6.0",
3
3
  "name": "@dotenvx/primitives",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",