cashaddr

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"

Variables

View Source
var (
	// ErrChecksumMismatch describes an error where decoding failed due
	// to a bad checksum.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// ErrUnknownAddressType describes an error where an address can not
	// decoded as a specific address type due to the string encoding
	// beginning with an identifier byte unknown to any standard or
	// registered (via chaincfg.Register) network.
	ErrUnknownAddressType = errors.New("unknown address type")

	// 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.  Rather
	// than assuming or defaulting to one or the other, this error is
	// returned and the caller must decide how to decode the address.
	ErrAddressCollision = errors.New("address collision")

	// ErrInvalidFormat describes an error where decoding failed due to invalid version
	ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing")

	Prefixes map[string]string
)
View Source
var CharsetRev = [128]int8{}/* 128 elements not displayed */

Functions

func CashPayToAddrScript added in v0.0.3

func CashPayToAddrScript(addr Address) ([]byte, error)

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

func CheckEncodeCashAddress

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

func Encode

func Encode(prefix string, payload Data) string

func LowerCase

func LowerCase(c byte) byte

func PolyMod

func PolyMod(v Data) uint64

func VerifyChecksum

func VerifyChecksum(prefix string, payload Data) bool

Types

type Address

type Address interface {
	// String returns the string encoding of the transaction output
	// destination.
	//
	// Please note that String differs subtly from EncodeAddress: String
	// will return the value as a string without any conversion, while
	// EncodeAddress may convert destination types (for example,
	// converting pubkeys to P2PKH addresses) before encoding as a
	// payment address string.
	String() string

	// EncodeAddress returns the string encoding of the payment address
	// associated with the Address value.  See the comment on String
	// for how this method differs from String.
	EncodeAddress() string

	// ScriptAddress returns the raw bytes of the address to be used
	// when inserting the address into a txout's script.
	ScriptAddress() []byte

	// IsForNet returns whether or not the address is associated with the
	// passed bitcoin network.
	IsForNet(*model.BitcoinParams) bool
}

func DecodeAddress

func DecodeAddress(addr string, defaultNet *model.BitcoinParams) (Address, error)

DecodeAddress 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 ExtractPkScriptAddrs

func ExtractPkScriptAddrs(pkScript []byte, chainParams *model.BitcoinParams) (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.

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.

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 *model.BitcoinParams) (*CashAddressPubKeyHash, error)

NewCashAddressPubKeyHash returns a new AddressPubKeyHash. 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 *model.BitcoinParams) 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 *model.BitcoinParams) (*CashAddressScriptHash, error)

NewCashAddressScriptHash returns a new AddressScriptHash.

func NewCashAddressScriptHashFromHash

func NewCashAddressScriptHashFromHash(scriptHash []byte, net *model.BitcoinParams) (*CashAddressScriptHash, error)

NewCashAddressScriptHashFromHash returns a new AddressScriptHash. 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 *model.BitcoinParams) 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.

type Data

type Data []byte

func Cat

func Cat(x, y Data) Data

func CreateChecksum

func CreateChecksum(prefix string, payload Data) Data

func DecodeCashAddress

func DecodeCashAddress(str string) (string, Data, error)

func ExpandPrefix

func ExpandPrefix(prefix string) Data

Jump to

Keyboard shortcuts

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