├── .gitignore ├── LICENSE ├── README.md ├── browser.js ├── circle.yml ├── index.js ├── package.json └── test └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | package-lock.json 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Alex Beregszaszi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Keccak.js 2 | 3 | The only Keccak hash (aka SHA3 before standardisation) library you need in Javascript. Ever. Pinky promise! 4 | 5 | It is a meta package and lets you to use `node-sha3` or `js-sha3` with the same interface on your choice of deployment. It uses `browserify-sha3` to do the mapping for you. 6 | 7 | There's no speed loss, it is as thin as it can get (but there is some twiddling in `package.json` to select the right package for your environment): 8 | ```js 9 | module.exports = require('sha3').SHA3Hash 10 | ``` 11 | 12 | Example usage: 13 | ```js 14 | const keccak = require('keccakjs') 15 | 16 | var hash = new keccak() // uses 512 bits by default 17 | hash.update('hello') 18 | hash.update(Buffer.from('42004200', 'hex')) 19 | hash.digest() // binary output 20 | hash.digest('hex') // hex output 21 | ``` 22 | 23 | **NOTE: This library supports the Keccak padding only - and not the final SHA3 padding.** 24 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | module.exports = require('browserify-sha3').SHA3Hash 2 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | workflows: 2 | version: 2.1 3 | node-multi-build: 4 | jobs: 5 | - node-v6 6 | - node-v8 7 | - node-v10 8 | 9 | version: 2.1 10 | jobs: 11 | node-base: &node-base 12 | working_directory: ~/solc-js 13 | docker: 14 | - image: circleci/node 15 | steps: 16 | - run: 17 | name: Versions 18 | command: npm version 19 | - checkout 20 | - restore_cache: 21 | key: dependency-cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} 22 | - run: 23 | name: install-npm 24 | command: npm install 25 | - run: 26 | name: lint 27 | command: npm run lint 28 | - run: 29 | name: test 30 | command: npm run test 31 | - save_cache: 32 | key: dependency-cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.json" }} 33 | paths: 34 | - ./node_modules 35 | 36 | node-v6: 37 | <<: *node-base 38 | docker: 39 | - image: circleci/node:6 40 | node-v8: 41 | <<: *node-base 42 | docker: 43 | - image: circleci/node:8 44 | node-v10: 45 | <<: *node-base 46 | docker: 47 | - image: circleci/node:10 48 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports = require('sha3').SHA3Hash 3 | } catch (err) { 4 | module.exports = require('./browser') 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "keccakjs", 3 | "version": "0.2.3", 4 | "description": "Keccak hash (SHA3) in Node.js and in the browser. Fast & simple.", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "standard", 8 | "test": "tape ./test/index.js" 9 | }, 10 | "author": { 11 | "name": "Alex Beregszaszi", 12 | "email": "alex@rtfs.hu" 13 | }, 14 | "repository": "https://github.com/axic/keccakjs", 15 | "keywords": [ 16 | "sha3", 17 | "keccak", 18 | "hash" 19 | ], 20 | "license": "MIT", 21 | "dependencies": { 22 | "browserify-sha3": "^0.0.4", 23 | "sha3": "^1.2.2" 24 | }, 25 | "browser": "browser.js", 26 | "devDependencies": { 27 | "standard": "^12.0.0", 28 | "tape": "^4.9.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const tape = require('tape') 2 | const Keccak = require('../index') 3 | const KeccakJS = require('../browser') 4 | 5 | tape('Auto-detected', function (t) { 6 | t.test('basic', function (st) { 7 | var hash = new Keccak() 8 | hash.update('hello') 9 | hash.update(Buffer.from('42004200', 'hex')) 10 | st.equal(hash.digest('hex'), '1f900dfea0147b249861792bcf838a42c0bb276a395a64d90ee08491e5dbce09273846902b57b739b40b9983d21de29678df9e8585f56f532088c80ed41d6354') 11 | st.end() 12 | }) 13 | }) 14 | 15 | tape('Javascript', function (t) { 16 | t.test('basic', function (st) { 17 | var hash = new KeccakJS() 18 | hash.update('hello') 19 | hash.update(Buffer.from('42004200', 'hex')) 20 | st.equal(hash.digest('hex'), '1f900dfea0147b249861792bcf838a42c0bb276a395a64d90ee08491e5dbce09273846902b57b739b40b9983d21de29678df9e8585f56f532088c80ed41d6354') 21 | st.end() 22 | }) 23 | }) 24 | --------------------------------------------------------------------------------