diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-30 09:01:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-30 09:01:54 +0800 |
commit | f2c13bd773c9684356a8a992d783916d49e70b59 (patch) | |
tree | 8cb875496ebbe21b7497d4482c9947bfbf73eb2f /core/authenticator.go | |
parent | 7ee55d0963555a1dfb212f0fb5c2ee59bedfb221 (diff) | |
download | tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar.gz tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar.bz2 tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar.lz tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar.xz tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.tar.zst tangerine-consensus-f2c13bd773c9684356a8a992d783916d49e70b59.zip |
core: integrate authenticator (#150)
Diffstat (limited to 'core/authenticator.go')
-rw-r--r-- | core/authenticator.go | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/core/authenticator.go b/core/authenticator.go index 7e6505d..91477c5 100644 --- a/core/authenticator.go +++ b/core/authenticator.go @@ -25,21 +25,24 @@ import ( // Authenticator verify data owner. type Authenticator struct { - prvKey crypto.PrivateKey - pubKey crypto.PublicKey + prvKey crypto.PrivateKey + pubKey crypto.PublicKey + proposerID types.NodeID } // NewAuthenticator constructs an Authenticator instance. -func NewAuthenticator(prvKey crypto.PrivateKey) *Authenticator { - return &Authenticator{ +func NewAuthenticator(prvKey crypto.PrivateKey) (auth *Authenticator) { + auth = &Authenticator{ prvKey: prvKey, pubKey: prvKey.PublicKey(), } + auth.proposerID = types.NewNodeID(auth.pubKey) + return } // SignBlock signs a types.Block. func (au *Authenticator) SignBlock(b *types.Block) (err error) { - b.ProposerID = types.NewNodeID(au.pubKey) + b.ProposerID = au.proposerID if b.Hash, err = hashBlock(b); err != nil { return } @@ -51,14 +54,14 @@ func (au *Authenticator) SignBlock(b *types.Block) (err error) { // SignVote signs a types.Vote. func (au *Authenticator) SignVote(v *types.Vote) (err error) { - v.ProposerID = types.NewNodeID(au.pubKey) + v.ProposerID = au.proposerID v.Signature, err = au.prvKey.Sign(hashVote(v)) return } // SignCRS signs CRS signature of types.Block. func (au *Authenticator) SignCRS(b *types.Block, crs common.Hash) (err error) { - if b.ProposerID != types.NewNodeID(au.pubKey) { + if b.ProposerID != au.proposerID { err = ErrInvalidProposerID return } @@ -66,6 +69,59 @@ func (au *Authenticator) SignCRS(b *types.Block, crs common.Hash) (err error) { return } +// SignAsWitnessAck create a witness ack from a confirmed block. +func (au *Authenticator) SignAsWitnessAck( + b *types.Block) (wAck *types.WitnessAck, err error) { + + hash, err := hashWitness(b) + if err != nil { + return + } + sig, err := au.prvKey.Sign(hash) + if err != nil { + return + } + wAck = &types.WitnessAck{ + ProposerID: au.proposerID, + WitnessBlockHash: b.Hash, + Signature: sig, + Hash: hash, + } + return +} + +// SignDKGComplaint signs a DKG complaint. +func (au *Authenticator) SignDKGComplaint( + complaint *types.DKGComplaint) (err error) { + complaint.ProposerID = au.proposerID + complaint.Signature, err = au.prvKey.Sign(hashDKGComplaint(complaint)) + return +} + +// SignDKGMasterPublicKey signs a DKG master public key. +func (au *Authenticator) SignDKGMasterPublicKey( + mpk *types.DKGMasterPublicKey) (err error) { + mpk.ProposerID = au.proposerID + mpk.Signature, err = au.prvKey.Sign(hashDKGMasterPublicKey(mpk)) + return +} + +// SignDKGPrivateShare signs a DKG private share. +func (au *Authenticator) SignDKGPrivateShare( + prvShare *types.DKGPrivateShare) (err error) { + prvShare.ProposerID = au.proposerID + prvShare.Signature, err = au.prvKey.Sign(hashDKGPrivateShare(prvShare)) + return +} + +// SignDKGPartialSignature signs a DKG partial signature. +func (au *Authenticator) SignDKGPartialSignature( + pSig *types.DKGPartialSignature) (err error) { + pSig.ProposerID = au.proposerID + pSig.Signature, err = au.prvKey.Sign(hashDKGPartialSignature(pSig)) + return +} + // VerifyBlock verifies the signature of types.Block. func (au *Authenticator) VerifyBlock(b *types.Block) (err error) { hash, err := hashBlock(b) |