Class: Interapp::Message

Inherits:
Object
  • Object
show all
Defined in:
app/models/interapp/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Message

Returns a new instance of Message.



5
6
7
# File 'app/models/interapp/message.rb', line 5

def initialize(attributes = {})
  attributes.each { |name, value| send("#{name}=", value) }
end

Instance Attribute Details

#payloadObject

Returns the value of attribute payload.



3
4
5
# File 'app/models/interapp/message.rb', line 3

def payload
  @payload
end

#peerObject

Returns the value of attribute peer.



3
4
5
# File 'app/models/interapp/message.rb', line 3

def peer
  @peer
end

#signatureObject

Returns the value of attribute signature.



3
4
5
# File 'app/models/interapp/message.rb', line 3

def signature
  @signature
end

Instance Method Details

#signObject



13
14
15
16
# File 'app/models/interapp/message.rb', line 13

def sign
  encoded_signature = Interapp::Cryptography.sign(payload, Interapp.configuration.private_key.to_i(16))
  self.signature = encoded_signature.unpack("H*").first
end

#signature_decodedObject



18
19
20
# File 'app/models/interapp/message.rb', line 18

def signature_decoded
  ECDSA::Format::SignatureDerString.decode([signature].pack("H*"))
end

#verifyObject



9
10
11
# File 'app/models/interapp/message.rb', line 9

def verify
  Interapp::Cryptography.verify(payload, signature_decoded, peer.public_key_decoded)
end