class Exonum::MessageT
Attributes
body[RW]
head[RW]
message_id[RW]
protocol_version[RW]
service_id[RW]
signature[RW]
Public Class Methods
new(protocol_version, message_id, service_id, body)
click to toggle source
# File lib/exonum/types/message.rb, line 10 def initialize protocol_version, message_id, service_id, body self.protocol_version = protocol_version self.message_id = message_id self.service_id = service_id self.head = StructT.new([ { name: 'network_id', type: UInt8T }, { name: 'protocol_version', type: UInt8T }, { name: 'message_id', type: UInt16T }, { name: 'service_id', type: UInt16T }, { name: 'payload', type: UInt32T } ]) self.body = body end
Public Instance Methods
serialize(data)
click to toggle source
# File lib/exonum/types/message.rb, line 24 def serialize data buffer = SparseArray.new head_data = { network_id: 0, protocol_version: self.protocol_version, message_id: self.message_id, service_id: self.service_id, payload: 0 # placeholder, real value will be inserted later } head.serialize head_data, buffer, 0 body.serialize data, buffer, head.size, 0, true UInt32T.serialize buffer.length + SignatureT.size, buffer, 6 buffer.serialize end
sign(secret, data)
click to toggle source
# File lib/exonum/types/message.rb, line 39 def sign secret, data raise "Expecting 64 bytes key in hex" unless secret.is_a?(String) and secret.length == 128 key = Ed25519::SigningKey.new [secret[0..63]].pack 'H*' buffer = serialize(data).pack('c*') key.sign(buffer).unpack('H*').first end