Class: MixinBot::MainAddress
- Inherits:
-
Object
- Object
- MixinBot::MainAddress
- Defined in:
- lib/mixin_bot/address.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
Class Method Summary collapse
Instance Method Summary collapse
- #decode ⇒ Object
- #encode ⇒ Object
-
#initialize(**args) ⇒ MainAddress
constructor
A new instance of MainAddress.
Constructor Details
#initialize(**args) ⇒ MainAddress
Returns a new instance of MainAddress.
122 123 124 125 126 127 128 129 130 |
# File 'lib/mixin_bot/address.rb', line 122 def initialize(**args) if args[:address] @address = args[:address] decode else @public_key = args[:public_key] encode end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
120 121 122 |
# File 'lib/mixin_bot/address.rb', line 120 def address @address end |
#public_key ⇒ Object
Returns the value of attribute public_key.
120 121 122 |
# File 'lib/mixin_bot/address.rb', line 120 def public_key @public_key end |
Class Method Details
.burning_address ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/mixin_bot/address.rb', line 160 def self.burning_address seed = "\0" * 64 digest1 = SHA3::Digest::SHA256.digest seed digest2 = SHA3::Digest::SHA256.digest digest1 src = digest1 + digest2 spend_key = MixinBot::Utils.shared_public_key(seed) view_key = MixinBot::Utils.shared_public_key(src) MainAddress.new(public_key: spend_key + view_key) end |
Instance Method Details
#decode ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/mixin_bot/address.rb', line 142 def decode raise ArgumentError, 'invalid address' unless address.start_with? MAIN_ADDRESS_PREFIX data = address[MAIN_ADDRESS_PREFIX.length..] data = Base58.base58_to_binary data, :bitcoin payload = data[...-4] msg = MAIN_ADDRESS_PREFIX + payload checksum = SHA3::Digest::SHA256.digest msg raise ArgumentError, 'invalid address' unless checksum[0...4] == data[-4..] self.public_key = payload public_key end |
#encode ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/mixin_bot/address.rb', line 132 def encode msg = MAIN_ADDRESS_PREFIX + public_key checksum = SHA3::Digest::SHA256.digest msg data = public_key + checksum[0...4] base58 = Base58.binary_to_base58 data, :bitcoin self.address = "#{MAIN_ADDRESS_PREFIX}#{base58}" address end |