bitcoin-secp256k1 0.4.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: 6035dfb23c9b97f481f98bf2bdee8aa281776cb0
4
- data.tar.gz: 31d82871124f52d7f3e8cbbd21ff35756ffca425
2
+ SHA256:
3
+ metadata.gz: '038eab383cf48791b0fec41361ffd2d12ebc0e8f237e1c8610abef9884380400'
4
+ data.tar.gz: 50a54d28c8ed10245ffa16dab0c73e7a336505dca71ce859416028428878a9ea
5
5
  SHA512:
6
- metadata.gz: bab2b773ca043cfb475f83f46b7e81496ec6c9c582408ea598a4da3ef9a14d090758680f3e78ea048a5d25250fd866f25424279e94052cb081cbd45f1e784280
7
- data.tar.gz: 3ac36d282caf5d578121f209fdfd2937483bdbc7126c74bdedea1cd955610724ef1554231378aef4f7ec9a5e43c92dcd3e46f0d930f1c4725bae67773fbe1990
6
+ metadata.gz: bdbf5f0f3b92a943d37db6c352e078f6bdcafae23a4d04a72d9fa51e499b0f94211d80898084457ee349fc846f217e4c46bcd0c10251854dd3210b66171ce163
7
+ data.tar.gz: fa51063d85e791793c9314efe3aee7084005d8f854e5f941d725529aa37d69b89542136b2592d567a3aba9ae70d2c240c9f556864f656de4706ccecbfb301f16
@@ -1,3 +1,3 @@
1
1
  [submodule "secp256k1"]
2
2
  path = secp256k1
3
- url = git@github.com:bitcoin/secp256k1.git
3
+ url = https://github.com/bitcoin-core/secp256k1.git
@@ -0,0 +1,61 @@
1
+ ################
2
+ # CI Workflow:
3
+ # feature development, trigger by `git push`:
4
+ # test -> code_audit(code_security_audit and code_quality_audit)
5
+ #
6
+ # feature deploy, trigger by `git push --tags`
7
+ # test -> deploy
8
+ #
9
+ # Stages:
10
+ # - test: run `rake test`
11
+ # - code_audit: run `code_quality security_audit` and `code_quality quality_audit`
12
+ # - deploy: auto build and upload a gem package to rubygems.org after `git push --tags`
13
+ #
14
+ # Principle:
15
+ # - fail fast
16
+ # - done is better than perfect
17
+ ################
18
+
19
+ stages:
20
+ - test
21
+ - code_audit
22
+ - deploy
23
+
24
+ sudo: false
25
+ language: ruby
26
+ rvm:
27
+ - 2.4.4
28
+ - 2.5.3
29
+ before_install:
30
+ - gem install bundler
31
+ - git submodule update --init --recursive
32
+ - ./install_lib.sh
33
+
34
+ # config GitHub OAuth Token
35
+ env:
36
+ global:
37
+ secure: ENV_GLOBAL_SECURE
38
+
39
+ jobs:
40
+ include:
41
+ - stage: code_audit
42
+ if: branch != master
43
+ install: gem install code_quality --no-ri --no-rdoc
44
+ script:
45
+ - bundle install # to generate Gemfile.lock
46
+ - code_quality security_audit:bundler_audit
47
+ - code_quality quality_audit fail_fast=false generate_index=true lowest_score=80 rubocop_max_offenses=200
48
+
49
+ # automatically release Ruby gem to RubyGems after a successful build with `git push --tags`
50
+ # refs: https://docs.travis-ci.com/user/deployment/rubygems/
51
+ # 1. how to get your api_key: https://rubygems.org/profile/edit
52
+ # 2. intall `travis` cli: $ gem install travis
53
+ # 3. get encrypted api_key secure: $ travis setup rubygems
54
+ deploy:
55
+ - provider: rubygems
56
+ api_key:
57
+ secure: oAeCF8k1NW3a94NXJoQs6kBRJG5TY9zdGJAVgvMxFuEnDVgjmuoKceTLdeQzKin+2PS2KRzGhT5E27wrNvCnQGfjKmQA9kPDqSQeJNnRBkbTjxKwkbi2P4g2EE1wR5PYgKq0mJ/4BMxVWZOleYT+ihwMiZDzoadAglbs5PSlC1HNnaQbnPQ3nfN1iG7o1KXdva5Bw4mcm86QPDrSoR9Fl/7ZJvteVouvC71Qt4QhkcaVV3piDUDM6JRbxa6ydsDOV6zq4nZP7UwufgK1GIpVNiLnVZtL3jCndY84a4MYz5sgBbvSEmSVbF1OdrPgllCV2wnauOtuzTqRYF5ATYyM3Hx58jYLUyd6YwXQrEoirHCyt2XaKSF1r2f9zvllVdXSCj+6/CJ70HkHrJTO3K2C9/uZEYIfNbTFZjMASWKyB52Vch5dFmlTloI/eLF2vp5jjY4iYTInPeb59UzqyBkMT4jtwconbre8eVKW/9qHTdTJDKQqmp4jKD+raeia/FbVaOTKyZ9nWxSQI3mVy49diK2j+Pd1LVw3nXY9zMz5f5W/D/zyGVf/Xt6gRNo0aj8UdMvZJm3awvruwQpJTa2tcp5m/iv74JzsFMdgit1pEbimF6xs7Ph8wVAI7eKVctZtI/zeaw+nv3mcg3+/GNGzSSj0RsjdXetrFSh6eh+qfL0=
58
+ gem: bitcoin-secp256k1
59
+ on:
60
+ tags: true
61
+ repo: cryptape/ruby-bitcoin-secp256k1
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitcoin-secp256k1 (0.4.0)
5
- ffi (>= 1.9.10)
4
+ bitcoin-secp256k1 (0.5.0)
5
+ ffi (>= 1.9.25)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ffi (1.9.10)
11
- minitest (5.8.3)
12
- rake (10.5.0)
13
- yard (0.8.7.6)
10
+ ffi (1.9.25)
11
+ minitest (5.11.3)
12
+ rake (12.3.2)
13
+ yard (0.9.16)
14
14
 
