Class: OPP::KeyPair

Inherits:
Object
  • Object
show all
Defined in:
lib/opp/key_pair.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signing_key) ⇒ KeyPair

Returns a new instance of KeyPair.



15
16
17
18
19
# File 'lib/opp/key_pair.rb', line 15

def initialize(signing_key)
  @signing_key = signing_key
  @private_key = Base64URL.encode(signing_key.to_bytes)
  @public_key = Base64URL.encode(signing_key.verify_key.to_bytes)
end

Instance Attribute Details

#private_keyObject (readonly)

Returns the value of attribute private_key.



5
6
7
# File 'lib/opp/key_pair.rb', line 5

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



5
6
7
# File 'lib/opp/key_pair.rb', line 5

def public_key
  @public_key
end

Class Method Details

.from_private_key(value) ⇒ Object



11
12
13
# File 'lib/opp/key_pair.rb', line 11

def self.from_private_key(value)
  new(Ed25519::SigningKey.new(Base64URL.decode(value, length: 32)))
end

.generateObject



7
8
9
# File 'lib/opp/key_pair.rb', line 7

def self.generate
  new(Ed25519::SigningKey.generate)
end

Instance Method Details

#sign(bytes) ⇒ Object



21
22
23
# File 'lib/opp/key_pair.rb', line 21

def sign(bytes)
  @signing_key.sign(bytes)
end