bitpay-key-utils 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: 57e7c32f43dd65ee8f2978c596ceae25ab5554c7
4
- data.tar.gz: 1d9d8a9921b01e5c79ee85ad190eb8c443248d8f
3
+ metadata.gz: 85114def0e839cb4dbf3f9b5e3fca31190f45c80
4
+ data.tar.gz: d0848a5549a96ddc69167ce3e942ef532a04a659
5
5
  SHA512:
6
- metadata.gz: 23b464c38bf539f3a80f2cde38dbe2b9c6b6397ec16a7a74cb5005fb9324120f5eb9ad0ee6807dade17a6ec40f14bee974fa3f306bc67a3c089993dda8cdb354
7
- data.tar.gz: 400893ec62fdfa9cdc9766784dd06968ff2d3a3f60d38eb8c33ba598ca4160bfd734ef5498aefba660eefdea58ccd69b847077a5b54174a7d5076ec3a854bd2d
6
+ metadata.gz: f06a652fdfc8247875b269645f4d93a4c980ccef43efb0a5dfdc3dbbac43f48ce50dba9c94bdc3ade411f14ffbb0f38edabff5d154c5f5180d52d97017a977c1
7
+ data.tar.gz: 5e81f4d5629f25f56130188baa2cbf3592f7cd15910e627cf597179a4bd18a14ab5be39872f1df98aeaf41c391d86d7d9e245b0934d897d0bc82723db351323b
data/.gitignore CHANGED
@@ -27,7 +27,7 @@ build/
27
27
 
28
28
  # for a library or gem, you might want to ignore these files since the code is
29
29
  # intended to run in multiple environments; otherwise, check them in:
30
- # Gemfile.lock
30
+ Gemfile.lock
31
31
  # .ruby-version
32
32
  # .ruby-gemset
