Class: Universa::PrivateKey

Inherits:
RemoteAdapter show all
Defined in:
lib/universa/keys.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteAdapter

#__getobj__, #__setobj__, #initialize, #inspect, invoke_static, remote_class, remote_class_name, remote_field, static_method, #to_s

Constructor Details

This class inherits a constructor from Universa::RemoteAdapter

Class Method Details

.from_packed(packed, password: nil) ⇒ Object

Load key from packed, optinally, using the password

Parameters:

  • packed (String)

    binary string with packed key

  • password (String) (defaults to: nil)

    optional password



12
13
14
15
16
17
18
19
# 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

Instance Method Details

#bit_strengthObject

Returns key strength in bits, e.g. 2048, 4096…

Returns:

  • key strength in bits, e.g. 2048, 4096…



37
38
39
# File 'lib/universa/keys.rb', line 37

def bit_strength
  @public_key.bit_strength
end

#long_addressKeyAddress

Returns long address of the corresponding public key.

Returns:

  • (KeyAddress)

    long address of the corresponding public key



27
28
29
# File 'lib/universa/keys.rb', line 27

def long_address
  @long_address ||= public_key.long_address
end

#public_keyPublicKey

Returns public key that matches this.

Returns:

  • (PublicKey)

    public key that matches this



32
33
34
# File 'lib/universa/keys.rb', line 32

def public_key
  @public_key ||= get_public_key
end

#short_addressKeyAddress

Returns short address of the corresponding public key.

Returns:

  • (KeyAddress)

    short address of the corresponding public key



22
23
24
# File 'lib/universa/keys.rb', line 22

def short_address
  @short_address ||= public_key.short_address
end

#sign(data, hash_type = "SHA3_384") ⇒ Object

sign data or string with a specified hash type

Returns:

  • binary signature



43
44
45
# File 'lib/universa/keys.rb', line 43

def sign(data, hash_type = "SHA3_384")
  __getobj__.sign(data.force_encoding('binary'), hash_type)
end