@futdevpro/fsm-dynamo 1.11.21 → 1.11.23

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,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const crypto_2_non_stable_util_1 = require("./crypto-2-non-stable.util");
3
+ const crypto_util_1 = require("./crypto.util");
4
4
  describe('| DyFM_Crypto', () => {
5
5
  const testKey = 'test-secret-key-123';
6
6
  const testData = { id: 1, name: 'test' };
7
7
  describe('| encrypt', () => {
8
8
  it('| should successfully encrypt data', () => {
9
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
9
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
10
10
  expect(encrypted).toBeDefined();
11
11
  expect(typeof encrypted).toBe('string');
12
12
  expect(encrypted).toMatch(/^[A-Za-z0-9\-_]+$/);
@@ -14,13 +14,13 @@ describe('| DyFM_Crypto', () => {
14
14
  it('| should encrypt different data with different results', () => {
15
15
  const data1 = { id: 1 };
16
16
  const data2 = { id: 2 };
17
- const encrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(data1, testKey);
18
- const encrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(data2, testKey);
17
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(data1, testKey);
18
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(data2, testKey);
19
19
  expect(encrypted1).not.toEqual(encrypted2);
20
20
  });
21
21
  it('| should throw DyFM_Error when encryption fails', () => {
22
22
  // @ts-ignore - Testing invalid input
23
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(undefined, testKey)).toThrow();
23
+ expect(() => crypto_util_1.DyFM_Crypto.encrypt(undefined, testKey)).toThrow();
24
24
  });
25
25
  it('| should handle complex objects', () => {
26
26
  const complexData = {
@@ -31,8 +31,8 @@ describe('| DyFM_Crypto', () => {
31
31
  array: [1, 2, 3]
32
32
  }
33
33
  };
34
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(complexData, testKey);
35
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
34
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(complexData, testKey);
35
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
36
36
  expect(decrypted).toEqual(complexData);
37
37
  });
38
38
  it('| should get the same result with the same input', () => {
@@ -45,8 +45,8 @@ describe('| DyFM_Crypto', () => {
45
45
  }
46
46
  };
47
47
  const expectedResult = JSON.stringify(complexData);
48
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(complexData, testKey);
49
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
48
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(complexData, testKey);
49
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
50
50
  const result = JSON.stringify(decrypted);
51
51
  expect(result).toBe(expectedResult);
52
52
  });
@@ -57,81 +57,264 @@ describe('| DyFM_Crypto', () => {
57
57
  nested: { value: 'nested-value', array: [1, 2, 3] }
58
58
  };
59
59
  const originalData = JSON.stringify(complexData);
60
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(complexData, testKey);
61
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
60
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(complexData, testKey);
61
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
62
62
  const result = JSON.stringify(decrypted);
63
63
  expect(result).toBe(originalData);
64
64
  });
65
65
  it('| should handle arrays', () => {
66
66
  const arrayData = [1, 'test', { nested: true }];
67
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(arrayData, testKey);
68
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
67
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(arrayData, testKey);
68
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
69
69
  expect(decrypted).toEqual(arrayData);
70
70
  });
71
71
  it('| should handle primitive values', () => {
72
72
  const stringData = 'test string';
73
73
  const numberData = 42;
74
74
  const booleanData = true;
75
- const encryptedString = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(stringData, testKey);
76
- const encryptedNumber = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(numberData, testKey);
77
- const encryptedBoolean = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(booleanData, testKey);
78
- expect(crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encryptedString, testKey)).toBe(stringData);
79
- expect(crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encryptedNumber, testKey)).toBe(numberData);
80
- expect(crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encryptedBoolean, testKey)).toBe(booleanData);
75
+ const encryptedString = crypto_util_1.DyFM_Crypto.encrypt(stringData, testKey);
76
+ const encryptedNumber = crypto_util_1.DyFM_Crypto.encrypt(numberData, testKey);
77
+ const encryptedBoolean = crypto_util_1.DyFM_Crypto.encrypt(booleanData, testKey);
78
+ expect(crypto_util_1.DyFM_Crypto.decrypt(encryptedString, testKey)).toBe(stringData);
79
+ expect(crypto_util_1.DyFM_Crypto.decrypt(encryptedNumber, testKey)).toBe(numberData);
80
+ expect(crypto_util_1.DyFM_Crypto.decrypt(encryptedBoolean, testKey)).toBe(booleanData);
81
81
  });
82
82
  });
83
83
  describe('| decrypt', () => {
84
84
  it('| should successfully decrypt encrypted data', () => {
85
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
86
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
85
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
86
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
87
87
  expect(decrypted).toEqual(testData);
88
88
  });
89
89
  it('| should throw DyFM_Error when decryption fails', () => {
90
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt('invalid-encrypted-data', testKey)).toThrow();
90
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt('invalid-encrypted-data', testKey)).toThrow();
91
91
  });
92
92
  it('| should throw DyFM_Error when using wrong key', () => {
93
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
94
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, 'wrong-key')).toThrow();
93
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
94
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt(encrypted, 'wrong-key')).toThrow();
95
95
  });
