Merge PR #4881: Linting Galore
This commit is contained in:
committed by
Alexander Bezobchuk
parent
89b1220398
commit
3a4f1fc4d4
@@ -207,7 +207,7 @@ func DerivePrivateKeyForPath(privKeyBytes [32]byte, chainCode [32]byte, path str
|
||||
func derivePrivateKey(privKeyBytes [32]byte, chainCode [32]byte, index uint32, harden bool) ([32]byte, [32]byte) {
|
||||
var data []byte
|
||||
if harden {
|
||||
index = index | 0x80000000
|
||||
index |= 0x80000000
|
||||
data = append([]byte{byte(0)}, privKeyBytes[:]...)
|
||||
} else {
|
||||
// this can't return an error:
|
||||
@@ -245,14 +245,14 @@ 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 []byte, data []byte) (il [32]byte, ir [32]byte) {
|
||||
mac := hmac.New(sha512.New, key)
|
||||
// sha512 does not err
|
||||
_, _ = mac.Write(data)
|
||||
|
||||
I := mac.Sum(nil)
|
||||
copy(IL[:], I[:32])
|
||||
copy(IR[:], I[32:])
|
||||
copy(il[:], I[:32])
|
||||
copy(ir[:], I[32:])
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
+8
-10
@@ -235,22 +235,20 @@ func (kb dbKeybase) Sign(name, passphrase string, msg []byte) (sig []byte, pub t
|
||||
|
||||
var priv tmcrypto.PrivKey
|
||||
|
||||
switch info.(type) {
|
||||
switch i := info.(type) {
|
||||
case localInfo:
|
||||
linfo := info.(localInfo)
|
||||
if linfo.PrivKeyArmor == "" {
|
||||
if i.PrivKeyArmor == "" {
|
||||
err = fmt.Errorf("private key not available")
|
||||
return
|
||||
}
|
||||
|
||||
priv, err = mintkey.UnarmorDecryptPrivKey(linfo.PrivKeyArmor, passphrase)
|
||||
priv, err = mintkey.UnarmorDecryptPrivKey(i.PrivKeyArmor, passphrase)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
case ledgerInfo:
|
||||
linfo := info.(ledgerInfo)
|
||||
priv, err = crypto.NewPrivKeyLedgerSecp256k1Unsafe(linfo.Path)
|
||||
priv, err = crypto.NewPrivKeyLedgerSecp256k1Unsafe(i.Path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -297,9 +295,9 @@ func (kb dbKeybase) ExportPrivateKeyObject(name string, passphrase string) (tmcr
|
||||
|
||||
var priv tmcrypto.PrivKey
|
||||
|
||||
switch info.(type) {
|
||||
switch i := info.(type) {
|
||||
case localInfo:
|
||||
linfo := info.(localInfo)
|
||||
linfo := i
|
||||
if linfo.PrivKeyArmor == "" {
|
||||
err = fmt.Errorf("private key not available")
|
||||
return nil, err
|
||||
@@ -434,9 +432,9 @@ func (kb dbKeybase) Update(name, oldpass string, getNewpass func() (string, erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch info.(type) {
|
||||
switch i := info.(type) {
|
||||
case localInfo:
|
||||
linfo := info.(localInfo)
|
||||
linfo := i
|
||||
key, err := mintkey.UnarmorDecryptPrivKey(linfo.PrivKeyArmor, oldpass)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -19,6 +19,11 @@ func init() {
|
||||
mintkey.BcryptSecurityParameter = 1
|
||||
}
|
||||
|
||||
const (
|
||||
nums = "1234"
|
||||
foobar = "foobar"
|
||||
)
|
||||
|
||||
func TestLanguage(t *testing.T) {
|
||||
kb := NewInMemory()
|
||||
_, _, err := kb.CreateMnemonic("something", Japanese, "no_pass", Secp256k1)
|
||||
@@ -68,11 +73,13 @@ func TestCreateLedger(t *testing.T) {
|
||||
|
||||
// Check that restoring the key gets the same results
|
||||
restoredKey, err := kb.Get("some_account")
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, restoredKey)
|
||||
assert.Equal(t, "some_account", restoredKey.GetName())
|
||||
assert.Equal(t, TypeLedger, restoredKey.GetType())
|
||||
pubKey = restoredKey.GetPubKey()
|
||||
pk, err = sdk.Bech32ifyAccPub(pubKey)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "cosmospub1addwnpepqdszcr95mrqqs8lw099aa9h8h906zmet22pmwe9vquzcgvnm93eqygufdlv", pk)
|
||||
|
||||
path, err := restoredKey.GetPath()
|
||||
@@ -87,7 +94,7 @@ func TestKeyManagement(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2, n3 := "personal", "business", "other"
|
||||
p1, p2 := "1234", "really-secure!@#$"
|
||||
p1, p2 := nums, "really-secure!@#$"
|
||||
|
||||
// Check empty state
|
||||
l, err := cstore.List()
|
||||
@@ -170,7 +177,7 @@ func TestSignVerify(t *testing.T) {
|
||||
algo := Secp256k1
|
||||
|
||||
n1, n2, n3 := "some dude", "a dudette", "dude-ish"
|
||||
p1, p2, p3 := "1234", "foobar", "foobar"
|
||||
p1, p2, p3 := nums, foobar, foobar
|
||||
|
||||
// create two users and get their info
|
||||
i1, _, err := cstore.CreateMnemonic(n1, English, p1, algo)
|
||||
@@ -320,7 +327,7 @@ func TestAdvancedKeyManagement(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2 := "old-name", "new name"
|
||||
p1, p2 := "1234", "foobar"
|
||||
p1, p2 := nums, foobar
|
||||
|
||||
// make sure key works with initial password
|
||||
_, _, err := cstore.CreateMnemonic(n1, English, p1, algo)
|
||||
@@ -368,7 +375,7 @@ func TestSeedPhrase(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2 := "lost-key", "found-again"
|
||||
p1, p2 := "1234", "foobar"
|
||||
p1, p2 := nums, foobar
|
||||
|
||||
// make sure key works with initial password
|
||||
info, mnemonic, err := cstore.CreateMnemonic(n1, English, p1, algo)
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestLazyKeyManagement(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2, n3 := "personal", "business", "other"
|
||||
p1, p2 := "1234", "really-secure!@#$"
|
||||
p1, p2 := nums, "really-secure!@#$"
|
||||
|
||||
// Check empty state
|
||||
l, err := kb.List()
|
||||
@@ -113,7 +113,7 @@ func TestLazySignVerify(t *testing.T) {
|
||||
algo := Secp256k1
|
||||
|
||||
n1, n2, n3 := "some dude", "a dudette", "dude-ish"
|
||||
p1, p2, p3 := "1234", "foobar", "foobar"
|
||||
p1, p2, p3 := nums, foobar, foobar
|
||||
|
||||
// create two users and get their info
|
||||
i1, _, err := kb.CreateMnemonic(n1, English, p1, algo)
|
||||
@@ -301,7 +301,7 @@ func TestLazyAdvancedKeyManagement(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2 := "old-name", "new name"
|
||||
p1, p2 := "1234", "foobar"
|
||||
p1, p2 := nums, foobar
|
||||
|
||||
// make sure key works with initial password
|
||||
_, _, err := kb.CreateMnemonic(n1, English, p1, algo)
|
||||
@@ -349,7 +349,7 @@ func TestLazySeedPhrase(t *testing.T) {
|
||||
|
||||
algo := Secp256k1
|
||||
n1, n2 := "lost-key", "found-again"
|
||||
p1, p2 := "1234", "foobar"
|
||||
p1, p2 := nums, foobar
|
||||
|
||||
// make sure key works with initial password
|
||||
info, mnemonic, err := kb.CreateMnemonic(n1, English, p1, algo)
|
||||
|
||||
@@ -77,11 +77,11 @@ func unarmorBytes(armorStr, blockType string) (bz []byte, err error) {
|
||||
return
|
||||
}
|
||||
if bType != blockType {
|
||||
err = fmt.Errorf("Unrecognized armor type %q, expected: %q", bType, blockType)
|
||||
err = fmt.Errorf("unrecognized armor type %q, expected: %q", bType, blockType)
|
||||
return
|
||||
}
|
||||
if header["version"] != "0.0.0" {
|
||||
err = fmt.Errorf("Unrecognized version: %v", header["version"])
|
||||
err = fmt.Errorf("unrecognized version: %v", header["version"])
|
||||
return
|
||||
}
|
||||
return
|
||||
@@ -123,17 +123,17 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (crypto.PrivKey,
|
||||
return privKey, err
|
||||
}
|
||||
if blockType != blockTypePrivKey {
|
||||
return privKey, fmt.Errorf("Unrecognized armor type: %v", blockType)
|
||||
return privKey, fmt.Errorf("unrecognized armor type: %v", blockType)
|
||||
}
|
||||
if header["kdf"] != "bcrypt" {
|
||||
return privKey, fmt.Errorf("Unrecognized KDF type: %v", header["KDF"])
|
||||
return privKey, fmt.Errorf("unrecognized KDF type: %v", header["KDF"])
|
||||
}
|
||||
if header["salt"] == "" {
|
||||
return privKey, fmt.Errorf("Missing salt bytes")
|
||||
return privKey, fmt.Errorf("missing salt bytes")
|
||||
}
|
||||
saltBytes, err := hex.DecodeString(header["salt"])
|
||||
if err != nil {
|
||||
return privKey, fmt.Errorf("Error decoding salt: %v", err.Error())
|
||||
return privKey, fmt.Errorf("error decoding salt: %v", err.Error())
|
||||
}
|
||||
privKey, err = decryptPrivKey(saltBytes, encBytes, passphrase)
|
||||
return privKey, err
|
||||
@@ -142,7 +142,7 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (crypto.PrivKey,
|
||||
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey crypto.PrivKey, err error) {
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
|
||||
if err != nil {
|
||||
cmn.Exit("Error generating bcrypt key from passphrase: " + err.Error())
|
||||
cmn.Exit("error generating bcrypt key from passphrase: " + err.Error())
|
||||
}
|
||||
key = crypto.Sha256(key) // Get 32 bytes
|
||||
privKeyBytes, err := xsalsa20symmetric.DecryptSymmetric(encBytes, key)
|
||||
|
||||
@@ -171,7 +171,7 @@ func warnIfErrors(f func() error) {
|
||||
}
|
||||
|
||||
func convertDERtoBER(signatureDER []byte) ([]byte, error) {
|
||||
sigDER, err := btcec.ParseDERSignature(signatureDER[:], btcec.S256())
|
||||
sigDER, err := btcec.ParseDERSignature(signatureDER, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func getPubKeyUnsafe(device LedgerSECP256K1, path hd.BIP44Params) (tmcrypto.PubK
|
||||
}
|
||||
|
||||
// re-serialize in the 33-byte compressed format
|
||||
cmp, err := btcec.ParsePubKey(publicKey[:], btcec.S256())
|
||||
cmp, err := btcec.ParsePubKey(publicKey, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing public key: %v", err)
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func getPubKeyAddrSafe(device LedgerSECP256K1, path hd.BIP44Params, hrp string)
|
||||
}
|
||||
|
||||
// re-serialize in the 33-byte compressed format
|
||||
cmp, err := btcec.ParsePubKey(publicKey[:], btcec.S256())
|
||||
cmp, err := btcec.ParsePubKey(publicKey, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("error parsing public key: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user