This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
moneroutil/address.go
2017-04-24 17:19:04 -07:00

38 lines
760 B
Go

package moneroutil
import (
"bytes"
)
type Address struct {
network int
spendingKey []byte
viewingKey []byte
}
func (a *Address) Base58() (result string) {
prefix := []byte{byte(a.network)}
checksum := Checksum(prefix, a.spendingKey, a.viewingKey)
result = EncodeMoneroBase58(prefix, a.spendingKey, a.viewingKey, checksum)
return
}
func NewAddress(address string) (result *Address, err string) {
raw := DecodeMoneroBase58(address)
if len(raw) != 69 {
err = "Address is the wrong length"
return
}
checksum := Checksum(raw[:65])
if bytes.Compare(checksum, raw[65:]) != 0 {
err = "Checksum does not validate"
return
}
result = &Address{
network: int(raw[0]),
spendingKey: raw[1:33],
viewingKey: raw[33:65],
}
return
}