### Fixed

- Incorrect hash for `DataView` input, and for `Int8Array` with negative values.
- Throws `ArrayBuffer is not defined` in browsers without `ArrayBuffer`.
- Throws `global is not defined` in browsers with a `process` polyfill (e.g. BrowserFS) and Electron renderers.

### 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:32:01 +08:00
co-authored by Claude Opus 5.5
parent 290d679fbd
commit 9c5eb82a0d
12 changed files with 90 additions and 21 deletions
+9 -5
View File
@@ -9,7 +9,7 @@ var sha3$1 = {exports: {}};
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.15.0
* @version 0.16.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2026
* @license MIT
@@ -32,7 +32,7 @@ var sha3$1 = {exports: {}};
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && !WINDOW && typeof process === 'object' && process.versions && process.versions.node && process.type != 'renderer';
if (NODE_JS) {
root = commonjsGlobal;
} else if (WEB_WORKER) {
@@ -66,7 +66,7 @@ var sha3$1 = {exports: {}};
}
: Array.isArray;
var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
var isView = !ARRAY_BUFFER ? null : (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)
? function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
}
@@ -84,10 +84,14 @@ var sha3$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 empty = function (message) {