@dotenvx/primitives 0.5.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.
- package/dist/index.cjs +8 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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") {
|
|
@@ -6007,9 +6008,12 @@ var require_encrypt = __commonJS({
|
|
|
6007
6008
|
"src/encrypt.js"(exports2, module2) {
|
|
6008
6009
|
var { encrypt: eciesEncrypt } = require_dist();
|
|
6009
6010
|
var { PREFIX } = require_encrypted();
|
|
6010
|
-
function encrypt2(publicKeyHex, value) {
|
|
6011
|
+
function encrypt2(publicKeyHex, value, options = {}) {
|
|
6011
6012
|
const ciphertext = eciesEncrypt(publicKeyHex, Buffer.from(value));
|
|
6012
6013
|
const encoded = Buffer.from(ciphertext, "hex").toString("base64");
|
|
6014
|
+
if (options.prefix === false) {
|
|
6015
|
+
return encoded;
|
|
6016
|
+
}
|
|
6013
6017
|
return `${PREFIX}${encoded}`;
|
|
6014
6018
|
}
|
|
6015
6019
|
module2.exports = encrypt2;
|
package/package.json
CHANGED