rbsecp256k1 6.0.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbd0a847d061c266d044174528f14b1351484f58a703e7ec76719122689ae6d4
4
- data.tar.gz: c7bbdaf0dc9bdaf24dd5de7c40d95c16f08b72d466216af6789e523ee14bba8b
3
+ metadata.gz: 713b484c223a4c3fec618c6d8050c964657a26ff73d9f4022a87b26b6009812b
4
+ data.tar.gz: c87b25bee566a967d8d3f9f28b5f99a4841942bb46ee062fbf9734e8082b02dc
5
5
  SHA512:
6
- metadata.gz: cf695d750f38e4d27de61caa0e1ec8d9160925d7c10cc556691c7335478137f71f7f49901d50ade3c9e2c917779b38a3d4ee49ca931a8691cc99e7a751fd8243
7
- data.tar.gz: 7b5a75562a90c3e845a0b42477873562991d19ca610b89aef95581e0f7dc010f123e8ed4055225978cb2ad4b6667e184d18915114f69cfdaabb993bfcf4b06a7
6
+ metadata.gz: ad34fd4905564c2afd5694966ff783a05e851048530c255996f496db35f5ef109558609a2a28d944b9a7c6a9b4c3a9d4cc0d95b4e5be63473bfc4d489913fae3
7
+ data.tar.gz: a8b5a50de652d42050f42d38a3dbc87b7c2a923747d9cedd1b2c5651fbf995131b1a43cd0fb9253bfed304eb6e3215ca80dc73906a053f080c391a36e7542c2c
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
data/README.md CHANGED
@@ -84,6 +84,11 @@ the following command to set up your local environment:
84
84
  make setup
85
85
  ```
86
86
 
87
+ ### Line Endings
88
+
89
+ .gitattributes keeps text files in Unix LF format across Windows, Linux, and
90
+ macOS. Git detects binary files automatically and leaves their contents unchanged.
91
+
87
92
  ### Compiling Extension
88
93
 
89
94
  To compile the extension gem run the following (this is required to run tests):
data/Rakefile CHANGED
@@ -4,8 +4,13 @@ require "rake/extensiontask"
4
4
  require "ruby_memcheck"
5
5
  require "rspec/core/rake_task"
6
6
  require 'ruby_memcheck/rspec/rake_task'
7
+ require 'shellwords'
7
8
 
8
- RubyMemcheck.config(binary_name: "rbsecp256k1")
9
+ memcheck_options = RubyMemcheck::Configuration::DEFAULT_VALGRIND_OPTIONS.dup
10
+ if ENV['MEMCHECK_DEBUGINFO_PATH']
11
+ memcheck_options << "--extra-debuginfo-path=#{Shellwords.escape(File.expand_path(ENV['MEMCHECK_DEBUGINFO_PATH']))}"
12
+ end
13
+ RubyMemcheck.config(binary_name: "rbsecp256k1", valgrind_options: memcheck_options)
9
14
 
10
15
  # See: https://guides.rubygems.org/gems-with-extensions/
11
16
  Rake::ExtensionTask.new "rbsecp256k1" do |ext|
@@ -18,6 +18,18 @@ initialization if given `context_randomization_bytes`. The
18
18
  32 bytes of random data, if not provided then the Context is not randomized and
19
19
  may be vulnerable to side-channel attacks.
20
20
 
21
+ `dup` and `clone` create independently owned native contexts using
22
+ `secp256k1_context_clone`. The original and copy can be used and collected
23
+ independently. Copying preserves the source context state; it does not provide
24
+ fresh randomization. Use `Context.create` for a newly randomized context.
25
+ Normal Ruby copy behavior applies: `clone` preserves frozen state, while `dup`
26
+ returns an unfrozen copy. Copying an uninitialized context raises
27
+ `Secp256k1::Error`.
28
+
29
+ Native operations on an allocated context that has not completed initialization raise
30
+ `Secp256k1::Error`. Reinitializing an existing context also raises
31
+ `Secp256k1::Error` and leaves the existing context usable.
32
+
21
33
  Class Methods
22
34
  -------------
23
35
 
@@ -75,16 +87,31 @@ new [RecoverableSignature](recoverable_signature.md). The `private_key` is expec
75
87
 
76
88
  #### sign_schnorr(keypair, message)
77
89
 
90
+ Signs a Ruby `String` containing any number of bytes, including zero bytes.
91
+
78
92
  Same as `sign_schnorr_custom(keypair, message, auxrand)` but generates
79
93
  `auxrand` for you using `SecureRandom`. This should almost always be the method
80
94
  used for Schnorr signing.
81
95
 
82
96
  #### sign_schnorr_custom(keypair, message, auxrand)
83
97
 
84
- Sign the given 32-byte binary string `message` using the given `keypair`. It is
85
- recommend that `message` be generated using `tagged_sha256`. `auxrand` should
86
- be 32-bytes of fresh randomness, but can optionally be `nil` if generating
87
- randomness is expensive.
98
+ Signs the bytes of the Ruby `String` `message` using the given [KeyPair](key_pair.md)
99
+ and returns a [SchnorrSignature](schnorr_signature.md). Messages may have any byte
100
+ length, including zero, and may contain null bytes. String encoding does not
101
+ change the bytes being signed.
102
+
103
+ The message is signed directly, without implicit hashing, padding, or truncation.
104
+ If your protocol requires a tagged hash for domain separation, compute it
105
+ explicitly with `tagged_sha256` before signing. Verification must use the same
106
+ message bytes.
107
+
108
+ `auxrand` must be a `String` containing exactly 32 bytes of fresh randomness,
109
+ or `nil`. With `nil`, the default BIP-340 nonce function treats auxiliary
110
+ randomness as 32 zero bytes. Prefer `sign_schnorr`, which generates fresh
111
+ randomness automatically.
112
+
113
+ Non-string messages or non-string, non-`nil` randomness raise `TypeError`.
114
+ Randomness strings with a byte length other than 32 raise `Secp256k1::Error`.
88
115
 
89
116
  #### tagged_sha256(tag, message)
90
117
 
@@ -43,7 +43,7 @@ of a piece of data.
43
43
  **[RecoverableSignature](recoverable_signature.md)** is a recoverable ECDSA signature of the SHA-256 message
44
44
  hash of a piece of data.
45
45
 
46
- **[SchnorrSignature](schnorr_signature.md)** is a Schnorr signature of a 32-byte message.
46
+ **[SchnorrSignature](schnorr_signature.md)** is a 64-byte Schnorr signature of a message of any byte length.
47
47
 
48
48
  Examples
49
49
  --------
@@ -245,6 +245,19 @@ schnorr_sig.serialized
245
245
  => "\x16\xEF\x04\xB0JP\xE9\x90\xC2\xB1\xE6-l\xDB\x1D\xAE\xAAc\xBF@9s\x02\xC2\xD5[\xFB\x19Q\xFAI^Hj\xD1)\xBE\xEA\xA5!a\xAD\xBEO\xCE7\x9Em\x13;\xE8R\x8A\x81$\nv\xF4\xD3\xB25\xA9\xF9\xC0"
246
246
  ```
