diff --git a/.gitignore b/.gitignore index acb3481..47b3907 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,31 @@ node_modules ./bitauth.min.js ./tests.js +# OSX +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# VIM ignore + +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fc5f4b2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: node_js -sudo: false -compiler: - - gcc -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-6 -node_js: - - '8' - - '10' - - '12' -before_install: - - export CXX="g++-6" -install: - - npm install -script: npm run test diff --git a/README.md b/README.md index dbe12ce..218c13b 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,6 @@ Install with Node.js: npm install bitauth ``` -To generate a browser bundle, you can then run: - -```bash -gulp browser -``` - ## Advantages over other authentication mechanisms * By signing each request, man in the middle attacks are impossible. @@ -199,25 +193,3 @@ BitAuth exposes a connect middleware for use in connect or ExpressJS application var bitauth = require('bitauth'); app.use( bitauth.middleware ); ``` - -## Development - -To build a browser compatible version of BitAuth, run the following command from the project's root directory: - -```bash -gulp browser -``` - -This will output `bitauth.min.js` to project directory. The script can be loaded using `require('bitauth')`. - -To then run tests for a web browser: - -```bash -gulp test:browser -``` - -To run tests for Node.js: - -```bash -gulp test:node -``` diff --git a/bower.json b/bower.json deleted file mode 100644 index 80fa544..0000000 --- a/bower.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "bitauth", - "main": "./bitauth.min.js", - "version": "0.4.0", - "homepage": "https://github.com/bitpay/bitauth", - "authors": [ - "BitPay, Inc." - ], - "description": "Passwordless authentication using Bitcoin cryptography", - "moduleType": [ - "globals" - ], - "keywords": [ - "bitcoin", - "bitcore", - "btc", - "satoshi" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "CONTRIBUTING.md", - "gulpfile.js", - "lib", - "index.js", - "karma.conf.js", - "test" - ] -} diff --git a/browserify.js b/browserify.js deleted file mode 100644 index 604f4c3..0000000 --- a/browserify.js +++ /dev/null @@ -1,14 +0,0 @@ -const fs = require('fs'); -const browserify = require('browserify'); -const minifyStream = require('minify-stream'); - -// This currently generates the dist files but there are no tests done - -browserify('index.js') - .bundle() - .pipe(fs.createWriteStream('./dist/bitauth.js')); - -fs.createReadStream('./dist/bitauth.js') - .pipe(minifyStream({ sourceMap: false })) - .pipe(fs.createWriteStream('./dist/bitauth.min.js')); - diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..63c075b --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,24 @@ +module.exports = function(config) { + config.set({ + basePath: './', + frameworks: ['browserify', 'mocha'], + files: [ + 'test/*.js' + ], + exclude: [ + ], + preprocessors: { + 'test/*.js': [ 'browserify' ] + }, + browserify: { + debug: true + }, + reporters: ['progress'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: false, + browsers: ['Chrome'], + singleRun: true + }) +} diff --git a/lib/bitauth-browserify.js b/lib/bitauth-browserify.js index 9025dc8..119e88b 100644 --- a/lib/bitauth-browserify.js +++ b/lib/bitauth-browserify.js @@ -19,7 +19,7 @@ BitAuth._getPublicKeyFromPrivateKey = function(privkey) { } else { privKeyString = privkey; } - const keys = ecdsa.keyPair(privkey, 'hex'); + const keys = ecdsa.keyFromPrivate(privKeyString, 'hex'); // compressed public key const pubKey = keys.getPublic(); @@ -36,12 +36,13 @@ BitAuth._getPublicKeyFromPrivateKey = function(privkey) { }; BitAuth._sign = function(hashBuffer, privkey) { - const signature = ecdsa.sign(hashBuffer.toString('hex'), privkey); + const keys = ecdsa.keyFromPrivate(privkey, 'hex'); + const signature = keys.sign(hashBuffer.toString('hex')); return signature.toDER('hex'); }; BitAuth._verifySignature = function(hashBuffer, signatureBuffer, pubkey) { - return ecdsa.verify(hashBuffer.toString('hex'), signatureBuffer, pubkey); + return ecdsa.verify(hashBuffer.toString('hex'), signatureBuffer, pubkey, 'hex'); }; module.exports = BitAuth; diff --git a/package.json b/package.json index bbc9ea7..cf31b1d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ } ], "scripts": { - "test": "mocha" + "test": "mocha", + "test-browser": "karma start karma.conf.js" }, "main": "index.js", "version": "0.4.0", @@ -38,8 +39,14 @@ }, "devDependencies": { "benchmark": "^2.1.4", + "browserify": "^16.5.1", "chai": "^4.2.0", - "mocha": "^6.2.2" + "karma": "^4.4.1", + "karma-browserify": "^7.0.0", + "karma-chrome-launcher": "^3.1.0", + "karma-mocha": "^1.3.0", + "mocha": "^6.2.2", + "watchify": "^3.11.1" }, "license": "MIT" }