@loaders.gl/crypto 4.0.0-alpha.9 → 4.0.0-beta.1

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.
Files changed (96) hide show
  1. package/dist/crypto-worker-node.js +1 -1
  2. package/dist/crypto-worker-node.js.map +2 -2
  3. package/dist/crypto-worker.js +1 -1
  4. package/dist/crypto-worker.js.map +2 -2
  5. package/dist/dist.min.js +1 -1
  6. package/dist/dist.min.js.map +2 -2
  7. package/dist/es5/index.js +24 -5
  8. package/dist/es5/index.js.map +1 -1
  9. package/dist/es5/lib/algorithms/md5-wasm.js +3 -3
  10. package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
  11. package/dist/es5/lib/crc32-hash.js +11 -13
  12. package/dist/es5/lib/crc32-hash.js.map +1 -1
  13. package/dist/es5/lib/crc32c-hash.js +11 -13
  14. package/dist/es5/lib/crc32c-hash.js.map +1 -1
  15. package/dist/es5/lib/crypto-hash.js +12 -9
  16. package/dist/es5/lib/crypto-hash.js.map +1 -1
  17. package/dist/es5/lib/hash.js +2 -1
  18. package/dist/es5/lib/hash.js.map +1 -1
  19. package/dist/es5/lib/md5-hash.js +3 -3
  20. package/dist/es5/lib/md5-hash.js.map +1 -1
  21. package/dist/es5/lib/node-hash.js +20 -12
  22. package/dist/es5/lib/node-hash.js.map +1 -1
  23. package/dist/es5/lib/utils/base64-utils.js +41 -2
  24. package/dist/es5/lib/utils/base64-utils.js.map +1 -1
  25. package/dist/es5/lib/utils/digest-utils.js +45 -7
  26. package/dist/es5/lib/utils/digest-utils.js.map +1 -1
  27. package/dist/es5/workers/worker.js +6 -4
  28. package/dist/es5/workers/worker.js.map +1 -1
  29. package/dist/esm/index.js +3 -2
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/lib/algorithms/md5-wasm.js +3 -3
  32. package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
  33. package/dist/esm/lib/crc32-hash.js +24 -19
  34. package/dist/esm/lib/crc32-hash.js.map +1 -1
  35. package/dist/esm/lib/crc32c-hash.js +24 -19
  36. package/dist/esm/lib/crc32c-hash.js.map +1 -1
  37. package/dist/esm/lib/crypto-hash.js +23 -13
  38. package/dist/esm/lib/crypto-hash.js.map +1 -1
  39. package/dist/esm/lib/hash.js +19 -11
  40. package/dist/esm/lib/hash.js.map +1 -1
  41. package/dist/esm/lib/md5-hash.js +3 -3
  42. package/dist/esm/lib/md5-hash.js.map +1 -1
  43. package/dist/esm/lib/node-hash.js +29 -15
  44. package/dist/esm/lib/node-hash.js.map +1 -1
  45. package/dist/esm/lib/utils/base64-utils.js +39 -1
  46. package/dist/esm/lib/utils/base64-utils.js.map +1 -1
  47. package/dist/esm/lib/utils/digest-utils.js +39 -6
  48. package/dist/esm/lib/utils/digest-utils.js.map +1 -1
  49. package/dist/esm/workers/worker.js +5 -4
  50. package/dist/esm/workers/worker.js.map +1 -1
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/lib/crc32-hash.d.ts +3 -3
  54. package/dist/lib/crc32-hash.d.ts.map +1 -1
  55. package/dist/lib/crc32c-hash.d.ts +3 -3
  56. package/dist/lib/crc32c-hash.d.ts.map +1 -1
  57. package/dist/lib/crypto-hash.d.ts +2 -2
  58. package/dist/lib/crypto-hash.d.ts.map +1 -1
  59. package/dist/lib/hash.d.ts +2 -2
  60. package/dist/lib/hash.d.ts.map +1 -1
  61. package/dist/lib/md5-hash.d.ts +1 -1
  62. package/dist/lib/md5-hash.d.ts.map +1 -1
  63. package/dist/lib/node-hash.d.ts +2 -2
  64. package/dist/lib/node-hash.d.ts.map +1 -1
  65. package/dist/lib/utils/base64-utils.d.ts +8 -1
  66. package/dist/lib/utils/base64-utils.d.ts.map +1 -1
  67. package/dist/lib/utils/digest-utils.d.ts +6 -6
  68. package/dist/lib/utils/digest-utils.d.ts.map +1 -1
  69. package/package.json +4 -4
  70. package/src/index.ts +10 -7
  71. package/src/lib/algorithms/md5-wasm.ts +4 -3
  72. package/src/lib/crc32-hash.ts +10 -12
  73. package/src/lib/crc32c-hash.ts +10 -12
  74. package/src/lib/crypto-hash.ts +10 -5
  75. package/src/lib/hash.ts +4 -3
  76. package/src/lib/md5-hash.ts +3 -3
  77. package/src/lib/node-hash.ts +14 -6
  78. package/src/lib/utils/base64-utils.ts +97 -1
  79. package/src/lib/utils/digest-utils.ts +57 -8
  80. package/src/workers/worker.ts +4 -4
  81. package/dist/bundle.js +0 -5
  82. package/dist/index.js +0 -47
  83. package/dist/lib/algorithms/crc32.js +0 -30
  84. package/dist/lib/algorithms/crc32c.js +0 -38
  85. package/dist/lib/algorithms/md5-wasm.js +0 -435
  86. package/dist/lib/crc32-hash.js +0 -47
  87. package/dist/lib/crc32c-hash.js +0 -51
  88. package/dist/lib/crypto-hash.js +0 -61
  89. package/dist/lib/hash.js +0 -29
  90. package/dist/lib/md5-hash.js +0 -32
  91. package/dist/lib/node-hash.js +0 -42
  92. package/dist/lib/sha256-hash.js +0 -14
  93. package/dist/lib/utils/base64-utils.js +0 -67
  94. package/dist/lib/utils/digest-utils.js +0 -27
  95. package/dist/types.js +0 -2
  96. package/dist/workers/worker.js +0 -23
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeHash = void 0;
4
- // This dependency is too big, application must provide it
5
- const hash_1 = require("./hash");
6
- const crypto_1 = require("crypto"); // Node.js builtin
7
- /**
8
- * Calculates Cryptographic Hash using Node.js crypto library
9
- * @deprecated Warning, experimental class
10
- */
11
- class NodeHash extends hash_1.Hash {
12
- constructor(options) {
13
- super();
14
- this.name = 'crypto-node';
15
- this.options = options;
16
- if (!this.options?.crypto?.algorithm) {
17
- throw new Error(this.name);
18
- }
19
- }
20
- /**
21
- * Atomic hash calculation
22
- * @returns base64 encoded hash
23
- */
24
- async hash(input) {
25
- await this.preload();
26
- const hash = (0, crypto_1.createHash)(this.options?.crypto?.algorithm?.toLowerCase());
27
- const inputArray = new Uint8Array(input);
28
- return hash.update(inputArray).digest('base64');
29
- }
30
- async *hashBatches(asyncIterator) {
31
- await this.preload();
32
- const hash = (0, crypto_1.createHash)(this.options?.crypto?.algorithm?.toLowerCase());
33
- for await (const chunk of asyncIterator) {
34
- // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
35
- const inputArray = new Uint8Array(chunk);
36
- hash.update(inputArray);
37
- yield chunk;
38
- }
39
- this.options?.crypto?.onEnd?.({ hash: hash.digest('base64') });
40
- }
41
- }
42
- exports.NodeHash = NodeHash;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SHA256Hash = void 0;
4
- //
5
- const crypto_hash_1 = require("./crypto-hash");
6
- /**
7
- * A transform that calculates Cryptographic Hash
8
- */
9
- class SHA256Hash extends crypto_hash_1.CryptoHash {
10
- constructor(options) {
11
- super({ ...options, crypto: { ...options.crypto, algorithm: 'SHA256' } });
12
- }
13
- }
14
- exports.SHA256Hash = SHA256Hash;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBase64 = void 0;
4
- /**
5
- * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references
6
- * RFC 4648.
7
- */
8
- function toBase64(string) {
9
- // String conversion as required by Web IDL.
10
- string = `${string}`;
11
- // "The btoa() method must throw an "InvalidCharacterError" DOMException if
12
- // data contains any character whose code point is greater than U+00FF."
13
- for (let i = 0; i < string.length; i++) {
14
- if (string.charCodeAt(i) > 255) {
15
- return null;
16
- }
17
- }
18
- let out = '';
19
- for (let i = 0; i < string.length; i += 3) {
20
- /** @type {Array[4]} */
21
- const groupsOfSix = [undefined, undefined, undefined, undefined];
22
- groupsOfSix[0] = string.charCodeAt(i) >> 2;
23
- groupsOfSix[1] = (string.charCodeAt(i) & 0x03) << 4;
24
- if (string.length > i + 1) {
25
- groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;
26
- groupsOfSix[2] = (string.charCodeAt(i + 1) & 0x0f) << 2;
27
- }
28
- if (string.length > i + 2) {
29
- // @ts-expect-error
30
- groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;
31
- groupsOfSix[3] = string.charCodeAt(i + 2) & 0x3f;
32
- }
33
- for (let j = 0; j < groupsOfSix.length; j++) {
34
- if (typeof groupsOfSix[j] === 'undefined') {
35
- out += '=';
36
- }
37
- else {
38
- out += btoaLookup(groupsOfSix[j]);
39
- }
40
- }
41
- }
42
- return out;
43
- }
44
- exports.toBase64 = toBase64;
45
- /**
46
- * Lookup table for btoa(), which converts a six-bit number into the
47
- * corresponding ASCII character.
48
- */
49
- function btoaLookup(idx) {
50
- if (idx < 26) {
51
- return String.fromCharCode(idx + 'A'.charCodeAt(0));
52
- }
53
- if (idx < 52) {
54
- return String.fromCharCode(idx - 26 + 'a'.charCodeAt(0));
55
- }
56
- if (idx < 62) {
57
- return String.fromCharCode(idx - 52 + '0'.charCodeAt(0));
58
- }
59
- if (idx === 62) {
60
- return '+';
61
- }
62
- if (idx === 63) {
63
- return '/';
64
- }
65
- // Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the teststring.
66
- return undefined;
67
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexToBase64 = exports.toHex = void 0;
4
- const base64_utils_1 = require("./base64-utils");
5
- /**
6
- *
7
- */
8
- function toHex(cipher) {
9
- const hexString = cipher.toString(16);
10
- return hexString === '0' ? `0${hexString}` : hexString;
11
- }
12
- exports.toHex = toHex;
13
- /**
14
- * @see https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript
15
- */
16
- function hexToBase64(hexstring) {
17
- // Add leading zero to keep even count of digits
18
- // eg. f85d741 => 0f85d741
19
- if (hexstring.length % 2 !== 0) {
20
- hexstring = `0${hexstring}`;
21
- }
22
- const matches = hexstring.match(/\w{2}/g) || [];
23
- const string = matches.map((a) => String.fromCharCode(parseInt(a, 16))).join('');
24
- // TODO - define how to handle failures
25
- return (0, base64_utils_1.toBase64)(string) || '';
26
- }
27
- exports.hexToBase64 = hexToBase64;
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CRC32CHash = exports.CRC32Hash = void 0;
4
- const worker_utils_1 = require("@loaders.gl/worker-utils");
5
- const crc32_hash_1 = require("../lib/crc32-hash");
6
- Object.defineProperty(exports, "CRC32Hash", { enumerable: true, get: function () { return crc32_hash_1.CRC32Hash; } });
7
- const crc32c_hash_1 = require("../lib/crc32c-hash");
8
- Object.defineProperty(exports, "CRC32CHash", { enumerable: true, get: function () { return crc32c_hash_1.CRC32CHash; } });
9
- const md5_hash_1 = require("../lib/md5-hash");
10
- (0, worker_utils_1.createWorker)(async (data, options = {}) => {
11
- // @ts-ignore
12
- const { operation } = options;
13
- switch (operation) {
14
- case 'crc32':
15
- return await new crc32_hash_1.CRC32Hash(options).hash(data);
16
- case 'crc32c':
17
- return await new crc32c_hash_1.CRC32CHash(options).hash(data);
18
- case 'md5':
19
- return await new md5_hash_1.MD5Hash(options).hash(data);
20
- default:
21
- throw new Error(`invalid option: ${operation}`);
22
- }
23
- });