Documentation
¶
Index ¶
Constants ¶
const ( MIN_KEY_LENGTH = 2 MAX_KEY_LENGTH = 256 )
Minimum and maximum key lengths in bytes.
const ( IDENTITY = uint64(0x00) ED_25519 = uint64(0x11) BIP_32 = uint64(0x22) DSA = uint64(0x33) RSA = uint64(0x44) )
Support ciphers. Accepting PRs for more!
Variables ¶
var ( ErrUnknownCode = errors.New("unknown multikeypair code") ErrTooShort = errors.New("multikeypair too short. must be >= 2 bytes") ErrTooLong = errors.New("multikeypair too long. must be < 129 bytes") ErrInvalidMultikeypair = errors.New("input isn't valid multikeypair") ErrVarintBufferShort = errors.New("uvarint: buffer too small") ErrVarintTooLong = errors.New("uvarint: varint too big (max 64bit)") )
Keypair-specific errors this module exports.
var Codes = map[uint64]string{ IDENTITY: "identity", ED_25519: "ed25519", BIP_32: "bip32", DSA: "dsa", RSA: "rsa", }
Codes is a mapping from cipher code to name.
var Names = map[string]uint64{ "identity": IDENTITY, "ed25519": ED_25519, "bip32": BIP_32, "dsa": DSA, "res": RSA, }
Names is a mapping from cipher name to code.
Functions ¶
func UnpackCode ¶
UnpackCode unpacks a varint cipher code.
Types ¶
type Keypair ¶
type Keypair struct { // Cipher identification code. Code uint64 // Human-readable cipher name. Name string // Raw public key bytes. Public []byte // Length in bytes of public key. PublicLength int // Raw private key bytes. Private []byte // Length in bytes of private key. PrivateLength int }
Keypair is a public/private keypair unpacked into a struct for easy access.
func Decode ¶
func Decode(m Multikeypair) (Keypair, error)
Decode unpacks a multikeypair into a Keypair struct.
func KeypairFromB58 ¶
KeypairFromB58 parses a base58-encoded hex string into a Keypair.
func (Keypair) Encode ¶
func (k Keypair) Encode() (Multikeypair, error)
Encode a Keypair struct into a Multikeypair.
type Multikeypair ¶
type Multikeypair []byte
Multikeypair is a byte slice with the following form: [length] (24-bit length prefix)
[code length]<code> (16-bit length prefix, uvarint code) [private key length]<private key> (16-bit length prefix) [public key length]<public key> (16-bit length prefix)
func Encode ¶
func Encode(private []byte, public []byte, code uint64) (Multikeypair, error)
Encode a keypair into a Multikeypair, specifying the keypair type using an integer code.
func EncodeName ¶
func EncodeName(private []byte, public []byte, name string) (Multikeypair, error)
EncodeName encodes a keypair into a Multikeypair, specifying the keypair type using a string name instead of an integer code.
func MultikeypairFromB58 ¶
func MultikeypairFromB58(s string) (Multikeypair, error)
MultikeypairFromB58 parses a base58-encoded hex string into a Multikeypair.
func (Multikeypair) B58String ¶
func (m Multikeypair) B58String() string
B58String generates a base58-encoded version of a Multikeypair.
func (Multikeypair) Decode ¶
func (m Multikeypair) Decode() (Keypair, error)
Decode unpacks a multikeypair into a Keypair struct.