lightning-invoice 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/lightning/invoice.rb +252 -0
- data/lib/lightning/invoice/routing_info.rb +23 -0
- data/lib/lightning/invoice/version.rb +5 -0
- data/lightning-invoice.gemspec +29 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af1b94aef372d8292e484d74ce290e23636133e8bc665c7c290db17115fb6bd5
|
4
|
+
data.tar.gz: b38a7257c18a3967420c2014dfa4f6d4379be29210830cd564b64d9d42d0e877
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed96a93cce981352263d8d8391311471b6affebbc89e8b896c03beca15557039903b6f3b5d8744cf7197eb9a2c6d3ed99645277c45e33d9d0d08474d64a8f5f5
|
7
|
+
data.tar.gz: cb4322f321c4d3d441e8979d086cbfffe352b64740a2fda5c77850ab8da08a977cb67b06ecf0a8e86955fca85cbf03ef7d1c600cebd9edb9f75f0c0f61ef1b7d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at h_yamaguchi@haw.co.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Lightning::Invoice
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lightning/invoice`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'lightning-invoice'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install lightning-invoice
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Running console
|
26
|
+
|
27
|
+
```
|
28
|
+
$ ./bin/console
|
29
|
+
```
|
30
|
+
|
31
|
+
Encode Payment
|
32
|
+
|
33
|
+
```
|
34
|
+
irb(main):001:0> message = Lightning::Invoice::Message.new
|
35
|
+
=> #<Lightning::Invoice::Message:0x007fd1ec1df1f8 @amount=-1, @timestamp=0, @expiry=3600, @min_final_cltv_expiry=9, @routing_info=[]>
|
36
|
+
irb(main):002:0> message.prefix = "lnbc"
|
37
|
+
=> "lnbc"
|
38
|
+
irb(main):003:0> message.amount = 2500
|
39
|
+
=> 2500
|
40
|
+
irb(main):004:0> message.multiplier = "u"
|
41
|
+
=> "u"
|
42
|
+
irb(main):005:0> message.timestamp = Time.now.to_i
|
43
|
+
=> 1535552315
|
44
|
+
irb(main):006:0> message.payment_hash = "0001020304050607080900010203040506070809000102030405060708090102".htb
|
45
|
+
=> "\x00\x01\x02\x03\x04\x05\x06\a\b\t\x00\x01\x02\x03\x04\x05\x06\a\b\t\x00\x01\x02\x03\x04\x05\x06\a\b\t\x01\x02"
|
46
|
+
irb(main):007:0> message.description = "Please consider supporting this project"
|
47
|
+
=> "Please consider supporting this project"
|
48
|
+
irb(main):008:0> message.expiry = 60
|
49
|
+
=> 60
|
50
|
+
irb(main):009:0> message.signature = "38ec6891345e204145be8a3a99de38e98a39d6a569434e1845c8af7205afcfcc7f425fcd1463e93c32881ead0d6e356d467ec8c02553f9aab15e5738b11f127f00".htb
|
51
|
+
=> "8\xECh\x914^ AE\xBE\x8A:\x99\xDE8\xE9\x8A9\xD6\xA5iCN\x18E\xC8\xAFr\x05\xAF\xCF\xCC\x7FB_\xCD\x14c\xE9<2\x88\x1E\xAD\rn5mF~\xC8\xC0%S\xF9\xAA\xB1^W8\xB1\x1F\x12\x7F\x00"
|
52
|
+
irb(main):010:0> message.fallback_address = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
|
53
|
+
=> "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
|
54
|
+
irb(main):011:0> message.to_bech32
|
55
|
+
=> "lnbc2500u1pdcd2empp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaqxqzpufppqw508d6qejxtdg4y5r3zarvary0c5xw7k8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqgtxcst"
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
Decode Payment
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
irb(main):012:0> Lightning::Invoice.parse("lnbc2500u1pdcd2empp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaqxqzpufppqw508d6qejxtdg4y5r3zarvary0c5xw7k8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqgtxcst")
|
64
|
+
=> #<Lightning::Invoice::Message:0x007fd1eb2dc390 @amount=2500, @timestamp=1535552315, @expiry=60, @min_final_cltv_expiry=9, @routing_info=[], @prefix="lnbc", @multiplier="u", @payment_hash="\x00\x01\x02\x03\x04\x05\x06\a\b\t\x00\x01\x02\x03\x04\x05\x06\a\b\t\x00\x01\x02\x03\x04\x05\x06\a\b\t\x01\x02", @description="Please consider supporting this project", @signature="8\xECh\x914^ AE\xBE\x8A:\x99\xDE8\xE9\x8A9\xD6\xA5iCN\x18E\xC8\xAFr\x05\xAF\xCF\xCC\x7FB_\xCD\x14c\xE9<2\x88\x1E\xAD\rn5mF~\xC8\xC0%S\xF9\xAA\xB1^W8\xB1\x1F\x12\x7F\x00", @fallback_address="bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4">
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
## Development
|
69
|
+
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Yamaguchi/lightning-invoice. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
77
|
+
|
78
|
+
## Code of Conduct
|
79
|
+
|
80
|
+
Everyone interacting in the Lightning::Invoice project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Yamaguchi/lightning-invoice/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lightning/invoice"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
require "lightning/invoice/version"
|
2
|
+
|
3
|
+
require 'bech32'
|
4
|
+
require 'bitcoin'
|
5
|
+
|
6
|
+
module Lightning
|
7
|
+
module Invoice
|
8
|
+
autoload :RoutingInfo, 'lightning/invoice/routing_info'
|
9
|
+
|
10
|
+
PREFIX = 'lnbc'
|
11
|
+
MAX_LENGTH = 2 ** 64
|
12
|
+
|
13
|
+
class Message
|
14
|
+
attr_accessor :prefix, :amount, :multiplier
|
15
|
+
attr_accessor :timestamp, :signature, :payment_hash, :description, :pubkey, :description_hash, :expiry, :min_final_cltv_expiry, :fallback_address, :routing_info
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@amount = -1
|
19
|
+
@timestamp = 0
|
20
|
+
@expiry = 3600
|
21
|
+
@min_final_cltv_expiry = 9
|
22
|
+
@routing_info = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_bech32
|
26
|
+
human = +''
|
27
|
+
human << prefix
|
28
|
+
human << amount.to_s if amount && amount > 0
|
29
|
+
human << multiplier if multiplier
|
30
|
+
data = []
|
31
|
+
data += Invoice.int_to_array(timestamp)
|
32
|
+
if payment_hash
|
33
|
+
data += [1]
|
34
|
+
data += [1, 20]
|
35
|
+
data += Invoice.buffer_to_word(payment_hash)
|
36
|
+
end
|
37
|
+
if description
|
38
|
+
data += [13]
|
39
|
+
description_word = Invoice.buffer_to_word(description)
|
40
|
+
data += Invoice.int_to_array(description_word.size)
|
41
|
+
data += description_word
|
42
|
+
end
|
43
|
+
if pubkey
|
44
|
+
data += [19]
|
45
|
+
data += [1, 21]
|
46
|
+
data += Invoice.buffer_to_word(pubkey)
|
47
|
+
end
|
48
|
+
if description_hash
|
49
|
+
data += [23]
|
50
|
+
data += [1, 20]
|
51
|
+
data += Invoice.buffer_to_word(description_hash)
|
52
|
+
end
|
53
|
+
if expiry && expiry != 3600
|
54
|
+
data += [6]
|
55
|
+
expiry_word = Invoice.int_to_array(expiry)
|
56
|
+
data += Invoice.int_to_array(expiry_word.size)
|
57
|
+
data += expiry_word
|
58
|
+
end
|
59
|
+
if min_final_cltv_expiry && min_final_cltv_expiry != 9
|
60
|
+
data += [24]
|
61
|
+
min_final_cltv_expiry_word = Invoice.int_to_array(min_final_cltv_expiry)
|
62
|
+
data += Invoice.int_to_array(min_final_cltv_expiry_word.size)
|
63
|
+
data += min_final_cltv_expiry_word
|
64
|
+
end
|
65
|
+
if fallback_address
|
66
|
+
data += [9]
|
67
|
+
type = fallback_address_type(fallback_address)
|
68
|
+
case type
|
69
|
+
when 0
|
70
|
+
_, data_part = Bech32.decode(fallback_address)
|
71
|
+
data += Invoice.int_to_array(data_part.size)
|
72
|
+
data += data_part
|
73
|
+
when 17, 18
|
74
|
+
decoded = Bitcoin::Base58.decode(fallback_address)
|
75
|
+
decoded = decoded.htb[1...-4]
|
76
|
+
decoded = Invoice.buffer_to_word(decoded)
|
77
|
+
data += Invoice.int_to_array(decoded.size + 1)
|
78
|
+
data << type
|
79
|
+
data += decoded
|
80
|
+
end
|
81
|
+
end
|
82
|
+
if routing_info && !routing_info.empty?
|
83
|
+
data += [3]
|
84
|
+
data += Invoice.int_to_array(82 * routing_info.size)
|
85
|
+
tmp = []
|
86
|
+
routing_info.each do |r|
|
87
|
+
tmp += r.to_array
|
88
|
+
end
|
89
|
+
data += Invoice.buffer_to_word(tmp.pack("C*"))
|
90
|
+
end
|
91
|
+
data += Invoice.buffer_to_word(signature)
|
92
|
+
Bech32.encode(human, data)
|
93
|
+
end
|
94
|
+
|
95
|
+
def fallback_address_type(fallback_address)
|
96
|
+
address_types = {
|
97
|
+
'lnbc' => [0, 5],
|
98
|
+
'lntb' => [111, 196]
|
99
|
+
}
|
100
|
+
|
101
|
+
hrp, data = Bech32.decode(fallback_address)
|
102
|
+
if hrp
|
103
|
+
0
|
104
|
+
else
|
105
|
+
decoded = [Bitcoin::Base58.decode(fallback_address)].pack("H*").unpack("C*")
|
106
|
+
if decoded[0] == address_types[prefix][0]
|
107
|
+
17
|
108
|
+
elsif decoded[0] == address_types[prefix][1]
|
109
|
+
18
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.parse(str)
|
116
|
+
human, data_part = Bech32.decode(str, MAX_LENGTH)
|
117
|
+
return nil unless human
|
118
|
+
prefix, amount, multiplier = parse_human_readable(human)
|
119
|
+
message = Message.new
|
120
|
+
message.prefix = prefix
|
121
|
+
message.amount = amount.to_i if !amount&.empty?
|
122
|
+
message.multiplier = multiplier
|
123
|
+
message.timestamp = to_int(data_part[0...7])
|
124
|
+
tags = data_part[7...data_part.size - 104]
|
125
|
+
index = 0
|
126
|
+
while index < tags.size
|
127
|
+
type = tags[index]
|
128
|
+
data_length = (tags[index + 1].to_i << 5) + tags[index + 2].to_i
|
129
|
+
data = tags[index + 3 ... index + 3 + data_length]
|
130
|
+
bytes = to_bytes(data)
|
131
|
+
index += 3 + data_length
|
132
|
+
case type
|
133
|
+
when 1
|
134
|
+
message.payment_hash = bytes[0...64].pack("C*")
|
135
|
+
when 13
|
136
|
+
message.description = bytes.pack("C*").force_encoding('utf-8')
|
137
|
+
when 19
|
138
|
+
message.pubkey = bytes[0...66].pack("C*")
|
139
|
+
when 23
|
140
|
+
message.description_hash = bytes[0...64].pack("C*")
|
141
|
+
when 6
|
142
|
+
message.expiry = to_int(data)
|
143
|
+
when 24
|
144
|
+
message.min_final_cltv_expiry = to_int(data)
|
145
|
+
when 9
|
146
|
+
address = to_bytes(data[1..-1])
|
147
|
+
hex = address.pack("C*").unpack("H*").first
|
148
|
+
case data[0]
|
149
|
+
when 0
|
150
|
+
message.fallback_address = Bitcoin::Script.to_p2wpkh(hex).addresses.first
|
151
|
+
when 17
|
152
|
+
message.fallback_address = Bitcoin.encode_base58_address(hex, Bitcoin.chain_params.address_version)
|
153
|
+
when 18
|
154
|
+
message.fallback_address = Bitcoin.encode_base58_address(hex, Bitcoin.chain_params.p2sh_version)
|
155
|
+
else
|
156
|
+
end
|
157
|
+
when 3
|
158
|
+
offset = 0
|
159
|
+
while offset < bytes.size
|
160
|
+
message.routing_info << Lightning::Invoice::RoutingInfo.new(
|
161
|
+
bytes[offset...offset + 33].pack("C*"),
|
162
|
+
bytes[offset + 33...offset + 41].pack("C*"),
|
163
|
+
to_int(bytes[offset + 41...offset + 45]),
|
164
|
+
to_int(bytes[offset + 45...offset + 49]),
|
165
|
+
to_int(bytes[offset + 49...offset + 51])
|
166
|
+
)
|
167
|
+
offset += 51
|
168
|
+
end
|
169
|
+
else
|
170
|
+
end
|
171
|
+
end
|
172
|
+
message.signature = word_to_buffer(data_part[data_part.size - 104..-1], true)
|
173
|
+
message
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.parse_human_readable(human)
|
177
|
+
human.scan(/^([a-zA-Z]+)(\d*)([munp]?)$/)&.first
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.word_to_buffer(data, trim)
|
181
|
+
buffer = convert(data, 5, 8)
|
182
|
+
|
183
|
+
if trim && (data.size * 5 % 8 != 0)
|
184
|
+
buffer = buffer[0...-1]
|
185
|
+
end
|
186
|
+
return buffer.pack("C*")
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.buffer_to_word(buffer)
|
190
|
+
words = convert(buffer.unpack('C*'), 8, 5)
|
191
|
+
return words
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.convert(data, inbits, outbits)
|
195
|
+
value = 0
|
196
|
+
bits = 0
|
197
|
+
max = (1 << outbits) - 1
|
198
|
+
|
199
|
+
result = []
|
200
|
+
n = data.length
|
201
|
+
n.times do |i|
|
202
|
+
value = (value << inbits) | data[i]
|
203
|
+
bits += inbits
|
204
|
+
while bits >= outbits
|
205
|
+
bits -= outbits
|
206
|
+
result << ((value >> bits) & max)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
if bits > 0
|
211
|
+
result << ((value << (outbits - bits)) & max)
|
212
|
+
end
|
213
|
+
|
214
|
+
return result
|
215
|
+
end
|
216
|
+
|
217
|
+
def self.to_int(data)
|
218
|
+
data.inject(0) do |i, sum|
|
219
|
+
sum + (i << 5)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.int_to_array(i, bits = 5, padding = 2)
|
224
|
+
array = []
|
225
|
+
return [0] if i.nil? || i == 0
|
226
|
+
while i > 0
|
227
|
+
array << (i & (2**bits - 1))
|
228
|
+
i = (i / (2**bits)).to_i
|
229
|
+
end
|
230
|
+
if padding > array.size
|
231
|
+
array += [0] * (padding - array.size)
|
232
|
+
end
|
233
|
+
array.reverse
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.to_bytes(data)
|
237
|
+
buf = []
|
238
|
+
(data.size * 5).times do |i|
|
239
|
+
loc5 = (i / 5).to_i
|
240
|
+
loc8 = i >> 3
|
241
|
+
if i % 8 == 0
|
242
|
+
buf[loc8] = 0
|
243
|
+
end
|
244
|
+
buf[loc8] |= ((data[loc5] >> (4 - (i % 5))) & 1) << (7 - (i % 8))
|
245
|
+
end
|
246
|
+
if data.size % 8 != 0
|
247
|
+
buf = buf[0...-1]
|
248
|
+
end
|
249
|
+
buf
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Lightning
|
2
|
+
module Invoice
|
3
|
+
class RoutingInfo
|
4
|
+
attr_accessor :pubkey, :short_channel_id, :fee_base_msat, :fee_proportional_millionths, :cltv_expiry_delta
|
5
|
+
|
6
|
+
def initialize(pubkey, short_channel_id, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta)
|
7
|
+
@pubkey = pubkey
|
8
|
+
@short_channel_id = short_channel_id
|
9
|
+
@fee_base_msat = fee_base_msat
|
10
|
+
@fee_proportional_millionths = fee_proportional_millionths
|
11
|
+
@cltv_expiry_delta = cltv_expiry_delta
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_array
|
15
|
+
pubkey.unpack("C*") +
|
16
|
+
short_channel_id.unpack("C*") +
|
17
|
+
Invoice.int_to_array(fee_base_msat, 5, 4) +
|
18
|
+
Invoice.int_to_array(fee_proportional_millionths, 5, 4) +
|
19
|
+
Invoice.int_to_array(cltv_expiry_delta)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "lightning/invoice/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lightning-invoice"
|
8
|
+
spec.version = Lightning::Invoice::VERSION
|
9
|
+
spec.authors = ["Hajime Yamaguchi"]
|
10
|
+
spec.email = ["gen.yamaguchi0@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Ruby implementation of the Lightning Network Invoice Protocol (BOLT #11).'
|
13
|
+
spec.description = 'Ruby implementation of the Lightning Network Invoice Protocol (BOLT #11).'
|
14
|
+
spec.homepage = 'https://github.com/Yamaguchi/lightning-invoice'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'bech32'
|
28
|
+
spec.add_runtime_dependency 'bitcoinrb'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lightning-invoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hajime Yamaguchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bech32
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bitcoinrb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 'Ruby implementation of the Lightning Network Invoice Protocol (BOLT
|
84
|
+
#11).'
|
85
|
+
email:
|
86
|
+
- gen.yamaguchi0@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/lightning/invoice.rb
|
101
|
+
- lib/lightning/invoice/routing_info.rb
|
102
|
+
- lib/lightning/invoice/version.rb
|
103
|
+
- lightning-invoice.gemspec
|
104
|
+
homepage: https://github.com/Yamaguchi/lightning-invoice
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: 'Ruby implementation of the Lightning Network Invoice Protocol (BOLT #11).'
|
127
|
+
test_files: []
|