Class: Ed25519::VerifyKey

Inherits:
Object
  • Object
show all
Defined in:
lib/ed25519/verify_key.rb

Overview

Public key for verifying digital signatures

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ VerifyKey

Create a Ed25519::VerifyKey from its serialized Twisted Edwards representation

Parameters:

  • key (String)

    32-byte string representing a serialized public key



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

#inspectObject

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_bytesString Also known as: to_str

Return a compressed twisted Edwards coordinate representing the public key

Returns:

  • (String)

    bytestring serialization of this 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

Parameters:

  • signature (String)

    64-byte string containing an Ed25519 signature

  • message (String)

    string containing message to be verified

Returns:

  • (true)

    message verified successfully

Raises:

  • Ed25519::VerifyError signature verification failed



22
23
24
25
26
27
28
29
30
# File 'lib/ed25519/verify_key.rb', line 22

def verify(signature, message)
  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, message)

  raise VerifyError, "signature verification failed!"
end