-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed4b390
commit de79a9a
Showing
11 changed files
with
1,107 additions
and
1 deletion.
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
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
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,21 @@ | ||
syntax = "proto3"; | ||
package neutron.crypto.v1beta1.ethsecp256k1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/neutron-org/neutron/v5/x/crypto/ethsecp256k1"; | ||
|
||
// PubKey defines a type alias for an ecdsa.PublicKey that implements | ||
// Tendermint's PubKey interface. It represents the 33-byte compressed public | ||
// key format. | ||
message PubKey { | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
bytes key = 1; | ||
} | ||
|
||
// PrivKey defines a type alias for an ecdsa.PrivateKey that implements | ||
// Tendermint's PrivateKey interface. | ||
message PrivKey { | ||
bytes key = 1; | ||
} |
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,21 @@ | ||
package codec | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/legacy" | ||
|
||
"github.com/neutron-org/neutron/v5/x/crypto/ethsecp256k1" | ||
) | ||
|
||
// RegisterLegacyAminoCodec registers all crypto dependency types with the provided Amino | ||
// codec. | ||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
cdc.RegisterConcrete(ðsecp256k1.PubKey{}, | ||
ethsecp256k1.PubKeyName, nil) | ||
cdc.RegisterConcrete(ðsecp256k1.PrivKey{}, | ||
ethsecp256k1.PrivKeyName, nil) | ||
|
||
// NOTE: update SDK's amino codec to include the ethsecp256k1 keys. | ||
// DO NOT REMOVE unless deprecated on the SDK. | ||
legacy.Cdc = cdc | ||
} |
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,14 @@ | ||
package codec | ||
|
||
import ( | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
|
||
"github.com/neutron-org/neutron/v5/x/crypto/ethsecp256k1" | ||
) | ||
|
||
// RegisterInterfaces register the Evmos key concrete types. | ||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) { | ||
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), ðsecp256k1.PubKey{}) | ||
registry.RegisterImplementations((*cryptotypes.PrivKey)(nil), ðsecp256k1.PrivKey{}) | ||
} |
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,29 @@ | ||
package ethsecp256k1 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func BenchmarkGenerateKey(b *testing.B) { | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
_ = GenerateKey() | ||
} | ||
} | ||
|
||
func BenchmarkPubKey_VerifySignature(b *testing.B) { | ||
privKey := GenerateKey() | ||
pubKey := privKey.PubKey() | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
msg := []byte(fmt.Sprintf("%10d", i)) | ||
sig, err := privKey.Sign(msg) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
pubKey.VerifySignature(msg, sig) | ||
} | ||
} |
Oops, something went wrong.