96
96
  it('| should throw DyFM_Error when encrypted data is modified', () => {
97
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
97
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
98
98
  const modified = encrypted.slice(0, -1) + 'A';
99
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(modified, testKey)).toThrow();
99
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt(modified, testKey)).toThrow();
100
100
  });
101
101
  });
102
102
  describe('| URL-safe encryption', () => {
103
103
  it('| should produce URL-safe strings', () => {
104
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
104
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
105
105
  expect(encrypted).toMatch(/^[A-Za-z0-9\-_]+$/);
106
106
  });
107
107
  it('| should work in HTTP headers', () => {
108
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
108
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
109
109
  const header = `Bearer ${encrypted}`;
110
110
  const extracted = header.split(' ')[1];
111
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(extracted, testKey);
111
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(extracted, testKey);
112
112
  expect(decrypted).toEqual(testData);
113
113
  });
114
114
  it('| should work in URLs', () => {
115
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
115
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
116
116
  const url = `https://example.com/api?token=${encrypted}`;
117
117
  const params = new URLSearchParams(url.split('?')[1]);
118
118
  const extracted = params.get('token');
119
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(extracted, testKey);
119
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(extracted, testKey);
120
120
  expect(decrypted).toEqual(testData);
121
121
  });
122
122
  });
123
+ describe('| LONG-TERM STABILITY TESTS - Cross-platform compatibility', () => {
124
+ describe('| Deterministic encryption consistency', () => {
125
+ it('| should produce identical encrypted output for identical input across multiple calls', () => {
126
+ const testData = { id: 1, name: 'test', timestamp: '2024-01-01T00:00:00Z' };
127
+ const key = 'stable-test-key-123';
128
+ // Multiple encryption calls should produce identical results
129
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
130
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
131
+ const encrypted3 = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
132
+ expect(encrypted1).toBe(encrypted2);
133
+ expect(encrypted2).toBe(encrypted3);
134
+ expect(encrypted1).toBe(encrypted3);
135
+ // All should decrypt to the same data
136
+ const decrypted1 = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
137
+ const decrypted2 = crypto_util_1.DyFM_Crypto.decrypt(encrypted2, key);
138
+ const decrypted3 = crypto_util_1.DyFM_Crypto.decrypt(encrypted3, key);
139
+ expect(decrypted1).toEqual(decrypted2);
140
+ expect(decrypted2).toEqual(decrypted3);
141
+ expect(decrypted1).toEqual(testData);
142
+ });
143
+ it('| should maintain consistency with different data types and structures', () => {
144
+ const testCases = [
145
+ { data: { id: 1, name: 'simple' }, key: 'key1' },
146
+ { data: 'plain string', key: 'key2' },
147
+ { data: [1, 2, 3, 'array'], key: 'key3' },
148
+ { data: { nested: { deep: { value: true } } }, key: 'key4' },
149
+ { data: { empty: {}, null: null }, key: 'key5' } // Removed undefined as it gets filtered out
150
+ ];
151
+ testCases.forEach(({ data, key }) => {
152
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
153
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
154
+ expect(encrypted1).toBe(encrypted2);
155
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
156
+ expect(decrypted).toEqual(data);
157
+ });
158
+ });
159
+ it('| should handle edge cases consistently', () => {
160
+ const edgeCases = [
161
+ { data: '', key: 'empty-string-key' },
162
+ { data: 0, key: 'zero-number-key' },
163
+ { data: false, key: 'false-boolean-key' },
164
+ { data: { a: 0, b: false, c: '' }, key: 'mixed-edge-key' }
165
+ ];
166
+ edgeCases.forEach(({ data, key }) => {
167
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
168
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
169
+ expect(encrypted1).toBe(encrypted2);
170
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
171
+ expect(decrypted).toEqual(data);
172
+ });
173
+ });
174
+ });
175
+ describe('| Cross-version compatibility simulation', () => {
176
+ it('| should handle data encrypted with different configurations consistently', () => {
177
+ const testData = { id: 1, name: 'config-test' };
178
+ const key = 'config-test-key';
179
+ // Test with default config
180
+ const defaultEncrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
181
+ const defaultDecrypted = crypto_util_1.DyFM_Crypto.decrypt(defaultEncrypted, key);
182
+ expect(defaultDecrypted).toEqual(testData);
183
+ // Test with custom config
184
+ const customConfig = { keyIterations: 500, keySize: 6 };
185
+ const customEncrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, key, customConfig);
186
+ const customDecrypted = crypto_util_1.DyFM_Crypto.decrypt(customEncrypted, key, customConfig);
187
+ expect(customDecrypted).toEqual(testData);
188
+ // Test that different configs produce different encrypted results
189
+ expect(defaultEncrypted).not.toBe(customEncrypted);
190
+ });
191
+ it('| should maintain backward compatibility with existing encrypted data', () => {
192
+ // Simulate data that was encrypted with previous version
193
+ const legacyData = { id: 1, name: 'legacy-test', version: '1.0' };
194
+ const key = 'legacy-key';
195
+ // Encrypt with current implementation
196
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(legacyData, key);
197
+ // Simulate system restart/reload
198
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, key);
199
+ expect(decrypted).toEqual(legacyData);
200
+ // Re-encrypt should produce same result
201
+ const reEncrypted = crypto_util_1.DyFM_Crypto.encrypt(decrypted, key);
202
+ expect(reEncrypted).toBe(encrypted);
203
+ });
204
+ });
205
+ describe('| Platform independence tests', () => {
206
+ it('| should handle different character encodings consistently', () => {
207
+ const unicodeData = {
208
+ hungarian: 'árvíztűrő tükörfúrógép',
209
+ chinese: '你好世界',
210
+ emoji: '🚀💻🔒',
211
+ special: '!@#$%^&*()_+-=[]{}|;:,.<>?'
212
+ };
213
+ const key = 'unicode-test-key';
214
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(unicodeData, key);
215
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, key);
216
+ expect(decrypted).toEqual(unicodeData);
217
+ // Multiple encryptions should be identical
218
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(unicodeData, key);
219
+ expect(encrypted).toBe(encrypted2);
220
+ });
221
+ it('| should handle large data objects consistently', () => {
222
+ // Create a large object with many properties
223
+ const largeData = { id: 1 };
224
+ for (let i = 0; i < 100; i++) {
225
+ largeData[`prop${i}`] = `value${i}`;
226
+ }
227
+ const key = 'large-data-key';
228
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(largeData, key);
229
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(largeData, key);
230
+ expect(encrypted1).toBe(encrypted2);
231
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
232
+ expect(decrypted).toEqual(largeData);
233
+ });
234
+ it('| should handle nested circular references gracefully', () => {
235
+ const circularData = { id: 1, name: 'circular' };
236
+ circularData.self = circularData;
237
+ const key = 'circular-key';
238
+ // Should handle circular references without crashing
239
+ expect(() => {
240
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(circularData, key);
241
+ // Note: JSON.stringify will fail on circular refs, so this test ensures graceful handling
242
+ }).toThrow(); // Expected to throw due to circular reference
243
+ });
244
+ });
245
+ describe('| Time-based stability tests', () => {
246
+ it('| should maintain consistency across time-based operations', () => {
247
+ const timeData = {
248
+ timestamp: new Date().toISOString(),
249
+ id: 1,
250
+ name: 'time-test'
251
+ };
252
+ const key = 'time-test-key';
253
+ // Encrypt same data multiple times
254
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(timeData, key);
255
+ // Simulate time passing
256
+ setTimeout(() => {
257
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(timeData, key);
258
+ expect(encrypted1).toBe(encrypted2);
259
+ }, 100);
260
+ });
261
+ it('| should handle date objects consistently', () => {
262
+ const dateData = {
263
+ created: new Date('2024-01-01T00:00:00Z'),
264
+ updated: new Date('2024-12-31T23:59:59Z'),
265
+ id: 1
266
+ };
267
+ const key = 'date-test-key';
268
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(dateData, key);
269
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(dateData, key);
270
+ expect(encrypted1).toBe(encrypted2);
271
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
272
+ // Compare ISO strings since JSON serialization converts dates to strings
273
+ expect(decrypted.created).toEqual(dateData.created.toISOString());
274
+ expect(decrypted.updated).toEqual(dateData.updated.toISOString());
275
+ expect(decrypted.id).toBe(dateData.id);
276
+ });
277
+ });
278
+ describe('| Memory and performance stability', () => {
279
+ it('| should handle multiple encryption/decryption cycles without memory leaks', () => {
280
+ const testData = { id: 1, name: 'memory-test' };
281
+ const key = 'memory-test-key';
282
+ // Perform many encryption/decryption cycles
283
+ for (let i = 0; i < 1000; i++) {
284
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
285
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, key);
286
+ expect(decrypted).toEqual(testData);
287
+ }
288
+ });
289
+ it('| should maintain consistent performance across multiple operations', () => {
290
+ const testData = { id: 1, name: 'performance-test' };
291
+ const key = 'performance-test-key';
292
+ const startTime = Date.now();
293
+ // Perform multiple operations
294
+ for (let i = 0; i < 100; i++) {
295
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
296
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, key);
297
+ expect(decrypted).toEqual(testData);
298
+ }
299
+ const endTime = Date.now();
300
+ const duration = endTime - startTime;
301
+ // Should complete within reasonable time (adjust threshold as needed)
302
+ expect(duration).toBeLessThan(5000); // 5 seconds max
303
+ });
304
+ });
305
+ });
123
306
  describe('| edge cases', () => {
124
307
  describe('| empty and null values', () => {
125
308
  it('| should handle empty objects', () => {
126
309
  const emptyObj = {};
127
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(emptyObj, testKey);
128
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
310
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(emptyObj, testKey);
311
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
129
312
  expect(decrypted).toEqual(emptyObj);
130
313
  });
131
314
  it('| should handle empty arrays', () => {
132
315
  const emptyArr = [];
133
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(emptyArr, testKey);
134
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
316
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(emptyArr, testKey);
317
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
135
318
  expect(decrypted).toEqual(emptyArr);
136
319
  });
137
320
  it('| should handle null values in objects', () => {
@@ -140,8 +323,8 @@ describe('| DyFM_Crypto', () => {
140
323
  name: null,
141
324
  nested: { value: null }
142
325
  };
143
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(dataWithNull, testKey);
144
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
326
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(dataWithNull, testKey);
327
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
145
328
  expect(decrypted).toEqual(dataWithNull);
146
329
  });
147
330
  it('| should handle undefined values in objects', () => {
@@ -150,41 +333,41 @@ describe('| DyFM_Crypto', () => {
150
333
  name: undefined,
151
334
  nested: { value: undefined }
152
335
  };
153
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(dataWithUndefined, testKey);
154
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
336
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(dataWithUndefined, testKey);
337
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
155
338
  expect(decrypted).toEqual({ id: 1, nested: {} });
156
339
  });
157
340
  });
158
341
  describe('| key edge cases', () => {
159
342
  it('| should handle very long keys', () => {
160
343
  const longKey = 'a'.repeat(1000);
161
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, longKey);
162
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, longKey);
344
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, longKey);
345
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, longKey);
163
346
  expect(decrypted).toEqual(testData);
164
347
  });
165
348
  it('| should handle empty key', () => {
166
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, '')).toThrow();
349
+ expect(() => crypto_util_1.DyFM_Crypto.encrypt(testData, '')).toThrow();
167
350
  });
