@xiboplayer/utils 0.6.13 → 0.7.0
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.
- package/package.json +2 -2
- package/src/config.js +0 -28
- package/src/config.test.js +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Shared utilities for Xibo Player packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"./config": "./src/config.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@xiboplayer/crypto": "0.
|
|
15
|
+
"@xiboplayer/crypto": "0.7.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"vitest": "^2.0.0"
|
package/src/config.js
CHANGED
|
@@ -510,34 +510,6 @@ export class Config {
|
|
|
510
510
|
console.log('[Config] RSA key pair generated and saved');
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
-
hash(str) {
|
|
514
|
-
// FNV-1a hash algorithm (better distribution than simple hash)
|
|
515
|
-
// Produces high-entropy 32-character hex string
|
|
516
|
-
let hash = 2166136261; // FNV offset basis
|
|
517
|
-
|
|
518
|
-
for (let i = 0; i < str.length; i++) {
|
|
519
|
-
hash ^= str.charCodeAt(i);
|
|
520
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// Convert to unsigned 32-bit integer
|
|
524
|
-
hash = hash >>> 0;
|
|
525
|
-
|
|
526
|
-
// Extend to 32 characters by hashing multiple times with different seeds
|
|
527
|
-
let result = '';
|
|
528
|
-
for (let round = 0; round < 4; round++) {
|
|
529
|
-
let roundHash = hash + round * 1234567;
|
|
530
|
-
for (let i = 0; i < str.length; i++) {
|
|
531
|
-
roundHash ^= str.charCodeAt(i) + round;
|
|
532
|
-
roundHash += (roundHash << 1) + (roundHash << 4) + (roundHash << 7) + (roundHash << 8) + (roundHash << 24);
|
|
533
|
-
}
|
|
534
|
-
roundHash = roundHash >>> 0;
|
|
535
|
-
result += roundHash.toString(16).padStart(8, '0');
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return result.substring(0, 32);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
513
|
get cmsUrl() { return this.data.cmsUrl; }
|
|
542
514
|
set cmsUrl(val) { this.data.cmsUrl = val; this.save(); }
|
|
543
515
|
|
package/src/config.test.js
CHANGED
|
@@ -224,51 +224,6 @@ describe('Config', () => {
|
|
|
224
224
|
});
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
describe('Hash Function (FNV-1a)', () => {
|
|
228
|
-
beforeEach(() => {
|
|
229
|
-
config = new Config();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('should generate 32-character hex hash', () => {
|
|
233
|
-
const hash = config.hash('test string');
|
|
234
|
-
|
|
235
|
-
expect(hash).toMatch(/^[0-9a-f]{32}$/);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('should be deterministic for same input', () => {
|
|
239
|
-
const hash1 = config.hash('test');
|
|
240
|
-
const hash2 = config.hash('test');
|
|
241
|
-
|
|
242
|
-
expect(hash1).toBe(hash2);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('should produce different hashes for different inputs', () => {
|
|
246
|
-
const hash1 = config.hash('test1');
|
|
247
|
-
const hash2 = config.hash('test2');
|
|
248
|
-
|
|
249
|
-
expect(hash1).not.toBe(hash2);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should handle empty string', () => {
|
|
253
|
-
const hash = config.hash('');
|
|
254
|
-
|
|
255
|
-
expect(hash).toMatch(/^[0-9a-f]{32}$/);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should produce good entropy for similar inputs', () => {
|
|
259
|
-
const hash1 = config.hash('a');
|
|
260
|
-
const hash2 = config.hash('b');
|
|
261
|
-
|
|
262
|
-
// Hashes should be completely different (not just 1 character difference)
|
|
263
|
-
let differences = 0;
|
|
264
|
-
for (let i = 0; i < hash1.length; i++) {
|
|
265
|
-
if (hash1[i] !== hash2[i]) differences++;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
expect(differences).toBeGreaterThan(15); // At least half different
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
227
|
describe('Canvas Fingerprint', () => {
|
|
273
228
|
let createElementSpy;
|
|
274
229
|
|
|
@@ -482,22 +437,6 @@ describe('Config', () => {
|
|
|
482
437
|
expect(config.cmsUrl).toBe('');
|
|
483
438
|
});
|
|
484
439
|
|
|
485
|
-
it('should handle very long strings', () => {
|
|
486
|
-
config = new Config();
|
|
487
|
-
|
|
488
|
-
const longString = 'a'.repeat(10000);
|
|
489
|
-
const hash = config.hash(longString);
|
|
490
|
-
|
|
491
|
-
expect(hash).toMatch(/^[0-9a-f]{32}$/);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it('should handle unicode in hash', () => {
|
|
495
|
-
config = new Config();
|
|
496
|
-
|
|
497
|
-
const hash = config.hash('测试中文🎉');
|
|
498
|
-
|
|
499
|
-
expect(hash).toMatch(/^[0-9a-f]{32}$/);
|
|
500
|
-
});
|
|
501
440
|
});
|
|
502
441
|
|
|
503
442
|
describe('Persistence', () => {
|