@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/esm/lib/hash.js
CHANGED
|
@@ -10,18 +10,26 @@ export class Hash {
|
|
|
10
10
|
async preload() {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
hashBatches(asyncIterator) {
|
|
14
|
+
try {
|
|
15
|
+
var _this = this;
|
|
16
|
+
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'base64';
|
|
17
|
+
return async function* () {
|
|
18
|
+
var _this$options$crypto, _this$options$crypto$;
|
|
19
|
+
const arrayBuffers = [];
|
|
20
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
21
|
+
arrayBuffers.push(arrayBuffer);
|
|
22
|
+
yield arrayBuffer;
|
|
23
|
+
}
|
|
24
|
+
const output = await _this.concatenate(arrayBuffers);
|
|
25
|
+
const hash = await _this.hash(output, encoding);
|
|
26
|
+
(_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, {
|
|
27
|
+
hash
|
|
28
|
+
});
|
|
29
|
+
}();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return Promise.reject(e);
|
|
19
32
|
}
|
|
20
|
-
const output = await this.concatenate(arrayBuffers);
|
|
21
|
-
const hash = await this.hash(output);
|
|
22
|
-
(_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, {
|
|
23
|
-
hash
|
|
24
|
-
});
|
|
25
33
|
}
|
|
26
34
|
async concatenate(asyncIterator) {
|
|
27
35
|
return await concatenateArrayBuffersAsync(asyncIterator);
|
package/dist/esm/lib/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","names":["concatenateArrayBuffersAsync","Hash","constructor","options","arguments","length","undefined","_defineProperty","hashBatches","bind","preload","asyncIterator","_this$options$crypto","_this$options$crypto$","arrayBuffers","arrayBuffer","push","output","concatenate","hash","crypto","onEnd","call"],"sources":["../../../src/lib/hash.ts"],"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
|
|
1
|
+
{"version":3,"file":"hash.js","names":["concatenateArrayBuffersAsync","Hash","constructor","options","arguments","length","undefined","_defineProperty","hashBatches","bind","preload","asyncIterator","_this","encoding","_this$options$crypto","_this$options$crypto$","arrayBuffers","arrayBuffer","push","output","concatenate","hash","crypto","onEnd","call","e","Promise","reject"],"sources":["../../../src/lib/hash.ts"],"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, encoding: 'hex' | 'base64'): Promise<string>;\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n encoding: 'hex' | 'base64' = 'base64'\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, encoding);\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"],"mappings":";AACA,SAAQA,4BAA4B,QAAO,0BAA0B;AAUrE,OAAO,MAAeC,IAAI,CAAC;EAIzBC,WAAWA,CAAA,EAA4B;IAAA,IAA3BC,OAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAAG,eAAA;IAAAA,eAAA;IACnC,IAAI,CAACC,WAAW,GAAG,IAAI,CAACA,WAAW,CAACC,IAAI,CAAC,IAAI,CAAC;EAChD;EAEA,MAAMC,OAAOA,CAAA,EAAkB;IAC7B;EACF;EAIOF,WAAWA,CAChBG,aAAiE;IAAA;MAAA,IAAAC,KAAA;MAAA,IACjEC,QAA0B,GAAAT,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,QAAQ;MAAA,0BACT;QAAA,IAAAU,oBAAA,EAAAC,qBAAA;QAC5B,MAAMC,YAA2B,GAAG,EAAE;QACtC,WAAW,MAAMC,WAAW,IAAIN,aAAa,EAAE;UAC7CK,YAAY,CAACE,IAAI,CAACD,WAAW,CAAC;UAC9B,MAAMA,WAAW;QACnB;QACA,MAAME,MAAM,GAAG,MAAMP,KAAI,CAACQ,WAAW,CAACJ,YAAY,CAAC;QACnD,MAAMK,IAAI,GAAG,MAAMT,KAAI,CAACS,IAAI,CAACF,MAAM,EAAEN,QAAQ,CAAC;QAC9C,CAAAC,oBAAA,GAAAF,KAAI,CAACT,OAAO,CAACmB,MAAM,cAAAR,oBAAA,wBAAAC,qBAAA,GAAnBD,oBAAA,CAAqBS,KAAK,cAAAR,qBAAA,uBAA1BA,qBAAA,CAAAS,IAAA,CAAAV,oBAAA,EAA6B;UAACO;QAAI,CAAC,CAAC;MACtC,CAAC;IAAA,SAAAI,CAAA;MAAA,OAAAC,OAAA,CAAAC,MAAA,CAAAF,CAAA;IAAA;EAAA;EAID,MAAgBL,WAAWA,CAACT,aAAa,EAAwB;IAC/D,OAAO,MAAMX,4BAA4B,CAACW,aAAa,CAAC;EAC1D;AACF"}
|
package/dist/esm/lib/md5-hash.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { Hash } from './hash';
|
|
3
3
|
import md5WASM from './algorithms/md5-wasm';
|
|
4
|
-
import {
|
|
4
|
+
import { encodeHex } from './utils/digest-utils';
|
|
5
5
|
export class MD5Hash extends Hash {
|
|
6
6
|
constructor() {
|
|
7
7
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -10,10 +10,10 @@ export class MD5Hash extends Hash {
|
|
|
10
10
|
_defineProperty(this, "options", void 0);
|
|
11
11
|
this.options = options;
|
|
12
12
|
}
|
|
13
|
-
async hash(input) {
|
|
13
|
+
async hash(input, encoding) {
|
|
14
14
|
const md5Promise = new Promise((resolve, reject) => md5WASM(input).then(resolve).catch(reject));
|
|
15
15
|
const hex = await md5Promise;
|
|
16
|
-
return
|
|
16
|
+
return encodeHex(hex, encoding);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=md5-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"md5-hash.js","names":["Hash","md5WASM","
|
|
1
|
+
{"version":3,"file":"md5-hash.js","names":["Hash","md5WASM","encodeHex","MD5Hash","constructor","options","arguments","length","undefined","_defineProperty","hash","input","encoding","md5Promise","Promise","resolve","reject","then","catch","hex"],"sources":["../../../src/lib/md5-hash.ts"],"sourcesContent":["// Fork of https://github.com/briantbutton/md5-wasm under MIT license\nimport {Hash} from './hash';\nimport md5WASM from './algorithms/md5-wasm';\nimport {encodeHex} 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, encoding: 'hex' | 'base64'): Promise<string> {\n const md5Promise = new Promise<string>((resolve, reject) =>\n // @ts-expect-error\n md5WASM(input).then(resolve).catch(reject)\n );\n const hex = await md5Promise;\n return encodeHex(hex, encoding);\n }\n}\n"],"mappings":";AACA,SAAQA,IAAI,QAAO,QAAQ;AAC3B,OAAOC,OAAO,MAAM,uBAAuB;AAC3C,SAAQC,SAAS,QAAO,sBAAsB;AAK9C,OAAO,MAAMC,OAAO,SAASH,IAAI,CAAC;EAIhCI,WAAWA,CAAA,EAAe;IAAA,IAAdC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtB,KAAK,CAAC,CAAC;IAACG,eAAA,eAJM,KAAK;IAAAA,eAAA;IAKnB,IAAI,CAACJ,OAAO,GAAGA,OAAO;EACxB;EAMA,MAAMK,IAAIA,CAACC,KAAkB,EAAEC,QAA0B,EAAmB;IAC1E,MAAMC,UAAU,GAAG,IAAIC,OAAO,CAAS,CAACC,OAAO,EAAEC,MAAM,KAErDf,OAAO,CAACU,KAAK,CAAC,CAACM,IAAI,CAACF,OAAO,CAAC,CAACG,KAAK,CAACF,MAAM,CAC3C,CAAC;IACD,MAAMG,GAAG,GAAG,MAAMN,UAAU;IAC5B,OAAOX,SAAS,CAACiB,GAAG,EAAEP,QAAQ,CAAC;EACjC;AACF"}
|
|
@@ -14,25 +14,39 @@ export class NodeHash extends Hash {
|
|
|
14
14
|
throw new Error(this.name);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
async hash(input) {
|
|
17
|
+
async hash(input, encoding) {
|
|
18
18
|
var _this$options2, _this$options2$crypto, _this$options2$crypto2;
|
|
19
19
|
await this.preload();
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const algorithm = (_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();
|
|
21
|
+
try {
|
|
22
|
+
const hash = createHash(algorithm);
|
|
23
|
+
const inputArray = new Uint8Array(input);
|
|
24
|
+
return hash.update(inputArray).digest('base64');
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw Error("".concat(algorithm, " hash not available. ").concat(error));
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
hashBatches(asyncIterator) {
|
|
30
|
+
try {
|
|
31
|
+
var _this = this;
|
|
32
|
+
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'base64';
|
|
33
|
+
return async function* () {
|
|
34
|
+
var _this$options3, _this$options3$crypto, _this$options3$crypto2, _this$options4, _this$options4$crypto, _this$options4$crypto2;
|
|
35
|
+
await _this.preload();
|
|
36
|
+
const hash = 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());
|
|
37
|
+
for await (const chunk of asyncIterator) {
|
|
38
|
+
const inputArray = new Uint8Array(chunk);
|
|
39
|
+
hash.update(inputArray);
|
|
40
|
+
yield chunk;
|
|
41
|
+
}
|
|
42
|
+
const digest = hash.digest(encoding);
|
|
43
|
+
(_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, {
|
|
44
|
+
hash: digest
|
|
45
|
+
});
|
|
46
|
+
}();
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return Promise.reject(e);
|
|
32
49
|
}
|
|
33
|
-
(_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, {
|
|
34
|
-
hash: hash.digest('base64')
|
|
35
|
-
});
|
|
36
50
|
}
|
|
37
51
|
}
|
|
38
52
|
//# sourceMappingURL=node-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-hash.js","names":["Hash","createHash","NodeHash","constructor","options","_this$options","_this$options$crypto","_defineProperty","crypto","algorithm","Error","name","hash","input","_this$options2","_this$options2$crypto","_this$options2$crypto2","preload","toLowerCase","inputArray","Uint8Array","update","digest","hashBatches","asyncIterator","_this$options3","_this$options3$crypto","_this$options3$crypto2","_this$options4","_this$options4$crypto","_this$options4$crypto2","chunk","onEnd","call"],"sources":["../../../src/lib/node-hash.ts"],"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
|
|
1
|
+
{"version":3,"file":"node-hash.js","names":["Hash","createHash","NodeHash","constructor","options","_this$options","_this$options$crypto","_defineProperty","crypto","algorithm","Error","name","hash","input","encoding","_this$options2","_this$options2$crypto","_this$options2$crypto2","preload","toLowerCase","inputArray","Uint8Array","update","digest","error","concat","hashBatches","asyncIterator","_this","arguments","length","undefined","_this$options3","_this$options3$crypto","_this$options3$crypto2","_this$options4","_this$options4$crypto","_this$options4$crypto2","chunk","onEnd","call","e","Promise","reject"],"sources":["../../../src/lib/node-hash.ts"],"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, encoding: 'hex' | 'base64'): Promise<string> {\n await this.preload();\n const algorithm = this.options?.crypto?.algorithm?.toLowerCase();\n try {\n const hash = createHash(algorithm);\n const inputArray = new Uint8Array(input);\n return hash.update(inputArray).digest('base64');\n } catch (error) {\n throw Error(`${algorithm} hash not available. ${error}`);\n }\n }\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n encoding: 'hex' | 'base64' = 'base64'\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 // We can pass our encoding constant directly to Node.js digest as it already supports `hex` and `base64`\n const digest = hash.digest(encoding);\n this.options?.crypto?.onEnd?.({hash: digest});\n }\n}\n"],"mappings":";AACA,SAAQA,IAAI,QAAO,QAAQ;AAC3B,SAAQC,UAAU,QAAO,QAAQ;AAajC,OAAO,MAAMC,QAAQ,SAASF,IAAI,CAAC;EASjCG,WAAWA,CAACC,OAA0B,EAAE;IAAA,IAAAC,aAAA,EAAAC,oBAAA;IACtC,KAAK,CAAC,CAAC;IAACC,eAAA,eATM,aAAa;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAU3B,IAAI,CAACH,OAAO,GAAGA,OAAO;IACtB,IAAI,GAAAC,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AAI,GAAGX,UAAU,EAAA+B,cAAA,GAACJ,KAAI,CAACxB,OAAO,cAAA4B,cAAA,wBAAAC,qBAAA,GAAZD,cAAA,CAAcxB,MAAM,cAAAyB,qBAAA,wBAAAC,sBAAA,GAApBD,qBAAA,CAAsBxB,SAAS,cAAAyB,sBAAA,uBAA/BA,sBAAA,CAAiCf,WAAW,CAAC,CAAC,CAAC;QACvE,WAAW,MAAMmB,KAAK,IAAIX,aAAa,EAAE;UAEvC,MAAMP,UAAU,GAAG,IAAIC,UAAU,CAACiB,KAAK,CAAC;UACxC1B,IAAI,CAACU,MAAM,CAACF,UAAU,CAAC;UACvB,MAAMkB,KAAK;QACb;QAEA,MAAMf,MAAM,GAAGX,IAAI,CAACW,MAAM,CAACT,QAAQ,CAAC;QACpC,CAAAqB,cAAA,GAAAP,KAAI,CAACxB,OAAO,cAAA+B,cAAA,wBAAAC,qBAAA,GAAZD,cAAA,CAAc3B,MAAM,cAAA4B,qBAAA,wBAAAC,sBAAA,GAApBD,qBAAA,CAAsBG,KAAK,cAAAF,sBAAA,uBAA3BA,sBAAA,CAAAG,IAAA,CAAAJ,qBAAA,EAA8B;UAACxB,IAAI,EAAEW;QAAM,CAAC,CAAC;MAC/C,CAAC;IAAA,SAAAkB,CAAA;MAAA,OAAAC,OAAA,CAAAC,MAAA,CAAAF,CAAA;IAAA;EAAA;AACH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function asciiToBase64(string) {
|
|
2
2
|
string = "".concat(string);
|
|
3
3
|
for (let i = 0; i < string.length; i++) {
|
|
4
4
|
if (string.charCodeAt(i) > 255) {
|
|
@@ -28,6 +28,44 @@ export function toBase64(string) {
|
|
|
28
28
|
}
|
|
29
29
|
return out;
|
|
30
30
|
}
|
|
31
|
+
export function base64ToAscii(data) {
|
|
32
|
+
data = "".concat(data);
|
|
33
|
+
data = data.replace(/[ \t\n\f\r]/g, '');
|
|
34
|
+
if (data.length % 4 === 0) {
|
|
35
|
+
data = data.replace(/[=]=?$/, '');
|
|
36
|
+
}
|
|
37
|
+
if (data.length % 4 === 1 || /[^+/0-9A-Za-z]/.test(data)) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
let output = '';
|
|
41
|
+
let buffer = 0;
|
|
42
|
+
let accumulatedBits = 0;
|
|
43
|
+
for (let i = 0; i < data.length; i++) {
|
|
44
|
+
buffer <<= 6;
|
|
45
|
+
buffer |= atobLookup(data[i]);
|
|
46
|
+
accumulatedBits += 6;
|
|
47
|
+
if (accumulatedBits === 24) {
|
|
48
|
+
output += String.fromCharCode((buffer & 0xff0000) >> 16);
|
|
49
|
+
output += String.fromCharCode((buffer & 0xff00) >> 8);
|
|
50
|
+
output += String.fromCharCode(buffer & 0xff);
|
|
51
|
+
buffer = accumulatedBits = 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (accumulatedBits === 12) {
|
|
55
|
+
buffer >>= 4;
|
|
56
|
+
output += String.fromCharCode(buffer);
|
|
57
|
+
} else if (accumulatedBits === 18) {
|
|
58
|
+
buffer >>= 2;
|
|
59
|
+
output += String.fromCharCode((buffer & 0xff00) >> 8);
|
|
60
|
+
output += String.fromCharCode(buffer & 0xff);
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
const keystr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
65
|
+
function atobLookup(chr) {
|
|
66
|
+
const index = keystr.indexOf(chr);
|
|
67
|
+
return index < 0 ? undefined : index;
|
|
68
|
+
}
|
|
31
69
|
function btoaLookup(idx) {
|
|
32
70
|
if (idx < 26) {
|
|
33
71
|
return String.fromCharCode(idx + 'A'.charCodeAt(0));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-utils.js","names":["
|
|
1
|
+
{"version":3,"file":"base64-utils.js","names":["asciiToBase64","string","concat","i","length","charCodeAt","out","groupsOfSix","undefined","j","btoaLookup","base64ToAscii","data","replace","test","output","buffer","accumulatedBits","atobLookup","String","fromCharCode","keystr","chr","index","indexOf","idx"],"sources":["../../../../src/lib/utils/base64-utils.ts"],"sourcesContent":["/**\n * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references\n * RFC 4648.\n */\nexport function asciiToBase64(string: string): string | null {\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: (number | undefined)[] = [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 // @ts-expect-error\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 * Implementation of atob() according to the HTML and Infra specs, except that\n * instead of throwing INVALID_CHARACTER_ERR we return null.\n *\n * @note Forked from https://github.com/jsdom/abab under BSD 3 clause license\n */\nexport function base64ToAscii(data: string): string {\n // Web IDL requires DOMStrings to just be converted using ECMAScript\n // ToString, which in our case amounts to using a template literal.\n data = `${data}`;\n // \"Remove all ASCII whitespace from data.\"\n data = data.replace(/[ \\t\\n\\f\\r]/g, '');\n // \"If data's code point length divides by 4 leaving no remainder, then: if data ends\n // with one or two U+003D (=) code points, then remove them from data.\"\n if (data.length % 4 === 0) {\n data = data.replace(/[=]=?$/, '');\n }\n // \"If data's code point length divides by 4 leaving a remainder of 1, then return\n // failure.\"\n //\n // \"If data contains a code point that is not one of\n //\n // U+002B (+)\n // U+002F (/)\n // ASCII alphanumeric\n //\n // then return failure.\"\n if (data.length % 4 === 1 || /[^+/0-9A-Za-z]/.test(data)) {\n return '';\n }\n // \"Let output be an empty byte sequence.\"\n let output = '';\n // \"Let buffer be an empty buffer that can have bits appended to it.\"\n //\n // We append bits via left-shift and or. accumulatedBits is used to track\n // when we've gotten to 24 bits.\n let buffer = 0;\n let accumulatedBits = 0;\n // \"Let position be a position variable for data, initially pointing at the\n // start of data.\"\n //\n // \"While position does not point past the end of data:\"\n for (let i = 0; i < data.length; i++) {\n // \"Find the code point pointed to by position in the second column of\n // Table 1: The Base 64 Alphabet of RFC 4648. Let n be the number given in\n // the first cell of the same row.\n //\n // \"Append to buffer the six bits corresponding to n, most significant bit\n // first.\"\n //\n // atobLookup() implements the table from RFC 4648.\n buffer <<= 6;\n // @ts-expect-error\n buffer |= atobLookup(data[i]);\n accumulatedBits += 6;\n // \"If buffer has accumulated 24 bits, interpret them as three 8-bit\n // big-endian numbers. Append three bytes with values equal to those\n // numbers to output, in the same order, and then empty buffer.\"\n if (accumulatedBits === 24) {\n output += String.fromCharCode((buffer & 0xff0000) >> 16);\n output += String.fromCharCode((buffer & 0xff00) >> 8);\n output += String.fromCharCode(buffer & 0xff);\n buffer = accumulatedBits = 0;\n }\n // \"Advance position by 1.\"\n }\n // \"If buffer is not empty, it contains either 12 or 18 bits. If it contains\n // 12 bits, then discard the last four and interpret the remaining eight as\n // an 8-bit big-endian number. If it contains 18 bits, then discard the last\n // two and interpret the remaining 16 as two 8-bit big-endian numbers. Append\n // the one or two bytes with values equal to those one or two numbers to\n // output, in the same order.\"\n if (accumulatedBits === 12) {\n buffer >>= 4;\n output += String.fromCharCode(buffer);\n } else if (accumulatedBits === 18) {\n buffer >>= 2;\n output += String.fromCharCode((buffer & 0xff00) >> 8);\n output += String.fromCharCode(buffer & 0xff);\n }\n // \"Return output.\"\n return output;\n}\n/**\n * A lookup table for atob(), which converts an ASCII character to the\n * corresponding six-bit number.\n */\n\nconst keystr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nfunction atobLookup(chr: string): number | undefined {\n const index = keystr.indexOf(chr);\n // Throw exception if character is not in the lookup string; should not be hit in tests\n return index < 0 ? undefined : index;\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"],"mappings":"AAIA,OAAO,SAASA,aAAaA,CAACC,MAAc,EAAiB;EAE3DA,MAAM,MAAAC,MAAA,CAAMD,MAAM,CAAE;EAGpB,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,CAACG,MAAM,EAAED,CAAC,EAAE,EAAE;IACtC,IAAIF,MAAM,CAACI,UAAU,CAACF,CAAC,CAAC,GAAG,GAAG,EAAE;MAC9B,OAAO,IAAI;IACb;EACF;EACA,IAAIG,GAAG,GAAG,EAAE;EACZ,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,CAACG,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;IAEzC,MAAMI,WAAmC,GAAG,CAACC,SAAS,EAAEA,SAAS,EAAEA,SAAS,EAAEA,SAAS,CAAC;IACxFD,WAAW,CAAC,CAAC,CAAC,GAAGN,MAAM,CAACI,UA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AAG,kEAAkE;AAEjF,SAASH,UAAUA,CAACI,GAAW,EAAsB;EACnD,MAAMC,KAAK,GAAGF,MAAM,CAACG,OAAO,CAACF,GAAG,CAAC;EAEjC,OAAOC,KAAK,GAAG,CAAC,GAAGf,SAAS,GAAGe,KAAK;AACtC;AAMA,SAASb,UAAUA,CAACe,GAAG,EAAE;EACvB,IAAIA,GAAG,GAAG,EAAE,EAAE;IACZ,OAAON,MAAM,CAACC,YAAY,CAACK,GAAG,GAAG,GAAG,CAACpB,UAAU,CAAC,CAAC,CAAC,CAAC;EACrD;EACA,IAAIoB,GAAG,GAAG,EAAE,EAAE;IACZ,OAAON,MAAM,CAACC,YAAY,CAACK,GAAG,GAAG,EAAE,GAAG,GAAG,CAACpB,UAAU,CAAC,CAAC,CAAC,CAAC;EAC1D;EACA,IAAIoB,GAAG,GAAG,EAAE,EAAE;IACZ,OAAON,MAAM,CAACC,YAAY,CAACK,GAAG,GAAG,EAAE,GAAG,GAAG,CAACpB,UAAU,CAAC,CAAC,CAAC,CAAC;EAC1D;EACA,IAAIoB,GAAG,KAAK,EAAE,EAAE;IACd,OAAO,GAAG;EACZ;EACA,IAAIA,GAAG,KAAK,EAAE,EAAE;IACd,OAAO,GAAG;EACZ;EAEA,OAAOjB,SAAS;AAClB"}
|
|
@@ -1,14 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { asciiToBase64, base64ToAscii } from './base64-utils';
|
|
2
|
+
export function encodeNumber(number, encoding) {
|
|
3
|
+
switch (encoding) {
|
|
4
|
+
case 'hex':
|
|
5
|
+
return convertNumberToHex(number);
|
|
6
|
+
case 'base64':
|
|
7
|
+
return convertHexToBase64(convertNumberToHex(number));
|
|
8
|
+
default:
|
|
9
|
+
throw new Error(encoding);
|
|
10
|
+
}
|
|
5
11
|
}
|
|
6
|
-
export function
|
|
12
|
+
export function encodeHex(hex, encoding) {
|
|
13
|
+
switch (encoding) {
|
|
14
|
+
case 'hex':
|
|
15
|
+
return hex;
|
|
16
|
+
case 'base64':
|
|
17
|
+
return convertHexToBase64(hex);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(encoding);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function encodeBase64(base64, encoding) {
|
|
23
|
+
switch (encoding) {
|
|
24
|
+
case 'hex':
|
|
25
|
+
return convertBase64ToHex(base64);
|
|
26
|
+
case 'base64':
|
|
27
|
+
return base64;
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(encoding);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function convertHexToBase64(hexstring) {
|
|
7
33
|
if (hexstring.length % 2 !== 0) {
|
|
8
34
|
hexstring = "0".concat(hexstring);
|
|
9
35
|
}
|
|
10
36
|
const matches = hexstring.match(/\w{2}/g) || [];
|
|
11
37
|
const string = matches.map(a => String.fromCharCode(parseInt(a, 16))).join('');
|
|
12
|
-
return
|
|
38
|
+
return asciiToBase64(string) || '';
|
|
39
|
+
}
|
|
40
|
+
function convertBase64ToHex(base64String) {
|
|
41
|
+
return [...base64ToAscii(base64String)].map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('');
|
|
42
|
+
}
|
|
43
|
+
function convertNumberToHex(cipher) {
|
|
44
|
+
const hexString = cipher.toString(16);
|
|
45
|
+
return hexString === '0' ? "0".concat(hexString) : hexString;
|
|
13
46
|
}
|
|
14
47
|
//# sourceMappingURL=digest-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-utils.js","names":["
|
|
1
|
+
{"version":3,"file":"digest-utils.js","names":["asciiToBase64","base64ToAscii","encodeNumber","number","encoding","convertNumberToHex","convertHexToBase64","Error","encodeHex","hex","encodeBase64","base64","convertBase64ToHex","hexstring","length","concat","matches","match","string","map","a","String","fromCharCode","parseInt","join","base64String","c","charCodeAt","toString","padStart","cipher","hexString"],"sources":["../../../../src/lib/utils/digest-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {asciiToBase64, base64ToAscii} from './base64-utils';\n\n/**\n * Encode a number (usually a digest from a hash function / cipher) as either hex or base64\n * Suitable for hashes like CRC32 where the number of required bits fit withing a JavaScript number.\n */\nexport function encodeNumber(number: number, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return convertNumberToHex(number);\n case 'base64':\n return convertHexToBase64(convertNumberToHex(number));\n default:\n throw new Error(encoding);\n }\n}\n\n/** Encode a hex string, aeither return hex or re-encode as base64 */\nexport function encodeHex(hex: string, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return hex;\n case 'base64':\n return convertHexToBase64(hex);\n default:\n throw new Error(encoding);\n }\n}\n\nexport function encodeBase64(base64: string, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return convertBase64ToHex(base64);\n case 'base64':\n return base64;\n default:\n throw new Error(encoding);\n }\n}\n\n/**\n * Convert a hexadecimal string to base64 encoded string representation\n */\nfunction convertHexToBase64(hexstring: string): string {\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 matches = hexstring.match(/\\w{2}/g) || [];\n const string = matches.map((a) => String.fromCharCode(parseInt(a, 16))).join('');\n // TODO - define how to handle failures\n return asciiToBase64(string) || '';\n}\n\n/**\n * Convert a base64 encoded string to hexadecimal encoded string representation\n */\nfunction convertBase64ToHex(base64String: string): string {\n return [...base64ToAscii(base64String)]\n .map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))\n .join('');\n}\n\n/**\n * Converts a number to hex\n */\nfunction convertNumberToHex(cipher: number): string {\n const hexString = cipher.toString(16);\n return hexString === '0' ? `0${hexString}` : hexString;\n}\n"],"mappings":"AAEA,SAAQA,aAAa,EAAEC,aAAa,QAAO,gBAAgB;AAM3D,OAAO,SAASC,YAAYA,CAACC,MAAc,EAAEC,QAA0B,EAAU;EAC/E,QAAQA,QAAQ;IACd,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O,CAAC,IAAKA,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CACzDL,IAAI,CAAC,EAAE,CAAC;AACb;AAKA,SAASnB,kBAAkBA,CAACyB,MAAc,EAAU;EAClD,MAAMC,SAAS,GAAGD,MAAM,CAACF,QAAQ,CAAC,EAAE,CAAC;EACrC,OAAOG,SAAS,KAAK,GAAG,OAAAhB,MAAA,CAAOgB,SAAS,IAAKA,SAAS;AACxD"}
|
|
@@ -6,15 +6,16 @@ export { CRC32Hash, CRC32CHash };
|
|
|
6
6
|
createWorker(async function (data) {
|
|
7
7
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
8
|
const {
|
|
9
|
-
operation
|
|
9
|
+
operation,
|
|
10
|
+
encoding = 'base64'
|
|
10
11
|
} = options;
|
|
11
12
|
switch (operation) {
|
|
12
13
|
case 'crc32':
|
|
13
|
-
return await new CRC32Hash(options).hash(data);
|
|
14
|
+
return await new CRC32Hash(options).hash(data, encoding);
|
|
14
15
|
case 'crc32c':
|
|
15
|
-
return await new CRC32CHash(options).hash(data);
|
|
16
|
+
return await new CRC32CHash(options).hash(data, encoding);
|
|
16
17
|
case 'md5':
|
|
17
|
-
return await new MD5Hash(options).hash(data);
|
|
18
|
+
return await new MD5Hash(options).hash(data, encoding);
|
|
18
19
|
default:
|
|
19
20
|
throw new Error("invalid option: ".concat(operation));
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","names":["createWorker","CRC32Hash","CRC32CHash","MD5Hash","data","options","arguments","length","undefined","operation","hash","Error","concat"],"sources":["../../../src/workers/worker.ts"],"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"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,SAAQC,SAAS,QAAO,mBAAmB;AAC3C,SAAQC,UAAU,QAAO,oBAAoB;AAC7C,SAAQC,OAAO,QAAO,iBAAiB;AAGvC,SAAQF,SAAS,EAAEC,UAAU;AAE7BF,YAAY,CAAC,gBAAOI,IAAI,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEpC,MAAM;IAACG;
|
|
1
|
+
{"version":3,"file":"worker.js","names":["createWorker","CRC32Hash","CRC32CHash","MD5Hash","data","options","arguments","length","undefined","operation","encoding","hash","Error","concat"],"sources":["../../../src/workers/worker.ts"],"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, encoding = 'base64'} = options;\n\n switch (operation) {\n case 'crc32':\n return await new CRC32Hash(options).hash(data, encoding);\n case 'crc32c':\n return await new CRC32CHash(options).hash(data, encoding);\n case 'md5':\n return await new MD5Hash(options).hash(data, encoding);\n default:\n throw new Error(`invalid option: ${operation}`);\n }\n});\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,SAAQC,SAAS,QAAO,mBAAmB;AAC3C,SAAQC,UAAU,QAAO,oBAAoB;AAC7C,SAAQC,OAAO,QAAO,iBAAiB;AAGvC,SAAQF,SAAS,EAAEC,UAAU;AAE7BF,YAAY,CAAC,gBAAOI,IAAI,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEpC,MAAM;IAACG,SAAS;IAAEC,QAAQ,GAAG;EAAQ,CAAC,GAAGL,OAAO;EAEhD,QAAQI,SAAS;IACf,KAAK,OAAO;MACV,OAAO,MAAM,IAAIR,SAAS,CAACI,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IAC1D,KAAK,QAAQ;MACX,OAAO,MAAM,IAAIR,UAAU,CAACG,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IAC3D,KAAK,KAAK;MACR,OAAO,MAAM,IAAIP,OAAO,CAACE,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IACxD;MACE,MAAM,IAAIE,KAAK,oBAAAC,MAAA,CAAoBJ,SAAS,CAAE,CAAC;EACnD;AACF,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export { MD5Hash } from './lib/md5-hash';
|
|
|
4
4
|
export { SHA256Hash } from './lib/sha256-hash';
|
|
5
5
|
export { CryptoHash } from './lib/crypto-hash';
|
|
6
6
|
export { NodeHash } from './lib/node-hash';
|
|
7
|
-
export { hexToBase64 as _hexToBase64, toHex as _toHex } from './lib/utils/digest-utils';
|
|
8
7
|
/**
|
|
9
8
|
* Small, fast worker for CRC32, CRC32c and MD5 Hashes
|
|
10
9
|
*/
|
|
@@ -30,4 +29,6 @@ export declare const CryptoJSWorker: {
|
|
|
30
29
|
cryptojs: {};
|
|
31
30
|
};
|
|
32
31
|
};
|
|
32
|
+
export { encodeNumber, encodeHex, encodeBase64 } from './lib/utils/digest-utils';
|
|
33
|
+
export { asciiToBase64, base64ToAscii } from './lib/utils/base64-utils';
|
|
33
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;CAQxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAC;AAIF,OAAO,EAAC,YAAY,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC"}
|
package/dist/lib/crc32-hash.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class CRC32Hash extends Hash {
|
|
|
11
11
|
* Atomic hash calculation
|
|
12
12
|
* @returns base64 encoded hash
|
|
13
13
|
*/
|
|
14
|
-
hash(input: ArrayBuffer): Promise<string>;
|
|
15
|
-
hashSync(input: ArrayBuffer): string;
|
|
16
|
-
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
14
|
+
hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
15
|
+
hashSync(input: ArrayBuffer, encoding: 'hex' | 'base64'): string;
|
|
16
|
+
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, encoding?: 'hex' | 'base64'): AsyncIterable<ArrayBuffer>;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=crc32-hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crc32-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crc32-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,qBAAa,SAAU,SAAQ,IAAI;IACjC,QAAQ,CAAC,IAAI,WAAW;IAExB,OAAO,MAAC;IACR,OAAO,CAAC,KAAK,CAAQ;gBAET,OAAO,KAAK;IAOxB;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"crc32-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crc32-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,qBAAa,SAAU,SAAQ,IAAI;IACjC,QAAQ,CAAC,IAAI,WAAW;IAExB,OAAO,MAAC;IACR,OAAO,CAAC,KAAK,CAAQ;gBAET,OAAO,KAAK;IAOxB;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3E,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM;IAMzD,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAS9B"}
|
|
@@ -15,8 +15,8 @@ export declare class CRC32CHash extends Hash {
|
|
|
15
15
|
* Atomic hash calculation
|
|
16
16
|
* @returns base64 encoded hash
|
|
17
17
|
*/
|
|
18
|
-
hash(input: ArrayBuffer): Promise<string>;
|
|
19
|
-
hashSync(input: ArrayBuffer): string;
|
|
20
|
-
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
18
|
+
hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
19
|
+
hashSync(input: ArrayBuffer, encoding: 'hex' | 'base64'): string;
|
|
20
|
+
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, encoding?: 'hex' | 'base64'): AsyncIterable<ArrayBuffer>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=crc32c-hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crc32c-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crc32c-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,qBAAa,UAAW,SAAQ,IAAI;IAClC,QAAQ,CAAC,IAAI,YAAY;IAEzB,OAAO,MAAC;IACR,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;gBACS,OAAO,KAAK;IAMxB;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"crc32c-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crc32c-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,qBAAa,UAAW,SAAQ,IAAI;IAClC,QAAQ,CAAC,IAAI,YAAY;IAEzB,OAAO,MAAC;IACR,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;gBACS,OAAO,KAAK;IAMxB;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAI3E,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM;IAQzD,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAS9B"}
|
|
@@ -25,8 +25,8 @@ export declare class CryptoHash extends Hash {
|
|
|
25
25
|
* Atomic hash calculation
|
|
26
26
|
* @returns base64 encoded hash
|
|
27
27
|
*/
|
|
28
|
-
hash(input: ArrayBuffer): Promise<string>;
|
|
29
|
-
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
28
|
+
hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
29
|
+
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, encoding?: 'hex' | 'base64'): AsyncIterable<ArrayBuffer>;
|
|
30
30
|
}
|
|
31
31
|
export {};
|
|
32
32
|
//# sourceMappingURL=crypto-hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crypto-hash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAE5B,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACrC,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAA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E,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAe9B"}
|
package/dist/lib/hash.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare abstract class Hash {
|
|
|
14
14
|
abstract readonly options: HashOptions;
|
|
15
15
|
constructor(options?: HashOptions);
|
|
16
16
|
preload(): Promise<void>;
|
|
17
|
-
abstract hash(arrayBuffer: ArrayBuffer): Promise<string>;
|
|
18
|
-
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
17
|
+
abstract hash(arrayBuffer: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
18
|
+
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, encoding?: 'hex' | 'base64'): AsyncIterable<ArrayBuffer>;
|
|
19
19
|
protected concatenate(asyncIterator: any): Promise<ArrayBuffer>;
|
|
20
20
|
}
|
|
21
21
|
export {};
|
package/dist/lib/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/lib/hash.ts"],"names":[],"mappings":"AAGA,KAAK,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;
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/lib/hash.ts"],"names":[],"mappings":"AAGA,KAAK,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,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAE7E,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;cAab,WAAW,CAAC,aAAa,KAAA,GAAG,OAAO,CAAC,WAAW,CAAC;CAGjE"}
|
package/dist/lib/md5-hash.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export declare class MD5Hash extends Hash {
|
|
|
10
10
|
* Atomic hash calculation
|
|
11
11
|
* @returns base64 encoded hash
|
|
12
12
|
*/
|
|
13
|
-
hash(input: ArrayBuffer): Promise<string>;
|
|
13
|
+
hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=md5-hash.d.ts.map
|
|
@@ -1 +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;
|
|
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,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ5E"}
|
package/dist/lib/node-hash.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export declare class NodeHash extends Hash {
|
|
|
21
21
|
* Atomic hash calculation
|
|
22
22
|
* @returns base64 encoded hash
|
|
23
23
|
*/
|
|
24
|
-
hash(input: ArrayBuffer): Promise<string>;
|
|
25
|
-
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
24
|
+
hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string>;
|
|
25
|
+
hashBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, encoding?: 'hex' | 'base64'): AsyncIterable<ArrayBuffer>;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
|
28
28
|
//# sourceMappingURL=node-hash.d.ts.map
|
|
@@ -1 +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,KAAK,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;
|
|
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,KAAK,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,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAYpE,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAa9B"}
|
|
@@ -2,5 +2,12 @@
|
|
|
2
2
|
* `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references
|
|
3
3
|
* RFC 4648.
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function asciiToBase64(string: string): string | null;
|
|
6
|
+
/**
|
|
7
|
+
* Implementation of atob() according to the HTML and Infra specs, except that
|
|
8
|
+
* instead of throwing INVALID_CHARACTER_ERR we return null.
|
|
9
|
+
*
|
|
10
|
+
* @note Forked from https://github.com/jsdom/abab under BSD 3 clause license
|
|
11
|
+
*/
|
|
12
|
+
export declare function base64ToAscii(data: string): string;
|
|
6
13
|
//# sourceMappingURL=base64-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"base64-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkC3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4ElD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Encode a number (usually a digest from a hash function / cipher) as either hex or base64
|
|
3
|
+
* Suitable for hashes like CRC32 where the number of required bits fit withing a JavaScript number.
|
|
3
4
|
*/
|
|
4
|
-
export declare function
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function hexToBase64(hexstring: string): string;
|
|
5
|
+
export declare function encodeNumber(number: number, encoding: 'hex' | 'base64'): string;
|
|
6
|
+
/** Encode a hex string, aeither return hex or re-encode as base64 */
|
|
7
|
+
export declare function encodeHex(hex: string, encoding: 'hex' | 'base64'): string;
|
|
8
|
+
export declare function encodeBase64(base64: string, encoding: 'hex' | 'base64'): string;
|
|
9
9
|
//# sourceMappingURL=digest-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/digest-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"digest-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/digest-utils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAS/E;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CASzE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAS/E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/crypto",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "Cryptographic/hashing plugins for loaders.gl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.3.1",
|
|
37
|
-
"@loaders.gl/loader-utils": "4.0.0-
|
|
38
|
-
"@loaders.gl/worker-utils": "4.0.0-
|
|
37
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.2",
|
|
38
|
+
"@loaders.gl/worker-utils": "4.0.0-beta.2",
|
|
39
39
|
"@types/crypto-js": "^4.0.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"crypto": false,
|
|
46
46
|
"sse4_crc32": false
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc"
|
|
49
49
|
}
|