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

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 (110) hide show
  1. package/dist/bundle.d.ts +2 -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/bundle.js +1 -1
  7. package/dist/es5/bundle.js.map +1 -1
  8. package/dist/es5/index.js +11 -11
  9. package/dist/es5/index.js.map +1 -1
  10. package/dist/es5/lib/algorithms/crc32.js +20 -26
  11. package/dist/es5/lib/algorithms/crc32.js.map +1 -1
  12. package/dist/es5/lib/algorithms/crc32c.js +21 -27
  13. package/dist/es5/lib/algorithms/crc32c.js.map +1 -1
  14. package/dist/es5/lib/algorithms/md5-wasm.js +25 -36
  15. package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
  16. package/dist/es5/lib/crc32-hash.js +39 -185
  17. package/dist/es5/lib/crc32-hash.js.map +1 -1
  18. package/dist/es5/lib/crc32c-hash.js +38 -184
  19. package/dist/es5/lib/crc32c-hash.js.map +1 -1
  20. package/dist/es5/lib/crypto-hash.js +49 -225
  21. package/dist/es5/lib/crypto-hash.js.map +1 -1
  22. package/dist/es5/lib/hash.js +21 -175
  23. package/dist/es5/lib/hash.js.map +1 -1
  24. package/dist/es5/lib/md5-hash.js +13 -71
  25. package/dist/es5/lib/md5-hash.js.map +1 -1
  26. package/dist/es5/lib/node-hash.js +33 -181
  27. package/dist/es5/lib/node-hash.js.map +1 -1
  28. package/dist/es5/lib/sha256-hash.js +7 -33
  29. package/dist/es5/lib/sha256-hash.js.map +1 -1
  30. package/dist/es5/lib/utils/base64-utils.js +13 -13
  31. package/dist/es5/lib/utils/base64-utils.js.map +1 -1
  32. package/dist/es5/lib/utils/digest-utils.js +4 -5
  33. package/dist/es5/lib/utils/digest-utils.js.map +1 -1
  34. package/dist/es5/workers/worker.js +17 -55
  35. package/dist/es5/workers/worker.js.map +1 -1
  36. package/dist/esm/index.js +1 -1
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/lib/algorithms/crc32.js +3 -0
  39. package/dist/esm/lib/algorithms/crc32.js.map +1 -1
  40. package/dist/esm/lib/algorithms/crc32c.js +5 -0
  41. package/dist/esm/lib/algorithms/crc32c.js.map +1 -1
  42. package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
  43. package/dist/esm/lib/md5-hash.js.map +1 -1
  44. package/dist/esm/lib/utils/base64-utils.js +1 -1
  45. package/dist/esm/lib/utils/base64-utils.js.map +1 -1
  46. package/dist/esm/lib/utils/digest-utils.js +5 -4
  47. package/dist/esm/lib/utils/digest-utils.js.map +1 -1
  48. package/dist/esm/workers/worker.js +1 -1
  49. package/dist/esm/workers/worker.js.map +1 -1
  50. package/dist/index.d.ts +33 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +47 -0
  53. package/dist/lib/algorithms/crc32.d.ts +10 -0
  54. package/dist/lib/algorithms/crc32.d.ts.map +1 -0
  55. package/dist/lib/algorithms/crc32.js +30 -0
  56. package/dist/lib/algorithms/crc32c.d.ts +11 -0
  57. package/dist/lib/algorithms/crc32c.d.ts.map +1 -0
  58. package/dist/lib/algorithms/crc32c.js +38 -0
  59. package/dist/lib/algorithms/md5-wasm.d.ts +2 -0
  60. package/dist/lib/algorithms/md5-wasm.d.ts.map +1 -0
  61. package/dist/lib/algorithms/md5-wasm.js +435 -0
  62. package/dist/lib/crc32-hash.d.ts +18 -0
  63. package/dist/lib/crc32-hash.d.ts.map +1 -0
  64. package/dist/lib/crc32-hash.js +47 -0
  65. package/dist/lib/crc32c-hash.d.ts +22 -0
  66. package/dist/lib/crc32c-hash.d.ts.map +1 -0
  67. package/dist/lib/crc32c-hash.js +51 -0
  68. package/dist/lib/crypto-hash.d.ts +32 -0
  69. package/dist/lib/crypto-hash.d.ts.map +1 -0
  70. package/dist/lib/crypto-hash.js +61 -0
  71. package/dist/lib/hash.d.ts +22 -0
  72. package/dist/lib/hash.d.ts.map +1 -0
  73. package/dist/lib/hash.js +29 -0
  74. package/dist/lib/md5-hash.d.ts +15 -0
  75. package/dist/lib/md5-hash.d.ts.map +1 -0
  76. package/dist/lib/md5-hash.js +32 -0
  77. package/dist/lib/node-hash.d.ts +28 -0
  78. package/dist/lib/node-hash.d.ts.map +1 -0
  79. package/dist/lib/node-hash.js +42 -0
  80. package/dist/lib/sha256-hash.d.ts +19 -0
  81. package/dist/lib/sha256-hash.d.ts.map +1 -0
  82. package/dist/lib/sha256-hash.js +14 -0
  83. package/dist/lib/utils/base64-utils.d.ts +6 -0
  84. package/dist/lib/utils/base64-utils.d.ts.map +1 -0
  85. package/dist/lib/utils/base64-utils.js +67 -0
  86. package/dist/lib/utils/digest-utils.d.ts +9 -0
  87. package/dist/lib/utils/digest-utils.d.ts.map +1 -0
  88. package/dist/lib/utils/digest-utils.js +27 -0
  89. package/dist/types.d.ts +10 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +2 -0
  92. package/dist/worker.js +2 -5069
  93. package/dist/worker.js.map +7 -1
  94. package/dist/workers/worker.d.ts +4 -0
  95. package/dist/workers/worker.d.ts.map +1 -0
  96. package/dist/workers/worker.js +23 -0
  97. package/package.json +7 -7
  98. package/src/lib/algorithms/{crc32.js → crc32.ts} +2 -0
  99. package/src/lib/algorithms/{crc32c.js → crc32c.ts} +3 -0
  100. package/src/lib/algorithms/{md5-wasm.js → md5-wasm.ts} +2 -2
  101. package/src/lib/md5-hash.ts +1 -0
  102. package/src/lib/utils/{base64-utils.js → base64-utils.ts} +3 -2
  103. package/src/lib/utils/digest-utils.ts +24 -0
  104. package/dist/es5/lib/utils/base64-utils.d.ts +0 -5
  105. package/dist/es5/lib/utils/digest-utils.d.ts +0 -6
  106. package/dist/esm/lib/utils/base64-utils.d.ts +0 -5
  107. package/dist/esm/lib/utils/digest-utils.d.ts +0 -6
  108. package/src/lib/utils/base64-utils.d.ts +0 -5
  109. package/src/lib/utils/digest-utils.d.ts +0 -6
  110. package/src/lib/utils/digest-utils.js +0 -25
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoHash = void 0;
4
+ const hash_1 = require("./hash");
5
+ let CryptoJS;
6
+ /**
7
+ * A transform that calculates Cryptographic Hash using Crypto JS library
8
+ * @deprecated Warning, experimental class
9
+ */
10
+ class CryptoHash extends hash_1.Hash {
11
+ constructor(options) {
12
+ super();
13
+ this.options = options;
14
+ this._algorithm = this.options?.crypto?.algorithm;
15
+ if (!this._algorithm) {
16
+ throw new Error(this.name);
17
+ }
18
+ this.name = this._algorithm.toLowerCase();
19
+ }
20
+ async preload() {
21
+ if (!CryptoJS) {
22
+ CryptoJS = this.options?.modules?.CryptoJS;
23
+ if (!CryptoJS) {
24
+ throw new Error(this.name);
25
+ }
26
+ }
27
+ if (!this._hash) {
28
+ const algo = CryptoJS.algo[this._algorithm];
29
+ this._hash = algo.create();
30
+ }
31
+ if (!this._hash) {
32
+ throw new Error(this.name);
33
+ }
34
+ }
35
+ /**
36
+ * Atomic hash calculation
37
+ * @returns base64 encoded hash
38
+ */
39
+ async hash(input) {
40
+ await this.preload();
41
+ // arrayBuffer is accepted, even though types and docs say no
42
+ // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
43
+ // @ts-expect-error
44
+ const typedWordArray = CryptoJS.lib.WordArray.create(input);
45
+ return this._hash.update(typedWordArray).finalize().toString(CryptoJS.enc.Base64);
46
+ }
47
+ async *hashBatches(asyncIterator) {
48
+ await this.preload();
49
+ for await (const chunk of asyncIterator) {
50
+ // arrayBuffer is accepted, even though types and docs say no
51
+ // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
52
+ // @ts-expect-error
53
+ const typedWordArray = CryptoJS.lib.WordArray.create(chunk);
54
+ this._hash.update(typedWordArray);
55
+ yield chunk;
56
+ }
57
+ const hash = this._hash.finalize().toString(CryptoJS.enc.Base64);
58
+ this.options?.crypto?.onEnd?.({ hash });
59
+ }
60
+ }
61
+ exports.CryptoHash = CryptoHash;
@@ -0,0 +1,22 @@
1
+ declare type HashOptions = {
2
+ modules?: {
3
+ [moduleName: string]: any;
4
+ };
5
+ crypto?: {
6
+ onEnd?: (result: {
7
+ hash: string;
8
+ }) => any;
9
+ };
10
+ };
11
+ /** Abstract hash base class */
12
+ export declare abstract class Hash {
13
+ abstract readonly name: string;
14
+ abstract readonly options: HashOptions;
15
+ constructor(options?: HashOptions);
16
+ preload(): Promise<void>;
17
+ abstract hash(arrayBuffer: ArrayBuffer): Promise<string>;
18
+ hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
19
+ protected concatenate(asyncIterator: any): Promise<ArrayBuffer>;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/lib/hash.ts"],"names":[],"mappings":"AAGA,aAAK,WAAW,GAAG;IACjB,OAAO,CAAC,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACtC,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAAG,CAAC;KACzC,CAAC;CACH,CAAC;AAEF,+BAA+B;AAC/B,8BAAsB,IAAI;IACxB,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;gBAE3B,OAAO,GAAE,WAAgB;IAI/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjD,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,WAAW,CAAC;cAab,WAAW,CAAC,aAAa,KAAA,GAAG,OAAO,CAAC,WAAW,CAAC;CAGjE"}
@@ -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;
@@ -0,0 +1,15 @@
1
+ import { Hash } from './hash';
2
+ /**
3
+ * A transform that calculates MD5 hashes, passing data through
4
+ */
5
+ export declare class MD5Hash extends Hash {
6
+ readonly name = "md5";
7
+ readonly options: any;
8
+ constructor(options?: {});
9
+ /**
10
+ * Atomic hash calculation
11
+ * @returns base64 encoded hash
12
+ */
13
+ hash(input: ArrayBuffer): Promise<string>;
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;
@@ -0,0 +1,28 @@
1
+ import { Hash } from './hash';
2
+ declare type CryptoHashOptions = {
3
+ crypto: {
4
+ algorithm: string;
5
+ onEnd?: (result: {
6
+ hash: string;
7
+ }) => any;
8
+ };
9
+ };
10
+ /**
11
+ * Calculates Cryptographic Hash using Node.js crypto library
12
+ * @deprecated Warning, experimental class
13
+ */
14
+ export declare class NodeHash extends Hash {
15
+ readonly name = "crypto-node";
16
+ options: CryptoHashOptions;
17
+ private _algorithm;
18
+ private _hash;
19
+ constructor(options: CryptoHashOptions);
20
+ /**
21
+ * Atomic hash calculation
22
+ * @returns base64 encoded hash
23
+ */
24
+ hash(input: ArrayBuffer): Promise<string>;
25
+ hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrayBuffer>;
26
+ }
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;
@@ -0,0 +1,19 @@
1
+ import { CryptoHash } from './crypto-hash';
2
+ declare type CryptoHashOptions = {
3
+ modules: {
4
+ [moduleName: string]: any;
5
+ };
6
+ crypto?: {
7
+ onEnd?: (result: {
8
+ hash: string;
9
+ }) => any;
10
+ };
11
+ };
12
+ /**
13
+ * A transform that calculates Cryptographic Hash
14
+ */
15
+ export declare class SHA256Hash extends CryptoHash {
16
+ constructor(options: CryptoHashOptions);
17
+ }
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;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references
3
+ * RFC 4648.
4
+ */
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
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ */
4
+ export declare function toHex(cipher: number): string;
5
+ /**
6
+ * @see https://stackoverflow.com/questions/23190056/hex-to-base64-converter-for-javascript
7
+ */
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;
@@ -0,0 +1,10 @@
1
+ export declare type CryptoHashOptions = {
2
+ modules?: {
3
+ [moduleName: string]: any;
4
+ };
5
+ crypto?: {
6
+ algorithm: any;
7
+ onEnd?: any;
8
+ };
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 });