show eth address on evm chains

This commit is contained in:
liangping 2022-05-06 15:27:33 +08:00
parent 13c8ccf40f
commit ccf519154e
2 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import {
Bech32, fromBase64, fromHex, toHex,
Bech32, fromBase64, fromBech32, fromHex, toHex,
} from '@cosmjs/encoding'
import { sha256, stringToPath } from '@cosmjs/crypto'
// ledger
@ -169,12 +169,16 @@ export function consensusPubkeyToHexAddress(consensusPubkey) {
}
raw = sha256(fromBase64(consensusPubkey.value))
} else {
raw = sha256(fromHex(toHex(Bech32.decode(consensusPubkey).data).toUpperCase().replace('1624DE6420', '')))
raw = sha256(fromHex(toHex(fromBech32(consensusPubkey).data).toUpperCase().replace('1624DE6420', '')))
}
const address = toHex(raw).slice(0, 40).toUpperCase()
return address
}
export function toETHAddress(cosmosAddress) {
return `0x${toHex(fromBech32(cosmosAddress).data)}`
}
function toSignAddress(addr) {
const { data } = addressDecode(addr)
return addressEnCode('cosmos', data)

View File

@ -30,6 +30,7 @@
/>
</h3>
{{ address }}
<span v-if="isEthAddr"> - {{ ethaddress() }}</span>
</div>
</div>
</b-card>
@ -426,7 +427,7 @@ import VueQr from 'vue-qr'
import chainAPI from '@/libs/fetch'
import {
formatToken, formatTokenAmount, formatTokenDenom, getStakingValidatorOperator, percent, tokenFormatter, toDay,
toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas,
toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas, toETHAddress,
} from '@/libs/utils'
import OperationModal from '@/views/components/OperationModal/index.vue'
import ObjectFieldComponent from './ObjectFieldComponent.vue'
@ -627,6 +628,9 @@ export default {
denoms() {
return this.$store.state.chains.denoms
},
isEthAddr() {
return JSON.stringify(this.account).indexOf('PubKeyEthSecp256k1') > 0
},
},
created() {
this.$http.getAuthAccount(this.address).then(acc => {
@ -730,6 +734,9 @@ export default {
})
})
},
ethaddress() {
return toETHAddress(this.address)
},
},
}
</script>