Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 3bb6e4f

Browse files
committed
sha3 backward compatibility. #205
1 parent 3fb420f commit 3bb6e4f

File tree

8 files changed

+44
-13
lines changed

8 files changed

+44
-13
lines changed

dist/web3-light.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3-light.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3-light.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils/sha3.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
* @date 2015
2121
*/
2222

23+
var utils = require('./utils');
2324
var sha3 = require('crypto-js/sha3');
2425

25-
module.exports = function (str) {
26+
module.exports = function (str, isNew) {
27+
if (str.substr(0, 2) === '0x' && !isNew) {
28+
console.warn('requirement of using web3.fromAscii before sha3 is deprecated');
29+
console.warn('new usage: \'web3.sha3("hello")\'');
30+
console.warn('see https://github.com/ethereum/web3.js/pull/205');
31+
console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\'');
32+
str = utils.toAscii(str);
33+
}
34+
2635
return sha3(str, {
2736
outputLength: 256
2837
}).toString();

test/sha3.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var chai = require('chai');
22
var assert = chai.assert;
33
var sha3 = require('../lib/utils/sha3');
4+
var web3 = require('../index');
45

56
describe('lib/utils/sha3', function () {
67
var test = function (v, e) {
@@ -11,5 +12,6 @@ describe('lib/utils/sha3', function () {
1112

1213
test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
1314
test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1');
15+
test(web3.fromAscii('test123'), 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
1416
});
1517

0 commit comments

Comments
 (0)