class Convex::KeyPair

Constants

VERSION

Public Class Methods

new(import_text=nil, password=nil) click to toggle source

Create a new Convex::KeyPair object

import_text

If set with a encrypted PEM text of the key.

password

If import_text is used, then you need to provide the password that was used when using export_to_text

Example ↑

# Create a random key
key = Convex::KeyPair.new

# export the key to a encrypted PEM text
pem_text = key.export_to_text('secret')

# re-import the same key
saved_key = Convex::KeyPair.new(pem_text, 'secret')

"keys are equal" if saved_key.eql?(key)
# File lib/convex/key_pair.rb, line 36
def initialize(import_text=nil, password=nil)
  if import_text and password then
    @key = AccountKey::create_from_text(import_text, password)
  else
    @key = AccountKey::create
  end
end

Public Instance Methods

eql?(other) click to toggle source
# File lib/convex/key_pair.rb, line 60
def eql?(other)
  public_key == other.public_key
end
export_to_text(password) click to toggle source
# File lib/convex/key_pair.rb, line 48
def export_to_text(password)
  @key.export_to_text(password) if @key
end
public_key() click to toggle source
# File lib/convex/key_pair.rb, line 44
def public_key
  @key.public_key if @key
end
sign(hash_data) click to toggle source
# File lib/convex/key_pair.rb, line 52
def sign(hash_data)
  @key.sign(hash_data) if @key
end
to_s() click to toggle source
# File lib/convex/key_pair.rb, line 64
def to_s
  public_key if valid?
  "<empty>"
end
valid?() click to toggle source
# File lib/convex/key_pair.rb, line 56
def valid?
  @key != false
end