owkeychain

package
v1.1.22 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 用于产生根密钥的种子长度
	MinRecommendedSeedLen = 16
	MAxRecommendedSeedLen = 64
	// 强化子密钥索引号起始值
	HardenedKeyStart uint32 = 0x80000000
)

Variables

View Source
var (
	BitcoinAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
	IPFSAlphabet    = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
	FlickrAlphabet  = NewAlphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
	RippleAlphabet  = NewAlphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")
)

Alphabet: copy from https://en.wikipedia.org/wiki/Base58

View Source
var (
	// 公钥不能进行强化扩展
	ErrDeriveHardFromPublic = errors.New("cannot derive a hardened key from a public key")

	// 超过最大扩展深度
	ErrDeriveBeyondMaxDepth = errors.New("cannot derive a key with more than 255 indices in its path")

	// 公钥无法扩展子私钥
	ErrNotPrivExtKey = errors.New("unable to create private keys from a public extended key")

	// 该索引号无法扩展,应尝试下一个
	ErrInvalidChild = errors.New("the extended key at this index is invalid")

	// 种子长度错误
	ErrInvalidSeedLen = fmt.Errorf("seed length should be between 16 bytes and 64 bytes!")

	// reserve
	ErrBadChecksum = errors.New("bad extended key checksum")

	// reserve
	ErrInvalidKeyLen = errors.New("the provided serialized extended key length is invalid")
)
View Source
var (
	ErrInvalidDerivedPath = errors.New("Invalid DerivedPath")
	ErrKeyIsNotPrivate    = errors.New("The key is not private")
)
View Source
var (
	Bitcoin  = CoinType{uint32(0), owcrypt.ECC_CURVE_SECP256K1}
	Ethereum = CoinType{uint32(1), owcrypt.ECC_CURVE_SECP256K1}
)

XXX[0]:hd扩展索引 XXX[1]:曲线类型

View Source
var (
	BitcoinPubkeyPrefix = []byte{0}
	BitcoinScriptPrefix = []byte{5}
)
View Source
var ChainPrefix = []byte{0x08, 0x61, 0x24, 0x96, 0x12, 0xae, 0x5c}
View Source
var (
	ErrInvalidAddress = errors.New("address is invalid")
)
View Source
var (
	ErrorInvalidBase58String = errors.New("invalid base58 string")
)

Errors

Functions

func Base58checkDecode

func Base58checkDecode(address string, fix []byte) ([]byte, error)

func Base58checkEncode

func Base58checkEncode(data []byte, fix []byte) string

func Decode

func Decode(input string, alphabet *Alphabet) ([]byte, error)

Decode docode with custom alphabet

func DerivedPrivateKeyBytes

func DerivedPrivateKeyBytes(seed []byte, coinType CoinType, serializes uint32) ([]byte, error)

func Encode

func Encode(input []byte, alphabet *Alphabet) string

Encode encode with custom alphabet

func GetMultiSigShareData added in v1.1.13

func GetMultiSigShareData(owpub string) (string, error)

Types

type Alphabet

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

Alphabet The base58 alphabet object.

func NewAlphabet

func NewAlphabet(alphabet string) *Alphabet

NewAlphabet create a custom alphabet from 58-length string. Note: len(rune(alphabet)) must be 58.

func (Alphabet) String

func (alphabet Alphabet) String() string

Alphabet's string representation

type CoinType

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

type ExtendedKey

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

ExtendedKey 扩展密钥结构体

func DerivedPrivateKeyWithPath

func DerivedPrivateKeyWithPath(seed []byte, derivedPath string, curveType uint32) (*ExtendedKey, error)

接口仅接受绝对路径

func GetCoinRootPublicKey

func GetCoinRootPublicKey(seed []byte, coinType CoinType) (*ExtendedKey, error)

func InitRootKeyFromSeed

func InitRootKeyFromSeed(seed []byte, curveType uint32) (*ExtendedKey, error)

InitRootKeyFromSeed 通过种子获得根私钥

func NewExtendedKey

func NewExtendedKey(key, chainCode, parentFP []byte, depth uint8,
	serializes uint32, isPrivate bool, curveType uint32) *ExtendedKey

NewExtendedKey 初始化密钥结构体

func OWDecode

func OWDecode(data string) (*ExtendedKey, error)

func (*ExtendedKey) DerivedPublicKeyFromPath

func (k *ExtendedKey) DerivedPublicKeyFromPath(derivedPath string) (*ExtendedKey, error)

DerivedPublicKeyFromPath 从当前密钥k按照相对路径进行扩展

func (*ExtendedKey) DerivedPublicKeyFromSerializes

func (k *ExtendedKey) DerivedPublicKeyFromSerializes(serializes uint32) (*ExtendedKey, error)

DerivedPublicKeyFromSerializes 普通密钥扩展的单层深度派生

func (*ExtendedKey) GenPrivateChild

func (k *ExtendedKey) GenPrivateChild(serializes uint32) (*ExtendedKey, error)

GenPrivateChild 通过k扩展子私钥

func (*ExtendedKey) GenPublicChild

func (k *ExtendedKey) GenPublicChild(serializes uint32) (*ExtendedKey, error)

GenPublicChild 通过k扩展子公钥

func (*ExtendedKey) GetPrivateKeyBytes

func (k *ExtendedKey) GetPrivateKeyBytes() ([]byte, error)

GetPrivateKey 获取当前密钥对应的私钥数组

func (*ExtendedKey) GetPublicKey

func (k *ExtendedKey) GetPublicKey() *ExtendedKey

GePublicKey 获取公钥结构体

func (*ExtendedKey) GetPublicKeyBytes

func (k *ExtendedKey) GetPublicKeyBytes() []byte

GetPublicKeyBytes 获取当前密钥对应的公钥

func (*ExtendedKey) GetUncompressedPublicKeyBytes

func (k *ExtendedKey) GetUncompressedPublicKeyBytes() []byte

//GetPublicKeyUncompressedBytes 获取当前密钥对应的公钥(未压缩,且去除04)

func (*ExtendedKey) OWEncode

func (k *ExtendedKey) OWEncode() string

type MultiSigShare added in v1.1.13

type MultiSigShare struct {
	Pubkey    []byte
	ChainCode []byte
	CurveType uint32
}

func ChainDecode added in v1.1.13

func ChainDecode(owchain string) (*MultiSigShare, error)

func (MultiSigShare) ChianEncode added in v1.1.13

func (ms MultiSigShare) ChianEncode() string

Jump to

Keyboard shortcuts

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