Skip to content

Commit

Permalink
add standard, cleanup package.json and README
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Aug 27, 2015
1 parent fb354aa commit 39dade6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 76 deletions.
24 changes: 0 additions & 24 deletions .gitignore
@@ -1,25 +1 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules node_modules
12 changes: 6 additions & 6 deletions .travis.yml
@@ -1,10 +1,10 @@
sudo: false
language: node_js language: node_js
before_install:
- "npm install npm -g"
node_js: node_js:
- "0.11" - "0.12"
- "0.10" - "iojs"
env: env:
- TEST_SUITE=test - TEST_SUITE=coverage
- TEST_SUITE=coveralls - TEST_SUITE=standard
- TEST_SUITE=unit
script: "npm run-script $TEST_SUITE" script: "npm run-script $TEST_SUITE"
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)


Copyright (c) 2014 Daniel Cousens Copyright (c) 2015 Daniel Cousens


Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 8 additions & 5 deletions README.md
@@ -1,13 +1,14 @@
# bip32-utils # bip32-utils


[![build status](https://secure.travis-ci.org/dcousens/bip32-utils.png)](http://travis-ci.org/dcousens/bip32-utils) [![TRAVIS](https://secure.travis-ci.org/bitcoinjs/bip32-utils.png)](http://travis-ci.org/bitcoinjs/bip32-utils)
[![Coverage Status](https://coveralls.io/repos/dcousens/bip32-utils/badge.png)](https://coveralls.io/r/dcousens/bip32-utils) [![NPM](http://img.shields.io/npm/v/bip32-utils.svg)](https://www.npmjs.org/package/bip32-utils)
[![Version](http://img.shields.io/npm/v/bip32-utils.svg)](https://www.npmjs.org/package/bip32-utils)


[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)


## Examples A set of utilities for working with BIP32.


BIP32 [Used] Address discovery
## Example


``` javascript ``` javascript
var bip32utils = require('bip32-utils') var bip32utils = require('bip32-utils')
Expand Down Expand Up @@ -100,3 +101,5 @@ console.log(iter.indexOf(address))
console.log(iter.pop()) console.log(iter.pop())
// => address // => address
``` ```

## LICENSE [MIT](LICENSE)
File renamed without changes.
52 changes: 36 additions & 16 deletions package.json
@@ -1,28 +1,48 @@
{ {
"name": "bip32-utils", "name": "bip32-utils",
"version": "0.4.2", "version": "0.4.2",
"description": "bip32-utils", "description": "A set of utilities for working with BIP32.",
"main": "./src/index.js", "author": "Daniel Cousens",
"scripts": { "license": "MIT",
"coverage": "istanbul cover _mocha -- test/*.js",
"coveralls": "npm run coverage && coveralls < coverage/lcov.info",
"test": "istanbul test mocha -- --reporter list test/*.js"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/dcousens/bip32-utils.git" "url": "https://github.com/bitcoinjs/bip32-utils.git"
}, },
"author": "Daniel Cousens",
"license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/dcousens/bip32-utils/issues" "url": "https://github.com/bitcoinjs/bip32-utils/issues"
},
"homepage": "https://github.com/bitcoinjs/bip32-utils",
"keywords": [
"bip32-utils"
],
"main": "index.js",
"scripts": {
"coverage": "mocha --require blanket -R travis-cov",
"coverage-local": "mocha --require blanket -R html-cov",
"standard": "standard",
"test": "npm run standard && npm run unit",
"unit": "mocha"
},
"config": {
"blanket": {
"pattern": [
""
],
"data-cover-never": [
"node_modules",
"test"
]
},
"travis-cov": {
"threshold": 100
}
}, },
"homepage": "https://github.com/dcousens/bip32-utils",
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"bitcoinjs-lib": "^1.5.0", "bitcoinjs-lib": "^1.5.8",
"coveralls": "^2.11.2", "blanket": "*",
"istanbul": "^0.3.5", "mocha": "*",
"mocha": "^2.1.0" "standard": "*",
"travis-cov": "*"
} }
} }
26 changes: 13 additions & 13 deletions src/account.js
@@ -1,26 +1,26 @@
var AddressIterator = require('./iterator') var AddressIterator = require('./iterator')


function Account(external, internal, k) { function Account (external, internal, k) {
this.external = new AddressIterator(external, k) this.external = new AddressIterator(external, k)
this.internal = new AddressIterator(internal, k) this.internal = new AddressIterator(internal, k)
} }


Account.prototype.containsAddress = function(address) { return this.isExternalAddress(address) || this.isInternalAddress(address) } Account.prototype.containsAddress = function (address) { return this.isExternalAddress(address) || this.isInternalAddress(address) }
Account.prototype.getAllAddresses = function() { return this.external.addresses.concat(this.internal.addresses) } Account.prototype.getAllAddresses = function () { return this.external.addresses.concat(this.internal.addresses) }
Account.prototype.getExternalAddress = function() { return this.external.get() } Account.prototype.getExternalAddress = function () { return this.external.get() }
Account.prototype.getInternalAddress = function() { return this.internal.get() } Account.prototype.getInternalAddress = function () { return this.internal.get() }
Account.prototype.getNetwork = function() { return this.external.node.network } Account.prototype.getNetwork = function () { return this.external.node.network }
Account.prototype.getNode = function(address, external, internal) { Account.prototype.getNode = function (address, external, internal) {
return this.getNodes([address], external, internal)[0] return this.getNodes([address], external, internal)[0]
} }
Account.prototype.getNodes = function(addresses, external, internal) { Account.prototype.getNodes = function (addresses, external, internal) {
external = external || this.external.node external = external || this.external.node
internal = internal || this.internal.node internal = internal || this.internal.node


var externalIter = this.external var externalIter = this.external
var internalIter = this.internal var internalIter = this.internal


return addresses.map(function(address) { return addresses.map(function (address) {
var k var k


if (address in externalIter.map) { if (address in externalIter.map) {
Expand All @@ -39,10 +39,10 @@ Account.prototype.getNodes = function(addresses, external, internal) {
}) })
} }


Account.prototype.isExternalAddress = function(address) { return address in this.external.map } Account.prototype.isExternalAddress = function (address) { return address in this.external.map }
Account.prototype.isInternalAddress = function(address) { return address in this.internal.map } Account.prototype.isInternalAddress = function (address) { return address in this.internal.map }


Account.prototype.nextExternalAddress = function() { return this.external.next() } Account.prototype.nextExternalAddress = function () { return this.external.next() }
Account.prototype.nextInternalAddress = function() { return this.internal.next() } Account.prototype.nextInternalAddress = function () { return this.internal.next() }


module.exports = Account module.exports = Account
12 changes: 7 additions & 5 deletions src/discovery.js
@@ -1,9 +1,9 @@
// https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery // https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery
module.exports = function discovery(iterator, gapLimit, queryCb, done) { module.exports = function discovery (iterator, gapLimit, queryCb, done) {
var gap = 0 var gap = 0
var checked = 0 var checked = 0


;(function cycle() { function cycle () {
var batch = [iterator.get()] var batch = [iterator.get()]
checked++ checked++


Expand All @@ -14,10 +14,10 @@ module.exports = function discovery(iterator, gapLimit, queryCb, done) {
checked++ checked++
} }


queryCb(batch, function(err, results) { queryCb(batch, function (err, results) {
if (err) return done(err) if (err) return done(err)


results.forEach(function(isUsed) { results.forEach(function (isUsed) {
if (isUsed) { if (isUsed) {
gap = 0 gap = 0


Expand All @@ -38,5 +38,7 @@ module.exports = function discovery(iterator, gapLimit, queryCb, done) {


cycle() cycle()
}) })
})() }

cycle()
} }
12 changes: 6 additions & 6 deletions src/iterator.js
@@ -1,4 +1,4 @@
function AddressIterator(node, k) { function AddressIterator (node, k) {
k = k || 0 k = k || 0


this.addresses = [] this.addresses = []
Expand All @@ -10,15 +10,15 @@ function AddressIterator(node, k) {
this.next() this.next()
} }


AddressIterator.prototype.get = function() { AddressIterator.prototype.get = function () {
return this.addresses[this.addresses.length - 1] return this.addresses[this.addresses.length - 1]
} }


AddressIterator.prototype.indexOf = function(address) { AddressIterator.prototype.indexOf = function (address) {
return (address in this.map) ? this.map[address] : -1 return (address in this.map) ? this.map[address] : -1
} }


AddressIterator.prototype.next = function() { AddressIterator.prototype.next = function () {
var address = this.peek() var address = this.peek()
this.k += 1 this.k += 1


Expand All @@ -31,13 +31,13 @@ AddressIterator.prototype.next = function() {
return this.get() return this.get()
} }


AddressIterator.prototype.peek = function() { AddressIterator.prototype.peek = function () {
var xpub = this.node.derive(this.k + 1) var xpub = this.node.derive(this.k + 1)


return xpub.getAddress().toString() return xpub.getAddress().toString()
} }


AddressIterator.prototype.pop = function() { AddressIterator.prototype.pop = function () {
var address = this.addresses.pop() var address = this.addresses.pop()


delete this.map[address] delete this.map[address]
Expand Down

0 comments on commit 39dade6

Please sign in to comment.