Skip to content

Commit

Permalink
Fix seid keys list with evm-addr (#495)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
In
6f469f1#diff-453f834b1c4250b6c9532c7dfa5f4c11435b280993d7548bbeea92a74d4c9541R92
only secp256k1 algo is supported,
## Testing performed to validate your change
Verified that you can list keys and that evm_addr is populated for keys
with secp256k1
``` name: g_admin1
  type: local
  address: sei1657ehtfxcr60hjp2z0xvtljcj25ykw8yf2uyh5
  evm_address: 0xa026539E8Ba20B29e45c5ab5B689850CD4B7e11a
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A+iu6BIZT/4qps6MAYPwCgZsZO0ovkawFsq/RjysvOjV"}'
  mnemonic: ""
- name: g_admin2
  type: local
  address: sei12n3568vs2zpgl9uydxcczmqtgdcpyjpflwp33c
  evm_address: 0xDB4f98f00a0242C910ebC3e9482A7A333491BfB9
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A5LRw3M1+gWLtsAl1WufvqSeZ1wy8Z+Lp8JWjhyXcqrR"}'
  mnemonic: ""
- name: g_admin3
  type: local
  address: sei1snz65x86nvsd56h5uvj0gjl3g8zzr7h4fwphts
  evm_address: 0x7D26B545FBa2D3070aB7562dDd9aa5895ca35490
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/sfqbrrTy8zfXACuy5275eAnyuzVsPsZcyfu60rrUqv"}'
  mnemonic: ""
- name: g_admin4
  type: local
  address: sei16qkjxtewl78cw6d53vcfmdksgm7l0atsqfnhjp
  evm_address: 0xe81B39b6c7b8F7959Ef4420508C0C3B2db05259F
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AgdzUmYDPLVzofGzTD5QXRg62tLGEu40GsRS+fuunEER"}'
  mnemonic: ""
- name: new_admin
  type: local
  address: sei1qepx73fek53gc5e2azlr8gjz6kl69e0nmhmat7
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"jA1Qd6kxED53/2Q7fJsMLwriaV4E8/ui+jEouL+A9BU="}'
  mnemonic: ""
- name: oracle-price-feeder
  type: local
  address: sei1mz6qmg9cx3yjjetm2lyjh343ppwddljfq3kdur
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"oNvpOVZYs/CsBnSfNZpA9+synReN6/OrWzFLdBgcems="}'
  mnemonic: ""
- name: psu
  type: local
  address: sei1lj9ruvpaj5ygcte9kyfj45x0vghrzmy86tgua7
  evm_address: 0xfD5ec2Edf8E90920C4BE66Da96cC4DA9A3c4ED6C
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A3VgbsBy4PMuaHNQsjgj81mA9VnE4rcTdSneCQqf/VxY"}'
  mnemonic: ""
- name: sei-foundation
  type: local
  address: sei1jdppe6fnj2q7hjsepty5crxtrryzhuqsjrj95y
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"JAo57kGWGrxSeLs0o01MeqE+fizec5Pmdk44CRkOzjc="}'
  mnemonic: ""
- name: sei-testing
  type: local
  address: sei1fz73n2mdhsgs2xdf4as23uk2vp8yvrw64crahf
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"7OHprbp/gx2NL/GTT32de6FN1cMcAM4kYgsNgavOm1o="}'
  mnemonic: ""
- name: ta1
  type: local
  address: sei1efyt36a7y9nt4nr9xl4vh65a4nqgfztv8wtf20
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"uLbMLqjEMbv9qZknLviTo0jA1i+qTGyE9lrWjYgLmCs="}'
  mnemonic: ""
- name: ta2
  type: local
  address: sei1e3wxhsfcweh95u7psnq3a5m9elesfwa6rc4ysx
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"LnInmmNguoKKdtwz/Xd77sjrH+hi6L1F2JefwBrCpnk="}'
  mnemonic: ""
- name: test-add-key
  type: local
  address: sei1qq2g4kjghj67fp65affzgn0rewphmlqy73easx
  evm_address: 0x8fE5dc3268b50e44ce17Fb247954A6b5f2A211F2
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AshsWcC+rIPgXyNrLOz+tbjY+5oIrs4hfOUbiHiCPWgT"}'
  mnemonic: ""
- name: test-faucet-alert
  type: local
  address: sei1r9swx6499exq7h077ry02dv6amrctqnhyshdjs
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"uHNuKhUM3Qhr86GS7wMSAjKJte4i3tDYAze2bocTyCc="}'
  mnemonic: ""
- name: test-fee-grantee
  type: local
  address: sei1pfcd6mhav9fzdlddsnlpq3rq958xjj44lyymqm
  evm_address: 0x31FB1f795522098195Dc284293A5776653e9DCe7
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/SeQxNztswvMAWWJFdJ+fRq0tGNq4vEiJNDnmukhq/W"}'
  mnemonic: ""
- name: test_count
  type: local
  address: sei12k8vuwqrthpnahru6lqx6sac2yqlt8l94wccg0
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"/kmVTKDeszYkLuNmuBpDz3QjHLXKc2IgOQYb4UdrvjU="}'
  mnemonic: ""
- name: tombstoned_admin
  type: local
  address: sei1h788zafh8u6cdffj2fq0d8eq65j6gwcg4tufhw
  evm_address: ""
  pubkey: '{"@type":"/cosmos.crypto.sr25519.PubKey","key":"LB3oxQm4QmGV8PMsVoo5GIrOl9ao545E9F8m6BxOcB8="}'
  mnemonic: ""```
  • Loading branch information
philipsu522 authored Apr 29, 2024
1 parent 35f54e3 commit 9c70a66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crypto/keyring/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keyring

import (
"encoding/hex"
"github.com/cosmos/cosmos-sdk/crypto/hd"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
Expand Down Expand Up @@ -77,9 +78,13 @@ func MkAccKeysOutput(infos []Info) ([]KeyOutput, error) {
if err != nil {
return nil, err
}
kos[i], err = PopulateEvmAddrIfApplicable(info, kos[i])
if err != nil {
return nil, err
if info.GetAlgo() == hd.Secp256k1Type {
// We only support getting evm-addr if the algo type is secp256k1 (which it should be, though there
// may be some legacy keys with sr25519)
kos[i], err = PopulateEvmAddrIfApplicable(info, kos[i])
if err != nil {
return nil, err
}
}
}

Expand All @@ -89,6 +94,7 @@ func MkAccKeysOutput(infos []Info) ([]KeyOutput, error) {
func PopulateEvmAddrIfApplicable(info Info, o KeyOutput) (KeyOutput, error) {
localInfo, ok := info.(LocalInfo)
if ok {
// Only works with secp256k1 algo
priv, err := legacy.PrivKeyFromBytes([]byte(localInfo.PrivKeyArmor))
if err != nil {
return o, err
Expand All @@ -99,6 +105,7 @@ func PopulateEvmAddrIfApplicable(info Info, o KeyOutput) (KeyOutput, error) {
return o, err
}
o.EvmAddress = crypto.PubkeyToAddress(privKey.PublicKey).Hex()
} else {
}
return o, nil
}
17 changes: 17 additions & 0 deletions crypto/keyring/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keyring

import (
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keys/sr25519"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -28,3 +29,19 @@ func TestBech32KeysOutput(t *testing.T) {
require.Equal(t, expectedOutput, out)
require.Equal(t, `{Name:multisig Type:multi Address:cosmos1nf8lf6n4wa43rzmdzwe6hkrnw5guekhqt595cw EvmAddress: PubKey:{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":1,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AurroA7jvfPd1AadmmOvWM2rJSwipXfRf8yD6pLbA2DJ"}]} Mnemonic:}`, fmt.Sprintf("%+v", out))
}

func TestMkAccKeyOutputForSr25519(t *testing.T) {
sk := sr25519.GenPrivKey()
tmpKey := sk.PubKey()
multisigPk := kmultisig.NewLegacyAminoPubKey(1, []types.PubKey{tmpKey})

info, err := NewMultiInfo("multisig", multisigPk)
require.NoError(t, err)
accAddr := sdk.AccAddress(info.GetPubKey().Address())
expectedOutput, err := NewKeyOutput(info.GetName(), info.GetType(), accAddr, multisigPk)
require.NoError(t, err)

out, err := MkAccKeyOutput(info)
require.NoError(t, err)
require.Equal(t, expectedOutput, out)
}

0 comments on commit 9c70a66

Please sign in to comment.