These constants are used to identify a specific Error.
const ( // ErrSigTooShort is returned when a signature that should be a DER // signature is too short. ErrSigTooShort = ErrorKind("ErrSigTooShort") // ErrSigTooLong is returned when a signature that should be a DER signature // is too long. ErrSigTooLong = ErrorKind("ErrSigTooLong") // ErrSigInvalidSeqID is returned when a signature that should be a DER // signature does not have the expected ASN.1 sequence ID. ErrSigInvalidSeqID = ErrorKind("ErrSigInvalidSeqID") // ErrSigInvalidDataLen is returned when a signature that should be a DER // signature does not specify the correct number of remaining bytes for the // R and S portions. ErrSigInvalidDataLen = ErrorKind("ErrSigInvalidDataLen") // ErrSigMissingSTypeID is returned when a signature that should be a DER // signature does not provide the ASN.1 type ID for S. ErrSigMissingSTypeID = ErrorKind("ErrSigMissingSTypeID") // ErrSigMissingSLen is returned when a signature that should be a DER // signature does not provide the length of S. ErrSigMissingSLen = ErrorKind("ErrSigMissingSLen") // ErrSigInvalidSLen is returned when a signature that should be a DER // signature does not specify the correct number of bytes for the S portion. ErrSigInvalidSLen = ErrorKind("ErrSigInvalidSLen") // ErrSigInvalidRIntID is returned when a signature that should be a DER // signature does not have the expected ASN.1 integer ID for R. ErrSigInvalidRIntID = ErrorKind("ErrSigInvalidRIntID") // ErrSigZeroRLen is returned when a signature that should be a DER // signature has an R length of zero. ErrSigZeroRLen = ErrorKind("ErrSigZeroRLen") // ErrSigNegativeR is returned when a signature that should be a DER // signature has a negative value for R. ErrSigNegativeR = ErrorKind("ErrSigNegativeR") // ErrSigTooMuchRPadding is returned when a signature that should be a DER // signature has too much padding for R. ErrSigTooMuchRPadding = ErrorKind("ErrSigTooMuchRPadding") // ErrSigRIsZero is returned when a signature has R set to the value zero. ErrSigRIsZero = ErrorKind("ErrSigRIsZero") // ErrSigRTooBig is returned when a signature has R with a value that is // greater than or equal to the group order. ErrSigRTooBig = ErrorKind("ErrSigRTooBig") // ErrSigInvalidSIntID is returned when a signature that should be a DER // signature does not have the expected ASN.1 integer ID for S. ErrSigInvalidSIntID = ErrorKind("ErrSigInvalidSIntID") // ErrSigZeroSLen is returned when a signature that should be a DER // signature has an S length of zero. ErrSigZeroSLen = ErrorKind("ErrSigZeroSLen") // ErrSigNegativeS is returned when a signature that should be a DER // signature has a negative value for S. ErrSigNegativeS = ErrorKind("ErrSigNegativeS") // ErrSigTooMuchSPadding is returned when a signature that should be a DER // signature has too much padding for S. ErrSigTooMuchSPadding = ErrorKind("ErrSigTooMuchSPadding") // ErrSigSIsZero is returned when a signature has S set to the value zero. ErrSigSIsZero = ErrorKind("ErrSigSIsZero") // ErrSigSTooBig is returned when a signature has S with a value that is // greater than or equal to the group order. ErrSigSTooBig = ErrorKind("ErrSigSTooBig") // ErrSigInvalidLen is returned when a signature that should be a compact // signature is not the required length. ErrSigInvalidLen = ErrorKind("ErrSigInvalidLen") // ErrSigInvalidRecoveryCode is returned when a signature that should be a // compact signature has an invalid value for the public key recovery code. ErrSigInvalidRecoveryCode = ErrorKind("ErrSigInvalidRecoveryCode") // ErrSigOverflowsPrime is returned when a signature that should be a // compact signature has the overflow bit set but adding the order to it // would overflow the underlying field prime. ErrSigOverflowsPrime = ErrorKind("ErrSigOverflowsPrime") // ErrPointNotOnCurve is returned when attempting to recover a public key // from a compact signature results in a point that is not on the elliptic // curve. ErrPointNotOnCurve = ErrorKind("ErrPointNotOnCurve") )
func RecoverCompact(signature, hash []byte) (*secp256k1.PublicKey, bool, error)
RecoverCompact attempts to recover the secp256k1 public key from the provided compact signature and message hash. It first verifies the signature, and, if the signature matches then the recovered public key will be returned as well as a boolean indicating whether or not the original key was compressed.
func SignCompact(key *secp256k1.PrivateKey, hash []byte, isCompressedKey bool) []byte
SignCompact produces a compact ECDSA signature over the secp256k1 curve for the provided hash (which should be the result of hashing a larger message) using the given private key. The isCompressedKey parameter specifies if the produced signature should reference a compressed public key or not.
Compact signature format: <1-byte compact sig recovery code><32-byte R><32-byte S>
The compact sig recovery code is the value 27 + public key recovery code + 4 if the compact signature was created with a compressed public key.
Error identifies an error related to an ECDSA signature. It has full support for errors.Is and errors.As, so the caller can ascertain the specific reason for the error by checking the underlying error.
type Error struct { Err error Description string }
func (e Error) Error() string
Error satisfies the error interface and prints human-readable errors.
func (e Error) Unwrap() error
Unwrap returns the underlying wrapped error.
ErrorKind identifies a kind of error. It has full support for errors.Is and errors.As, so the caller can directly check against an error kind when determining the reason for an error.
type ErrorKind string
func (e ErrorKind) Error() string
Error satisfies the error interface and prints human-readable errors.
Signature is a type representing an ECDSA signature.
type Signature struct {
// contains filtered or unexported fields
}
func NewSignature(r, s *secp256k1.ModNScalar) *Signature
NewSignature instantiates a new signature given some r and s values.
func ParseDERSignature(sig []byte) (*Signature, error)
ParseDERSignature parses a signature in the Distinguished Encoding Rules (DER) format per section 10 of [ISO/IEC 8825-1] and enforces the following additional restrictions specific to secp256k1:
- The R and S values must be in the valid range for secp256k1 scalars:
func Sign(key *secp256k1.PrivateKey, hash []byte) *Signature
Sign generates an ECDSA signature over the secp256k1 curve for the provided hash (which should be the result of hashing a larger message) using the given private key. The produced signature is deterministic (same message and same key yield the same signature) and canonical in accordance with RFC6979 and BIP0062.
▹ Example
func (sig *Signature) IsEqual(otherSig *Signature) bool
IsEqual compares this Signature instance to the one passed, returning true if both Signatures are equivalent. A signature is equivalent to another, if they both have the same scalar value for R and S.
func (sig *Signature) R() secp256k1.ModNScalar
R returns the r value of the signature.
func (sig *Signature) S() secp256k1.ModNScalar
S returns the s value of the signature.
func (sig *Signature) Serialize() []byte
Serialize returns the ECDSA signature in the Distinguished Encoding Rules (DER) format per section 10 of [ISO/IEC 8825-1] and such that the S component of the signature is less than or equal to the half order of the group.
Note that the serialized bytes returned do not include the appended hash type used in Decred signature scripts.
func (sig *Signature) Verify(hash []byte, pubKey *secp256k1.PublicKey) bool
Verify returns whether or not the signature is valid for the provided hash and secp256k1 public key.
▹ Example