Class: Eth::RpcSigner
- Inherits:
-
Object
- Object
- Eth::RpcSigner
- Defined in:
- lib/eth/rpc_signer.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key) ⇒ RpcSigner
constructor
A new instance of RpcSigner.
- #sign_message(message) ⇒ Object
Constructor Details
#initialize(key) ⇒ RpcSigner
Returns a new instance of RpcSigner.
6 7 8 |
# File 'lib/eth/rpc_signer.rb', line 6 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/eth/rpc_signer.rb', line 4 def key @key end |
Class Method Details
.ecrecover_address(message_hash_hex, signature_hex) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/eth/rpc_signer.rb', line 24 def ecrecover_address(, signature_hex) = Eth::Utils.hex_to_bin() signature = Eth::Utils.hex_to_bin(signature_hex) public_key = Eth::OpenSsl.recover_compact(, signature) signer = Eth::Utils.public_key_to_address(public_key) return signer end |
Instance Method Details
#sign_message(message) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/eth/rpc_signer.rb', line 10 def () payload = Eth::Signature.new() payload.signer = @key.address payload. = Eth::Utils.() payload.hash = Eth::Utils.keccak256(payload.) payload.signature = @key.sign_hash(payload.hash) payload.v, payload.r, payload.s = Eth::Utils.v_r_s_for(payload.signature) payload.rpc_signature = Eth::Utils.zpad_int(payload.r, 32) + Eth::Utils.zpad_int(payload.s, 32) + [(payload.v - 27)].pack('C') return payload end |