bech32 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/exe/bech32 +24 -5
- data/lib/bech32/nostr/entity.rb +17 -1
- data/lib/bech32/nostr/nip19.rb +4 -1
- data/lib/bech32/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d29f1fc27cc6566387a4810caa45c5abf8acfd98f53d5bc91467f4479f97c4
|
4
|
+
data.tar.gz: e681f66af497af6f5f5089a4cdfd7937fda0a53bba80ba11c7fd7f3ea650163d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e479ba31346cb4e8d3ab586d780ec7586a076f9a89040c3cb48177243f814440e491592b9473555bb8fb08a7c40a9c82f0bb45065e768d42f4b97404dc904c5
|
7
|
+
data.tar.gz: 053b883473ccf56a6c529898c7c707aaf3abd21e25f097ced6c61e9e52b5919e19b2d36230c0e56c7631748fad366ea468c614971781c54500be1408a06e54b0
|
data/README.md
CHANGED
@@ -153,9 +153,31 @@ The `decode` command takes bech32/bech32m string as arguments and outputs `HRP`,
|
|
153
153
|
|
154
154
|
$ bech32 decode genesis1qyfe883hey6jrgj2xvk5g3dfmfqfzm7a4wez4pd2krf7ltsxffd6u6nrvjvv0uzda6whtuhzscj72zuj6udkmknakfn0anc07gaya2303dnngu3sxqctqvg5v7nw0fvkwqce7auqkxv3sj5j7e8d6vu4zy5qlssvffxqccxqcfgwc98zenr3qrzk5msfgkvjnj0ejpl8zunedeqhvajry08ueg99ynwgd2sdntrq22gensffcj03r3yjv4cv4j20ee8vujxve3fssj2demyvknzwe3glqt6t954vknpdvurthpc9fpex7t97nvqryeqpjrpscap6q0zvfpgv3nxzpy6wmx24k9xcu35vuatm5zvn7t084ec7tlw2gh0av9xwumwkv02hats66l5hkwd55rwkm2q8fsd4zvqwpvqqqqtdc6rp
|
155
155
|
HRP: genesis
|
156
|
-
DATA:
|
156
|
+
DATA: [0, 4, 9, 25, 7, 7, 17, 23, 25, 4, 26, 18, 3, 8, 18, 10, 6, 12, 22, 20, 8, 17, 13, 9, 27, 9, 0, 9, 2, 27, 30, 29, 21, 14, 25, 2, 21, 1, 13, 10, 22, 3, 9, 30, 31, 11, 16, 6, 9, 9, 13, 26, 28, 26, 19, 3, 12, 18, 12, 12, 15, 28, 2, 13, 29, 26, 14, 23, 11, 28, 23, 2, 16, 24, 18, 30, 10, 2, 28, 18, 26, 28, 13, 22, 27, 22, 19, 29, 22, 9, 19, 15, 29, 19, 24, 15, 30, 8, 29, 4, 29, 10, 17, 15, 17, 13, 19, 19, 8, 28, 17, 16, 6, 0, 24, 11, 0, 12, 8, 20, 12, 30, 19, 14, 15, 9, 12, 22, 14, 0, 24, 25, 30, 29, 28, 0, 22, 6, 12, 17, 16, 18, 20, 18, 30, 25, 7, 13, 26, 12, 28, 21, 2, 4, 20, 0, 31, 16, 16, 12, 9, 9, 6, 0, 24, 24, 6, 0, 24, 9, 8, 14, 24, 5, 7, 2, 25, 19, 3, 17, 0, 3, 2, 22, 20, 27, 16, 9, 8, 22, 12, 18, 19, 18, 15, 25, 18, 1, 31, 7, 2, 28, 19, 25, 13, 25, 0, 23, 12, 29, 18, 3, 4, 15, 7, 28, 25, 8, 5, 5, 4, 19, 14, 8, 13, 10, 16, 13, 19, 11, 3, 0, 10, 10, 8, 25, 19, 16, 9, 9, 24, 18, 15, 17, 3, 17, 4, 18, 12, 21, 24, 12, 21, 18, 10, 15, 25, 25, 7, 12, 28, 18, 6, 12, 25, 17, 9, 16, 16, 18, 10, 13, 25, 27, 4, 12, 22, 19, 2, 14, 25, 17, 8, 31, 0, 11, 26, 11, 5, 20, 21, 12, 22, 19, 1, 13, 12, 28, 3, 11, 23, 1, 24, 5, 9, 1, 25, 6, 30, 11, 5, 30, 19, 12, 0, 3, 4, 25, 0, 1, 18, 3, 1, 16, 24, 29, 1, 26, 0, 15, 2, 12, 9, 1, 8, 12, 17, 19, 6, 2, 1, 4, 26, 14, 27, 6, 10, 21, 22, 5, 6, 24, 28, 17, 20, 12, 28, 29, 11, 27, 20, 2, 12, 19, 30, 11, 15, 7, 21, 25, 24, 30, 11, 31, 14, 10, 8, 23, 15, 29, 12, 5, 6, 14, 28, 27, 14, 22, 12, 15, 10, 23, 29, 11, 16, 26, 26, 31, 20, 23, 22, 14, 13, 20, 20, 3, 14, 22, 27, 10, 0, 7, 9, 16, 13, 21, 2, 12, 0, 14, 1, 12, 0, 0, 0, 0]
|
157
157
|
TYPE: bech32
|
158
158
|
|
159
|
+
Note: `DATA` is not bit-converted.
|
160
|
+
|
161
|
+
If bech32 string has segwit hrp, it will also output witness version and witness program:
|
162
|
+
|
163
|
+
$ bech32 decode bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y
|
164
|
+
HRP: bc
|
165
|
+
DATA: [1, 14, 20, 15, 7, 13, 26, 0, 25, 18, 6, 11, 13, 8, 21, 4, 20, 3, 17, 2, 29, 3, 12, 29, 3, 4, 15, 24, 20, 6, 14, 30, 22, 14, 20, 15, 7, 13, 26, 0, 25, 18, 6, 11, 13, 8, 21, 4, 20, 3, 17, 2, 29, 3, 12, 29, 3, 4, 15, 24, 20, 6, 14, 30, 22]
|
166
|
+
TYPE: bech32m
|
167
|
+
WITNESS VERSION: 1
|
168
|
+
WITNESS PROGRAM: 751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6
|
169
|
+
|
170
|
+
If bech32 string has NIP-19 hrp, it will also output NIP-19 entry:
|
171
|
+
|
172
|
+
$ bech32 decode nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p
|
173
|
+
HRP: nprofile
|
174
|
+
DATA: [0, 0, 16, 3, 23, 28, 6, 6, 7, 31, 5, 25, 6, 17, 17, 20, 0, 30, 23, 25, 15, 9, 15, 5, 29, 25, 18, 15, 21, 2, 1, 29, 2, 1, 31, 15, 19, 25, 10, 24, 8, 28, 22, 4, 29, 14, 13, 10, 21, 27, 29, 4, 11, 7, 8, 1, 1, 21, 27, 23, 6, 28, 25, 26, 5, 28, 23, 23, 4, 11, 19, 24, 5, 25, 17, 22, 30, 27, 8, 1, 2, 21, 27, 23, 6, 28, 25, 26, 5, 28, 23, 22, 8, 26, 19, 2, 12, 5, 25, 18, 28, 28, 27, 1, 12, 17, 21, 22, 4, 11, 19, 3, 13, 29, 22, 16]
|
175
|
+
TYPE: bech32
|
176
|
+
NIP19 Entities:
|
177
|
+
special: 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d
|
178
|
+
relay: wss://r.x.com
|
179
|
+
relay: wss://djbas.sadkb.com
|
180
|
+
|
159
181
|
## License
|
160
182
|
|
161
183
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/exe/bech32
CHANGED
@@ -18,13 +18,32 @@ class CLI < Thor
|
|
18
18
|
|
19
19
|
desc 'decode "bech32string"', 'Decoding bech32/bech32m string.'
|
20
20
|
def decode(bech32_str)
|
21
|
-
|
22
|
-
if
|
21
|
+
hrp, data, spec = Bech32.decode(bech32_str, bech32_str.length)
|
22
|
+
if hrp
|
23
23
|
puts <<~EOS
|
24
|
-
HRP: #{
|
25
|
-
DATA: #{
|
26
|
-
TYPE: #{
|
24
|
+
HRP: #{hrp}
|
25
|
+
DATA: #{data.pack('C*').unpack1('H*')}
|
26
|
+
TYPE: #{spec == Bech32::Encoding::BECH32 ? 'bech32' : 'bech32m'}
|
27
27
|
EOS
|
28
|
+
if [Bech32::SegwitAddr::HRP_MAINNET, Bech32::SegwitAddr::HRP_TESTNET, Bech32::SegwitAddr::HRP_REGTEST].include?(hrp)
|
29
|
+
addr = Bech32::SegwitAddr.new(bech32_str)
|
30
|
+
puts <<~EOS
|
31
|
+
WITNESS VERSION: #{addr.ver}
|
32
|
+
WITNESS PROGRAM: #{addr.prog.pack('C*').unpack1('H*')}
|
33
|
+
EOS
|
34
|
+
elsif Bech32::Nostr::NIP19::ALL_PREFIXES.include?(hrp)
|
35
|
+
entity = Bech32::Nostr::NIP19.decode(bech32_str)
|
36
|
+
if entity.is_a?(Bech32::Nostr::BareEntity)
|
37
|
+
puts <<~EOS
|
38
|
+
NIP19 Entity: #{entity.data}
|
39
|
+
EOS
|
40
|
+
else
|
41
|
+
puts 'NIP19 Entities:'
|
42
|
+
entity.entries.each do |entry|
|
43
|
+
puts " #{entry.to_s}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
28
47
|
else
|
29
48
|
puts 'Can not decode.'
|
30
49
|
end
|
data/lib/bech32/nostr/entity.rb
CHANGED
@@ -47,6 +47,22 @@ module Bech32
|
|
47
47
|
[type, len].pack('CC') + data
|
48
48
|
end
|
49
49
|
|
50
|
+
def to_s
|
51
|
+
type_label = case type
|
52
|
+
when TLVEntity::TYPE_SPECIAL
|
53
|
+
'special'
|
54
|
+
when TLVEntity::TYPE_RELAY
|
55
|
+
'relay'
|
56
|
+
when TLVEntity::TYPE_AUTHOR
|
57
|
+
'author'
|
58
|
+
when TLVEntity::TYPE_KIND
|
59
|
+
'kind'
|
60
|
+
else
|
61
|
+
'unknown'
|
62
|
+
end
|
63
|
+
"#{type_label}: #{value}"
|
64
|
+
end
|
65
|
+
|
50
66
|
private
|
51
67
|
|
52
68
|
# Check whether +str+ is hex string or not.
|
@@ -91,7 +107,7 @@ module Bech32
|
|
91
107
|
# @param [String] data Entity data(binary format).
|
92
108
|
# @return [TLVEntity]
|
93
109
|
def self.parse(hrp, data)
|
94
|
-
buf = StringIO.new(data)
|
110
|
+
buf = ::StringIO.new(data)
|
95
111
|
entries = []
|
96
112
|
until buf.eof?
|
97
113
|
type, len = buf.read(2).unpack('CC')
|
data/lib/bech32/nostr/nip19.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
1
3
|
module Bech32
|
2
4
|
module Nostr
|
3
5
|
module NIP19
|
@@ -18,7 +20,8 @@ module Bech32
|
|
18
20
|
|
19
21
|
# Decode nip19 string.
|
20
22
|
# @param [String] string Bech32 string.
|
21
|
-
# @return [BareEntity
|
23
|
+
# @return [BareEntity]
|
24
|
+
# @return [TLVEntity]
|
22
25
|
def decode(string)
|
23
26
|
hrp, data, spec = Bech32.decode(string, string.length)
|
24
27
|
|
data/lib/bech32/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bech32
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shigeyuki Azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|