hdkeystore

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: GPL-3.0 Imports: 20 Imported by: 34

Documentation

Index

Constants

View Source
const (

	// MinSeedBytes is the minimum number of bytes allowed for a seed to
	// a master node.
	MinSeedBytes = 16 // 128 bits

	// MaxSeedBytes is the maximum number of bytes allowed for a seed to
	// a master node.
	MaxSeedBytes = 64 // 512 bits

	// The hierarchy described by BIP0043 is:
	//  m/<purpose>'/*
	// This is further extended by BIP0044 to:
	//  m/44'/<coin type>'/<account>'
	// BIP0044,m/44'/
	//openwallet coin type is 88': m/44'/88'
	OpenwCoinTypePath = "m/44'/88'"
)
View Source
const (

	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6

	//种子长度
	SeedLen = 32
)

Variables

View Source
var (

	//KeyID首字节的标识
	KeyIDVer = []byte{0x48}

	//Derived路径错误
	ErrInvalidDerivedPath = errors.New("Invalid DerivedPath")

	//错误的HDPath
	ErrInvalidHDPath = errors.New("Invalid HDPath")

	// ErrInvalidSeedLen describes an error in which the provided seed or
	// seed length is not in the allowed range.
	ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+
		"bits", MinSeedBytes*8, MaxSeedBytes*8)
)
View Source
var (
	//ErrLocked  = accounts.NewAuthNeededError("password or unlock")
	ErrNoMatch = errors.New("no key for given address or file")
	//ErrDecrypt 机密出错
	ErrDecrypt = errors.New("could not decrypt key with given passphrase")
)

Functions

func EncryptKey

func EncryptKey(hdkey *HDKey, auth string, scryptN, scryptP int) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func GenerateSeed

func GenerateSeed(length uint8) ([]byte, error)

GenerateSeed returns a cryptographically secure random seed that can be used as the input for the NewMaster function to generate a new master node.

The length is in bytes and it must be between 16 and 64 (128 to 512 bits). The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen constant.

func GetExtendSeed

func GetExtendSeed(seed []byte, masterKey string) ([]byte, error)

GetExtendSeed 获得某个币种的扩展种子

func KeyFileName

func KeyFileName(alias, rootId string) string

keyFileName implements the naming convention for keyfiles: wallet--<alias>-<rootId>

Types

type HDKey

type HDKey struct {
	//私钥别名
	Alias string
	//账户路径
	RootPath string
	// 账户的扩展ID
	KeyID string
	// contains filtered or unexported fields
}

HDKey 分层确定性密钥,基于BIP32模型创建的账户模型

func DecryptHDKey

func DecryptHDKey(keyjson []byte, auth string) (*HDKey, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

func NewHDKey

func NewHDKey(seed []byte, alias, rootPath string) (*HDKey, error)

NewHDKey 通过userkey,私钥种子,根私钥标识符,账户路径,创建HDKey

func StoreHDKey

func StoreHDKey(dir, alias, auth string, scryptN, scryptP int) (*HDKey, string, error)

StoreHDKey 创建HDKey

func StoreHDKeyWithSeed

func StoreHDKeyWithSeed(dir, alias, auth string, seed []byte, scryptN, scryptP int) (*HDKey, string, error)

StoreHDKey 创建HDKey

func (*HDKey) DerivedKeyWithPath

func (k *HDKey) DerivedKeyWithPath(path string, curveType uint32) (*owkeychain.ExtendedKey, error)

DerivedKeyWithPath 根据BIP32的规则获取子密钥,例如:m/<purpose>'/* @param path string "" (root key) "m" (root key) "/" (root key) "m/0'" (hardened child #0 of the root key) "/0'" (hardened child #0 of the root key) "0'" (hardened child #0 of the root key) "m/44'/1'/2'" (BIP44 testnet account #2) "/44'/1'/2'" (BIP44 testnet account #2) "44'/1'/2'" (BIP44 testnet account #2)

The following paths are invalid:

"m / 0 / 1" (contains spaces) "m/b/c" (alphabetical characters instead of numerical indexes) "m/1.2^3" (contains illegal characters) @param curveType string ECC_CURVE_SECP256K1 ECC_CURVE_SECP256R1 ECC_CURVE_ED25519

func (*HDKey) FileName

func (k *HDKey) FileName() string

FileName 文件名

func (*HDKey) Seed

func (k *HDKey) Seed() []byte

Seed 密钥种子

type HDKeystore

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

HDKeystore HDKey的存粗工具类

func NewHDKeystore

func NewHDKeystore(keydir string, scryptN, scryptP int) *HDKeystore

NewHDKeystore 实例化HDKeystore

func (HDKeystore) GetKey

func (ks HDKeystore) GetKey(rootId, filename, auth string) (*HDKey, error)

GetKey 通过accountId读取钥匙

func (*HDKeystore) JoinPath

func (ks *HDKeystore) JoinPath(filename string) string

JoinPath 文件路径组合

func (*HDKeystore) StoreKey

func (ks *HDKeystore) StoreKey(filename string, key *HDKey, auth string) error

StoreKey 把HDKey重写加密写入到文件中

Jump to

Keyboard shortcuts

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