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-wasm

v1.2.0

Published

Bitcoin BIP32 hierarchical deterministic keys, uses bitcoin-ts as its base instead of secp256k1-node

Downloads

17

Readme

hdkey

NPM Package

A stripped down version of BIP32(hierarchical deterministic keys). This version only derives pure, non-extended private keys. Intended to be used with bitcoin-ts as its base. Forked from hdkey

Installation

npm i --save hdkey-wasm

Usage

example:

const bitcoinTs = require('bitcoin-ts');
const {instantiatePbkdf2} = require('pbkdf2-wasm');
const {HDKey, initializeHDKey} = require('hdkey-wasm');
await initializeHDKey(bitcoinTs.instantiateSecp256k1(), instantiatePbkdf2(bitcoinTs.instantiateSha512()));

const seed = 'a0c42a9c3ac6abf2ba6a9946ae83af18f51bf1c9fa7dacc4c92513cc4dd015834341c775dcd4c0fac73547c5662d81a9e9361a0aac604a73a321bd9103bce8af'
let hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'));
console.log(hdkey.privateKey)
// => <Uint8Array 15 49 3c 2b e2 a4 15 9c d9 82 b9 3c af 3d 70 5f d2 9b 9b ac 77 80 31 ca ea 21 6e fb eb fe 24 78>
console.log(hdkey.publicKey)
// => <Uint8Array 02 2a ec b9 22 ae 00 1d 9d 0c b9 69 27 e5 50 ee 6c fd 60 74 1a c6 27 f1 02 89 fe 2c 29 3b 3c 73 41>

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.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.privateKey)
// -> <Uint8Array 70 4a dd f5 44 a0 6e 5e e4 be a3 70 98 46 3c 23 61 3d a3 20 20 d6 04 50 6d a8 c0 51 8e 1d a4 b7>
console.log(childkey.publicKey)
// -> <Uint8Array 03 a7 d1 d8 56 de b7 4c 50 8e 05 03 1f 98 95 da b5 46 26 25 1b 38 06 e1 6b 4b d1 2e 78 1a 7d f5 b9>

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.

hdkey.privateKey

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

hdkey.publicKey

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

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