Class: ArkEcosystem::Crypto::Utils::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/arkecosystem/crypto/utils/message.rb

Overview

The builder to work with signed messages.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Message

Returns a new instance of Message.



6
7
8
9
10
# File 'lib/arkecosystem/crypto/utils/message.rb', line 6

def initialize(message)
  @public_key = message[:publickey]
  @signature = message[:signature]
  @message = message[:message]
end

Class Method Details

.sign(message, passphrase) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/arkecosystem/crypto/utils/message.rb', line 12

def self.sign(message, passphrase)
  key = ArkEcosystem::Crypto::Identities::PrivateKey.from_passphrase(passphrase)

  hash = Digest::SHA256.digest(message)

  Message.new(publickey: BTC.to_hex(key.public_key),
              signature: BTC.to_hex(key.ecdsa_signature(hash)),
              message: message)
end

Instance Method Details

#to_jsonObject



36
37
38
# File 'lib/arkecosystem/crypto/utils/message.rb', line 36

def to_json
  to_params.to_json
end

#to_paramsObject



30
31
32
33
34
# File 'lib/arkecosystem/crypto/utils/message.rb', line 30

def to_params
  { publickey: @public_key,
    signature: @signature,
    message: @message }
end

#verifyObject



22
23
24
25
26
27
28
# File 'lib/arkecosystem/crypto/utils/message.rb', line 22

def verify
  key = BTC::Key.new(public_key: BTC.from_hex(@public_key))

  hash = Digest::SHA256.digest(@message)

  key.verify_ecdsa_signature(BTC.from_hex(@signature), hash)
end