github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/signature/errors.go (about)

     1  package signature
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  var (
     9  	ErrInvalidSignatureFormat = errors.New("signature's binary format is invalid")
    10  
    11  	ErrInsufficientShares = errors.New("insufficient threshold signature shares")
    12  
    13  	// ErrIncompatibleBitVectorLength indicates that the bit vector's length is different than
    14  	// the expected length, based on the supplied node list.
    15  	ErrIncompatibleBitVectorLength = errors.New("bit vector has incompatible length")
    16  
    17  	// ErrIllegallyPaddedBitVector indicates that the index vector was padded with unexpected bit values.
    18  	ErrIllegallyPaddedBitVector = errors.New("index vector padded with unexpected bit values")
    19  
    20  	// ErrInvalidChecksum indicates that the index vector's checksum is invalid
    21  	ErrInvalidChecksum = errors.New("index vector's checksum is invalid")
    22  
    23  	// ErrIdentityPublicKey indicates that the signer's public keys add up to the BLS identity public key.
    24  	// Any signature would fail the cryptographic verification if verified against the
    25  	// the identity public key. This case can only happen if public keys were forged to sum up to
    26  	// an identity public key. If private keys are sampled uniformly at random, there is vanishing
    27  	// probability of generating the aggregated identity public key. However, (colluding) byzantine
    28  	// signers could force the generation of private keys that result in the identity aggregated key.
    29  	ErrIdentityPublicKey = errors.New("aggregated public key is identity and aggregated signature is invalid")
    30  )
    31  
    32  /* ********************* InvalidSignatureIncludedError ********************* */
    33  
    34  // InvalidSignatureIncludedError indicates that some signatures, included via TrustedAdd, are invalid
    35  type InvalidSignatureIncludedError struct {
    36  	err error
    37  }
    38  
    39  func NewInvalidSignatureIncludedErrorf(msg string, args ...interface{}) error {
    40  	return InvalidSignatureIncludedError{
    41  		err: fmt.Errorf(msg, args...),
    42  	}
    43  }
    44  
    45  func (e InvalidSignatureIncludedError) Error() string { return e.err.Error() }
    46  func (e InvalidSignatureIncludedError) Unwrap() error { return e.err }
    47  
    48  // IsInvalidSignatureIncludedError returns whether err is an InvalidSignatureIncludedError
    49  func IsInvalidSignatureIncludedError(err error) bool {
    50  	var e InvalidSignatureIncludedError
    51  	return errors.As(err, &e)
    52  }
    53  
    54  /* ************************* InvalidSignerIdxError ************************* */
    55  
    56  // InvalidSignerIdxError indicates that the signer index is invalid
    57  type InvalidSignerIdxError struct {
    58  	err error
    59  }
    60  
    61  func NewInvalidSignerIdxErrorf(msg string, args ...interface{}) error {
    62  	return InvalidSignerIdxError{
    63  		err: fmt.Errorf(msg, args...),
    64  	}
    65  }
    66  
    67  func (e InvalidSignerIdxError) Error() string { return e.err.Error() }
    68  func (e InvalidSignerIdxError) Unwrap() error { return e.err }
    69  
    70  // IsInvalidSignerIdxError returns whether err is an InvalidSignerIdxError
    71  func IsInvalidSignerIdxError(err error) bool {
    72  	var e InvalidSignerIdxError
    73  	return errors.As(err, &e)
    74  }
    75  
    76  /* ************************ DuplicatedSignerIdxError *********************** */
    77  
    78  // DuplicatedSignerIdxError indicates that a signature from the respective signer index was already added
    79  type DuplicatedSignerIdxError struct {
    80  	err error
    81  }
    82  
    83  func NewDuplicatedSignerIdxErrorf(msg string, args ...interface{}) error {
    84  	return DuplicatedSignerIdxError{
    85  		err: fmt.Errorf(msg, args...),
    86  	}
    87  }
    88  
    89  func (e DuplicatedSignerIdxError) Error() string { return e.err.Error() }
    90  func (e DuplicatedSignerIdxError) Unwrap() error { return e.err }
    91  
    92  // IsDuplicatedSignerIdxError returns whether err is an DuplicatedSignerIdxError
    93  func IsDuplicatedSignerIdxError(err error) bool {
    94  	var e DuplicatedSignerIdxError
    95  	return errors.As(err, &e)
    96  }
    97  
    98  /* ********************** InsufficientSignaturesError ********************** */
    99  
   100  // InsufficientSignaturesError indicates that not enough signatures have been stored to complete the operation.
   101  type InsufficientSignaturesError struct {
   102  	err error
   103  }
   104  
   105  func NewInsufficientSignaturesErrorf(msg string, args ...interface{}) error {
   106  	return InsufficientSignaturesError{
   107  		err: fmt.Errorf(msg, args...),
   108  	}
   109  }
   110  
   111  func (e InsufficientSignaturesError) Error() string { return e.err.Error() }
   112  func (e InsufficientSignaturesError) Unwrap() error { return e.err }
   113  
   114  // IsInsufficientSignaturesError returns whether err is an InsufficientSignaturesError
   115  func IsInsufficientSignaturesError(err error) bool {
   116  	var e InsufficientSignaturesError
   117  	return errors.As(err, &e)
   118  }
   119  
   120  /* ********************** InvalidSignerIndicesError ********************** */
   121  
   122  // InvalidSignerIndicesError indicates that a bit vector does not encode a valid set of signers
   123  type InvalidSignerIndicesError struct {
   124  	err error
   125  }
   126  
   127  func NewInvalidSignerIndicesErrorf(msg string, args ...interface{}) error {
   128  	return InvalidSignerIndicesError{
   129  		err: fmt.Errorf(msg, args...),
   130  	}
   131  }
   132  
   133  func (e InvalidSignerIndicesError) Error() string { return e.err.Error() }
   134  func (e InvalidSignerIndicesError) Unwrap() error { return e.err }
   135  
   136  // IsInvalidSignerIndicesError returns whether err is an InvalidSignerIndicesError
   137  func IsInvalidSignerIndicesError(err error) bool {
   138  	var e InvalidSignerIndicesError
   139  	return errors.As(err, &e)
   140  }
   141  
   142  /* ********************** InvalidSignerIndicesError ********************** */
   143  
   144  // InvalidSigTypesError indicates that the given data not encode valid signature types
   145  type InvalidSigTypesError struct {
   146  	err error
   147  }
   148  
   149  func NewInvalidSigTypesErrorf(msg string, args ...interface{}) error {
   150  	return InvalidSigTypesError{
   151  		err: fmt.Errorf(msg, args...),
   152  	}
   153  }
   154  
   155  func (e InvalidSigTypesError) Error() string { return e.err.Error() }
   156  func (e InvalidSigTypesError) Unwrap() error { return e.err }
   157  
   158  // IsInvalidSigTypesError returns whether err is an InvalidSigTypesError
   159  func IsInvalidSigTypesError(err error) bool {
   160  	var e InvalidSigTypesError
   161  	return errors.As(err, &e)
   162  }