@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.
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/dist.min.js +2 -2
- package/dist/dist.min.js.map +7 -1
- package/dist/es5/index.js +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32.js +5 -0
- package/dist/es5/lib/algorithms/crc32.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32c.js +6 -0
- package/dist/es5/lib/algorithms/crc32c.js.map +1 -1
- package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/es5/lib/md5-hash.js.map +1 -1
- package/dist/es5/lib/utils/base64-utils.js.map +1 -1
- package/dist/es5/lib/utils/digest-utils.js +3 -2
- package/dist/es5/lib/utils/digest-utils.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/crc32.js +3 -0
- package/dist/esm/lib/algorithms/crc32.js.map +1 -1
- package/dist/esm/lib/algorithms/crc32c.js +5 -0
- package/dist/esm/lib/algorithms/crc32c.js.map +1 -1
- package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/esm/lib/md5-hash.js.map +1 -1
- package/dist/esm/lib/utils/base64-utils.js.map +1 -1
- package/dist/esm/lib/utils/digest-utils.js +3 -2
- package/dist/esm/lib/utils/digest-utils.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/lib/algorithms/crc32.d.ts +3 -1
- package/dist/lib/algorithms/crc32.d.ts.map +1 -0
- package/dist/lib/algorithms/crc32.js +30 -0
- package/dist/lib/algorithms/crc32c.d.ts +4 -3
- package/dist/lib/algorithms/crc32c.d.ts.map +1 -0
- package/dist/lib/algorithms/crc32c.js +38 -0
- package/dist/lib/algorithms/md5-wasm.d.ts +2 -4
- package/dist/lib/algorithms/md5-wasm.d.ts.map +1 -0
- package/dist/lib/algorithms/md5-wasm.js +435 -0
- package/dist/lib/crc32-hash.d.ts +1 -0
- package/dist/lib/crc32-hash.d.ts.map +1 -0
- package/dist/lib/crc32-hash.js +47 -0
- package/dist/lib/crc32c-hash.d.ts +1 -0
- package/dist/lib/crc32c-hash.d.ts.map +1 -0
- package/dist/lib/crc32c-hash.js +51 -0
- package/dist/lib/crypto-hash.d.ts +1 -0
- package/dist/lib/crypto-hash.d.ts.map +1 -0
- package/dist/lib/crypto-hash.js +61 -0
- package/dist/lib/hash.d.ts +1 -0
- package/dist/lib/hash.d.ts.map +1 -0
- package/dist/lib/hash.js +29 -0
- package/dist/lib/md5-hash.d.ts +1 -0
- package/dist/lib/md5-hash.d.ts.map +1 -0
- package/dist/lib/md5-hash.js +32 -0
- package/dist/lib/node-hash.d.ts +1 -0
- package/dist/lib/node-hash.d.ts.map +1 -0
- package/dist/lib/node-hash.js +42 -0
- package/dist/lib/sha256-hash.d.ts +1 -0
- package/dist/lib/sha256-hash.d.ts.map +1 -0
- package/dist/lib/sha256-hash.js +14 -0
- package/dist/lib/utils/base64-utils.d.ts +2 -1
- package/dist/lib/utils/base64-utils.d.ts.map +1 -0
- package/dist/lib/utils/base64-utils.js +67 -0
- package/dist/lib/utils/digest-utils.d.ts +4 -3
- package/dist/lib/utils/digest-utils.d.ts.map +1 -0
- package/dist/lib/utils/digest-utils.js +27 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/worker.js +2 -5069
- package/dist/worker.js.map +7 -1
- package/dist/workers/worker.d.ts +1 -0
- package/dist/workers/worker.d.ts.map +1 -0
- package/dist/workers/worker.js +23 -0
- package/package.json +6 -7
- package/src/lib/algorithms/{crc32.js → crc32.ts} +2 -0
- package/src/lib/algorithms/{crc32c.js → crc32c.ts} +3 -0
- package/src/lib/algorithms/{md5-wasm.js → md5-wasm.ts} +2 -2
- package/src/lib/md5-hash.ts +1 -0
- package/src/lib/utils/{base64-utils.js → base64-utils.ts} +3 -2
- package/src/lib/utils/digest-utils.ts +24 -0
- package/dist/es5/lib/utils/base64-utils.d.ts +0 -5
- package/dist/es5/lib/utils/digest-utils.d.ts +0 -6
- package/dist/esm/lib/utils/base64-utils.d.ts +0 -5
- package/dist/esm/lib/utils/digest-utils.d.ts +0 -6
- package/src/lib/utils/base64-utils.d.ts +0 -5
- package/src/lib/utils/digest-utils.d.ts +0 -6
- package/src/lib/utils/digest-utils.js +0 -25
package/dist/lib/hash.js
ADDED
|
@@ -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;
|
package/dist/lib/md5-hash.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/node-hash.d.ts
CHANGED
|
@@ -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 @@
|
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
@@ -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