168
351
  it('| should handle whitespace-only keys', () => {
169
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, ' ')).toThrow();
352
+ expect(() => crypto_util_1.DyFM_Crypto.encrypt(testData, ' ')).toThrow();
170
353
  });
171
354
  });
172
355
  describe('| encrypted data manipulation', () => {
173
356
  it('| should detect when encrypted data is truncated', () => {
174
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
357
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
175
358
  const truncated = encrypted.slice(0, -10);
176
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(truncated, testKey)).toThrow();
359
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt(truncated, testKey)).toThrow();
177
360
  });
178
361
  it('| should detect when encrypted data is extended', () => {
179
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
362
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
180
363
  const extended = encrypted + 'A'.repeat(10);
181
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(extended, testKey)).toThrow();
364
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt(extended, testKey)).toThrow();
182
365
  });
183
366
  it('| should detect when encrypted data is modified in the middle', () => {
184
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, testKey);
367
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(testData, testKey);
185
368
  const midPoint = Math.floor(encrypted.length / 2);
186
369
  const modified = encrypted.slice(0, midPoint) + 'X' + encrypted.slice(midPoint + 1);
187
- expect(() => crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(modified, testKey)).toThrow();
370
+ expect(() => crypto_util_1.DyFM_Crypto.decrypt(modified, testKey)).toThrow();
188
371
  });
