class Eth::Key
def initialize(priv: nil)
-
priv
(String
) -- binary string of private key data.
def initialize(priv: nil) # Creates a new, randomized libsecp256k1 context. ctx = Secp256k1::Context.new context_randomization_bytes: SecureRandom.random_bytes(32) # Creates a new random key pair (public, private). key = ctx.generate_key_pair unless priv.nil? # Converts hex private keys to binary strings. priv = Util.hex_to_bin priv if Util.is_hex? priv # Creates a keypair from existing private key data. key = ctx.key_pair_from_private_key priv end # Sets the attributes. @private_key = key.private_key @public_key = key.public_key end