@aws-sdk/sha256-tree-hash 3.186.0 → 3.190.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,22 @@
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.190.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.189.0...v3.190.0) (2022-10-17)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/sha256-tree-hash
9
+
10
+
11
+
12
+
13
+
14
+ # [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
15
+
16
+ **Note:** Version bump only for package @aws-sdk/sha256-tree-hash
17
+
18
+
19
+
20
+
21
+
6
22
  # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
23
 
8
24
  **Note:** Version bump only for package @aws-sdk/sha256-tree-hash
package/dist-es/index.js CHANGED
@@ -1,86 +1,67 @@
1
- import { __awaiter, __generator, __read } from "tslib";
2
- var MiB = 1048576;
3
- var TreeHash = (function () {
4
- function TreeHash(Sha256, fromUtf8) {
1
+ const MiB = 1048576;
2
+ export class TreeHash {
3
+ constructor(Sha256, fromUtf8) {
5
4
  this.Sha256 = Sha256;
6
5
  this.fromUtf8 = fromUtf8;
7
6
  this.collectedHashDigests = [];
8
7
  }
9
- TreeHash.prototype.hashBuffer = function () {
8
+ hashBuffer() {
10
9
  if (!this.buffer) {
11
10
  return;
12
11
  }
13
- var remainingSize = this.buffer.byteLength;
12
+ let remainingSize = this.buffer.byteLength;
14
13
  while (remainingSize >= MiB) {
15
- var hash = new this.Sha256();
14
+ const hash = new this.Sha256();
16
15
  hash.update(this.buffer.subarray(0, MiB));
17
16
  this.collectedHashDigests.push(hash.digest());
18
17
  this.buffer = this.buffer.subarray(MiB);
19
18
  remainingSize = this.buffer.byteLength;
20
19
  }
21
- };
22
- TreeHash.prototype.update = function (data) {
23
- var chunk = this.convertToBuffer(data);
20
+ }
21
+ update(data) {
22
+ const chunk = this.convertToBuffer(data);
24
23
  if (!this.buffer) {
25
24
  this.buffer = chunk;
26
25
  }
27
26
  else {
28
- var totalSize = this.buffer.byteLength + chunk.byteLength;
29
- var tempBuffer = new Uint8Array(totalSize);
27
+ const totalSize = this.buffer.byteLength + chunk.byteLength;
28
+ const tempBuffer = new Uint8Array(totalSize);
30
29
  tempBuffer.set(this.buffer);
31
30
  tempBuffer.set(chunk, this.buffer.byteLength);
32
31
  this.buffer = tempBuffer;
33
32
  }
34
33
  this.hashBuffer();
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]];
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());
79
55
  }
80
- });
81
- });
82
- };
83
- TreeHash.prototype.convertToBuffer = function (data) {
56
+ else {
57
+ higherLevelHashDigests.push(collectedHashDigests[i]);
58
+ }
59
+ }
60
+ collectedHashDigests = higherLevelHashDigests;
61
+ }
62
+ return collectedHashDigests[0];
63
+ }
64
+ convertToBuffer(data) {
84
65
  if (typeof data === "string") {
85
66
  return this.fromUtf8(data);
86
67
  }
@@ -88,7 +69,5 @@ var TreeHash = (function () {
88
69
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
89
70
  }
90
71
  return new Uint8Array(data);
91
- };
92
- return TreeHash;
93
- }());
94
- export { TreeHash };
72
+ }
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/sha256-tree-hash",
3
- "version": "3.186.0",
3
+ "version": "3.190.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.186.0",
23
+ "@aws-sdk/types": "3.190.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.186.0",
29
- "@aws-sdk/util-utf8-node": "3.186.0",
28
+ "@aws-sdk/util-hex-encoding": "3.188.0",
29
+ "@aws-sdk/util-utf8-node": "3.188.0",
30
30
  "@tsconfig/recommended": "1.0.1",
31
31
  "concurrently": "7.0.0",
32
32
  "downlevel-dts": "0.10.1",