Fixed ArrayBuffer dosen't work in Webpack.

pull/12/head
Chen, Yi-Cyuan 9 years ago
parent 035642212a
commit 8ae70989ae

@ -1,5 +1,9 @@
# Change Log
## v0.5.6 / 2016-12-29
### Fixed
- ArrayBuffer dosen't work in Webpack.
## v0.5.5 / 2016-09-26
### Added
- TypeScript support.

@ -1,6 +1,6 @@
{
"name": "js-sha3",
"version": "0.5.5",
"version": "0.5.6",
"main": ["src/sha3.js"],
"ignore": [
"samples",

@ -1,6 +1,6 @@
{
"name": "js-sha3",
"version": "0.5.5",
"version": "0.5.6",
"description": "A simple SHA-3 / Keccak / Shake hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha3.js",
"typings": "index",

@ -1,19 +1,21 @@
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.5.5
* @version 0.5.6
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2016
* @license MIT
*/
(function (root) {
/*jslint bitwise: true */
(function () {
'use strict';
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_SHA3_TEST && typeof module == 'object' && module.exports;
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
var HEX_CHARS = '0123456789abcdef'.split('');
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
var KECCAK_PADDING = [1, 256, 65536, 16777216];
@ -31,13 +33,13 @@
var createOutputMethod = function (bits, padding, outputType) {
return function (message) {
return new Keccak(bits, padding, bits).update(message)[outputType]();
}
};
};
var createShakeOutputMethod = function (bits, padding, outputType) {
return function (message, outputBits) {
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
}
};
};
var createMethod = function (bits, padding) {
@ -76,13 +78,15 @@
{name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
];
var methods = {};
var methods = {}, methodNames = [];
for (var i = 0; i < algorithms.length; ++i) {
var algorithm = algorithms[i];
var bits = algorithm.bits;
for (var j = 0; j < bits.length; ++j) {
methods[algorithm.name +'_' + bits[j]] = algorithm.createMethod(bits[j], algorithm.padding);
var methodName = algorithm.name +'_' + bits[j];
methodNames.push(methodName);
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
}
}
@ -102,7 +106,7 @@
for (var i = 0; i < 50; ++i) {
this.s[i] = 0;
}
};
}
Keccak.prototype.update = function (message) {
var notString = typeof message != 'string';
@ -191,7 +195,7 @@
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);
i = 0;
}
@ -228,7 +232,7 @@
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
array[j] = s[i];
}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);
}
}
@ -256,7 +260,7 @@
array[offset + 2] = (block >> 16) & 0xFF;
array[offset + 3] = (block >> 24) & 0xFF;
}
if (j % blockCount == 0) {
if (j % blockCount === 0) {
f(s);
}
}
@ -459,13 +463,13 @@
s[0] ^= RC[n];
s[1] ^= RC[n + 1];
}
}
};
if (COMMON_JS) {
module.exports = methods;
} else if (root) {
for (var key in methods) {
root[key] = methods[key];
} else {
for (var i = 0; i < methodNames.length; ++i) {
root[methodNames[i]] = methods[methodNames[i]];
}
}
}(this));
})();

@ -1,3 +1,26 @@
// Node.js env
expect = require('expect.js');
var sha3 = require('../src/sha3.js');
keccak_512 = sha3.keccak_512;
keccak_384 = sha3.keccak_384;
keccak_256 = sha3.keccak_256;
keccak_224 = sha3.keccak_224;
sha3_512 = sha3.sha3_512;
sha3_384 = sha3.sha3_384;
sha3_256 = sha3.sha3_256;
sha3_224 = sha3.sha3_224;
shake_128 = sha3.shake_128;
shake_256 = sha3.shake_256;
require('./test.js');
require('./test-shake.js');
delete require.cache[require.resolve('../src/sha3.js')];
delete require.cache[require.resolve('./test.js')];
delete require.cache[require.resolve('./test-shake.js')];
// Webpack browser env
JS_SHA3_NO_NODE_JS = true;
window = global;
expect = require('expect.js');
var sha3 = require('../src/sha3.js');
keccak_512 = sha3.keccak_512;
@ -27,7 +50,10 @@ keccak_224 = null;
shake_128 = null;
shake_256 = null;
JS_SHA3_TEST = true;
// browser env
JS_SHA3_NO_NODE_JS = true;
JS_SHA3_NO_COMMON_JS = true;
window = global;
require('../src/sha3.js');
require('./test.js');
require('./test-shake.js');

Loading…
Cancel
Save