class Nis::Unit::Address
@attr [String] value
Attributes
value[RW]
Public Class Methods
from_public_key(public_key, network = :testnet)
click to toggle source
# 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
new(value)
click to toggle source
# File lib/nis/unit/address.rb, line 10 def initialize(value) @value = value @first_char = @value[0] end
Public Instance Methods
==(other)
click to toggle source
@return [Boolean]
# File lib/nis/unit/address.rb, line 46 def ==(other) @value == other.value end
mainnet?()
click to toggle source
@return [Boolean]
# File lib/nis/unit/address.rb, line 21 def mainnet? @first_char == 'N' end
mijin?()
click to toggle source
@return [Boolean]
# File lib/nis/unit/address.rb, line 31 def mijin? @first_char == 'M' end
testnet?()
click to toggle source
@return [Boolean]
# File lib/nis/unit/address.rb, line 26 def testnet? @first_char == 'T' end
to_hexadecimal()
click to toggle source
@return [String]
# 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()
click to toggle source
@return [String]
# File lib/nis/unit/address.rb, line 36 def to_s @value end
valid?()
click to toggle source
@return [Boolean]
# File lib/nis/unit/address.rb, line 16 def valid? !!(@value =~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{40}/) end