@gustavo-valsechi/utils 1.0.10 → 1.0.14

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.js CHANGED
@@ -266,21 +266,19 @@ var Cryptor = {
266
266
  },
267
267
  decrypt: async (payload) => {
268
268
  if (!SECRET) throw new Error("AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET is required!");
269
- console.log("SECRET", SECRET);
270
- const key = await Cryptor.deriveKey(SECRET);
271
- console.log("key", key);
272
- const iv = Cryptor.fromBase64(payload.iv);
273
- const encrypted = Cryptor.fromBase64(payload.data);
274
- console.log("iv", iv);
275
- console.log("encrypted", encrypted);
276
- const decrypted = await crypto.subtle.decrypt(
277
- { name: "AES-GCM", iv },
278
- key,
279
- encrypted
280
- );
281
- console.log("decrypted", decrypted);
282
- console.log("return", JSON.parse(new TextDecoder().decode(decrypted)));
283
- return JSON.parse(new TextDecoder().decode(decrypted));
269
+ try {
270
+ const key = await Cryptor.deriveKey(SECRET);
271
+ const iv = Cryptor.fromBase64(payload.iv);
272
+ const encrypted = Cryptor.fromBase64(payload.data);
273
+ const decrypted = await crypto.subtle.decrypt(
274
+ { name: "AES-GCM", iv },
275
+ key,
276
+ encrypted
277
+ );
278
+ return JSON.parse(new TextDecoder().decode(decrypted));
279
+ } catch (e) {
280
+ throw new Error("Invalid AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET!");
281
+ }
284
282
  }
285
283
  };
286
284
  var cryptor_default = Cryptor;
package/dist/index.mjs CHANGED
@@ -230,21 +230,19 @@ var Cryptor = {
230
230
  },
231
231
  decrypt: async (payload) => {
232
232
  if (!SECRET) throw new Error("AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET is required!");
233
- console.log("SECRET", SECRET);
234
- const key = await Cryptor.deriveKey(SECRET);
235
- console.log("key", key);
236
- const iv = Cryptor.fromBase64(payload.iv);
237
- const encrypted = Cryptor.fromBase64(payload.data);
238
- console.log("iv", iv);
239
- console.log("encrypted", encrypted);
240
- const decrypted = await crypto.subtle.decrypt(
241
- { name: "AES-GCM", iv },
242
- key,
243
- encrypted
244
- );
245
- console.log("decrypted", decrypted);
246
- console.log("return", JSON.parse(new TextDecoder().decode(decrypted)));
247
- return JSON.parse(new TextDecoder().decode(decrypted));
233
+ try {
234
+ const key = await Cryptor.deriveKey(SECRET);
235
+ const iv = Cryptor.fromBase64(payload.iv);
236
+ const encrypted = Cryptor.fromBase64(payload.data);
237
+ const decrypted = await crypto.subtle.decrypt(
238
+ { name: "AES-GCM", iv },
239
+ key,
240
+ encrypted
241
+ );
242
+ return JSON.parse(new TextDecoder().decode(decrypted));
243
+ } catch (e) {
244
+ throw new Error("Invalid AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET!");
245
+ }
248
246
  }
249
247
  };
250
248
  var cryptor_default = Cryptor;
@@ -68,21 +68,19 @@ var Cryptor = {
68
68
  },
69
69
  decrypt: async (payload) => {
70
70
  if (!SECRET) throw new Error("AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET is required!");
71
- console.log("SECRET", SECRET);
72
- const key = await Cryptor.deriveKey(SECRET);
73
- console.log("key", key);
74
- const iv = Cryptor.fromBase64(payload.iv);
75
- const encrypted = Cryptor.fromBase64(payload.data);
76
- console.log("iv", iv);
77
- console.log("encrypted", encrypted);
78
- const decrypted = await crypto.subtle.decrypt(
79
- { name: "AES-GCM", iv },
80
- key,
81
- encrypted
82
- );
83
- console.log("decrypted", decrypted);
84
- console.log("return", JSON.parse(new TextDecoder().decode(decrypted)));
85
- return JSON.parse(new TextDecoder().decode(decrypted));
71
+ try {
72
+ const key = await Cryptor.deriveKey(SECRET);
73
+ const iv = Cryptor.fromBase64(payload.iv);
74
+ const encrypted = Cryptor.fromBase64(payload.data);
75
+ const decrypted = await crypto.subtle.decrypt(
76
+ { name: "AES-GCM", iv },
77
+ key,
78
+ encrypted
79
+ );
80
+ return JSON.parse(new TextDecoder().decode(decrypted));
81
+ } catch (e) {
82
+ throw new Error("Invalid AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET!");
83
+ }
86
84
  }
87
85
  };
88
86
  var cryptor_default = Cryptor;
@@ -44,21 +44,19 @@ var Cryptor = {
44
44
  },
45
45
  decrypt: async (payload) => {
46
46
  if (!SECRET) throw new Error("AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET is required!");
47
- console.log("SECRET", SECRET);
48
- const key = await Cryptor.deriveKey(SECRET);
49
- console.log("key", key);
50
- const iv = Cryptor.fromBase64(payload.iv);
51
- const encrypted = Cryptor.fromBase64(payload.data);
52
- console.log("iv", iv);
53
- console.log("encrypted", encrypted);
54
- const decrypted = await crypto.subtle.decrypt(
55
- { name: "AES-GCM", iv },
56
- key,
57
- encrypted
58
- );
59
- console.log("decrypted", decrypted);
60
- console.log("return", JSON.parse(new TextDecoder().decode(decrypted)));
61
- return JSON.parse(new TextDecoder().decode(decrypted));
47
+ try {
48
+ const key = await Cryptor.deriveKey(SECRET);
49
+ const iv = Cryptor.fromBase64(payload.iv);
50
+ const encrypted = Cryptor.fromBase64(payload.data);
51
+ const decrypted = await crypto.subtle.decrypt(
52
+ { name: "AES-GCM", iv },
53
+ key,
54
+ encrypted
55
+ );
56
+ return JSON.parse(new TextDecoder().decode(decrypted));
57
+ } catch (e) {
58
+ throw new Error("Invalid AUTH_SECRET or NEXT_PUBLIC_AUTH_SECRET!");
59
+ }
62
60
  }
63
61
  };
64
62
  var cryptor_default = Cryptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/utils",
3
- "version": "1.0.10",
3
+ "version": "1.0.14",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",