### Fixed

- Incorrect hash for `DataView` input, and for `Int8Array` with negative values in browsers.

### 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:59 +08:00
co-authored by Claude Opus 5.5
parent e57611d11f
commit 0f3bc529d4
13 changed files with 38 additions and 17 deletions
+3 -2
View File
@@ -1,7 +1,7 @@
/**
* [js-sha256]{@link https://github.com/emn178/js-sha256}
*
* @version 1.0.1
* @version 1.1.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2026
* @license MIT
@@ -27,7 +27,8 @@ var formatMessage = function (message) {
if (message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
} else if (ArrayBuffer.isView(message)) {
return [message, false];
// read the underlying bytes of any view (Int8Array, DataView, Uint16Array, ...)
return [new Uint8Array(message.buffer, message.byteOffset, message.byteLength), false];
}
}
throw new Error(INPUT_ERROR);