### Fixed

- Incorrect hash for `DataView` input, and for `Int8Array` with negative values in browsers.
- Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`.

### Changed
- Multi-byte typed arrays such as `Uint16Array`, `Uint32Array` and `Float32Array` are now hashed by their underlying bytes, the same as Node.js `crypto` and Web Crypto. Previously each element was treated as one byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yi-Cyuan Chen
2026-11-18 13:31:57 +08:00
co-authored by Claude Opus 5.5
parent 9e1e7d1397
commit 4ad1b7a3b2
13 changed files with 65 additions and 26 deletions
+8 -4
View File
@@ -7,7 +7,7 @@ var sha1$1 = {exports: {}};
/*
* [js-sha1]{@link https://github.com/emn178/js-sha1}
*
* @version 0.8.0
* @version 0.9.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2026
* @license MIT
@@ -44,7 +44,7 @@ var sha1$1 = {exports: {}};
};
}
var isView = ArrayBuffer.isView;
var isView = ARRAY_BUFFER ? ArrayBuffer.isView : null;
if (ARRAY_BUFFER && (root.JS_SHA1_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
@@ -63,10 +63,14 @@ var sha1$1 = {exports: {}};
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) && !isView(message)) {
if (isArray(message)) {
return [message, false];
}
if (!ARRAY_BUFFER || !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
// read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...)
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
};
var createOutputMethod = function (outputType) {