Class: Lightning::Invoice::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/invoice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



17
18
19
# File 'lib/lightning/invoice.rb', line 17

def initialize
  @routing_info = []
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



14
15
16
# File 'lib/lightning/invoice.rb', line 14

def amount
  @amount
end

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def description
  @description
end

#description_hashObject

Returns the value of attribute description_hash.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def description_hash
  @description_hash
end

#expiryObject

Returns the value of attribute expiry.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def expiry
  @expiry
end

#fallback_addressObject

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_expiryObject

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

#multiplierObject

Returns the value of attribute multiplier.



14
15
16
# File 'lib/lightning/invoice.rb', line 14

def multiplier
  @multiplier
end

#payment_hashObject

Returns the value of attribute payment_hash.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def payment_hash
  @payment_hash
end

#prefixObject

Returns the value of attribute prefix.



14
15
16
# File 'lib/lightning/invoice.rb', line 14

def prefix
  @prefix
end

#pubkeyObject

Returns the value of attribute pubkey.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def pubkey
  @pubkey
end

#routing_infoObject

Returns the value of attribute routing_info.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def routing_info
  @routing_info
end

#signatureObject

Returns the value of attribute signature.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def signature
  @signature
end

#timestampObject

Returns the value of attribute timestamp.



15
16
17
# File 'lib/lightning/invoice.rb', line 15

def timestamp
  @timestamp
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_bech32Object



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