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

bitcoinutil

v3.0.2

Published

commonly used bitcoin functions

Downloads

17

Readme

Circle CI

bitcoinutil

Commonly used bitcoin functions

install

npm install bitcoinutil --save

import

var bitcoinutil = require("bitcoinutil")

methods

bitcoinutil.isValidBitcoinAddress(address)

address: public key in base58 format returns: true for valid address

bitcoinutil.toAddress(publicKey, 'testnet') or bitcoinutil.toAddress()

publicKey: public key in base58 format returns : public key in hex format

bitcoinutil.addressFromPrivateKey(privateKey)

privateKey: in WIF format returns : address, privateKey and publicKey in an object

example

var priv = "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P"
bitcoinutil.addressFromPrivateKey(priv)

result

{
    "address"   : "mjsXa5HBdemtrjFZeLUB1D3NetupVNxFyN",
    "privateKey": "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P",
    "publicKey" : "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"
}

bitcoinutil.makeRandom('testnet') or bitcoinutil.makeRandom()

generates random key and return address, privateKey and publicKey in an object

result

{
    "address"   : "mjsXa5HBdemtrjFZeLUB1D3NetupVNxFyN",
    "privateKey": "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P",
    "publicKey" : "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"
}

bitcoinutil.getMultisigAddress(m, publicKeys)

creates m of n multisig address from n public keys in hex format

example (2 of 2)

var publicKeys = ["035da95734281849a327dea6402bd9c19f49bdd5b04f1cbb3136512984ec7b8d34", "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"]
bitcoinutil.getMultisigAddress(2, publicKeys)

result

{
    "address": "2N4htmodeibCZVtLKRX9EFg8RGL4xdifi6x",
    "redeem" : "5221035da95734281849a327dea6402bd9c19f49bdd5b04f1cbb3136512984ec7b8d342103abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb51548352ae"
}

bitcoinutil.sign(tx, privateKey, redeem, isIncomplete)

tx : transaction to be signed (required) privateKey : private key used for signing (required) redeem : if multisig/p2sh, redeem script is required isIncomplete: value is true if tx is partially built i.e. more signatures are needed

bitcoinutil.satoshify(btc)

converts btc to satoshi

bitcoinutil.btcfy(satoshi)

converts satoshi to btc

bitcoinutil.hash160(input)

returns ripemd160 of sha256(input)

bitcoinutil.hash256(input)

returns sha256 of sha256(input)

bitcoinutil.signMessage(privateKey, message)

privateKey : private key in wif format used for signing message : Message to be signed returns signature in base64 format

bitcoinutil.verifyMessage(address, signature, message)

address : bitcoin address of the private key used in signing the message signature : signature of message in base64 format message : Message signed result true or false

bitcoinutil.getTxIdFromHex(tx)

tx : bitcoin transaction string represented in hex format result txid as will be displayed on bitcoin network