sha3 backward compatibility. #205

This commit is contained in:
Marek Kotewicz 2015-05-26 20:47:04 +02:00
parent 3fb420f63c
commit 3bb6e4f723
8 changed files with 44 additions and 13 deletions

13
dist/web3-light.js vendored
View File

@ -820,16 +820,25 @@ module.exports = {
* @date 2015 * @date 2015
*/ */
var utils = require('./utils');
var sha3 = require('crypto-js/sha3'); var sha3 = require('crypto-js/sha3');
module.exports = function (str) { module.exports = function (str, isNew) {
if (str.substr(0, 2) === '0x' && !isNew) {
console.warn('requirement of using web3.fromAscii before sha3 is deprecated');
console.warn('new usage: \'web3.sha3("hello")\'');
console.warn('see https://github.com/ethereum/web3.js/pull/205');
console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\'');
str = utils.toAscii(str);
}
return sha3(str, { return sha3(str, {
outputLength: 256 outputLength: 256
}).toString(); }).toString();
}; };
},{"crypto-js/sha3":30}],7:[function(require,module,exports){ },{"./utils":7,"crypto-js/sha3":30}],7:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

13
dist/web3.js vendored
View File

@ -820,16 +820,25 @@ module.exports = {
* @date 2015 * @date 2015
*/ */
var utils = require('./utils');
var sha3 = require('crypto-js/sha3'); var sha3 = require('crypto-js/sha3');
module.exports = function (str) { module.exports = function (str, isNew) {
if (str.substr(0, 2) === '0x' && !isNew) {
console.warn('requirement of using web3.fromAscii before sha3 is deprecated');
console.warn('new usage: \'web3.sha3("hello")\'');
console.warn('see https://github.com/ethereum/web3.js/pull/205');
console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\'');
str = utils.toAscii(str);
}
return sha3(str, { return sha3(str, {
outputLength: 256 outputLength: 256
}).toString(); }).toString();
}; };
},{"crypto-js/sha3":30}],7:[function(require,module,exports){ },{"./utils":7,"crypto-js/sha3":30}],7:[function(require,module,exports){
/* /*
This file is part of ethereum.js. This file is part of ethereum.js.

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

5
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -20,9 +20,18 @@
* @date 2015 * @date 2015
*/ */
var utils = require('./utils');
var sha3 = require('crypto-js/sha3'); var sha3 = require('crypto-js/sha3');
module.exports = function (str) { module.exports = function (str, isNew) {
if (str.substr(0, 2) === '0x' && !isNew) {
console.warn('requirement of using web3.fromAscii before sha3 is deprecated');
console.warn('new usage: \'web3.sha3("hello")\'');
console.warn('see https://github.com/ethereum/web3.js/pull/205');
console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\'');
str = utils.toAscii(str);
}
return sha3(str, { return sha3(str, {
outputLength: 256 outputLength: 256
}).toString(); }).toString();

View File

@ -1,6 +1,7 @@
var chai = require('chai'); var chai = require('chai');
var assert = chai.assert; var assert = chai.assert;
var sha3 = require('../lib/utils/sha3'); var sha3 = require('../lib/utils/sha3');
var web3 = require('../index');
describe('lib/utils/sha3', function () { describe('lib/utils/sha3', function () {
var test = function (v, e) { var test = function (v, e) {
@ -11,5 +12,6 @@ describe('lib/utils/sha3', function () {
test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad'); test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1'); test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1');
test(web3.fromAscii('test123'), 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
}); });