decred

package
v0.16.10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package blake256 implements BLAKE-256 and BLAKE-224 hash functions (SHA-3 candidate).

Index

Constants

View Source
const (
	// ErrUnsupportedAddress indicates that an address successfully decoded, but
	// is not a supported/recognized type.
	ErrUnsupportedAddress = ErrorKind("ErrUnsupportedAddress")

	// ErrUnsupportedScriptVersion indicates that an address type does not
	// support a given script version.
	ErrUnsupportedScriptVersion = ErrorKind("ErrUnsupportedScriptVersion")

	// ErrMalformedAddress indicates an address failed to decode.
	ErrMalformedAddress = ErrorKind("ErrMalformedAddress")

	// ErrMalformedAddressData indicates an address successfully decoded and is
	// a recognized type, but the encoded data is not the expected length.
	ErrMalformedAddressData = ErrorKind("ErrMalformedAddressData")

	// ErrBadAddressChecksum indicates an address failed to decode due to an
	// invalid checksum.
	ErrBadAddressChecksum = ErrorKind("ErrBadAddressChecksum")

	// ErrInvalidPubKey indicates that a serialized public key failed to
	// parse.
	ErrInvalidPubKey = ErrorKind("ErrInvalidPubKey")

	// ErrInvalidPubKeyFormat indicates that a serialized public key parsed
	// successfully, but is not one of the allowed formats.
	ErrInvalidPubKeyFormat = ErrorKind("ErrInvalidPubKeyFormat")

	// ErrInvalidHashLen indicates that either a public key hash or a script
	// hash is not an allowed length.
	ErrInvalidHashLen = ErrorKind("ErrInvalidHashLen")
)

These constants are used to identify a specific ErrorKind.

View Source
const BlockSize = 64

BlockSize is the block size of the hash algorithm in bytes.

View Source
const Size = 32

Size is the size of BLAKE-256 hash in bytes.

View Source
const Size224 = 28

Size224 is the size of BLAKE-224 hash in bytes.

Variables

View Source
var (
	DecredChainBase string
	DecredChainId   crypto.Hash
)
View Source
var ErrChecksum = errors.New("checksum error")

ErrChecksum indicates that the checksum of a check-encoded string does not verify against the checksum.

View Source
var ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing")

ErrInvalidFormat indicates that the check-encoded string has an invalid format.

Functions

func CheckDecode added in v0.13.6

func CheckDecode(input string) ([]byte, [2]byte, error)

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

func DecodeAddressV0 added in v0.13.6

func DecodeAddressV0(addr string, params AddressParamsV0) error

DecodeAddressV0 decodes the string encoding of an address and returns the relevant Address if it is a valid encoding for a known version 0 address type and is for the network identified by the provided parameters.

func GenerateAssetId

func GenerateAssetId(assetKey string) crypto.Hash

func New added in v0.13.6

func New() hash.Hash

New returns a new hash.Hash computing the BLAKE-256 checksum.

func New224 added in v0.13.6

func New224() hash.Hash

New224 returns a new hash.Hash computing the BLAKE-224 checksum.

func New224Salt added in v0.13.6

func New224Salt(salt []byte) hash.Hash

New224Salt is like New224 but initializes salt with the given 16-byte slice.

func NewSalt added in v0.13.6

func NewSalt(salt []byte) hash.Hash

NewSalt is like New but initializes salt with the given 16-byte slice.

func Sum224 added in v0.13.6

func Sum224(data []byte) (sum224 [Size224]byte)

Sum224 returns the BLAKE-224 checksum of the data.

func Sum256 added in v0.13.6

func Sum256(data []byte) [Size]byte

Sum256 returns the BLAKE-256 checksum of the data.

func VerifyAddress

func VerifyAddress(address string) error

func VerifyAssetKey

func VerifyAssetKey(assetKey string) error

func VerifyTransactionHash

func VerifyTransactionHash(hash string) error

Types

type AddressParamsV0 added in v0.13.6

type AddressParamsV0 interface {
	// AddrIDPubKeyV0 returns the magic prefix bytes for version 0 pay-to-pubkey
	// addresses.
	AddrIDPubKeyV0() [2]byte

	// AddrIDPubKeyHashECDSAV0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey is secp256k1 and
	// the signature algorithm is ECDSA.
	AddrIDPubKeyHashECDSAV0() [2]byte

	// AddrIDPubKeyHashEd25519V0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey and signature
	// algorithm are Ed25519.
	AddrIDPubKeyHashEd25519V0() [2]byte

	// AddrIDPubKeyHashSchnorrV0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey is secp256k1 and
	// the signature algorithm is Schnorr.
	AddrIDPubKeyHashSchnorrV0() [2]byte

	// AddrIDScriptHashV0 returns the magic prefix bytes for version 0
	// pay-to-script-hash addresses.
	AddrIDScriptHashV0() [2]byte
}

AddressParamsV0 defines an interface that is used to provide the parameters required when encoding and decoding addresses for version 0 scripts. These values are typically well-defined and unique per network.

type Error added in v0.13.6

type Error struct {
	Err         error
	Description string
}

Error identifies an address-related error.

It has full support for errors.Is and errors.As, so the caller can ascertain the specific reason for the error by checking the underlying error.

func (Error) Error added in v0.13.6

func (e Error) Error() string

Error satisfies the error interface and prints human-readable errors.

func (Error) Unwrap added in v0.13.6

func (e Error) Unwrap() error

Unwrap returns the underlying wrapped error.

type ErrorKind added in v0.13.6

type ErrorKind string

ErrorKind identifies a kind of error.

func (ErrorKind) Error added in v0.13.6

func (e ErrorKind) Error() string

Error satisfies the error interface and prints human-readable errors.

Jump to

Keyboard shortcuts

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