lnurl 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +12 -0
- data/lib/lnurl.rb +35 -7
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb41a73ee0984e37274f04544835308f492c64fb1a53f64f86160320b440a501
|
|
4
|
+
data.tar.gz: 4f0a3139f4e8ac0e6f55d8933ac7afc8b7afd55219da5a0c7846230d34ec17fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46d6ab4938ad39f8810cd640f51c4476775ac22f1f09ab73ae93613789e3ea8d4d4fbcd4cbfa5c221a31ee6b72f40070b907961500669d1c8a2a91c479ab1d9e
|
|
7
|
+
data.tar.gz: 6416737b60aaf96f4881d92657789d8e2527def63b035a449bd70fc0989afa61511deaf9bc318d952c9eeb27332436187a51949ef8a51216cdb479040e9bf25b
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lnurl (
|
|
5
|
-
bech32 (~> 1.
|
|
4
|
+
lnurl (1.1.1)
|
|
5
|
+
bech32 (~> 1.1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
bech32 (1.2
|
|
10
|
+
bech32 (1.4.2)
|
|
11
11
|
thor (>= 1.1.0)
|
|
12
12
|
diff-lcs (1.4.4)
|
|
13
13
|
rake (12.3.3)
|
|
@@ -24,7 +24,7 @@ GEM
|
|
|
24
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
25
25
|
rspec-support (~> 3.10.0)
|
|
26
26
|
rspec-support (3.10.2)
|
|
27
|
-
thor (1.
|
|
27
|
+
thor (1.2.2)
|
|
28
28
|
|
|
29
29
|
PLATFORMS
|
|
30
30
|
ruby
|
|
@@ -35,4 +35,4 @@ DEPENDENCIES
|
|
|
35
35
|
rspec (~> 3.0)
|
|
36
36
|
|
|
37
37
|
BUNDLED WITH
|
|
38
|
-
2.
|
|
38
|
+
2.4.4
|
data/README.md
CHANGED
|
@@ -42,6 +42,18 @@ lnurl = Lnurl.decode('LNURL1DP68GURN8GHJ7MRWW4EXCTNRDAKJ7URP0YVM59LW')
|
|
|
42
42
|
lnurl.uri # => #<URI::HTTPS https://lnurl.com/pay>
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
By default we accept long LNURLs but you can configure a custom max length:
|
|
46
|
+
```ruby
|
|
47
|
+
lnurl = Lnurl.decode(a_short_lnurl, 90)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### [Lightning Address](https://github.com/andrerfneves/lightning-address)
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
lnurl = Lnurl.from_lightning_address('user@lnurl.com')
|
|
54
|
+
lnurl.uri # => #<URI::HTTPS https://lnurl.com/.well-known/lnurlp/user>
|
|
55
|
+
```
|
|
56
|
+
|
|
45
57
|
### LNURL responses
|
|
46
58
|
|
|
47
59
|
```ruby
|
data/lib/lnurl.rb
CHANGED
|
@@ -4,7 +4,11 @@ require 'json'
|
|
|
4
4
|
require 'ostruct'
|
|
5
5
|
|
|
6
6
|
class Lnurl
|
|
7
|
-
VERSION = '1.
|
|
7
|
+
VERSION = '1.1.1'.freeze
|
|
8
|
+
|
|
9
|
+
# Maximum integer size
|
|
10
|
+
# Useful for max_length when decoding
|
|
11
|
+
MAX_INTEGER = 2**31 - 1
|
|
8
12
|
|
|
9
13
|
InvoiceResponse = Class.new(OpenStruct)
|
|
10
14
|
LnurlResponse = Class.new(OpenStruct) do
|
|
@@ -16,7 +20,7 @@ class Lnurl
|
|
|
16
20
|
args = Hash[URI.decode_www_form(callback_uri.query)].merge(args) # reverse merge
|
|
17
21
|
end
|
|
18
22
|
callback_uri.query = URI.encode_www_form(args)
|
|
19
|
-
body =
|
|
23
|
+
body = Lnurl.http_get(callback_uri)
|
|
20
24
|
InvoiceResponse.new JSON.parse(body)
|
|
21
25
|
end
|
|
22
26
|
end
|
|
@@ -40,7 +44,7 @@ class Lnurl
|
|
|
40
44
|
|
|
41
45
|
def response
|
|
42
46
|
@response ||= begin
|
|
43
|
-
body =
|
|
47
|
+
body = self.class.http_get(uri)
|
|
44
48
|
LnurlResponse.new JSON.parse(body)
|
|
45
49
|
end
|
|
46
50
|
end
|
|
@@ -61,17 +65,26 @@ class Lnurl
|
|
|
61
65
|
return decoded.match?(URI.regexp) # check if the URI is valid
|
|
62
66
|
end
|
|
63
67
|
|
|
64
|
-
def self.decode(lnurl)
|
|
65
|
-
Lnurl.new(decode_raw(lnurl))
|
|
68
|
+
def self.decode(lnurl, max_length = MAX_INTEGER)
|
|
69
|
+
Lnurl.new(decode_raw(lnurl, max_length))
|
|
66
70
|
end
|
|
67
71
|
|
|
68
|
-
def self.decode_raw(lnurl)
|
|
72
|
+
def self.decode_raw(lnurl, max_length = MAX_INTEGER)
|
|
69
73
|
lnurl = lnurl.gsub(/^lightning:/, '')
|
|
70
|
-
hrp, data, sepc = Bech32.decode(lnurl)
|
|
74
|
+
hrp, data, sepc = Bech32.decode(lnurl, max_length)
|
|
71
75
|
# raise 'no lnurl' if hrp != HRP
|
|
72
76
|
convert_bits(data, 5, 8, false).pack('C*').force_encoding('utf-8')
|
|
73
77
|
end
|
|
74
78
|
|
|
79
|
+
def self.from_lightning_address(lightning_address)
|
|
80
|
+
Lnurl.new(decode_lightning_address(lightning_address))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.decode_lightning_address(lightning_address)
|
|
84
|
+
username, domain = lightning_address.split('@')
|
|
85
|
+
"https://#{domain}/.well-known/lnurlp/#{username}"
|
|
86
|
+
end
|
|
87
|
+
|
|
75
88
|
# FROM: https://github.com/azuchi/bech32rb/blob/master/lib/bech32/segwit_addr.rb
|
|
76
89
|
def self.convert_bits(data, from, to, padding=true)
|
|
77
90
|
acc = 0
|
|
@@ -95,4 +108,19 @@ class Lnurl
|
|
|
95
108
|
end
|
|
96
109
|
ret
|
|
97
110
|
end
|
|
111
|
+
|
|
112
|
+
# Handles HTTP GET requests and follows redirects if necessary
|
|
113
|
+
def self.http_get(uri, limit = 10)
|
|
114
|
+
raise ArgumentError, 'too many HTTP redirects' if limit.zero?
|
|
115
|
+
|
|
116
|
+
response = Net::HTTP.get_response(uri)
|
|
117
|
+
|
|
118
|
+
case response
|
|
119
|
+
when Net::HTTPRedirection
|
|
120
|
+
location = response['location']
|
|
121
|
+
http_get(URI(location), limit - 1)
|
|
122
|
+
else
|
|
123
|
+
response.body
|
|
124
|
+
end
|
|
125
|
+
end
|
|
98
126
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lnurl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Bumann
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bech32
|
|
@@ -51,7 +51,7 @@ metadata:
|
|
|
51
51
|
homepage_uri: https://github.com/bumi/lnurl-ruby
|
|
52
52
|
source_code_uri: https://github.com/bumi/lnurl-ruby
|
|
53
53
|
funding: lightning:02ad33d99d0bb3bf3bb8ec8e089cbefa8fd7de23a13cfa59aec9af9730816be76f
|
|
54
|
-
post_install_message:
|
|
54
|
+
post_install_message:
|
|
55
55
|
rdoc_options: []
|
|
56
56
|
require_paths:
|
|
57
57
|
- lib
|
|
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
68
|
requirements: []
|
|
69
|
-
rubygems_version: 3.
|
|
70
|
-
signing_key:
|
|
69
|
+
rubygems_version: 3.4.10
|
|
70
|
+
signing_key:
|
|
71
71
|
specification_version: 4
|
|
72
72
|
summary: LNURL implementation for ruby
|
|
73
73
|
test_files: []
|