sibit 0.32.6 → 0.32.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sibit/version.rb +1 -1
  3. data/lib/sibit.rb +15 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fd0f078031f164079de39c2fd14dcd8ac8675861ff74bec96fac105525110cd
4
- data.tar.gz: 7f77f659da2b18be975c7587915f5aa875a21e55237d06582cdac36c8ccda6f8
3
+ metadata.gz: 759028cb2cfe895ec5f71b65a19b0cf2ea6e4cf190b8754196a9b62366095ff8
4
+ data.tar.gz: 49129fb0e16c0554ef74d9a94b2d40a6eb08e4e8c92b41c8079887ee180b0cbe
5
5
  SHA512:
6
- metadata.gz: 072721e3965d7e0719332cdf970f32be79d2b266c5807bad9c56d00a8e2fbd5ba4ca7817c876d093e57873dd6393486e9c3d2052147315dd64ff0b1a565c7f6f
7
- data.tar.gz: bd3727fef02c55442ed256fa836baf422fe9352f58eff4b755f2f87da45a7bf0fd3ba424d54e29da3c9a9f1d8fcd4e6cc913dd4f557de52374ee9ffa29842256
6
+ metadata.gz: e4ef5e308449ad6342a3df1834fdd2d14511d3bcaaac4f180af4ac9d2a424493abc90c6660b119b5e688994f09db6d5393b88f710ad4f261711ca7bac4f0eeec
7
+ data.tar.gz: a38f706880d1e63ac4264926199152aae8e5aab401754f58f20f301227bbdecb89ef01327f9837605f9f5ee1d0c4b276ff4f109fb1e28e151544b390b4ebc704
data/lib/sibit/version.rb CHANGED
@@ -9,5 +9,5 @@
9
9
  # License:: MIT
10
10
  class Sibit
11
11
  # Current version of the library.
12
- VERSION = '0.32.6' unless defined?(VERSION)
12
+ VERSION = '0.32.7' unless defined?(VERSION)
13
13
  end
data/lib/sibit.rb CHANGED
@@ -59,7 +59,7 @@ class Sibit
59
59
 
60
60
  # Creates Bitcoin address using the private key in Hash160 format.
61
61
  def create(pvt)
62
- raise Error, 'Invalid private key (must be 64 chars)' unless /^[0-9a-f]{64}$/.match?(pvt)
62
+ raise Error, 'Invalid private key (must be 64 hex chars)' unless /^[0-9a-f]{64}$/.match?(pvt)
63
63
  Key.new(pvt).bech32
64
64
  end
65
65
 
@@ -105,8 +105,21 @@ class Sibit
105
105
  # +change+: the address where the change has to be sent to
106
106
  # +network+: optional network override (:mainnet, :testnet, :regtest)
107
107
  def pay(amount, fee, sources, target, change, skip_utxo: [], network: nil, base58: false)
108
+ unless amount.is_a?(Integer) || amount.is_a?(String)
109
+ raise Error, "The amount #{amount.inspect} must be Integer or String"
110
+ end
111
+ raise Error, 'The amount must be positive' if amount.is_a?(Integer) && amount.negative?
112
+ raise Error, 'The sources must be an Array' unless sources.is_a?(Array)
113
+ raise Error, 'The target must be a String' unless target.is_a?(String)
114
+ raise Error, 'The change must be a String' unless change.is_a?(String)
108
115
  p = price('USD')
109
- keys = sources.map { |k| Key.new(k, network: network) }
116
+ keys = sources.map do |k|
117
+ raise Error, 'Each source private key must be a String' unless k.is_a?(String)
118
+ hex = /^[0-9a-f]{64}$/i.match?(k)
119
+ wif = /^[5KLc][1-9A-HJ-NP-Za-km-z]{50,51}$/.match?(k)
120
+ raise Error, "Invalid private key format: #{k.inspect.ellipsized(8)}" unless hex || wif
121
+ Key.new(k, network: network)
122
+ end
110
123
  network = keys.first&.network || :mainnet
111
124
  sources = keys.to_h do |k|
112
125
  pub =
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.6
4
+ version: 0.32.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko