ggez-banking-sdk 0.1.100 → 0.1.102

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: (program_id: string) => CipherKeyIV;
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
- const KEY = _a.PaddingLeft(code.toString(), 32, "0");
29
- const IV = _a.PaddingLeft(code.toString(), 16, "0");
30
- return { key: KEY, iv: IV };
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
- const DID_KEY = _a.PaddingLeft(USR.device_id.toString(), 10, "0");
34
- const UID_KEY = _a.PaddingLeft(USR.user_id.toString(), 10, "0");
35
- const IID_KEY = IID.slice(0, 10);
36
- const KEY = `${DID_KEY}.${UID_KEY}.${IID_KEY}`.toString();
37
- const DID_IV = _a.PaddingLeft(USR.device_id.toString(), 8, "0");
38
- const UID_IV = _a.PaddingLeft(USR.user_id.toString(), 8, "0");
39
- const IV = `${DID_IV}${UID_IV}`.toString();
40
- return { key: KEY, iv: IV };
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 = (program_id) => {
43
- const PID_KEY = _a.PaddingLeft(program_id.toString(), 10, "0");
44
- const F_KEY = _a.PaddingLeft("0".toString(), 10, "0");
45
- const FingerPrint_KEY = _a.PaddingLeft("", 10, "0");
46
- const KEY = `${PID_KEY}.${F_KEY}.${FingerPrint_KEY}`;
47
- const PID_IV = _a.PaddingLeft(program_id.toString(), 8, "0");
48
- const F_IV = _a.PaddingLeft("0".toString(), 8, "0");
49
- const IV = `${PID_IV}${F_IV}`;
50
- return { key: KEY, iv: IV };
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
- const IID_KEY = IID.slice(0, 32);
59
- const IID_IV = IID.slice(0, 16);
60
- return { key: IID_KEY, iv: IID_IV };
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)
@@ -1,13 +1,14 @@
1
1
  import { USR } from "../types";
2
2
  declare class CookiesHelper {
3
- static GetIID: () => string;
3
+ static GetIID: () => any;
4
4
  static SetIID: () => void;
5
5
  static GetDEK: () => string;
6
6
  static SetDEK: (deviceEncryptionKey: string, USR: USR) => void;
7
7
  static GetUSR: () => USR;
8
8
  static SetUSR: (deviceId: string, userId: string) => void;
9
9
  static GetDeviceSecurityCode: () => string;
10
- static SET: (key: string, value: string, expires?: Date) => void;
11
10
  static GET: (key: string) => string | undefined;
11
+ static SET: (key: string, value: string, expires?: Date) => void;
12
+ static REMOVE: (key: string) => void;
12
13
  }
13
14
  export { CookiesHelper };
@@ -8,9 +8,12 @@ _a = CookiesHelper;
8
8
  // #region "IID"
9
9
  CookiesHelper.GetIID = () => {
10
10
  try {
11
- const programId = process.env.NEXT_PUBLIC_PROGRAM_ID;
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(programId);
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 { iv, key } = CipherHelper.GenerateByInstallationID(IID);
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 { iv, key } = CipherHelper.GenerateByInstallationID(IID);
87
+ const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
83
88
  const USR = JSON.stringify({
84
89
  device_id: deviceId,
85
90
  user_id: userId,
@@ -109,6 +114,9 @@ CookiesHelper.GetDeviceSecurityCode = () => {
109
114
  };
110
115
  // #endregion
111
116
  // #region "Getters & Setters"
117
+ CookiesHelper.GET = (key) => {
118
+ return Cookies.get(key);
119
+ };
112
120
  CookiesHelper.SET = (key, value, expires) => {
113
121
  const defaultExpireDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365);
114
122
  Cookies.set(key, value, {
@@ -118,7 +126,7 @@ CookiesHelper.SET = (key, value, expires) => {
118
126
  expires: expires || defaultExpireDate,
119
127
  });
120
128
  };
121
- CookiesHelper.GET = (key) => {
122
- return Cookies.get(key);
129
+ CookiesHelper.REMOVE = (key) => {
130
+ Cookies.remove(key);
123
131
  };
124
132
  export { CookiesHelper };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ggez-banking-sdk",
3
- "version": "0.1.100",
3
+ "version": "0.1.102",
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",