bip32

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 11 Imported by: 0

README

bip32

Introduction

This package is an implementation of the BIP32 specifications in the Go programming language. You can read the documentation here.

Example

package main

import (
    "fmt"

    "github.com/augcos/bip32"
    "github.com/augcos/bip39"
)

func main() {
    // we generate the random entropy
    entropy, _ := bip39.GenEntropy(256)
    // we generate the mnemonic corresponding to that entropy
    mnemonic, _ := bip39.GetMnemonicFromEntropy(entropy)
    // finally, we generate the 512-bit seed from the mnemonic, plus a passphrase
    seed, _ := bip39.GetSeedFromMnemonic(mnemonic, "passphrase")

    // we create the master key
    masterKey, _ := bip32.GenMasterKey(seed)
    // we derivate the child private key
    childKey, _ := bip32.ChildKeyDeriv(masterKey, 0)
    // we get the child public key from the private key
    pubChildKey, _ := bip32.Neuter(childKey)

    // we serialize the child public key
    serializedPubChildKey, _ := bip32.Serialization(pubChildKey)

    fmt.Println("Public Child Key:", serializedPubMasterKey)
}

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serialization

func Serialization(key *Extkey) (string, error)

Serialization returns the serialized extended key as a string

Types

type Extkey

type Extkey struct {
	Version     []byte
	Depth       byte
	Fingerprint []byte
	ChildNumber []byte
	ChainCode   []byte
	Key         []byte
}

ExtKey is a struct type representing a extended key according to BIP32 specifications

func ChildKeyDeriv

func ChildKeyDeriv(parentKey *Extkey, index uint32) (*Extkey, error)

ChildKeyDeriv is a generic interface for generating extended child keys from any exnteded parent keys, either private or public

func ChildKeyDerivPriv

func ChildKeyDerivPriv(parentKey *Extkey, index uint32) (*Extkey, error)

ChildKeyGenPriv returns an extended private child key using as input its extended parent private key and a child index (capable of producing both hardened and non-hardened keys)

func ChildKeyDerivPub

func ChildKeyDerivPub(parentKey *Extkey, index uint32) (*Extkey, error)

ChildKeyGenPriv returns an extended public child key using as input its extended parent public key and a child index

func Deserialization

func Deserialization(serializedKey string) (*Extkey, error)

Deserialization returns the ExtKey objet of a given serialized key

func GenMasterKey

func GenMasterKey(seed []byte) (*Extkey, error)

GenMasterKey takes a seed as an input and returns the extended key for the master key

func Neuter

func Neuter(privateKey *Extkey) (*Extkey, error)

Neuter returns the extended public key corresponding to a given extended private key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL