Class: Universa::PrivateKey
- Inherits:
-
RemoteAdapter
- Object
- Delegator
- RemoteAdapter
- Universa::PrivateKey
- 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
-
.from_packed(packed, password: nil) ⇒ Object
Load key from packed, optinally, using the password.
Instance Method Summary collapse
-
#bit_strength ⇒ Object
Key strength in bits, e.g.
-
#long_address ⇒ KeyAddress
Long address of the corresponding public key.
-
#public_key ⇒ PublicKey
Public key that matches this.
-
#short_address ⇒ KeyAddress
Short address of the corresponding public key.
-
#sign(data, hash_type = "SHA3_384") ⇒ Object
sign data or string with a specified hash type.
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
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_strength ⇒ Object
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_address ⇒ KeyAddress
Returns 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_key ⇒ PublicKey
Returns 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_address ⇒ KeyAddress
Returns 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
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 |