ggez-banking-sdk 0.1.151 → 0.1.153
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: () => CipherKeyIV;
|
|
7
|
+
static GenerateByProgramID: (programId: string) => 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;
|
|
@@ -66,17 +66,16 @@ class CipherHelper {
|
|
|
66
66
|
return { key: "", iv: "" };
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
-
static GenerateByProgramID = () => {
|
|
69
|
+
static GenerateByProgramID = (programId) => {
|
|
70
70
|
try {
|
|
71
|
-
const programId = process.env.NEXT_PUBLIC_PROGRAM_ID || process.env.VITE_PROGRAM_ID;
|
|
72
71
|
if (!programId) {
|
|
73
72
|
throw new Error("Program ID is not defined");
|
|
74
73
|
}
|
|
75
|
-
const PID_KEY = this.PaddingLeft(programId
|
|
74
|
+
const PID_KEY = this.PaddingLeft(programId, 10, "0");
|
|
76
75
|
const F_KEY = this.PaddingLeft("0".toString(), 10, "0");
|
|
77
76
|
const FingerPrint_KEY = this.PaddingLeft("", 10, "0");
|
|
78
77
|
const KEY = `${PID_KEY}.${F_KEY}.${FingerPrint_KEY}`;
|
|
79
|
-
const PID_IV = this.PaddingLeft(programId
|
|
78
|
+
const PID_IV = this.PaddingLeft(programId, 8, "0");
|
|
80
79
|
const F_IV = this.PaddingLeft("0".toString(), 8, "0");
|
|
81
80
|
const IV = `${PID_IV}${F_IV}`;
|
|
82
81
|
return { key: KEY, iv: IV };
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
import { UserData, USR } from "../types";
|
|
2
2
|
declare class CookiesHelper {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
private domain;
|
|
4
|
+
private programId;
|
|
5
|
+
constructor(programId: string, domain: string);
|
|
6
|
+
GetIID(): any;
|
|
7
|
+
SetIID(): void;
|
|
8
|
+
ValidateIID(IID: string): string;
|
|
9
|
+
isIIDValid(IID: string): boolean;
|
|
10
|
+
GetDEK(): string;
|
|
11
|
+
SetDEK(deviceEncryptionKey: string, USR: USR): void;
|
|
12
|
+
ValidateDEK(DEK: string): string;
|
|
13
|
+
GetUSR(): USR;
|
|
14
|
+
SetUSR(deviceId: string, userId: string): void;
|
|
15
|
+
ValidateUSR(USR: string): string;
|
|
16
|
+
GetDeviceSecurityCode(): string;
|
|
17
|
+
GetAccessToken(): string;
|
|
18
|
+
SetAccessToken(accessToken: string, expires: Date): void;
|
|
19
|
+
ValidateAccessToken(accessToken: string): string;
|
|
20
|
+
GetJWTToken(): string;
|
|
21
|
+
SetJWTToken(jwtToken: string): void;
|
|
22
|
+
ValidateJWTToken(jwtToken: string): string;
|
|
23
|
+
GetUserData(): UserData;
|
|
24
|
+
SetUserData(userData: UserData): void;
|
|
25
|
+
GET(key: string): string | undefined;
|
|
26
|
+
SET(key: string, value: string, expires?: Date): void;
|
|
27
|
+
REMOVE(key: string): void;
|
|
28
|
+
cookieEventHandler(e: CookieChangeEvent, callback: () => void): void;
|
|
29
|
+
onChangeHandler(changed: CookieInit[], callback: () => void): void;
|
|
30
|
+
onDeleteHandler(deleted: CookieInit[], callback: () => void): void;
|
|
31
|
+
addOnChangeEventListener(callback: () => void): void;
|
|
32
|
+
removeOnChangeEventListener(callback: () => void): void;
|
|
30
33
|
}
|
|
31
34
|
export { CookiesHelper };
|
|
@@ -2,15 +2,25 @@ import { v4 } from "uuid";
|
|
|
2
2
|
import Cookies from "js-cookie";
|
|
3
3
|
import { CipherHelper } from ".";
|
|
4
4
|
class CookiesHelper {
|
|
5
|
+
// #region "Properties"
|
|
6
|
+
domain = "";
|
|
7
|
+
programId = "0";
|
|
8
|
+
// #endregion
|
|
9
|
+
// #region "Constructor"
|
|
10
|
+
constructor(programId, domain) {
|
|
11
|
+
this.programId = programId;
|
|
12
|
+
this.domain = domain;
|
|
13
|
+
}
|
|
14
|
+
// #endregion
|
|
5
15
|
// #region "IID"
|
|
6
|
-
|
|
16
|
+
GetIID() {
|
|
7
17
|
try {
|
|
8
18
|
const IID = this.GET("IID");
|
|
9
19
|
if (!IID) {
|
|
10
20
|
this.SetIID();
|
|
11
21
|
return this.GetIID();
|
|
12
22
|
}
|
|
13
|
-
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
23
|
+
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
14
24
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
15
25
|
return decryptedIID;
|
|
16
26
|
}
|
|
@@ -18,10 +28,10 @@ class CookiesHelper {
|
|
|
18
28
|
console.error(error);
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
|
-
|
|
31
|
+
SetIID() {
|
|
22
32
|
try {
|
|
23
33
|
const IID = v4();
|
|
24
|
-
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
34
|
+
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
25
35
|
const encryptedIID = CipherHelper.Encrypt(IID, key, iv);
|
|
26
36
|
this.SET("IID", encryptedIID);
|
|
27
37
|
}
|
|
@@ -29,9 +39,9 @@ class CookiesHelper {
|
|
|
29
39
|
console.error(error);
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
|
|
42
|
+
ValidateIID(IID) {
|
|
33
43
|
try {
|
|
34
|
-
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
44
|
+
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
35
45
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
36
46
|
return decryptedIID;
|
|
37
47
|
}
|
|
@@ -39,9 +49,9 @@ class CookiesHelper {
|
|
|
39
49
|
console.error(error);
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
isIIDValid(IID) {
|
|
43
53
|
try {
|
|
44
|
-
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
54
|
+
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
45
55
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
46
56
|
return decryptedIID == this.GetIID();
|
|
47
57
|
}
|
|
@@ -51,7 +61,7 @@ class CookiesHelper {
|
|
|
51
61
|
}
|
|
52
62
|
// #endregion
|
|
53
63
|
// #region "DEK"
|
|
54
|
-
|
|
64
|
+
GetDEK() {
|
|
55
65
|
try {
|
|
56
66
|
const IID = this.GetIID();
|
|
57
67
|
const DEK = this.GET("DEK");
|
|
@@ -68,7 +78,7 @@ class CookiesHelper {
|
|
|
68
78
|
console.error(error);
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
|
-
|
|
81
|
+
SetDEK(deviceEncryptionKey, USR) {
|
|
72
82
|
try {
|
|
73
83
|
const IID = this.GetIID();
|
|
74
84
|
const { user_id } = USR;
|
|
@@ -84,7 +94,7 @@ class CookiesHelper {
|
|
|
84
94
|
console.error(error);
|
|
85
95
|
}
|
|
86
96
|
}
|
|
87
|
-
|
|
97
|
+
ValidateDEK(DEK) {
|
|
88
98
|
try {
|
|
89
99
|
const IID = this.GetIID();
|
|
90
100
|
const USR = this.GetUSR();
|
|
@@ -100,7 +110,7 @@ class CookiesHelper {
|
|
|
100
110
|
}
|
|
101
111
|
// #endregion
|
|
102
112
|
// #region "USR"
|
|
103
|
-
|
|
113
|
+
GetUSR() {
|
|
104
114
|
try {
|
|
105
115
|
const IID = this.GetIID();
|
|
106
116
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -112,7 +122,7 @@ class CookiesHelper {
|
|
|
112
122
|
console.error(error);
|
|
113
123
|
}
|
|
114
124
|
}
|
|
115
|
-
|
|
125
|
+
SetUSR(deviceId, userId) {
|
|
116
126
|
try {
|
|
117
127
|
const IID = this.GetIID();
|
|
118
128
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -127,7 +137,7 @@ class CookiesHelper {
|
|
|
127
137
|
console.error(error);
|
|
128
138
|
}
|
|
129
139
|
}
|
|
130
|
-
|
|
140
|
+
ValidateUSR(USR) {
|
|
131
141
|
try {
|
|
132
142
|
const IID = this.GetIID();
|
|
133
143
|
if (!IID)
|
|
@@ -142,7 +152,7 @@ class CookiesHelper {
|
|
|
142
152
|
}
|
|
143
153
|
// #endregion
|
|
144
154
|
// #region "Device Security Code"
|
|
145
|
-
|
|
155
|
+
GetDeviceSecurityCode() {
|
|
146
156
|
try {
|
|
147
157
|
const IID = this.GetIID();
|
|
148
158
|
const DEK = this.GetDEK();
|
|
@@ -161,7 +171,7 @@ class CookiesHelper {
|
|
|
161
171
|
}
|
|
162
172
|
// #endregion
|
|
163
173
|
// #region "Access Token"
|
|
164
|
-
|
|
174
|
+
GetAccessToken() {
|
|
165
175
|
try {
|
|
166
176
|
const IID = this.GetIID();
|
|
167
177
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -173,7 +183,7 @@ class CookiesHelper {
|
|
|
173
183
|
console.error(error);
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
|
-
|
|
186
|
+
SetAccessToken(accessToken, expires) {
|
|
177
187
|
try {
|
|
178
188
|
const IID = this.GetIID();
|
|
179
189
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -184,7 +194,7 @@ class CookiesHelper {
|
|
|
184
194
|
console.error(error);
|
|
185
195
|
}
|
|
186
196
|
}
|
|
187
|
-
|
|
197
|
+
ValidateAccessToken(accessToken) {
|
|
188
198
|
try {
|
|
189
199
|
const IID = this.GetIID();
|
|
190
200
|
if (!IID)
|
|
@@ -199,7 +209,7 @@ class CookiesHelper {
|
|
|
199
209
|
}
|
|
200
210
|
// #endregion
|
|
201
211
|
// #region "JWT Token"
|
|
202
|
-
|
|
212
|
+
GetJWTToken() {
|
|
203
213
|
try {
|
|
204
214
|
const IID = this.GetIID();
|
|
205
215
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -211,7 +221,7 @@ class CookiesHelper {
|
|
|
211
221
|
console.error(error);
|
|
212
222
|
}
|
|
213
223
|
}
|
|
214
|
-
|
|
224
|
+
SetJWTToken(jwtToken) {
|
|
215
225
|
try {
|
|
216
226
|
const IID = this.GetIID();
|
|
217
227
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -222,7 +232,7 @@ class CookiesHelper {
|
|
|
222
232
|
console.error(error);
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
|
-
|
|
235
|
+
ValidateJWTToken(jwtToken) {
|
|
226
236
|
try {
|
|
227
237
|
const IID = this.GetIID();
|
|
228
238
|
if (!IID)
|
|
@@ -237,7 +247,7 @@ class CookiesHelper {
|
|
|
237
247
|
}
|
|
238
248
|
// #endregion
|
|
239
249
|
// #region "User Data"
|
|
240
|
-
|
|
250
|
+
GetUserData() {
|
|
241
251
|
try {
|
|
242
252
|
const IID = this.GetIID();
|
|
243
253
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -252,7 +262,7 @@ class CookiesHelper {
|
|
|
252
262
|
console.error(error);
|
|
253
263
|
}
|
|
254
264
|
}
|
|
255
|
-
|
|
265
|
+
SetUserData(userData) {
|
|
256
266
|
try {
|
|
257
267
|
const IID = this.GetIID();
|
|
258
268
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -266,24 +276,24 @@ class CookiesHelper {
|
|
|
266
276
|
}
|
|
267
277
|
// #endregion
|
|
268
278
|
// #region "Getters & Setters"
|
|
269
|
-
|
|
279
|
+
GET(key) {
|
|
270
280
|
return Cookies.get(key);
|
|
271
281
|
}
|
|
272
|
-
|
|
282
|
+
SET(key, value, expires) {
|
|
273
283
|
const defaultExpireDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365);
|
|
274
284
|
Cookies.set(key, value, {
|
|
275
285
|
path: "/",
|
|
276
286
|
sameSite: "lax",
|
|
277
|
-
domain:
|
|
287
|
+
domain: this.domain || "ggez.one",
|
|
278
288
|
expires: expires || defaultExpireDate,
|
|
279
289
|
});
|
|
280
290
|
}
|
|
281
|
-
|
|
291
|
+
REMOVE(key) {
|
|
282
292
|
Cookies.remove(key);
|
|
283
293
|
}
|
|
284
294
|
// #endregion
|
|
285
295
|
// #region "Cookie Change Event Listener"
|
|
286
|
-
|
|
296
|
+
cookieEventHandler(e, callback) {
|
|
287
297
|
if (e.changed.length > 0) {
|
|
288
298
|
this.onChangeHandler(e.changed, callback);
|
|
289
299
|
}
|
|
@@ -291,7 +301,7 @@ class CookiesHelper {
|
|
|
291
301
|
this.onDeleteHandler(e.deleted, callback);
|
|
292
302
|
}
|
|
293
303
|
}
|
|
294
|
-
|
|
304
|
+
onChangeHandler(changed, callback) {
|
|
295
305
|
const changedCookie = changed[0];
|
|
296
306
|
switch (changedCookie.name) {
|
|
297
307
|
case "IID":
|
|
@@ -317,7 +327,7 @@ class CookiesHelper {
|
|
|
317
327
|
break;
|
|
318
328
|
case "access_token":
|
|
319
329
|
const accessToken = this.GetAccessToken();
|
|
320
|
-
const changedAccessToken =
|
|
330
|
+
const changedAccessToken = this.ValidateAccessToken(changedCookie.value);
|
|
321
331
|
if (accessToken != changedAccessToken) {
|
|
322
332
|
callback();
|
|
323
333
|
}
|
|
@@ -331,16 +341,16 @@ class CookiesHelper {
|
|
|
331
341
|
break;
|
|
332
342
|
}
|
|
333
343
|
}
|
|
334
|
-
|
|
344
|
+
onDeleteHandler(deleted, callback) {
|
|
335
345
|
const deletedCookie = deleted[0];
|
|
336
346
|
if (["DEK", "USR", "IID", "access_token", "jwt_token"].includes(deletedCookie.name)) {
|
|
337
347
|
callback();
|
|
338
348
|
}
|
|
339
349
|
}
|
|
340
|
-
|
|
350
|
+
addOnChangeEventListener(callback) {
|
|
341
351
|
window.cookieStore.addEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
342
352
|
}
|
|
343
|
-
|
|
353
|
+
removeOnChangeEventListener(callback) {
|
|
344
354
|
window.cookieStore.removeEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
345
355
|
}
|
|
346
356
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.153",
|
|
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",
|