189
372
  });
190
373
  describe('| JSON handling edge cases', () => {
@@ -200,8 +383,8 @@ describe('| DyFM_Crypto', () => {
200
383
  };
201
384
  // Simulate double stringification
202
385
  const doubleStringified = JSON.stringify(JSON.stringify(testData));
203
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(doubleStringified, testKey);
204
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
386
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(doubleStringified, testKey);
387
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
205
388
  // Should be able to parse the decrypted data back to the original object
206
389
  const parsed = JSON.parse(decrypted);
207
390
  expect(parsed).toEqual(testData);
@@ -451,8 +634,8 @@ describe('| DyFM_Crypto', () => {
451
634
  '239': '}',
452
635
  '240': '}'
453
636
  };
454
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(charByCharData, testKey);
455
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
637
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(charByCharData, testKey);
638
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
456
639
  // Should be able to parse the decrypted data back to the original object
457
640
  expect(decrypted).toEqual(charByCharData);
458
641
  });
@@ -466,11 +649,11 @@ describe('| DyFM_Crypto', () => {
466
649
  };
467
650
  const key = 'test-secret-key-123';
468
651
  // Simulate different environments by creating new instances
469
- const encrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, key);
470
- const encrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(testData, key);
652
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
653
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(testData, key);
471
654
  expect(encrypted1).toBe(encrypted2);
472
- expect(crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted1, key)).toEqual(testData);
473
- expect(crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted2, key)).toEqual(testData);
655
+ expect(crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key)).toEqual(testData);
656
+ expect(crypto_util_1.DyFM_Crypto.decrypt(encrypted2, key)).toEqual(testData);
474
657
  });
