These js utilities should work reliably on both server and client.
Using the WebCrypto API makes it difficult to make it work with both NodeJS versions under v19 and the browser runtime.
Original PR approach:
The hashing function of choice was coming from: https://geraintluff.github.io/sha256/
It's small-sized but it only supports ASCII. It fits our needs for now but further research should be done to find a better and still small-sized solution.
New approach:
The hashing function code comes from: https://www.movable-type.co.uk/scripts/sha256.html#src-code
It is not optimised but it's Unicode compatible.
This script is oriented toward hashing text messages rather than binary data. The standard considers hashing byte-stream (or bit-stream) messages only. Text which contains (multi-byte) characters outside ISO 8859-1 (i.e. accented characters outside Latin-1 or non-European character sets – anything with Unicode code-point above U+FF), can’t be encoded 4-per-word, so the script defaults to encoding the text as UTF-8 before hashing it.
A beta release 2.30.0-beta.native-hash has been published to test this behaviour on preproduction environments and it's working as desired.
Related Issue
Since we started using it, we've been seeing an increase in error logs coming from the server. This happens when this hashing function, as it currently is, is called from a NodeJS environment.
Description
These js utilities should work reliably on both server and client. Using the
WebCrypto
API makes it difficult to make it work with both NodeJS versions under v19 and the browser runtime.Original
PR
approach:New approach:
A beta release
2.30.0-beta.native-hash
has been published to test this behaviour on preproduction environments and it's working as desired.Related Issue
Since we started using it, we've been seeing an increase in error logs coming from the server. This happens when this hashing function, as it currently is, is called from a NodeJS environment.
Example
N/A