Class: Secp256k1Recipe

Inherits:
MiniPortile
  • Object
show all
Defined in:
ext/rbsecp256k1/extconf.rb

Overview

Recipe for downloading and building libsecp256k1 as part of installation

Constant Summary collapse

LIBSECP256K1_ZIP_URL =

Hard-coded URL for libsecp256k1 zipfile (HEAD of master as of 26-11-2018)

'https://github.com/bitcoin-core/secp256k1/archive/e34ceb333b1c0e6f4115ecbb80c632ac1042fa49.zip'
LIBSECP256K1_SHA256 =

Expected SHA-256 of the zipfile above (computed using sha256sum)

'd87d3ca7ebc42edbabb0f38e79205040b24b09b3e6d1c9ac89585de9bf302143'
WITH_RECOVERY =
ENV.fetch('WITH_RECOVERY', '1') == '1'
WITH_ECDH =
ENV.fetch('WITH_ECDH', '1') == '1'

Instance Method Summary collapse

Constructor Details

#initializeSecp256k1Recipe

Returns a new instance of Secp256k1Recipe.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/rbsecp256k1/extconf.rb', line 18

def initialize
  super('libsecp256k1', '0.0.0')
  @tarball = File.join(Dir.pwd, "/ports/archives/libsecp256k1.zip")
  @files = ["file://#{@tarball}"]
  self.configure_options += [
    "--disable-benchmark",
    "--disable-exhaustive-tests",
    "--disable-tests",
    "--disable-debug",
    "--enable-experimental",
    "--with-pic=yes"
  ]

  configure_options << "--enable-module-recovery" if WITH_RECOVERY
  configure_options << "--enable-module-ecdh" if WITH_ECDH
end

Instance Method Details

#configureObject



35
36
37
38
39
40
41
42
43
44
45
# File 'ext/rbsecp256k1/extconf.rb', line 35

def configure
  # Need to run autogen.sh before configure since it creates it
  if RUBY_PLATFORM =~ /mingw|mswin/
    # Windows doesn't recognize the shebang.
    execute('autogen', %w[sh ./autogen.sh])
  else
    execute('autogen', %w[./autogen.sh])
  end

  super
end

#downloadObject



47
48
49
50
# File 'ext/rbsecp256k1/extconf.rb', line 47

def download
  download_file_http(LIBSECP256K1_ZIP_URL, @tarball)
  verify_file(local_path: @tarball, sha256: LIBSECP256K1_SHA256)
end

#downloaded?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'ext/rbsecp256k1/extconf.rb', line 52

def downloaded?
  File.exist?(@tarball)
end

#extractObject



67
68
69
70
71
# File 'ext/rbsecp256k1/extconf.rb', line 67

def extract
  files_hashs.each do |file|
    extract_zip_file(file[:local_path], tmp_path)
  end
end

#extract_zip_file(file, destination) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'ext/rbsecp256k1/extconf.rb', line 56

def extract_zip_file(file, destination)
  FileUtils.mkdir_p(destination)

  Zip::File.open(file) do |zip_file|
    zip_file.each do |f|
      fpath = File.join(destination, f.name)
      zip_file.extract(f, fpath) unless File.exist?(fpath)
    end
  end
end