### 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
+5
View File
@@ -257,6 +257,11 @@
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': new Uint8Array([]),
'01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103])
};
testCases.sha3_512['ArrayBuffer view'] = {
'd9ba1ec23c0d273be9e6689ccb573478226fa909ab53dc0dd8ff3ff1d342a5246b69dcbad5cecba577aaabc5595939e6f3e8ae30778f8a35f88d265c4ca683f7': new Int8Array([-1, -128, 65, 0, -2]),
'db986a889a9a39d6f1db1250ceebd35b943b15d7c0466979f2314801992f380bc7b0c76d20234dfbd1e2afcd13cc858f4a66c04b24fab037845e2c3a9b45af43': new Uint16Array(new Uint8Array([2, 1]).buffer),
'8143d62fff557e3c37e15a7e7e1be8dd031401cd55da9ca74237e70f8c9d0f20bad8a2af7b22986e56ee6a704ee365f79f83fe7fbfe0c359d7caecc8030f6af5': new DataView(new Uint8Array([9, 72, 69, 76, 76, 79, 9]).buffer, 1, 5)
};
testCases.sha3_512.ArrayBuffer = {
'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26': new ArrayBuffer(0),
'01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]).buffer