bch

package
v0.4.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

https://github.com/cpacia/bchutil/blob/master/cashaddr.go nolint: staticcheck, gomnd

Index

Constants

View Source
const CHARSET string = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"

Variables

View Source
var CHARSET_REV = [128]int8{}/* 128 elements not displayed */

CHARSET_REV The cashaddr character set for decoding. nolint: golint, revive, stylecheck

View Source
var Prefixes map[string]string

Functions

func Cat

func Cat(x, y []byte) []byte

Cat Concatenate two byte arrays.

func CheckEncodeCashAddress

func CheckEncodeCashAddress(input []byte, prefix string, t AddressType) string

func CreateChecksum

func CreateChecksum(prefix string, payload []byte) []byte

func DecodeBCHAddress

func DecodeBCHAddress(addr string, defaultNet *chaincfg.Params) (jaxutil.Address, error)

DecodeBCHAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type.

The bitcoin cash network the address is associated with is extracted if possible.

func DecodeCashAddress

func DecodeCashAddress(str string) (string, []byte, error)

nolint: stylecheck

func Encode

func Encode(prefix string, payload []byte) string

Encode a cashaddr string.

func ExpandPrefix

func ExpandPrefix(prefix string) []byte

ExpandPrefix expands the address prefix for the checksum computation. nolint: unconvert

func ExtractPkScriptAddrs

func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (jaxutil.Address, error)

ExtractPkScriptAddrs returns the type of script, addresses and required signatures associated with the passed PkScript. Note that it only works for 'standard' transaction script types. Any data such as public keys which are invalid are omitted from the results.

func JaxVanityPrefix added in v0.4.3

func JaxVanityPrefix(pkScript []byte) bool

func LowerCase

func LowerCase(c byte) byte

func PayToAddrScript

func PayToAddrScript(addr jaxutil.Address) ([]byte, error)

PayToAddrScript creates a new script to pay a transaction output to a the specified address.

func PolyMod

func PolyMod(v []byte) uint64

PolyMod is function will compute what 8 5-bit values to XOR into the last 8 input values, in order to make the checksum 0. These 8 values are packed together in a single 40-bit integer. The higher bits correspond to earlier values.

func VerifyChecksum

func VerifyChecksum(prefix string, payload []byte) bool

Types

type AddressType

type AddressType int
const (
	P2PKH AddressType = 0
	P2SH  AddressType = 1
)

func CheckDecodeCashAddress

func CheckDecodeCashAddress(input string) (result []byte, prefix string, t AddressType, err error)

CheckDecodeCashAddress decodes a string that was encoded with CheckEncode and verifies the checksum.

nolint: stylecheck

type CashAddressPubKeyHash

type CashAddressPubKeyHash struct {
	// contains filtered or unexported fields
}

CashAddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.

func NewCashAddressPubKeyHash

func NewCashAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*CashAddressPubKeyHash, error)

NewCashAddressPubKeyHash returns a new CashAddressPubKeyHash. pkHash mustbe 20 bytes.

func (*CashAddressPubKeyHash) EncodeAddress

func (a *CashAddressPubKeyHash) EncodeAddress() string

EncodeAddress returns the string encoding of a pay-to-pubkey-hash address. Part of the Address interface.

func (*CashAddressPubKeyHash) Hash160

func (a *CashAddressPubKeyHash) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*CashAddressPubKeyHash) IsForNet

func (a *CashAddressPubKeyHash) IsForNet(net *chaincfg.Params) bool

IsForNet returns whether or not the pay-to-pubkey-hash address is associated with the passed bitcoin cash network.

func (*CashAddressPubKeyHash) ScriptAddress

func (a *CashAddressPubKeyHash) ScriptAddress() []byte

ScriptAddress returns the bytes to be included in a txout script to pay to a pubkey hash. Part of the Address interface.

func (*CashAddressPubKeyHash) String

func (a *CashAddressPubKeyHash) String() string

String returns a human-readable string for the pay-to-pubkey-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.

type CashAddressScriptHash

type CashAddressScriptHash struct {
	// contains filtered or unexported fields
}

CashAddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction.

func NewCashAddressScriptHash

func NewCashAddressScriptHash(serializedScript []byte, net *chaincfg.Params) (*CashAddressScriptHash, error)

NewCashAddressScriptHash returns a new CashAddressScriptHash.

func NewCashAddressScriptHashFromHash

func NewCashAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*CashAddressScriptHash, error)

NewCashAddressScriptHashFromHash returns a new CashAddressScriptHash. scriptHash must be 20 bytes.

func (*CashAddressScriptHash) EncodeAddress

func (a *CashAddressScriptHash) EncodeAddress() string

EncodeAddress returns the string encoding of a pay-to-script-hash address. Part of the Address interface.

func (*CashAddressScriptHash) Hash160

func (a *CashAddressScriptHash) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the script hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*CashAddressScriptHash) IsForNet

func (a *CashAddressScriptHash) IsForNet(net *chaincfg.Params) bool

IsForNet returns whether or not the pay-to-script-hash address is associated with the passed bitcoin cash network.

func (*CashAddressScriptHash) ScriptAddress

func (a *CashAddressScriptHash) ScriptAddress() []byte

ScriptAddress returns the bytes to be included in a txout script to pay to a script hash. Part of the Address interface.

func (*CashAddressScriptHash) String

func (a *CashAddressScriptHash) String() string

String returns a human-readable string for the pay-to-script-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL