style: enable strict gofumpt (#15579)
This commit is contained in:
+4
-4
@@ -128,7 +128,7 @@ func unarmorBytes(armorStr, blockType string) (bz []byte, header map[string]stri
|
||||
// encrypt/decrypt with armor
|
||||
|
||||
// Encrypt and armor the private key.
|
||||
func EncryptArmorPrivKey(privKey cryptotypes.PrivKey, passphrase string, algo string) string {
|
||||
func EncryptArmorPrivKey(privKey cryptotypes.PrivKey, passphrase, algo string) string {
|
||||
saltBytes, encBytes := encryptPrivKey(privKey, passphrase)
|
||||
header := map[string]string{
|
||||
"kdf": "bcrypt",
|
||||
@@ -147,7 +147,7 @@ func EncryptArmorPrivKey(privKey cryptotypes.PrivKey, passphrase string, algo st
|
||||
// encrypt the given privKey with the passphrase using a randomly
|
||||
// generated salt and the xsalsa20 cipher. returns the salt and the
|
||||
// encrypted priv key.
|
||||
func encryptPrivKey(privKey cryptotypes.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
|
||||
func encryptPrivKey(privKey cryptotypes.PrivKey, passphrase string) (saltBytes, encBytes []byte) {
|
||||
saltBytes = crypto.CRandBytes(16)
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
|
||||
if err != nil {
|
||||
@@ -161,7 +161,7 @@ func encryptPrivKey(privKey cryptotypes.PrivKey, passphrase string) (saltBytes [
|
||||
}
|
||||
|
||||
// UnarmorDecryptPrivKey returns the privkey byte slice, a string of the algo type, and an error
|
||||
func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey cryptotypes.PrivKey, algo string, err error) {
|
||||
func UnarmorDecryptPrivKey(armorStr, passphrase string) (privKey cryptotypes.PrivKey, algo string, err error) {
|
||||
blockType, header, encBytes, err := DecodeArmor(armorStr)
|
||||
if err != nil {
|
||||
return privKey, "", err
|
||||
@@ -193,7 +193,7 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey cryptoty
|
||||
return privKey, header[headerType], err
|
||||
}
|
||||
|
||||
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey cryptotypes.PrivKey, err error) {
|
||||
func decryptPrivKey(saltBytes, encBytes []byte, passphrase string) (privKey cryptotypes.PrivKey, err error) {
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
|
||||
if err != nil {
|
||||
return privKey, errorsmod.Wrap(err, "error generating bcrypt key from passphrase")
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestArmorUnarmorPrivKey(t *testing.T) {
|
||||
require.Contains(t, err.Error(), "unrecognized armor type")
|
||||
|
||||
// armor key manually
|
||||
encryptPrivKeyFn := func(privKey cryptotypes.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
|
||||
encryptPrivKeyFn := func(privKey cryptotypes.PrivKey, passphrase string) (saltBytes, encBytes []byte) {
|
||||
saltBytes = cmtcrypto.CRandBytes(16)
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), crypto.BcryptSecurityParameter)
|
||||
require.NoError(t, err)
|
||||
|
||||
+3
-3
@@ -26,12 +26,12 @@ const (
|
||||
var Secp256k1 = secp256k1Algo{}
|
||||
|
||||
type (
|
||||
DeriveFn func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
|
||||
DeriveFn func(mnemonic, bip39Passphrase, hdPath string) ([]byte, error)
|
||||
GenerateFn func(bz []byte) types.PrivKey
|
||||
)
|
||||
|
||||
type WalletGenerator interface {
|
||||
Derive(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
|
||||
Derive(mnemonic, bip39Passphrase, hdPath string) ([]byte, error)
|
||||
Generate(bz []byte) types.PrivKey
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (s secp256k1Algo) Name() PubKeyType {
|
||||
|
||||
// Derive derives and returns the secp256k1 private key for the given seed and HD path.
|
||||
func (s secp256k1Algo) Derive() DeriveFn {
|
||||
return func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error) {
|
||||
return func(mnemonic, bip39Passphrase, hdPath string) ([]byte, error) {
|
||||
seed, err := bip39.NewSeedWithErrorChecking(mnemonic, bip39Passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+4
-4
@@ -156,7 +156,7 @@ func (p BIP44Params) String() string {
|
||||
}
|
||||
|
||||
// ComputeMastersFromSeed returns the master secret key's, and chain code.
|
||||
func ComputeMastersFromSeed(seed []byte) (secret [32]byte, chainCode [32]byte) {
|
||||
func ComputeMastersFromSeed(seed []byte) (secret, chainCode [32]byte) {
|
||||
curveIdentifier := []byte("Bitcoin seed")
|
||||
secret, chainCode = i64(curveIdentifier, seed)
|
||||
|
||||
@@ -216,7 +216,7 @@ func DerivePrivateKeyForPath(privKeyBytes, chainCode [32]byte, path string) ([]b
|
||||
// It returns the new private key and new chain code.
|
||||
// For more information on hardened keys see:
|
||||
// - https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
||||
func derivePrivateKey(privKeyBytes [32]byte, chainCode [32]byte, index uint32, harden bool) ([32]byte, [32]byte) {
|
||||
func derivePrivateKey(privKeyBytes, chainCode [32]byte, index uint32, harden bool) ([32]byte, [32]byte) {
|
||||
var data []byte
|
||||
|
||||
if harden {
|
||||
@@ -244,7 +244,7 @@ func derivePrivateKey(privKeyBytes [32]byte, chainCode [32]byte, index uint32, h
|
||||
}
|
||||
|
||||
// modular big endian addition
|
||||
func addScalars(a []byte, b []byte) [32]byte {
|
||||
func addScalars(a, b []byte) [32]byte {
|
||||
aInt := new(big.Int).SetBytes(a)
|
||||
bInt := new(big.Int).SetBytes(b)
|
||||
sInt := new(big.Int).Add(aInt, bInt)
|
||||
@@ -263,7 +263,7 @@ func uint32ToBytes(i uint32) []byte {
|
||||
}
|
||||
|
||||
// i64 returns the two halfs of the SHA512 HMAC of key and data.
|
||||
func i64(key []byte, data []byte) (il [32]byte, ir [32]byte) {
|
||||
func i64(key, data []byte) (il, ir [32]byte) {
|
||||
mac := hmac.New(sha512.New, key)
|
||||
// sha512 does not err
|
||||
_, _ = mac.Write(data)
|
||||
|
||||
@@ -1978,7 +1978,7 @@ func TestChangeBcrypt(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func requireEqualRenamedKey(t *testing.T, key *Record, mnemonic *Record, nameMatch bool) {
|
||||
func requireEqualRenamedKey(t *testing.T, key, mnemonic *Record, nameMatch bool) {
|
||||
if nameMatch {
|
||||
require.Equal(t, key.Name, mnemonic.Name)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ type hashed struct {
|
||||
// cost. If the cost given is less than MinCost, the cost will be set to
|
||||
// DefaultCost, instead. Use CompareHashAndPassword, as defined in this package,
|
||||
// to compare the returned hashed password with its cleartext version.
|
||||
func GenerateFromPassword(salt []byte, password []byte, cost uint32) ([]byte, error) {
|
||||
func GenerateFromPassword(salt, password []byte, cost uint32) ([]byte, error) {
|
||||
if len(salt) != maxSaltSize {
|
||||
return nil, fmt.Errorf("salt len must be %v", maxSaltSize)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func Cost(hashedPassword []byte) (uint32, error) {
|
||||
return p.cost, nil
|
||||
}
|
||||
|
||||
func newFromPassword(salt []byte, password []byte, cost uint32) (*hashed, error) {
|
||||
func newFromPassword(salt, password []byte, cost uint32) (*hashed, error) {
|
||||
if cost < MinCost {
|
||||
cost = DefaultCost
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func (pubKey *PubKey) Bytes() []byte {
|
||||
return pubKey.Key
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
func (pubKey *PubKey) VerifySignature(msg, sig []byte) bool {
|
||||
// make sure we use the same algorithm to sign
|
||||
if len(sig) != SignatureSize {
|
||||
return false
|
||||
|
||||
@@ -39,7 +39,7 @@ func NormalizeS(sigS *big.Int) *big.Int {
|
||||
// signatureRaw will serialize signature to R || S.
|
||||
// R, S are padded to 32 bytes respectively.
|
||||
// code roughly copied from secp256k1_nocgo.go
|
||||
func signatureRaw(r *big.Int, s *big.Int) []byte {
|
||||
func signatureRaw(r, s *big.Int) []byte {
|
||||
rBytes := r.Bytes()
|
||||
sBytes := s.Bytes()
|
||||
sigBytes := make([]byte, 64)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (pk *PubKey) Bytes() []byte {
|
||||
// where the s integer component of the signature is in the
|
||||
// lower half of the curve order
|
||||
// 7/21/21 - expects raw encoded signature (fixed-width 64-bytes, R || S)
|
||||
func (pk *PubKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
func (pk *PubKey) VerifySignature(msg, sig []byte) bool {
|
||||
// check length for raw signature
|
||||
// which is two 32-byte padded big.Ints
|
||||
// concatenated
|
||||
|
||||
@@ -100,7 +100,7 @@ func (m *LegacyAminoPubKey) VerifyMultisignature(getSignBytes multisigtypes.GetS
|
||||
// VerifySignature implements cryptotypes.PubKey VerifySignature method,
|
||||
// it panics because it can't handle MultiSignatureData
|
||||
// cf. https://github.com/cosmos/cosmos-sdk/issues/7109#issuecomment-686329936
|
||||
func (m *LegacyAminoPubKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
func (m *LegacyAminoPubKey) VerifySignature(msg, sig []byte) bool {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ var (
|
||||
// The caller is responsible for ensuring that msg cannot be chosen
|
||||
// directly by an attacker. It is usually preferable to use a cryptographic
|
||||
// hash function on any input before handing it to this function.
|
||||
func Sign(msg []byte, seckey []byte) ([]byte, error) {
|
||||
func Sign(msg, seckey []byte) ([]byte, error) {
|
||||
if len(msg) != 32 {
|
||||
return nil, ErrInvalidMsgLen
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) {
|
||||
// msg must be the 32-byte hash of the message to be signed.
|
||||
// sig must be a 65-byte compact ECDSA signature containing the
|
||||
// recovery id as the last element.
|
||||
func RecoverPubkey(msg []byte, sig []byte) ([]byte, error) {
|
||||
func RecoverPubkey(msg, sig []byte) ([]byte, error) {
|
||||
if len(msg) != 32 {
|
||||
return nil, ErrInvalidMsgLen
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
|
||||
|
||||
// VerifyBytes verifies a signature of the form R || S.
|
||||
// It rejects signatures which are not in lower-S form.
|
||||
func (pubKey *PubKey) VerifySignature(msg []byte, sigStr []byte) bool {
|
||||
func (pubKey *PubKey) VerifySignature(msg, sigStr []byte) bool {
|
||||
if len(sigStr) != 64 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (m *PubKey) Type() string {
|
||||
}
|
||||
|
||||
// VerifySignature implements SDK PubKey interface.
|
||||
func (m *PubKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
func (m *PubKey) VerifySignature(msg, sig []byte) bool {
|
||||
return m.Key.VerifySignature(msg, sig)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
)
|
||||
|
||||
func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) {
|
||||
func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) {
|
||||
// Marshal to JSON bytes.
|
||||
js, err := cdc.MarshalJSON(src)
|
||||
require.Nil(t, err, "%+v", err)
|
||||
|
||||
@@ -11,7 +11,7 @@ type PubKey interface {
|
||||
|
||||
Address() Address
|
||||
Bytes() []byte
|
||||
VerifySignature(msg []byte, sig []byte) bool
|
||||
VerifySignature(msg, sig []byte) bool
|
||||
Equals(PubKey) bool
|
||||
Type() string
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ var ErrCiphertextDecrypt = errors.New("ciphertext decryption failed")
|
||||
|
||||
// secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase))
|
||||
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
|
||||
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
|
||||
func EncryptSymmetric(plaintext, secret []byte) (ciphertext []byte) {
|
||||
if len(secret) != secretLen {
|
||||
panic(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
|
||||
|
||||
// secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase))
|
||||
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
|
||||
func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err error) {
|
||||
func DecryptSymmetric(ciphertext, secret []byte) (plaintext []byte, err error) {
|
||||
if len(secret) != secretLen {
|
||||
panic(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user