15
15
  PLATFORMS
16
16
  ruby
17
17
 
18
18
  DEPENDENCIES
19
19
  bitcoin-secp256k1!
20
- minitest (= 5.8.3)
21
- rake (~> 10.5)
22
- yard (= 0.8.7.6)
20
+ minitest (= 5.11.3)
21
+ rake (~> 12.3)
22
+ yard (= 0.9.16)
23
23
 
24
24
  BUNDLED WITH
25
- 1.11.2
25
+ 1.17.2
data/README.md CHANGED
@@ -1,16 +1,26 @@
1
1
  # ruby-bitcoin-secp256k1
2
2
 
3
- ## Prerequiste
3
+ ## Prerequisite
4
4
 
5
- In order to use this gem, [libsecp256k1](https://github.com/bitcoin/secp256k1) with recovery module enabled must be in place.
5
+ In order to use this gem, [libsecp256k1](https://github.com/bitcoin/secp256k1) must be in place.
6
6
 
7
- If you have cloned the project and in project root:
7
+ ```
8
+ $ git clone https://github.com/bitcoin-core/secp256k1.git && cd secp256k1
9
+ $ ./autogen.sh
10
+ $ ./configure
11
+ $ make
12
+ $ sudo make install
13
+ ```
14
+
15
+ Or if you have cloned the project, you could go to project root and run this install script:
8
16
 
9
17
  ```
10
18
  git submodule update --init --recursive
11
19
  ./install_lib.sh
12
20
  ```
13
21
 
22
+ The recovery and ecdh modules are optional. If your local installation of secp256k1 doesn't enable them then the gem would throw `LoadModuleError` when related functions are invoked.
23
+
14
24
  ## Install
15
25
 
16
26
  ```
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Secp256k1::VERSION
8
8
  s.authors = ["Jan Xie"]
9
9
  s.email = ["jan.h.xie@gmail.com"]
10
- s.homepage = "https://github.com/janx/ruby-bitcoin-secp256k1"
10
+ s.homepage = "https://github.com/cryptape/ruby-bitcoin-secp256k1"
11
11
  s.summary = "Ruby binding to bitcoin's secp256k1 implementation."
12
12
  s.description = "Ruby binding to bitcoin's secp256k1 implementation."
13
13
  s.license = 'MIT'
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
 
18
- s.add_dependency('ffi', '>= 1.9.10')
18
+ s.add_dependency('ffi', '>= 1.9.25')
19
19
 
20
- s.add_development_dependency('rake', '~> 10.5')
21
- s.add_development_dependency('minitest', '5.8.3')
22
- s.add_development_dependency('yard', '0.8.7.6')
20
+ s.add_development_dependency('rake', '~> 12.3')
21
+ s.add_development_dependency('minitest', '5.11.3')
22
+ s.add_development_dependency('yard', '0.9.16')
23
23
  end
@@ -16,5 +16,6 @@ module Secp256k1
16
16
  ALL_FLAGS = FLAG_SIGN | FLAG_VERIFY
17
17
 
18
18
  class AssertError < StandardError; end
19
+ class LoadModuleError < StandardError; end
19
20
 
20
21
  end
@@ -64,26 +64,44 @@ module Secp256k1
64
64
  # int secp256k1_ecdsa_sign(const secp256k1_context* ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata)
65
65
  attach_function :secp256k1_ecdsa_sign, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int
66
66
 
67
- # int secp256k1_ecdsa_sign_recoverable(const secp256k1_context* ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata)
68
- attach_function :secp256k1_ecdsa_sign_recoverable, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int
69
-
70
- # int secp256k1_ecdsa_recover(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32)
71
- attach_function :secp256k1_ecdsa_recover, [:pointer, :pointer, :pointer, :pointer], :int
72
-
73
67
  # int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey)
74
68
  attach_function :secp256k1_ecdsa_verify, [:pointer, :pointer, :pointer, :pointer], :int
75
69
 
76
70
  # int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin)
77
71
  attach_function :secp256k1_ecdsa_signature_normalize, [:pointer, :pointer, :pointer], :int
78
72
 
79
- # int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig)
80
- attach_function :secp256k1_ecdsa_recoverable_signature_serialize_compact, [:pointer, :pointer, :pointer, :pointer], :int
73
+ # recovery module
74
+ begin
75
+ # int secp256k1_ecdsa_recoverable_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *input64, int recid)
76
+ attach_function :secp256k1_ecdsa_recoverable_signature_parse_compact, [:pointer, :pointer, :pointer, :int], :int
77
+
78
+ # int secp256k1_ecdsa_recoverable_signature_convert(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const secp256k1_ecdsa_recoverable_signature *sigin)
79
+ attach_function :secp256k1_ecdsa_recoverable_signature_convert, [:pointer, :pointer, :pointer], :int
80
+
81
+ # int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig)
82
+ attach_function :secp256k1_ecdsa_recoverable_signature_serialize_compact, [:pointer, :pointer, :pointer, :pointer], :int
83
+
84
+ # int secp256k1_ecdsa_sign_recoverable(const secp256k1_context* ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata)
85
+ attach_function :secp256k1_ecdsa_sign_recoverable, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int
81
86
 
82
- # int secp256k1_ecdsa_recoverable_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *input64, int recid)
83
- attach_function :secp256k1_ecdsa_recoverable_signature_parse_compact, [:pointer, :pointer, :pointer, :int], :int
87
+ # int secp256k1_ecdsa_recover(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32)
88
+ attach_function :secp256k1_ecdsa_recover, [:pointer, :pointer, :pointer, :pointer], :int
89
+ rescue FFI::NotFoundError
90
+ end
84
91
 
85
- # int secp256k1_ecdsa_recoverable_signature_convert(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const secp256k1_ecdsa_recoverable_signature *sigin)
86
- attach_function :secp256k1_ecdsa_recoverable_signature_convert, [:pointer, :pointer, :pointer], :int
92
+ def self.module_recovery_enabled?
93
+ respond_to? :secp256k1_ecdsa_recover
94
+ end
87
95
 
96
+ # ecdh module
97
+ begin
98
+ # int secp256k1_ecdh(const secp256k1_context* ctx, unsigned char *result, const secp256k1_pubkey *point, const unsigned char *scalar)
99
+ attach_function :secp256k1_ecdh, [:pointer, :pointer, :pointer, :pointer], :int
100
+ rescue FFI::NotFoundError
101
+ end
102
+
103
+ def self.module_ecdh_enabled?
104
+ respond_to :secp256k1_ecdh
105
+ end
88
106
  end
89
107
  end
@@ -171,6 +171,8 @@ module Secp256k1
171
171
  end
172
172
 
173
173
  def ecdsa_sign_recoverable(msg, raw: false, digest: Digest::SHA256)
174
+ raise LoadModuleError, "libsecp256k1 recovery module is not enabled" unless C.module_recovery_enabled?
175
+
174
176
  msg32 = hash32 msg, raw, digest
175
177
  raw_sig = C::ECDSARecoverableSignature.new.pointer
176
178
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : ascii-8bit -*-
2
2
  module Secp256k1
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
@@ -61,7 +61,7 @@ class Secp256k1Test < Minitest::Test
61
61
 
62
62
  had_to_normalize, normsig = pk.ecdsa_signature_normalize(raw_sig, check_only: true)
63
63
  assert_equal false, had_to_normalize
64
- assert_equal nil, normsig
64
+ assert_nil normsig
65
65
 
66
66
  sig = "\xAA" + "\xFF"*31 + "\xAA" + "\xFF"*31
67
67
  raw_sig = pk.ecdsa_deserialize_compact sig
@@ -72,10 +72,12 @@ class Secp256k1Test < Minitest::Test
72
72
 
73
73
  normalized, normsig = pk.ecdsa_signature_normalize raw_sig, check_only: true
74
74
  assert_equal true, normalized
75
- assert_equal nil, normsig
75
+ assert_nil normsig
76
76
  end
77
77
 
78
78
  def test_ecdsa_recover
79
+ return unless C.module_recovery_enabled?
80
+
79
81
  pk = PrivateKey.new
80
82
  unrelated = MyECDSA.new
81
83
 
@@ -85,7 +87,7 @@ class Secp256k1Test < Minitest::Test
85
87
  assert_equal pubser, pk.pubkey.serialize
86
88
 
87
89
  recsig_ser = unrelated.ecdsa_recoverable_serialize recsig
88
- recsig2 = unrelated.ecdsa_recoverable_deserialize *recsig_ser
90
+ recsig2 = unrelated.ecdsa_recoverable_deserialize(*recsig_ser)
89
91
  pubkey2 = unrelated.ecdsa_recover 'hello', recsig2
90
92
  pubser2 = PublicKey.new(pubkey: pubkey2).serialize
91
93
  assert_equal pubser, pubser2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin-secp256k1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Xie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.10
19
+ version: 1.9.25
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.9.10
26
+ version: 1.9.25
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.5'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.5'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 5.8.3
47
+ version: 5.11.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 5.8.3
54
+ version: 5.11.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.7.6
61
+ version: 0.9.16
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.7.6
68
+ version: 0.9.16
69
69
  description: Ruby binding to bitcoin's secp256k1 implementation.
70
70
  email:
71
71
  - jan.h.xie@gmail.com
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".gitmodules"
78
+ - ".travis.yml"
78
79
  - Gemfile
79
80
  - Gemfile.lock
80
81
  - LICENSE
@@ -91,7 +92,7 @@ files:
91
92
  - test/fixtures/ecdsa_sig.json
92
93
  - test/fixtures/pubkey.json
93
94
  - test/secp256k1_test.rb
94
- homepage: https://github.com/janx/ruby-bitcoin-secp256k1
95
+ homepage: https://github.com/cryptape/ruby-bitcoin-secp256k1
95
96
  licenses:
96
97
  - MIT
97
98
  metadata: {}
@@ -111,12 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.4.5.1
115
+ rubygems_version: 2.7.7
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Ruby binding to bitcoin's secp256k1 implementation.
118
- test_files:
119
- - test/fixtures/ecdsa_sig.json
120
- - test/fixtures/pubkey.json
121
- - test/secp256k1_test.rb
122
- has_rdoc:
119
+ test_files: []