Skip to content
Permalink
Browse files

add standard, cleanup package.json and README

  • Loading branch information...
dcousens committed Aug 27, 2015
1 parent fb354aa commit 39dade61a9712be06c35e5a3c9fcdefcb8375e68
Showing with 77 additions and 76 deletions.
  1. +0 −24 .gitignore
  2. +6 −6 .travis.yml
  3. +1 −1 LICENSE
  4. +8 −5 README.md
  5. 0 {src → }/index.js
  6. +36 −16 package.json
  7. +13 −13 src/account.js
  8. +7 −5 src/discovery.js
  9. +6 −6 src/iterator.js
@@ -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
@@ -1,10 +1,10 @@
sudo: false
language: node_js
before_install:
- "npm install npm -g"
node_js:
- "0.11"
- "0.10"
- "0.12"
- "iojs"
env:
- TEST_SUITE=test
- TEST_SUITE=coveralls
- TEST_SUITE=coverage
- TEST_SUITE=standard
- TEST_SUITE=unit
script: "npm run-script $TEST_SUITE"
@@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal
@@ -1,13 +1,14 @@
# bip32-utils

[![build status](https://secure.travis-ci.org/dcousens/bip32-utils.png)](http://travis-ci.org/dcousens/bip32-utils)
[![Coverage Status](https://coveralls.io/repos/dcousens/bip32-utils/badge.png)](https://coveralls.io/r/dcousens/bip32-utils)
[![Version](http://img.shields.io/npm/v/bip32-utils.svg)](https://www.npmjs.org/package/bip32-utils)
[![TRAVIS](https://secure.travis-ci.org/bitcoinjs/bip32-utils.png)](http://travis-ci.org/bitcoinjs/bip32-utils)
[![NPM](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
var bip32utils = require('bip32-utils')
@@ -100,3 +101,5 @@ console.log(iter.indexOf(address))
console.log(iter.pop())
// => address
```

## LICENSE [MIT](LICENSE)
File renamed without changes.
@@ -1,28 +1,48 @@
{
"name": "bip32-utils",
"version": "0.4.2",
"description": "bip32-utils",
"main": "./src/index.js",
"scripts": {
"coverage": "istanbul cover _mocha -- test/*.js",
"coveralls": "npm run coverage && coveralls < coverage/lcov.info",
"test": "istanbul test mocha -- --reporter list test/*.js"
},
"description": "A set of utilities for working with BIP32.",
"author": "Daniel Cousens",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dcousens/bip32-utils.git"
"url": "https://github.com/bitcoinjs/bip32-utils.git"
},
"author": "Daniel Cousens",
"license": "MIT",
"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": {},
"devDependencies": {
"bitcoinjs-lib": "^1.5.0",
"coveralls": "^2.11.2",
"istanbul": "^0.3.5",
"mocha": "^2.1.0"
"bitcoinjs-lib": "^1.5.8",
"blanket": "*",
"mocha": "*",
"standard": "*",
"travis-cov": "*"
}
}
@@ -1,26 +1,26 @@
var AddressIterator = require('./iterator')

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

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.getExternalAddress = function() { return this.external.get() }
Account.prototype.getInternalAddress = function() { return this.internal.get() }
Account.prototype.getNetwork = function() { return this.external.node.network }
Account.prototype.getNode = function(address, external, internal) {
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.getExternalAddress = function () { return this.external.get() }
Account.prototype.getInternalAddress = function () { return this.internal.get() }
Account.prototype.getNetwork = function () { return this.external.node.network }
Account.prototype.getNode = function (address, external, internal) {
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
internal = internal || this.internal.node

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

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

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

Account.prototype.isExternalAddress = function(address) { return address in this.external.map }
Account.prototype.isInternalAddress = function(address) { return address in this.internal.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.nextExternalAddress = function() { return this.external.next() }
Account.prototype.nextInternalAddress = function() { return this.internal.next() }
Account.prototype.nextExternalAddress = function () { return this.external.next() }
Account.prototype.nextInternalAddress = function () { return this.internal.next() }

module.exports = Account
@@ -1,9 +1,9 @@
// 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 checked = 0

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

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

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

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

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

cycle()
})
})()
}

cycle()
}
@@ -1,4 +1,4 @@
function AddressIterator(node, k) {
function AddressIterator (node, k) {
k = k || 0

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

AddressIterator.prototype.get = function() {
AddressIterator.prototype.get = function () {
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
}

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

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

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

return xpub.getAddress().toString()
}

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

delete this.map[address]

0 comments on commit 39dade6

Please sign in to comment.
You can’t perform that action at this time.