Class: AdequateCryptoAddress::Xmr

Inherits:
Object
  • Object
show all
Defined in:
lib/adequate_crypto_address/xmr.rb

Overview

Validates Monero addresses by decoding the Monero Base58 payload and verifying the network byte, structural length, and Keccak-256 checksum. References: https://docs.getmonero.org/public-address/standard-address/ and https://docs.getmonero.org/public-address/integrated-address/

Constant Summary collapse

STANDARD_LENGTH =

prefix(1) + spend key(32) + view key(32) + checksum(4)

69
INTEGRATED_LENGTH =

standard + payment id(8)

77
CHECKSUM_LENGTH =
4
ENCODED_LENGTHS =
[95, 106].freeze
NETWORK_PREFIXES =
{
  standard: { 18 => :mainnet, 53 => :testnet, 24 => :stagenet },
  integrated: { 19 => :mainnet, 54 => :testnet, 25 => :stagenet },
  subaddress: { 42 => :mainnet, 63 => :testnet, 36 => :stagenet }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Xmr

Returns a new instance of Xmr.



24
25
26
27
# File 'lib/adequate_crypto_address/xmr.rb', line 24

def initialize(address)
  @address = address
  @type = detect_type
end

Instance Attribute Details

#address ⇒ Object (readonly)

Returns the value of attribute address.



22
23
24
# File 'lib/adequate_crypto_address/xmr.rb', line 22

def address
  @address
end

#network ⇒ Object (readonly)

Returns the value of attribute network.



22
23
24
# File 'lib/adequate_crypto_address/xmr.rb', line 22

def network
  @network
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/adequate_crypto_address/xmr.rb', line 22

def type
  @type
end

Instance Method Details

#address_type ⇒ Object

:standard, :integrated, or :subaddress when valid, otherwise nil.



36
37
38
# File 'lib/adequate_crypto_address/xmr.rb', line 36

def address_type
  type
end

#valid?(validated_type = nil) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/adequate_crypto_address/xmr.rb', line 29

def valid?(validated_type = nil)
  return !type.nil? unless validated_type

  type == validated_type.to_sym
end