Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-sdk/sha256-tree-hash

Package Overview
Dependencies
Maintainers
5
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/sha256-tree-hash - npm Package Compare versions

Comparing version 3.183.0 to 3.186.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
**Note:** Version bump only for package @aws-sdk/sha256-tree-hash
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)

@@ -8,0 +16,0 @@

107

dist-es/index.js

@@ -1,4 +0,5 @@

const MiB = 1048576;
export class TreeHash {
constructor(Sha256, fromUtf8) {
import { __awaiter, __generator, __read } from "tslib";
var MiB = 1048576;
var TreeHash = (function () {
function TreeHash(Sha256, fromUtf8) {
this.Sha256 = Sha256;

@@ -8,9 +9,9 @@ this.fromUtf8 = fromUtf8;

}
hashBuffer() {
TreeHash.prototype.hashBuffer = function () {
if (!this.buffer) {
return;
}
let remainingSize = this.buffer.byteLength;
var remainingSize = this.buffer.byteLength;
while (remainingSize >= MiB) {
const hash = new this.Sha256();
var hash = new this.Sha256();
hash.update(this.buffer.subarray(0, MiB));

@@ -21,5 +22,5 @@ this.collectedHashDigests.push(hash.digest());

}
}
update(data) {
const chunk = this.convertToBuffer(data);
};
TreeHash.prototype.update = function (data) {
var chunk = this.convertToBuffer(data);
if (!this.buffer) {

@@ -29,4 +30,4 @@ this.buffer = chunk;

else {
const totalSize = this.buffer.byteLength + chunk.byteLength;
const tempBuffer = new Uint8Array(totalSize);
var totalSize = this.buffer.byteLength + chunk.byteLength;
var tempBuffer = new Uint8Array(totalSize);
tempBuffer.set(this.buffer);

@@ -37,33 +38,51 @@ tempBuffer.set(chunk, this.buffer.byteLength);

this.hashBuffer();
}
async digest() {
let collectedHashDigests = this.collectedHashDigests;
this.collectedHashDigests = [];
if (this.buffer && this.buffer.byteLength > 0) {
const smallHash = new this.Sha256();
smallHash.update(this.buffer);
collectedHashDigests.push(smallHash.digest());
this.buffer = void 0;
}
while (collectedHashDigests.length > 1) {
const higherLevelHashDigests = [];
for (let i = 0; i < collectedHashDigests.length; i += 2) {
if (i + 1 < collectedHashDigests.length) {
const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
chunk.set(digest1);
chunk.set(digest2, digest1.byteLength);
const hash = new this.Sha256();
hash.update(chunk);
higherLevelHashDigests.push(hash.digest());
};
TreeHash.prototype.digest = function () {
return __awaiter(this, void 0, void 0, function () {
var collectedHashDigests, smallHash, higherLevelHashDigests, i, _a, digest1, digest2, chunk, hash;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
collectedHashDigests = this.collectedHashDigests;
this.collectedHashDigests = [];
if (this.buffer && this.buffer.byteLength > 0) {
smallHash = new this.Sha256();
smallHash.update(this.buffer);
collectedHashDigests.push(smallHash.digest());
this.buffer = void 0;
}
_b.label = 1;
case 1:
if (!(collectedHashDigests.length > 1)) return [3, 7];
higherLevelHashDigests = [];
i = 0;
_b.label = 2;
case 2:
if (!(i < collectedHashDigests.length)) return [3, 6];
if (!(i + 1 < collectedHashDigests.length)) return [3, 4];
return [4, Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]])];
case 3:
_a = __read.apply(void 0, [_b.sent(), 2]), digest1 = _a[0], digest2 = _a[1];
chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
chunk.set(digest1);
chunk.set(digest2, digest1.byteLength);
hash = new this.Sha256();
hash.update(chunk);
higherLevelHashDigests.push(hash.digest());
return [3, 5];
case 4:
higherLevelHashDigests.push(collectedHashDigests[i]);
_b.label = 5;
case 5:
i += 2;
return [3, 2];
case 6:
collectedHashDigests = higherLevelHashDigests;
return [3, 1];
case 7: return [2, collectedHashDigests[0]];
}
else {
higherLevelHashDigests.push(collectedHashDigests[i]);
}
}
collectedHashDigests = higherLevelHashDigests;
}
return collectedHashDigests[0];
}
convertToBuffer(data) {
});
});
};
TreeHash.prototype.convertToBuffer = function (data) {
if (typeof data === "string") {

@@ -76,3 +95,5 @@ return this.fromUtf8(data);

return new Uint8Array(data);
}
}
};
return TreeHash;
}());
export { TreeHash };
{
"name": "@aws-sdk/sha256-tree-hash",
"version": "3.183.0",
"version": "3.186.0",
"scripts": {

@@ -23,3 +23,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",

"dependencies": {
"@aws-sdk/types": "3.183.0",
"@aws-sdk/types": "3.186.0",
"tslib": "^2.3.1"

@@ -29,4 +29,4 @@ },

"@aws-crypto/sha256-js": "2.0.0",
"@aws-sdk/util-hex-encoding": "3.183.0",
"@aws-sdk/util-utf8-node": "3.183.0",
"@aws-sdk/util-hex-encoding": "3.186.0",
"@aws-sdk/util-utf8-node": "3.186.0",
"@tsconfig/recommended": "1.0.1",

@@ -33,0 +33,0 @@ "concurrently": "7.0.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc