Class: Ed25519::SigningKey

Inherits:
Object
  • Object
show all
Defined in:
lib/red25519/keys.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed) ⇒ SigningKey

Returns a new instance of SigningKey.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/red25519/keys.rb', line 14

def initialize(seed)
  case seed.length
  when 32
    @seed = seed
  when 64
    @seed = [seed].pack("H*")
  else raise ArgumentError, "seed must be 32 or 64 bytes long"
  end

  verify_key, @signing_key = Ed25519::Engine.create_keypair(@seed)
  @verify_key = VerifyKey.new(verify_key)
end

Instance Attribute Details

#verify_keyObject (readonly)

Returns the value of attribute verify_key.



6
7
8
# File 'lib/red25519/keys.rb', line 6

def verify_key
  @verify_key
end

Class Method Details

.generateObject



8
9
10
11
12
# File 'lib/red25519/keys.rb', line 8

def self.generate
  random_bytes = SecureRandom.random_bytes(Ed25519::SECRET_KEY_BYTES)
  hkdf = HKDF.new(random_bytes)
  new hkdf.next_bytes(Ed25519::SECRET_KEY_BYTES)
end

Instance Method Details

#inspectObject



31
32
33
# File 'lib/red25519/keys.rb', line 31

def inspect
  "#<Ed25519::SigningKey:#{to_hex}>"
end

#sign(message) ⇒ Object



27
28
29
# File 'lib/red25519/keys.rb', line 27

def sign(message)
  Ed25519::Engine.sign(@signing_key, message)
end

#to_bytesObject Also known as: to_s



35
36
37
# File 'lib/red25519/keys.rb', line 35

def to_bytes
  @seed
end

#to_hexObject



40
41
42
# File 'lib/red25519/keys.rb', line 40

def to_hex
  to_bytes.unpack("H*").first
end