@loaders.gl/crypto 3.1.0-alpha.5 → 3.1.0-beta.4

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 (88) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +5 -0
  4. package/dist/dist.min.js +2 -2
  5. package/dist/dist.min.js.map +7 -1
  6. package/dist/es5/index.js +1 -1
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/lib/algorithms/crc32.js +5 -0
  9. package/dist/es5/lib/algorithms/crc32.js.map +1 -1
  10. package/dist/es5/lib/algorithms/crc32c.js +6 -0
  11. package/dist/es5/lib/algorithms/crc32c.js.map +1 -1
  12. package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
  13. package/dist/es5/lib/md5-hash.js.map +1 -1
  14. package/dist/es5/lib/utils/base64-utils.js.map +1 -1
  15. package/dist/es5/lib/utils/digest-utils.js +3 -2
  16. package/dist/es5/lib/utils/digest-utils.js.map +1 -1
  17. package/dist/esm/index.js +1 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/lib/algorithms/crc32.js +3 -0
  20. package/dist/esm/lib/algorithms/crc32.js.map +1 -1
  21. package/dist/esm/lib/algorithms/crc32c.js +5 -0
  22. package/dist/esm/lib/algorithms/crc32c.js.map +1 -1
  23. package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
  24. package/dist/esm/lib/md5-hash.js.map +1 -1
  25. package/dist/esm/lib/utils/base64-utils.js.map +1 -1
  26. package/dist/esm/lib/utils/digest-utils.js +3 -2
  27. package/dist/esm/lib/utils/digest-utils.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +47 -0
  31. package/dist/lib/algorithms/crc32.d.ts +3 -1
  32. package/dist/lib/algorithms/crc32.d.ts.map +1 -0
  33. package/dist/lib/algorithms/crc32.js +30 -0
  34. package/dist/lib/algorithms/crc32c.d.ts +4 -3
  35. package/dist/lib/algorithms/crc32c.d.ts.map +1 -0
  36. package/dist/lib/algorithms/crc32c.js +38 -0
  37. package/dist/lib/algorithms/md5-wasm.d.ts +2 -4
  38. package/dist/lib/algorithms/md5-wasm.d.ts.map +1 -0
  39. package/dist/lib/algorithms/md5-wasm.js +435 -0
  40. package/dist/lib/crc32-hash.d.ts +1 -0
  41. package/dist/lib/crc32-hash.d.ts.map +1 -0
  42. package/dist/lib/crc32-hash.js +47 -0
  43. package/dist/lib/crc32c-hash.d.ts +1 -0
  44. package/dist/lib/crc32c-hash.d.ts.map +1 -0
  45. package/dist/lib/crc32c-hash.js +51 -0
  46. package/dist/lib/crypto-hash.d.ts +1 -0
  47. package/dist/lib/crypto-hash.d.ts.map +1 -0
  48. package/dist/lib/crypto-hash.js +61 -0
  49. package/dist/lib/hash.d.ts +1 -0
  50. package/dist/lib/hash.d.ts.map +1 -0
  51. package/dist/lib/hash.js +29 -0
  52. package/dist/lib/md5-hash.d.ts +1 -0
  53. package/dist/lib/md5-hash.d.ts.map +1 -0
  54. package/dist/lib/md5-hash.js +32 -0
  55. package/dist/lib/node-hash.d.ts +1 -0
  56. package/dist/lib/node-hash.d.ts.map +1 -0
  57. package/dist/lib/node-hash.js +42 -0
  58. package/dist/lib/sha256-hash.d.ts +1 -0
  59. package/dist/lib/sha256-hash.d.ts.map +1 -0
  60. package/dist/lib/sha256-hash.js +14 -0
  61. package/dist/lib/utils/base64-utils.d.ts +2 -1
  62. package/dist/lib/utils/base64-utils.d.ts.map +1 -0
  63. package/dist/lib/utils/base64-utils.js +67 -0
  64. package/dist/lib/utils/digest-utils.d.ts +4 -3
  65. package/dist/lib/utils/digest-utils.d.ts.map +1 -0
  66. package/dist/lib/utils/digest-utils.js +27 -0
  67. package/dist/types.d.ts +1 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +2 -0
  70. package/dist/worker.js +2 -5069
  71. package/dist/worker.js.map +7 -1
  72. package/dist/workers/worker.d.ts +1 -0
  73. package/dist/workers/worker.d.ts.map +1 -0
  74. package/dist/workers/worker.js +23 -0
  75. package/package.json +6 -7
  76. package/src/lib/algorithms/{crc32.js → crc32.ts} +2 -0
  77. package/src/lib/algorithms/{crc32c.js → crc32c.ts} +3 -0
  78. package/src/lib/algorithms/{md5-wasm.js → md5-wasm.ts} +2 -2
  79. package/src/lib/md5-hash.ts +1 -0
  80. package/src/lib/utils/{base64-utils.js → base64-utils.ts} +3 -2
  81. package/src/lib/utils/digest-utils.ts +24 -0
  82. package/dist/es5/lib/utils/base64-utils.d.ts +0 -5
  83. package/dist/es5/lib/utils/digest-utils.d.ts +0 -6
  84. package/dist/esm/lib/utils/base64-utils.d.ts +0 -5
  85. package/dist/esm/lib/utils/digest-utils.d.ts +0 -6
  86. package/src/lib/utils/base64-utils.d.ts +0 -5
  87. package/src/lib/utils/digest-utils.d.ts +0 -6
  88. package/src/lib/utils/digest-utils.js +0 -25
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash = void 0;
4
+ // Hash
5
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
6
+ /** Abstract hash base class */
7
+ class Hash {
8
+ constructor(options = {}) {
9
+ this.hashBatches = this.hashBatches.bind(this);
10
+ }
11
+ async preload() {
12
+ return;
13
+ }
14
+ async *hashBatches(asyncIterator) {
15
+ const arrayBuffers = [];
16
+ for await (const arrayBuffer of asyncIterator) {
17
+ arrayBuffers.push(arrayBuffer);
18
+ yield arrayBuffer;
19
+ }
20
+ const output = await this.concatenate(arrayBuffers);
21
+ const hash = await this.hash(output);
22
+ this.options?.crypto?.onEnd?.({ hash });
23
+ }
24
+ // HELPERS
25
+ async concatenate(asyncIterator) {
26
+ return await (0, loader_utils_1.concatenateArrayBuffersAsync)(asyncIterator);
27
+ }
28
+ }
29
+ exports.Hash = Hash;
@@ -12,3 +12,4 @@ export declare class MD5Hash extends Hash {
12
12
  */
13
13
  hash(input: ArrayBuffer): Promise<string>;
14
14
  }