247
247
 
248
+ Messages can also be signed directly, including empty strings. No implicit
249
+ hashing, padding, or truncation is performed; use the same bytes for verification.
250
+ The tagged hash above is an explicit application choice.
251
+
252
+ ```ruby
253
+ message = 'a message of any byte length'.b
254
+ signature = context.sign_schnorr(key_pair, message)
255
+ signature.verify(message, key_pair.xonly_public_key)
256
+ # => true
257
+ signature.serialized.bytesize
258
+ # => 64
259
+ ```
260
+
248
261
  ### 4. Load a Schnorr signature from binary serialized version
249
262
 
250
263
  ```ruby
File without changes
File without changes
File without changes
File without changes
@@ -3,7 +3,8 @@
3
3
  Secp256k1::SchnorrSignature
4
4
  ===========================
5
5
 
6
- Secp256k1::SchnorrSignature represents an Schnorr signature signing a 32-byte message.
6
+ Secp256k1::SchnorrSignature represents a 64-byte Schnorr signature of a message
7
+ of any byte length, including zero.
7
8
 
8
9
  Class Methods
9
10
  -------------
@@ -25,6 +26,9 @@ Returns the 64-byte binary `String` of the serialized Schnorr signature.
25
26
  Returns `true` if the schnorr signature is a valid signing of `msg` with the
26
27
  private key for `xonly_pubkey`, `false` otherwise.
27
28
 
29
+ `msg` must be a Ruby `String` containing the exact bytes passed to signing.
30
+ It may have any byte length, including zero. No implicit hashing is performed.
31
+
28
32
  #### ==(other)
29
33
 
30
34
  Returns `true` if this signature matches `other`.
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,72 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mini_portile2'
4
3
  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
4
+ require_relative 'secp256k1_recipe'
70
5
 
71
6
  if with_config('system-library')
72
7
  # Require that libsecp256k1 be installed using `make install` or similar.
@@ -88,6 +23,9 @@ else
88
23
  "-Wall"
89
24
  ]
90
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/
91
29
  append_ldflags(
92
30
  [
93
31
  "-Wl,--no-as-needed"
@@ -102,6 +40,9 @@ else
102
40
  have_library("gmp")
103
41
  end
104
42
 
43
+ # Reject ABI-incompatible pointer arguments when the compiler supports it.
44
+ append_cflags('-Werror=incompatible-pointer-types')
45
+
105
46
  # Sanity check for the basic library
106
47
  have_header('secp256k1.h')
107
48