Commonly used bitcoin functions
npm install bitcoinutil --save
var bitcoinutil = require("bitcoinutil")
address: public key in base58 format returns: true for valid address
publicKey: public key in base58 format returns : public key in hex format
privateKey: in WIF format returns : address, privateKey and publicKey in an object
var priv = "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P"
bitcoinutil.addressFromPrivateKey(priv)
{
"address" : "mjsXa5HBdemtrjFZeLUB1D3NetupVNxFyN",
"privateKey": "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P",
"publicKey" : "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"
}
generates random key and return address, privateKey and publicKey in an object
{
"address" : "mjsXa5HBdemtrjFZeLUB1D3NetupVNxFyN",
"privateKey": "L56nAFJCUMuAUF1zp8e4Bhdq8S25kcFD5YrLTnys3ha8QK65dj8P",
"publicKey" : "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"
}
creates m of n multisig address from n public keys in hex format
var publicKeys = ["035da95734281849a327dea6402bd9c19f49bdd5b04f1cbb3136512984ec7b8d34", "03abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb515483"]
bitcoinutil.getMultisigAddress(2, publicKeys)
{
"address": "2N4htmodeibCZVtLKRX9EFg8RGL4xdifi6x",
"redeem" : "5221035da95734281849a327dea6402bd9c19f49bdd5b04f1cbb3136512984ec7b8d342103abeb481466887c35e046de4b504a029e03bd3a5e35b03c67fe7821f5fb51548352ae"
}
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
converts btc to satoshi
converts satoshi to btc
returns ripemd160 of sha256(input)
returns sha256 of sha256(input)
privateKey : private key in wif format used for signing message : Message to be signed returns signature in base64 format
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
tx : bitcoin transaction string represented in hex format result txid as will be displayed on bitcoin network