Created
June 30, 2018 06:23
-
-
Save Varriount/b7d3b21788335fb082d545328ddf72f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
proc newAddress*(key: string): string = | |
#ase58 encoded version of the first 80 characters, and append the checksum of the key. | |
var keyHash = $digest(sha512, key) | |
keyhash.setLen(80) | |
result = Base58.convert(Hex.revert(keyhash)) | |
result.add(generateChecksum(key)) | |
while result.len < 57: | |
result.insert("0", 0) | |
while result.len > 61: | |
result = result.substr(1, result.len) | |
result = "Emb" & result |
This file contains hidden or 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
import sequtils | |
proc verify*(value: openarray[char]) = | |
# NOTE: This might be better returning a bool. Exceptions are expensive. | |
const validRanges = mapLiterals([ | |
48 .. 58, | |
64 .. 73, | |
73 .. 79, | |
79 .. 91, | |
96 .. 108, | |
108 .. 123, | |
], char) | |
for character in value: | |
var isBase58 = true | |
for charRange in validRanges: | |
isBase58 = character in charRange | |
if isBase58: | |
break | |
if not isBase58: | |
raise newException(Exception, "Invalid Base58 Number") |
This file contains hidden or 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
proc randbytes(quantity: int): seq[char] = | |
result = newSeq[char](quantity) | |
# Open the file, closing it at the end of the procedure | |
let urandom = open("/dev/urandom") | |
defer: close(urandom) | |
discard urandom.readChars(result, 0, quantity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment