tapyrus 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba1dec1b7532b15985c9233604dc63ad38b4a11e61d4bbc63d54cebdb291b3d6
4
- data.tar.gz: 3b7cb3c9e41df3693ac45b22084108b1ec682fd753a10ff95cf0d50133bff959
3
+ metadata.gz: 15ad1708c6361b20c98632d45f81d2ad445114b45123fbc5acc2c8da2fc01c1b
4
+ data.tar.gz: 74a754e7045b6a2475eeb913b79acee31fe882ac8bda39918c774017e1d0cb4e
5
5
  SHA512:
6
- metadata.gz: f82c7815830b1eb9aba88b0247acf36cb64f9ab47802e6b05c6dc4e167503baf85fa1696bfc59fe79cd78c8866b0638b2022cb52b3c924e2db34f09c06d01370
7
- data.tar.gz: 8cdeec0c475d32f905b245f3b2a8ef9551d4ee55a1e21abe9a5b1f38b1dfe6fb317cfa85387899b5d0d5667bf19278654fee800b0b90234fa1407cd9f1703f8b
6
+ metadata.gz: e71234f42f008a4e81ab87652ffe1e386303b0e0a731fce90a84e7e77fb40ef6549f777762970d6dbbb380d8f6d6fa5f1d4af2a7e42038d8a210221317eb6d33
7
+ data.tar.gz: 21c7fbefd23b4fb42d4dc9400917c2d42650db8b7dfaa09bb5d96ed14f2d04a707fa749e8964c69b6c297261875f30f2e0a0a6e2b7c1a702e607e9bce537fd49
data/lib/tapyrus.rb CHANGED
@@ -118,14 +118,7 @@ module Tapyrus
118
118
 
119
119
  # get opcode
120
120
  def opcode
121
- case encoding
122
- when Encoding::ASCII_8BIT
123
- each_byte.next
124
- when Encoding::US_ASCII
125
- ord
126
- else
127
- to_i
128
- end
121
+ force_encoding(Encoding::ASCII_8BIT).ord
129
122
  end
130
123
 
131
124
  def opcode?
@@ -130,6 +130,12 @@ module Tapyrus
130
130
  Tapyrus::Script.to_p2pkh(hex)
131
131
  when Tapyrus.chain_params.p2sh_version
132
132
  Tapyrus::Script.to_p2sh(hex)
133
+ when Tapyrus.chain_params.cp2pkh_version
134
+ color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
135
+ Tapyrus::Script.to_cp2pkh(color, hex[66..-1])
136
+ when Tapyrus.chain_params.cp2sh_version
137
+ color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
138
+ Tapyrus::Script.to_cp2sh(color, hex[66..-1])
133
139
  else
134
140
  throw e
135
141
  end
data/lib/tapyrus/util.rb CHANGED
@@ -113,6 +113,9 @@ module Tapyrus
113
113
  if hex.size == 50 && calc_checksum(hex[0...-8]) == hex[-8..-1]
114
114
  raise 'Invalid version bytes.' unless [Tapyrus.chain_params.address_version, Tapyrus.chain_params.p2sh_version].include?(hex[0..1])
115
115
  [hex[2...-8], hex[0..1]]
116
+ elsif hex.size == 116 && calc_checksum(hex[0...-8]) == hex[-8..-1]
117
+ raise 'Invalid version bytes.' unless [Tapyrus.chain_params.cp2pkh_version, Tapyrus.chain_params.cp2sh_version].include?(hex[0..1])
118
+ [hex[2...-8], hex[0..1]]
116
119
  else
117
120
  raise 'Invalid address.'
118
121
  end
@@ -128,6 +131,18 @@ module Tapyrus
128
131
  OpenSSL::HMAC.digest(DIGEST_NAME_SHA256, key, data)
129
132
  end
130
133
 
134
+ # check whether +addr+ is valid address.
135
+ # @param [String] addr an address
136
+ # @return [Boolean] if valid address return true, otherwise false.
137
+ def valid_address?(addr)
138
+ begin
139
+ Tapyrus::Script.parse_from_addr(addr)
140
+ true
141
+ rescue Exception => e
142
+ false
143
+ end
144
+ end
145
+
131
146
  end
132
147
 
133
148
  module HexConverter
@@ -1,3 +1,3 @@
1
1
  module Tapyrus
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapyrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa
@@ -421,7 +421,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
421
421
  - !ruby/object:Gem::Version
422
422
  version: '0'
423
423
  requirements: []
424
- rubygems_version: 3.1.2
424
+ rubygems_version: 3.0.6
425
425
  signing_key:
426
426
  specification_version: 4
427
427
  summary: The implementation of Tapyrus Protocol for Ruby.