Class: Ed25519::VerifyKey
- Inherits:
-
Object
- Object
- Ed25519::VerifyKey
- Defined in:
- lib/ed25519/verify_key.rb
Overview
Public key for verifying digital signatures
Instance Method Summary collapse
-
#initialize(key) ⇒ VerifyKey
constructor
Create a Ed25519::VerifyKey from its serialized Twisted Edwards representation.
-
#inspect ⇒ Object
Show hex representation of serialized coordinate in string inspection.
-
#to_bytes ⇒ String
(also: #to_str)
Return a compressed twisted Edwards coordinate representing the public key.
-
#verify(signature, message) ⇒ true
Verify an Ed25519 signature against the message.
Constructor Details
#initialize(key) ⇒ VerifyKey
Create a Ed25519::VerifyKey from its serialized Twisted Edwards representation
9 10 11 12 |
# File 'lib/ed25519/verify_key.rb', line 9 def initialize(key) Ed25519.validate_key_bytes(key) @key_bytes = key end |
Instance Method Details
#inspect ⇒ Object
Show hex representation of serialized coordinate in string inspection
41 42 43 |
# File 'lib/ed25519/verify_key.rb', line 41 def inspect "#<#{self.class}:#{@key_bytes.unpack1('H*')}>" end |
#to_bytes ⇒ String Also known as: to_str
Return a compressed twisted Edwards coordinate representing the public key
35 36 37 |
# File 'lib/ed25519/verify_key.rb', line 35 def to_bytes @key_bytes end |
#verify(signature, message) ⇒ true
Verify an Ed25519 signature against the message
22 23 24 25 26 27 28 29 30 |
# File 'lib/ed25519/verify_key.rb', line 22 def verify(signature, ) if signature.length != SIGNATURE_SIZE raise ArgumentError, "expected #{SIGNATURE_SIZE} byte signature, got #{signature.length}" end return true if Ed25519.provider.verify(@key_bytes, signature, ) raise VerifyError, "signature verification failed!" end |