@loaders.gl/crypto 4.0.0-alpha.9 → 4.0.0-beta.2
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/crypto-worker-node.js +1 -1
- package/dist/crypto-worker-node.js.map +2 -2
- package/dist/crypto-worker.js +1 -1
- package/dist/crypto-worker.js.map +2 -2
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +2 -2
- package/dist/es5/index.js +24 -5
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/md5-wasm.js +3 -3
- package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/es5/lib/crc32-hash.js +11 -13
- package/dist/es5/lib/crc32-hash.js.map +1 -1
- package/dist/es5/lib/crc32c-hash.js +11 -13
- package/dist/es5/lib/crc32c-hash.js.map +1 -1
- package/dist/es5/lib/crypto-hash.js +12 -9
- package/dist/es5/lib/crypto-hash.js.map +1 -1
- package/dist/es5/lib/hash.js +2 -1
- package/dist/es5/lib/hash.js.map +1 -1
- package/dist/es5/lib/md5-hash.js +3 -3
- package/dist/es5/lib/md5-hash.js.map +1 -1
- package/dist/es5/lib/node-hash.js +20 -12
- package/dist/es5/lib/node-hash.js.map +1 -1
- package/dist/es5/lib/utils/base64-utils.js +41 -2
- package/dist/es5/lib/utils/base64-utils.js.map +1 -1
- package/dist/es5/lib/utils/digest-utils.js +45 -7
- package/dist/es5/lib/utils/digest-utils.js.map +1 -1
- package/dist/es5/workers/worker.js +6 -4
- package/dist/es5/workers/worker.js.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/md5-wasm.js +3 -3
- package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/esm/lib/crc32-hash.js +24 -19
- package/dist/esm/lib/crc32-hash.js.map +1 -1
- package/dist/esm/lib/crc32c-hash.js +24 -19
- package/dist/esm/lib/crc32c-hash.js.map +1 -1
- package/dist/esm/lib/crypto-hash.js +23 -13
- package/dist/esm/lib/crypto-hash.js.map +1 -1
- package/dist/esm/lib/hash.js +19 -11
- package/dist/esm/lib/hash.js.map +1 -1
- package/dist/esm/lib/md5-hash.js +3 -3
- package/dist/esm/lib/md5-hash.js.map +1 -1
- package/dist/esm/lib/node-hash.js +29 -15
- package/dist/esm/lib/node-hash.js.map +1 -1
- package/dist/esm/lib/utils/base64-utils.js +39 -1
- package/dist/esm/lib/utils/base64-utils.js.map +1 -1
- package/dist/esm/lib/utils/digest-utils.js +39 -6
- package/dist/esm/lib/utils/digest-utils.js.map +1 -1
- package/dist/esm/workers/worker.js +5 -4
- package/dist/esm/workers/worker.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/crc32-hash.d.ts +3 -3
- package/dist/lib/crc32-hash.d.ts.map +1 -1
- package/dist/lib/crc32c-hash.d.ts +3 -3
- package/dist/lib/crc32c-hash.d.ts.map +1 -1
- package/dist/lib/crypto-hash.d.ts +2 -2
- package/dist/lib/crypto-hash.d.ts.map +1 -1
- package/dist/lib/hash.d.ts +2 -2
- package/dist/lib/hash.d.ts.map +1 -1
- package/dist/lib/md5-hash.d.ts +1 -1
- package/dist/lib/md5-hash.d.ts.map +1 -1
- package/dist/lib/node-hash.d.ts +2 -2
- package/dist/lib/node-hash.d.ts.map +1 -1
- package/dist/lib/utils/base64-utils.d.ts +8 -1
- package/dist/lib/utils/base64-utils.d.ts.map +1 -1
- package/dist/lib/utils/digest-utils.d.ts +6 -6
- package/dist/lib/utils/digest-utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +10 -7
- package/src/lib/algorithms/md5-wasm.ts +4 -3
- package/src/lib/crc32-hash.ts +10 -12
- package/src/lib/crc32c-hash.ts +10 -12
- package/src/lib/crypto-hash.ts +10 -5
- package/src/lib/hash.ts +4 -3
- package/src/lib/md5-hash.ts +3 -3
- package/src/lib/node-hash.ts +14 -6
- package/src/lib/utils/base64-utils.ts +97 -1
- package/src/lib/utils/digest-utils.ts +57 -8
- package/src/workers/worker.ts +4 -4
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -47
- package/dist/lib/algorithms/crc32.js +0 -30
- package/dist/lib/algorithms/crc32c.js +0 -38
- package/dist/lib/algorithms/md5-wasm.js +0 -435
- package/dist/lib/crc32-hash.js +0 -47
- package/dist/lib/crc32c-hash.js +0 -51
- package/dist/lib/crypto-hash.js +0 -61
- package/dist/lib/hash.js +0 -29
- package/dist/lib/md5-hash.js +0 -32
- package/dist/lib/node-hash.js +0 -42
- package/dist/lib/sha256-hash.js +0 -14
- package/dist/lib/utils/base64-utils.js +0 -67
- package/dist/lib/utils/digest-utils.js +0 -27
- package/dist/types.js +0 -2
- package/dist/workers/worker.js +0 -23
package/dist/lib/node-hash.js
DELETED
|
@@ -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;
|
package/dist/lib/sha256-hash.js
DELETED
|
@@ -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
package/dist/workers/worker.js
DELETED
|
@@ -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
|
-
});
|