-
Notifications
You must be signed in to change notification settings - Fork 199
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
Showing
20 changed files
with
900 additions
and
361 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
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,27 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
"github.com/initia-labs/initia/crypto/keys/eth/secp256k1" | ||
) | ||
|
||
// DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas | ||
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched | ||
// by the concrete type. | ||
func DefaultSigVerificationGasConsumer( | ||
meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params, | ||
) error { | ||
pubkey := sig.PubKey | ||
switch pubkey.(type) { | ||
case *secp256k1.PubKey: | ||
meter.ConsumeGas(params.SigVerifyCostSecp256k1, "ante verify: eth_secp256k1") | ||
return nil | ||
|
||
default: | ||
return ante.DefaultSigVerificationGasConsumer(meter, sig, params) | ||
} | ||
} |
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
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,37 @@ | ||
package hd | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/types" | ||
|
||
"github.com/initia-labs/initia/crypto/keys/eth/secp256k1" | ||
) | ||
|
||
var ( | ||
// EthSecp256k1Type uses the ethereum secp256k1 ECDSA parameters. | ||
EthSecp256k1Type = hd.PubKeyType("eth_secp256k1") | ||
) | ||
|
||
// EthSecp256k1 uses the Bitcoin secp256k1 ECDSA parameters. | ||
var EthSecp256k1 = ethSecp256k1Algo{} | ||
|
||
type ethSecp256k1Algo struct{} | ||
|
||
func (s ethSecp256k1Algo) Name() hd.PubKeyType { | ||
return EthSecp256k1Type | ||
} | ||
|
||
// Derive derives and returns the secp256k1 private key for the given seed and HD path. | ||
func (s ethSecp256k1Algo) Derive() hd.DeriveFn { | ||
return hd.Secp256k1.Derive() | ||
} | ||
|
||
// Generate generates a eth_secp256k1 private key from the given bytes. | ||
func (s ethSecp256k1Algo) Generate() hd.GenerateFn { | ||
return func(bz []byte) types.PrivKey { | ||
bzArr := make([]byte, secp256k1.PrivKeySize) | ||
copy(bzArr, bz) | ||
|
||
return &secp256k1.PrivKey{Key: bzArr} | ||
} | ||
} |
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,11 @@ | ||
package secp256k1 | ||
|
||
import "golang.org/x/crypto/sha3" | ||
|
||
func Keccak256(msg []byte) []byte { | ||
hasher := sha3.NewLegacyKeccak256() | ||
if _, err := hasher.Write(msg); err != nil { | ||
panic(err) | ||
} | ||
return hasher.Sum(nil) | ||
} |
Oops, something went wrong.