-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start factoring out duplicate test keys
- Loading branch information
Daniel
committed
Nov 2, 2022
1 parent
97abb29
commit 983c87c
Showing
2 changed files
with
59 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package crypto | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
"github.com/cosmos/ibc-go/v3/testing/mock" | ||
|
||
cryptoEd25519 "crypto/ed25519" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
|
||
sdkcryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
sdkcryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
|
||
tmcrypto "github.com/tendermint/tendermint/crypto" | ||
tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" | ||
) | ||
|
||
type Validator struct { | ||
mock.PV | ||
} | ||
|
||
func NewValidatorFromBytesSeed(seed []byte) Validator { | ||
//lint:ignore SA1019 We don't care because this is only a test. | ||
privKey := mock.PV{PrivKey: &ed25519.PrivKey{Key: cryptoEd25519.NewKeyFromSeed(seed)}} | ||
return Validator{PV: privKey} | ||
} | ||
|
||
func NewValidatorFromIntSeed(i int) Validator { | ||
iUint64 := uint64(i) | ||
seed := []byte("AAAAAAAAabcdefghijklmnopqrstuvwx") // 8+24 bytes | ||
binary.LittleEndian.PutUint64(seed[:8], iUint64) | ||
return NewValidatorFromBytesSeed(seed) | ||
} | ||
|
||
func (v *Validator) TMProtoCryptoPublicKey() tmprotocrypto.PublicKey { | ||
ret, err := sdkcryptocodec.ToTmProtoPublicKey(v.SDKPubKey()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ret | ||
} | ||
|
||
func (v *Validator) TMCryptoPubKey() tmcrypto.PubKey { | ||
ret, err := v.GetPubKey() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ret | ||
} | ||
|
||
func (v *Validator) SDKPubKey() sdkcryptotypes.PubKey { | ||
tmcryptoPubKey := v.TMCryptoPubKey() | ||
ret, err := sdkcryptocodec.FromTmPubKeyInterface(tmcryptoPubKey) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ret | ||
} |
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