15
+ //# sourceMappingURL=md5-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"md5-hash.d.ts","sourceRoot":"","sources":["../../src/lib/md5-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,qBAAa,OAAQ,SAAQ,IAAI;IAC/B,QAAQ,CAAC,IAAI,SAAS;IACtB,QAAQ,CAAC,OAAO,MAAC;gBAEL,OAAO,KAAK;IAKxB;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAQhD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MD5Hash = void 0;
7
+ // Fork of https://github.com/briantbutton/md5-wasm under MIT license
8
+ const hash_1 = require("./hash");
9
+ const md5_wasm_1 = __importDefault(require("./algorithms/md5-wasm"));
10
+ const digest_utils_1 = require("./utils/digest-utils");
11
+ /**
12
+ * A transform that calculates MD5 hashes, passing data through
13
+ */
14
+ class MD5Hash extends hash_1.Hash {
15
+ constructor(options = {}) {
16
+ super();
17
+ this.name = 'md5';
18
+ this.options = options;
19
+ }
20
+ /**
21
+ * Atomic hash calculation
22
+ * @returns base64 encoded hash
23
+ */
24
+ async hash(input) {
25
+ const md5Promise = new Promise((resolve, reject) =>
26
+ // @ts-expect-error
27
+ (0, md5_wasm_1.default)(input).then(resolve).catch(reject));
28
+ const hex = await md5Promise;
29
+ return (0, digest_utils_1.hexToBase64)(hex);
30
+ }
31
+ }
32
+ exports.MD5Hash = MD5Hash;
@@ -25,3 +25,4 @@ export declare class NodeHash extends Hash {
25
25
  hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
26
26
  }
27
27
  export {};
28
+ //# sourceMappingURL=node-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-hash.d.ts","sourceRoot":"","sources":["../../src/lib/node-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAG5B,aAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAAG,CAAC;KACzC,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,qBAAa,QAAS,SAAQ,IAAI;IAChC,QAAQ,CAAC,IAAI,iBAAiB;IAE9B,OAAO,EAAE,iBAAiB,CAAC;IAE3B,OAAO,CAAC,UAAU,CAAC;IAEnB,OAAO,CAAC,KAAK,CAAC;gBAEF,OAAO,EAAE,iBAAiB;IAQtC;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAOxC,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,WAAW,CAAC;CAW9B"}
@@ -0,0 +1,42 @@
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;
@@ -16,3 +16,4 @@ export declare class SHA256Hash extends CryptoHash {
16
16
  constructor(options: CryptoHashOptions);
17
17
  }
18
18
  export {};
19
+ //# sourceMappingURL=sha256-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256-hash.d.ts","sourceRoot":"","sources":["../../src/lib/sha256-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,aAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACrC,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAAG,CAAC;KACzC,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;gBAC5B,OAAO,EAAE,iBAAiB;CAGvC"}
@@ -0,0 +1,14 @@
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;
@@ -2,4 +2,5 @@
2
2
  * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references
3
3
  * RFC 4648.
4
4
  */
5
- export function toBase64(string: any): string | null;
5
+ export declare function toBase64(string: string): string | null;
6
+ //# sourceMappingURL=base64-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkCtD"}
@@ -0,0 +1,67 @@
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,8 +1,9 @@
1
1
  /**
2
2
  *
3
3
  */
4
- export function toHex(cipher: any): any;
4
+ export declare function toHex(cipher: number): string;
5
5
  /**
6
- *
6
+ * @see https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript
7
7
  */
8
- export function hexToBase64(hexstring: any): string;
8
+ export declare function hexToBase64(hexstring: string): string;
9
+ //# sourceMappingURL=digest-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/digest-utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAUrD"}
@@ -0,0 +1,27 @@
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.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare type CryptoHashOptions = {
7
7
  onEnd?: any;
8
8
  };
9
9
  };
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACtC,MAAM,CAAC,EAAE;QACP,SAAS,MAAC;QACV,KAAK,CAAC,MAAC;KACR,CAAC;CACH,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });