From 33cb0764141a754e57f6fe86840c85672021f931 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Wed, 1 Dec 2021 16:11:59 +0100 Subject: [PATCH 1/2] gems: rename sha3 to keccak --- etherlite.gemspec | 20 +++++++++---------- lib/etherlite.rb | 2 +- .../commands/utils/validate_address.rb | 2 +- lib/etherlite/contract/event_base.rb | 2 +- lib/etherlite/contract/function.rb | 2 +- lib/etherlite/utils.rb | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/etherlite.gemspec b/etherlite.gemspec index be5dfdf..cd7d363 100644 --- a/etherlite.gemspec +++ b/etherlite.gemspec @@ -19,16 +19,16 @@ Gem::Specification.new do |spec| 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 "keccak", "~> 1.1" + spec.add_dependency "power-types", "~> 0.4" + spec.add_dependency "eth", "~> 0.4" + spec.add_dependency "activesupport", "~> 6.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 "bundler", "~> 2.2" + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.10" + spec.add_development_dependency "guard", "~> 2.18" 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 "webmock", "~> 3.14" + spec.add_development_dependency "pry", "~> 0.14" end diff --git a/lib/etherlite.rb b/lib/etherlite.rb index 63edb13..dea94d3 100644 --- a/lib/etherlite.rb +++ b/lib/etherlite.rb @@ -1,4 +1,4 @@ -require "digest/sha3" +require "digest/keccak" require "active_support/all" require "forwardable" require "net/http" diff --git a/lib/etherlite/commands/utils/validate_address.rb b/lib/etherlite/commands/utils/validate_address.rb index a95f22c..0938ed1 100644 --- a/lib/etherlite/commands/utils/validate_address.rb +++ b/lib/etherlite/commands/utils/validate_address.rb @@ -12,7 +12,7 @@ def perform def valid_checksum? trimmed_address = @address.gsub(/^0x/, '') - address_hash = Etherlite::Utils.sha3 trimmed_address.downcase + address_hash = Etherlite::Utils.keccak trimmed_address.downcase trimmed_address.chars.each_with_index do |c, i| hash_byte = address_hash[i].to_i(16) diff --git a/lib/etherlite/contract/event_base.rb b/lib/etherlite/contract/event_base.rb index 837b38d..a6c9fe1 100644 --- a/lib/etherlite/contract/event_base.rb +++ b/lib/etherlite/contract/event_base.rb @@ -18,7 +18,7 @@ def self.signature end def self.topic - '0x' + Etherlite::Utils.sha3(signature) + '0x' + Etherlite::Utils.keccak(signature) end def self.decode(_connection, _json) diff --git a/lib/etherlite/contract/function.rb b/lib/etherlite/contract/function.rb index 728d544..d2e1178 100644 --- a/lib/etherlite/contract/function.rb +++ b/lib/etherlite/contract/function.rb @@ -34,7 +34,7 @@ def encode(_values) encoded_inputs = Etherlite::Support::Array.encode(@inputs.map(&:type), _values) if @name - signature_hash = Etherlite::Utils.sha3 signature + signature_hash = Etherlite::Utils.keccak signature '0x' + signature_hash[0..7] + encoded_inputs else encoded_inputs # if no name is provided, just render arguments diff --git a/lib/etherlite/utils.rb b/lib/etherlite/utils.rb index 5238614..580a6db 100644 --- a/lib/etherlite/utils.rb +++ b/lib/etherlite/utils.rb @@ -4,8 +4,8 @@ module Etherlite module Utils extend self - def sha3(_data) - Digest::SHA3.hexdigest(_data, 256) + def keccak(_data) + Digest::Keccak.hexdigest(_data, 256) end def uint_to_hex(_value, bytes: 32) From e68d92be77d5d4b70df876d5f26c784a5aed5132 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Wed, 1 Dec 2021 16:13:24 +0100 Subject: [PATCH 2/2] gems: bump keccak to 1.3.0 --- etherlite.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etherlite.gemspec b/etherlite.gemspec index cd7d363..1725e83 100644 --- a/etherlite.gemspec +++ b/etherlite.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "keccak", "~> 1.1" + spec.add_dependency "keccak", "~> 1.3" spec.add_dependency "power-types", "~> 0.4" spec.add_dependency "eth", "~> 0.4" spec.add_dependency "activesupport", "~> 6.1"