rbsecp256k1 6.0.1 → 6.0.2

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.
@@ -1,121 +1,62 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mini_portile2'
4
- require 'mkmf'
5
- require 'zip'
6
-
7
- # Enable the recovery module by default
8
- WITH_RECOVERY = ENV.fetch('WITH_RECOVERY', '1') == '1'
9
-
10
- # Recipe for downloading and building libsecp256k1 as part of installation
11
- class Secp256k1Recipe < MiniPortile
12
- # Hard-coded URL for libsecp256k1 zipfile (Official release v0.2.0)
13
- LIBSECP256K1_ZIP_URL = 'https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.2.0.zip'
14
-
15
- # Expected SHA-256 of the zipfile above (computed using sha256sum)
16
- LIBSECP256K1_SHA256 = '6ece280c0e6ea9d861051077c28a25b7f48800c43a4098a800b7d3b0c124e406'
17
-
18
- def initialize
19
- super('libsecp256k1', '0.2.0')
20
- @tarball = File.join(Dir.pwd, "/ports/archives/libsecp256k1.zip")
21
- @files = ["file://#{@tarball}"]
22
- self.configure_options += [
23
- "--with-pic=yes"
24
- ]
25
-
26
- # ECDH is enabled by default in release v0.2.0, but recovery still needs to
27
- # be enabled manually.
28
- configure_options << "--enable-module-recovery" if WITH_RECOVERY
29
- end
30
-
31
- def configure
32
- # Need to run autogen.sh before configure since it creates it
33
- if RUBY_PLATFORM =~ /mingw|mswin/
34
- # Windows doesn't recognize the shebang.
35
- execute('autogen', %w[sh ./autogen.sh])
36
- else
37
- execute('chmod', %w[chmod +x ./autogen.sh])
38
- execute('autogen', %w[./autogen.sh])
39
- end
40
-
41
- super
42
- end
43
-
44
- def download
45
- download_file_http(LIBSECP256K1_ZIP_URL, @tarball)
46
- verify_file(local_path: @tarball, sha256: LIBSECP256K1_SHA256)
47
- end
48
-
49
- def downloaded?
50
- File.exist?(@tarball)
51
- end
52
-
53
- def extract_zip_file(file, destination)
54
- FileUtils.mkdir_p(destination)
55
-
56
- Zip::File.open(file) do |zip_file|
57
- zip_file.each do |f|
58
- fpath = File.join(destination, f.name)
59
- zip_file.extract(f, fpath) unless File.exist?(fpath)
60
- end
61
- end
62
- end
63
-
64
- def extract
65
- files_hashs.each do |file|
66
- extract_zip_file(file[:local_path], tmp_path)
67
- end
68
- end
69
- end
70
-
71
- if with_config('system-library')
72
- # Require that libsecp256k1 be installed using `make install` or similar.
73
- message("checking for libsecp256k1\n")
74
- results = pkg_config('libsecp256k1')
75
- abort "missing libsecp256k1" unless results && results[1]
76
- else
77
- # Build the libsecp256k1 dependency
78
- recipe = Secp256k1Recipe.new
79
- recipe.cook
80
- recipe.activate
81
-
82
- # Need to add paths to includes and libraries for library for build
83
- append_cflags(
84
- [
85
- "-I#{recipe.path}/include",
86
- "-fPIC",
87
- "-Wno-undef",
88
- "-Wall"
89
- ]
90
- )
91
- append_ldflags(
92
- [
93
- "-Wl,--no-as-needed"
94
- ]
95
- )
96
- # rubocop:disable Style/GlobalVars
97
- $LIBPATH = ["#{recipe.path}/lib"] | $LIBPATH
98
- # rubocop:enable Style/GlobalVars
99
-
100
- # Also need to make sure we add the library as part of the build
101
- have_library("secp256k1")
102
- have_library("gmp")
103
- end
104
-
105
- # Sanity check for the basic library
106
- have_header('secp256k1.h')
107
-
108
- # Check if we have the libsecp256k1 recoverable signature header.
109
- have_header('secp256k1_recovery.h') if WITH_RECOVERY
110
-
111
- # Check if we have EC Diffie-Hellman functionality
112
- have_header('secp256k1_ecdh.h')
113
-
114
- # Check if we have Schnorr signatures
115
- have_header('secp256k1_schnorrsig.h')
116
-
117
- # Check if we have extra keys module
118
- have_header('secp256k1_extrakeys.h')
119
-
120
- # See: https://guides.rubygems.org/gems-with-extensions/
121
- create_makefile('rbsecp256k1/rbsecp256k1')
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ require_relative 'secp256k1_recipe'
5
+
6
+ if with_config('system-library')
7
+ # Require that libsecp256k1 be installed using `make install` or similar.
8
+ message("checking for libsecp256k1\n")
9
+ results = pkg_config('libsecp256k1')
10
+ abort "missing libsecp256k1" unless results && results[1]
11
+ else
12
+ # Build the libsecp256k1 dependency
13
+ recipe = Secp256k1Recipe.new
14
+ recipe.cook
15
+ recipe.activate
16
+
17
+ # Need to add paths to includes and libraries for library for build
18
+ append_cflags(
19
+ [
20
+ "-I#{recipe.path}/include",
21
+ "-fPIC",
22
+ "-Wno-undef",
23
+ "-Wall"
24
+ ]
25
+ )
26
+ # Since libsecp256k1 v0.4.0, consumers of the static library on Windows must
27
+ # define SECP256K1_STATIC before including secp256k1.h.
28
+ append_cflags("-DSECP256K1_STATIC") if RUBY_PLATFORM =~ /mingw|mswin/
29
+ append_ldflags(
30
+ [
31
+ "-Wl,--no-as-needed"
32
+ ]
33
+ )
34
+ # rubocop:disable Style/GlobalVars
35
+ $LIBPATH = ["#{recipe.path}/lib"] | $LIBPATH
36
+ # rubocop:enable Style/GlobalVars
37
+
38
+ # Also need to make sure we add the library as part of the build
39
+ have_library("secp256k1")
40
+ have_library("gmp")
41
+ end
42
+
43
+ # Reject ABI-incompatible pointer arguments when the compiler supports it.
44
+ append_cflags('-Werror=incompatible-pointer-types')
45
+
46
+ # Sanity check for the basic library
47
+ have_header('secp256k1.h')
48
+
49
+ # Check if we have the libsecp256k1 recoverable signature header.
50
+ have_header('secp256k1_recovery.h') if WITH_RECOVERY
51
+
52
+ # Check if we have EC Diffie-Hellman functionality
53
+ have_header('secp256k1_ecdh.h')
54
+
55
+ # Check if we have Schnorr signatures
56
+ have_header('secp256k1_schnorrsig.h')
57
+
58
+ # Check if we have extra keys module
59
+ have_header('secp256k1_extrakeys.h')
60
+
61
+ # See: https://guides.rubygems.org/gems-with-extensions/
62
+ create_makefile('rbsecp256k1/rbsecp256k1')