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.
162 163 164 165 166 167 168 169 170 |
# File 'lib/mixin_bot/address.rb', line 162 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.
160 161 162 |
# File 'lib/mixin_bot/address.rb', line 160 def address @address end |
#public_key ⇒ Object
Returns the value of attribute public_key.
160 161 162 |
# File 'lib/mixin_bot/address.rb', line 160 def public_key @public_key end |
Class Method Details
.burning_address ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/mixin_bot/address.rb', line 200 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
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/mixin_bot/address.rb', line 182 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
172 173 174 175 176 177 178 179 180 |
# File 'lib/mixin_bot/address.rb', line 172 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 |