Class: Glueby::Internal::Wallet::AR::Key

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/glueby/internal/wallet/active_record/key.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.key_for_output(output) ⇒ Glueby::Internal::Wallet::AR::Key

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

Parameters:

  • output (Tapyrus::TxOut)

Returns:



35
36
37
# 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) ⇒ Glueby::Internal::Wallet::AR::Key

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

Parameters:

  • script_pubkey (Tapyrus::Script)

Returns:



44
45
46
47
48
49
50
51
# 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

Instance Method Details

#addressObject



26
27
28
# File 'lib/glueby/internal/wallet/active_record/key.rb', line 26

def address
  to_p2pkh.addresses.first
end

#sign(data) ⇒ Object



22
23
24
# File 'lib/glueby/internal/wallet/active_record/key.rb', line 22

def sign(data)
  Tapyrus::Key.new(priv_key: self.private_key, key_type: Tapyrus::Key::TYPES[:compressed]).sign(data, algo: :schnorr)
end

#to_p2pkhObject



18
19
20
# File 'lib/glueby/internal/wallet/active_record/key.rb', line 18

def to_p2pkh
  Tapyrus::Script.to_p2pkh(Tapyrus.hash160(public_key))
end