Documentation ¶
Overview ¶
A Nyzo identity, represented by a private and public key pair. Offering some convenience conversions to Nyzo hex key notations and Nyzo strings. A nickname can be added optionally.
Index ¶
Constants ¶
const ( NyzoStringTypePrivateKey = 1 NyzoStringPrivateKeyPrefix = "key_" NyzoStringTypePublicKey = 2 NyzoStringPublicKeyPrefix = "id__" NyzoStringCharacters = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ-.~_" )
Variables ¶
var NyzoStringCharacterMap map[byte]int
Functions ¶
func BytesToNyzoHex ¶
BytesToNyzoHex converts the given byte array to a Nyzo style hex string with separating dashes.
func FromNyzoString ¶ added in v1.0.4
func NyzoHexToBytes ¶
NyzoHexToBytes converts 'data' - a sequence of hex character bytes - to a byte array of the defined length. So, [102 54] (aka 'f6') will turn into [246]. The function mimics the somewhat idiosyncratic behavior of the original java function by ignoring any non-hex characters in the input data. Like that, separator dashes ('-') will be filtered out, but so would any other non-hex characters. Also like the original function, we ignore if we get too much input data for the desired result length. We do however NOT ignore if we don't get enough input data, so unless there is an error returned, the result will always have the desired length.
func ToNyzoString ¶
ToNyzoString converts the given content data to a Nyzo string of the given type. A Nyzo string consists of: prefix + content length + content + checksum. In terms of its underlying byte array, the prefix is always 3 bytes long, the content length is expressed in one byte, then comes the content, and finally, the checksum is a minimum of 4 bytes and a maximum of 6 bytes, widening the expanded array so that its length is always divisible by 3. This byte arrray is then mapped to a select set of characters for human readability, resulting in what is commonly known as a "Nyzo String". TODO: only public and private key string types are supported, add the others: micropay, prefilled and transactions.
Types ¶
type Identity ¶
type Identity struct { PrivateKey ed25519.PrivateKey // the private key (native format) PublicKey ed25519.PublicKey // the public key (native format) PrivateHex string // hexadecimal dashed representation of the private key PublicHex string // hexadecimal dashed representation of the public key ShortId string // a short identifier based on the public key hex (ab03...de78) Nickname string // the user defined Nyzo nickname, used for display only NyzoStringPrivate string // typed, error-protected encoding of the private key NyzoStringPublic string // typed, error-protected encoding of the public key }
func FromPrivateKey ¶
Generate an ID from a private key directly.
func FromPrivateKeyFile ¶
Load an identity from a private key file.
func New ¶
Creates a new identity and saves info about it to the given files. Existing files will be overwritten, so the caller must make sure that no private key info gets unintentionally lost along the way.
func (*Identity) LoadNicknameFromFile ¶
Loads the user-defined nickname from the given file (if not possible, the ShortId is taken as a nick).