keys

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package keys wraps public/private keys and implements NEP-2 and WIF.

Index

Constants

View Source
const MaxMultiSigCount int = 21

MaxMultiSigCount

View Source
const SignatureLen = 64

SignatureLen is the length of standard signature for 256-bit EC key.

Variables

This section is empty.

Functions

func GetDefaultHonestNodeCount

func GetDefaultHonestNodeCount(n int) int

func GetMajorityHonestNodeCount

func GetMajorityHonestNodeCount(n int) int

func NEP2Encrypt

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

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

Types

type PrivateKey

type PrivateKey struct {
	ecdsa.PrivateKey
}

func NEP2Decrypt

func NEP2Decrypt(key, passphrase string, params ScryptParams) (*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 Secp256k1 private key.

func NewPrivateKeyFromASN1

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

func NewPrivateKeyFromBytes

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

func NewPrivateKeyFromHex

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

NewPrivateKeyFromHex returns a Secp256k1 PrivateKey created from the given hex string.

func (*PrivateKey) Address

func (p *PrivateKey) Address() common.Address

func (*PrivateKey) Bytes

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

Bytes returns the underlying bytes of the PrivateKey.

func (*PrivateKey) GetScriptHash

func (p *PrivateKey) GetScriptHash() common.Address

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

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() *PublicKey

PublicKey derives the uncompressed 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. It uses SHA256 to calculate hash and then SignHash to create a signature (so you can save on hash calculation if you already have it).

func (*PrivateKey) SignHash

func (p *PrivateKey) SignHash(digest common.Hash) []byte

SignHash signs particular hash the private key.

func (*PrivateKey) SignHashable

func (p *PrivateKey) SignHashable(chainId uint64, hh hash.Hashable) []byte

SignHashable signs some Hashable item for the network specified using hash.NetSha256() with the private key.

func (*PrivateKey) String

func (p *PrivateKey) String() string

String implements the stringer interface.

type PublicKey

type PublicKey ecdsa.PublicKey

PublicKey represents a public key and provides a high level API around ecdsa.PublicKey.

func NewPublicKeyFromASN1

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

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(b []byte, curve elliptic.Curve) (*PublicKey, error)

NewPublicKeyFromBytes returns public key created from b using given EC.

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() common.Address

func (*PublicKey) Bytes

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

Bytes returns byte array representation of the public key in compressed form (33 bytes with 0x02 or 0x03 prefix, except infinity which is always 0).

func (*PublicKey) Cmp

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

Cmp compares two keys.

func (PublicKey) CreateVerificationScript

func (p PublicKey) CreateVerificationScript() []byte

func (*PublicKey) DecodeBinary

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

DecodeBinary decodes a PublicKey from the given BinReader using information about the EC curve to decompress Y point. Secp256r1 is a default value for EC curve.

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

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

Equal returns true in case public keys are equal.

func (PublicKey) GetScriptHash

func (p PublicKey) GetScriptHash() common.Address

GetScriptHash returns a Hash160 of verification script for the key.

func (*PublicKey) IsInfinity

func (p *PublicKey) IsInfinity() bool

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

func (PublicKey) MarshalJSON

func (p PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*PublicKey) String

func (p *PublicKey) String() string

String implements the Stringer interface.

func (*PublicKey) UncompressedBytes

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

UncompressedBytes returns byte array representation of the public key in uncompressed form (65 bytes with 0x04 prefix, except infinity which is always 0).

func (*PublicKey) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler 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.

func (*PublicKey) VerifyHashable

func (p *PublicKey) VerifyHashable(signature []byte, chainId uint64, hh hash.Hashable) bool

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

type PublicKeys

type PublicKeys []*PublicKey

Parameters is a list of public keys.

func NewPublicKeysFromStrings

func NewPublicKeysFromStrings(ss []string) (PublicKeys, error)

NewPublicKeysFromStrings converts an array of string-encoded P256 public keys into an array of Parameters.

func (*PublicKeys) Bytes

func (keys *PublicKeys) Bytes() []byte

Bytes encodes Parameters to the new slice of bytes.

func (PublicKeys) Contains

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

Contains checks whether passed param contained in Parameters.

func (PublicKeys) Copy

func (keys PublicKeys) Copy() PublicKeys

Copy returns copy of keys.

func (PublicKeys) CreateDefaultMultiSigRedeemScript

func (keys PublicKeys) CreateDefaultMultiSigRedeemScript() ([]byte, error)

func (PublicKeys) CreateMajorityMultiSigRedeemScript

func (keys PublicKeys) CreateMajorityMultiSigRedeemScript() ([]byte, error)

func (PublicKeys) CreateMultiSigVerificationScript

func (keys PublicKeys) CreateMultiSigVerificationScript(m int) ([]byte, error)

func (*PublicKeys) DecodeBytes

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

DecodeBytes decodes a Parameters 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

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.

Jump to

Keyboard shortcuts

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