Class: Lightning::Invoice::Message
- Inherits:
-
Object
- Object
- Lightning::Invoice::Message
- Defined in:
- lib/lightning/invoice.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#description ⇒ Object
Returns the value of attribute description.
-
#description_hash ⇒ Object
Returns the value of attribute description_hash.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#fallback_address ⇒ Object
Returns the value of attribute fallback_address.
-
#min_final_cltv_expiry ⇒ Object
Returns the value of attribute min_final_cltv_expiry.
-
#multiplier ⇒ Object
Returns the value of attribute multiplier.
-
#payment_hash ⇒ Object
Returns the value of attribute payment_hash.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#pubkey ⇒ Object
Returns the value of attribute pubkey.
-
#routing_info ⇒ Object
Returns the value of attribute routing_info.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #fallback_address_type(fallback_address) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #sign(key, recovery: '00') ⇒ Object
- #to_bech32 ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
17 18 19 |
# File 'lib/lightning/invoice.rb', line 17 def initialize @routing_info = [] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
14 15 16 |
# File 'lib/lightning/invoice.rb', line 14 def amount @amount end |
#description ⇒ Object
Returns the value of attribute description.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def description @description end |
#description_hash ⇒ Object
Returns the value of attribute description_hash.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def description_hash @description_hash end |
#expiry ⇒ Object
Returns the value of attribute expiry.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def expiry @expiry end |
#fallback_address ⇒ Object
Returns the value of attribute fallback_address.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def fallback_address @fallback_address end |
#min_final_cltv_expiry ⇒ Object
Returns the value of attribute min_final_cltv_expiry.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def min_final_cltv_expiry @min_final_cltv_expiry end |
#multiplier ⇒ Object
Returns the value of attribute multiplier.
14 15 16 |
# File 'lib/lightning/invoice.rb', line 14 def multiplier @multiplier end |
#payment_hash ⇒ Object
Returns the value of attribute payment_hash.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def payment_hash @payment_hash end |
#prefix ⇒ Object
Returns the value of attribute prefix.
14 15 16 |
# File 'lib/lightning/invoice.rb', line 14 def prefix @prefix end |
#pubkey ⇒ Object
Returns the value of attribute pubkey.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def pubkey @pubkey end |
#routing_info ⇒ Object
Returns the value of attribute routing_info.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def routing_info @routing_info end |
#signature ⇒ Object
Returns the value of attribute signature.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def signature @signature end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
15 16 17 |
# File 'lib/lightning/invoice.rb', line 15 def end |
Instance Method Details
#fallback_address_type(fallback_address) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lightning/invoice.rb', line 28 def fallback_address_type(fallback_address) address_types = { 'lnbc' => [0, 5], 'lntb' => [111, 196] } hrp, data = Bech32.decode(fallback_address) if hrp 0 else decoded = [Bitcoin::Base58.decode(fallback_address)].pack("H*").unpack("C*") if decoded[0] == address_types[prefix][0] 17 elsif decoded[0] == address_types[prefix][1] 18 end end end |
#sign(key, recovery: '00') ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lightning/invoice.rb', line 47 def sign(key, recovery: '00') human = to_human_string data = to_data_array sig_data = human.bth + Invoice.word_to_buffer(data).bth sig_as_der = key.sign(Bitcoin.sha256(sig_data.htb)) sig = ECDSA::Format::SignatureDerString.decode(sig_as_der) self.signature = sig.r.to_s(16).rjust(64, '0') + sig.s.to_s(16).rjust(64, '0') self.signature += recovery self end |
#to_bech32 ⇒ Object
21 22 23 24 25 26 |
# File 'lib/lightning/invoice.rb', line 21 def to_bech32 human = to_human_string data = to_data_array data += Invoice.buffer_to_word(signature.htb) Bech32.encode(human, data) end |