Documentation
¶
Overview ¶
Package keys wraps public/private keys and implements NEP-2 and WIF.
Index ¶
- Constants
- func GetDefaultHonestNodeCount(n int) int
- func GetMajorityHonestNodeCount(n int) int
- func NEP2Encrypt(priv *PrivateKey, passphrase string, params ScryptParams) (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 (p *PrivateKey) Address() common.Address
- func (p *PrivateKey) Bytes() []byte
- func (p *PrivateKey) GetScriptHash() common.Address
- func (p *PrivateKey) PublicKey() *PublicKey
- func (p *PrivateKey) Sign(data []byte) []byte
- func (p *PrivateKey) SignHash(digest common.Hash) []byte
- func (p *PrivateKey) SignHashable(chainId uint64, hh hash.Hashable) []byte
- func (p *PrivateKey) String() string
- type PublicKey
- func (p PublicKey) Address() common.Address
- func (p *PublicKey) Bytes() []byte
- func (p *PublicKey) Cmp(key *PublicKey) int
- func (p PublicKey) CreateVerificationScript() []byte
- 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() common.Address
- func (p *PublicKey) IsInfinity() bool
- func (p PublicKey) MarshalJSON() ([]byte, error)
- func (p *PublicKey) String() string
- func (p *PublicKey) UncompressedBytes() []byte
- func (p *PublicKey) UnmarshalJSON(data []byte) error
- func (p *PublicKey) Verify(signature []byte, hash []byte) bool
- func (p *PublicKey) VerifyHashable(signature []byte, chainId uint64, 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) CreateDefaultMultiSigRedeemScript() ([]byte, error)
- func (keys PublicKeys) CreateMajorityMultiSigRedeemScript() ([]byte, error)
- func (keys PublicKeys) CreateMultiSigVerificationScript(m int) ([]byte, error)
- 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
Constants ¶
const MaxMultiSigCount int = 21
MaxMultiSigCount
const SignatureLen = 64
SignatureLen is the length of standard signature for 256-bit EC key.
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 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 ¶
PublicKey represents a public key and provides a high level API around ecdsa.PublicKey.
func NewPublicKeyFromASN1 ¶
func NewPublicKeyFromBytes ¶
NewPublicKeyFromBytes returns public key created from b using given EC.
func NewPublicKeyFromString ¶
NewPublicKeyFromString returns a public key created from the given hex string.
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) CreateVerificationScript ¶
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) IsInfinity ¶
IsInfinity checks if the key is infinite (null, basically).
func (PublicKey) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*PublicKey) UncompressedBytes ¶
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 ¶
UnmarshalJSON implements json.Unmarshaler interface.
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) 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 ¶
ScryptParams is a json-serializable container for scrypt KDF parameters.
func NEP2ScryptParams ¶
func NEP2ScryptParams() ScryptParams
NEP2ScryptParams returns scrypt parameters specified in the NEP-2.