@loaders.gl/crypto 3.1.0-alpha.1 → 3.1.0-alpha.5
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/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +91 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/algorithms/crc32.js +37 -0
- package/dist/es5/lib/algorithms/crc32.js.map +1 -0
- package/dist/es5/lib/algorithms/crc32c.js +38 -0
- package/dist/es5/lib/algorithms/crc32c.js.map +1 -0
- package/dist/es5/lib/algorithms/md5-wasm.js +476 -0
- package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -0
- package/dist/es5/lib/crc32-hash.js +67 -0
- package/dist/es5/lib/crc32-hash.js.map +1 -0
- package/dist/es5/lib/crc32c-hash.js +66 -0
- package/dist/es5/lib/crc32c-hash.js.map +1 -0
- package/dist/es5/lib/crypto-hash.js +85 -0
- package/dist/es5/lib/crypto-hash.js.map +1 -0
- package/dist/es5/lib/hash.js +49 -0
- package/dist/es5/lib/hash.js.map +1 -0
- package/dist/es5/lib/md5-hash.js +35 -0
- package/dist/es5/lib/md5-hash.js.map +1 -0
- package/dist/es5/lib/node-hash.js +61 -0
- package/dist/{lib → es5/lib}/node-hash.js.map +1 -1
- package/dist/es5/lib/sha256-hash.js +22 -0
- package/dist/es5/lib/sha256-hash.js.map +1 -0
- package/dist/es5/lib/utils/base64-utils.d.ts +5 -0
- package/dist/es5/lib/utils/base64-utils.js +69 -0
- package/dist/es5/lib/utils/base64-utils.js.map +1 -0
- package/dist/es5/lib/utils/digest-utils.d.ts +6 -0
- package/dist/es5/lib/utils/digest-utils.js +24 -0
- package/dist/es5/lib/utils/digest-utils.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/{types.js.map → es5/types.js.map} +0 -0
- package/dist/{workers → es5/workers}/cryptojs-worker.ts.disabled +0 -0
- package/dist/es5/workers/worker.js +46 -0
- package/dist/es5/workers/worker.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/{index.js → esm/index.js} +1 -1
- package/dist/esm/index.js.map +1 -0
- package/dist/{lib → esm/lib}/algorithms/crc32.js +0 -0
- package/dist/esm/lib/algorithms/crc32.js.map +1 -0
- package/dist/{lib → esm/lib}/algorithms/crc32c.js +0 -0
- package/dist/esm/lib/algorithms/crc32c.js.map +1 -0
- package/dist/{lib → esm/lib}/algorithms/md5-wasm.js +0 -0
- package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -0
- package/dist/{lib → esm/lib}/crc32-hash.js +0 -0
- package/dist/esm/lib/crc32-hash.js.map +1 -0
- package/dist/{lib → esm/lib}/crc32c-hash.js +0 -0
- package/dist/esm/lib/crc32c-hash.js.map +1 -0
- package/dist/{lib → esm/lib}/crypto-hash.js +0 -0
- package/dist/esm/lib/crypto-hash.js.map +1 -0
- package/dist/{lib → esm/lib}/hash.js +0 -0
- package/dist/esm/lib/hash.js.map +1 -0
- package/dist/{lib → esm/lib}/md5-hash.js +0 -0
- package/dist/esm/lib/md5-hash.js.map +1 -0
- package/dist/{lib → esm/lib}/node-hash.js +0 -0
- package/dist/esm/lib/node-hash.js.map +1 -0
- package/dist/{lib → esm/lib}/sha256-hash.js +0 -0
- package/dist/esm/lib/sha256-hash.js.map +1 -0
- package/dist/esm/lib/utils/base64-utils.d.ts +5 -0
- package/dist/{lib → esm/lib}/utils/base64-utils.js +1 -1
- package/dist/esm/lib/utils/base64-utils.js.map +1 -0
- package/dist/esm/lib/utils/digest-utils.d.ts +6 -0
- package/dist/{lib → esm/lib}/utils/digest-utils.js +2 -2
- package/dist/esm/lib/utils/digest-utils.js.map +1 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/cryptojs-worker.ts.disabled +26 -0
- package/dist/{workers → esm/workers}/worker.js +1 -1
- package/dist/esm/workers/worker.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/lib/algorithms/crc32.d.ts +8 -0
- package/dist/lib/algorithms/crc32c.d.ts +10 -0
- package/dist/lib/algorithms/md5-wasm.d.ts +4 -0
- package/dist/lib/crc32-hash.d.ts +17 -0
- package/dist/lib/crc32c-hash.d.ts +21 -0
- package/dist/lib/crypto-hash.d.ts +31 -0
- package/dist/lib/hash.d.ts +21 -0
- package/dist/lib/md5-hash.d.ts +14 -0
- package/dist/lib/node-hash.d.ts +27 -0
- package/dist/lib/sha256-hash.d.ts +18 -0
- package/dist/lib/utils/base64-utils.d.ts +2 -2
- package/dist/lib/utils/digest-utils.d.ts +6 -4
- package/dist/types.d.ts +9 -0
- package/dist/worker.js +183 -46
- package/dist/worker.js.map +1 -1
- package/dist/workers/worker.d.ts +3 -0
- package/package.json +8 -7
- package/src/bundle.ts +2 -3
- package/dist/bundle.js +0 -7
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/algorithms/crc32.js.map +0 -1
- package/dist/lib/algorithms/crc32c.js.map +0 -1
- package/dist/lib/algorithms/md5-wasm.js.map +0 -1
- package/dist/lib/crc32-hash.js.map +0 -1
- package/dist/lib/crc32c-hash.js.map +0 -1
- package/dist/lib/crypto-hash.js.map +0 -1
- package/dist/lib/hash.js.map +0 -1
- package/dist/lib/md5-hash.js.map +0 -1
- package/dist/lib/sha256-hash.js.map +0 -1
- package/dist/lib/utils/base64-utils.js.map +0 -1
- package/dist/lib/utils/digest-utils.js.map +0 -1
- package/dist/workers/worker.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CRC32Hash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _hash = require("./hash");
|
|
13
|
+
|
|
14
|
+
var _crc = _interopRequireDefault(require("./algorithms/crc32"));
|
|
15
|
+
|
|
16
|
+
var _digestUtils = require("./utils/digest-utils");
|
|
17
|
+
|
|
18
|
+
class CRC32Hash extends _hash.Hash {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'crc32');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
24
|
+
this.options = {
|
|
25
|
+
crypto: {},
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
28
|
+
this._hash = new _crc.default();
|
|
29
|
+
this.hashBatches = this.hashBatches.bind(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async hash(input) {
|
|
33
|
+
return this.hashSync(input);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
hashSync(input) {
|
|
37
|
+
this._hash.update(input);
|
|
38
|
+
|
|
39
|
+
const hashValue = this._hash.finalize();
|
|
40
|
+
|
|
41
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
42
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
43
|
+
return hash;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async *hashBatches(asyncIterator) {
|
|
47
|
+
var _this$options$crypto, _this$options$crypto$;
|
|
48
|
+
|
|
49
|
+
for await (const chunk of asyncIterator) {
|
|
50
|
+
this._hash.update(chunk);
|
|
51
|
+
|
|
52
|
+
yield chunk;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const hashValue = this._hash.finalize();
|
|
56
|
+
|
|
57
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
58
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
59
|
+
(_this$options$crypto = this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
60
|
+
hash
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.CRC32Hash = CRC32Hash;
|
|
67
|
+
//# sourceMappingURL=crc32-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crc32-hash.ts"],"names":["CRC32Hash","Hash","constructor","options","crypto","_hash","CRC32","hashBatches","bind","hash","input","hashSync","update","hashValue","finalize","hex","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAKO,MAAMA,SAAN,SAAwBC,UAAxB,CAA6B;AAMlCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxB;AADwB,gDALV,OAKU;AAAA;AAAA;AAExB,SAAKA,OAAL,GAAe;AAACC,MAAAA,MAAM,EAAE,EAAT;AAAa,SAAGD;AAAhB,KAAf;AACA,SAAKE,KAAL,GAAa,IAAIC,YAAJ,EAAb;AACA,SAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAsB,IAAtB,CAAnB;AACD;;AAMS,QAAJC,IAAI,CAACC,KAAD,EAAsC;AAC9C,WAAO,KAAKC,QAAL,CAAcD,KAAd,CAAP;AACD;;AAEDC,EAAAA,QAAQ,CAACD,KAAD,EAA6B;AACnC,SAAKL,KAAL,CAAWO,MAAX,CAAkBF,KAAlB;;AACA,UAAMG,SAAS,GAAG,KAAKR,KAAL,CAAWS,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,WAAON,IAAP;AACD;;AAEiB,SAAXF,WAAW,CAChBS,aADgB,EAEY;AAAA;;AAC5B,eAAW,MAAMC,KAAjB,IAA0BD,aAA1B,EAAyC;AACvC,WAAKX,KAAL,CAAWO,MAAX,CAAkBK,KAAlB;;AACA,YAAMA,KAAN;AACD;;AACD,UAAMJ,SAAS,GAAG,KAAKR,KAAL,CAAWS,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,iCAAKZ,OAAL,CAAaC,MAAb,uGAAqBc,KAArB,2GAA6B;AAACT,MAAAA;AAAD,KAA7B;AACD;;AAxCiC","sourcesContent":["// CRC32\nimport {Hash} from './hash';\nimport CRC32 from './algorithms/crc32';\nimport {toHex, hexToBase64} from './utils/digest-utils';\n\n/**\n * Calculates CRC32 Cryptographic Hash\n */\nexport class CRC32Hash extends Hash {\n readonly name = 'crc32';\n\n options;\n private _hash: CRC32;\n\n constructor(options = {}) {\n super();\n this.options = {crypto: {}, ...options};\n this._hash = new CRC32();\n this.hashBatches = this.hashBatches.bind(this);\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n return this.hashSync(input);\n }\n\n hashSync(input: ArrayBuffer): string {\n this._hash.update(input);\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n return hash;\n }\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n for await (const chunk of asyncIterator) {\n this._hash.update(chunk);\n yield chunk;\n }\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n this.options.crypto?.onEnd?.({hash});\n }\n}\n"],"file":"crc32-hash.js"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CRC32CHash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _hash = require("./hash");
|
|
13
|
+
|
|
14
|
+
var _crc32c = _interopRequireDefault(require("./algorithms/crc32c"));
|
|
15
|
+
|
|
16
|
+
var _digestUtils = require("./utils/digest-utils");
|
|
17
|
+
|
|
18
|
+
class CRC32CHash extends _hash.Hash {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'crc32c');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
24
|
+
this.options = {
|
|
25
|
+
crypto: {},
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
28
|
+
this._hash = new _crc32c.default(options);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async hash(input) {
|
|
32
|
+
return this.hashSync(input);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
hashSync(input) {
|
|
36
|
+
this._hash.update(input);
|
|
37
|
+
|
|
38
|
+
const hashValue = this._hash.finalize();
|
|
39
|
+
|
|
40
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
41
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
42
|
+
return hash;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async *hashBatches(asyncIterator) {
|
|
46
|
+
var _this$options$crypto, _this$options$crypto$;
|
|
47
|
+
|
|
48
|
+
for await (const chunk of asyncIterator) {
|
|
49
|
+
this._hash.update(chunk);
|
|
50
|
+
|
|
51
|
+
yield chunk;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const hashValue = this._hash.finalize();
|
|
55
|
+
|
|
56
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
57
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
58
|
+
(_this$options$crypto = this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
59
|
+
hash
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.CRC32CHash = CRC32CHash;
|
|
66
|
+
//# sourceMappingURL=crc32c-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crc32c-hash.ts"],"names":["CRC32CHash","Hash","constructor","options","crypto","_hash","CRC32C","hash","input","hashSync","update","hashValue","finalize","hex","hashBatches","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAKO,MAAMA,UAAN,SAAyBC,UAAzB,CAA8B;AAUnCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxB;AADwB,gDATV,QASU;AAAA;AAAA;AAExB,SAAKA,OAAL,GAAe;AAACC,MAAAA,MAAM,EAAE,EAAT;AAAa,SAAGD;AAAhB,KAAf;AACA,SAAKE,KAAL,GAAa,IAAIC,eAAJ,CAAWH,OAAX,CAAb;AACD;;AAMS,QAAJI,IAAI,CAACC,KAAD,EAAsC;AAC9C,WAAO,KAAKC,QAAL,CAAcD,KAAd,CAAP;AACD;;AAEDC,EAAAA,QAAQ,CAACD,KAAD,EAA6B;AACnC,SAAKH,KAAL,CAAWK,MAAX,CAAkBF,KAAlB;;AACA,UAAMG,SAAS,GAAG,KAAKN,KAAL,CAAWO,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,WAAON,IAAP;AACD;;AAIiB,SAAXO,WAAW,CAChBC,aADgB,EAEY;AAAA;;AAC5B,eAAW,MAAMC,KAAjB,IAA0BD,aAA1B,EAAyC;AACvC,WAAKV,KAAL,CAAWK,MAAX,CAAkBM,KAAlB;;AACA,YAAMA,KAAN;AACD;;AACD,UAAML,SAAS,GAAG,KAAKN,KAAL,CAAWO,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,iCAAKV,OAAL,CAAaC,MAAb,uGAAqBa,KAArB,2GAA6B;AAACV,MAAAA;AAAD,KAA7B;AACD;;AA7CkC","sourcesContent":["// CRC32c\nimport {Hash} from './hash';\nimport CRC32C from './algorithms/crc32c';\nimport {toHex, hexToBase64} from './utils/digest-utils';\n\n/**\n * A transform that calculates CRC32c Hash\n */\nexport class CRC32CHash extends Hash {\n readonly name = 'crc32c';\n\n options;\n private _hash: CRC32C;\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n constructor(options = {}) {\n super();\n this.options = {crypto: {}, ...options};\n this._hash = new CRC32C(options);\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n return this.hashSync(input);\n }\n\n hashSync(input: ArrayBuffer): string {\n this._hash.update(input);\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n return hash;\n }\n\n // runInBatches inherited\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n for await (const chunk of asyncIterator) {\n this._hash.update(chunk);\n yield chunk;\n }\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n this.options.crypto?.onEnd?.({hash});\n }\n}\n"],"file":"crc32c-hash.js"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CryptoHash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _hash = require("./hash");
|
|
13
|
+
|
|
14
|
+
let CryptoJS;
|
|
15
|
+
|
|
16
|
+
class CryptoHash extends _hash.Hash {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _this$options, _this$options$crypto;
|
|
19
|
+
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_algorithm", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
25
|
+
this.options = options;
|
|
26
|
+
this._algorithm = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$crypto = _this$options.crypto) === null || _this$options$crypto === void 0 ? void 0 : _this$options$crypto.algorithm;
|
|
27
|
+
|
|
28
|
+
if (!this._algorithm) {
|
|
29
|
+
throw new Error(this.name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.name = this._algorithm.toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async preload() {
|
|
36
|
+
if (!CryptoJS) {
|
|
37
|
+
var _this$options2, _this$options2$module;
|
|
38
|
+
|
|
39
|
+
CryptoJS = (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : (_this$options2$module = _this$options2.modules) === null || _this$options2$module === void 0 ? void 0 : _this$options2$module.CryptoJS;
|
|
40
|
+
|
|
41
|
+
if (!CryptoJS) {
|
|
42
|
+
throw new Error(this.name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!this._hash) {
|
|
47
|
+
const algo = CryptoJS.algo[this._algorithm];
|
|
48
|
+
this._hash = algo.create();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!this._hash) {
|
|
52
|
+
throw new Error(this.name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async hash(input) {
|
|
57
|
+
await this.preload();
|
|
58
|
+
const typedWordArray = CryptoJS.lib.WordArray.create(input);
|
|
59
|
+
return this._hash.update(typedWordArray).finalize().toString(CryptoJS.enc.Base64);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async *hashBatches(asyncIterator) {
|
|
63
|
+
var _this$options3, _this$options3$crypto, _this$options3$crypto2;
|
|
64
|
+
|
|
65
|
+
await this.preload();
|
|
66
|
+
|
|
67
|
+
for await (const chunk of asyncIterator) {
|
|
68
|
+
const typedWordArray = CryptoJS.lib.WordArray.create(chunk);
|
|
69
|
+
|
|
70
|
+
this._hash.update(typedWordArray);
|
|
71
|
+
|
|
72
|
+
yield chunk;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hash = this._hash.finalize().toString(CryptoJS.enc.Base64);
|
|
76
|
+
|
|
77
|
+
(_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : (_this$options3$crypto = _this$options3.crypto) === null || _this$options3$crypto === void 0 ? void 0 : (_this$options3$crypto2 = _this$options3$crypto.onEnd) === null || _this$options3$crypto2 === void 0 ? void 0 : _this$options3$crypto2.call(_this$options3$crypto, {
|
|
78
|
+
hash
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
exports.CryptoHash = CryptoHash;
|
|
85
|
+
//# sourceMappingURL=crypto-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crypto-hash.ts"],"names":["CryptoJS","CryptoHash","Hash","constructor","options","_algorithm","crypto","algorithm","Error","name","toLowerCase","preload","modules","_hash","algo","create","hash","input","typedWordArray","lib","WordArray","update","finalize","toString","enc","Base64","hashBatches","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AAEA;;AAUA,IAAIA,QAAJ;;AAMO,MAAMC,UAAN,SAAyBC,UAAzB,CAA8B;AAOnCC,EAAAA,WAAW,CAACC,OAAD,EAA6B;AAAA;;AACtC;AADsC;AAAA;AAAA;AAAA;AAEtC,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKC,UAAL,oBAAkB,KAAKD,OAAvB,0EAAkB,cAAcE,MAAhC,yDAAkB,qBAAsBC,SAAxC;;AACA,QAAI,CAAC,KAAKF,UAAV,EAAsB;AACpB,YAAM,IAAIG,KAAJ,CAAU,KAAKC,IAAf,CAAN;AACD;;AACD,SAAKA,IAAL,GAAY,KAAKJ,UAAL,CAAgBK,WAAhB,EAAZ;AACD;;AAEY,QAAPC,OAAO,GAAkB;AAC7B,QAAI,CAACX,QAAL,EAAe;AAAA;;AACbA,MAAAA,QAAQ,qBAAG,KAAKI,OAAR,4EAAG,eAAcQ,OAAjB,0DAAG,sBAAuBZ,QAAlC;;AACA,UAAI,CAACA,QAAL,EAAe;AACb,cAAM,IAAIQ,KAAJ,CAAU,KAAKC,IAAf,CAAN;AACD;AACF;;AACD,QAAI,CAAC,KAAKI,KAAV,EAAiB;AACf,YAAMC,IAAI,GAAGd,QAAQ,CAACc,IAAT,CAAc,KAAKT,UAAnB,CAAb;AACA,WAAKQ,KAAL,GAAaC,IAAI,CAACC,MAAL,EAAb;AACD;;AACD,QAAI,CAAC,KAAKF,KAAV,EAAiB;AACf,YAAM,IAAIL,KAAJ,CAAU,KAAKC,IAAf,CAAN;AACD;AACF;;AAMS,QAAJO,IAAI,CAACC,KAAD,EAAsC;AAC9C,UAAM,KAAKN,OAAL,EAAN;AAIA,UAAMO,cAAc,GAAGlB,QAAQ,CAACmB,GAAT,CAAaC,SAAb,CAAuBL,MAAvB,CAA8BE,KAA9B,CAAvB;AACA,WAAO,KAAKJ,KAAL,CAAWQ,MAAX,CAAkBH,cAAlB,EAAkCI,QAAlC,GAA6CC,QAA7C,CAAsDvB,QAAQ,CAACwB,GAAT,CAAaC,MAAnE,CAAP;AACD;;AAEiB,SAAXC,WAAW,CAChBC,aADgB,EAEY;AAAA;;AAC5B,UAAM,KAAKhB,OAAL,EAAN;;AACA,eAAW,MAAMiB,KAAjB,IAA0BD,aAA1B,EAAyC;AAIvC,YAAMT,cAAc,GAAGlB,QAAQ,CAACmB,GAAT,CAAaC,SAAb,CAAuBL,MAAvB,CAA8Ba,KAA9B,CAAvB;;AACA,WAAKf,KAAL,CAAWQ,MAAX,CAAkBH,cAAlB;;AACA,YAAMU,KAAN;AACD;;AACD,UAAMZ,IAAI,GAAG,KAAKH,KAAL,CAAWS,QAAX,GAAsBC,QAAtB,CAA+BvB,QAAQ,CAACwB,GAAT,CAAaC,MAA5C,CAAb;;AACA,2BAAKrB,OAAL,2FAAcE,MAAd,0GAAsBuB,KAAtB,8GAA8B;AAACb,MAAAA;AAAD,KAA9B;AACD;;AA5DkC","sourcesContent":["// This dependency is too big, application must provide it\nimport type * as CryptoJSNamespace from 'crypto-js';\nimport {Hash} from './hash';\n\ntype CryptoHashOptions = {\n modules: {[moduleName: string]: any};\n crypto: {\n algorithm: string;\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\nlet CryptoJS: typeof CryptoJSNamespace;\n\n/**\n * A transform that calculates Cryptographic Hash using Crypto JS library\n * @deprecated Warning, experimental class\n */\nexport class CryptoHash extends Hash {\n readonly name;\n\n options: CryptoHashOptions;\n private _algorithm;\n private _hash;\n\n constructor(options: CryptoHashOptions) {\n super();\n this.options = options;\n this._algorithm = this.options?.crypto?.algorithm;\n if (!this._algorithm) {\n throw new Error(this.name);\n }\n this.name = this._algorithm.toLowerCase();\n }\n\n async preload(): Promise<void> {\n if (!CryptoJS) {\n CryptoJS = this.options?.modules?.CryptoJS;\n if (!CryptoJS) {\n throw new Error(this.name);\n }\n }\n if (!this._hash) {\n const algo = CryptoJS.algo[this._algorithm];\n this._hash = algo.create();\n }\n if (!this._hash) {\n throw new Error(this.name);\n }\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n await this.preload();\n // arrayBuffer is accepted, even though types and docs say no\n // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer\n // @ts-expect-error\n const typedWordArray = CryptoJS.lib.WordArray.create(input);\n return this._hash.update(typedWordArray).finalize().toString(CryptoJS.enc.Base64);\n }\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n await this.preload();\n for await (const chunk of asyncIterator) {\n // arrayBuffer is accepted, even though types and docs say no\n // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer\n // @ts-expect-error\n const typedWordArray = CryptoJS.lib.WordArray.create(chunk);\n this._hash.update(typedWordArray);\n yield chunk;\n }\n const hash = this._hash.finalize().toString(CryptoJS.enc.Base64);\n this.options?.crypto?.onEnd?.({hash});\n }\n}\n"],"file":"crypto-hash.js"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Hash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
13
|
+
|
|
14
|
+
class Hash {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
(0, _defineProperty2.default)(this, "name", void 0);
|
|
17
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
18
|
+
this.hashBatches = this.hashBatches.bind(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async preload() {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async *hashBatches(asyncIterator) {
|
|
26
|
+
var _this$options, _this$options$crypto, _this$options$crypto$;
|
|
27
|
+
|
|
28
|
+
const arrayBuffers = [];
|
|
29
|
+
|
|
30
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
31
|
+
arrayBuffers.push(arrayBuffer);
|
|
32
|
+
yield arrayBuffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const output = await this.concatenate(arrayBuffers);
|
|
36
|
+
const hash = await this.hash(output);
|
|
37
|
+
(_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$crypto = _this$options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
38
|
+
hash
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async concatenate(asyncIterator) {
|
|
43
|
+
return await (0, _loaderUtils.concatenateArrayBuffersAsync)(asyncIterator);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.Hash = Hash;
|
|
49
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/hash.ts"],"names":["Hash","constructor","options","hashBatches","bind","preload","asyncIterator","arrayBuffers","arrayBuffer","push","output","concatenate","hash","crypto","onEnd"],"mappings":";;;;;;;;;;;AACA;;AAUO,MAAeA,IAAf,CAAoB;AAIzBC,EAAAA,WAAW,CAACC,OAAoB,GAAG,EAAxB,EAA4B;AAAA;AAAA;AACrC,SAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAsB,IAAtB,CAAnB;AACD;;AAEY,QAAPC,OAAO,GAAkB;AAC7B;AACD;;AAIiB,SAAXF,WAAW,CAChBG,aADgB,EAEY;AAAA;;AAC5B,UAAMC,YAA2B,GAAG,EAApC;;AACA,eAAW,MAAMC,WAAjB,IAAgCF,aAAhC,EAA+C;AAC7CC,MAAAA,YAAY,CAACE,IAAb,CAAkBD,WAAlB;AACA,YAAMA,WAAN;AACD;;AACD,UAAME,MAAM,GAAG,MAAM,KAAKC,WAAL,CAAiBJ,YAAjB,CAArB;AACA,UAAMK,IAAI,GAAG,MAAM,KAAKA,IAAL,CAAUF,MAAV,CAAnB;AACA,0BAAKR,OAAL,wFAAcW,MAAd,uGAAsBC,KAAtB,2GAA8B;AAACF,MAAAA;AAAD,KAA9B;AACD;;AAI0B,QAAXD,WAAW,CAACL,aAAD,EAAsC;AAC/D,WAAO,MAAM,+CAA6BA,aAA7B,CAAb;AACD;;AA/BwB","sourcesContent":["// Hash\nimport {concatenateArrayBuffersAsync} from '@loaders.gl/loader-utils';\n\ntype HashOptions = {\n modules?: {[moduleName: string]: any};\n crypto?: {\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\n/** Abstract hash base class */\nexport abstract class Hash {\n abstract readonly name: string;\n abstract readonly options: HashOptions;\n\n constructor(options: HashOptions = {}) {\n this.hashBatches = this.hashBatches.bind(this);\n }\n\n async preload(): Promise<void> {\n return;\n }\n\n abstract hash(arrayBuffer: ArrayBuffer): Promise<string>;\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n const arrayBuffers: ArrayBuffer[] = [];\n for await (const arrayBuffer of asyncIterator) {\n arrayBuffers.push(arrayBuffer);\n yield arrayBuffer;\n }\n const output = await this.concatenate(arrayBuffers);\n const hash = await this.hash(output);\n this.options?.crypto?.onEnd?.({hash});\n }\n\n // HELPERS\n\n protected async concatenate(asyncIterator): Promise<ArrayBuffer> {\n return await concatenateArrayBuffersAsync(asyncIterator);\n }\n}\n"],"file":"hash.js"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.MD5Hash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _hash = require("./hash");
|
|
13
|
+
|
|
14
|
+
var _md5Wasm = _interopRequireDefault(require("./algorithms/md5-wasm"));
|
|
15
|
+
|
|
16
|
+
var _digestUtils = require("./utils/digest-utils");
|
|
17
|
+
|
|
18
|
+
class MD5Hash extends _hash.Hash {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'md5');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async hash(input) {
|
|
27
|
+
const md5Promise = new Promise((resolve, reject) => (0, _md5Wasm.default)(input).then(resolve).catch(reject));
|
|
28
|
+
const hex = await md5Promise;
|
|
29
|
+
return (0, _digestUtils.hexToBase64)(hex);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.MD5Hash = MD5Hash;
|
|
35
|
+
//# sourceMappingURL=md5-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/md5-hash.ts"],"names":["MD5Hash","Hash","constructor","options","hash","input","md5Promise","Promise","resolve","reject","then","catch","hex"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAKO,MAAMA,OAAN,SAAsBC,UAAtB,CAA2B;AAIhCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxB;AADwB,gDAHV,KAGU;AAAA;AAExB,SAAKA,OAAL,GAAeA,OAAf;AACD;;AAMS,QAAJC,IAAI,CAACC,KAAD,EAAsC;AAC9C,UAAMC,UAAU,GAAG,IAAIC,OAAJ,CAAoB,CAACC,OAAD,EAAUC,MAAV,KACrC,sBAAQJ,KAAR,EAAeK,IAAf,CAAoBF,OAApB,EAA6BG,KAA7B,CAAmCF,MAAnC,CADiB,CAAnB;AAGA,UAAMG,GAAG,GAAG,MAAMN,UAAlB;AACA,WAAO,8BAAYM,GAAZ,CAAP;AACD;;AAnB+B","sourcesContent":["// Fork of https://github.com/briantbutton/md5-wasm under MIT license\nimport {Hash} from './hash';\nimport md5WASM from './algorithms/md5-wasm';\nimport {hexToBase64} from './utils/digest-utils';\n\n/**\n * A transform that calculates MD5 hashes, passing data through\n */\nexport class MD5Hash extends Hash {\n readonly name = 'md5';\n readonly options;\n\n constructor(options = {}) {\n super();\n this.options = options;\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n const md5Promise = new Promise<string>((resolve, reject) =>\n md5WASM(input).then(resolve).catch(reject)\n );\n const hex = await md5Promise;\n return hexToBase64(hex);\n }\n}\n"],"file":"md5-hash.js"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.NodeHash = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _hash = require("./hash");
|
|
13
|
+
|
|
14
|
+
var _crypto = require("crypto");
|
|
15
|
+
|
|
16
|
+
class NodeHash extends _hash.Hash {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _this$options, _this$options$crypto;
|
|
19
|
+
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'crypto-node');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_algorithm", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
25
|
+
this.options = options;
|
|
26
|
+
|
|
27
|
+
if (!((_this$options = this.options) !== null && _this$options !== void 0 && (_this$options$crypto = _this$options.crypto) !== null && _this$options$crypto !== void 0 && _this$options$crypto.algorithm)) {
|
|
28
|
+
throw new Error(this.name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async hash(input) {
|
|
33
|
+
var _this$options2, _this$options2$crypto, _this$options2$crypto2;
|
|
34
|
+
|
|
35
|
+
await this.preload();
|
|
36
|
+
const hash = (0, _crypto.createHash)((_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : (_this$options2$crypto = _this$options2.crypto) === null || _this$options2$crypto === void 0 ? void 0 : (_this$options2$crypto2 = _this$options2$crypto.algorithm) === null || _this$options2$crypto2 === void 0 ? void 0 : _this$options2$crypto2.toLowerCase());
|
|
37
|
+
const inputArray = new Uint8Array(input);
|
|
38
|
+
return hash.update(inputArray).digest('base64');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async *hashBatches(asyncIterator) {
|
|
42
|
+
var _this$options3, _this$options3$crypto, _this$options3$crypto2, _this$options4, _this$options4$crypto, _this$options4$crypto2;
|
|
43
|
+
|
|
44
|
+
await this.preload();
|
|
45
|
+
const hash = (0, _crypto.createHash)((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : (_this$options3$crypto = _this$options3.crypto) === null || _this$options3$crypto === void 0 ? void 0 : (_this$options3$crypto2 = _this$options3$crypto.algorithm) === null || _this$options3$crypto2 === void 0 ? void 0 : _this$options3$crypto2.toLowerCase());
|
|
46
|
+
|
|
47
|
+
for await (const chunk of asyncIterator) {
|
|
48
|
+
const inputArray = new Uint8Array(chunk);
|
|
49
|
+
hash.update(inputArray);
|
|
50
|
+
yield chunk;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
(_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : (_this$options4$crypto = _this$options4.crypto) === null || _this$options4$crypto === void 0 ? void 0 : (_this$options4$crypto2 = _this$options4$crypto.onEnd) === null || _this$options4$crypto2 === void 0 ? void 0 : _this$options4$crypto2.call(_this$options4$crypto, {
|
|
54
|
+
hash: hash.digest('base64')
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.NodeHash = NodeHash;
|
|
61
|
+
//# sourceMappingURL=node-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/node-hash.ts"],"names":["NodeHash","Hash","constructor","options","crypto","algorithm","Error","name","hash","input","preload","toLowerCase","inputArray","Uint8Array","update","digest","hashBatches","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAaO,MAAMA,QAAN,SAAuBC,UAAvB,CAA4B;AASjCC,EAAAA,WAAW,CAACC,OAAD,EAA6B;AAAA;;AACtC;AADsC,gDARxB,aAQwB;AAAA;AAAA;AAAA;AAEtC,SAAKA,OAAL,GAAeA,OAAf;;AACA,QAAI,mBAAC,KAAKA,OAAN,kEAAC,cAAcC,MAAf,iDAAC,qBAAsBC,SAAvB,CAAJ,EAAsC;AACpC,YAAM,IAAIC,KAAJ,CAAU,KAAKC,IAAf,CAAN;AACD;AACF;;AAMS,QAAJC,IAAI,CAACC,KAAD,EAAsC;AAAA;;AAC9C,UAAM,KAAKC,OAAL,EAAN;AACA,UAAMF,IAAI,GAAG,0CAAW,KAAKL,OAAhB,4EAAW,eAAcC,MAAzB,oFAAW,sBAAsBC,SAAjC,2DAAW,uBAAiCM,WAAjC,EAAX,CAAb;AACA,UAAMC,UAAU,GAAG,IAAIC,UAAJ,CAAeJ,KAAf,CAAnB;AACA,WAAOD,IAAI,CAACM,MAAL,CAAYF,UAAZ,EAAwBG,MAAxB,CAA+B,QAA/B,CAAP;AACD;;AAEiB,SAAXC,WAAW,CAChBC,aADgB,EAEY;AAAA;;AAC5B,UAAM,KAAKP,OAAL,EAAN;AACA,UAAMF,IAAI,GAAG,0CAAW,KAAKL,OAAhB,4EAAW,eAAcC,MAAzB,oFAAW,sBAAsBC,SAAjC,2DAAW,uBAAiCM,WAAjC,EAAX,CAAb;;AACA,eAAW,MAAMO,KAAjB,IAA0BD,aAA1B,EAAyC;AAEvC,YAAML,UAAU,GAAG,IAAIC,UAAJ,CAAeK,KAAf,CAAnB;AACAV,MAAAA,IAAI,CAACM,MAAL,CAAYF,UAAZ;AACA,YAAMM,KAAN;AACD;;AACD,2BAAKf,OAAL,2FAAcC,MAAd,0GAAsBe,KAAtB,8GAA8B;AAACX,MAAAA,IAAI,EAAEA,IAAI,CAACO,MAAL,CAAY,QAAZ;AAAP,KAA9B;AACD;;AAxCgC","sourcesContent":["// This dependency is too big, application must provide it\nimport {Hash} from './hash';\nimport {createHash} from 'crypto'; // Node.js builtin\n\ntype CryptoHashOptions = {\n crypto: {\n algorithm: string;\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\n/**\n * Calculates Cryptographic Hash using Node.js crypto library\n * @deprecated Warning, experimental class\n */\nexport class NodeHash extends Hash {\n readonly name = 'crypto-node';\n\n options: CryptoHashOptions;\n // @ts-ignore\n private _algorithm;\n // @ts-ignore\n private _hash;\n\n constructor(options: CryptoHashOptions) {\n super();\n this.options = options;\n if (!this.options?.crypto?.algorithm) {\n throw new Error(this.name);\n }\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n await this.preload();\n const hash = createHash(this.options?.crypto?.algorithm?.toLowerCase());\n const inputArray = new Uint8Array(input);\n return hash.update(inputArray).digest('base64');\n }\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n await this.preload();\n const hash = createHash(this.options?.crypto?.algorithm?.toLowerCase());\n for await (const chunk of asyncIterator) {\n // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer\n const inputArray = new Uint8Array(chunk);\n hash.update(inputArray);\n yield chunk;\n }\n this.options?.crypto?.onEnd?.({hash: hash.digest('base64')});\n }\n}\n"],"file":"node-hash.js"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SHA256Hash = void 0;
|
|
7
|
+
|
|
8
|
+
var _cryptoHash = require("./crypto-hash");
|
|
9
|
+
|
|
10
|
+
class SHA256Hash extends _cryptoHash.CryptoHash {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super({ ...options,
|
|
13
|
+
crypto: { ...options.crypto,
|
|
14
|
+
algorithm: 'SHA256'
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.SHA256Hash = SHA256Hash;
|
|
22
|
+
//# sourceMappingURL=sha256-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/sha256-hash.ts"],"names":["SHA256Hash","CryptoHash","constructor","options","crypto","algorithm"],"mappings":";;;;;;;AACA;;AAYO,MAAMA,UAAN,SAAyBC,sBAAzB,CAAoC;AACzCC,EAAAA,WAAW,CAACC,OAAD,EAA6B;AACtC,UAAM,EAAC,GAAGA,OAAJ;AAAaC,MAAAA,MAAM,EAAE,EAAC,GAAGD,OAAO,CAACC,MAAZ;AAAoBC,QAAAA,SAAS,EAAE;AAA/B;AAArB,KAAN;AACD;;AAHwC","sourcesContent":["//\nimport {CryptoHash} from './crypto-hash';\n\ntype CryptoHashOptions = {\n modules: {[moduleName: string]: any};\n crypto?: {\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\n/**\n * A transform that calculates Cryptographic Hash\n */\nexport class SHA256Hash extends CryptoHash {\n constructor(options: CryptoHashOptions) {\n super({...options, crypto: {...options.crypto, algorithm: 'SHA256'}});\n }\n}\n"],"file":"sha256-hash.js"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toBase64 = toBase64;
|
|
7
|
+
|
|
8
|
+
function toBase64(string) {
|
|
9
|
+
string = "".concat(string);
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < string.length; i++) {
|
|
12
|
+
if (string.charCodeAt(i) > 255) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let out = '';
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < string.length; i += 3) {
|
|
20
|
+
const groupsOfSix = [undefined, undefined, undefined, undefined];
|
|
21
|
+
groupsOfSix[0] = string.charCodeAt(i) >> 2;
|
|
22
|
+
groupsOfSix[1] = (string.charCodeAt(i) & 0x03) << 4;
|
|
23
|
+
|
|
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
|
+
|
|
29
|
+
if (string.length > i + 2) {
|
|
30
|
+
groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;
|
|
31
|
+
groupsOfSix[3] = string.charCodeAt(i + 2) & 0x3f;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
35
|
+
if (typeof groupsOfSix[j] === 'undefined') {
|
|
36
|
+
out += '=';
|
|
37
|
+
} else {
|
|
38
|
+
out += btoaLookup(groupsOfSix[j]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function btoaLookup(idx) {
|
|
47
|
+
if (idx < 26) {
|
|
48
|
+
return String.fromCharCode(idx + 'A'.charCodeAt(0));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (idx < 52) {
|
|
52
|
+
return String.fromCharCode(idx - 26 + 'a'.charCodeAt(0));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (idx < 62) {
|
|
56
|
+
return String.fromCharCode(idx - 52 + '0'.charCodeAt(0));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (idx === 62) {
|
|
60
|
+
return '+';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (idx === 63) {
|
|
64
|
+
return '/';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=base64-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/base64-utils.js"],"names":["toBase64","string","i","length","charCodeAt","out","groupsOfSix","undefined","j","btoaLookup","idx","String","fromCharCode"],"mappings":";;;;;;;AAIO,SAASA,QAAT,CAAkBC,MAAlB,EAA0B;AAE/BA,EAAAA,MAAM,aAAMA,MAAN,CAAN;;AAGA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,MAAM,CAACE,MAA3B,EAAmCD,CAAC,EAApC,EAAwC;AACtC,QAAID,MAAM,CAACG,UAAP,CAAkBF,CAAlB,IAAuB,GAA3B,EAAgC;AAC9B,aAAO,IAAP;AACD;AACF;;AACD,MAAIG,GAAG,GAAG,EAAV;;AACA,OAAK,IAAIH,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,MAAM,CAACE,MAA3B,EAAmCD,CAAC,IAAI,CAAxC,EAA2C;AAEzC,UAAMI,WAAW,GAAG,CAACC,SAAD,EAAYA,SAAZ,EAAuBA,SAAvB,EAAkCA,SAAlC,CAApB;AACAD,IAAAA,WAAW,CAAC,CAAD,CAAX,GAAiBL,MAAM,CAACG,UAAP,CAAkBF,CAAlB,KAAwB,CAAzC;AACAI,IAAAA,WAAW,CAAC,CAAD,CAAX,GAAiB,CAACL,MAAM,CAACG,UAAP,CAAkBF,CAAlB,IAAuB,IAAxB,KAAiC,CAAlD;;AACA,QAAID,MAAM,CAACE,MAAP,GAAgBD,CAAC,GAAG,CAAxB,EAA2B;AACzBI,MAAAA,WAAW,CAAC,CAAD,CAAX,IAAkBL,MAAM,CAACG,UAAP,CAAkBF,CAAC,GAAG,CAAtB,KAA4B,CAA9C;AACAI,MAAAA,WAAW,CAAC,CAAD,CAAX,GAAiB,CAACL,MAAM,CAACG,UAAP,CAAkBF,CAAC,GAAG,CAAtB,IAA2B,IAA5B,KAAqC,CAAtD;AACD;;AACD,QAAID,MAAM,CAACE,MAAP,GAAgBD,CAAC,GAAG,CAAxB,EAA2B;AACzBI,MAAAA,WAAW,CAAC,CAAD,CAAX,IAAkBL,MAAM,CAACG,UAAP,CAAkBF,CAAC,GAAG,CAAtB,KAA4B,CAA9C;AACAI,MAAAA,WAAW,CAAC,CAAD,CAAX,GAAiBL,MAAM,CAACG,UAAP,CAAkBF,CAAC,GAAG,CAAtB,IAA2B,IAA5C;AACD;;AACD,SAAK,IAAIM,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,WAAW,CAACH,MAAhC,EAAwCK,CAAC,EAAzC,EAA6C;AAC3C,UAAI,OAAOF,WAAW,CAACE,CAAD,CAAlB,KAA0B,WAA9B,EAA2C;AACzCH,QAAAA,GAAG,IAAI,GAAP;AACD,OAFD,MAEO;AACLA,QAAAA,GAAG,IAAII,UAAU,CAACH,WAAW,CAACE,CAAD,CAAZ,CAAjB;AACD;AACF;AACF;;AACD,SAAOH,GAAP;AACD;;AAMD,SAASI,UAAT,CAAoBC,GAApB,EAAyB;AACvB,MAAIA,GAAG,GAAG,EAAV,EAAc;AACZ,WAAOC,MAAM,CAACC,YAAP,CAAoBF,GAAG,GAAG,IAAIN,UAAJ,CAAe,CAAf,CAA1B,CAAP;AACD;;AACD,MAAIM,GAAG,GAAG,EAAV,EAAc;AACZ,WAAOC,MAAM,CAACC,YAAP,CAAoBF,GAAG,GAAG,EAAN,GAAW,IAAIN,UAAJ,CAAe,CAAf,CAA/B,CAAP;AACD;;AACD,MAAIM,GAAG,GAAG,EAAV,EAAc;AACZ,WAAOC,MAAM,CAACC,YAAP,CAAoBF,GAAG,GAAG,EAAN,GAAW,IAAIN,UAAJ,CAAe,CAAf,CAA/B,CAAP;AACD;;AACD,MAAIM,GAAG,KAAK,EAAZ,EAAgB;AACd,WAAO,GAAP;AACD;;AACD,MAAIA,GAAG,KAAK,EAAZ,EAAgB;AACd,WAAO,GAAP;AACD;;AAED,SAAOH,SAAP;AACD","sourcesContent":["/**\n * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references\n * RFC 4648.\n */\nexport function toBase64(string) {\n // String conversion as required by Web IDL.\n string = `${string}`;\n // \"The btoa() method must throw an \"InvalidCharacterError\" DOMException if\n // data contains any character whose code point is greater than U+00FF.\"\n for (let i = 0; i < string.length; i++) {\n if (string.charCodeAt(i) > 255) {\n return null;\n }\n }\n let out = '';\n for (let i = 0; i < string.length; i += 3) {\n /** @type {Array[4]} */\n const groupsOfSix = [undefined, undefined, undefined, undefined];\n groupsOfSix[0] = string.charCodeAt(i) >> 2;\n groupsOfSix[1] = (string.charCodeAt(i) & 0x03) << 4;\n if (string.length > i + 1) {\n groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;\n groupsOfSix[2] = (string.charCodeAt(i + 1) & 0x0f) << 2;\n }\n if (string.length > i + 2) {\n groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;\n groupsOfSix[3] = string.charCodeAt(i + 2) & 0x3f;\n }\n for (let j = 0; j < groupsOfSix.length; j++) {\n if (typeof groupsOfSix[j] === 'undefined') {\n out += '=';\n } else {\n out += btoaLookup(groupsOfSix[j]);\n }\n }\n }\n return out;\n}\n\n/**\n * Lookup table for btoa(), which converts a six-bit number into the\n * corresponding ASCII character.\n */\nfunction btoaLookup(idx) {\n if (idx < 26) {\n return String.fromCharCode(idx + 'A'.charCodeAt(0));\n }\n if (idx < 52) {\n return String.fromCharCode(idx - 26 + 'a'.charCodeAt(0));\n }\n if (idx < 62) {\n return String.fromCharCode(idx - 52 + '0'.charCodeAt(0));\n }\n if (idx === 62) {\n return '+';\n }\n if (idx === 63) {\n return '/';\n }\n // Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the teststring.\n return undefined;\n}\n"],"file":"base64-utils.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toHex = toHex;
|
|
7
|
+
exports.hexToBase64 = hexToBase64;
|
|
8
|
+
|
|
9
|
+
var _base64Utils = require("./base64-utils");
|
|
10
|
+
|
|
11
|
+
function toHex(cipher) {
|
|
12
|
+
const hexString = cipher.toString(16);
|
|
13
|
+
return hexString === '0' ? "0".concat(hexString) : hexString;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function hexToBase64(hexstring) {
|
|
17
|
+
if (hexstring.length % 2 !== 0) {
|
|
18
|
+
hexstring = "0".concat(hexstring);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const string = hexstring.match(/\w{2}/g).map(a => String.fromCharCode(parseInt(a, 16))).join('');
|
|
22
|
+
return (0, _base64Utils.toBase64)(string);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=digest-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/digest-utils.js"],"names":["toHex","cipher","hexString","toString","hexToBase64","hexstring","length","string","match","map","a","String","fromCharCode","parseInt","join"],"mappings":";;;;;;;;AAAA;;AAKO,SAASA,KAAT,CAAeC,MAAf,EAAuB;AAC5B,QAAMC,SAAS,GAAGD,MAAM,CAACE,QAAP,CAAgB,EAAhB,CAAlB;AACA,SAAOD,SAAS,KAAK,GAAd,cAAwBA,SAAxB,IAAsCA,SAA7C;AACD;;AAKM,SAASE,WAAT,CAAqBC,SAArB,EAAgC;AAGrC,MAAIA,SAAS,CAACC,MAAV,GAAmB,CAAnB,KAAyB,CAA7B,EAAgC;AAC9BD,IAAAA,SAAS,cAAOA,SAAP,CAAT;AACD;;AACD,QAAME,MAAM,GAAGF,SAAS,CACrBG,KADY,CACN,QADM,EAEZC,GAFY,CAEPC,CAAD,IAAOC,MAAM,CAACC,YAAP,CAAoBC,QAAQ,CAACH,CAAD,EAAI,EAAJ,CAA5B,CAFC,EAGZI,IAHY,CAGP,EAHO,CAAf;AAIA,SAAO,2BAASP,MAAT,CAAP;AACD","sourcesContent":["import {toBase64} from './base64-utils';\n\n/**\n *\n */\nexport function toHex(cipher) {\n const hexString = cipher.toString(16);\n return hexString === '0' ? `0${hexString}` : hexString;\n}\n\n/**\n *\n */\nexport function hexToBase64(hexstring) {\n // Add leading zero to keep even count of digits\n // eg. f85d741 => 0f85d741\n if (hexstring.length % 2 !== 0) {\n hexstring = `0${hexstring}`;\n }\n const string = hexstring\n .match(/\\w{2}/g)\n .map((a) => String.fromCharCode(parseInt(a, 16)))\n .join('');\n return toBase64(string);\n}\n"],"file":"digest-utils.js"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CRC32Hash", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _crc32Hash.CRC32Hash;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CRC32CHash", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _crc32cHash.CRC32CHash;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
20
|
+
|
|
21
|
+
var _crc32Hash = require("../lib/crc32-hash");
|
|
22
|
+
|
|
23
|
+
var _crc32cHash = require("../lib/crc32c-hash");
|
|
24
|
+
|
|
25
|
+
var _md5Hash = require("../lib/md5-hash");
|
|
26
|
+
|
|
27
|
+
(0, _workerUtils.createWorker)(async (data, options = {}) => {
|
|
28
|
+
const {
|
|
29
|
+
operation
|
|
30
|
+
} = options;
|
|
31
|
+
|
|
32
|
+
switch (operation) {
|
|
33
|
+
case 'crc32':
|
|
34
|
+
return await new _crc32Hash.CRC32Hash(options).hash(data);
|
|
35
|
+
|
|
36
|
+
case 'crc32c':
|
|
37
|
+
return await new _crc32cHash.CRC32CHash(options).hash(data);
|
|
38
|
+
|
|
39
|
+
case 'md5':
|
|
40
|
+
return await new _md5Hash.MD5Hash(options).hash(data);
|
|
41
|
+
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("invalid option: ".concat(operation));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/workers/worker.ts"],"names":["data","options","operation","CRC32Hash","hash","CRC32CHash","MD5Hash","Error"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA,+BAAa,OAAOA,IAAP,EAAaC,OAAO,GAAG,EAAvB,KAA8B;AAEzC,QAAM;AAACC,IAAAA;AAAD,MAAcD,OAApB;;AAEA,UAAQC,SAAR;AACE,SAAK,OAAL;AACE,aAAO,MAAM,IAAIC,oBAAJ,CAAcF,OAAd,EAAuBG,IAAvB,CAA4BJ,IAA5B,CAAb;;AACF,SAAK,QAAL;AACE,aAAO,MAAM,IAAIK,sBAAJ,CAAeJ,OAAf,EAAwBG,IAAxB,CAA6BJ,IAA7B,CAAb;;AACF,SAAK,KAAL;AACE,aAAO,MAAM,IAAIM,gBAAJ,CAAYL,OAAZ,EAAqBG,IAArB,CAA0BJ,IAA1B,CAAb;;AACF;AACE,YAAM,IAAIO,KAAJ,2BAA6BL,SAA7B,EAAN;AARJ;AAUD,CAdD","sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport {CRC32Hash} from '../lib/crc32-hash';\nimport {CRC32CHash} from '../lib/crc32c-hash';\nimport {MD5Hash} from '../lib/md5-hash';\n\n// Assuming we can bundle as module\nexport {CRC32Hash, CRC32CHash};\n\ncreateWorker(async (data, options = {}) => {\n // @ts-ignore\n const {operation} = options;\n\n switch (operation) {\n case 'crc32':\n return await new CRC32Hash(options).hash(data);\n case 'crc32c':\n return await new CRC32CHash(options).hash(data);\n case 'md5':\n return await new MD5Hash(options).hash(data);\n default:\n throw new Error(`invalid option: ${operation}`);\n }\n});\n"],"file":"worker.js"}
|