pkg

package
v0.0.0-...-e18d7b5 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PurposeBIP44 Purpose = 0x8000002C // 44' BIP44
	PurposeBIP49 Purpose = 0x80000031 // 49' BIP49
	PurposeBIP84 Purpose = 0x80000054 // 84' BIP84

	CoinTypeBTC CoinType = 0x80000000

	Apostrophe uint32 = 0x80000000 // 0'
)
View Source
const (
	MinPasswordBytesLen = 6

	DefaultIterations = 100000

	MinSaltIterations = 8192

	MinPBKDF2Iterations = 2048

	// Bits eg 128 = 12-word seed. 256 = 24-word seed.
	Bits128 = 128
	Bits256 = 256
)

Variables

This section is empty.

Functions

func MakeSalt

func MakeSalt(password []byte, iterations int) ([]byte, error)

MakeSalt takes password bytes and number of interations and hashes is sha256(password) -> sha256(result) -> sha256(result) until iteration number of times returns final digest bytes, number of seconds int and error

Types

type AddressResult

type AddressResult struct {
	Address        string
	SecretExponent []byte
	Wif            string
	Num            int
	DerivationPath string
}

AddressResult holds the MakeAddress result

func MakeAddress

func MakeAddress(mnemonic string, password string, num int, script string) (AddressResult, error)

MakeAddress function takes mnemonic and password and returns an address and wif

type CoinType

type CoinType = uint32

CoinType SLIP-0044 : Registered coin types for BIP-0044 https://github.com/satoshilabs/slips/blob/master/slip-0044.md

type Key

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

Key hold path and key and Encode function

func (*Key) Encode

func (k *Key) Encode(compress bool) (wif, address, segwitBech32, segwitNested string, err error)

func (*Key) GetPath

func (k *Key) GetPath() string

type KeyManager

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

func NewKeyManager

func NewKeyManager(bitSize int, passphrase, mnemonic string) (*KeyManager, error)

NewKeyManager return new key manager bitSize has to be a multiple 32 and be within the inclusive range of {128, 256} 128: 12 phrases 256: 24 phrases

func (*KeyManager) GetAccountKey

func (km *KeyManager) GetAccountKey(purpose, coinType, account uint32) (*bip32.Key, error)

func (*KeyManager) GetChangeKey

func (km *KeyManager) GetChangeKey(purpose, coinType, account, change uint32) (*bip32.Key, error)

GetChangeKey ... https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change change constant 0 is used for external chain change constant 1 is used for internal chain (also known as change addresses)

func (*KeyManager) GetCoinTypeKey

func (km *KeyManager) GetCoinTypeKey(purpose, coinType uint32) (*bip32.Key, error)

func (*KeyManager) GetKey

func (km *KeyManager) GetKey(purpose, coinType, account, change, index uint32) (*Key, error)

func (*KeyManager) GetMasterKey

func (km *KeyManager) GetMasterKey() (*bip32.Key, error)

func (*KeyManager) GetMnemonic

func (km *KeyManager) GetMnemonic() string

func (*KeyManager) GetPassphrase

func (km *KeyManager) GetPassphrase() string

func (*KeyManager) GetPurposeKey

func (km *KeyManager) GetPurposeKey(purpose uint32) (*bip32.Key, error)

func (*KeyManager) GetSeed

func (km *KeyManager) GetSeed() []byte

type Purpose

type Purpose = uint32

Purpose BIP43 - Purpose Field for Deterministic Wallets https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki

Purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation. It indicates that the subtree of this node is used according to this specification.

What does 44' mean in BIP44? https://bitcoin.stackexchange.com/questions/74368/what-does-44-mean-in-bip44

44' means that hardened keys should be used. The distinguisher for whether a key a given index is hardened is that the index is greater than 2^31, which is 2147483648. In hex, that is 0x80000000. That is what the apostrophe (') means. The 44 comes from adding it to 2^31 to get the final hardened key index. In hex, 44 is 2C, so 0x80000000 + 0x2C = 0x8000002C.

type SeedResult

type SeedResult struct {
	Entropy  []byte
	Mnemonic string
}

func MakeSeed

func MakeSeed(password []byte, salt []byte, iterations, bits int, language string) (SeedResult, error)

MakeSeed takes password, salt and iterations and performs pbkdf2 hmac to produce seed entropy return SeedResult and error

Jump to

Keyboard shortcuts

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