-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4316 from ElrondNetwork/signatures-holder-component
Signature handler component for consensus
- Loading branch information
Showing
22 changed files
with
1,262 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package mock | ||
|
||
// SignatureHandlerStub implements SignatureHandler interface | ||
type SignatureHandlerStub struct { | ||
ResetCalled func(pubKeys []string) error | ||
CreateSignatureShareCalled func(msg []byte, index uint16, epoch uint32) ([]byte, error) | ||
StoreSignatureShareCalled func(index uint16, sig []byte) error | ||
SignatureShareCalled func(index uint16) ([]byte, error) | ||
VerifySignatureShareCalled func(index uint16, sig []byte, msg []byte, epoch uint32) error | ||
AggregateSigsCalled func(bitmap []byte, epoch uint32) ([]byte, error) | ||
SetAggregatedSigCalled func(_ []byte) error | ||
VerifyCalled func(msg []byte, bitmap []byte, epoch uint32) error | ||
} | ||
|
||
// Reset - | ||
func (stub *SignatureHandlerStub) Reset(pubKeys []string) error { | ||
if stub.ResetCalled != nil { | ||
return stub.ResetCalled(pubKeys) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CreateSignatureShare - | ||
func (stub *SignatureHandlerStub) CreateSignatureShare(msg []byte, index uint16, epoch uint32) ([]byte, error) { | ||
if stub.CreateSignatureShareCalled != nil { | ||
return stub.CreateSignatureShareCalled(msg, index, epoch) | ||
} | ||
|
||
return []byte("sigShare"), nil | ||
} | ||
|
||
// StoreSignatureShare - | ||
func (stub *SignatureHandlerStub) StoreSignatureShare(index uint16, sig []byte) error { | ||
if stub.StoreSignatureShareCalled != nil { | ||
return stub.StoreSignatureShareCalled(index, sig) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SignatureShare - | ||
func (stub *SignatureHandlerStub) SignatureShare(index uint16) ([]byte, error) { | ||
if stub.SignatureShareCalled != nil { | ||
return stub.SignatureShareCalled(index) | ||
} | ||
|
||
return []byte("sigShare"), nil | ||
} | ||
|
||
// VerifySignatureShare - | ||
func (stub *SignatureHandlerStub) VerifySignatureShare(index uint16, sig []byte, msg []byte, epoch uint32) error { | ||
if stub.VerifySignatureShareCalled != nil { | ||
return stub.VerifySignatureShareCalled(index, sig, msg, epoch) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// AggregateSigs - | ||
func (stub *SignatureHandlerStub) AggregateSigs(bitmap []byte, epoch uint32) ([]byte, error) { | ||
if stub.AggregateSigsCalled != nil { | ||
return stub.AggregateSigsCalled(bitmap, epoch) | ||
} | ||
|
||
return []byte("aggSigs"), nil | ||
} | ||
|
||
// SetAggregatedSig - | ||
func (stub *SignatureHandlerStub) SetAggregatedSig(sig []byte) error { | ||
if stub.SetAggregatedSigCalled != nil { | ||
return stub.SetAggregatedSigCalled(sig) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Verify - | ||
func (stub *SignatureHandlerStub) Verify(msg []byte, bitmap []byte, epoch uint32) error { | ||
if stub.VerifyCalled != nil { | ||
return stub.VerifyCalled(msg, bitmap, epoch) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// IsInterfaceNil - | ||
func (stub *SignatureHandlerStub) IsInterfaceNil() bool { | ||
return stub == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package signing | ||
|
||
import "errors" | ||
|
||
// ErrInvalidSignature is raised for an invalid signature | ||
var ErrInvalidSignature = errors.New("invalid signature was provided") | ||
|
||
// ErrNilElement is raised when searching for a specific element but found nil | ||
var ErrNilElement = errors.New("element is nil") | ||
|
||
// ErrIndexNotSelected is raised when a not selected index is used for multi-signing | ||
var ErrIndexNotSelected = errors.New("index is not selected") | ||
|
||
// ErrNilBitmap is raised when a nil bitmap is used | ||
var ErrNilBitmap = errors.New("bitmap is nil") | ||
|
||
// ErrNoPrivateKeySet is raised when no private key was set | ||
var ErrNoPrivateKeySet = errors.New("no private key was set") | ||
|
||
// ErrNoPublicKeySet is raised when no public key was set for a multisignature | ||
var ErrNoPublicKeySet = errors.New("no public key was set") | ||
|
||
// ErrNilKeyGenerator is raised when a valid key generator is expected but nil used | ||
var ErrNilKeyGenerator = errors.New("key generator is nil") | ||
|
||
// ErrNilPublicKeys is raised when public keys are expected but received nil | ||
var ErrNilPublicKeys = errors.New("public keys are nil") | ||
|
||
// ErrNilMultiSignerContainer is raised when a nil multi signer container has been provided | ||
var ErrNilMultiSignerContainer = errors.New("multi signer container is nil") | ||
|
||
// ErrIndexOutOfBounds is raised when an out of bound index is used | ||
var ErrIndexOutOfBounds = errors.New("index is out of bounds") | ||
|
||
// ErrEmptyPubKeyString is raised when an empty public key string is used | ||
var ErrEmptyPubKeyString = errors.New("public key string is empty") | ||
|
||
// ErrNilMessage is raised when trying to verify a nil signed message or trying to sign a nil message | ||
var ErrNilMessage = errors.New("message to be signed or to be verified is nil") | ||
|
||
// ErrBitmapMismatch is raised when an invalid bitmap is passed to the multisigner | ||
var ErrBitmapMismatch = errors.New("multi signer reported a mismatch in used bitmap") |
Oops, something went wrong.