class Universa::PrivateKey

A com.icodici.crypto.PrivateKey extension. As the key is immutable, caching is used to avoid innecessary UMI calls.

Public Class Methods

from_packed(packed, password: nil) click to toggle source

Load key from packed, optinally, using the password

@param [String] packed binary string with packed key @param [String] password optional password

# File lib/universa/keys.rb, line 12
def self.from_packed(packed, password: nil)
  packed.force_encoding 'binary'
  if password
    invoke_static "unpackWithPassword", packed, password
  else
    PrivateKey.new packed
  end
end

Public Instance Methods

bit_strength() click to toggle source

@return key strength in bits, e.g. 2048, 4096…

# File lib/universa/keys.rb, line 37
def bit_strength
  @public_key.bit_strength
end
long_address() click to toggle source

@return [KeyAddress] long address of the corresponding public key

# File lib/universa/keys.rb, line 27
def long_address
  @long_address ||= public_key.long_address
end
public_key() click to toggle source

@return [PublicKey] public key that matches this

# File lib/universa/keys.rb, line 32
def public_key
  @public_key ||= get_public_key
end
short_address() click to toggle source

@return [KeyAddress] short address of the corresponding public key

# File lib/universa/keys.rb, line 22
def short_address
  @short_address ||= public_key.short_address
end
sign(data, hash_type = "SHA3_384") click to toggle source

sign data or string with a specified hash type @return binary signature

# File lib/universa/keys.rb, line 43
def sign(data, hash_type = "SHA3_384")
  __getobj__.sign(data.force_encoding('binary'), hash_type)
end