Class: Ed25519::SigningKey
- Inherits:
-
Object
- Object
- Ed25519::SigningKey
- Defined in:
- lib/ed25519/signing_key.rb
Overview
Private key for producing digital signatures
Instance Attribute Summary collapse
-
#keypair ⇒ Object
readonly
Returns the value of attribute keypair.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#verify_key ⇒ Object
readonly
Returns the value of attribute verify_key.
Class Method Summary collapse
-
.from_keypair(keypair) ⇒ Object
Create a SigningKey from a 64-byte Ed25519 keypair (i.e. public + private).
-
.generate ⇒ Object
Generate a random Ed25519 signing key (i.e. private scalar).
Instance Method Summary collapse
-
#initialize(seed) ⇒ SigningKey
constructor
Create a new Ed25519::SigningKey from the given seed value.
-
#inspect ⇒ Object
String inspection that does not leak secret values.
-
#sign(message) ⇒ String
Sign the given message, returning an Ed25519 signature.
-
#to_bytes ⇒ String
(also: #to_str)
Return a bytestring representation of this signing key.
Constructor Details
#initialize(seed) ⇒ SigningKey
Create a new Ed25519::SigningKey from the given seed value
30 31 32 33 34 35 36 |
# File 'lib/ed25519/signing_key.rb', line 30 def initialize(seed) Ed25519.validate_key_bytes(seed) @seed = seed @keypair = Ed25519.provider.create_keypair(seed) @verify_key = VerifyKey.new(@keypair[32, 32]) end |
Instance Attribute Details
#keypair ⇒ Object (readonly)
Returns the value of attribute keypair.
8 9 10 |
# File 'lib/ed25519/signing_key.rb', line 8 def keypair @keypair end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
8 9 10 |
# File 'lib/ed25519/signing_key.rb', line 8 def seed @seed end |
#verify_key ⇒ Object (readonly)
Returns the value of attribute verify_key.
8 9 10 |
# File 'lib/ed25519/signing_key.rb', line 8 def verify_key @verify_key end |
Class Method Details
.from_keypair(keypair) ⇒ Object
Create a SigningKey from a 64-byte Ed25519 keypair (i.e. public + private)
18 19 20 21 22 23 24 25 |
# File 'lib/ed25519/signing_key.rb', line 18 def self.from_keypair(keypair) raise TypeError, "expected String, got #{keypair.class}" unless keypair.is_a?(String) raise ArgumentError, "expected 64-byte String, got #{keypair.bytesize}" unless keypair.bytesize == 64 new(keypair[0, KEY_SIZE]).tap do |key| raise ArgumentError, "corrupt keypair" unless keypair[KEY_SIZE, KEY_SIZE] == key.verify_key.to_bytes end end |
Instance Method Details
#inspect ⇒ Object
String inspection that does not leak secret values
48 49 50 |
# File 'lib/ed25519/signing_key.rb', line 48 def inspect to_s end |
#sign(message) ⇒ String
Sign the given message, returning an Ed25519 signature
43 44 45 |
# File 'lib/ed25519/signing_key.rb', line 43 def sign() Ed25519.provider.sign(@keypair, ) end |
#to_bytes ⇒ String Also known as: to_str
Return a bytestring representation of this signing key
55 56 57 |
# File 'lib/ed25519/signing_key.rb', line 55 def to_bytes seed end |