lib/universa/keys.rb in universa-0.1.6 vs lib/universa/keys.rb in universa-0.1.7

- old
+ new

@@ -3,9 +3,22 @@ # A +com.icodici.crypto.PrivateKey+ extension. As the key is immutable, # caching is used to avoid innecessary UMI calls. class PrivateKey < RemoteAdapter remote_class 'com.icodici.crypto.PrivateKey' + # Load key from packed, optinally, using the password + # + # @param [String] packed binary string with packed key + # @param [String] password optional password + def self.from_packed(packed, password: nil) + packed.force_encoding 'binary' + if password + invoke_static "unpackWithPassword", packed, password + else + PrivateKey.new packed + end + end + # @return [KeyAddress] short address of the corresponding public key def short_address @short_address ||= public_key.short_address end