<commit_before># 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)


## Examples

BIP32 [Used] Address discovery

``` javascript
var bip32utils = require('bip32-utils')
var bitcoin = require('bitcoinjs-lib')
var Helloblock = require('cb-helloblock')

// ...

var blockchain = new Helloblock('testnet')
var hdNode = bitcoin.HDNode.fromSeedHex(seedHex)
var iterator = bip32utils.AddressIterator(hdNode)
var GAP_LIMIT = 20

bip32utils.discovery(iterator, GAP_LIMIT, function(addresses, callback) {
  blockchain.addresses.summary(addresses, function(err, results) {
    if (err) return callback(err)

    var areUsed = results.map(function(result) {
      return result.totalReceived > 0
    })

    callback(undefined, areUsed)
  })
}, function(err, k, n) {
  if (err) throw err

  console.log('Discovered ' + k + ' [new] addresses in use...')
  console.log('Checked ' + n + ' addresses')
  console.log('Checked ' + (n - k) + ' unused addresses')

  // throw away unused addresses
  for (var i = 0; i < n - k; ++i) {
	iterator.pop()
  }

  // n !== total, iterator may start at k > 0
  console.log('Total number of used addresses: ', iterator.addresses.length)
})
```


BIP32 Account
``` javascript
var bitcoin = require('bitcoinjs-lib')
var bip32utils = require('bip32-utils')

// ...

var hdNode = bitcoin.HDNode.fromSeedHex(seedHex)
var external = hdNode.derive(0)
var internal = hdNode.derive(1)
var account = new bip32utils.Account(external.neutered(), internal.neutered())

console.log(account.getAddress())
// => 1QEj2WQD9vxTzsGEvnmLpvzeLVrpzyKkGt<commit_msg>README: update discovery example variable explanations<commit_after># 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)


## Examples

BIP32 [Used] Address discovery

``` javascript
var bip32utils = require('bip32-utils')
var bitcoin = require('bitcoinjs-lib')
var Helloblock = require('cb-helloblock')

// ...

var blockchain = new Helloblock('testnet')
var hdNode = bitcoin.HDNode.fromSeedHex(seedHex)
var iterator = bip32utils.AddressIterator(hdNode)
var GAP_LIMIT = 20

bip32utils.discovery(iterator, GAP_LIMIT, function(addresses, callback) {
  blockchain.addresses.summary(addresses, function(err, results) {
    if (err) return callback(err)

    var areUsed = results.map(function(result) {
      return result.totalReceived > 0
    })

    callback(undefined, areUsed)
  })
}, function(err, n, k) {
  if (err) throw err

  console.log('Discovered ' + n + ' [new] addresses in use...')
  console.log('Checked ' + k + ' addresses')
  console.log('Checked ' + (k - n) + ' more than necessary')

  // throw away unused addresses
  for (var i = 0; i < (k - n); ++i) {
	iterator.pop()
  }

  // k !== total, iterator may start at a k > 0
  console.log('Total number of used addresses: ', iterator.addresses.length)
})
```


BIP32 Account
``` javascript
var bitcoin = require('bitcoinjs-lib')
var bip32utils = require('bip32-utils')

// ...

var hdNode = bitcoin.HDNode.fromSeedHex(seedHex)
var external = hdNode.derive(0)
var internal = hdNode.derive(1)
var account = new bip32utils.Account(external.neutered(), internal.neutered())

console.log(account.getAddress())
// => 1QEj2WQD9vxTzsGEvnmLpvzeLVrpzyKkGt
{'fraction_non_alphanumeric': 0.15988372093023256, 'fraction_numerical': 0.022198731501057084, 'mean_word_length': 4.438218390804598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6086360', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1332, 'n_words': 260}