Module: LocalVault::Identity
- Defined in:
- lib/localvault/identity.rb
Overview
Manages the user’s X25519 identity keypair for vault sharing and sync.
The keypair is stored in ~/.localvault/keys/:
-
identity.priv(mode 0600) — base64-encoded private key -
identity.pub(mode 0644) — base64-encoded public key
The public key is published to InventList so others can encrypt key slots for you. The private key never leaves the local machine.
Class Method Summary collapse
-
.exists? ⇒ Boolean
Check whether both key files exist on disk.
-
.generate!(force: false) ⇒ Hash{Symbol => String}
Generate a new X25519 identity keypair and write to disk.
-
.priv_key_path ⇒ String
Path to the private key file.
-
.private_key_b64 ⇒ String?
Read the private key as a base64-encoded string.
-
.private_key_bytes ⇒ String?
Read the private key as raw bytes (decoded from base64).
-
.pub_key_path ⇒ String
Path to the public key file.
-
.public_key ⇒ String?
Read the public key as a base64-encoded string.
-
.setup? ⇒ Boolean
Check whether identity is fully configured (keypair exists and token is set).
Class Method Details
.exists? ⇒ Boolean
Check whether both key files exist on disk.
33 34 35 |
# File 'lib/localvault/identity.rb', line 33 def self.exists? File.exist?(priv_key_path) && File.exist?(pub_key_path) end |
.generate!(force: false) ⇒ Hash{Symbol => String}
Generate a new X25519 identity keypair and write to disk.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/localvault/identity.rb', line 42 def self.generate!(force: false) raise "Keypair already exists. Use --force to overwrite." if exists? && !force Config.ensure_directories! kp = Crypto.generate_keypair File.write(priv_key_path, Base64.strict_encode64(kp[:private_key])) File.chmod(0o600, priv_key_path) File.write(pub_key_path, Base64.strict_encode64(kp[:public_key])) File.chmod(0o644, pub_key_path) kp end |
.priv_key_path ⇒ String
Path to the private key file.
23 |
# File 'lib/localvault/identity.rb', line 23 def self.priv_key_path = File.join(Config.keys_path, "identity.priv") |
.private_key_b64 ⇒ String?
Read the private key as a base64-encoded string.
66 67 68 69 |
# File 'lib/localvault/identity.rb', line 66 def self.private_key_b64 return nil unless File.exist?(priv_key_path) File.read(priv_key_path).strip end |
.private_key_bytes ⇒ String?
Read the private key as raw bytes (decoded from base64).
74 75 76 77 |
# File 'lib/localvault/identity.rb', line 74 def self.private_key_bytes b64 = private_key_b64 b64 ? Base64.strict_decode64(b64) : nil end |
.pub_key_path ⇒ String
Path to the public key file.
28 |
# File 'lib/localvault/identity.rb', line 28 def self.pub_key_path = File.join(Config.keys_path, "identity.pub") |
.public_key ⇒ String?
Read the public key as a base64-encoded string.
58 59 60 61 |
# File 'lib/localvault/identity.rb', line 58 def self.public_key return nil unless File.exist?(pub_key_path) File.read(pub_key_path).strip end |