Manages cryptographic identities using X25519 encryption and Ed25519 signing key pairs.
Provides encryption, decryption, signing, validation, and destination tracking for the Reticulum network.
Constants
DERIVED_KEY_LENGTH = 512 // 8
DERIVED_KEY_LENGTH_LEGACY = 256 // 8
RATCHET_EXPIRY = ((60 * 60) * 24) * 30
TOKEN_OVERHEAD = Cryptography::Token::TOKEN_OVERHEAD
TRUNCATED_HASHLENGTH = 128
Constructors
new(create_keys :
Bool = true)
Creates a new Identity instance. When create_keys is true, generates fresh key pairs immediately.
SourceClass methods
from_bytes(prv_bytes :
Bytes) :
Identity |
Nil Creates an Identity from raw private key bytes. Returns nil if the key is invalid.
Sourcefrom_file(path :
String) :
Identity |
Nil Loads an Identity from a file containing private key bytes. Returns nil on failure.
SourceComputes a full SHA-256 hash of the given data.
Sourceget_random_hash
Generates a random truncated hash from secure random bytes.
Sourceload_known_destinations(storage_path :
String |
Nil = nil)
Sourcerecall(target_hash :
Bytes, from_identity_hash :
Bool = false) :
Identity |
Nil Recalls a known Identity by destination hash or identity hash. Returns nil if not found.
Sourcerecall_app_data(destination_hash :
Bytes) :
Bytes |
Nil Retrieves the stored app data for a known destination, or nil if not found.
Sourceremember(packet_hash :
Bytes, destination_hash :
Bytes, public_key :
Bytes, app_data :
Bytes |
Nil = nil)
Stores a destination's public key and app data in the known destinations table.
Sourcesave_known_destinations(storage_path :
String |
Nil = nil)
SourceComputes a truncated hash (first 128 bits of the full SHA-256 hash).
Sourcetry_clean_ratchets
Clean expired ratchets from @@known_ratchets
Sourcevalidate_announce(packet :
Packet, only_validate_signature :
Bool = false) :
Bool Validates an announce packet. Returns true if valid, false otherwise.
When only_validate_signature is true, skips destination hash and
known_destinations checks (used for quick signature validation).
SourceInstance methods
create_keys
Generates new X25519 encryption and Ed25519 signing key pairs, then updates identity hashes.
SourceDecrypts ciphertext, optionally trying ratchet keys first. Returns nil on failure.
SourceEncrypts plaintext using ECDH key exchange with an ephemeral key and Token-based symmetric encryption.
Sourceget_private_key
Returns the concatenated private key bytes (encryption key + signing key).
Sourceget_public_key
Returns the concatenated public key bytes (encryption key + signing key).
Sourcehash
Generates an UInt64 hash value for this object.
This method must have the property that a == b implies a.hash == b.hash.
The hash value is used along with == by the Hash class to determine if two objects
reference the same hash key.
Subclasses must not override this method. Instead, they must define hash(hasher),
though usually the macro def_hash can be used to generate this method.
SourceLoads an identity's private key from a file and derives all key pairs from it.
SourceLoads encryption and signing key pairs from raw private key bytes. Returns true on success.
Sourceload_public_key(pub_bytes :
Bytes)
Loads encryption and signing public keys from raw public key bytes.
Sourceprv
─── Instance properties ───────────────────────────────────────────
Sourceprv=(prv : Cryptography::X25519PrivateKey | Nil)
─── Instance properties ───────────────────────────────────────────
Sourcepub=(pub : Cryptography::X25519PublicKey | Nil)
Sourcesig_prv=(sig_prv : Cryptography::Ed25519PrivateKey | Nil)
Sourcesig_pub=(sig_pub : Cryptography::Ed25519PublicKey | Nil)
SourceSigns a message using the Ed25519 private signing key.
SourceSaves the identity's private key to a file at the given path.
SourceAppends a short String representation of this object
which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
SourceValidates an Ed25519 signature against a message. Returns true if the signature is valid.
Source