475
658
  it('| should maintain encryption consistency with different data types', () => {
476
659
  const testCases = [
@@ -480,8 +663,8 @@ describe('| DyFM_Crypto', () => {
480
663
  { data: { nested: { value: true } }, key: 'key4' }
481
664
  ];
482
665
  testCases.forEach(({ data, key }) => {
483
- const encrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(data, key);
484
- const encrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(data, key);
666
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
667
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(data, key);
485
668
  expect(encrypted1).toBe(encrypted2);
486
669
  });
487
670
  });
@@ -499,10 +682,10 @@ describe('| DyFM_Crypto', () => {
499
682
  };
500
683
  const key = 'db-storage-key';
501
684
  // Simulate database storage and retrieval
502
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(originalData, key);
685
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(originalData, key);
503
686
  const storedData = encrypted; // Simulating database storage
504
687
  const retrievedData = storedData; // Simulating database retrieval
505
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(retrievedData, key);
688
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(retrievedData, key);
506
689
  expect(decrypted).toEqual(originalData);
507
690
  });
508
691
  it('| should handle multiple encryption/decryption cycles for database operations', () => {
@@ -517,15 +700,15 @@ describe('| DyFM_Crypto', () => {
517
700
  };
518
701
  const key = 'persistent-key';
519
702
  // Simulate multiple database operations
520
- const encrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(userData, key);
521
- const decrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted1, key);
703
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(userData, key);
704
+ const decrypted1 = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
522
705
  // Simulate data update with a different timestamp
523
706
  const updatedData = {
524
707
  ...decrypted1,
525
708
  lastLogin: '2024-01-02T15:30:00.000Z'
526
709
  };
527
- const encrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(updatedData, key);
528
- const decrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted2, key);
710
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(updatedData, key);
711
+ const decrypted2 = crypto_util_1.DyFM_Crypto.decrypt(encrypted2, key);
529
712
  expect(decrypted1).toEqual(userData);
530
713
  expect(decrypted2).toEqual(updatedData);
531
714
  expect(decrypted2.lastLogin).not.toBe(userData.lastLogin);
@@ -541,10 +724,10 @@ describe('| DyFM_Crypto', () => {
541
724
  };
542
725
  const key = 'sensitive-data-key';
543
726
  // Simulate multiple database operations with the same data
544
- const encrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(sensitiveData, key);
545
- const decrypted1 = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted1, key);
546
- const encrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(decrypted1, key);
547
- const decrypted2 = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted2, key);
727
+ const encrypted1 = crypto_util_1.DyFM_Crypto.encrypt(sensitiveData, key);
728
+ const decrypted1 = crypto_util_1.DyFM_Crypto.decrypt(encrypted1, key);
729
+ const encrypted2 = crypto_util_1.DyFM_Crypto.encrypt(decrypted1, key);
730
+ const decrypted2 = crypto_util_1.DyFM_Crypto.decrypt(encrypted2, key);
548
731
  expect(decrypted1).toEqual(sensitiveData);
549
732
  expect(decrypted2).toEqual(sensitiveData);
550
733
  expect(encrypted1).toBe(encrypted2); // Different encryption instances
@@ -559,8 +742,8 @@ describe('| DyFM_Crypto', () => {
559
742
  'ĐĐĐđđđßßߤ¤¤×××÷÷÷¨¨¨¨~~~ˇˇˇ^^^˘˘˘°°°˛˛˛```˙˙˙´´´˝˝˝˝¸¸¸§§§' +
560
743
  '???ééééáááűűűúúúőőőóóóüüüöööíííÉÉÉÁÁÁŰŰŰÚÚÚŐŐŐÓÓÓÜÖÖÖÍÍÍ'
561
744
  };
562
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(unicodeData, testKey);
563
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
745
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(unicodeData, testKey);
746
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
564
747
  expect(decrypted).toEqual(unicodeData);
565
748
  });
