bip85

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 7 Imported by: 0

README

Go-BIP85

Go Reference

This is a Go library for deriving BIP-39 mnemonic seeds from a BIP-32 master root key, based on the BIP-85 specification.

Note: This library is an open-source project and is seeking community contributions and review to ensure it is production-ready. Your help in validating and improving the code is welcome!

Features

  • Derivation of BIP-39 mnemonics (12, 18, and 24 words).
  • Initialization from a master mnemonic phrase (English only).
  • Initialization from a master extended private key (XPRV).

Usage

Here is a basic example of how to use the library:

package main

import (
	"fmt"
	"log"

	"github.com/lescuer97/bip85"
)

func main() {
	// Initialize from a mnemonic
	mnemonic := "all all all all all all all all all all all all"
	passphrase := ""
	b, err := bip85.NewBip85FromMnemonic(mnemonic, passphrase)
	if err != nil {
		log.Fatal(err)
	}

	// Derive a new 12-word mnemonic
	derivedMnemonic, err := b.DeriveMnemonic(12, 0)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(derivedMnemonic)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBip32IsNil = errors.New("bip32 key is nil")
)
View Source
var (
	PrivateWalletVersion, _ = hex.DecodeString("0488ADE4")
)

Functions

func CountWords

func CountWords(mnemonic string) uint

CountWords counts the number of words in a mnemonic phrase, handling leading/trailing whitespace and multiple spaces between words. This implementation is optimized to avoid memory allocations.

Types

type Bip85

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

Bip85 wraps a BIP32 master key for BIP85 derivations.

func NewBip85FromBip32Key added in v0.1.1

func NewBip85FromBip32Key(bip32Key *bip32.Key) (*Bip85, error)

NewBip85FromBip32Key allows direct import of an existing BIP-32 key

func NewBip85FromMnemonic

func NewBip85FromMnemonic(mnemonic, passphrase string) (*Bip85, error)

NewBip85FromMnemonic creates a new Bip85 instance from a BIP39 mnemonic. This implementation only supports the English wordlist.

func NewBip85FromXPRVString added in v0.1.1

func NewBip85FromXPRVString(xprv string) (*Bip85, error)

NewBip85FromXPRVString allows direct import of an existing BIP-32 xpriv string.

func (*Bip85) DeriveToMnemonic

func (b *Bip85) DeriveToMnemonic(language MnemonicLanguage, wordCount uint32, index uint32) (string, error)

func (*Bip85) DeriveToXpriv

func (b *Bip85) DeriveToXpriv(index uint32) (*bip32.Key, error)

func (*Bip85) GetMasterKey added in v0.1.2

func (b *Bip85) GetMasterKey() *bip32.Key

type DerivationType

type DerivationType uint
const Mnemonic DerivationType = 39
const Xprv DerivationType = 32

type MnemonicLanguage

type MnemonicLanguage uint
const English MnemonicLanguage = 0

Jump to

Keyboard shortcuts

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