class Glueby::Internal::Wallet::AR::Key

Public Class Methods

key_for_output(output) click to toggle source

Return Glueby::Internal::Wallet::AR::Key object for output. If output is colored output, key is found by corresponding `uncolored` script.

@param [Tapyrus::TxOut] output @return [Glueby::Internal::Wallet::AR::Key] key for output

# File lib/glueby/internal/wallet/active_record/key.rb, line 35
def self.key_for_output(output)
  key_for_script(output.script_pubkey)
end
key_for_script(script_pubkey) click to toggle source

Return Glueby::Internal::Wallet::AR::Key object for script. If script is colored, key is found by corresponding `uncolored` script.

@param [Tapyrus::Script] script_pubkey @return [Glueby::Internal::Wallet::AR::Key] key for input

# File lib/glueby/internal/wallet/active_record/key.rb, line 44
def self.key_for_script(script_pubkey)
  script_pubkey = if script_pubkey.colored?
    script_pubkey.remove_color.to_hex
  else
    script_pubkey.to_hex
  end
  find_by(script_pubkey: script_pubkey)
end

Public Instance Methods

address() click to toggle source
# File lib/glueby/internal/wallet/active_record/key.rb, line 26
def address
  to_p2pkh.addresses.first
end
sign(data) click to toggle source
# File lib/glueby/internal/wallet/active_record/key.rb, line 22
def sign(data)
  Tapyrus::Key.new(priv_key: self.private_key).sign(data, algo: :schnorr)
end
to_p2pkh() click to toggle source
# File lib/glueby/internal/wallet/active_record/key.rb, line 18
def to_p2pkh
  Tapyrus::Script.to_p2pkh(Tapyrus.hash160(public_key))
end

Private Instance Methods

generate_key() click to toggle source
# File lib/glueby/internal/wallet/active_record/key.rb, line 55
def generate_key
  key = if private_key
    Tapyrus::Key.new(priv_key: private_key)
  else
    Tapyrus::Key.generate
  end
  self.private_key ||= key.priv_key
  self.public_key ||= key.pubkey
end
set_script_pubkey() click to toggle source
# File lib/glueby/internal/wallet/active_record/key.rb, line 65
def set_script_pubkey
  self.script_pubkey = to_p2pkh.to_hex
end