Class: Eth::RpcSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/eth/rpc_signer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/eth/rpc_signer.rb', line 4

def key
  @key
end

Instance Method Details

#sign_message(message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eth/rpc_signer.rb', line 10

def sign_message(message)
  payload = Eth::Signature.new(message)
  payload.prefixed_message = Eth::Utils.prefix_message(message)
  payload.hash = Eth::Utils.keccak256(payload.prefixed_message)
  payload.hash_hex = Eth::Utils.bin_to_prefixed_hex(payload.hash)
  payload.signature = @key.sign(payload.prefixed_message)
  payload.signature_hex = Eth::Utils.bin_to_prefixed_hex(payload.signature)
  payload.v, payload.r, payload.s = Eth::Utils.v_r_s_for(payload.signature)
  payload.rpc = Eth::Utils.zpad_int(payload.r, 32) + Eth::Utils.zpad_int(payload.s, 32) + [(payload.v - 27)].pack('C')
  payload.rpc_hex = Eth::Utils.bin_to_prefixed_hex(payload.rpc)
  return payload
end