nimbus-eth1/nimbus/random_keys.nim

18 lines
445 B
Nim
Raw Normal View History

import eth/keys as ethkeys
# You should only create one instance of the RNG per application / library
# Ref is used so that it can be shared between components
var theRNG {.threadvar.}: ref BrHmacDrbgContext
proc getRng*(): ref BrHmacDrbgContext {.gcsafe.} =
if theRNG.isNil:
theRNG = newRng()
theRNG
proc randomPrivateKey*(): PrivateKey =
random(PrivateKey, theRNG[])
proc randomKeyPair*(): KeyPair =
random(KeyPair, theRNG[])