address

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 6 Imported by: 31

Documentation

Index

Constants

View Source
const (
	KindUser        byte = 'a'
	KindNdau        byte = 'n'
	KindEndowment   byte = 'e'
	KindExchange    byte = 'x'
	KindBPC         byte = 'b'
	KindMarketMaker byte = 'm'
)

predefined address kinds

View Source
const AddrLength = 48

AddrLength is the length of the generated address, in characters

View Source
const HashTrim = 26

HashTrim is the number of bytes that we trim the input hash to.

We don't want any dead characters, so since we trim the generated SHA hash anyway, we trim it to a length that plays well with the above, meaning that we want it to pad the result out to a multiple of 5 bytes so that a byte32 encoding has no filler).

Note that ETH does something similar, and uses a 20-byte subset of a 32-byte hash. The possibility of collision is low: As of June 2018, the BTC hashpower is 42 exahashes per second. If that much hashpower is applied to this problem, the likelihood of generating a collision in one year is about 1 in 10^19.

View Source
const MinDataLength = 12

MinDataLength is the minimum acceptable length for the data to be used as input to generate. This will prevent simple errors like trying to create an address from an empty key.

Variables

This section is empty.

Functions

func IsValidKind

func IsValidKind(k byte) bool

IsValidKind returns true if the last letter of a is one of the currently-valid kinds

func ParseKind

func ParseKind(i interface{}) (byte, error)

ParseKind returns a Kind or an explanation of why the supplied value is not one.

Types

type Address

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

An Address is a 48-character string uniquely identifying an Ndau account

For type-safety purposes, it is an opaque struct. This should help make it difficult to accidentally pass in a wrong string or something: so long as one gets an Address by means of the Generate or Validate functions, it is known to be good.

func Generate

func Generate(kind byte, data []byte) (Address, error)

Generate creates an address of a given kind from an array of bytes (which would normally be a public key). It is an error if len(data) < MinDataLength or if kind is not a valid kind. Since length changes are explicitly disallowed, we can use a relatively simple crc model to have a short (16-bit) checksum and still be quite safe against transposition and typos.

func Validate

func Validate(addr string) (Address, error)

Validate tests if an address is valid on its face. It checks the address kind, and the checksum. It does NOT test the nd prefix, as that may vary -- clients should test that themselves.

func (*Address) DecodeMsg

func (z *Address) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Address) EncodeMsg

func (z Address) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Address) Kind

func (z Address) Kind() byte

Kind returns the kind byte of the address.

func (Address) MarshalMsg

func (z Address) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Address) Msgsize

func (z Address) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Address) Revalidate

func (z Address) Revalidate() error

Revalidate this address to ensure it is legitimate

func (Address) String

func (z Address) String() string

String gives us a human-readable form of an address, because sometimes we just need that.

func (*Address) UnmarshalMsg

func (z *Address) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Error

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

Error is the type of all the errors this package returns

func (*Error) Error

func (a *Error) Error() string

Jump to

Keyboard shortcuts

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