@loaders.gl/crypto 3.1.0-alpha.4 → 3.1.0-beta.3
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 +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/dist.min.js +2 -2
- package/dist/dist.min.js.map +7 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +11 -11
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32.js +20 -26
- package/dist/es5/lib/algorithms/crc32.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32c.js +21 -27
- package/dist/es5/lib/algorithms/crc32c.js.map +1 -1
- package/dist/es5/lib/algorithms/md5-wasm.js +25 -36
- package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/es5/lib/crc32-hash.js +39 -185
- package/dist/es5/lib/crc32-hash.js.map +1 -1
- package/dist/es5/lib/crc32c-hash.js +38 -184
- package/dist/es5/lib/crc32c-hash.js.map +1 -1
- package/dist/es5/lib/crypto-hash.js +49 -225
- package/dist/es5/lib/crypto-hash.js.map +1 -1
- package/dist/es5/lib/hash.js +21 -175
- package/dist/es5/lib/hash.js.map +1 -1
- package/dist/es5/lib/md5-hash.js +13 -71
- package/dist/es5/lib/md5-hash.js.map +1 -1
- package/dist/es5/lib/node-hash.js +33 -181
- package/dist/es5/lib/node-hash.js.map +1 -1
- package/dist/es5/lib/sha256-hash.js +7 -33
- package/dist/es5/lib/sha256-hash.js.map +1 -1
- package/dist/es5/lib/utils/base64-utils.js +13 -13
- package/dist/es5/lib/utils/base64-utils.js.map +1 -1
- package/dist/es5/lib/utils/digest-utils.js +4 -5
- package/dist/es5/lib/utils/digest-utils.js.map +1 -1
- package/dist/es5/workers/worker.js +17 -55
- package/dist/es5/workers/worker.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/crc32.js +3 -0
- package/dist/esm/lib/algorithms/crc32.js.map +1 -1
- package/dist/esm/lib/algorithms/crc32c.js +5 -0
- package/dist/esm/lib/algorithms/crc32c.js.map +1 -1
- package/dist/esm/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/esm/lib/md5-hash.js.map +1 -1
- package/dist/esm/lib/utils/base64-utils.js +1 -1
- package/dist/esm/lib/utils/base64-utils.js.map +1 -1
- package/dist/esm/lib/utils/digest-utils.js +5 -4
- package/dist/esm/lib/utils/digest-utils.js.map +1 -1
- package/dist/esm/workers/worker.js +1 -1
- package/dist/esm/workers/worker.js.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/lib/algorithms/crc32.d.ts +10 -0
- package/dist/lib/algorithms/crc32.d.ts.map +1 -0
- package/dist/lib/algorithms/crc32.js +30 -0
- package/dist/lib/algorithms/crc32c.d.ts +11 -0
- package/dist/lib/algorithms/crc32c.d.ts.map +1 -0
- package/dist/lib/algorithms/crc32c.js +38 -0
- package/dist/lib/algorithms/md5-wasm.d.ts +2 -0
- package/dist/lib/algorithms/md5-wasm.d.ts.map +1 -0
- package/dist/lib/algorithms/md5-wasm.js +435 -0
- package/dist/lib/crc32-hash.d.ts +18 -0
- package/dist/lib/crc32-hash.d.ts.map +1 -0
- package/dist/lib/crc32-hash.js +47 -0
- package/dist/lib/crc32c-hash.d.ts +22 -0
- package/dist/lib/crc32c-hash.d.ts.map +1 -0
- package/dist/lib/crc32c-hash.js +51 -0
- package/dist/lib/crypto-hash.d.ts +32 -0
- package/dist/lib/crypto-hash.d.ts.map +1 -0
- package/dist/lib/crypto-hash.js +61 -0
- package/dist/lib/hash.d.ts +22 -0
- package/dist/lib/hash.d.ts.map +1 -0
- package/dist/lib/hash.js +29 -0
- package/dist/lib/md5-hash.d.ts +15 -0
- package/dist/lib/md5-hash.d.ts.map +1 -0
- package/dist/lib/md5-hash.js +32 -0
- package/dist/lib/node-hash.d.ts +28 -0
- package/dist/lib/node-hash.d.ts.map +1 -0
- package/dist/lib/node-hash.js +42 -0
- package/dist/lib/sha256-hash.d.ts +19 -0
- package/dist/lib/sha256-hash.d.ts.map +1 -0
- package/dist/lib/sha256-hash.js +14 -0
- package/dist/lib/utils/base64-utils.d.ts +6 -0
- package/dist/lib/utils/base64-utils.d.ts.map +1 -0
- package/dist/lib/utils/base64-utils.js +67 -0
- package/dist/lib/utils/digest-utils.d.ts +9 -0
- package/dist/lib/utils/digest-utils.d.ts.map +1 -0
- package/dist/lib/utils/digest-utils.js +27 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/worker.js +2 -5069
- package/dist/worker.js.map +7 -1
- package/dist/workers/worker.d.ts +4 -0
- package/dist/workers/worker.d.ts.map +1 -0
- package/dist/workers/worker.js +23 -0
- package/package.json +7 -7
- package/src/lib/algorithms/{crc32.js → crc32.ts} +2 -0
- package/src/lib/algorithms/{crc32c.js → crc32c.ts} +3 -0
- package/src/lib/algorithms/{md5-wasm.js → md5-wasm.ts} +2 -2
- package/src/lib/md5-hash.ts +1 -0
- package/src/lib/utils/{base64-utils.js → base64-utils.ts} +3 -2
- package/src/lib/utils/digest-utils.ts +24 -0
- package/dist/es5/lib/utils/base64-utils.d.ts +0 -5
- package/dist/es5/lib/utils/digest-utils.d.ts +0 -6
- package/dist/esm/lib/utils/base64-utils.d.ts +0 -5
- package/dist/esm/lib/utils/digest-utils.d.ts +0 -6
- package/src/lib/utils/base64-utils.d.ts +0 -5
- package/src/lib/utils/digest-utils.d.ts +0 -6
- package/src/lib/utils/digest-utils.js +0 -25
package/dist/es5/lib/hash.js
CHANGED
|
@@ -7,197 +7,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.Hash = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
11
|
|
|
20
|
-
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
21
|
-
|
|
22
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
23
|
-
|
|
24
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
25
|
-
|
|
26
12
|
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
27
13
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
-
(0, _classCallCheck2.default)(this, Hash);
|
|
14
|
+
class Hash {
|
|
15
|
+
constructor(options = {}) {
|
|
32
16
|
(0, _defineProperty2.default)(this, "name", void 0);
|
|
33
17
|
(0, _defineProperty2.default)(this, "options", void 0);
|
|
34
18
|
this.hashBatches = this.hashBatches.bind(this);
|
|
35
19
|
}
|
|
36
20
|
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var _preload = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
41
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
42
|
-
while (1) {
|
|
43
|
-
switch (_context.prev = _context.next) {
|
|
44
|
-
case 0:
|
|
45
|
-
return _context.abrupt("return");
|
|
46
|
-
|
|
47
|
-
case 1:
|
|
48
|
-
case "end":
|
|
49
|
-
return _context.stop();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}, _callee);
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
function preload() {
|
|
56
|
-
return _preload.apply(this, arguments);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return preload;
|
|
60
|
-
}()
|
|
61
|
-
}, {
|
|
62
|
-
key: "hashBatches",
|
|
63
|
-
value: function hashBatches(asyncIterator) {
|
|
64
|
-
var _this = this;
|
|
65
|
-
|
|
66
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee2() {
|
|
67
|
-
var _this$options, _this$options$crypto, _this$options$crypto$;
|
|
68
|
-
|
|
69
|
-
var arrayBuffers, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _arrayBuffer, output, hash;
|
|
70
|
-
|
|
71
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
72
|
-
while (1) {
|
|
73
|
-
switch (_context2.prev = _context2.next) {
|
|
74
|
-
case 0:
|
|
75
|
-
arrayBuffers = [];
|
|
76
|
-
_iteratorNormalCompletion = true;
|
|
77
|
-
_didIteratorError = false;
|
|
78
|
-
_context2.prev = 3;
|
|
79
|
-
_iterator = (0, _asyncIterator2.default)(asyncIterator);
|
|
80
|
-
|
|
81
|
-
case 5:
|
|
82
|
-
_context2.next = 7;
|
|
83
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
84
|
-
|
|
85
|
-
case 7:
|
|
86
|
-
_step = _context2.sent;
|
|
87
|
-
_iteratorNormalCompletion = _step.done;
|
|
88
|
-
_context2.next = 11;
|
|
89
|
-
return (0, _awaitAsyncGenerator2.default)(_step.value);
|
|
90
|
-
|
|
91
|
-
case 11:
|
|
92
|
-
_value = _context2.sent;
|
|
93
|
-
|
|
94
|
-
if (_iteratorNormalCompletion) {
|
|
95
|
-
_context2.next = 20;
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
_arrayBuffer = _value;
|
|
100
|
-
arrayBuffers.push(_arrayBuffer);
|
|
101
|
-
_context2.next = 17;
|
|
102
|
-
return _arrayBuffer;
|
|
103
|
-
|
|
104
|
-
case 17:
|
|
105
|
-
_iteratorNormalCompletion = true;
|
|
106
|
-
_context2.next = 5;
|
|
107
|
-
break;
|
|
108
|
-
|
|
109
|
-
case 20:
|
|
110
|
-
_context2.next = 26;
|
|
111
|
-
break;
|
|
112
|
-
|
|
113
|
-
case 22:
|
|
114
|
-
_context2.prev = 22;
|
|
115
|
-
_context2.t0 = _context2["catch"](3);
|
|
116
|
-
_didIteratorError = true;
|
|
117
|
-
_iteratorError = _context2.t0;
|
|
118
|
-
|
|
119
|
-
case 26:
|
|
120
|
-
_context2.prev = 26;
|
|
121
|
-
_context2.prev = 27;
|
|
122
|
-
|
|
123
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
124
|
-
_context2.next = 31;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_context2.next = 31;
|
|
129
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
130
|
-
|
|
131
|
-
case 31:
|
|
132
|
-
_context2.prev = 31;
|
|
133
|
-
|
|
134
|
-
if (!_didIteratorError) {
|
|
135
|
-
_context2.next = 34;
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
throw _iteratorError;
|
|
140
|
-
|
|
141
|
-
case 34:
|
|
142
|
-
return _context2.finish(31);
|
|
143
|
-
|
|
144
|
-
case 35:
|
|
145
|
-
return _context2.finish(26);
|
|
146
|
-
|
|
147
|
-
case 36:
|
|
148
|
-
_context2.next = 38;
|
|
149
|
-
return (0, _awaitAsyncGenerator2.default)(_this.concatenate(arrayBuffers));
|
|
21
|
+
async preload() {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
150
24
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
_context2.next = 41;
|
|
154
|
-
return (0, _awaitAsyncGenerator2.default)(_this.hash(output));
|
|
25
|
+
async *hashBatches(asyncIterator) {
|
|
26
|
+
var _this$options, _this$options$crypto, _this$options$crypto$;
|
|
155
27
|
|
|
156
|
-
|
|
157
|
-
hash = _context2.sent;
|
|
158
|
-
(_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, {
|
|
159
|
-
hash: hash
|
|
160
|
-
});
|
|
28
|
+
const arrayBuffers = [];
|
|
161
29
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}, _callee2, null, [[3, 22, 26, 36], [27,, 31, 35]]);
|
|
168
|
-
}))();
|
|
30
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
31
|
+
arrayBuffers.push(arrayBuffer);
|
|
32
|
+
yield arrayBuffer;
|
|
169
33
|
}
|
|
170
|
-
}, {
|
|
171
|
-
key: "concatenate",
|
|
172
|
-
value: function () {
|
|
173
|
-
var _concatenate = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(asyncIterator) {
|
|
174
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
175
|
-
while (1) {
|
|
176
|
-
switch (_context3.prev = _context3.next) {
|
|
177
|
-
case 0:
|
|
178
|
-
_context3.next = 2;
|
|
179
|
-
return (0, _loaderUtils.concatenateArrayBuffersAsync)(asyncIterator);
|
|
180
|
-
|
|
181
|
-
case 2:
|
|
182
|
-
return _context3.abrupt("return", _context3.sent);
|
|
183
34
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}));
|
|
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
|
+
}
|
|
191
41
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
42
|
+
async concatenate(asyncIterator) {
|
|
43
|
+
return await (0, _loaderUtils.concatenateArrayBuffersAsync)(asyncIterator);
|
|
44
|
+
}
|
|
195
45
|
|
|
196
|
-
|
|
197
|
-
}()
|
|
198
|
-
}]);
|
|
199
|
-
return Hash;
|
|
200
|
-
}();
|
|
46
|
+
}
|
|
201
47
|
|
|
202
48
|
exports.Hash = Hash;
|
|
203
49
|
//# sourceMappingURL=hash.js.map
|
package/dist/es5/lib/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/hash.ts"],"names":["Hash","options","hashBatches","bind","asyncIterator","arrayBuffers","arrayBuffer","push","
|
|
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"}
|
package/dist/es5/lib/md5-hash.js
CHANGED
|
@@ -7,87 +7,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.MD5Hash = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
11
|
|
|
28
|
-
var
|
|
12
|
+
var _hash = require("./hash");
|
|
29
13
|
|
|
30
14
|
var _md5Wasm = _interopRequireDefault(require("./algorithms/md5-wasm"));
|
|
31
15
|
|
|
32
16
|
var _digestUtils = require("./utils/digest-utils");
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _super = _createSuper(MD5Hash);
|
|
42
|
-
|
|
43
|
-
function MD5Hash() {
|
|
44
|
-
var _this;
|
|
45
|
-
|
|
46
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
47
|
-
(0, _classCallCheck2.default)(this, MD5Hash);
|
|
48
|
-
_this = _super.call(this);
|
|
49
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", 'md5');
|
|
50
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "options", void 0);
|
|
51
|
-
_this.options = options;
|
|
52
|
-
return _this;
|
|
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;
|
|
53
24
|
}
|
|
54
25
|
|
|
55
|
-
(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
61
|
-
while (1) {
|
|
62
|
-
switch (_context.prev = _context.next) {
|
|
63
|
-
case 0:
|
|
64
|
-
md5Promise = new Promise(function (resolve, reject) {
|
|
65
|
-
return (0, _md5Wasm.default)(input).then(resolve).catch(reject);
|
|
66
|
-
});
|
|
67
|
-
_context.next = 3;
|
|
68
|
-
return md5Promise;
|
|
69
|
-
|
|
70
|
-
case 3:
|
|
71
|
-
hex = _context.sent;
|
|
72
|
-
return _context.abrupt("return", (0, _digestUtils.hexToBase64)(hex));
|
|
73
|
-
|
|
74
|
-
case 5:
|
|
75
|
-
case "end":
|
|
76
|
-
return _context.stop();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, _callee);
|
|
80
|
-
}));
|
|
81
|
-
|
|
82
|
-
function hash(_x) {
|
|
83
|
-
return _hash.apply(this, arguments);
|
|
84
|
-
}
|
|
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
|
+
}
|
|
85
31
|
|
|
86
|
-
|
|
87
|
-
}()
|
|
88
|
-
}]);
|
|
89
|
-
return MD5Hash;
|
|
90
|
-
}(_hash2.Hash);
|
|
32
|
+
}
|
|
91
33
|
|
|
92
34
|
exports.MD5Hash = MD5Hash;
|
|
93
35
|
//# sourceMappingURL=md5-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/md5-hash.ts"],"names":["MD5Hash","options","input","md5Promise","Promise","resolve","reject","then","catch","hex"
|
|
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,KAErC,sBAAQJ,KAAR,EAAeK,IAAf,CAAoBF,OAApB,EAA6BG,KAA7B,CAAmCF,MAAnC,CAFiB,CAAnB;AAIA,UAAMG,GAAG,GAAG,MAAMN,UAAlB;AACA,WAAO,8BAAYM,GAAZ,CAAP;AACD;;AApB+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 // @ts-expect-error\n md5WASM(input).then(resolve).catch(reject)\n );\n const hex = await md5Promise;\n return hexToBase64(hex);\n }\n}\n"],"file":"md5-hash.js"}
|
|
@@ -7,203 +7,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.NodeHash = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
11
|
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
31
|
-
|
|
32
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
33
|
-
|
|
34
|
-
var _hash2 = require("./hash");
|
|
12
|
+
var _hash = require("./hash");
|
|
35
13
|
|
|
36
14
|
var _crypto = require("crypto");
|
|
37
15
|
|
|
38
|
-
|
|
16
|
+
class NodeHash extends _hash.Hash {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _this$options, _this$options$crypto;
|
|
39
19
|
|
|
40
|
-
|
|
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;
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|
|
44
31
|
|
|
45
|
-
|
|
32
|
+
async hash(input) {
|
|
33
|
+
var _this$options2, _this$options2$crypto, _this$options2$crypto2;
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
async *hashBatches(asyncIterator) {
|
|
42
|
+
var _this$options3, _this$options3$crypto, _this$options3$crypto2, _this$options4, _this$options4$crypto, _this$options4$crypto2;
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "name", 'crypto-node');
|
|
55
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "options", void 0);
|
|
56
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "_algorithm", void 0);
|
|
57
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "_hash", void 0);
|
|
58
|
-
_this2.options = options;
|
|
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());
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
for await (const chunk of asyncIterator) {
|
|
48
|
+
const inputArray = new Uint8Array(chunk);
|
|
49
|
+
hash.update(inputArray);
|
|
50
|
+
yield chunk;
|
|
62
51
|
}
|
|
63
52
|
|
|
64
|
-
|
|
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
|
+
});
|
|
65
56
|
}
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
key: "hash",
|
|
69
|
-
value: function () {
|
|
70
|
-
var _hash = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(input) {
|
|
71
|
-
var _this$options, _this$options$crypto, _this$options$crypto$;
|
|
72
|
-
|
|
73
|
-
var hash, inputArray;
|
|
74
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
75
|
-
while (1) {
|
|
76
|
-
switch (_context.prev = _context.next) {
|
|
77
|
-
case 0:
|
|
78
|
-
_context.next = 2;
|
|
79
|
-
return this.preload();
|
|
80
|
-
|
|
81
|
-
case 2:
|
|
82
|
-
hash = (0, _crypto.createHash)((_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.algorithm) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.toLowerCase());
|
|
83
|
-
inputArray = new Uint8Array(input);
|
|
84
|
-
return _context.abrupt("return", hash.update(inputArray).digest('base64'));
|
|
85
|
-
|
|
86
|
-
case 5:
|
|
87
|
-
case "end":
|
|
88
|
-
return _context.stop();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}, _callee, this);
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
function hash(_x) {
|
|
95
|
-
return _hash.apply(this, arguments);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return hash;
|
|
99
|
-
}()
|
|
100
|
-
}, {
|
|
101
|
-
key: "hashBatches",
|
|
102
|
-
value: function hashBatches(asyncIterator) {
|
|
103
|
-
var _this = this;
|
|
104
|
-
|
|
105
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee2() {
|
|
106
|
-
var _this$options2, _this$options2$crypto, _this$options2$crypto2, _this$options3, _this$options3$crypto, _this$options3$crypto2;
|
|
107
|
-
|
|
108
|
-
var hash, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, inputArray;
|
|
109
|
-
|
|
110
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
111
|
-
while (1) {
|
|
112
|
-
switch (_context2.prev = _context2.next) {
|
|
113
|
-
case 0:
|
|
114
|
-
_context2.next = 2;
|
|
115
|
-
return (0, _awaitAsyncGenerator2.default)(_this.preload());
|
|
116
|
-
|
|
117
|
-
case 2:
|
|
118
|
-
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());
|
|
119
|
-
_iteratorNormalCompletion = true;
|
|
120
|
-
_didIteratorError = false;
|
|
121
|
-
_context2.prev = 5;
|
|
122
|
-
_iterator = (0, _asyncIterator2.default)(asyncIterator);
|
|
123
|
-
|
|
124
|
-
case 7:
|
|
125
|
-
_context2.next = 9;
|
|
126
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
127
|
-
|
|
128
|
-
case 9:
|
|
129
|
-
_step = _context2.sent;
|
|
130
|
-
_iteratorNormalCompletion = _step.done;
|
|
131
|
-
_context2.next = 13;
|
|
132
|
-
return (0, _awaitAsyncGenerator2.default)(_step.value);
|
|
133
|
-
|
|
134
|
-
case 13:
|
|
135
|
-
_value = _context2.sent;
|
|
136
|
-
|
|
137
|
-
if (_iteratorNormalCompletion) {
|
|
138
|
-
_context2.next = 23;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
chunk = _value;
|
|
143
|
-
inputArray = new Uint8Array(chunk);
|
|
144
|
-
hash.update(inputArray);
|
|
145
|
-
_context2.next = 20;
|
|
146
|
-
return chunk;
|
|
147
|
-
|
|
148
|
-
case 20:
|
|
149
|
-
_iteratorNormalCompletion = true;
|
|
150
|
-
_context2.next = 7;
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
case 23:
|
|
154
|
-
_context2.next = 29;
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
case 25:
|
|
158
|
-
_context2.prev = 25;
|
|
159
|
-
_context2.t0 = _context2["catch"](5);
|
|
160
|
-
_didIteratorError = true;
|
|
161
|
-
_iteratorError = _context2.t0;
|
|
162
|
-
|
|
163
|
-
case 29:
|
|
164
|
-
_context2.prev = 29;
|
|
165
|
-
_context2.prev = 30;
|
|
166
|
-
|
|
167
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
168
|
-
_context2.next = 34;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
_context2.next = 34;
|
|
173
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
174
|
-
|
|
175
|
-
case 34:
|
|
176
|
-
_context2.prev = 34;
|
|
177
|
-
|
|
178
|
-
if (!_didIteratorError) {
|
|
179
|
-
_context2.next = 37;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
throw _iteratorError;
|
|
184
|
-
|
|
185
|
-
case 37:
|
|
186
|
-
return _context2.finish(34);
|
|
187
|
-
|
|
188
|
-
case 38:
|
|
189
|
-
return _context2.finish(29);
|
|
190
|
-
|
|
191
|
-
case 39:
|
|
192
|
-
(_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, {
|
|
193
|
-
hash: hash.digest('base64')
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
case 40:
|
|
197
|
-
case "end":
|
|
198
|
-
return _context2.stop();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}, _callee2, null, [[5, 25, 29, 39], [30,, 34, 38]]);
|
|
202
|
-
}))();
|
|
203
|
-
}
|
|
204
|
-
}]);
|
|
205
|
-
return NodeHash;
|
|
206
|
-
}(_hash2.Hash);
|
|
58
|
+
}
|
|
207
59
|
|
|
208
60
|
exports.NodeHash = NodeHash;
|
|
209
61
|
//# sourceMappingURL=node-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/node-hash.ts"],"names":["NodeHash","options","crypto","algorithm","Error","name","
|
|
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"}
|