Class: Nostr::Key Private
- Inherits:
-
String
- Object
- String
- Nostr::Key
- Defined in:
- lib/nostr/key.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Abstract class for all keys
Direct Known Subclasses
Constant Summary collapse
- FORMAT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The regular expression for hexadecimal lowercase characters
/^[a-f0-9]+$/
- LENGTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The length of the key in hex format
64
Class Method Summary collapse
-
.from_bech32(bech32_value) ⇒ Key
Instantiates a key from a bech32 string.
-
.hrp ⇒ String
private
Abstract method to be implemented by subclasses to provide the HRP (npub, nsec).
Instance Method Summary collapse
-
#initialize(hex_value) ⇒ Key
constructor
private
Instantiates a new key.
-
#to_bech32 ⇒ String
Converts the key to a bech32 string representation.
Constructor Details
#initialize(hex_value) ⇒ Key
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiates a new key. Can’t be used directly because this is an abstract class. Raises a KeyValidationError
30 31 32 33 34 |
# File 'lib/nostr/key.rb', line 30 def initialize(hex_value) validate_hex_value(hex_value) super(hex_value) end |
Class Method Details
.from_bech32(bech32_value) ⇒ Key
Instantiates a key from a bech32 string
50 51 52 53 54 55 56 |
# File 'lib/nostr/key.rb', line 50 def self.from_bech32(bech32_value) type, data = Bech32.decode(bech32_value) raise InvalidHRPError.new(type, hrp) unless type == hrp new(data) end |
.hrp ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Abstract method to be implemented by subclasses to provide the HRP (npub, nsec)
64 65 66 |
# File 'lib/nostr/key.rb', line 64 def self.hrp raise 'Subclasses must implement this method' end |