npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hdkey

v2.1.0

Published

Bitcoin BIP32 hierarchical deterministic keys

Downloads

184,200

Readme

hdkey

NPM Package build status js-standard-style

A JavaScript component for BIP32(hierarchical deterministic keys).

Installation

npm i --save hdkey

Usage

example:

var HDKey = require('hdkey')
var seed = 'a0c42a9c3ac6abf2ba6a9946ae83af18f51bf1c9fa7dacc4c92513cc4dd015834341c775dcd4c0fac73547c5662d81a9e9361a0aac604a73a321bd9103bce8af'
var hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'))
console.log(hdkey.privateExtendedKey)
// => 'xprv9s21ZrQH143K2SKJK9EYRW3Vsg8tWVHRS54hAJasj1eGsQXeWDHLeuu5hpLHRbeKedDJM4Wj9wHHMmuhPF8dQ3bzyup6R7qmMQ1i1FtzNEW'
console.log(hdkey.publicExtendedKey)
// => 'xpub661MyMwAqRbcEvPmRAmYndzERhyNux1GoHzHxgzVHMBFkCro3kbbCiDZZ5XabZDyXPj5mH3hktvkjhhUdCQxie5e1g4t2GuAWNbPmsSfDp2'

HDKey.fromMasterSeed(seedBuffer[, versions])

Creates an hdkey object from a master seed buffer. Accepts an optional versions object.

var seed = 'a0c42a9c3ac6abf2ba6a9946ae83af18f51bf1c9fa7dacc4c92513cc4dd015834341c775dcd4c0fac73547c5662d81a9e9361a0aac604a73a321bd9103bce8af'
var hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'))

HDKey.fromExtendedKey(extendedKey[, versions, skipVerification])

Creates an hdkey object from a xprv or xpub extended key string. Accepts an optional versions object & an optional skipVerification boolean. If skipVerification is set to true, then the provided public key's x (and y if uncompressed) coordinate will not will be verified to be on the curve.

var key = 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
var hdkey = HDKey.fromExtendedKey(key)

or

var key = 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
var hdkey = HDKey.fromExtendedKey(key)

HDKey.fromJSON(obj)

Creates an hdkey object from an object created via hdkey.toJSON().


hdkey.derive(path)

Derives the hdkey at path from the current hdkey.

var seed = 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
var hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'))
var childkey = hdkey.derive("m/0/2147483647'/1")

console.log(childkey.privateExtendedKey)
// -> "xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef"
console.log(childkey.publicExtendedKey)
// -> "xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon"

Newer, "hardened" derivation paths look like this:

// as defined by BIP-44
var childkey = hdkey.derive("m/44'/0'/0'/0/0");

hdkey.sign(hash)

Signs the buffer hash with the private key using secp256k1 and returns the signature as a buffer.

hdkey.verify(hash, signature)

Verifies that the signature is valid for hash and the hdkey's public key using secp256k1. Returns true for valid, false for invalid. Throws if the hash or signature is the wrong length.

hdkey.wipePrivateData()

Wipes all record of the private key from the hdkey instance. After calling this method, the instance will behave as if it was created via HDKey.fromExtendedKey(xpub).

hdkey.toJSON()

Serializes the hdkey to an object that can be JSON.stringify()ed.

var seed = 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
var hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'))

console.log(hdkey.toJSON())
// -> {
//      xpriv: 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U',
//      xpub: 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
//    }

hdkey.privateKey

Getter/Setter of the hdkey's private key, stored as a buffer.

hdkey.publicKey

Getter/Setter of the hdkey's public key, stored as a buffer.

hdkey.privateExtendedKey

Getter/Setter of the hdkey's xprv, stored as a string.

hdkey.publicExtendedKey

Getter/Setter of the hdkey's xpub, stored as a string.

References

  • https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/hdnode.js
  • http://bip32.org/
  • http://blog.richardkiss.com/?p=313
  • https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
  • http://bitcoinmagazine.com/8396/deterministic-wallets-advantages-flaw/

License

MIT