Documentation ¶
Overview ¶
Package keys wraps public/private keys and implements NEP-2 and WIF.
Index ¶
- Constants
- func NEP2Encrypt(priv *PrivateKey, passphrase string, params ScryptParams) (s string, err error)
- func WIFEncode(key []byte, version byte, compressed bool) (s string, err error)
- type PrivateKey
- func NEP2Decrypt(key, passphrase string, params ScryptParams) (*PrivateKey, error)
- func NewPrivateKey() (*PrivateKey, error)
- func NewPrivateKeyFromASN1(b []byte) (*PrivateKey, error)
- func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error)
- func NewPrivateKeyFromHex(str string) (*PrivateKey, error)
- func NewPrivateKeyFromWIF(wif string) (*PrivateKey, error)
- func NewSecp256k1PrivateKey() (*PrivateKey, error)
- func (p *PrivateKey) Address() string
- func (p *PrivateKey) Bytes() []byte
- func (p *PrivateKey) Destroy()
- func (p *PrivateKey) GetScriptHash() util.Uint160
- func (p *PrivateKey) PublicKey() *PublicKey
- func (p *PrivateKey) Sign(data []byte) []byte
- func (p *PrivateKey) SignHash(digest util.Uint256) []byte
- func (p *PrivateKey) SignHashable(net uint32, hh hash.Hashable) []byte
- func (p *PrivateKey) String() string
- func (p *PrivateKey) WIF() string
- type PublicKey
- func (p *PublicKey) Address() string
- func (p *PublicKey) Bytes() []byte
- func (p *PublicKey) Cmp(key *PublicKey) int
- func (p *PublicKey) DecodeBinary(r *io.BinReader)
- func (p *PublicKey) DecodeBytes(data []byte) error
- func (p *PublicKey) EncodeBinary(w *io.BinWriter)
- func (p *PublicKey) Equal(key *PublicKey) bool
- func (p *PublicKey) GetScriptHash() util.Uint160
- func (p *PublicKey) GetVerificationScript() []byte
- func (p *PublicKey) IsInfinity() bool
- func (p PublicKey) MarshalJSON() ([]byte, error)
- func (p *PublicKey) MarshalYAML() (any, error)
- func (p *PublicKey) String() string
- func (p *PublicKey) StringCompressed() string
- func (p *PublicKey) UncompressedBytes() []byte
- func (p *PublicKey) UnmarshalJSON(data []byte) error
- func (p *PublicKey) UnmarshalYAML(unmarshal func(any) error) error
- func (p *PublicKey) Verify(signature []byte, hash []byte) bool
- func (p *PublicKey) VerifyHashable(signature []byte, net uint32, hh hash.Hashable) bool
- type PublicKeys
- func (keys *PublicKeys) Bytes() []byte
- func (keys PublicKeys) Contains(pKey *PublicKey) bool
- func (keys PublicKeys) Copy() PublicKeys
- func (keys *PublicKeys) DecodeBytes(data []byte) error
- func (keys PublicKeys) Len() int
- func (keys PublicKeys) Less(i, j int) bool
- func (keys PublicKeys) Swap(i, j int)
- func (keys PublicKeys) Unique() PublicKeys
- type ScryptParams
- type WIF
Constants ¶
const SignatureLen = 64
SignatureLen is the length of a standard signature for 256-bit EC key.
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, params ScryptParams) (s string, err error)
NEP2Encrypt encrypts a the PrivateKey using the given passphrase under the NEP-2 standard.
Types ¶
type PrivateKey ¶
type PrivateKey struct {
ecdsa.PrivateKey
}
PrivateKey represents a Neo private key and provides a high level API around ecdsa.PrivateKey.
func NEP2Decrypt ¶
func NEP2Decrypt(key, passphrase string, params ScryptParams) (*PrivateKey, error)
NEP2Decrypt decrypts an encrypted key using the given passphrase under the NEP-2 standard.
func NewPrivateKey ¶
func NewPrivateKey() (*PrivateKey, error)
NewPrivateKey creates a new random Secp256r1 private key.
func NewPrivateKeyFromASN1 ¶
func NewPrivateKeyFromASN1(b []byte) (*PrivateKey, error)
NewPrivateKeyFromASN1 returns a NEO Secp256k1 PrivateKey from the ASN.1 serialized key.
func NewPrivateKeyFromBytes ¶
func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error)
NewPrivateKeyFromBytes returns a NEO Secp256r1 PrivateKey from the given byte slice.
func NewPrivateKeyFromHex ¶
func NewPrivateKeyFromHex(str string) (*PrivateKey, error)
NewPrivateKeyFromHex returns a Secp256k1 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 NewSecp256k1PrivateKey ¶ added in v0.92.0
func NewSecp256k1PrivateKey() (*PrivateKey, error)
NewSecp256k1PrivateKey creates a new random Secp256k1 private key.
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) Destroy ¶ added in v0.99.3
func (p *PrivateKey) Destroy()
Destroy wipes the contents of the private key from memory. Any operations with the key after call to Destroy have undefined behavior.
func (*PrivateKey) GetScriptHash ¶
func (p *PrivateKey) GetScriptHash() util.Uint160
GetScriptHash returns verification script hash for the 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. 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 ¶ added in v0.92.0
func (p *PrivateKey) SignHash(digest util.Uint256) []byte
SignHash signs a particular hash with the private key.
func (*PrivateKey) SignHashable ¶ added in v0.94.1
func (p *PrivateKey) SignHashable(net uint32, 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.
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 ¶
PublicKey represents a public key and provides a high level API around ecdsa.PublicKey.
func NewPublicKeyFromASN1 ¶
NewPublicKeyFromASN1 returns a NEO PublicKey from the ASN.1 serialized key.
func NewPublicKeyFromBytes ¶ added in v0.90.0
NewPublicKeyFromBytes returns a public key created from b using the given EC.
func NewPublicKeyFromString ¶
NewPublicKeyFromString returns a public key created from the given hex string public key representation in compressed form.
func (*PublicKey) Address ¶
Address returns a base58-encoded NEO-specific address based on the key hash.
func (*PublicKey) Bytes ¶
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) DecodeBinary ¶
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 ¶
DecodeBytes decodes a PublicKey from the given slice of bytes.
func (*PublicKey) EncodeBinary ¶
EncodeBinary encodes a PublicKey to the given BinWriter.
func (*PublicKey) GetScriptHash ¶
GetScriptHash returns a Hash160 of verification script for the key.
func (*PublicKey) GetVerificationScript ¶
GetVerificationScript returns NEO VM bytecode with CHECKSIG command for the public key.
func (*PublicKey) IsInfinity ¶
IsInfinity checks if the key is infinite (null, basically).
func (PublicKey) MarshalJSON ¶ added in v0.75.0
MarshalJSON implements the json.Marshaler interface.
func (*PublicKey) MarshalYAML ¶ added in v0.103.0
MarshalYAML implements the YAML marshaler interface.
func (*PublicKey) StringCompressed ¶ added in v0.106.0
StringCompressed returns the hex string representation of the public key in its compressed form.
func (*PublicKey) UncompressedBytes ¶ added in v0.76.0
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 ¶ added in v0.75.0
UnmarshalJSON implements the json.Unmarshaler interface.
func (*PublicKey) UnmarshalYAML ¶ added in v0.103.0
UnmarshalYAML implements the YAML unmarshaler interface.
type PublicKeys ¶
type PublicKeys []*PublicKey
PublicKeys is a list of public keys.
func NewPublicKeysFromStrings ¶ added in v0.98.2
func NewPublicKeysFromStrings(ss []string) (PublicKeys, error)
NewPublicKeysFromStrings converts an array of string-encoded P256 public keys into an array of PublicKeys.
func (*PublicKeys) Bytes ¶ added in v0.90.0
func (keys *PublicKeys) Bytes() []byte
Bytes encodes PublicKeys to the new slice of bytes.
func (PublicKeys) Contains ¶
func (keys PublicKeys) Contains(pKey *PublicKey) bool
Contains checks whether the passed param is contained in PublicKeys.
func (PublicKeys) Copy ¶ added in v0.90.0
func (keys PublicKeys) Copy() PublicKeys
Copy returns a shallow copy of the PublicKeys slice. It creates a new slice with the same elements, but does not perform a deep copy of the elements themselves.
func (*PublicKeys) DecodeBytes ¶
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 ¶
func (keys PublicKeys) Unique() PublicKeys
Unique returns a set of public keys.
type ScryptParams ¶
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 // A string representation of the WIF. S string }
WIF represents a wallet import format.