Categorygithub.com/nspcc-dev/neofs-crypto
modulepackage
0.4.1
Repository: https://github.com/nspcc-dev/neofs-crypto.git
Documentation: pkg.go.dev

# README

NeoFS Crypto library

¡Atención! This library is deprecated and no longer supported.

For WIF, key management and RFC6979 signatures please refer to github.com/nspcc-dev/neo-go/pkg/crypto/keys and github.com/nspcc-dev/rfc6979. For NeoFS-specific signatures with SHA-512 hashes use github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa.

This package contained useful methods to work with crypto-primitives used in NeoFS/Neo.

Examples

Simple Marshal / Unmarshal ECDSA public key (PK):

// returns slice of 33 bytes marshaled public key
data := crypto.MarshalPublicKey(&sk.PublicKey)

// returns public key decoded from 33 bytes    
pk := crypto.UnmarshalPublicKey(data)

Simple Marshal / Unmarshal ECDSA private key (SK):

// returns slice of 32 bytes marshaled private key
data := crypto.MarshalPrivateKey(&sk)

// returns private key decoded from 32 bytes or error,
// if something whet wrong    
newSk, err := crypto.UnmarshalPrivateKey(data)

ECDSA Sign / Verify bytes using PK / SK

// Sign returns signature (slice of 65 bytes) of SK for passed message (slice of bytes),
// or error, if something went wrong:
signature, err := crypto.Sign(sk, message)

// Verify returns error message if PK is empty or
// passed wrong signature (slice of 65 bytes) for message (slice of bytes),
err := crypto.Verify(&sk.PublicKey, signature, message)  

RFC6979 Sign / Verify bytes using PK / SK

// Sign returns signature (slice of 64 bytes) of SK for passed message (slice of bytes),
// or error, if something went wrong:
signature, err := crypto.SignRFC6979(sk, message)

// Verify returns error message if PK is empty or
// passed wrong signature (slice of 64 bytes) for message (slice of bytes),
err := crypto.VerifyRFC6979(&sk.PublicKey, signature, message)  

WIF Encode / Decode private key (SK)

// WIFEncode encodes the given private key into a WIF string.
// if sk or sk.D is empty, returns error
wif, err := crypto.WIFEncode(sk)

// WIFDecode decoded the given WIF string into a private key.
// if something went wrong, returns error:
skFromWIF, err := crypto.WIFDecode(wif)

LoadPrivateKey

// Load private key from wif format
sk, err := crypto.LoadPrivateKey(wif_string)

// Load private key from hex string
sk, err := crypto.LoadPrivateKey(hex_string)

// Load private key from file
sk, err := crypto.LoadPrivateKey(file_path)

# Packages

No description provided by the author

# Functions

LoadPrivateKey allows to load private key from various formats: - wif string - hex string - file path (D-bytes or SEC 1 / ASN.1 DER form).
MarshalPrivateKey to bytes.
MarshalPublicKey to bytes.
Sign signs a message using the private key.
SignHash signs message using it's hash and private key.
SignRFC6979 signs an arbitrary length hash (which should be the result of hashing a larger message) using the private key.
SignRFC6979Hash signs sha256 hash of the message using the private key.
UnmarshalPrivateKey from bytes.
UnmarshalPublicKey from bytes.
Verify verifies the signature of msg using the public key pub.
VerifyHash verifies the signature of msg using it's hash the public key pub.
VerifyRFC6979 verifies the signature of msg using the public key.
VerifyRFC6979 verifies the signature of msg using the public key.
WIFDecode decoded the given WIF string into a private key.
WIFEncode encodes the given private key into a WIF string.

# Constants

ErrBadChecksum when passed WIF-string could not be verified by last 4 bytes signature.
ErrBadWIF when passed WIF-string could not be decoded from base58.
ErrCannotUnmarshal when signature ([]byte) passed to Verify method has wrong format and cannot be parsed.
ErrEmptyPrivateKey when PK passed into WIFEncode method is nil.
ErrEmptyPublicKey when PK passed to Verify method is nil.
ErrInvalidSignature when signature passed to Verify method is mismatch.
ErrWrongHashSize when passed signature to VerifyRFC6979 has wrong size.
ErrWrongSignature when passed signature to VerifyRFC6979 isn't valid.
PrivateKeyCompressedSize is constant with compressed size of private key (SK).
PublicKeyCompressedSize is constant with compressed size of public key (PK).
PublicKeyUncompressedSize is constant with uncompressed size of public key (PK).
RFC6979SignatureSize contains r and s coordinates (32 bytes).
WIFLength constant length of WIF string.