mp-front-cli 2.3.2-next-0 → 2.3.2-next-1

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.
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var f=(s,t,e)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var o=(s,t,e)=>f(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("node-jose"),d=require("./mp-front-cli-encoder.cjs"),y=require("node:crypto"),S=s=>s.replace(/[\u00A0-\uffff]/gu,t=>"\\u"+("000"+t.charCodeAt(0).toString(16)).slice(-4));class l extends d.CustomEncoder{constructor(e="jwe"){super();o(this,"ALGORITHM","aes-256-gcm");o(this,"IV_LENGTH",12);o(this,"AUTH_TAG_LENGTH",16);o(this,"algType","jwe");this.algType=e}generateAESKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("PLEASE CREATE A KEY TO ENCRYPT 🙂");const r=this.generateSHA(e),n=Buffer.from(r,"hex");if(n.length!==32)throw new Error("KEY MUST BE 32 bytes (64 hex chars)");return n}async generateJWEKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("Define a SECRET_SIGNATURE from `.env`");return await E.JWK.asKey({kty:"oct",k:E.util.base64url.encode(e)})}async encrypt(e){const r=JSON.stringify(e),n=S(r);if(this.algType==="jwe"){const h=await this.generateJWEKey();return await E.JWE.createEncrypt({format:"compact"},h).update(n).final()}const u=this.generateAESKey(),i=y.randomBytes(this.IV_LENGTH),c=y.createCipheriv(this.ALGORITHM,u,i),a=Buffer.concat([c.update(n,"utf8"),c.final()]),T=c.getAuthTag();return Buffer.concat([i,T,a]).toString("hex")}async decrypt(e){if(this.algType==="jwe"){const h=await this.generateJWEKey(),{payload:p}=await E.JWE.createDecrypt(h).decrypt(e);return JSON.parse(p.toString())}const r=this.generateAESKey(),n=Buffer.from(e,"hex"),u=n.subarray(0,this.IV_LENGTH),i=n.subarray(this.IV_LENGTH,this.IV_LENGTH+this.AUTH_TAG_LENGTH),c=n.subarray(this.IV_LENGTH+this.AUTH_TAG_LENGTH),a=y.createDecipheriv(this.ALGORITHM,r,u);return a.setAuthTag(i),Buffer.concat([a.update(c),a.final()]).toString("utf8")}async isEncrypted(e){this.logInfo("EncryptionHandler",e);try{return await this.decrypt(e??""),this.logDebug("EncryptionHandler","IS ENCRYPTED 🥵"),!0}catch(r){return this.logWarn("EncryptionHandler",JSON.stringify(r)),this.logDebug("EncryptionHandler","IS NOT ENCRYPTED 🙂"),!1}}generateSHA(e){const r=JSON.stringify(e);return y.createHash("sha256").update(r).digest("hex")}}exports.CustomEncrypter=l;
1
+ "use strict";var g=Object.defineProperty;var f=(s,t,e)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var o=(s,t,e)=>f(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("node-jose"),d=require("./mp-front-cli-encoder.cjs"),y=require("crypto"),S=s=>s.replace(/[\u00A0-\uffff]/gu,t=>"\\u"+("000"+t.charCodeAt(0).toString(16)).slice(-4));class l extends d.CustomEncoder{constructor(e="jwe"){super();o(this,"ALGORITHM","aes-256-gcm");o(this,"IV_LENGTH",12);o(this,"AUTH_TAG_LENGTH",16);o(this,"algType","jwe");this.algType=e}generateAESKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("PLEASE CREATE A KEY TO ENCRYPT 🙂");const r=this.generateSHA(e),n=Buffer.from(r,"hex");if(n.length!==32)throw new Error("KEY MUST BE 32 bytes (64 hex chars)");return n}async generateJWEKey(){const e=process.env.SECRET_SIGNATURE;if(!e)throw new Error("Define a SECRET_SIGNATURE from `.env`");return await E.JWK.asKey({kty:"oct",k:E.util.base64url.encode(e)})}async encrypt(e){const r=JSON.stringify(e),n=S(r);if(this.algType==="jwe"){const h=await this.generateJWEKey();return await E.JWE.createEncrypt({format:"compact"},h).update(n).final()}const u=this.generateAESKey(),i=y.randomBytes(this.IV_LENGTH),c=y.createCipheriv(this.ALGORITHM,u,i),a=Buffer.concat([c.update(n,"utf8"),c.final()]),T=c.getAuthTag();return Buffer.concat([i,T,a]).toString("hex")}async decrypt(e){if(this.algType==="jwe"){const h=await this.generateJWEKey(),{payload:p}=await E.JWE.createDecrypt(h).decrypt(e);return JSON.parse(p.toString())}const r=this.generateAESKey(),n=Buffer.from(e,"hex"),u=n.subarray(0,this.IV_LENGTH),i=n.subarray(this.IV_LENGTH,this.IV_LENGTH+this.AUTH_TAG_LENGTH),c=n.subarray(this.IV_LENGTH+this.AUTH_TAG_LENGTH),a=y.createDecipheriv(this.ALGORITHM,r,u);return a.setAuthTag(i),Buffer.concat([a.update(c),a.final()]).toString("utf8")}async isEncrypted(e){this.logInfo("EncryptionHandler",e);try{return await this.decrypt(e??""),this.logDebug("EncryptionHandler","IS ENCRYPTED 🥵"),!0}catch(r){return this.logWarn("EncryptionHandler",JSON.stringify(r)),this.logDebug("EncryptionHandler","IS NOT ENCRYPTED 🙂"),!1}}generateSHA(e){const r=JSON.stringify(e);return y.createHash("sha256").update(r).digest("hex")}}exports.CustomEncrypter=l;
@@ -3,7 +3,7 @@ var f = (s, e, t) => e in s ? p(s, e, { enumerable: !0, configurable: !0, writab
3
3
  var o = (s, e, t) => f(s, typeof e != "symbol" ? e + "" : e, t);
4
4
  import E from "node-jose";
5
5
  import { CustomEncoder as g } from "./mp-front-cli-encoder.js";
6
- import { randomBytes as d, createCipheriv as S, createDecipheriv as A, createHash as l } from "node:crypto";
6
+ import { randomBytes as d, createCipheriv as S, createDecipheriv as A, createHash as l } from "crypto";
7
7
  const H = (s) => s.replace(/[\u00A0-\uffff]/gu, (e) => "\\u" + ("000" + e.charCodeAt(0).toString(16)).slice(-4));
8
8
  class _ extends g {
9
9
  constructor(t = "jwe") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mp-front-cli",
3
- "version": "2.3.2-next-0",
3
+ "version": "2.3.2-next-1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/mp-front-cli-all.cjs",