keys

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WIFVersion is the version used to decode and encode WIF keys.
	WIFVersion = 0x80
)

Variables

This section is empty.

Functions

func NEP2Encrypt

func NEP2Encrypt(priv *PrivateKey, passphrase string) (s string, err error)

NEP2Encrypt encrypts a the PrivateKey using a given passphrase under the NEP-2 standard.

func WIFEncode

func WIFEncode(key []byte, version byte, compressed bool) (s string, err error)

WIFEncode encodes the given private key into a WIF string.

Types

type PrivateKey

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

PrivateKey represents a NEO private key.

func NEP2Decrypt

func NEP2Decrypt(key, passphrase string) (*PrivateKey, error)

NEP2Decrypt decrypts an encrypted key using a given passphrase under the NEP-2 standard.

func NewPrivateKey

func NewPrivateKey() (*PrivateKey, error)

NewPrivateKey creates a new random private key.

func NewPrivateKeyFromASN1 added in v0.51.0

func NewPrivateKeyFromASN1(b []byte) (*PrivateKey, error)

NewPrivateKeyFromASN1 returns a NEO PrivateKey from the ASN.1 serialized key.

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error)

NewPrivateKeyFromBytes returns a NEO PrivateKey from the given byte slice.

func NewPrivateKeyFromHex

func NewPrivateKeyFromHex(str string) (*PrivateKey, error)

NewPrivateKeyFromHex returns a PrivateKey created from the given hex string.

func NewPrivateKeyFromWIF

func NewPrivateKeyFromWIF(wif string) (*PrivateKey, error)

NewPrivateKeyFromWIF returns a NEO PrivateKey from the given WIF (wallet import format).

func (*PrivateKey) Address

func (p *PrivateKey) Address() string

Address derives the public NEO address that is coupled with the private key, and returns it as a string.

func (*PrivateKey) Bytes

func (p *PrivateKey) Bytes() []byte

Bytes returns the underlying bytes of the PrivateKey.

func (*PrivateKey) GetScriptHash added in v0.73.0

func (p *PrivateKey) GetScriptHash() util.Uint160

GetScriptHash returns verification script hash for public key associated with the private key.

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() *PublicKey

PublicKey derives the public key from the private key.

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(data []byte) []byte

Sign signs arbitrary length data using the private key.

func (*PrivateKey) String

func (p *PrivateKey) String() string

String implements the stringer interface.

func (*PrivateKey) WIF

func (p *PrivateKey) WIF() string

WIF returns the (wallet import format) of the PrivateKey. Good documentation about this process can be found here: https://en.bitcoin.it/wiki/Wallet_import_format

type PublicKey

type PublicKey struct {
	X *big.Int
	Y *big.Int
}

PublicKey represents a public key and provides a high level API around the X/Y point.

func NewPublicKeyFromASN1 added in v0.51.0

func NewPublicKeyFromASN1(data []byte) (*PublicKey, error)

NewPublicKeyFromASN1 returns a NEO PublicKey from the ASN.1 serialized key.

func NewPublicKeyFromString

func NewPublicKeyFromString(s string) (*PublicKey, error)

NewPublicKeyFromString returns a public key created from the given hex string.

func (*PublicKey) Address

func (p *PublicKey) Address() string

Address returns a base58-encoded NEO-specific address based on the key hash.

func (*PublicKey) Bytes

func (p *PublicKey) Bytes() []byte

Bytes returns the byte array representation of the public key.

func (*PublicKey) Cmp added in v0.73.0

func (p *PublicKey) Cmp(key *PublicKey) int

Cmp compares two keys.

func (*PublicKey) DecodeBinary

func (p *PublicKey) DecodeBinary(r *io.BinReader)

DecodeBinary decodes a PublicKey from the given BinReader.

func (*PublicKey) DecodeBytes

func (p *PublicKey) DecodeBytes(data []byte) error

DecodeBytes decodes a PublicKey from the given slice of bytes.

func (*PublicKey) EncodeBinary

func (p *PublicKey) EncodeBinary(w *io.BinWriter)

EncodeBinary encodes a PublicKey to the given BinWriter.

func (*PublicKey) Equal added in v0.70.0

func (p *PublicKey) Equal(key *PublicKey) bool

Equal returns true in case public keys are equal.

func (*PublicKey) GetScriptHash added in v0.73.0

func (p *PublicKey) GetScriptHash() util.Uint160

GetScriptHash returns a Hash160 of verification script for the key.

func (*PublicKey) GetVerificationScript added in v0.70.1

func (p *PublicKey) GetVerificationScript() []byte

GetVerificationScript returns NEO VM bytecode with CHECKSIG command for the public key.

func (*PublicKey) IsInfinity added in v0.51.0

func (p *PublicKey) IsInfinity() bool

IsInfinity checks if the key is infinite (null, basically).

func (*PublicKey) String

func (p *PublicKey) String() string

String implements the Stringer interface.

func (*PublicKey) Verify

func (p *PublicKey) Verify(signature []byte, hash []byte) bool

Verify returns true if the signature is valid and corresponds to the hash and public key.

type PublicKeys

type PublicKeys []*PublicKey

PublicKeys is a list of public keys.

func (PublicKeys) Contains added in v0.70.0

func (keys PublicKeys) Contains(pKey *PublicKey) bool

Contains checks whether passed param contained in PublicKeys.

func (*PublicKeys) DecodeBytes added in v0.70.0

func (keys *PublicKeys) DecodeBytes(data []byte) error

DecodeBytes decodes a PublicKeys from the given slice of bytes.

func (PublicKeys) Len

func (keys PublicKeys) Len() int

func (PublicKeys) Less

func (keys PublicKeys) Less(i, j int) bool

func (PublicKeys) Swap

func (keys PublicKeys) Swap(i, j int)

func (PublicKeys) Unique added in v0.70.0

func (keys PublicKeys) Unique() PublicKeys

Unique returns set of public keys.

type ScryptParams

type ScryptParams struct {
	N int `json:"n"`
	R int `json:"r"`
	P int `json:"p"`
}

ScryptParams is a json-serializable container for scrypt KDF parameters.

func NEP2ScryptParams

func NEP2ScryptParams() ScryptParams

NEP2ScryptParams returns scrypt parameters specified in the NEP-2.

type WIF

type WIF struct {
	// Version of the wallet import format. Default to 0x80.
	Version byte

	// Bool to determine if the WIF is compressed or not.
	Compressed bool

	// A reference to the PrivateKey which this WIF is created from.
	PrivateKey *PrivateKey

	// The string representation of the WIF.
	S string
}

WIF represents a wallet import format.

func WIFDecode

func WIFDecode(wif string, version byte) (*WIF, error)

WIFDecode decodes the given WIF string into a WIF struct.

Jump to

Keyboard shortcuts

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