rbsecp256k1 2.0.0 → 3.0.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
2
  SHA256:
3
- metadata.gz: 5549a7ec71d1bddbefe1ea360d9316ea1bbe74f015e6676cfc7495a7b852831a
4
- data.tar.gz: dada9673b8fdf01e29ca2a2479ac3ce92ff43ba736f577feb6e58515ae3ab240
3
+ metadata.gz: adc488ad0d13cd01f56ce39b7c323ea57d9226b9380d747ebb8ef0c4cc62d6d1
4
+ data.tar.gz: 3118c92e72f09ff255483f7c90665236b9b060a881eb4c7d54b9d3a2791df747
5
5
  SHA512:
6
- metadata.gz: 9ac13a464fd1e0c5ee4378cea9f6b9c557d65b08e00a00f4dc94b64fc43822cec9c5e69463a450daa6725d12679a5e9440bb0e60a20f282346551099b64e2802
7
- data.tar.gz: 58f2932b693056f4051094d43d68636c2a3d99c71d475c5c1e7ca9c062a4e5d956e844209956e7e4041351677e4c4b376bd4b4a0e9dbdc13dab7e52c099302d0
6
+ metadata.gz: 5863c53473f0a162fffc82e319ab255b3e234acd0d425637783177e4c47e38768992b9d712f8957369e2ed53241eee377c31510e486d887e2cb6e9b12bb667b2
7
+ data.tar.gz: 046edbc96b3864969015ea02b2016fb167ae0c93172621801d7788ea484d3418a5868a8396aea57b4fbd21298157aa5a383b990dce00f2cceff68dd9f12106f0
@@ -1,14 +1,107 @@
1
+ require 'mini_portile2'
1
2
  require 'mkmf'
3
+ require 'zip'
4
+
5
+ # Recipe for downloading and building libsecp256k1 as part of installation
6
+ class Secp256k1Recipe < MiniPortile
7
+ # Hard-coded URL for libsecp256k1 zipfile (HEAD of master as of 26-11-2018)
8
+ LIBSECP256K1_ZIP_URL = 'https://github.com/bitcoin-core/secp256k1/archive/e34ceb333b1c0e6f4115ecbb80c632ac1042fa49.zip'.freeze
9
+
10
+ # Expected SHA-256 of the zipfile above (computed using sha256sum)
11
+ LIBSECP256K1_SHA256 = 'd87d3ca7ebc42edbabb0f38e79205040b24b09b3e6d1c9ac89585de9bf302143'.freeze
12
+
13
+ WITH_RECOVERY = ENV.fetch('WITH_RECOVERY', '1') == '1'
14
+ WITH_ECDH = ENV.fetch('WITH_ECDH', '1') == '1'
15
+
16
+ def initialize
17
+ super('libsecp256k1', '0.0.0')
18
+ @tarball = File.join(Dir.pwd, "/ports/archives/libsecp256k1.zip")
19
+ @files = ["file://#{@tarball}"]
20
+ self.configure_options += [
21
+ "--disable-benchmark",
22
+ "--disable-exhaustive-tests",
23
+ "--disable-tests",
24
+ "--disable-debug",
25
+ "--enable-experimental",
26
+ "--with-pic=yes"
27
+ ]
28
+
29
+ configure_options << "--enable-module-recovery" if WITH_RECOVERY
30
+ configure_options << "--enable-module-ecdh" if WITH_ECDH
31
+ end
32
+
33
+ def configure
34
+ # Need to run autogen.sh before configure since it creates it
35
+ if RUBY_PLATFORM =~ /mingw|mswin/
36
+ # Windows doesn't recognize the shebang.
37
+ execute('autogen', %w[sh ./autogen.sh])
38
+ else
39
+ execute('autogen', %w[./autogen.sh])
40
+ end
41
+
42
+ super
43
+ end
44
+
45
+ def download
46
+ download_file_http(LIBSECP256K1_ZIP_URL, @tarball)
47
+ verify_file(local_path: @tarball, sha256: LIBSECP256K1_SHA256)
48
+ end
49
+
50
+ def downloaded?
51
+ File.exist?(@tarball)
52
+ end
53
+
54
+ def extract_zip_file(file, destination)
55
+ FileUtils.mkdir_p(destination)
56
+
57
+ Zip::File.open(file) do |zip_file|
58
+ zip_file.each do |f|
59
+ fpath = File.join(destination, f.name)
60
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
61
+ end
62
+ end
63
+ end
64
+
65
+ def extract
66
+ files_hashs.each do |file|
67
+ extract_zip_file(file[:local_path], tmp_path)
68
+ end
69
+ end
70
+ end
2
71
 
3
72
  # OpenSSL flags
4
73
  print("checking for OpenSSL\n")
5
74
  results = pkg_config('openssl')
