@cutos/core 0.0.7 → 0.0.8

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/dist/cutos.cjs.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var crypto = require('crypto');
5
6
  var require$$1 = require('mqtt');
6
7
  var require$$0$1 = require('qs');
7
8
 
@@ -32,23 +33,16 @@ function getAugmentedNamespace(n) {
32
33
 
33
34
  var cutos = {};
34
35
 
35
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
36
- // require the crypto API and do not support built-in fallback to lower quality random number
37
- // generators (like Math.random()).
38
- let getRandomValues;
39
- const rnds8 = new Uint8Array(16);
40
- function rng() {
41
- // lazy load so that environments that need to polyfill have a chance to do so
42
- if (!getRandomValues) {
43
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
44
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
36
+ const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
45
37
 
46
- if (!getRandomValues) {
47
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
48
- }
38
+ let poolPtr = rnds8Pool.length;
39
+ function rng() {
40
+ if (poolPtr > rnds8Pool.length - 16) {
41
+ crypto.randomFillSync(rnds8Pool);
42
+ poolPtr = 0;
49
43
  }
50
44
 
51
- return getRandomValues(rnds8);
45
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
52
46
  }
53
47
 
54
48
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
@@ -276,226 +270,21 @@ function v35(name, version, hashfunc) {
276
270
  return generateUUID;
277
271
  }
278
272
 
279
- /*
280
- * Browser-compatible JavaScript MD5
281
- *
282
- * Modification of JavaScript MD5
283
- * https://github.com/blueimp/JavaScript-MD5
284
- *
285
- * Copyright 2011, Sebastian Tschan
286
- * https://blueimp.net
287
- *
288
- * Licensed under the MIT license:
289
- * https://opensource.org/licenses/MIT
290
- *
291
- * Based on
292
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
293
- * Digest Algorithm, as defined in RFC 1321.
294
- * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
295
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
296
- * Distributed under the BSD License
297
- * See http://pajhome.org.uk/crypt/md5 for more info.
298
- */
299
273
  function md5(bytes) {
300
- if (typeof bytes === 'string') {
301
- const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
302
-
303
- bytes = new Uint8Array(msg.length);
304
-
305
- for (let i = 0; i < msg.length; ++i) {
306
- bytes[i] = msg.charCodeAt(i);
307
- }
274
+ if (Array.isArray(bytes)) {
275
+ bytes = Buffer.from(bytes);
276
+ } else if (typeof bytes === 'string') {
277
+ bytes = Buffer.from(bytes, 'utf8');
308
278
  }
309
279
 
310
- return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
311
- }
312
- /*
313
- * Convert an array of little-endian words to an array of bytes
314
- */
315
-
316
-
317
- function md5ToHexEncodedArray(input) {
318
- const output = [];
319
- const length32 = input.length * 32;
320
- const hexTab = '0123456789abcdef';
321
-
322
- for (let i = 0; i < length32; i += 8) {
323
- const x = input[i >> 5] >>> i % 32 & 0xff;
324
- const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
325
- output.push(hex);
326
- }
327
-
328
- return output;
329
- }
330
- /**
331
- * Calculate output length with padding and bit length
332
- */
333
-
334
-
335
- function getOutputLength(inputLength8) {
336
- return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
337
- }
338
- /*
339
- * Calculate the MD5 of an array of little-endian words, and a bit length.
340
- */
341
-
342
-
343
- function wordsToMd5(x, len) {
344
- /* append padding */
345
- x[len >> 5] |= 0x80 << len % 32;
346
- x[getOutputLength(len) - 1] = len;
347
- let a = 1732584193;
348
- let b = -271733879;
349
- let c = -1732584194;
350
- let d = 271733878;
351
-
352
- for (let i = 0; i < x.length; i += 16) {
353
- const olda = a;
354
- const oldb = b;
355
- const oldc = c;
356
- const oldd = d;
357
- a = md5ff(a, b, c, d, x[i], 7, -680876936);
358
- d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
359
- c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
360
- b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
361
- a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
362
- d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
363
- c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
364
- b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
365
- a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
366
- d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
367
- c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
368
- b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
369
- a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
370
- d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
371
- c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
372
- b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
373
- a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
374
- d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
375
- c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
376
- b = md5gg(b, c, d, a, x[i], 20, -373897302);
377
- a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
378
- d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
379
- c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
380
- b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
381
- a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
382
- d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
383
- c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
384
- b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
385
- a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
386
- d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
387
- c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
388
- b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
389
- a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
390
- d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
391
- c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
392
- b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
393
- a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
394
- d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
395
- c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
396
- b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
397
- a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
398
- d = md5hh(d, a, b, c, x[i], 11, -358537222);
399
- c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
400
- b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
401
- a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
402
- d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
403
- c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
404
- b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
405
- a = md5ii(a, b, c, d, x[i], 6, -198630844);
406
- d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
407
- c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
408
- b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
409
- a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
410
- d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
411
- c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
412
- b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
413
- a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
414
- d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
415
- c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
416
- b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
417
- a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
418
- d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
419
- c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
420
- b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
421
- a = safeAdd(a, olda);
422
- b = safeAdd(b, oldb);
423
- c = safeAdd(c, oldc);
424
- d = safeAdd(d, oldd);
425
- }
426
-
427
- return [a, b, c, d];
428
- }
429
- /*
430
- * Convert an array bytes to an array of little-endian words
431
- * Characters >255 have their high-byte silently ignored.
432
- */
433
-
434
-
435
- function bytesToWords(input) {
436
- if (input.length === 0) {
437
- return [];
438
- }
439
-
440
- const length8 = input.length * 8;
441
- const output = new Uint32Array(getOutputLength(length8));
442
-
443
- for (let i = 0; i < length8; i += 8) {
444
- output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
445
- }
446
-
447
- return output;
448
- }
449
- /*
450
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
451
- * to work around bugs in some JS interpreters.
452
- */
453
-
454
-
455
- function safeAdd(x, y) {
456
- const lsw = (x & 0xffff) + (y & 0xffff);
457
- const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
458
- return msw << 16 | lsw & 0xffff;
459
- }
460
- /*
461
- * Bitwise rotate a 32-bit number to the left.
462
- */
463
-
464
-
465
- function bitRotateLeft(num, cnt) {
466
- return num << cnt | num >>> 32 - cnt;
467
- }
468
- /*
469
- * These functions implement the four basic operations the algorithm uses.
470
- */
471
-
472
-
473
- function md5cmn(q, a, b, x, s, t) {
474
- return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
475
- }
476
-
477
- function md5ff(a, b, c, d, x, s, t) {
478
- return md5cmn(b & c | ~b & d, a, b, x, s, t);
479
- }
480
-
481
- function md5gg(a, b, c, d, x, s, t) {
482
- return md5cmn(b & d | c & ~d, a, b, x, s, t);
483
- }
484
-
485
- function md5hh(a, b, c, d, x, s, t) {
486
- return md5cmn(b ^ c ^ d, a, b, x, s, t);
487
- }
488
-
489
- function md5ii(a, b, c, d, x, s, t) {
490
- return md5cmn(c ^ (b | ~d), a, b, x, s, t);
280
+ return crypto.createHash('md5').update(bytes).digest();
491
281
  }
492
282
 
493
283
  const v3 = v35('v3', 0x30, md5);
494
284
  var v3$1 = v3;
495
285
 
496
- const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
497
286
  var native = {
498
- randomUUID
287
+ randomUUID: crypto.randomUUID
499
288
  };
500
289
 
501
290
  function v4(options, buf, offset) {
@@ -522,99 +311,14 @@ function v4(options, buf, offset) {
522
311
  return unsafeStringify(rnds);
523
312
  }
524
313
 
525
- // Adapted from Chris Veness' SHA1 code at
526
- // http://www.movable-type.co.uk/scripts/sha1.html
527
- function f(s, x, y, z) {
528
- switch (s) {
529
- case 0:
530
- return x & y ^ ~x & z;
531
-
532
- case 1:
533
- return x ^ y ^ z;
534
-
535
- case 2:
536
- return x & y ^ x & z ^ y & z;
537
-
538
- case 3:
539
- return x ^ y ^ z;
540
- }
541
- }
542
-
543
- function ROTL(x, n) {
544
- return x << n | x >>> 32 - n;
545
- }
546
-
547
314
  function sha1(bytes) {
548
- const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
549
- const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
550
-
551
- if (typeof bytes === 'string') {
552
- const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
553
-
554
- bytes = [];
555
-
556
- for (let i = 0; i < msg.length; ++i) {
557
- bytes.push(msg.charCodeAt(i));
558
- }
559
- } else if (!Array.isArray(bytes)) {
560
- // Convert Array-like to Array
561
- bytes = Array.prototype.slice.call(bytes);
562
- }
563
-
564
- bytes.push(0x80);
565
- const l = bytes.length / 4 + 2;
566
- const N = Math.ceil(l / 16);
567
- const M = new Array(N);
568
-
569
- for (let i = 0; i < N; ++i) {
570
- const arr = new Uint32Array(16);
571
-
572
- for (let j = 0; j < 16; ++j) {
573
- arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
574
- }
575
-
576
- M[i] = arr;
577
- }
578
-
579
- M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
580
- M[N - 1][14] = Math.floor(M[N - 1][14]);
581
- M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
582
-
583
- for (let i = 0; i < N; ++i) {
584
- const W = new Uint32Array(80);
585
-
586
- for (let t = 0; t < 16; ++t) {
587
- W[t] = M[i][t];
588
- }
589
-
590
- for (let t = 16; t < 80; ++t) {
591
- W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
592
- }
593
-
594
- let a = H[0];
595
- let b = H[1];
596
- let c = H[2];
597
- let d = H[3];
598
- let e = H[4];
599
-
600
- for (let t = 0; t < 80; ++t) {
601
- const s = Math.floor(t / 20);
602
- const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
603
- e = d;
604
- d = c;
605
- c = ROTL(b, 30) >>> 0;
606
- b = a;
607
- a = T;
608
- }
609
-
610
- H[0] = H[0] + a >>> 0;
611
- H[1] = H[1] + b >>> 0;
612
- H[2] = H[2] + c >>> 0;
613
- H[3] = H[3] + d >>> 0;
614
- H[4] = H[4] + e >>> 0;
315
+ if (Array.isArray(bytes)) {
316
+ bytes = Buffer.from(bytes);
317
+ } else if (typeof bytes === 'string') {
318
+ bytes = Buffer.from(bytes, 'utf8');
615
319
  }
616
320
 
617
- return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
321
+ return crypto.createHash('sha1').update(bytes).digest();
618
322
  }
619
323
 
620
324
  const v5 = v35('v5', 0x50, sha1);
@@ -630,7 +334,7 @@ function version$1(uuid) {
630
334
  return parseInt(uuid.slice(14, 15), 16);
631
335
  }
632
336
 
633
- var esmBrowser = /*#__PURE__*/Object.freeze({
337
+ var esmNode = /*#__PURE__*/Object.freeze({
634
338
  __proto__: null,
635
339
  NIL: nil,
636
340
  parse: parse,
@@ -643,7 +347,7 @@ var esmBrowser = /*#__PURE__*/Object.freeze({
643
347
  version: version$1
644
348
  });
645
349
 
646
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(esmBrowser);
350
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(esmNode);
647
351
 
648
352
  /**
649
353
  * Copyright (C) 2010-2023 - SipTimes Technologies Corporation - All rights reserved.
@@ -676,7 +380,7 @@ const DEVICE = Object.freeze({ // core level api
676
380
  DEFAULT: 'device-default',
677
381
  ID_CARD_READER: 'device-id-card-reader',
678
382
  NFC: 'device-nfc',
679
- FINGERPRINT_READER: 'device-fingerprint-reader',
383
+ FINGERPRINT: 'device-fingerprint',
680
384
  QR_CODE_SCANNER: 'device-qr-code-scanner',
681
385
  PRINTER: 'device-printer'
682
386
  });
@@ -705,7 +409,7 @@ if(typeof window !== 'undefined') {
705
409
  var utils = config$1;
706
410
 
707
411
  var name = "@cutos/core";
708
- var version = "0.0.7";
412
+ var version = "0.0.8";
709
413
  var description = "";
710
414
  var main = "dist/cutos.cjs.js";
711
415
  var module$1 = "dist/cutos.esm.js";
package/dist/cutos.esm.js CHANGED
@@ -672,7 +672,7 @@ const DEVICE = Object.freeze({ // core level api
672
672
  DEFAULT: 'device-default',
673
673
  ID_CARD_READER: 'device-id-card-reader',
674
674
  NFC: 'device-nfc',
675
- FINGERPRINT_READER: 'device-fingerprint-reader',
675
+ FINGERPRINT: 'device-fingerprint',
676
676
  QR_CODE_SCANNER: 'device-qr-code-scanner',
677
677
  PRINTER: 'device-printer'
678
678
  });
@@ -701,7 +701,7 @@ if(typeof window !== 'undefined') {
701
701
  var utils = config$1;
702
702
 
703
703
  var name = "@cutos/core";
704
- var version = "0.0.7";
704
+ var version = "0.0.8";
705
705
  var description = "";
706
706
  var main = "dist/cutos.cjs.js";
707
707
  var module = "dist/cutos.esm.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "main": "dist/cutos.cjs.js",
6
6
  "module": "dist/cutos.esm.js",