33
33
 
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 2.1.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [2.0.1] - 2015-04-16
6
+ ### Changed
7
+ - Add method: sign\_with\_pem
data/GUIDE.md ADDED
@@ -0,0 +1,42 @@
1
+ # Using the BitPay Key Utilities Library
2
+
3
+ This gem provides utilities for use with the BitPay API. It enables creating keys, retrieving public keys, retrieiving private keys, creating the SIN that is used in retrieving tokens from BitPay, and signing payloads for the `X-Signature` header in a BitPay API request.
4
+ ## Quick Start
5
+ ### Installation
6
+ ```bash
7
+ gem install 'bitpay-key-utils'
8
+ ```
9
+
10
+ In your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'bitpay-key-utils', :require => 'bitpay_key_utils'
14
+ ```
15
+
16
+ Or directly:
17
+
18
+ ```irb
19
+ [1] pry(main)> require 'bitpay_key_utils'
20
+ => true
21
+ [2] pry(main)> pem = BitPay::KeyUtils.generate_pem
22
+ => "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEIF2HghUnVK/MbkS+y8PGOoVpswunIgWHd8GTzWvI97e/oAcGBSuBBAAK\noUQDQgAEA0Jz4UdYJZJugoxUn1k4PVoLKOUus3TkRq0xqoHkZL4QIzzxqS1DmGWr\nfb9Eot6w7QcWRWACF/G/xIp6Nap8bA==\n-----END EC PRIVATE KEY-----\n"
23
+ [3] pry(main)> sin = BitPay::KeyUtils.generate_sin_from_pem pem
24
+ => "TfEKWr2FcX2XnWxUNPJ3iD5Xe6X5frZb1DG"
25
+ [4] pry(main)> priv = BitPay::KeyUtils.get_private_key_from_pem pem
26
+ => "5d8782152754afcc6e44becbc3c63a8569b30ba722058777c193cd6bc8f7b7bf"
27
+ [5] pry(main)> pub = BitPay::KeyUtils.get_public_key_from_pem pem
28
+ => "02034273e1475825926e828c549f59383d5a0b28e52eb374e446ad31aa81e464be"
29
+ [6] pry(main)> BitPay::KeyUtils.sign "this message", priv
30
+ => "304402207b6d2d59f0e2061519c47744fcdff87e8136f0086aa4b94bd667d62221dfbcb802201a0ce7929eed614ff71972879cd0b31813c9ad7ed0e7bbde4590e9a836007db6"
31
+ ```
32
+
33
+ ## API Documentation
34
+
35
+ API Documentation is available on the [BitPay site](https://bitpay.com/api).
36
+
37
+ ## Running the Tests
38
+
39
+ ```bash
40
+ $ bundle
41
+ $ rspec
42
+ ```
data/README.md CHANGED
@@ -1,2 +1,13 @@
1
1
  # bitpay-ruby-keyutils
2
- Crypto methods
2
+
3
+ [![](https://secure.travis-ci.org/bitpay/bitpay-ruby-keyutils.png)](http://travis-ci.org/bitpay/bitpay-ruby-keyutils) [![Gem Version](https://badge.fury.io/rb/bitpay-key-utils.svg)](http://badge.fury.io/rb/bitpay-key-utils)
4
+
5
+ Provides required cryptographic functions to use the BitPay 2.0 API.
6
+
7
+ ## [Getting Started »](http://dev.bitpay.com/guides/ruby-key-utils.html)
8
+
9
+ ## Found a bug?
10
+ Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. We will respond to all filed issues.
11
+
12
+ ## Contributors
13
+ [Click here](https://github.com/bitpay/bitpay-ruby-keyutils/graphs/contributors) to see a list of the contributors to this library.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
5
+ rescue LoadError
6
+ end
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.licenses = ['MIT']
6
6
  s.authors = 'Bitpay, Inc.'
7
7
  s.email = 'info@bitpay.com'
8
- s.homepage = 'https://github.com/bitpay/ruby-key-utils'
8
+ s.homepage = 'https://github.com/bitpay/bitpay-ruby-keyutils'
9
9
  s.summary = 'Official Ruby library for the BitPay API'
10
10
  s.description = 'Powerful, flexible, lightweight, thread-safe interface to the BitPay developers API'
11
11
 
@@ -84,6 +84,11 @@ module BitPay
84
84
  end
85
85
  end
86
86
 
87
+ def sign_with_pem pem, message
88
+ priv = get_private_key_from_pem pem
89
+ sign(message, priv)
90
+ end
91
+
87
92
  ########## Private Class Methods ################
88
93
 
89
94
  ## Base58 Encoding Method
@@ -1,3 +1,3 @@
1
1
  module BitPay
2
- KEY_UTILS_VERSION="2.0.0"
2
+ KEY_UTILS_VERSION="2.0.1"
3
3
  end
@@ -28,7 +28,23 @@ describe BitPay::KeyUtils do
28
28
  it 'will return the right sin for the right pem' do
29
29
  expect(key_utils.generate_sin_from_pem(pem)).to eq sin
30
30
  end
31
+ end
32
+
33
+ describe '.sign_with_pem' do
34
+ it "should provide a valid signature" do
35
+ message = "hello cincinatti"
36
+ digest = Digest::SHA256.digest(message)
31
37
 
38
+ pem = PEM
39
+ signature = key_utils.sign_with_pem pem, message
40
+
41
+ priv= OpenSSL::PKey::EC.new(pem).private_key.to_i
42
+ group = ECDSA::Group::Secp256k1
43
+ pk = group.generator.multiply_by_scalar(priv)
44
+ decoded = ECDSA::Format::SignatureDerString.decode(signature.to_i(16).to_bn.to_s(2))
45
+ valid = ECDSA.valid_signature?(pk, digest, decoded)
46
+ expect(valid).to be(true)
47
+ end
32
48
  end
33
49
 
34
50
  context "errors when priv_key is not provided" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitpay-key-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitpay, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa
@@ -103,17 +103,20 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".ruby-version"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
108
+ - GUIDE.md
106
109
  - Gemfile
107
- - Gemfile.lock
108
110
  - LICENSE
109
111
  - README.md
112
+ - Rakefile
110
113
  - bitpay-key-utils.gemspec
111
114
  - lib/bitpay/key_utils.rb
112
115
  - lib/bitpay/key_version.rb
113
116
  - lib/bitpay_key_utils.rb
114
117
  - spec/key_utils_spec.rb
115
118
  - spec/spec_helper.rb
116
- homepage: https://github.com/bitpay/ruby-key-utils
119
+ homepage: https://github.com/bitpay/bitpay-ruby-keyutils
117
120
  licenses:
118
121
  - MIT
119
122
  metadata: {}
data/Gemfile.lock DELETED
@@ -1,55 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bitpay-key-utils (2.0.1)
5
- ecdsa (~> 1.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- byebug (3.5.1)
11
- columnize (~> 0.8)
12
- debugger-linecache (~> 1.2)
13
- slop (~> 3.6)
14
- coderay (1.1.0)
15
- columnize (0.9.0)
16
- debugger-linecache (1.2.0)
17
- diff-lcs (1.2.5)
18
- ecdsa (1.2.0)
19
- interception (0.5)
20
- method_source (0.8.2)
21
- pry (0.10.1)
22
- coderay (~> 1.1.0)
23
- method_source (~> 0.8.1)
24
- slop (~> 3.4)
25
- pry-byebug (2.0.0)
26
- byebug (~> 3.4)
27
- pry (~> 0.10)
28
- pry-rescue (1.4.1)
29
- interception (>= 0.5)
30
- pry
31
- rake (10.3.2)
32
- rspec (3.1.0)
33
- rspec-core (~> 3.1.0)
34
- rspec-expectations (~> 3.1.0)
35
- rspec-mocks (~> 3.1.0)
36
- rspec-core (3.1.7)
37
- rspec-support (~> 3.1.0)
38
- rspec-expectations (3.1.2)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.1.0)
41
- rspec-mocks (3.1.3)
42
- rspec-support (~> 3.1.0)
43
- rspec-support (3.1.2)
44
- slop (3.6.0)
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
50
- bitpay-key-utils!
51
- pry (= 0.10.1)
52
- pry-byebug (= 2.0.0)
53
- pry-rescue (= 1.4.1)
54
- rake (= 10.3.2)
55
- rspec (= 3.1.0)