ggez-banking-sdk 0.1.150 → 0.1.152
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: number) => 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,9 +66,8 @@ 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
|
}
|
|
@@ -1,30 +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
|
-
|
|
3
|
+
private domain;
|
|
4
|
+
private programId;
|
|
5
|
+
constructor(programId: number, 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;
|
|
29
33
|
}
|
|
30
34
|
export { CookiesHelper };
|
|
@@ -2,46 +2,66 @@ 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
|
}
|
|
17
27
|
catch (error) {
|
|
18
28
|
console.error(error);
|
|
19
29
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
30
|
+
}
|
|
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
|
}
|
|
28
38
|
catch (error) {
|
|
29
39
|
console.error(error);
|
|
30
40
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
41
|
+
}
|
|
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
|
}
|
|
38
48
|
catch (error) {
|
|
39
49
|
console.error(error);
|
|
40
50
|
}
|
|
41
|
-
}
|
|
51
|
+
}
|
|
52
|
+
isIIDValid(IID) {
|
|
53
|
+
try {
|
|
54
|
+
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
55
|
+
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
56
|
+
return decryptedIID == this.GetIID();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
42
62
|
// #endregion
|
|
43
63
|
// #region "DEK"
|
|
44
|
-
|
|
64
|
+
GetDEK() {
|
|
45
65
|
try {
|
|
46
66
|
const IID = this.GetIID();
|
|
47
67
|
const DEK = this.GET("DEK");
|
|
@@ -57,8 +77,8 @@ class CookiesHelper {
|
|
|
57
77
|
catch (error) {
|
|
58
78
|
console.error(error);
|
|
59
79
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
80
|
+
}
|
|
81
|
+
SetDEK(deviceEncryptionKey, USR) {
|
|
62
82
|
try {
|
|
63
83
|
const IID = this.GetIID();
|
|
64
84
|
const { user_id } = USR;
|
|
@@ -73,8 +93,8 @@ class CookiesHelper {
|
|
|
73
93
|
catch (error) {
|
|
74
94
|
console.error(error);
|
|
75
95
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
96
|
+
}
|
|
97
|
+
ValidateDEK(DEK) {
|
|
78
98
|
try {
|
|
79
99
|
const IID = this.GetIID();
|
|
80
100
|
const USR = this.GetUSR();
|
|
@@ -87,10 +107,10 @@ class CookiesHelper {
|
|
|
87
107
|
catch (error) {
|
|
88
108
|
console.error(error);
|
|
89
109
|
}
|
|
90
|
-
}
|
|
110
|
+
}
|
|
91
111
|
// #endregion
|
|
92
112
|
// #region "USR"
|
|
93
|
-
|
|
113
|
+
GetUSR() {
|
|
94
114
|
try {
|
|
95
115
|
const IID = this.GetIID();
|
|
96
116
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -101,8 +121,8 @@ class CookiesHelper {
|
|
|
101
121
|
catch (error) {
|
|
102
122
|
console.error(error);
|
|
103
123
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
124
|
+
}
|
|
125
|
+
SetUSR(deviceId, userId) {
|
|
106
126
|
try {
|
|
107
127
|
const IID = this.GetIID();
|
|
108
128
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -116,8 +136,8 @@ class CookiesHelper {
|
|
|
116
136
|
catch (error) {
|
|
117
137
|
console.error(error);
|
|
118
138
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
139
|
+
}
|
|
140
|
+
ValidateUSR(USR) {
|
|
121
141
|
try {
|
|
122
142
|
const IID = this.GetIID();
|
|
123
143
|
if (!IID)
|
|
@@ -129,10 +149,10 @@ class CookiesHelper {
|
|
|
129
149
|
catch (error) {
|
|
130
150
|
console.error(error);
|
|
131
151
|
}
|
|
132
|
-
}
|
|
152
|
+
}
|
|
133
153
|
// #endregion
|
|
134
154
|
// #region "Device Security Code"
|
|
135
|
-
|
|
155
|
+
GetDeviceSecurityCode() {
|
|
136
156
|
try {
|
|
137
157
|
const IID = this.GetIID();
|
|
138
158
|
const DEK = this.GetDEK();
|
|
@@ -148,10 +168,10 @@ class CookiesHelper {
|
|
|
148
168
|
catch (error) {
|
|
149
169
|
console.error(error);
|
|
150
170
|
}
|
|
151
|
-
}
|
|
171
|
+
}
|
|
152
172
|
// #endregion
|
|
153
173
|
// #region "Access Token"
|
|
154
|
-
|
|
174
|
+
GetAccessToken() {
|
|
155
175
|
try {
|
|
156
176
|
const IID = this.GetIID();
|
|
157
177
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -162,8 +182,8 @@ class CookiesHelper {
|
|
|
162
182
|
catch (error) {
|
|
163
183
|
console.error(error);
|
|
164
184
|
}
|
|
165
|
-
}
|
|
166
|
-
|
|
185
|
+
}
|
|
186
|
+
SetAccessToken(accessToken, expires) {
|
|
167
187
|
try {
|
|
168
188
|
const IID = this.GetIID();
|
|
169
189
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -173,8 +193,8 @@ class CookiesHelper {
|
|
|
173
193
|
catch (error) {
|
|
174
194
|
console.error(error);
|
|
175
195
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
196
|
+
}
|
|
197
|
+
ValidateAccessToken(accessToken) {
|
|
178
198
|
try {
|
|
179
199
|
const IID = this.GetIID();
|
|
180
200
|
if (!IID)
|
|
@@ -186,10 +206,10 @@ class CookiesHelper {
|
|
|
186
206
|
catch (error) {
|
|
187
207
|
console.error(error);
|
|
188
208
|
}
|
|
189
|
-
}
|
|
209
|
+
}
|
|
190
210
|
// #endregion
|
|
191
211
|
// #region "JWT Token"
|
|
192
|
-
|
|
212
|
+
GetJWTToken() {
|
|
193
213
|
try {
|
|
194
214
|
const IID = this.GetIID();
|
|
195
215
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -200,8 +220,8 @@ class CookiesHelper {
|
|
|
200
220
|
catch (error) {
|
|
201
221
|
console.error(error);
|
|
202
222
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
223
|
+
}
|
|
224
|
+
SetJWTToken(jwtToken) {
|
|
205
225
|
try {
|
|
206
226
|
const IID = this.GetIID();
|
|
207
227
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -211,8 +231,8 @@ class CookiesHelper {
|
|
|
211
231
|
catch (error) {
|
|
212
232
|
console.error(error);
|
|
213
233
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
234
|
+
}
|
|
235
|
+
ValidateJWTToken(jwtToken) {
|
|
216
236
|
try {
|
|
217
237
|
const IID = this.GetIID();
|
|
218
238
|
if (!IID)
|
|
@@ -224,10 +244,10 @@ class CookiesHelper {
|
|
|
224
244
|
catch (error) {
|
|
225
245
|
console.error(error);
|
|
226
246
|
}
|
|
227
|
-
}
|
|
247
|
+
}
|
|
228
248
|
// #endregion
|
|
229
249
|
// #region "User Data"
|
|
230
|
-
|
|
250
|
+
GetUserData() {
|
|
231
251
|
try {
|
|
232
252
|
const IID = this.GetIID();
|
|
233
253
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -241,8 +261,8 @@ class CookiesHelper {
|
|
|
241
261
|
catch (error) {
|
|
242
262
|
console.error(error);
|
|
243
263
|
}
|
|
244
|
-
}
|
|
245
|
-
|
|
264
|
+
}
|
|
265
|
+
SetUserData(userData) {
|
|
246
266
|
try {
|
|
247
267
|
const IID = this.GetIID();
|
|
248
268
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -253,80 +273,85 @@ class CookiesHelper {
|
|
|
253
273
|
catch (error) {
|
|
254
274
|
console.error(error);
|
|
255
275
|
}
|
|
256
|
-
}
|
|
276
|
+
}
|
|
257
277
|
// #endregion
|
|
258
278
|
// #region "Getters & Setters"
|
|
259
|
-
|
|
279
|
+
GET(key) {
|
|
260
280
|
return Cookies.get(key);
|
|
261
|
-
}
|
|
262
|
-
|
|
281
|
+
}
|
|
282
|
+
SET(key, value, expires) {
|
|
263
283
|
const defaultExpireDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365);
|
|
264
284
|
Cookies.set(key, value, {
|
|
265
285
|
path: "/",
|
|
266
286
|
sameSite: "lax",
|
|
267
|
-
domain:
|
|
287
|
+
domain: this.domain || "ggez.one",
|
|
268
288
|
expires: expires || defaultExpireDate,
|
|
269
289
|
});
|
|
270
|
-
}
|
|
271
|
-
|
|
290
|
+
}
|
|
291
|
+
REMOVE(key) {
|
|
272
292
|
Cookies.remove(key);
|
|
273
|
-
}
|
|
293
|
+
}
|
|
274
294
|
// #endregion
|
|
275
295
|
// #region "Cookie Change Event Listener"
|
|
276
|
-
|
|
296
|
+
cookieEventHandler(e, callback) {
|
|
277
297
|
if (e.changed.length > 0) {
|
|
278
298
|
this.onChangeHandler(e.changed, callback);
|
|
279
299
|
}
|
|
280
300
|
if (e.deleted.length > 0) {
|
|
281
301
|
this.onDeleteHandler(e.deleted, callback);
|
|
282
302
|
}
|
|
283
|
-
}
|
|
284
|
-
|
|
303
|
+
}
|
|
304
|
+
onChangeHandler(changed, callback) {
|
|
285
305
|
const changedCookie = changed[0];
|
|
286
306
|
switch (changedCookie.name) {
|
|
287
307
|
case "IID":
|
|
288
308
|
const IID = this.GetIID();
|
|
289
|
-
|
|
309
|
+
const changedIID = this.ValidateIID(changedCookie.value);
|
|
310
|
+
if (IID != changedIID) {
|
|
290
311
|
callback();
|
|
291
312
|
}
|
|
292
313
|
break;
|
|
293
314
|
case "USR":
|
|
294
315
|
const USR = this.GetUSR();
|
|
295
|
-
|
|
316
|
+
const changedUSR = this.ValidateUSR(changedCookie.value);
|
|
317
|
+
if (USR.toString() != changedUSR) {
|
|
296
318
|
callback();
|
|
297
319
|
}
|
|
298
320
|
break;
|
|
299
321
|
case "DEK":
|
|
300
322
|
const DEK = this.GetDEK();
|
|
301
|
-
|
|
323
|
+
const changedDEK = this.ValidateDEK(changedCookie.value);
|
|
324
|
+
if (DEK != changedDEK) {
|
|
302
325
|
callback();
|
|
303
326
|
}
|
|
304
327
|
break;
|
|
305
328
|
case "access_token":
|
|
306
329
|
const accessToken = this.GetAccessToken();
|
|
307
|
-
|
|
330
|
+
const changedAccessToken = this.ValidateAccessToken(changedCookie.value);
|
|
331
|
+
if (accessToken != changedAccessToken) {
|
|
308
332
|
callback();
|
|
309
333
|
}
|
|
310
334
|
break;
|
|
311
335
|
case "jwt_token":
|
|
312
336
|
const jwtToken = this.GetJWTToken();
|
|
313
|
-
|
|
337
|
+
const changedJWTToken = this.ValidateJWTToken(changedCookie.value);
|
|
338
|
+
if (jwtToken != changedJWTToken) {
|
|
314
339
|
callback();
|
|
315
340
|
}
|
|
316
341
|
break;
|
|
317
342
|
}
|
|
318
|
-
}
|
|
319
|
-
|
|
343
|
+
}
|
|
344
|
+
onDeleteHandler(deleted, callback) {
|
|
320
345
|
const deletedCookie = deleted[0];
|
|
321
346
|
if (["DEK", "USR", "IID", "access_token", "jwt_token"].includes(deletedCookie.name)) {
|
|
322
347
|
callback();
|
|
323
348
|
}
|
|
324
|
-
}
|
|
325
|
-
|
|
349
|
+
}
|
|
350
|
+
addOnChangeEventListener(callback) {
|
|
326
351
|
window.cookieStore.addEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
327
|
-
}
|
|
328
|
-
|
|
352
|
+
}
|
|
353
|
+
removeOnChangeEventListener(callback) {
|
|
329
354
|
window.cookieStore.removeEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
330
|
-
}
|
|
355
|
+
}
|
|
331
356
|
}
|
|
332
357
|
export { CookiesHelper };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.152",
|
|
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",
|