Documentation
¶
Index ¶
- Constants
- func IsValidKind(k byte) bool
- func ParseKind(i interface{}) (byte, error)
- type Address
- func (z *Address) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Address) EncodeMsg(en *msgp.Writer) (err error)
- func (z Address) Kind() byte
- func (z Address) MarshalMsg(b []byte) (o []byte, err error)
- func (a Address) MarshalText() ([]byte, error)
- func (z Address) Msgsize() (s int)
- func (z Address) Revalidate() error
- func (z Address) String() string
- func (z *Address) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (a *Address) UnmarshalText(text []byte) error
- type Error
Constants ¶
const ( KindUser byte = 'a' KindNdau byte = 'n' KindEndowment byte = 'e' KindExchange byte = 'x' KindBPC byte = 'b' KindMarketMaker byte = 'm' )
predefined address kinds
const AddrLength = 48
AddrLength is the length of the generated address, in characters
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.
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 ¶
IsValidKind returns true if the last letter of a is one of the currently-valid kinds
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 ¶
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 ¶
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (Address) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (Address) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (Address) Revalidate ¶
Revalidate this address to ensure it is legitimate
func (Address) String ¶
String gives us a human-readable form of an address, because sometimes we just need that.
func (*Address) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
func (*Address) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler