@aws-sdk/sha256-tree-hash 3.485.0 → 3.495.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.
Files changed (2) hide show
  1. package/dist-cjs/index.js +120 -74
  2. package/package.json +6 -6
package/dist-cjs/index.js CHANGED
@@ -1,81 +1,127 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeHash = void 0;
4
- const MiB = 1048576;
5
- class TreeHash {
6
- constructor(Sha256, fromUtf8) {
7
- this.Sha256 = Sha256;
8
- this.fromUtf8 = fromUtf8;
9
- this.collectedHashDigests = [];
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ TreeHash: () => TreeHash
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var MiB = 1048576;
27
+ var _TreeHash = class _TreeHash {
28
+ /**
29
+ * Initializes a TreeHash.
30
+ * @param Sha256 A Sha256 hash constructor.
31
+ */
32
+ constructor(Sha256, fromUtf8) {
33
+ this.Sha256 = Sha256;
34
+ this.fromUtf8 = fromUtf8;
35
+ this.collectedHashDigests = [];
36
+ }
37
+ /**
38
+ * Generates Sha256 hashes from 1 MiB chunks of the
39
+ * internal buffer.
40
+ * Will set the internal buffer to any bytes remaining
41
+ * that is less than 1 MiB.
42
+ */
43
+ hashBuffer() {
44
+ if (!this.buffer) {
45
+ return;
10
46
  }
11
- hashBuffer() {
12
- if (!this.buffer) {
13
- return;
14
- }
15
- let remainingSize = this.buffer.byteLength;
16
- while (remainingSize >= MiB) {
17
- const hash = new this.Sha256();
18
- hash.update(this.buffer.subarray(0, MiB));
19
- this.collectedHashDigests.push(hash.digest());
20
- this.buffer = this.buffer.subarray(MiB);
21
- remainingSize = this.buffer.byteLength;
22
- }
47
+ let remainingSize = this.buffer.byteLength;
48
+ while (remainingSize >= MiB) {
49
+ const hash = new this.Sha256();
50
+ hash.update(this.buffer.subarray(0, MiB));
51
+ this.collectedHashDigests.push(hash.digest());
52
+ this.buffer = this.buffer.subarray(MiB);
53
+ remainingSize = this.buffer.byteLength;
23
54
  }
24
- update(data) {
25
- const chunk = this.convertToBuffer(data);
26
- if (!this.buffer) {
27
- this.buffer = chunk;
28
- }
29
- else {
30
- const totalSize = this.buffer.byteLength + chunk.byteLength;
31
- const tempBuffer = new Uint8Array(totalSize);
32
- tempBuffer.set(this.buffer);
33
- tempBuffer.set(chunk, this.buffer.byteLength);
34
- this.buffer = tempBuffer;
35
- }
36
- this.hashBuffer();
55
+ }
56
+ /**
57
+ * Updates the tree hash with byte data.
58
+ * @param data Byte data to apply to the tree hash.
59
+ */
60
+ update(data) {
61
+ const chunk = this.convertToBuffer(data);
62
+ if (!this.buffer) {
63
+ this.buffer = chunk;
64
+ } else {
65
+ const totalSize = this.buffer.byteLength + chunk.byteLength;
66
+ const tempBuffer = new Uint8Array(totalSize);
67
+ tempBuffer.set(this.buffer);
68
+ tempBuffer.set(chunk, this.buffer.byteLength);
69
+ this.buffer = tempBuffer;
37
70
  }
38
- async digest() {
39
- let collectedHashDigests = this.collectedHashDigests;
40
- this.collectedHashDigests = [];
41
- if (this.buffer && this.buffer.byteLength > 0) {
42
- const smallHash = new this.Sha256();
43
- smallHash.update(this.buffer);
44
- collectedHashDigests.push(smallHash.digest());
45
- this.buffer = void 0;
46
- }
47
- while (collectedHashDigests.length > 1) {
48
- const higherLevelHashDigests = [];
49
- for (let i = 0; i < collectedHashDigests.length; i += 2) {
50
- if (i + 1 < collectedHashDigests.length) {
51
- const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
52
- const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
53
- chunk.set(digest1);
54
- chunk.set(digest2, digest1.byteLength);
55
- const hash = new this.Sha256();
56
- hash.update(chunk);
57
- higherLevelHashDigests.push(hash.digest());
58
- }
59
- else {
60
- higherLevelHashDigests.push(collectedHashDigests[i]);
61
- }
62
- }
63
- collectedHashDigests = higherLevelHashDigests;
64
- }
65
- return collectedHashDigests[0];
71
+ this.hashBuffer();
72
+ }
73
+ /**
74
+ * Calculates the digest for the tree hash.
75
+ */
76
+ async digest() {
77
+ let collectedHashDigests = this.collectedHashDigests;
78
+ this.collectedHashDigests = [];
79
+ if (this.buffer && this.buffer.byteLength > 0) {
80
+ const smallHash = new this.Sha256();
81
+ smallHash.update(this.buffer);
82
+ collectedHashDigests.push(smallHash.digest());
83
+ this.buffer = void 0;
66
84
  }
67
- convertToBuffer(data) {
68
- if (typeof data === "string") {
69
- return this.fromUtf8(data);
85
+ while (collectedHashDigests.length > 1) {
86
+ const higherLevelHashDigests = [];
87
+ for (let i = 0; i < collectedHashDigests.length; i += 2) {
88
+ if (i + 1 < collectedHashDigests.length) {
89
+ const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
90
+ const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
91
+ chunk.set(digest1);
92
+ chunk.set(digest2, digest1.byteLength);
93
+ const hash = new this.Sha256();
94
+ hash.update(chunk);
95
+ higherLevelHashDigests.push(hash.digest());
96
+ } else {
97
+ higherLevelHashDigests.push(collectedHashDigests[i]);
70
98
  }
71
- if (ArrayBuffer.isView(data)) {
72
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
73
- }
74
- return new Uint8Array(data);
99
+ }
100
+ collectedHashDigests = higherLevelHashDigests;
101
+ }
102
+ return collectedHashDigests[0];
103
+ }
104
+ /**
105
+ * Converts source data into a Uint8Array.
106
+ * @param data Data to convert to a Uint8Array.
107
+ */
108
+ convertToBuffer(data) {
109
+ if (typeof data === "string") {
110
+ return this.fromUtf8(data);
75
111
  }
76
- reset() {
77
- this.buffer = undefined;
78
- this.collectedHashDigests = [];
112
+ if (ArrayBuffer.isView(data)) {
113
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
79
114
  }
80
- }
81
- exports.TreeHash = TreeHash;
115
+ return new Uint8Array(data);
116
+ }
117
+ reset() {
118
+ this.buffer = void 0;
119
+ this.collectedHashDigests = [];
120
+ }
121
+ };
122
+ __name(_TreeHash, "TreeHash");
123
+ var TreeHash = _TreeHash;
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ TreeHash
127
+ });
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@aws-sdk/sha256-tree-hash",
3
- "version": "3.485.0",
3
+ "version": "3.495.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
- "build:cjs": "tsc -p tsconfig.cjs.json",
6
+ "build:cjs": "node ../../scripts/compilation/inline sha256-tree-hash",
7
7
  "build:es": "tsc -p tsconfig.es.json",
8
8
  "build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
9
9
  "build:types": "tsc -p tsconfig.types.json",
@@ -20,14 +20,14 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@aws-sdk/types": "3.485.0",
24
- "@smithy/types": "^2.8.0",
23
+ "@aws-sdk/types": "3.495.0",
24
+ "@smithy/types": "^2.9.0",
25
25
  "tslib": "^2.5.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@aws-crypto/sha256-js": "3.0.0",
29
- "@smithy/util-hex-encoding": "^2.0.0",
30
- "@smithy/util-utf8": "^2.0.2",
29
+ "@smithy/util-hex-encoding": "^2.1.0",
30
+ "@smithy/util-utf8": "^2.1.0",
31
31
  "@tsconfig/recommended": "1.0.1",
32
32
  "concurrently": "7.0.0",
33
33
  "downlevel-dts": "0.10.1",