Class: Ed25519::SigningKey
- Inherits:
-
Object
- Object
- Ed25519::SigningKey
- Defined in:
- lib/red25519/keys.rb
Instance Attribute Summary collapse
-
#verify_key ⇒ Object
readonly
Returns the value of attribute verify_key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(seed) ⇒ SigningKey
constructor
A new instance of SigningKey.
- #inspect ⇒ Object
- #sign(message) ⇒ Object
- #to_bytes ⇒ Object (also: #to_s)
- #to_hex ⇒ Object
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_key ⇒ Object (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
.generate ⇒ Object
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
#inspect ⇒ Object
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() Ed25519::Engine.sign(@signing_key, ) end |
#to_bytes ⇒ Object Also known as: to_s
35 36 37 |
# File 'lib/red25519/keys.rb', line 35 def to_bytes @seed end |
#to_hex ⇒ Object
40 41 42 |
# File 'lib/red25519/keys.rb', line 40 def to_hex to_bytes.unpack("H*").first end |