triangle-utils 1.0.21 → 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.21",
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
package/utils/Utils_S3.js CHANGED
@@ -23,7 +23,7 @@ export default class Utils_S3 {
23
23
  return undefined
24
24
  }
25
25
  try {
26
- const head = await s3.headObject(s3_key)
26
+ const head = await this.s3.headObject(s3_key)
27
27
  return true
28
28
  } catch (error) {
29
29
  return false
@@ -37,7 +37,7 @@ export default class Utils_S3 {
37
37
  return undefined
38
38
  }
39
39
  try {
40
- return await s3.getObject(s3_key)
40
+ return await this.s3.getObject(s3_key)
41
41
  .then(response => response.Body.transformToString("utf-8"))
42
42
  .then(text => json ? JSON.parse(text) : text)
43
43
  } catch (error) {
@@ -57,7 +57,7 @@ export default class Utils_S3 {
57
57
  if (s3_key === undefined) {
58
58
  return undefined
59
59
  }
60
- return await s3.putObject({
60
+ return await this.s3.putObject({
61
61
  ...s3_key,
62
62
  Body : content
63
63
  })
@@ -68,7 +68,7 @@ export default class Utils_S3 {
68
68
  if (s3_key === undefined) {
69
69
  return undefined
70
70
  }
71
- return await s3.deleteObject(s3_key)
71
+ return await this.s3.deleteObject(s3_key)
72
72
  }
73
73
 
74
74
  }