slip10

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 10 Imported by: 3

README

Ed25519 private key derivation from master private key

Golang SLIP-0010 implementation(ed25519 only) according to the https://github.com/satoshilabs/slips/blob/master/slip-0010.md

Example

    package main

    import (
    	"encoding/hex"
    	"fmt"

    	slip10 "github.com/anytypeio/go-slip10"
    )

    func main() {
    	seed, err := hex.DecodeString("000102030405060708090a0b0c0d0e0f")
    	if err != nil {
    		panic(err)
    	}

    	// example vector 1: https://github.com/satoshilabs/slips/blob/master/slip-0010.md#test-vector-1-for-ed25519
    	node, err := slip10.DeriveForPath("m/0'/1'", seed)
    	if err != nil {
    		panic(err)
    	}

    	pub, priv, err := node.Keypair()
    	if err != nil {
    		panic(err)
    	}

    	// prints b1d0bad404bf35da785a64ca1ac54b2617211d2777696fbffaf208f746ae84f2
    	fmt.Printf("%x\n", priv)

    	// prints 1932a5270f335bed617d5b935c80aedb1a35bd9fc1e31acafd5372c30f5c1187
    	// You can notice that example at https://github.com/satoshilabs/slips/blob/master/slip-0010.md#test-vector-1-for-ed25519
    	// adds 0x00 prefix for the public key. Because we are using native crypto/ed25519 for the keypair we won't do this for the Keypair() method
    	fmt.Printf("%x\n", pub)

    	// but you can use node.PublicKeyWithPrefix() to get the public key with prefix
    	pubK, err := node.PublicKeyWithPrefix()
    	if err != nil {
    		panic(err)
    	}

    	// prints 001932a5270f335bed617d5b935c80aedb1a35bd9fc1e31acafd5372c30f5c1187
    	fmt.Printf("%x\n", pubK)
    }

Licensing

The code in this project is licensed under the MIT License

Documentation

Index

Constants

View Source
const (
	// FirstHardenedIndex is the index of the first hardened key (2^31).
	// https://youtu.be/2HrMlVr1QX8?t=390
	FirstHardenedIndex = uint32(0x80000000)
)

Variables

View Source
var (
	ErrInvalidPath        = fmt.Errorf("invalid derivation path")
	ErrNoPublicDerivation = fmt.Errorf("no public derivation for ed25519")
)

Functions

func IsValidPath

func IsValidPath(path string) bool

IsValidPath check whether or not the path has valid segments.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

func DeriveForPath

func DeriveForPath(path string, seed []byte) (*Node, error)

DeriveForPath derives key for a path in BIP-44 format and a seed. Ed25119 derivation operated on hardened keys only.

func NewMasterNode

func NewMasterNode(seed []byte) (*Node, error)

NewMasterNode generates a new master key from seed.

func (*Node) Derive

func (k *Node) Derive(i uint32) (*Node, error)

func (*Node) Keypair

func (k *Node) Keypair() (ed25519.PublicKey, ed25519.PrivateKey)

Keypair returns the public and private key.

func (Node) MarshalJSON

func (k Node) MarshalJSON() ([]byte, error)

func (*Node) PrivateKey

func (k *Node) PrivateKey() []byte

PrivateKey returns private key seed bytes

func (*Node) PublicKeyWithPrefix

func (k *Node) PublicKeyWithPrefix() []byte

PublicKeyWithPrefix returns public key with 0x00 prefix, as specified in the slip-10 https://github.com/satoshilabs/slips/blob/master/slip-0010/testvectors.py#L64

func (*Node) RawSeed

func (k *Node) RawSeed() []byte

RawSeed returns raw seed bytes

func (*Node) UnmarshalJSON

func (k *Node) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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