Class: Nano::Account
- Inherits:
-
Object
- Object
- Nano::Account
- Defined in:
- lib/nano/account.rb
Overview
The Account class is used to simplify conversion from account to public key
Instance Attribute Summary collapse
-
#address ⇒ String
readonly
The base32 encoded account address.
-
#public_key ⇒ String
readonly
The public key for the account encoded in hexadecimal.
Class Method Summary collapse
-
.from_address(input) ⇒ Account
A class initializer to create an Account object from the account base32 address.
Instance Method Summary collapse
-
#initialize(val) ⇒ Account
constructor
The Account intiailizer.
Constructor Details
#initialize(val) ⇒ Account
The Account intiailizer.
17 18 19 20 21 22 23 24 25 |
# File 'lib/nano/account.rb', line 17 def initialize(val) if val[:address] @address = val[:address] end if val[:public_key] @public_key = val[:public_key] end end |
Instance Attribute Details
#address ⇒ String (readonly)
Returns The base32 encoded account address.
8 9 10 |
# File 'lib/nano/account.rb', line 8 def address @address end |
#public_key ⇒ String (readonly)
Returns The public key for the account encoded in hexadecimal.
11 12 13 |
# File 'lib/nano/account.rb', line 11 def public_key @public_key end |
Class Method Details
.from_address(input) ⇒ Account
A class initializer to create an Account object from the account base32 address.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/nano/account.rb', line 34 def self.from_address(input) return nil unless input.is_a? String prefix_length = nil if input.start_with? "nano_" prefix_length = 5 elsif input.start_with? "xrb_" prefix_length = 4 end return nil if prefix_length.nil? public_key_bytes = Nano::Base32.decode(input[prefix_length, 52]) checksum = Nano::Base32.decode(input[(prefix_length + 52)..-1]) public_key_bin = Nano::Utils.hex_to_bin public_key_bytes computed_check = Blake2b.hex( public_key_bin, Blake2b::Key.none, 5 ).reverse.upcase return nil if computed_check == checksum Account.new(:address => input, :public_key => public_key_bytes) end |