ggez-banking-sdk 0.1.100 → 0.1.101
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.
@@ -4,7 +4,7 @@ declare class CipherHelper {
|
|
4
4
|
static Decrypt: (cipherText: string, key: string, iv: string) => string;
|
5
5
|
static Generate: (code: string) => CipherKeyIV;
|
6
6
|
static GenerateByUSRAndIID: (USR: USR, IID: string) => CipherKeyIV;
|
7
|
-
static GenerateByProgramID: (
|
7
|
+
static GenerateByProgramID: () => CipherKeyIV;
|
8
8
|
static GenerateByUserID: (user_id: string) => CipherKeyIV;
|
9
9
|
static GenerateByInstallationID: (IID: string) => CipherKeyIV;
|
10
10
|
static PaddingLeft: (value: string, length: number, paddingChar: string) => string;
|
@@ -25,29 +25,59 @@ CipherHelper.Decrypt = (cipherText, key, iv) => {
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
CipherHelper.Generate = (code) => {
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
try {
|
29
|
+
if (!code)
|
30
|
+
throw new Error("code is not defined");
|
31
|
+
const KEY = _a.PaddingLeft(code.toString(), 32, "0");
|
32
|
+
const IV = _a.PaddingLeft(code.toString(), 16, "0");
|
33
|
+
return { key: KEY, iv: IV };
|
34
|
+
}
|
35
|
+
catch (error) {
|
36
|
+
console.error(error);
|
37
|
+
return { key: "", iv: "" };
|
38
|
+
}
|
31
39
|
};
|
32
40
|
CipherHelper.GenerateByUSRAndIID = (USR, IID) => {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
try {
|
42
|
+
if (!USR || !USR.device_id || !USR.user_id) {
|
43
|
+
throw new Error("USR is not defined");
|
44
|
+
}
|
45
|
+
if (!IID) {
|
46
|
+
throw new Error("IID is not defined");
|
47
|
+
}
|
48
|
+
const DID_KEY = _a.PaddingLeft(USR.device_id.toString(), 10, "0");
|
49
|
+
const UID_KEY = _a.PaddingLeft(USR.user_id.toString(), 10, "0");
|
50
|
+
const IID_KEY = IID.slice(0, 10);
|
51
|
+
const KEY = `${DID_KEY}.${UID_KEY}.${IID_KEY}`.toString();
|
52
|
+
const DID_IV = _a.PaddingLeft(USR.device_id.toString(), 8, "0");
|
53
|
+
const UID_IV = _a.PaddingLeft(USR.user_id.toString(), 8, "0");
|
54
|
+
const IV = `${DID_IV}${UID_IV}`.toString();
|
55
|
+
return { key: KEY, iv: IV };
|
56
|
+
}
|
57
|
+
catch (error) {
|
58
|
+
console.error(error);
|
59
|
+
return { key: "", iv: "" };
|
60
|
+
}
|
41
61
|
};
|
42
|
-
CipherHelper.GenerateByProgramID = (
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
62
|
+
CipherHelper.GenerateByProgramID = () => {
|
63
|
+
try {
|
64
|
+
const programId = process.env.NEXT_PUBLIC_PROGRAM_ID || process.env.VITE_PROGRAM_ID;
|
65
|
+
if (!programId) {
|
66
|
+
throw new Error("Program ID is not defined");
|
67
|
+
}
|
68
|
+
const PID_KEY = _a.PaddingLeft(programId.toString(), 10, "0");
|
69
|
+
const F_KEY = _a.PaddingLeft("0".toString(), 10, "0");
|
70
|
+
const FingerPrint_KEY = _a.PaddingLeft("", 10, "0");
|
71
|
+
const KEY = `${PID_KEY}.${F_KEY}.${FingerPrint_KEY}`;
|
72
|
+
const PID_IV = _a.PaddingLeft(programId.toString(), 8, "0");
|
73
|
+
const F_IV = _a.PaddingLeft("0".toString(), 8, "0");
|
74
|
+
const IV = `${PID_IV}${F_IV}`;
|
75
|
+
return { key: KEY, iv: IV };
|
76
|
+
}
|
77
|
+
catch (error) {
|
78
|
+
console.error(error);
|
79
|
+
return { key: "", iv: "" };
|
80
|
+
}
|
51
81
|
};
|
52
82
|
CipherHelper.GenerateByUserID = (user_id) => {
|
53
83
|
const UID_KEY = _a.PaddingLeft(user_id.toString(), 32, "0");
|
@@ -55,9 +85,18 @@ CipherHelper.GenerateByUserID = (user_id) => {
|
|
55
85
|
return { key: UID_KEY, iv: UID_IV };
|
56
86
|
};
|
57
87
|
CipherHelper.GenerateByInstallationID = (IID) => {
|
58
|
-
|
59
|
-
|
60
|
-
|
88
|
+
try {
|
89
|
+
if (!IID) {
|
90
|
+
throw new Error("Installation ID is not defined");
|
91
|
+
}
|
92
|
+
const IID_KEY = IID.slice(0, 32);
|
93
|
+
const IID_IV = IID.slice(0, 16);
|
94
|
+
return { key: IID_KEY, iv: IID_IV };
|
95
|
+
}
|
96
|
+
catch (error) {
|
97
|
+
console.error(error);
|
98
|
+
return { key: "", iv: "" };
|
99
|
+
}
|
61
100
|
};
|
62
101
|
CipherHelper.PaddingLeft = (value, length, paddingChar) => {
|
63
102
|
if (value.length >= length)
|
@@ -8,9 +8,12 @@ _a = CookiesHelper;
|
|
8
8
|
// #region "IID"
|
9
9
|
CookiesHelper.GetIID = () => {
|
10
10
|
try {
|
11
|
-
const
|
12
|
-
const { key, iv } = CipherHelper.GenerateByProgramID(programId);
|
11
|
+
const { key, iv } = CipherHelper.GenerateByProgramID();
|
13
12
|
const IID = _a.GET("IID");
|
13
|
+
if (!IID) {
|
14
|
+
_a.SetIID();
|
15
|
+
return _a.GetIID();
|
16
|
+
}
|
14
17
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
15
18
|
return decryptedIID;
|
16
19
|
}
|
@@ -20,9 +23,8 @@ CookiesHelper.GetIID = () => {
|
|
20
23
|
};
|
21
24
|
CookiesHelper.SetIID = () => {
|
22
25
|
try {
|
23
|
-
const programId = process.env.NEXT_PUBLIC_PROGRAM_ID;
|
24
26
|
const IID = v4();
|
25
|
-
const { key, iv } = CipherHelper.GenerateByProgramID(
|
27
|
+
const { key, iv } = CipherHelper.GenerateByProgramID();
|
26
28
|
const encryptedIID = CipherHelper.Encrypt(IID, key, iv);
|
27
29
|
_a.SET("IID", encryptedIID);
|
28
30
|
}
|
@@ -37,6 +39,9 @@ CookiesHelper.GetDEK = () => {
|
|
37
39
|
const IID = _a.GetIID();
|
38
40
|
const DEK = _a.GET("DEK");
|
39
41
|
const USR = _a.GetUSR();
|
42
|
+
if (!DEK || !USR) {
|
43
|
+
return null;
|
44
|
+
}
|
40
45
|
const { key, iv } = CipherHelper.GenerateByUSRAndIID(USR, IID);
|
41
46
|
const encryptionKey = CipherHelper.Decrypt(DEK, key, iv);
|
42
47
|
if (encryptionKey.length == 16)
|
@@ -67,7 +72,7 @@ CookiesHelper.SetDEK = (deviceEncryptionKey, USR) => {
|
|
67
72
|
CookiesHelper.GetUSR = () => {
|
68
73
|
try {
|
69
74
|
const IID = _a.GetIID();
|
70
|
-
const {
|
75
|
+
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
71
76
|
const USR = _a.GET("USR");
|
72
77
|
const decryptedUSR = CipherHelper.Decrypt(USR, key, iv);
|
73
78
|
return JSON.parse(decryptedUSR);
|
@@ -79,7 +84,7 @@ CookiesHelper.GetUSR = () => {
|
|
79
84
|
CookiesHelper.SetUSR = (deviceId, userId) => {
|
80
85
|
try {
|
81
86
|
const IID = _a.GetIID();
|
82
|
-
const {
|
87
|
+
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
83
88
|
const USR = JSON.stringify({
|
84
89
|
device_id: deviceId,
|
85
90
|
user_id: userId,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ggez-banking-sdk",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.101",
|
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",
|