Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateSeed(n uint8) ([]byte, error)
- type HDKey
- func (k *HDKey) Child(i uint32) (*HDKey, error)
- func (k *HDKey) CompressedPublicKey() *eckey.CompressedPublicKey
- func (k *HDKey) IsPrivate() bool
- func (k *HDKey) Neuter(vMap VersionMap) (*HDKey, error)
- func (k *HDKey) PublicKey() *eckey.PublicKey
- func (k *HDKey) SecretKey() (*eckey.SecretKey, error)
- func (k *HDKey) String() string
- func (k *HDKey) Zero()
- type VersionMap
Constants ¶
const ( // Minimum seed size to create master key. MinSeedSize = 16 // Recommended seed size to create master key. RecommendedSeedSize = 32 // Maximum seed size to create master key. MaxSeedSize = 64 )
const ( // Total size of an HDKey in bytes. HDKeySize = versionSize + depthSize + fingerprintSize + childNumberSize + chainCodeSize + childKeySize // 76 bytes )
const HardenedKeyStart = 0x80000000
Start of hardened key indexes, 2^31
Variables ¶
var ( // ErrDeriveHardenedFromPublic indicates that an attempt was made to derive a // hardened key from a public key. ErrDeriveHardenedFromPublic = errors.New("Cannot derive hardened key from " + "public key") // ErrInvalidKeyLength indicates an attempt to decode an HDKey that is not // HDKeySize bytes in length. ErrInvalidKeyLength = errors.New("Invalid key length") // ErrInvalidSeedLength indicates that the provided seed length is less than // MinSeedSize or greater that MaxSeedSize. ErrInvalidSeedLength = fmt.Errorf("Seed length must be between %d and %d "+ "bytes", MinSeedSize, MaxSeedSize) // ErrNotPrivHDKey indicates that an attempt was made to access the secret key // of a public HD key, which is not possible. ErrNotPrivHDKey = errors.New("Cannot get secret key from public key") // ErrUnknownVersionMapping indicates that the provided VersionMap does not // provide a mapping from the given private version to its public version. ErrUnknownVersionMapping = errors.New("Unknown version mapping") // ErrUnusableSeed indicates that the provided seed produces a secret key // greater than the order of secp256k1 or it's associated public key is the // point at infinity. ErrUnusableSeed = errors.New("Seed produces invalid key") )
Functions ¶
func GenerateSeed ¶
GenerateSeed produces a cryptographically secure seed consisting of n bytes.
Types ¶
type HDKey ¶
HDKey stores an extended key's version, depth, child number, chain code, parent fingerprint, and derived public or private key.
func New ¶
NewKeyFromString decodes a hex encoded string, verifies the included checksum, and checks that the public key is on the secp256k1 curve.
func NewMaster ¶
NewMasterHDKey computes the root HD key from the given seed, key and private version.
func (*HDKey) CompressedPublicKey ¶
func (k *HDKey) CompressedPublicKey() *eckey.CompressedPublicKey
CompressedPublicKey returns the associated compressed public key of an HDKey. If the HDKey corresponds to a public key, the derived key is copied and returned. Otherwise, the public key is computed from the secret key and subsequently compressed.
func (*HDKey) IsPrivate ¶
IsPrivate returns a boolean denoting whether the HDKey belongs to private key.
func (*HDKey) Neuter ¶
func (k *HDKey) Neuter(vMap VersionMap) (*HDKey, error)
Neuter converts a private HDKey into a public HDKey, effectively removing the signing capabilities.
func (*HDKey) PublicKey ¶
PublicKey returns the associated public key of an HDKey. If the HDKey corresponds to a secret key, the public key is computed and returned. Otherwise, if the HDKey corresponds to a compressed public key, the public key is decompressed and returned. No error handling is during these operations, as it is assumes the HDKey is uncorrupted.
func (*HDKey) SecretKey ¶
SecretKey returns the secret key belonging to an HDKey. This method returns an error if the HDKey corresponds to a compressed public key, since the secret key cannot be recovered.
type VersionMap ¶
VersionMap stores a mapping from private to public magic version constants for multiple networks.