triangle-utils 1.0.22 → 1.0.23

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "main": "index.js",
5
5
  "author": "",
6
6
  "license": "ISC",
7
7
  "description": "",
8
8
  "type": "module",
9
9
  "dependencies": {
10
+ "@aws-sdk/client-cognito-identity-provider": "^3.953.0",
10
11
  "@aws-sdk/client-dynamodb": "^3.953.0",
11
12
  "@aws-sdk/client-s3": "^3.953.0",
12
13
  "nodemailer": "^7.0.11"
@@ -62,7 +62,6 @@ export default class Utils_Misc {
62
62
  } else {
63
63
  await this.admin_alert(error.toString())
64
64
  }
65
-
66
65
  }
67
66
  }
68
67
 
@@ -94,6 +93,33 @@ export default class Utils_Misc {
94
93
  return hash
95
94
  }
96
95
 
96
+ encrypt(text) {
97
+ const iv = crypto.randomBytes(16)
98
+ const cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(this.config.secret_key, "hex"), iv)
99
+ let ciphertext = cipher.update(text, "utf8", "hex")
100
+ ciphertext += cipher.final("hex")
101
+ return {
102
+ iv: iv.toString("hex"),
103
+ ciphertext: ciphertext
104
+ }
105
+ }
106
+
107
+ decrypt(encryption) {
108
+ const iv = encryption.iv
109
+ const ciphertext = encryption.ciphertext
110
+ const decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(this.config.secret_key, "hex"), Buffer.from(iv, "hex"))
111
+ let text = decipher.update(ciphertext, "hex", "utf8")
112
+ text += decipher.final("utf8")
113
+ return text
114
+ }
115
+
116
+ get_secret_hash(username) {
117
+ const secret_hash = crypto.createHmac("sha256", this.config.secret_key)
118
+ .update(username + this.config.cognito_client_id)
119
+ .digest("base64")
120
+ return secret_hash
121
+ }
122
+
97
123
  get_election_id(year, office, state, district) {
98
124
  if (year === undefined || office === undefined || state === undefined || office === "P") {
99
125
  return undefined