Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/reference/configuration-reference
version: 2.1
orbs:
node: circleci/node@1.1.6

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/guides/orchestrate/jobs-steps/#jobs-overview & https://circleci.com/docs/reference/configuration-reference/#jobs
jobs:
build-and-test:
executor:
name: node/default
say-hello:
# Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/guides/execution-managed/executor-intro/ & https://circleci.com/docs/reference/configuration-reference/#executor-job
docker:
# Specify the version you desire here
# See: https://circleci.com/developer/images/image/cimg/base
- image: cimg/base:current

# Add steps to the job
# See: https://circleci.com/docs/guides/orchestrate/jobs-steps/#steps-overview & https://circleci.com/docs/reference/configuration-reference/#steps
steps:
# Checkout the code as the first step.
- checkout
- node/with-cache:
steps:
- run: npm install
- run: npm test
- run:
name: "Say hello"
command: "echo Hello, World!"

# Orchestrate jobs using workflows
# See: https://circleci.com/docs/guides/orchestrate/workflows/ & https://circleci.com/docs/reference/configuration-reference/#workflows
workflows:
build-and-test:
jobs:
- build-and-test
say-hello-workflow: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- say-hello
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
*~
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
```
29 changes: 0 additions & 29 deletions bower.json

This file was deleted.

14 changes: 0 additions & 14 deletions browserify.js

This file was deleted.

24 changes: 24 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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
})
}
7 changes: 4 additions & 3 deletions lib/bitauth-browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
12 changes: 6 additions & 6 deletions lib/bitauth-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const crypto = require('crypto');

BitAuth._generateRandomPair = function() {
const privateKeyBuffer = crypto.randomBytes(32); // may throw error if entropy sources drained
const publicKeyBuffer = secp256k1.publicKeyCreate(privateKeyBuffer, true);
const publicKeyBuffer = Buffer.from(secp256k1.publicKeyCreate(privateKeyBuffer, true));
return [privateKeyBuffer.toString('hex'), publicKeyBuffer.toString('hex')];
};

Expand All @@ -17,7 +17,7 @@ BitAuth._getPublicKeyFromPrivateKey = function(privkey) {
} else {
privateKeyBuffer = Buffer.from(privkey, 'hex');
}
return secp256k1.publicKeyCreate(privateKeyBuffer, true);
return Buffer.from(secp256k1.publicKeyCreate(privateKeyBuffer, true));
};

BitAuth._sign = function(hashBuffer, privkey) {
Expand All @@ -27,19 +27,19 @@ BitAuth._sign = function(hashBuffer, privkey) {
} else {
privkeyBuffer = Buffer.from(privkey, 'hex');
}
var signatureInfo = secp256k1.sign(hashBuffer, privkeyBuffer);
return secp256k1.signatureExport(signatureInfo.signature);
var signatureInfo = secp256k1.ecdsaSign(hashBuffer, privkeyBuffer);
return Buffer.from(secp256k1.signatureExport(signatureInfo.signature));
};

BitAuth._verifySignature = function(hashBuffer, signatureBuffer, pubkey) {
let pubkeyBuffer;
const signature = secp256k1.signatureNormalize(secp256k1.signatureImportLax(signatureBuffer));
const signature = secp256k1.signatureNormalize(secp256k1.signatureImport(signatureBuffer));
if (!Buffer.isBuffer(pubkey)){
pubkeyBuffer = Buffer.from(pubkey, 'hex');
} else {
pubkeyBuffer = pubkey;
}
return !!secp256k1.verify(hashBuffer, signature, pubkeyBuffer);
return !!secp256k1.ecdsaVerify(signature, hashBuffer, pubkeyBuffer);
};

module.exports = BitAuth;
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@
}
],
"scripts": {
"test": "mocha"
"test": "mocha",
"test-browser": "karma start karma.conf.js"
},
"main": "index.js",
"version": "0.4.0",
"dependencies": {
"bs58": "^2.0.0",
"secp256k1": "3.7.1"
"secp256k1": "4.0.2"
},
"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"
}