Documentation ¶
Overview ¶
Package slip10 implements the SLIP-0010 private key derivation. It only supports the private parent key → private child key derivation for the following curves:
secp256k1 curve NIST P-256 curve ed25519 curve
The public key of an SLIP-0010 extended private key can be computed using Curve.Public.
SLIP-0010 provides an extension of BIP-0032. As such, when the secp256k1 curve is selected this package is fully compatible to the corresponding derivations described in BIP-0032.
This package is tested against the test vectors provided in the official SLIP-0010 specification.
Index ¶
Constants ¶
const ( // FingerprintSize is the size, in bytes, of the key fingerprint. FingerprintSize = 4 // ChainCodeSize is the size, in bytes, of the chain code. ChainCodeSize = 32 // PrivateKeySize is the size, in bytes, of the normal private key. PrivateKeySize = 32 // PublicKeySize is the size, in bytes, of the normal public key. PublicKeySize = 33 // Hardened returns the first hardened index. Hardened uint32 = 1 << 31 )
Variables ¶
var ErrHardenedChildPublicKey = errors.New("cannot create hardened child from public parent key")
ErrHardenedChildPublicKey is returned when ExtendedKey.DeriveChild is called with a hardened index on a public key.
var ErrInvalidKey = errors.New("invalid key")
ErrInvalidKey is returned when the input led to an invalid private or public key.
Functions ¶
This section is empty.
Types ¶
type Curve ¶
type Curve interface { // Name returns the canonical name of the curve. Name() string // HmacKey returns the HMAC key used for the master key generation. HmacKey() []byte // NewPrivateKey generates a private key based on buf. // If an ErrInvalidKey is returned, generation will be retried with a different buf. // Any other errors are considered permanent and returned to the caller. NewPrivateKey(buf []byte) (Key, error) }
A Curve represents a curve type to derive private and public key pairs for.
type ExtendedKey ¶
ExtendedKey represents a SLIP-10 extended private or public key.
func DeriveKeyFromPath ¶
func DeriveKeyFromPath(seed []byte, curve Curve, path []uint32) (*ExtendedKey, error)
DeriveKeyFromPath derives an extended private key for the curve from seed and path as outlined by SLIP-10.
func NewMasterKey ¶
func NewMasterKey(seed []byte, curve Curve) (*ExtendedKey, error)
NewMasterKey creates a new master private extended key for the curve from a seed.
func (*ExtendedKey) DeriveChild ¶
func (e *ExtendedKey) DeriveChild(index uint32) (*ExtendedKey, error)
DeriveChild derives an extended key from a given parent extended key as outlined by SLIP-10. If the parent is an extended public key, the child will also be an extended public key.
func (*ExtendedKey) Fingerprint ¶
func (e *ExtendedKey) Fingerprint() []byte
Fingerprint returns the fingerprint of the parent's key.
func (*ExtendedKey) IsPrivate ¶
func (e *ExtendedKey) IsPrivate() bool
IsPrivate returns whether the key is an extended private key or extended public key.
func (*ExtendedKey) Public ¶
func (e *ExtendedKey) Public() *ExtendedKey
Public returns the public version of key. If key is already an extended public key, a copy is returned.
type Key ¶
type Key interface { // Bytes serializes the key as a byte slice. // The number of bytes must match PrivateKeySize or PublicKeySize respectively. Bytes() []byte // IsPrivate returns whether the key corresponds to a private or public key. IsPrivate() bool // Public returns the corresponding public key. Public() Key // Shift derives a new key using the provided additive shift. // It must not modify the receiver. // If an ErrInvalidKey is returned, generation will be retried with a different shift. // Any other errors are considered permanent and returned to the caller. Shift([]byte) (Key, error) }
A Key represents a private or public key for a curve.
Directories ¶
Path | Synopsis |
---|---|
Package btccurve implements the secp256k1 curve used by Bitcoin.
|
Package btccurve implements the secp256k1 curve used by Bitcoin. |
internal/btccurve
Package btccurve implements the secp256k1 curve used by Bitcoin.
|
Package btccurve implements the secp256k1 curve used by Bitcoin. |