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.
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 |
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 () payload = Eth::Signature.new() payload. = Eth::Utils.() payload.hash = Eth::Utils.keccak256(payload.) payload.hash_hex = Eth::Utils.bin_to_prefixed_hex(payload.hash) payload.signature = @key.sign(payload.) 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 |