@aws-sdk/sha256-tree-hash 3.183.0 → 3.186.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/sha256-tree-hash
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
7
15
 
8
16
  **Note:** Version bump only for package @aws-sdk/sha256-tree-hash
package/dist-es/index.js CHANGED
@@ -1,67 +1,86 @@
1
- const MiB = 1048576;
2
- export class TreeHash {
3
- constructor(Sha256, fromUtf8) {
1
+ import { __awaiter, __generator, __read } from "tslib";
2
+ var MiB = 1048576;
3
+ var TreeHash = (function () {
4
+ function TreeHash(Sha256, fromUtf8) {
4
5
  this.Sha256 = Sha256;
5
6
  this.fromUtf8 = fromUtf8;
6
7
  this.collectedHashDigests = [];
7
8
  }
8
- hashBuffer() {
9
+ TreeHash.prototype.hashBuffer = function () {
9
10
  if (!this.buffer) {
10
11
  return;
11
12
  }
12
- let remainingSize = this.buffer.byteLength;
13
+ var remainingSize = this.buffer.byteLength;
13
14
  while (remainingSize >= MiB) {
14
- const hash = new this.Sha256();
15
+ var hash = new this.Sha256();
15
16
  hash.update(this.buffer.subarray(0, MiB));
16
17
  this.collectedHashDigests.push(hash.digest());
17
18
  this.buffer = this.buffer.subarray(MiB);
18
19
  remainingSize = this.buffer.byteLength;
19
20
  }
20
- }
21
- update(data) {
22
- const chunk = this.convertToBuffer(data);
21
+ };
22
+ TreeHash.prototype.update = function (data) {
23
+ var chunk = this.convertToBuffer(data);
23
24
  if (!this.buffer) {
24
25
  this.buffer = chunk;
25
26
  }
26
27
  else {
27
- const totalSize = this.buffer.byteLength + chunk.byteLength;
28
- const tempBuffer = new Uint8Array(totalSize);
28
+ var totalSize = this.buffer.byteLength + chunk.byteLength;
29
+ var tempBuffer = new Uint8Array(totalSize);
29
30
  tempBuffer.set(this.buffer);
30
31
  tempBuffer.set(chunk, this.buffer.byteLength);
31
32
  this.buffer = tempBuffer;
32
33
  }
33
34
  this.hashBuffer();
34
- }
35
- async digest() {
36
- let collectedHashDigests = this.collectedHashDigests;
37
- this.collectedHashDigests = [];
38
- if (this.buffer && this.buffer.byteLength > 0) {
39
- const smallHash = new this.Sha256();
40
- smallHash.update(this.buffer);
41
- collectedHashDigests.push(smallHash.digest());
42
- this.buffer = void 0;
43
- }
44
- while (collectedHashDigests.length > 1) {
45
- const higherLevelHashDigests = [];
46
- for (let i = 0; i < collectedHashDigests.length; i += 2) {
47
- if (i + 1 < collectedHashDigests.length) {
48
- const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
49
- const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
50
- chunk.set(digest1);
51
- chunk.set(digest2, digest1.byteLength);
52
- const hash = new this.Sha256();
53
- hash.update(chunk);
54
- higherLevelHashDigests.push(hash.digest());
35
+ };
36
+ TreeHash.prototype.digest = function () {
37
+ return __awaiter(this, void 0, void 0, function () {
38
+ var collectedHashDigests, smallHash, higherLevelHashDigests, i, _a, digest1, digest2, chunk, hash;
39
+ return __generator(this, function (_b) {
40
+ switch (_b.label) {
41
+ case 0:
42
+ collectedHashDigests = this.collectedHashDigests;
43
+ this.collectedHashDigests = [];
44
+ if (this.buffer && this.buffer.byteLength > 0) {
45
+ smallHash = new this.Sha256();
46
+ smallHash.update(this.buffer);
47
+ collectedHashDigests.push(smallHash.digest());
48
+ this.buffer = void 0;
49
+ }
50
+ _b.label = 1;
51
+ case 1:
52
+ if (!(collectedHashDigests.length > 1)) return [3, 7];
53
+ higherLevelHashDigests = [];
54
+ i = 0;
55
+ _b.label = 2;
56
+ case 2:
57
+ if (!(i < collectedHashDigests.length)) return [3, 6];
58
+ if (!(i + 1 < collectedHashDigests.length)) return [3, 4];
59
+ return [4, Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]])];
60
+ case 3:
61
+ _a = __read.apply(void 0, [_b.sent(), 2]), digest1 = _a[0], digest2 = _a[1];
62
+ chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
63
+ chunk.set(digest1);
64
+ chunk.set(digest2, digest1.byteLength);
65
+ hash = new this.Sha256();
66
+ hash.update(chunk);
67
+ higherLevelHashDigests.push(hash.digest());
68
+ return [3, 5];
69
+ case 4:
70
+ higherLevelHashDigests.push(collectedHashDigests[i]);
71
+ _b.label = 5;
72
+ case 5:
73
+ i += 2;
74
+ return [3, 2];
75
+ case 6:
76
+ collectedHashDigests = higherLevelHashDigests;
77
+ return [3, 1];
78
+ case 7: return [2, collectedHashDigests[0]];
55
79
  }
56
- else {
57
- higherLevelHashDigests.push(collectedHashDigests[i]);
58
- }
59
- }
60
- collectedHashDigests = higherLevelHashDigests;
61
- }
62
- return collectedHashDigests[0];
63
- }
64
- convertToBuffer(data) {
80
+ });
81
+ });
82
+ };
83
+ TreeHash.prototype.convertToBuffer = function (data) {
65
84
  if (typeof data === "string") {
66
85
  return this.fromUtf8(data);
67
86
  }
@@ -69,5 +88,7 @@ export class TreeHash {
69
88
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
70
89
  }
71
90
  return new Uint8Array(data);
72
- }
73
- }
91
+ };
92
+ return TreeHash;
93
+ }());
94
+ export { TreeHash };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/sha256-tree-hash",
3
- "version": "3.183.0",
3
+ "version": "3.186.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -20,13 +20,13 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@aws-sdk/types": "3.183.0",
23
+ "@aws-sdk/types": "3.186.0",
24
24
  "tslib": "^2.3.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@aws-crypto/sha256-js": "2.0.0",
28
- "@aws-sdk/util-hex-encoding": "3.183.0",
29
- "@aws-sdk/util-utf8-node": "3.183.0",
28
+ "@aws-sdk/util-hex-encoding": "3.186.0",
29
+ "@aws-sdk/util-utf8-node": "3.186.0",
30
30
  "@tsconfig/recommended": "1.0.1",
31
31
  "concurrently": "7.0.0",
32
32
  "downlevel-dts": "0.10.1",