ggez-banking-sdk 0.1.147 → 0.1.148
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,12 +1,18 @@
|
|
|
1
1
|
import { createCipheriv, createDecipheriv } from "crypto";
|
|
2
2
|
class CipherHelper {
|
|
3
3
|
static Encrypt = (plainText, key, iv) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
try {
|
|
5
|
+
const keyBuffer = Buffer.from(key, "utf8");
|
|
6
|
+
const ivBuffer = Buffer.from(iv, "utf8");
|
|
7
|
+
const cipher = createCipheriv("aes-256-cbc", keyBuffer, ivBuffer);
|
|
8
|
+
let encrypted = cipher.update(plainText, "utf8", "base64");
|
|
9
|
+
encrypted += cipher.final("base64");
|
|
10
|
+
return encrypted;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error(error + " CipherHelper.Encrypt");
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
10
16
|
};
|
|
11
17
|
static Decrypt = (cipherText, key, iv) => {
|
|
12
18
|
try {
|
|
@@ -23,7 +29,6 @@ class CipherHelper {
|
|
|
23
29
|
catch (error) {
|
|
24
30
|
console.error(error + " CipherHelper.Decrypt");
|
|
25
31
|
return "";
|
|
26
|
-
// return JSON.stringify(error);
|
|
27
32
|
}
|
|
28
33
|
};
|
|
29
34
|
static Generate = (code) => {
|
|
@@ -35,7 +40,7 @@ class CipherHelper {
|
|
|
35
40
|
return { key: KEY, iv: IV };
|
|
36
41
|
}
|
|
37
42
|
catch (error) {
|
|
38
|
-
console.error(error);
|
|
43
|
+
console.error(error + " CipherHelper.Generate");
|
|
39
44
|
return { key: "", iv: "" };
|
|
40
45
|
}
|
|
41
46
|
};
|
|
@@ -57,7 +62,7 @@ class CipherHelper {
|
|
|
57
62
|
return { key: KEY, iv: IV };
|
|
58
63
|
}
|
|
59
64
|
catch (error) {
|
|
60
|
-
console.error(error);
|
|
65
|
+
console.error(error + " CipherHelper.GenerateByUSRAndIID");
|
|
61
66
|
return { key: "", iv: "" };
|
|
62
67
|
}
|
|
63
68
|
};
|
|
@@ -77,14 +82,20 @@ class CipherHelper {
|
|
|
77
82
|
return { key: KEY, iv: IV };
|
|
78
83
|
}
|
|
79
84
|
catch (error) {
|
|
80
|
-
console.error(error);
|
|
85
|
+
console.error(error + " CipherHelper.GenerateByProgramID");
|
|
81
86
|
return { key: "", iv: "" };
|
|
82
87
|
}
|
|
83
88
|
};
|
|
84
89
|
static GenerateByUserID = (user_id) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
try {
|
|
91
|
+
const UID_KEY = this.PaddingLeft(user_id.toString(), 32, "0");
|
|
92
|
+
const UID_IV = this.PaddingLeft(user_id.toString(), 16, "0");
|
|
93
|
+
return { key: UID_KEY, iv: UID_IV };
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error(error + " CipherHelper.GenerateByUserID");
|
|
97
|
+
return { key: "", iv: "" };
|
|
98
|
+
}
|
|
88
99
|
};
|
|
89
100
|
static GenerateByInstallationID = (IID) => {
|
|
90
101
|
try {
|
|
@@ -96,14 +107,20 @@ class CipherHelper {
|
|
|
96
107
|
return { key: IID_KEY, iv: IID_IV };
|
|
97
108
|
}
|
|
98
109
|
catch (error) {
|
|
99
|
-
console.error(error);
|
|
110
|
+
console.error(error + " CipherHelper.GenerateByInstallationID");
|
|
100
111
|
return { key: "", iv: "" };
|
|
101
112
|
}
|
|
102
113
|
};
|
|
103
114
|
static PaddingLeft = (value, length, paddingChar) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
try {
|
|
116
|
+
if (value.length >= length)
|
|
117
|
+
return value;
|
|
118
|
+
return paddingChar.repeat(length - value.length) + value;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error(error + " CipherHelper.PaddingLeft");
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
107
124
|
};
|
|
108
125
|
}
|
|
109
126
|
export { CipherHelper };
|
|
@@ -17,7 +17,7 @@ declare class CookiesHelper {
|
|
|
17
17
|
static SetJWTToken: (jwtToken: string) => void;
|
|
18
18
|
static ValidateJWTToken: (jwtToken: string) => string;
|
|
19
19
|
static GetUserData: () => UserData;
|
|
20
|
-
static SetUserData: (
|
|
20
|
+
static SetUserData: (userData: UserData) => void;
|
|
21
21
|
static GET: (key: string) => string | undefined;
|
|
22
22
|
static SET: (key: string, value: string, expires?: Date) => void;
|
|
23
23
|
static REMOVE: (key: string) => void;
|
|
@@ -233,17 +233,21 @@ class CookiesHelper {
|
|
|
233
233
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
234
234
|
const userData = this.GET("CUD");
|
|
235
235
|
const decryptedUserData = CipherHelper.Decrypt(userData, key, iv);
|
|
236
|
-
|
|
236
|
+
if (decryptedUserData) {
|
|
237
|
+
return JSON.parse(decryptedUserData);
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
237
240
|
}
|
|
238
241
|
catch (error) {
|
|
239
242
|
console.error(error);
|
|
240
243
|
}
|
|
241
244
|
};
|
|
242
|
-
static SetUserData = (
|
|
245
|
+
static SetUserData = (userData) => {
|
|
243
246
|
try {
|
|
244
247
|
const IID = this.GetIID();
|
|
245
248
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
246
|
-
const
|
|
249
|
+
const data = JSON.stringify(userData);
|
|
250
|
+
const encryptedUserData = CipherHelper.Encrypt(data, key, iv);
|
|
247
251
|
this.SET("CUD", encryptedUserData);
|
|
248
252
|
}
|
|
249
253
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.148",
|
|
4
4
|
"description": "A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|