chainkd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadKeyLen = errors.New("bad key length")
	ErrBadKeyStr = errors.New("bad key string")
)

Functions

func NewXKeys

func NewXKeys(r io.Reader) (xprv XPrv, xpub XPub, err error)

NewXKeys create new xprivite and xpublickey

func XPubKeys

func XPubKeys(xpubs []XPub) []sm2.PubKey

Types

type XPrv

type XPrv [64]byte

XPrv external private key

func NewXPrv

func NewXPrv(r io.Reader) (xprv XPrv, err error)

func (XPrv) Bytes

func (xprv XPrv) Bytes() []byte

func (XPrv) Child

func (xprv XPrv) Child(sel []byte, hardened bool) XPrv

Child derives a child xprv based on `selector` string and `hardened` flag. If `hardened` is false, child xpub can be derived independently from the parent xpub without using the parent xprv. If `hardened` is true, child key can only be derived from the parent xprv.

func (XPrv) Derive

func (xprv XPrv) Derive(path [][]byte) XPrv

Derive generates a child xprv by recursively deriving non-hardened child xprvs over the list of selectors: `Derive([a,b,c,...]) == Child(a).Child(b).Child(c)...`

func (XPrv) MarshalText

func (xprv XPrv) MarshalText() ([]byte, error)

func (XPrv) Sign

func (xprv XPrv) Sign(msg []byte) []byte

Sign creates an sm2 signature using expanded private key derived from the xprv.

func (XPrv) String

func (xprv XPrv) String() string

func (*XPrv) UnmarshalText

func (xprv *XPrv) UnmarshalText(inp []byte) error

func (XPrv) XPub

func (xprv XPrv) XPub() (xpub XPub)

XPub derives an extended public key from a given xprv.

type XPub

type XPub [65]byte

XPub external public key

func DeriveXPubs

func DeriveXPubs(xpubs []XPub, path [][]byte) []XPub

func (XPub) Bytes

func (xpub XPub) Bytes() []byte

func (XPub) Child

func (xpub XPub) Child(sel []byte) (xpubkey XPub)

Child derives a child xpub based on `selector` string. The corresponding child xprv can be derived from the parent xprv using non-hardened derivation: `parentxprv.Child(sel, false)`.

func (XPub) Derive

func (xpub XPub) Derive(path [][]byte) XPub

Derive generates a child xpub by recursively deriving non-hardened child xpubs over the list of selectors: `Derive([a,b,c,...]) == Child(a).Child(b).Child(c)...`

func (XPub) MarshalText

func (xpub XPub) MarshalText() ([]byte, error)

func (XPub) PublicKey

func (xpub XPub) PublicKey() sm2.PubKey

PublicKey extracts the sm2 public key from an xpub.

func (XPub) String

func (xpub XPub) String() string

func (*XPub) UnmarshalText

func (xpub *XPub) UnmarshalText(inp []byte) error

func (XPub) Verify

func (xpub XPub) Verify(msg []byte, sig []byte) bool

Verify checks an sm2 signature using public key extracted from the first 33 bytes of the xpub.

Jump to

Keyboard shortcuts

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