Documentation ¶
Index ¶
- Constants
- Variables
- type ExtendedKey
- func (k *ExtendedKey) Child(i uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) ChildWithIL(i uint32) (*big.Int, *ExtendedKey, error)
- func (k *ExtendedKey) Derive(path []uint32) (*ExtendedKey, error)
- func (k *ExtendedKey) DeriveWithIL(path []uint32) (*big.Int, *ExtendedKey, error)
- func (k *ExtendedKey) IsPrivate() bool
- func (k *ExtendedKey) MarshalBinary() ([]byte, error)
- func (k *ExtendedKey) Public() (*ExtendedKey, error)
- func (k *ExtendedKey) String() string
- func (k *ExtendedKey) ToECDSA() *ecdsa.PrivateKey
- func (k *ExtendedKey) ToPublicECDSA() (*ecdsa.PublicKey, error)
- func (k *ExtendedKey) ToPublicSecp256k1() (*secp256k1.PublicKey, error)
- func (k *ExtendedKey) UnmarshalBinary(data []byte) error
- type KeyVersion
Constants ¶
const (
HardenedBit = 0x80000000 // hardened keys do not allow derivation of public keys
)
Variables ¶
var ( ErrInvalidKey = errors.New("key is invalid") ErrInvalidKeyPurpose = errors.New("key purpose is invalid") ErrInvalidSeed = errors.New("seed is invalid") ErrDerivingHardenedFromPublic = errors.New("cannot derive a hardened key from public key") ErrBadChecksum = errors.New("bad extended key checksum") ErrInvalidKeyLen = errors.New("serialized extended key length is invalid") ErrDerivingChild = errors.New("error deriving child key") ErrInvalidMasterKey = errors.New("invalid master key supplied") ErrMaxDepthExceeded = errors.New("max depth exceeded") ErrInvalidPrivateFlag = errors.New("key private flag does not match version") )
var ( BitcoinMainnetPublic = KeyVersion{0x04, 0x88, 0xb2, 0x1e} BitcoinMainnetPrivate = KeyVersion{0x04, 0x88, 0xad, 0xe4} BitcoinTestnetPublic = KeyVersion{0x04, 0x35, 0x87, 0xcf} BitcoinTestnetPrivate = KeyVersion{0x04, 0x35, 0x83, 0x94} )
var (
ErrShaKeyInvalid = errors.New("generated key zero or overflow, try next one")
)
Functions ¶
This section is empty.
Types ¶
type ExtendedKey ¶
type ExtendedKey struct { Version KeyVersion Depth uint8 Fingerprint [4]byte ChildNumber uint32 // ser32(i) for i in xi = xpar/i, with xi the key being serialized. (0x00000000 if master key) KeyData []byte // 33 bytes, the public key or private key data (serP(K) for public keys, 0x00 || ser256(k) for private keys) ChainCode []byte // 32 bytes, the chain code // contains filtered or unexported fields }
func FromBitcoinSeed ¶
func FromBitcoinSeed(seed []byte) (*ExtendedKey, error)
FromBitcoinSeed returns a master node for a bitcoin wallet
func FromPublicKey ¶ added in v0.1.1
func FromPublicKey(pubkey *ecdsa.PublicKey, chainCode []byte) (*ExtendedKey, error)
FromPublicKey will initialize an ExtendedKey with the provided ecdsa.PublicKey.
func FromSeed ¶
func FromSeed(seed, masterSecret []byte) (*ExtendedKey, error)
func FromString ¶
func FromString(str string) (*ExtendedKey, error)
func (*ExtendedKey) Child ¶
func (k *ExtendedKey) Child(i uint32) (*ExtendedKey, error)
Child derives extended key at a given index i. If parent is private, then derived key is also private. If parent is public, then derived is public.
If i >= HardenedKeyStart, then hardened key is generated. You can only generate hardened keys from private parent keys. If you try generating hardened key form public parent key, ErrDerivingHardenedFromPublic is returned.
There are four CKD (child key derivation) scenarios: 1) Private extended key -> Hardened child private extended key 2) Private extended key -> Non-hardened child private extended key 3) Public extended key -> Non-hardened child public extended key 4) Public extended key -> Hardened child public extended key (INVALID!)
func (*ExtendedKey) ChildWithIL ¶ added in v0.1.1
func (k *ExtendedKey) ChildWithIL(i uint32) (*big.Int, *ExtendedKey, error)
ChildWithIL derives extended key at a given index i, and returns IL (I left) too.
func (*ExtendedKey) Derive ¶
func (k *ExtendedKey) Derive(path []uint32) (*ExtendedKey, error)
Derive returns a derived child key at a given path
func (*ExtendedKey) DeriveWithIL ¶ added in v0.1.1
func (k *ExtendedKey) DeriveWithIL(path []uint32) (*big.Int, *ExtendedKey, error)
DeriveWithIL returns a derived child key at a given path
func (*ExtendedKey) IsPrivate ¶
func (k *ExtendedKey) IsPrivate() bool
func (*ExtendedKey) MarshalBinary ¶
func (k *ExtendedKey) MarshalBinary() ([]byte, error)
MarshalBinary encodes the key in standard format that can be base58 encoded for humans
func (*ExtendedKey) Public ¶
func (k *ExtendedKey) Public() (*ExtendedKey, error)
Public returns a new extended public key from a give extended private key. If the input extended key is already public, it will be returned unaltered.
func (*ExtendedKey) String ¶
func (k *ExtendedKey) String() string
func (*ExtendedKey) ToECDSA ¶
func (k *ExtendedKey) ToECDSA() *ecdsa.PrivateKey
ToECDSA returns the key data as ecdsa.PrivateKey
func (*ExtendedKey) ToPublicECDSA ¶ added in v0.1.2
func (k *ExtendedKey) ToPublicECDSA() (*ecdsa.PublicKey, error)
ToPublicECDSA returns a ecdsa.PublicKey for the current key
func (*ExtendedKey) ToPublicSecp256k1 ¶ added in v0.2.6
func (k *ExtendedKey) ToPublicSecp256k1() (*secp256k1.PublicKey, error)
ToPublicSecp256k1 returns a secp256k1.PublicKey object for the current key
func (*ExtendedKey) UnmarshalBinary ¶
func (k *ExtendedKey) UnmarshalBinary(data []byte) error
type KeyVersion ¶
type KeyVersion [4]byte
func (KeyVersion) IsPrivate ¶
func (kv KeyVersion) IsPrivate() bool
IsPrivate returns true if the version is for a private key
func (KeyVersion) ToPublic ¶
func (kv KeyVersion) ToPublic() KeyVersion