@loaders.gl/crypto 4.2.0-alpha.6 → 4.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crypto-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,kBAAe;AAE5B,KAAK,iBAAiB,GAAG;IACvB,OAAO,CAAC,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACtC,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;AAIF;;;GAGG;AACH,qBAAa,UAAW,SAAQ,IAAI;IAClC,QAAQ,CAAC,IAAI,MAAC;IAEd,OAAO,EAAE,iBAAiB,CAAC;IAC3B,+BAA+B;IAC/B,OAAO,CAAC,UAAU,CAAC;IACnB,yBAAyB;IACzB,OAAO,CAAC,KAAK,CAAC;gBAEF,OAAO,EAAE,iBAAiB;IAUhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAU9B;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBpE,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAqB9B"}
1
+ {"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../../src/lib/crypto-hash.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,kBAAe;AAE5B,KAAK,iBAAiB,GAAG;IACvB,OAAO,CAAC,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACtC,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,UAAW,SAAQ,IAAI;IAClC,QAAQ,CAAC,IAAI,MAAC;IAEd,OAAO,EAAE,iBAAiB,CAAC;IAC3B,+BAA+B;IAC/B,OAAO,CAAC,UAAU,CAAC;IACnB,yBAAyB;IACzB,OAAO,CAAC,KAAK,CAAC;gBAEF,OAAO,EAAE,iBAAiB;IAYhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBpE,WAAW,CAChB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,QAAQ,GAAE,KAAK,GAAG,QAAmB,GACpC,aAAa,CAAC,WAAW,CAAC;CAsB9B"}
@@ -1,5 +1,5 @@
1
+ import { getJSModule, registerJSModules } from '@loaders.gl/loader-utils';
1
2
  import { Hash } from "./hash.js";
2
- let CryptoJS;
3
3
  /**
4
4
  * A transform that calculates Cryptographic Hash using Crypto JS library
5
5
  * @deprecated Warning, experimental class
@@ -14,6 +14,7 @@ export class CryptoHash extends Hash {
14
14
  constructor(options) {
15
15
  super();
16
16
  this.options = options;
17
+ registerJSModules(options?.modules);
17
18
  this._algorithm = this.options?.crypto?.algorithm;
18
19
  if (!this._algorithm) {
19
20
  throw new Error(this.name);
@@ -21,12 +22,7 @@ export class CryptoHash extends Hash {
21
22
  this.name = this._algorithm.toLowerCase();
22
23
  }
23
24
  async preload() {
24
- if (!CryptoJS) {
25
- CryptoJS = this.options?.modules?.CryptoJS;
26
- }
27
- if (!CryptoJS) {
28
- throw new Error(this.name);
29
- }
25
+ const CryptoJS = getJSModule('CryptoJS', this.name);
30
26
  this._algo = CryptoJS.algo[this._algorithm];
31
27
  }
32
28
  /**
@@ -39,6 +35,7 @@ export class CryptoHash extends Hash {
39
35
  if (!hash) {
40
36
  throw new Error(this.name);
41
37
  }
38
+ const CryptoJS = getJSModule('CryptoJS', this.name);
42
39
  // arrayBuffer is accepted, even though types and docs say no
43
40
  // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
44
41
  const typedWordArray = CryptoJS.lib.WordArray.create(input);
@@ -48,6 +45,7 @@ export class CryptoHash extends Hash {
48
45
  }
49
46
  async *hashBatches(asyncIterator, encoding = 'base64') {
50
47
  await this.preload();
48
+ const CryptoJS = getJSModule('CryptoJS', this.name);
51
49
  const hash = this._algo.create();
52
50
  if (!hash) {
53
51
  throw new Error(this.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/crypto",
3
- "version": "4.2.0-alpha.6",
3
+ "version": "4.2.0-beta.2",
4
4
  "description": "Cryptographic/hashing plugins for loaders.gl",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,8 +46,8 @@
46
46
  "build-worker-node": "esbuild src/workers/crypto-worker-node.ts --outfile=dist/crypto-worker-node.js --platform=node --target=esnext,node16 --bundle --minify --sourcemap --define:__VERSION__=\\\"$npm_package_version\\\""
47
47
  },
48
48
  "dependencies": {
49
- "@loaders.gl/loader-utils": "4.2.0-alpha.6",
50
- "@loaders.gl/worker-utils": "4.2.0-alpha.6",
49
+ "@loaders.gl/loader-utils": "4.2.0-beta.2",
50
+ "@loaders.gl/worker-utils": "4.2.0-beta.2",
51
51
  "@types/crypto-js": "^4.0.2"
52
52
  },
53
53
  "devDependencies": {
@@ -60,5 +60,5 @@
60
60
  "peerDependencies": {
61
61
  "@loaders.gl/core": "^4.0.0"
62
62
  },
63
- "gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca"
63
+ "gitHead": "13c03663fec365a4d24c06377d50035cebd7ba9f"
64
64
  }
@@ -1,3 +1,4 @@
1
+ import {getJSModule, registerJSModules} from '@loaders.gl/loader-utils';
1
2
  import {Hash} from './hash';
2
3
 
3
4
  type CryptoHashOptions = {
@@ -8,8 +9,6 @@ type CryptoHashOptions = {
8
9
  };
9
10
  };
10
11
 
11
- let CryptoJS: any;
12
-
13
12
  /**
14
13
  * A transform that calculates Cryptographic Hash using Crypto JS library
15
14
  * @deprecated Warning, experimental class
@@ -26,6 +25,8 @@ export class CryptoHash extends Hash {
26
25
  constructor(options: CryptoHashOptions) {
27
26
  super();
28
27
  this.options = options;
28
+ registerJSModules(options?.modules);
29
+
29
30
  this._algorithm = this.options?.crypto?.algorithm;
30
31
  if (!this._algorithm) {
31
32
  throw new Error(this.name);
@@ -34,12 +35,7 @@ export class CryptoHash extends Hash {
34
35
  }
35
36
 
36
37
  async preload(): Promise<void> {
37
- if (!CryptoJS) {
38
- CryptoJS = this.options?.modules?.CryptoJS;
39
- }
40
- if (!CryptoJS) {
41
- throw new Error(this.name);
42
- }
38
+ const CryptoJS = getJSModule('CryptoJS', this.name);
43
39
  this._algo = CryptoJS.algo[this._algorithm];
44
40
  }
45
41
 
@@ -55,6 +51,7 @@ export class CryptoHash extends Hash {
55
51
  throw new Error(this.name);
56
52
  }
57
53
 
54
+ const CryptoJS = getJSModule('CryptoJS', this.name);
58
55
  // arrayBuffer is accepted, even though types and docs say no
59
56
  // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
60
57
  const typedWordArray = CryptoJS.lib.WordArray.create(input);
@@ -68,6 +65,7 @@ export class CryptoHash extends Hash {
68
65
  encoding: 'hex' | 'base64' = 'base64'
69
66
  ): AsyncIterable<ArrayBuffer> {
70
67
  await this.preload();
68
+ const CryptoJS = getJSModule('CryptoJS', this.name);
71
69
 
72
70
  const hash = this._algo.create();
73
71
  if (!hash) {