Categorygithub.com/btcsuite/btcutil
modulepackage
1.0.2
Repository: https://github.com/btcsuite/btcutil.git
Documentation: pkg.go.dev

# README

btcutil

Build Status Coverage Status ISC License GoDoc

Package btcutil provides bitcoin-specific convenience functions and types. A comprehensive suite of tests is provided to ensure proper functionality. See test_coverage.txt for the gocov coverage report. Alternatively, if you are running a POSIX OS, you can run the cov_report.sh script for a real-time report.

This package was developed for btcd, an alternative full-node implementation of bitcoin which is under active development by Conformal. Although it was primarily written for btcd, this package has intentionally been designed so it can be used as a standalone package for any projects needing the functionality provided.

Installation and Updating

$ go get -u github.com/btcsuite/btcutil

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from the btcsuite developers. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btcutil is licensed under the copyfree ISC License.

# Packages

Package base58 provides an API for working with modified base58 and Base58Check encodings.
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.
Package gcs provides an API for building and using a Golomb-coded set filter.
Package hdkeychain provides an API for bitcoin hierarchical deterministic extended keys (BIP0032).
Package psbt is an implementation of Partially Signed Bitcoin Transactions (PSBT).
Package txsort provides the transaction sorting according to BIP 69.

# Functions

AppDataDir returns an operating system specific directory to be used for storing application data for an application.
DecodeAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type.
DecodeWIF creates a new WIF structure by decoding the string encoding of the import format.
Hash160 calculates the hash ripemd160(sha256(b)).
NewAddressPubKey returns a new AddressPubKey which represents a pay-to-pubkey address.
NewAddressPubKeyHash returns a new AddressPubKeyHash.
NewAddressScriptHash returns a new AddressScriptHash.
NewAddressScriptHashFromHash returns a new AddressScriptHash.
NewAddressWitnessPubKeyHash returns a new AddressWitnessPubKeyHash.
NewAddressWitnessScriptHash returns a new AddressWitnessPubKeyHash.
NewAmount creates an Amount from a floating point value representing some value in bitcoin.
NewBlock returns a new instance of a bitcoin block given an underlying wire.MsgBlock.
NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given an underlying wire.MsgBlock and the serialized bytes for it.
NewBlockFromBytes returns a new instance of a bitcoin block given the serialized bytes.
NewBlockFromReader returns a new instance of a bitcoin block given a Reader to deserialize the block.
NewTLSCertPair returns a new PEM-encoded x.509 certificate pair based on a 521-bit ECDSA private key.
NewTx returns a new instance of a bitcoin transaction given an underlying wire.MsgTx.
NewTxFromBytes returns a new instance of a bitcoin transaction given the serialized bytes.
NewTxFromReader returns a new instance of a bitcoin transaction given a Reader to deserialize the transaction.
NewWIF creates a new WIF structure to export an address and its private key as a string encoded in the Wallet Import Format.

# Constants

These constants define various units used when describing a bitcoin monetary amount.
These constants define various units used when describing a bitcoin monetary amount.
These constants define various units used when describing a bitcoin monetary amount.
These constants define various units used when describing a bitcoin monetary amount.
These constants define various units used when describing a bitcoin monetary amount.
These constants define various units used when describing a bitcoin monetary amount.
BlockHeightUnknown is the value returned for a block height that is unknown.
MaxSatoshi is the maximum transaction amount allowed in satoshi.
PKFCompressed indicates the pay-to-pubkey address format is a compressed public key.
PKFHybrid indicates the pay-to-pubkey address format is a hybrid public key.
PKFUncompressed indicates the pay-to-pubkey address format is an uncompressed public key.
SatoshiPerBitcent is the number of satoshi in one bitcoin cent.
SatoshiPerBitcoin is the number of satoshi in one bitcoin (1 BTC).
TxIndexUnknown is the value returned for a transaction index that is unknown.

# Variables

ErrAddressCollision describes an error where an address can not be uniquely determined as either a pay-to-pubkey-hash or pay-to-script-hash address since the leading identifier is used for describing both address kinds, but for different networks.
ErrChecksumMismatch describes an error where decoding failed due to a bad checksum.
ErrMalformedPrivateKey describes an error where a WIF-encoded private key cannot be decoded due to being improperly formatted.
ErrUnknownAddressType describes an error where an address can not decoded as a specific address type due to the string encoding begining with an identifier byte unknown to any standard or registered (via chaincfg.Register) network.

# Structs

AddressPubKey is an Address for a pay-to-pubkey transaction.
AddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.
AddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction.
AddressWitnessPubKeyHash is an Address for a pay-to-witness-pubkey-hash (P2WPKH) output.
AddressWitnessScriptHash is an Address for a pay-to-witness-script-hash (P2WSH) output.
Block defines a bitcoin block that provides easier and more efficient manipulation of raw blocks.
Tx defines a bitcoin transaction that provides easier and more efficient manipulation of raw transactions.
WIF contains the individual components described by the Wallet Import Format (WIF).

# Interfaces

Address is an interface type for any type of destination a transaction output may spend to.

# Type aliases

Amount represents the base bitcoin monetary unit (colloquially referred to as a `Satoshi').
AmountUnit describes a method of converting an Amount to something other than the base unit of a bitcoin.
OutOfRangeError describes an error due to accessing an element that is out of range.
PubKeyFormat describes what format to use for a pay-to-pubkey address.
UnsupportedWitnessProgLenError describes an error where a segwit address being decoded has an unsupported witness program length.
UnsupportedWitnessVerError describes an error where a segwit address being decoded has an unsupported witness version.