mirror of
https://github.com/emn178/js-sha256.git
synced 2026-08-12 20:32:16 +08:00
### Added
- Add dedicated ESM, CommonJS, Node.js, and browser distribution entry points. - Add streaming support to the native Node.js SHA-256, SHA-224, and HMAC implementations. - Add distribution contract tests and real browser Web Worker tests with Playwright. - Add Node.js 16, 18, 20, 22, and 24 runtime tests against the packed npm artifact. ### Changed - Refactor the implementation into environment-independent core and Node.js modules. - Use the native Node.js `crypto` implementation for hashing and HMAC. - Load the package version automatically when generating distribution banners. - Export unminified ESM source directly and build only CommonJS and browser/minified distributions. - Replace `expect.js`, NYC, Tiny Worker, and UglifyJS with Node.js assert, c8, Playwright, and Rollup/Terser. - Build automatically before `npm pack` and `npm publish`. - Throw error if update after finalize ### Removed - Remove runtime CommonJS, AMD, Node.js, Web Worker, and ArrayBuffer environment switches from the core implementation. - Remove legacy environment flags and obsolete compatibility polyfills. - Remove the old generated `sha256.mjs` and `sha256.node.mjs` entry points.
This commit is contained in:
+28
-31
@@ -78,32 +78,30 @@
|
||||
}
|
||||
};
|
||||
|
||||
if (!(typeof JS_SHA256_NO_ARRAY_BUFFER === 'boolean' && JS_SHA256_NO_ARRAY_BUFFER)) {
|
||||
testCases.sha256_hmac.Uint8Array = {
|
||||
'e48411262715c8370cd5e7bf8e82bef53bd53712d007f3429351843b77c7bb9b': [
|
||||
new Uint8Array(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha256_hmac.ArrayBuffer = {
|
||||
'e48411262715c8370cd5e7bf8e82bef53bd53712d007f3429351843b77c7bb9b': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha224_hmac.Uint8Array = {
|
||||
'da8f94de91d62154b55ea4e8d6eb133f6d553bcd1f1ba205b9488945': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha224_hmac.ArrayBuffer = {
|
||||
'da8f94de91d62154b55ea4e8d6eb133f6d553bcd1f1ba205b9488945': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
}
|
||||
testCases.sha256_hmac.Uint8Array = {
|
||||
'e48411262715c8370cd5e7bf8e82bef53bd53712d007f3429351843b77c7bb9b': [
|
||||
new Uint8Array(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha256_hmac.ArrayBuffer = {
|
||||
'e48411262715c8370cd5e7bf8e82bef53bd53712d007f3429351843b77c7bb9b': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha224_hmac.Uint8Array = {
|
||||
'da8f94de91d62154b55ea4e8d6eb133f6d553bcd1f1ba205b9488945': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
testCases.sha224_hmac.ArrayBuffer = {
|
||||
'da8f94de91d62154b55ea4e8d6eb133f6d553bcd1f1ba205b9488945': [
|
||||
new ArrayBuffer(0),
|
||||
'Hi There'
|
||||
]
|
||||
};
|
||||
|
||||
var errorTestCases = [null, undefined, { length: 0 }, 0, 1, false, true, NaN, Infinity, function () {}];
|
||||
|
||||
@@ -179,7 +177,6 @@
|
||||
call: function (key, message) {
|
||||
var hash = algorithm.update(key, message);
|
||||
hash.hex();
|
||||
hash.update(message);
|
||||
return hash.hex();
|
||||
}
|
||||
}
|
||||
@@ -197,7 +194,7 @@
|
||||
for (var hash in testCase) {
|
||||
(function (message, hash) {
|
||||
it('should be equal', function () {
|
||||
expect(method.call(message[0], message[1])).to.be(hash);
|
||||
assert.equal(method.call(message[0], message[1]), hash);
|
||||
});
|
||||
})(testCase[hash], hash);
|
||||
}
|
||||
@@ -216,7 +213,7 @@
|
||||
for (var hash in testCase) {
|
||||
(function (message, hash) {
|
||||
it('should be equal', function () {
|
||||
expect(method.call(message[0], message[1])).to.be(hash);
|
||||
assert.equal(method.call(message[0], message[1]), hash);
|
||||
});
|
||||
})(testCase[hash], hash);
|
||||
}
|
||||
@@ -230,9 +227,9 @@
|
||||
errorTestCases.forEach(function (testCase) {
|
||||
context('when ' + testCase, function () {
|
||||
it('should throw error', function () {
|
||||
expect(function () {
|
||||
assert.throws(function () {
|
||||
algorithm(testCase, '');
|
||||
}).to.throwError(/input is invalid type/);
|
||||
}, /input is invalid type/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user