Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #261 from Tenderly/v4-removing-native-js-dependencies
Browse files Browse the repository at this point in the history
V4 Removing native js dependencies
  • Loading branch information
holgerd77 authored Jul 15, 2020
2 parents 884cf09 + c157597 commit 0c80e9a
Show file tree
Hide file tree
Showing 11 changed files with 2,575 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
[
"env"
]
]
}
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
language: node_js
node_js:
- "0.11"
- "0.12"
- "4"
- "5"
- "6"
- "8"
- "10"
- "12"
env:
- CXX=g++-4.8
services:
- xvfb
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
before_install:
- sh -e /etc/init.d/xvfb start
env:
global:
- DISPLAY=:99.0
Expand All @@ -23,9 +23,9 @@ matrix:
fast_finish: true
include:
- os: linux
node_js: "4"
node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=coveralls
- os: linux
node_js: "4"
node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=lint
script: npm run $TEST_SUITE
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SHA3 = require('keccakjs')
const secp256k1 = require('secp256k1')
const { keccak224, keccak384, keccak256: k256, keccak512 } = require('ethereum-cryptography/keccak')
const secp256k1 = require('./secp256k1-adapter')
const assert = require('assert')
const rlp = require('rlp')
const BN = require('bn.js')
Expand Down Expand Up @@ -250,11 +250,23 @@ exports.sha3 = function (a, bytes) {
a = exports.toBuffer(a)
if (!bytes) bytes = 256

var h = new SHA3(bytes)
if (a) {
h.update(a)
switch (bytes) {
case 224: {
return keccak224(a)
}
case 256: {
return k256(a)
}
case 384: {
return keccak384(a)
}
case 512: {
return keccak512(a)
}
default: {
throw new Error(`Invalid algorithm: keccak${bytes}`)
}
}
return new Buffer(h.digest('hex'), 'hex')
}

/**
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
"name": "ethereumjs-util",
"version": "4.5.0",
"description": "a collection of utility functions for Ethereum",
"main": "index.js",
"main": "dist/index.js",
"files": [
"dist"
],
"scripts": {
"coverage": "istanbul cover _mocha",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"lint": "standard",
"prepublish": "npm run lint && npm run test",
"prepublish": "npm run lint && npm run build:dist && npm run test",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js",
"test:node": "istanbul test mocha -- --reporter spec",
"build:dist": "babel index.js secp256k1-adapter.js secp256k1-lib/* --source-root ./ -d ./dist",
"build:docs": "documentation --github -f md ./index.js > ./docs/index.md"
},
"repository": {
Expand All @@ -33,11 +37,13 @@
"dependencies": {
"bn.js": "^4.8.0",
"create-hash": "^1.1.2",
"keccakjs": "^0.2.0",
"rlp": "^2.0.0",
"secp256k1": "^3.0.1"
"ethereum-cryptography": "^0.1.3",
"elliptic": "^6.5.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"browserify": "^13.0.0",
"coveralls": "^2.11.4",
"documentation": "^3.0.4",
Expand All @@ -56,6 +62,9 @@
"globals": [
"describe",
"it"
],
"ignore": [
"dist/**"
]
}
}
Loading

0 comments on commit 0c80e9a

Please sign in to comment.