lnurl 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +12 -0
- data/lib/lnurl.rb +18 -5
- 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: f06941b90b37171d472eeec93f3decbd39f266dfcd561dc7a9e2b40169941e89
|
4
|
+
data.tar.gz: 548acd35d90b87c560a259f4efeba41ddd265197969c5e74acf0aa22d67bd999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac21021140798716061f2505fd4486624004c9d9fae2178cfc77d1fcb5a927c06dd62f580eb198b67fbcfa37b29b07364e9367d6519d80e482b3314549518b90
|
7
|
+
data.tar.gz: aba3f442248206c0aea044ba39b5cb25772db51094b7942bf15888f01da3093fc5f528e88f3709cb98c1670521b3eddc0c9d1b335491d6c60e20e207761c62a4
|
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.0)
|
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.0
|
7
|
+
VERSION = '1.1.0'.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
|
@@ -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
|
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.0
|
4
|
+
version: 1.1.0
|
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: 2023-09-26 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.1
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: LNURL implementation for ruby
|
73
73
|
test_files: []
|