Skip to content

Commit dd71c5e

Browse files
authored
Merge pull request #1 from raggi/master
Update from Bitcoin-ruby repo
2 parents f9b817c + ee22140 commit dd71c5e

File tree

9 files changed

+125
-96
lines changed

9 files changed

+125
-96
lines changed

.github/workflows/ruby.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7+
8+
name: Ruby
9+
10+
on:
11+
push:
12+
branches: [ master ]
13+
pull_request:
14+
branches: [ master ]
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
22+
matrix:
23+
os: [ubuntu-latest, macos-latest, ubuntu-18.04, macos-10.15]
24+
ruby-version: ['2.6', '2.7', '3.0']
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Set up Ruby
29+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
30+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
31+
# uses: ruby/setup-ruby@v1
32+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
33+
with:
34+
ruby-version: ${{ matrix.ruby-version }}
35+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
36+
- name: Brew automake
37+
run: brew install automake
38+
if: startsWith(matrix.os, 'macOS')
39+
- name: Build secp256k1
40+
run: bundle exec rake build_libsecp256k1
41+
- name: Run tests
42+
run: bundle exec rake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
secp256k1.so
12
*.gem
23
.bundle
34
pkg/*

Gemfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ source "https://rubygems.org"
33
gemspec
44

55
group :test do
6-
gem 'rake', '~> 12.3.1'
7-
gem 'bacon', '~> 1.2.0'
8-
gem 'rspec', '~> 3.7.0'
9-
gem 'rubocop', '~> 0.58.2'
10-
gem 'simplecov', '~> 0.16.1'
11-
gem 'minitest', '~> 5.11.3'
6+
gem 'rake'
7+
gem 'bacon'
8+
gem 'rspec'
9+
gem 'rubocop'
10+
gem 'simplecov'
11+
gem 'minitest'
12+
gem 'scanf'
1213
end
1314

1415
group :development do
15-
gem 'pry', '~> 0.11.3'
16-
gem 'pry-byebug', '~> 3.6.0'
16+
gem 'pry'
17+
gem 'pry-byebug'
1718
end

Gemfile.lock

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,82 @@ PATH
99
GEM
1010
remote: https://rubygems.org/
1111
specs:
12-
ast (2.4.0)
12+
ast (2.4.2)
1313
bacon (1.2.0)
14-
byebug (10.0.2)
15-
coderay (1.1.2)
16-
diff-lcs (1.3)
17-
docile (1.3.1)
14+
byebug (11.1.3)
15+
coderay (1.1.3)
16+
diff-lcs (1.4.4)
17+
docile (1.4.0)
1818
eventmachine (1.2.7)
19-
ffi (1.9.25)
19+
ffi (1.15.1)
2020
ffi-compiler (1.0.1)
2121
ffi (>= 1.0.0)
2222
rake
23-
jaro_winkler (1.5.1)
24-
json (2.1.0)
25-
method_source (0.9.0)
26-
minitest (5.11.3)
27-
parallel (1.12.1)
28-
parser (2.5.1.2)
29-
ast (~> 2.4.0)
30-
powerpack (0.1.2)
31-
pry (0.11.3)
32-
coderay (~> 1.1.0)
33-
method_source (~> 0.9.0)
34-
pry-byebug (3.6.0)
35-
byebug (~> 10.0)
36-
pry (~> 0.10)
23+
method_source (1.0.0)
24+
minitest (5.14.4)
25+
parallel (1.20.1)
26+
parser (3.0.1.1)
27+
ast (~> 2.4.1)
28+
pry (0.13.1)
29+
coderay (~> 1.1)
30+
method_source (~> 1.0)
31+
pry-byebug (3.9.0)
32+
byebug (~> 11.0)
33+
pry (~> 0.13.0)
3734
rainbow (3.0.0)
38-
rake (12.3.1)
39-
rspec (3.7.0)
40-
rspec-core (~> 3.7.0)
41-
rspec-expectations (~> 3.7.0)
42-
rspec-mocks (~> 3.7.0)
43-
rspec-core (3.7.1)
44-
rspec-support (~> 3.7.0)
45-
rspec-expectations (3.7.0)
35+
rake (13.0.3)
36+
regexp_parser (2.1.1)
37+
rexml (3.2.5)
38+
rspec (3.10.0)
39+
rspec-core (~> 3.10.0)
40+
rspec-expectations (~> 3.10.0)
41+
rspec-mocks (~> 3.10.0)
42+
rspec-core (3.10.1)
43+
rspec-support (~> 3.10.0)
44+
rspec-expectations (3.10.1)
4645
diff-lcs (>= 1.2.0, < 2.0)
47-
rspec-support (~> 3.7.0)
48-
rspec-mocks (3.7.0)
46+
rspec-support (~> 3.10.0)
47+
rspec-mocks (3.10.2)
4948
diff-lcs (>= 1.2.0, < 2.0)
50-
rspec-support (~> 3.7.0)
51-
rspec-support (3.7.1)
52-
rubocop (0.58.2)
53-
jaro_winkler (~> 1.5.1)
49+
rspec-support (~> 3.10.0)
50+
rspec-support (3.10.2)
51+
rubocop (1.15.0)
5452
parallel (~> 1.10)
55-
parser (>= 2.5, != 2.5.1.1)
56-
powerpack (~> 0.1)
53+
parser (>= 3.0.0.0)
5754
rainbow (>= 2.2.2, < 4.0)
55+
regexp_parser (>= 1.8, < 3.0)
56+
rexml
57+
rubocop-ast (>= 1.5.0, < 2.0)
5858
ruby-progressbar (~> 1.7)
59-
unicode-display_width (~> 1.0, >= 1.0.1)
60-
ruby-progressbar (1.9.0)
61-
scrypt (3.0.5)
59+
unicode-display_width (>= 1.4.0, < 3.0)
60+
rubocop-ast (1.7.0)
61+
parser (>= 3.0.1.1)
62+
ruby-progressbar (1.11.0)
63+
scanf (1.0.0)
64+
scrypt (3.0.7)
6265
ffi-compiler (>= 1.0, < 2.0)
63-
simplecov (0.16.1)
66+
simplecov (0.21.2)
6467
docile (~> 1.1)
65-
json (>= 1.8, < 3)
66-
simplecov-html (~> 0.10.0)
67-
simplecov-html (0.10.2)
68-
unicode-display_width (1.4.0)
68+
simplecov-html (~> 0.11)
69+
simplecov_json_formatter (~> 0.1)
70+
simplecov-html (0.12.3)
71+
simplecov_json_formatter (0.1.3)
72+
unicode-display_width (2.0.0)
6973

7074
PLATFORMS
7175
ruby
7276

7377
DEPENDENCIES
74-
bacon (~> 1.2.0)
78+
bacon
7579
bitcoin-ruby!
76-
minitest (~> 5.11.3)
77-
pry (~> 0.11.3)
78-
pry-byebug (~> 3.6.0)
79-
rake (~> 12.3.1)
80-
rspec (~> 3.7.0)
81-
rubocop (~> 0.58.2)
82-
simplecov (~> 0.16.1)
80+
minitest
81+
pry
82+
pry-byebug
83+
rake
84+
rspec
85+
rubocop
86+
scanf
87+
simplecov
8388

8489
BUNDLED WITH
85-
1.17.3
90+
2.2.19

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
22
require 'rspec/core/rake_task'
33

44
# libsecp256k1 repository URL
5-
LIBSECP256K1_REPO = 'https://github.com/bitcoin-core/secp256k1/'.freeze
5+
LIBSECP256K1_REPO = 'https://github.com/bitcoin-core/secp256k1.git'.freeze
66
# Folder into which libsecp256k1 repository is cloned
77
LIBSECP256K1_PATH = 'secp256k1'.freeze
88

@@ -34,8 +34,8 @@ end
3434

3535
desc 'Compiles the libsecp256k1 library'
3636
task :build_libsecp256k1, [:force] do |_, args|
37-
# Commit hash for libsecp256k1 from May 31, 2018.
38-
COMMIT_HASH = '1e6f1f5ad5e7f1e3ef79313ec02023902bf8175c'.freeze
37+
# Commit hash for libsecp256k1 from March 31, 2021.
38+
COMMIT_HASH = '50f33677122fed79dedb05e8046b2fea93496201'.freeze
3939

4040
force = args[:force]
4141

lib/bitcoin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def litecoin_hash(hex)
325325
bytes = [hex].pack("H*").reverse
326326
begin
327327
require "scrypt" unless defined?(::SCrypt)
328-
hash = SCrypt::Engine.__sc_crypt(bytes, bytes, 1024, 1, 1, 32)
328+
hash = SCrypt::Engine.scrypt(bytes, bytes, 1024, 1, 1, 32)
329329
rescue LoadError
330330
hash = Litecoin::Scrypt.scrypt_1024_1_1_256_sp(bytes)
331331
end

lib/bitcoin/ffi/openssl.rb

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
# encoding: ascii-8bit
22

3+
require 'openssl'
34
require 'ffi'
45

56
module Bitcoin
67
# autoload when you need to re-generate a public_key from only its private_key.
78
# ported from: https://github.com/sipa/bitcoin/blob/2d40fe4da9ea82af4b652b691a4185431d6e47a8/key.h
89
module OpenSSL_EC # rubocop:disable Naming/ClassAndModuleCamelCase
910
extend FFI::Library
10-
if FFI::Platform.windows?
11-
ffi_lib 'libeay32', 'ssleay32'
12-
else
13-
ffi_lib [
14-
'libssl.so.1.1.0', 'libssl.so.1.1',
15-
'libssl.so.1.0.0', 'libssl.so.10',
16-
'ssl'
17-
]
18-
end
11+
12+
# Use the library loaded by the extension require above.
13+
ffi_lib FFI::CURRENT_PROCESS
1914

2015
NID_secp256k1 = 714 # rubocop:disable Naming/ConstantName
2116
POINT_CONVERSION_COMPRESSED = 2
2217
POINT_CONVERSION_UNCOMPRESSED = 4
2318

24-
# OpenSSL 1.1.0 version as a numerical version value as defined in:
25-
# https://www.openssl.org/docs/man1.1.0/man3/OpenSSL_version.html
26-
VERSION_1_1_0_NUM = 0x10100000
27-
2819
# OpenSSL 1.1.0 engine constants, taken from:
2920
# https://github.com/openssl/openssl/blob/2be8c56a39b0ec2ec5af6ceaf729df154d784a43/include/openssl/crypto.h
3021
OPENSSL_INIT_ENGINE_RDRAND = 0x00000200
@@ -52,21 +43,10 @@ module OpenSSL_EC # rubocop:disable Naming/ClassAndModuleCamelCase
5243
attach_function :SSLeay, [], :long
5344
end
5445

55-
# Returns the version of SSL present.
56-
#
57-
# @return [Integer] version number as an integer.
58-
def self.version
59-
if self.respond_to?(:OpenSSL_version_num)
60-
OpenSSL_version_num()
61-
else
62-
SSLeay()
63-
end
64-
end
65-
66-
if version >= VERSION_1_1_0_NUM
46+
begin
6747
# Initialization procedure for the library was changed in OpenSSL 1.1.0
6848
attach_function :OPENSSL_init_ssl, [:uint64, :pointer], :int
69-
else
49+
rescue FFI::NotFoundError
7050
attach_function :SSL_library_init, [], :int
7151
attach_function :ERR_load_crypto_strings, [], :void
7252
attach_function :SSL_load_error_strings, [], :void
@@ -391,7 +371,7 @@ def self.init_ffi_ssl
391371
@ssl_loaded ||= false
392372
return if @ssl_loaded
393373

394-
if version >= VERSION_1_1_0_NUM
374+
if self.method_defined?(:OPENSSL_init_ssl)
395375
OPENSSL_init_ssl(
396376
OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_ENGINE_ALL_BUILTIN,
397377
nil

lib/bitcoin/key.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def to_bip38(passphrase)
183183
addresshash = Digest::SHA256.digest( Digest::SHA256.digest( self.addr ) )[0...4]
184184

185185
require 'scrypt' unless defined?(::SCrypt::Engine)
186-
buf = SCrypt::Engine.__sc_crypt(passphrase, addresshash, 16384, 8, 8, 64)
186+
buf = SCrypt::Engine.scrypt(passphrase, addresshash, 16384, 8, 8, 64)
187187
derivedhalf1, derivedhalf2 = buf[0...32], buf[32..-1]
188188

189189
aes = proc{|k,a,b|
@@ -212,7 +212,7 @@ def self.from_bip38(encrypted_privkey, passphrase)
212212
raise "Invalid checksum" unless Digest::SHA256.digest(Digest::SHA256.digest(version + flagbyte + addresshash + encryptedhalf1 + encryptedhalf2))[0...4] == checksum
213213

214214
require 'scrypt' unless defined?(::SCrypt::Engine)
215-
buf = SCrypt::Engine.__sc_crypt(passphrase, addresshash, 16384, 8, 8, 64)
215+
buf = SCrypt::Engine.scrypt(passphrase, addresshash, 16384, 8, 8, 64)
216216
derivedhalf1, derivedhalf2 = buf[0...32], buf[32..-1]
217217

218218
aes = proc{|k,a|

lib/bitcoin/litecoin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def xor_salsa8(a, b, a_offset, b_offset)
6868

6969
begin
7070
require "scrypt"
71-
hash = SCrypt::Engine.__sc_crypt(secret_bytes, secret_bytes, 1024, 1, 1, 32)
71+
hash = SCrypt::Engine.scrypt(secret_bytes, secret_bytes, 1024, 1, 1, 32)
7272
p hash.reverse.unpack("H*")[0] == "00000000002bef4107f882f6115e0b01f348d21195dacd3582aa2dabd7985806"
7373
rescue LoadError
7474
puts "scrypt gem not found, using native scrypt"
@@ -77,7 +77,7 @@ def xor_salsa8(a, b, a_offset, b_offset)
7777

7878
require 'benchmark'
7979
Benchmark.bmbm{|x|
80-
x.report("v1"){ SCrypt::Engine.__sc_crypt(secret_bytes, secret_bytes, 1024, 1, 1, 32).reverse.unpack("H*") rescue nil }
80+
x.report("v1"){ SCrypt::Engine.scrypt(secret_bytes, secret_bytes, 1024, 1, 1, 32).reverse.unpack("H*") rescue nil }
8181
x.report("v2"){ Litecoin::Scrypt.scrypt_1024_1_1_256_sp(secret_bytes).reverse.unpack("H*")[0] }
8282
}
8383
end

0 commit comments

Comments
 (0)