hex_to_eip55
returns 0x...
if the paramhex
is 0x...
This commit is contained in:
parent
16e45503be
commit
8836721791
2
ticc.js
2
ticc.js
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user