Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(etherlite.gemspec): replace old digest-sha3 gem with keccak #7

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions etherlite.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'etherlite/version'

Expand All @@ -9,26 +8,28 @@ Gem::Specification.new do |spec|
spec.authors = ["Ignacio Baixas"]
spec.email = ["ignacio@surbtc.com"]

spec.summary = %q{Ethereum integration for ruby on rails}
spec.description = %q{}
spec.summary = 'Ethereum integration for ruby on rails'
spec.description = ''
spec.homepage = "https://github.com/SurBTC/etherlite"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "digest-sha3", "~> 1.1"
spec.add_dependency "power-types", "~> 0.1"
spec.add_dependency "eth", "~> 0.4.4"
spec.add_dependency "activesupport"
spec.add_dependency "eth", "~> 0.4.4"
spec.add_dependency 'keccak', '~> 1.3', '>= 1.3.1'
spec.add_dependency "power-types", "~> 0.1"

spec.add_development_dependency "bundler", "~> 2.1.4"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "guard", "~> 2.14"
spec.add_development_dependency "guard-rspec", "~> 4.7"
spec.add_development_dependency "webmock", "~> 3.7.5"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "webmock", "~> 3.7.5"
end
2 changes: 1 addition & 1 deletion lib/etherlite.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "digest/sha3"
require 'digest/keccak'
require "active_support/all"
require "forwardable"
require "net/http"
Expand Down
14 changes: 8 additions & 6 deletions lib/etherlite/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module Utils
extend self

def sha3(_data)
Digest::SHA3.hexdigest(_data, 256)
Digest::Keccak.hexdigest(_data, 256)
end

def uint_to_hex(_value, bytes: 32)
_value.to_s(16).rjust(bytes * 2, '0')
end

def int_to_hex(_value, bytes: 32)
if _value < 0
if _value.negative?
# 2's complement for negative values
(_value & ((1 << bytes * 8) - 1)).to_s(16)
else
Expand All @@ -28,7 +28,7 @@ def hex_to_uint(_hex_value)
def hex_to_int(_hex_value, bytes: 32)
value = _hex_value.hex
top_bit = (1 << (bytes * 8 - 1))
value & top_bit > 0 ? (value - 2 * top_bit) : value
(value & top_bit).positive? ? (value - 2 * top_bit) : value
end

def valid_address?(_address)
Expand All @@ -45,21 +45,23 @@ def normalize_address_param(_value)
else
_value = _value.to_s
raise ArgumentError, 'invalid address' unless valid_address? _value

normalize_address _value
end
end

def encode_address_param(_value)
'0x' + normalize_address_param(_value)
"0x#{normalize_address_param(_value)}"
end

def encode_block_param(_value)
return _value.to_s if ['pending', 'earliest', 'latest'].include?(_value.to_s)
'0x' + _value.to_s(16)

"0x#{_value.to_s(16)}"
end

def encode_quantity_param(_value)
'0x' + _value.to_s(16)
"0x#{_value.to_s(16)}"
end
end
end