6
- abort "missing openssl pkg-config information" unless results[1]
75
+ abort "missing openssl pkg-config information" unless results && results[1]
76
+
77
+ if with_config('system-library')
78
+ # Require that libsecp256k1 be installed using `make install` or similar.
79
+ print("checking for libsecp256k1\n")
80
+ results = pkg_config('libsecp256k1')
81
+ abort "missing libsecp256k1" unless results && results[1]
82
+ else
83
+ # Build the libsecp256k1 dependency
84
+ recipe = Secp256k1Recipe.new
85
+ recipe.cook
86
+ recipe.activate
87
+
88
+ # Need to add paths to includes and libraries for library for build
89
+ append_cflags(
90
+ [
91
+ "-I#{recipe.path}/include",
92
+ "-fPIC",
93
+ "-Wno-undef",
94
+ "-Wall"
95
+ ]
96
+ )
97
+ # rubocop:disable Style/GlobalVars
98
+ $LIBPATH = ["#{recipe.path}/lib"] | $LIBPATH
99
+ # rubocop:enable Style/GlobalVars
7
100
 
8
- # Require that libsecp256k1 be installed using `make install` or similar.
9
- print("checking for libsecp256k1\n")
10
- results = pkg_config('libsecp256k1')
11
- abort "missing libsecp256k1" unless results[1]
101
+ # Also need to make sure we add the library as part of the build
102
+ have_library("secp256k1")
103
+ have_library("gmp")
104
+ end
12
105
 
13
106
  # Check if we have the libsecp256k1 recoverable signature header.
14
107
  have_header('secp256k1_recovery.h')
@@ -277,7 +277,7 @@ typedef enum ResultT_dummy {
277
277
  * RESULT_FAILURE otherwise.
278
278
  */
279
279
  static ResultT
280
- GenerateRandomBytes(unsigned char *out_bytes, size_t in_size)
280
+ GenerateRandomBytes(unsigned char *out_bytes, int in_size)
281
281
  {
282
282
  // OpenSSL RNG has not been seeded with enough data and is therefore
283
283
  // not usable.
@@ -1110,7 +1110,7 @@ Context_public_key_from_data(VALUE self, VALUE in_public_key_data)
1110
1110
  return PublicKey_create_from_data(
1111
1111
  context,
1112
1112
  public_key_data,
1113
- RSTRING_LEN(in_public_key_data)
1113
+ (int)RSTRING_LEN(in_public_key_data)
1114
1114
  );
1115
1115
  }
1116
1116
 
@@ -1156,6 +1156,8 @@ Context_key_pair_from_private_key(VALUE self, VALUE in_private_key_data)
1156
1156
  VALUE private_key;
1157
1157
  unsigned char *private_key_data;
1158
1158
 
1159
+ Check_Type(in_private_key_data, T_STRING);
1160
+
1159
1161
  if (RSTRING_LEN(in_private_key_data) != 32)
1160
1162
  {
1161
1163
  rb_raise(rb_eArgError, "private key data must be 32 bytes in length");
@@ -1229,6 +1231,13 @@ Context_signature_from_compact(VALUE self, VALUE in_compact_signature)
1229
1231
  VALUE signature_result;
1230
1232
  unsigned char *signature_data;
1231
1233
 
1234
+ Check_Type(in_compact_signature, T_STRING);
1235
+
1236
+ if (RSTRING_LEN(in_compact_signature) != 64)
1237
+ {
1238
+ rb_raise(rb_eArgError, "compact signature must be 64 bytes");
1239
+ }
1240
+
1232
1241
  TypedData_Get_Struct(self, Context, &Context_DataType, context);
1233
1242
  signature_data = (unsigned char*)StringValuePtr(in_compact_signature);
1234
1243
 
@@ -1393,10 +1402,11 @@ Context_sign_recoverable(VALUE self, VALUE in_private_key, VALUE in_hash32)
1393
1402
  *
1394
1403
  * @param in_compact_sig [String] binary string containing compact signature
1395
1404
  * data.
1396
- * @param in_recovery_id [Integer] recovery ID.
1405
+ * @param in_recovery_id [Integer] recovery ID (range [0, 3])
1397
1406
  * @return [Secp256k1::RecoverableSignature] signature parsed from data.
1398
1407
  * @raise [RuntimeError] if signature data or recovery ID is invalid.
1399
- * @raise [ArgumentError] if compact signature is not 64 bytes.
1408
+ * @raise [ArgumentError] if compact signature is not 64 bytes or recovery ID
1409
+ * is not in range [0, 3].
1400
1410
  */
1401
1411
  static VALUE
1402
1412
  Context_recoverable_signature_from_compact(
@@ -1420,6 +1430,11 @@ Context_recoverable_signature_from_compact(
1420
1430
  rb_raise(rb_eArgError, "compact signature is not 64 bytes");
1421
1431
  }
1422
1432
 
1433
+ if (recovery_id < 0 || recovery_id > 3)
1434
+ {
1435
+ rb_raise(rb_eArgError, "invalid recovery ID, must be in range [0, 3]");
1436
+ }
1437
+
1423
1438
  result = RecoverableSignature_alloc(Secp256k1_RecoverableSignature_class);
1424
1439
  TypedData_Get_Struct(
1425
1440
  result,
@@ -1,3 +1,3 @@
1
1
  module Secp256k1
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbsecp256k1
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Scrivner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-01 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_portile2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rake
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -117,5 +145,6 @@ rubyforge_project:
117
145
  rubygems_version: 2.7.6
118
146
  signing_key:
119
147
  specification_version: 4
120
- summary: Compiled, native ruby extension interfaces to libsecp256k1
148
+ summary: Compiled, native ruby extension interfaces to libsecp256k1. In rbsecp256k1
149
+ 3.0.0 and later libsecp256k1 is bundled with the gem.
121
150
  test_files: []