bitcoin-cigs 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitcoin-cigs (0.0.1)
4
+ bitcoin-cigs (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/bin/bitcoin-cigs ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'bitcoin-cigs'
5
+
6
+ @options = {}
7
+
8
+ opt_parser = OptionParser.new do |opt|
9
+ opt.banner = "Usage: bitcoin-cigs command [arguments ...] [options ...]"
10
+ opt.separator ""
11
+ opt.separator "Commands"
12
+ opt.separator " verify bitcoin-address signature [message-file]"
13
+ opt.separator " sign private-key [message-file]"
14
+ opt.separator ""
15
+ opt.separator "Options"
16
+ opt.on("-m", "--message MESSAGE", "Message can also be read from STDIN") do |message|
17
+ @options[:message] = message
18
+ end
19
+ opt.on("-S", "--no-strip", "Do not strip leading and trailing whitespace from message (stripped by default)") do
20
+ @options[:no_strip] = true
21
+ end
22
+ end
23
+
24
+ opt_parser.parse!
25
+
26
+ def message
27
+ message = @options[:message] || ARGF.read
28
+ message.strip! unless @options[:no_strip]
29
+
30
+ message
31
+ end
32
+
33
+ begin
34
+ case ARGV.shift
35
+ when "verify"
36
+ address = ARGV.shift or raise ArgumentError
37
+ signature = ARGV.shift or raise ArgumentError
38
+ ::BitcoinCigs.verify_message!(address, signature, message)
39
+ when "sign"
40
+ private_key = ARGV.shift or raise ArgumentError
41
+ puts ::BitcoinCigs.sign_message!(private_key, message)
42
+ else
43
+ raise ArgumentError
44
+ end
45
+ exit 0
46
+ rescue ::BitcoinCigs::Error => e
47
+ puts "Error: #{e}"
48
+ exit 2
49
+ rescue ArgumentError
50
+ puts opt_parser
51
+ exit 1
52
+ end
data/bitcoin-cigs.gemspec CHANGED
@@ -15,8 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "bitcoin-cigs"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.require_paths = ["lib"]
20
+ s.executables = ['bitcoin-cigs']
20
21
 
21
22
  s.add_development_dependency 'rspec', '~> 2.13.0'
22
23
  s.add_development_dependency 'rake', '~> 10.0.4'
data/lib/bitcoin_cigs.rb CHANGED
@@ -45,13 +45,14 @@ module BitcoinCigs
45
45
  order = g.order
46
46
 
47
47
  sig = decode64(signature)
48
- raise ::BitcoinCigs::Error.new("Bad signature") if sig.size != 65
48
+ raise ::BitcoinCigs::Error.new("Bad signature length") if sig.size != 65
49
+ raise ::BitcoinCigs::Error.new("Bad characters in signature") if signature != encode64(sig)
49
50
 
50
51
  hb = sig[0].ord
51
52
  r, s = [sig[1...33], sig[33...65]].collect { |s| str_to_num(s) }
52
53
 
53
54
 
54
- raise ::BitcoinCigs::Error.new("Bad first byte") if hb < 27 || hb >= 35
55
+ raise ::BitcoinCigs::Error.new("Bad signature first byte") if hb < 27 || hb >= 35
55
56
 
56
57
  compressed = false
57
58
  if hb >= 31
@@ -79,7 +80,7 @@ module BitcoinCigs
79
80
 
80
81
  public_key = ::BitcoinCigs::PublicKey.new(g, q, compressed)
81
82
  addr = public_key_to_bc_address(public_key.ser(), network_version)
82
- raise ::BitcoinCigs::Error.new("Bad address. Signing: #{addr}, Received: #{address}") if address != addr
83
+ raise ::BitcoinCigs::Error.new("Incorrect address or message for signature.") if address != addr
83
84
 
84
85
  nil
85
86
  end
@@ -1,3 +1,3 @@
1
1
  module BitcoinCigs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -103,8 +103,7 @@ describe BitcoinCigs do
103
103
  let(:address) { "invalid" }
104
104
 
105
105
  it "raises ::BitcoinCigs::Error" do
106
- # TODO: improve message
107
- expect { subject }.to raise_error(::BitcoinCigs::Error, "Bad address. Signing: #{original_address}, Received: #{address}")
106
+ expect { subject }.to raise_error(::BitcoinCigs::Error, "Incorrect address or message for signature.")
108
107
  end
109
108
  end
110
109
 
@@ -112,7 +111,7 @@ describe BitcoinCigs do
112
111
  let(:signature) { "invalid" }
113
112
 
114
113
  it "raises ::BitcoinCigs::Error" do
115
- expect { subject }.to raise_error(::BitcoinCigs::Error, "Bad signature")
114
+ expect { subject }.to raise_error(::BitcoinCigs::Error, "Bad signature length")
116
115
  end
117
116
  end
118
117
 
@@ -120,8 +119,7 @@ describe BitcoinCigs do
120
119
  let(:message) { "invalid" }
121
120
 
122
121
  it "raises ::BitcoinCigs::Error" do
123
- # TODO: wrong message, also occurs in python version
124
- expect { subject }.to raise_error(::BitcoinCigs::Error, "Bad address. Signing: 1Es3JV8zYTMtbg7rPMizYZYPc8rcvsJ21m, Received: #{address}")
122
+ expect { subject }.to raise_error(::BitcoinCigs::Error, "Incorrect address or message for signature.")
125
123
  end
126
124
  end
127
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin-cigs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -46,7 +46,8 @@ dependencies:
46
46
  description: Create and Verify Bitcoin Signatures.
47
47
  email:
48
48
  - michaelgpearce@yahoo.com
49
- executables: []
49
+ executables:
50
+ - bitcoin-cigs
50
51
  extensions: []
51
52
  extra_rdoc_files: []
52
53
  files:
@@ -56,6 +57,7 @@ files:
56
57
  - LICENSE.txt
57
58
  - README.md
58
59
  - Rakefile
60
+ - bin/bitcoin-cigs
59
61
  - bitcoin-cigs.gemspec
60
62
  - lib/bitcoin-cigs.rb
61
63
  - lib/bitcoin_cigs.rb