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 (Official release v0.2.0)

'https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.2.0.zip'
LIBSECP256K1_SHA256 =

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

'6ece280c0e6ea9d861051077c28a25b7f48800c43a4098a800b7d3b0c124e406'

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
# File 'ext/rbsecp256k1/extconf.rb', line 18

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

  # ECDH is enabled by default in release v0.2.0, but recovery still needs to
  # be enabled manually.
  configure_options << "--enable-module-recovery" if WITH_RECOVERY
end

Instance Method Details

#configureObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/rbsecp256k1/extconf.rb', line 31

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('chmod', %w[chmod +x ./autogen.sh])
    execute('autogen', %w[./autogen.sh])
  end

  super
end

#downloadObject



44
45
46
47
# File 'ext/rbsecp256k1/extconf.rb', line 44

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

#downloaded?Boolean

Returns:

  • (Boolean)


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

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

#extractObject



64
65
66
67
68
# File 'ext/rbsecp256k1/extconf.rb', line 64

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

#extract_zip_file(file, destination) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'ext/rbsecp256k1/extconf.rb', line 53

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