Browse Source

Cleanup up Multisig naming (#2255)

* crypto/multisig: Pubkey -> PubKey

* crypto/encoding/amino: use pkg vars for routes

* crypto/multisig/bitarray

* crypto/multisig: ThresholdMultiSignaturePubKey -> PubKeyMultisigThreshold

* crypto/encoding/amino: add PubKeyMultisig to table

* remove bA import alias

https://github.com/tendermint/tendermint/pull/2255#discussion_r211900709
pull/2291/head
Ethan Buchman 6 years ago
committed by Anton Kaliaev
parent
commit
38b401657e
8 changed files with 50 additions and 44 deletions
  1. +8
    -4
      crypto/encoding/amino/amino.go
  2. +1
    -0
      crypto/encoding/amino/encode_test.go
  3. +1
    -1
      crypto/multisig/bitarray/compact_bit_array.go
  4. +1
    -1
      crypto/multisig/bitarray/compact_bit_array_test.go
  5. +5
    -4
      crypto/multisig/multisignature.go
  6. +19
    -19
      crypto/multisig/threshold_pubkey.go
  7. +12
    -12
      crypto/multisig/threshold_pubkey_test.go
  8. +3
    -3
      crypto/multisig/wire.go

+ 8
- 4
crypto/encoding/amino/amino.go View File

@ -2,8 +2,10 @@ package cryptoAmino
import (
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
)
@ -24,15 +26,17 @@ func RegisterAmino(cdc *amino.Codec) {
// These are all written here instead of
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
"tendermint/PubKeyEd25519", nil)
ed25519.PubKeyAminoRoute, nil)
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
"tendermint/PubKeySecp256k1", nil)
secp256k1.PubKeyAminoRoute, nil)
cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{},
multisig.PubKeyMultisigThresholdAminoRoute, nil)
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
"tendermint/PrivKeyEd25519", nil)
ed25519.PrivKeyAminoRoute, nil)
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
"tendermint/PrivKeySecp256k1", nil)
secp256k1.PrivKeyAminoRoute, nil)
}
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {


+ 1
- 0
crypto/encoding/amino/encode_test.go View File

@ -53,6 +53,7 @@ func ExamplePrintRegisteredTypes() {
//| ---- | ---- | ------ | ----- | ------ |
//| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE64 | 0x20 | |
//| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | |
//| PubKeyMultisigThreshold | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | |
//| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | |
//| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | |
}


crypto/multisig/compact_bit_array.go → crypto/multisig/bitarray/compact_bit_array.go View File


crypto/multisig/compact_bit_array_test.go → crypto/multisig/bitarray/compact_bit_array_test.go View File


+ 5
- 4
crypto/multisig/multisignature.go View File

@ -4,12 +4,13 @@ import (
"errors"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig/bitarray"
)
// Multisignature is used to represent the signature object used in the multisigs.
// Sigs is a list of signatures, sorted by corresponding index.
type Multisignature struct {
BitArray *CompactBitArray
BitArray *bitarray.CompactBitArray
Sigs [][]byte
}
@ -17,7 +18,7 @@ type Multisignature struct {
func NewMultisig(n int) *Multisignature {
// Default the signature list to have a capacity of two, since we can
// expect that most multisigs will require multiple signers.
return &Multisignature{NewCompactBitArray(n), make([][]byte, 0, 2)}
return &Multisignature{bitarray.NewCompactBitArray(n), make([][]byte, 0, 2)}
}
// GetIndex returns the index of pk in keys. Returns -1 if not found
@ -52,9 +53,9 @@ func (mSig *Multisignature) AddSignature(sig []byte, index int) {
mSig.Sigs[newSigIndex] = sig
}
// AddSignatureFromPubkey adds a signature to the multisig,
// AddSignatureFromPubKey adds a signature to the multisig,
// at the index in keys corresponding to the provided pubkey.
func (mSig *Multisignature) AddSignatureFromPubkey(sig []byte, pubkey crypto.PubKey, keys []crypto.PubKey) error {
func (mSig *Multisignature) AddSignatureFromPubKey(sig []byte, pubkey crypto.PubKey, keys []crypto.PubKey) error {
index := getIndex(pubkey, keys)
if index == -1 {
return errors.New("provided key didn't exist in pubkeys")


crypto/multisig/threshold_multisig.go → crypto/multisig/threshold_pubkey.go View File


crypto/multisig/threshold_multisig_test.go → crypto/multisig/threshold_pubkey_test.go View File


+ 3
- 3
crypto/multisig/wire.go View File

@ -10,15 +10,15 @@ import (
// TODO: Figure out API for others to either add their own pubkey types, or
// to make verify / marshal accept a cdc.
const (
ThresholdPubkeyAminoRoute = "tendermint/PubkeyMultisigThreshold"
PubKeyMultisigThresholdAminoRoute = "tendermint/PubKeyMultisigThreshold"
)
var cdc = amino.NewCodec()
func init() {
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(ThresholdMultiSignaturePubKey{},
ThresholdPubkeyAminoRoute, nil)
cdc.RegisterConcrete(PubKeyMultisigThreshold{},
PubKeyMultisigThresholdAminoRoute, nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
ed25519.PubKeyAminoRoute, nil)
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},


Loading…
Cancel
Save