566
749
  it('| should handle special characters in object keys', () => {
@@ -570,8 +753,8 @@ describe('| DyFM_Crypto', () => {
570
753
  'key-with-special-chars!@#': 'value',
571
754
  'key-with-unicode-世界': 'value'
572
755
  };
573
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(specialKeyData, testKey);
574
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
756
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(specialKeyData, testKey);
757
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
575
758
  expect(decrypted).toEqual(specialKeyData);
576
759
  });
577
760
  it('| should handle special characters in nested objects', () => {
@@ -582,8 +765,8 @@ describe('| DyFM_Crypto', () => {
582
765
  }
583
766
  }
584
767
  };
585
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(nestedData, testKey);
586
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
768
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(nestedData, testKey);
769
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
587
770
  expect(decrypted).toEqual(nestedData);
588
771
  });
589
772
  it('| should handle special characters in arrays', () => {
@@ -592,8 +775,8 @@ describe('| DyFM_Crypto', () => {
592
775
  { 'special-key': 'value with !@#' },
593
776
  ['nested', 'array', 'with', 'special', 'chars!@#']
594
777
  ];
595
- const encrypted = crypto_2_non_stable_util_1.DyFM_Crypto.encrypt(arrayData, testKey);
596
- const decrypted = crypto_2_non_stable_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
778
+ const encrypted = crypto_util_1.DyFM_Crypto.encrypt(arrayData, testKey);
779
+ const decrypted = crypto_util_1.DyFM_Crypto.decrypt(encrypted, testKey);
597
780
  expect(decrypted).toEqual(arrayData);
598
781
  });
599
782
  });