Documentation
¶
Index ¶
- Constants
- func MarshalPrivateKey(key *ecdsa.PrivateKey) []byte
- func MarshalPublicKey(key *ecdsa.PublicKey) []byte
- func Sign(key *ecdsa.PrivateKey, data []byte) ([]byte, error)
- func SignRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error)
- func UnmarshalPrivateKey(data []byte) (*ecdsa.PrivateKey, error)
- func UnmarshalPublicKey(data []byte) *ecdsa.PublicKey
- func Verify(pub *ecdsa.PublicKey, hash, data []byte) error
- func VerifyRFC6979(key *ecdsa.PublicKey, hash, data []byte) error
- func WIFDecode(wif string) (*ecdsa.PrivateKey, error)
- func WIFEncode(key *ecdsa.PrivateKey) (string, error)
Constants ¶
const ( // ErrEmptyPublicKey when PK passed to Verify method is nil ErrEmptyPublicKey = internal.Error("empty public key") // ErrInvalidSignature when signature passed to Verify method is mismatch ErrInvalidSignature = internal.Error("invalid signature") // ErrCannotUnmarshal when signature ([]byte) passed to Verify method has wrong format // and cannot be parsed. ErrCannotUnmarshal = internal.Error("could not unmarshal signature") // PrivateKeyCompressedSize is constant with compressed size of private key (SK). // D coordinate stored, recover PK by formula x, y = curve.ScalarBaseMul(d,bytes). PrivateKeyCompressedSize = 32 // PublicKeyCompressedSize is constant with compressed size of public key (PK). PublicKeyCompressedSize = 33 // PublicKeyUncompressedSize is constant with uncompressed size of public key (PK). // First byte always should be 0x4 other 64 bytes is X and Y (32 bytes per coordinate). // 2 * 32 + 1. PublicKeyUncompressedSize = 65 )
const ( // RFC6979SignatureSize contains r and s coordinates (32 bytes) RFC6979SignatureSize = 64 // ErrWrongHashSize when passed signature to VerifyRFC6979 has wrong size ErrWrongHashSize = internal.Error("wrong hash size") // ErrWrongSignature when passed signature to VerifyRFC6979 isn't valid ErrWrongSignature = internal.Error("wrong signature") )
const ( // WIFLength constant length of WIF string. WIFLength = 38 // ErrBadWIF when passed WIF-string could not be decoded from base58. ErrBadWIF = internal.Error("bad wif") // ErrBadChecksum when passed WIF-string could not be verified // by last 4 bytes signature. ErrBadChecksum = internal.Error("bad checksum") // ErrEmptyPrivateKey when PK passed into WIFEncode method is nil ErrEmptyPrivateKey = internal.Error("empty private key") )
Variables ¶
This section is empty.
Functions ¶
func MarshalPrivateKey ¶
func MarshalPrivateKey(key *ecdsa.PrivateKey) []byte
MarshalPrivateKey to bytes
func MarshalPublicKey ¶
MarshalPublicKey to bytes
func Sign ¶
func Sign(key *ecdsa.PrivateKey, data []byte) ([]byte, error)
Sign signs a data using the private key. If the data is longer than the bit-length of the private key's curve order, the hash will be truncated to that length. It returns the signature as slice bytes. The security of the private key depends on the entropy of rand.
func SignRFC6979 ¶
func SignRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error)
SignRFC6979 signs an arbitrary length hash (which should be the result of hashing a larger message) using the private key. It returns the signature as a pair of integers.
Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated to the byte-length of the subgroup. This function does not perform that
func UnmarshalPrivateKey ¶
func UnmarshalPrivateKey(data []byte) (*ecdsa.PrivateKey, error)
UnmarshalPrivateKey method to parse SK from bytes. It is similar to `ecdsa.Generate()` but uses pre-defined big.Int and curve for NEO Blockchain Link - https://golang.org/pkg/crypto/ecdsa/#GenerateKey
func UnmarshalPublicKey ¶
UnmarshalPublicKey from bytes
func Verify ¶
Verify verifies the signature in r, s of hash using the public key, pub. Its return value records whether the signature is valid.
func VerifyRFC6979 ¶
VerifyRFC6979 verifies the signature in r, s of hash using the public key, pub. Its return value records whether the signature is valid.
Types ¶
This section is empty.