diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-23 15:17:52 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:16 +0800 |
commit | 9f723203a14fbe3f4ac087d2b7309381d7d1b419 (patch) | |
tree | 560f4f7b31186bc0fa3ff7ee18b4aa079c5f6c7a /vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go | |
parent | 18b940c6840e1030be76945207fb5bdf6323d696 (diff) | |
download | go-tangerine-9f723203a14fbe3f4ac087d2b7309381d7d1b419.tar.gz go-tangerine-9f723203a14fbe3f4ac087d2b7309381d7d1b419.tar.zst go-tangerine-9f723203a14fbe3f4ac087d2b7309381d7d1b419.zip |
vendor: use govendor to import dexon-consensus-core
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go new file mode 100644 index 000000000..f8d11b3c9 --- /dev/null +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg/utils.go @@ -0,0 +1,71 @@ +// Copyright 2018 The dexon-consensus-core Authors +// This file is part of the dexon-consensus-core library. +// +// The dexon-consensus-core library is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// The dexon-consensus-core library is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the dexon-consensus-core library. If not, see +// <http://www.gnu.org/licenses/>. + +package dkg + +import ( + "fmt" + + "github.com/dexon-foundation/bls/ffi/go/bls" + + "github.com/dexon-foundation/dexon-consensus-core/core/crypto" +) + +// PartialSignature is a partial signature in DKG+TSIG protocol. +type PartialSignature crypto.Signature + +var ( + // ErrEmptySignature is reported if the signature is empty. + ErrEmptySignature = fmt.Errorf("invalid empty signature") +) + +// RecoverSignature recovers TSIG signature. +func RecoverSignature(sigs []PartialSignature, signerIDs IDs) ( + crypto.Signature, error) { + blsSigs := make([]bls.Sign, len(sigs)) + for i, sig := range sigs { + if len(sig.Signature) == 0 { + return crypto.Signature{}, ErrEmptySignature + } + if err := blsSigs[i].Deserialize([]byte(sig.Signature)); err != nil { + return crypto.Signature{}, err + } + } + var recoverSig bls.Sign + if err := recoverSig.Recover(blsSigs, []bls.ID(signerIDs)); err != nil { + return crypto.Signature{}, err + } + return crypto.Signature{ + Type: cryptoType, + Signature: recoverSig.Serialize()}, nil +} + +// RecoverGroupPublicKey recovers group public key. +func RecoverGroupPublicKey(pubShares []*PublicKeyShares) *PublicKey { + var pub *PublicKey + for _, pubShare := range pubShares { + pk0 := pubShare.masterPublicKey[0] + if pub == nil { + pub = &PublicKey{ + publicKey: pk0, + } + } else { + pub.publicKey.Add(&pk0) + } + } + return pub +} |