hex_to_eip55 returns 0x... if the paramhex is 0x...

This commit is contained in:
陆柯 2023-08-03 17:35:28 +08:00
parent 16e45503be
commit 8836721791

View File

@ -1389,9 +1389,9 @@ class TicCrypto {
*/ */
static hex_to_eip55 (hex) { static hex_to_eip55 (hex) {
if (/^(0x)?[\da-fA-F]+$/.test(hex)) { if (/^(0x)?[\da-fA-F]+$/.test(hex)) {
let result = /^0x/.test(hex) ? '0x' : ''
hex = hex.toLowerCase().replace('0x', '') hex = hex.toLowerCase().replace('0x', '')
let hash = keccak('keccak256').update(hex).digest('hex') let hash = keccak('keccak256').update(hex).digest('hex')
let result = ''
for (var i = 0; i < hex.length; i++) { for (var i = 0; i < hex.length; i++) {
if (parseInt(hash[i], 16) >= 8) { if (parseInt(hash[i], 16) >= 8) {
result += hex[i].toUpperCase() result += hex[i].toUpperCase()