crypto: add sr25519 signature scheme (#4190)

* sr25519

* added amino encoding

* fixed dependencies

* Apply suggestions from code review

Co-Authored-By: Tess Rinearson <tess.rinearson@gmail.com>
Co-Authored-By: Marko <marbar3778@yahoo.com>

* file structure

* Apply suggestions from code review

Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>

* address @melekes and @marbar3778 review

* removed nolint

* CHANGELOG and go-schnorrkel mod update
This commit is contained in:
Sunny Aggarwal
2019-12-05 09:41:38 +01:00
committed by Marko
co-authored by Tess Rinearson Marko Anton Kaliaev
parent 06b8752a46
commit b0bb8a1437
12 changed files with 322 additions and 4 deletions
+16
View File
@@ -9,6 +9,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/sr25519"
)
//-------------------------------------------------------
@@ -21,12 +22,14 @@ const (
const (
ABCIPubKeyTypeEd25519 = "ed25519"
ABCIPubKeyTypeSr25519 = "sr25519"
ABCIPubKeyTypeSecp256k1 = "secp256k1"
)
// TODO: Make non-global by allowing for registration of more pubkey types
var ABCIPubKeyTypesToAminoNames = map[string]string{
ABCIPubKeyTypeEd25519: ed25519.PubKeyAminoName,
ABCIPubKeyTypeSr25519: sr25519.PubKeyAminoName,
ABCIPubKeyTypeSecp256k1: secp256k1.PubKeyAminoName,
}
@@ -102,6 +105,11 @@ func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
Type: ABCIPubKeyTypeEd25519,
Data: pk[:],
}
case sr25519.PubKeySr25519:
return abci.PubKey{
Type: ABCIPubKeyTypeSr25519,
Data: pk[:],
}
case secp256k1.PubKeySecp256k1:
return abci.PubKey{
Type: ABCIPubKeyTypeSecp256k1,
@@ -194,6 +202,14 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
var pk ed25519.PubKeyEd25519
copy(pk[:], pubKey.Data)
return pk, nil
case ABCIPubKeyTypeSr25519:
if len(pubKey.Data) != sr25519.PubKeySr25519Size {
return nil, fmt.Errorf("invalid size for PubKeySr25519. Got %d, expected %d",
len(pubKey.Data), sr25519.PubKeySr25519Size)
}
var pk sr25519.PubKeySr25519
copy(pk[:], pubKey.Data)
return pk, nil
case ABCIPubKeyTypeSecp256k1:
if len(pubKey.Data) != secp256k1.PubKeySecp256k1Size {
return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d",