mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 11:38:12 +00:00
sha3 init
This commit is contained in:
parent
16861fc194
commit
adf91dfe8f
@ -8,7 +8,8 @@
|
||||
"./dist/web3.min.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"bignumber.js": ">=2.0.0"
|
||||
"bignumber.js": ">=2.0.0",
|
||||
"crypto-js": "~3.1.4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
30
lib/utils/sha3.js
Normal file
30
lib/utils/sha3.js
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
ethereum.js is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ethereum.js is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file sha3.js
|
||||
* @author Marek Kotewicz <marek@ethdev.com>
|
||||
* @date 2015
|
||||
*/
|
||||
|
||||
var sha3 = require('crypto-js/sha3');
|
||||
|
||||
module.exports = function (str) {
|
||||
return sha3(str, {
|
||||
outputLength: 256
|
||||
}).toString();
|
||||
};
|
||||
|
@ -9,6 +9,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bignumber.js": "debris/bignumber.js#master",
|
||||
"crypto-js": "^3.1.4",
|
||||
"xmlhttprequest": "*"
|
||||
},
|
||||
"browser": {
|
||||
|
15
test/sha3.js
Normal file
15
test/sha3.js
Normal file
@ -0,0 +1,15 @@
|
||||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var sha3 = require('../lib/utils/sha3');
|
||||
|
||||
describe('lib/utils/sha3', function () {
|
||||
var test = function (v, e) {
|
||||
it('should encode ' + v + ' to ' + e, function () {
|
||||
assert.equal(sha3(v), e);
|
||||
});
|
||||
};
|
||||
|
||||
test('test123', 'f81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad');
|
||||
test('test(int)', 'f4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user