Class: ArkEcosystem::Crypto::Utils::Message
- Inherits:
-
Object
- Object
- ArkEcosystem::Crypto::Utils::Message
- Defined in:
- lib/arkecosystem/crypto/utils/message.rb
Overview
The builder to work with signed messages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message) ⇒ Message
constructor
A new instance of Message.
- #to_json ⇒ Object
- #to_params ⇒ Object
- #verify ⇒ Object
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() @public_key = [:publickey] @signature = [:signature] @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(, passphrase) key = ArkEcosystem::Crypto::Identities::PrivateKey.from_passphrase(passphrase) hash = Digest::SHA256.digest() Message.new(publickey: BTC.to_hex(key.public_key), signature: BTC.to_hex(key.ecdsa_signature(hash)), message: ) end |
Instance Method Details
#to_json ⇒ Object
36 37 38 |
# File 'lib/arkecosystem/crypto/utils/message.rb', line 36 def to_json to_params.to_json end |
#to_params ⇒ Object
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 |
#verify ⇒ Object
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 |