Class: LocalVault::CLI::Keys

Inherits:
Thor
  • Object
show all
Defined in:
lib/localvault/cli/keys.rb

Instance Method Summary collapse

Instance Method Details

#generateObject

Generate a new X25519 keypair for vault sharing.

Creates a private/public key pair in the LocalVault config directory. Refuses to overwrite an existing keypair unless --force is passed. After generating, run localvault keys publish to upload the public key.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/localvault/cli/keys.rb', line 13

def generate
  if Identity.exists? && !options[:force]
    $stdout.puts "Keypair already exists at #{Config.keys_path}"
    $stdout.puts "Use --force to overwrite."
    return
  end

  Config.ensure_directories!
  Identity.generate!(force: options[:force])
  $stdout.puts "Keypair generated:"
  $stdout.puts "  Private: #{Identity.priv_key_path}"
  $stdout.puts "  Public:  #{Identity.pub_key_path}"
  $stdout.puts
  $stdout.puts "Run 'localvault keys publish' to upload your public key to InventList."
rescue RuntimeError => e
  $stderr.puts "Error: #{e.message}"
end

#publishObject

Publish your X25519 public key to InventList.

Requires a keypair (run localvault keys generate first) and an active login session (run localvault login first). Once published, other users can share vaults with you.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/localvault/cli/keys.rb', line 37

def publish
  unless Identity.exists?
    $stderr.puts "Error: No keypair found. Run: localvault keys generate"
    return
  end

  unless Config.token
    $stderr.puts "Error: Not logged in. Run: localvault login"
    return
  end

  client = ApiClient.new(token: Config.token)
  client.publish_public_key(Identity.public_key)
  $stdout.puts "Public key published to InventList (@#{Config.inventlist_handle})."
  $stdout.puts "Others can now share vaults with you."
rescue ApiClient::ApiError => e
  $stderr.puts "Error: #{e.message}"
end

#showObject

Print your base64-encoded X25519 public key to stdout.

Useful for manual key exchange or verification. Requires a keypair to exist (run localvault keys generate first).



61
62
63
64
65
66
67
# File 'lib/localvault/cli/keys.rb', line 61

def show
  unless Identity.exists?
    $stderr.puts "Error: No keypair found. Run: localvault keys generate"
    return
  end
  $stdout.puts Identity.public_key
end