Documentation ¶
Index ¶
- Constants
- func GenerateKeyPair() (privKey *PrivateKey, pubKey *PublicKey)
- func SHA3Sum256(m []byte) []byte
- func SHASum256(m []byte) []byte
- type PrivateKey
- type PublicKey
- type Signature
- func (sig *Signature) HasV() bool
- func (sig *Signature) RecoverPublicKey(hash []byte) (*PublicKey, error)
- func (sig *Signature) SerializeRS() ([]byte, error)
- func (sig *Signature) SerializeRSV() ([]byte, error)
- func (sig *Signature) SerializeVRS() ([]byte, error)
- func (sig *Signature) String() string
- func (sig *Signature) Verify(msg []byte, pubKey *PublicKey) bool
Constants ¶
const ( // PublicKeyLenCompressed is the byte length of a compressed public key PublicKeyLenCompressed = 33 // PublicKeyLenUncompressed is the byte length of an uncompressed public key PublicKeyLenUncompressed = 65 )
const ( // SignatureLenRawWithV is the bytes length of signature including V value SignatureLenRawWithV = 65 // SignatureLenRaw is the bytes length of signature not including V value SignatureLenRaw = 64 // HashLen is the bytes length of hash for signature HashLen = 32 )
const (
// PrivateKeyLen is the byte length of a private key
PrivateKeyLen = 32
)
Variables ¶
This section is empty.
Functions ¶
func GenerateKeyPair ¶
func GenerateKeyPair() (privKey *PrivateKey, pubKey *PublicKey)
GenerateKeyPair generates a private and public key pair.
func SHA3Sum256 ¶
SHA3Sum256 returns the SHA3-256 digest of the data
Types ¶
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey is a type representing a private key. TODO private key always includes public key? or create KeyPair struct for both private key and public key
func ParsePrivateKey ¶
func ParsePrivateKey(b []byte) (*PrivateKey, error)
ParsePublicKey parse private key and return private key object.
func (*PrivateKey) Bytes ¶
func (key *PrivateKey) Bytes() []byte
Bytes returns bytes form of private key.
func (*PrivateKey) PublicKey ¶
func (key *PrivateKey) PublicKey() *PublicKey
PublicKey generates a public key paired with itself.
func (*PrivateKey) String ¶
func (key *PrivateKey) String() string
String returns the string representation.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is a type representing a public key, which can be serialized to or deserialized from compressed or uncompressed formats.
func ParsePublicKey ¶
ParsePublicKey parses the public key into a PublicKey instance. It supports uncompressed and compressed formats. NOTE: For the efficiency, it may use the slice directly. So don't change any internal value of the public key
func (*PublicKey) Equal ¶
Equal returns true if the given public key is same as this instance semantically
func (*PublicKey) SerializeCompressed ¶
SerializeCompressed serializes the public key in a 33-byte compressed format. For the efficiency, it returns the slice internally used, so don't change any internal value in the returned slice.
func (*PublicKey) SerializeUncompressed ¶
SerializeUncompressed serializes the public key in a 65-byte uncompressed format.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature is a type representing an ECDSA signature with or without V.
func NewSignature ¶
func NewSignature(hash []byte, privKey *PrivateKey) (*Signature, error)
NewSignature calculates an ECDSA signature including V, which is 0 or 1.
func ParseSignature ¶
ParseSignature parses a signature from the raw byte array of 64([R|S]) or 65([R|S|V]) bytes long. If a source signature is formatted as [V|R|S], call ParseSignatureVRS instead. NOTE: For the efficiency, it may use the slice directly. So don't change any internal value of the signature.
func ParseSignatureVRS ¶
ParseSignatureVRS parses a signature from the [V|R|S] formatted signature. If the format of a source signature is different, call ParseSignature instead.
func (*Signature) RecoverPublicKey ¶
RecoverPublicKey recovers a public key from the hash of message and its signature.
func (*Signature) SerializeRS ¶
SerializeRS returns the 64-byte data formatted as [R|S] from the signature. For the efficiency, it returns the slice internally used, so don't change any internal value in the returned slice.
func (*Signature) SerializeRSV ¶
SerializeRSV returns the 65-byte data formatted as [R|S|V] from the signature. Make sure that it has a valid V value. If it doesn't have V value, then it will throw error. For the efficiency, it returns the slice internally used, so don't change any internal value in the returned slice.
func (*Signature) SerializeVRS ¶
SerializeVRS returns the 65-byte data formatted as [V|R|S] from the signature. Make sure that it has a valid V value. If it doesn't have V value, then it will throw error. For the efficiency, it returns the slice internally used, so don't change any internal value in the returned slice.