This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vechain] Increaase blockTime and add address checksum (#258)
* Add blockTime to vechain * Add address checksum * Use utilz package
- Loading branch information
Showing
5 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package util | ||
|
||
import ( | ||
"golang.org/x/crypto/sha3" | ||
"strings" | ||
) | ||
|
||
// Decode decodes a hex string with 0x prefix. | ||
func Remove0x(input string) string { | ||
if strings.HasPrefix(input, "0x") { | ||
return input[2:] | ||
} | ||
return input | ||
} | ||
|
||
// Hex returns an EIP55-compliant hex string representation of the address. | ||
func Checksum(unchecksummed string) string { | ||
v := []byte(Remove0x(strings.ToLower(unchecksummed))) | ||
sha := sha3.NewLegacyKeccak256() | ||
sha.Write(v) | ||
hash := sha.Sum(nil) | ||
|
||
result := v | ||
for i := 0; i < len(result); i++ { | ||
hashByte := hash[i/2] | ||
if i%2 == 0 { | ||
hashByte = hashByte >> 4 | ||
} else { | ||
hashByte &= 0xf | ||
} | ||
if result[i] > '9' && hashByte > 7 { | ||
result[i] -= 32 | ||
} | ||
} | ||
val := string(result) | ||
return "0x" + val | ||
} |