Class: Nis::Unit::Address
- Inherits:
-
Object
- Object
- Nis::Unit::Address
- Defined in:
- lib/nis/unit/address.rb
Instance Attribute Summary collapse
-
#value ⇒ String
The current value of value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(value) ⇒ Address
constructor
A new instance of Address.
- #mainnet? ⇒ Boolean
- #mijin? ⇒ Boolean
- #testnet? ⇒ Boolean
- #to_hexadecimal ⇒ String
- #to_s ⇒ String
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Address
Returns a new instance of Address.
10 11 12 13 |
# File 'lib/nis/unit/address.rb', line 10 def initialize(value) @value = value @first_char = @value[0] end |
Instance Attribute Details
#value ⇒ String
Returns the current value of value.
7 8 9 |
# File 'lib/nis/unit/address.rb', line 7 def value @value end |
Class Method Details
.from_public_key(public_key, network = :testnet) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nis/unit/address.rb', line 50 def self.from_public_key(public_key, network = :testnet) bin_public_key = Nis::Util::Convert.hex2bin(public_key) public_key_hash = Digest::SHA3.digest(bin_public_key, 256) ripe = OpenSSL::Digest::RIPEMD160.digest(public_key_hash) if network == :testnet version = "\x98".force_encoding('ASCII-8BIT') << ripe elsif network == :mijin version = "\x60" << ripe else version = "\x68" << ripe end checksum = Digest::SHA3.digest(version, 256)[0...4] self.new(Base32.encode(version + checksum)) end |
Instance Method Details
#==(other) ⇒ Boolean
46 47 48 |
# File 'lib/nis/unit/address.rb', line 46 def ==(other) @value == other.value end |
#mainnet? ⇒ Boolean
21 22 23 |
# File 'lib/nis/unit/address.rb', line 21 def mainnet? @first_char == 'N' end |
#mijin? ⇒ Boolean
31 32 33 |
# File 'lib/nis/unit/address.rb', line 31 def mijin? @first_char == 'M' end |
#testnet? ⇒ Boolean
26 27 28 |
# File 'lib/nis/unit/address.rb', line 26 def testnet? @first_char == 'T' end |
#to_hexadecimal ⇒ String
41 42 43 |
# File 'lib/nis/unit/address.rb', line 41 def to_hexadecimal @value.each_byte.inject('') { |memo, b| memo << b.to_s(16) } end |
#to_s ⇒ String
36 37 38 |
# File 'lib/nis/unit/address.rb', line 36 def to_s @value end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/nis/unit/address.rb', line 16 def valid? !!(@value =~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{40}/) end |